Skip to content

Commit bd5d252

Browse files
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into uplink
2 parents f8a9279 + ec089de commit bd5d252

19 files changed

Lines changed: 1694 additions & 21 deletions

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ endif()
125125
set(BUNDLE_LOC "" CACHE STRING "Local path of bundle with pre-compile libraries")
126126
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cross_compiled_libraries.txt)
127127

128+
# object format needs to be set BEFORE enabling ASM
129+
# see: https://cmake.org/Bug/bug_relationship_graph.php?bug_id=13166
130+
if ("${ARCH}" STREQUAL "i686")
131+
set(CMAKE_ASM_NASM_OBJECT_FORMAT "elf")
132+
set(OBJCOPY_TARGET "elf32-i386")
133+
else()
134+
set(CMAKE_ASM_NASM_OBJECT_FORMAT "elf64")
135+
set(OBJCOPY_TARGET "elf64-x86-64")
136+
endif()
137+
138+
enable_language(ASM_NASM)
139+
128140
# Botan Crypto & TLS
129141
# Note: Include order matters!
130142
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/botan.cmake)
@@ -187,6 +199,11 @@ if(libmana)
187199
add_subdirectory(lib/mana)
188200
endif(libmana)
189201

202+
option(libliveupdate "Build and install LiveUpdate" ON)
203+
if(libliveupdate)
204+
add_subdirectory(lib/LiveUpdate)
205+
endif(libliveupdate)
206+
190207
#
191208
# Installation
192209
#

diskimagebuild/fat_internal.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ static const uint8_t LAST_LONG_ENTRY = 0x40;
3737
struct cl_dir
3838
{
3939
uint8_t shortname[11];
40-
uint8_t attrib;
40+
uint8_t attrib = 0;
4141
uint8_t pad1[8];
42-
uint16_t cluster_hi;
43-
uint32_t modified;
44-
uint16_t cluster_lo;
45-
uint32_t filesize;
42+
uint16_t cluster_hi = 0;
43+
uint32_t modified = 0;
44+
uint16_t cluster_lo = 0;
45+
uint32_t filesize = 0;
4646

4747
} __attribute__((packed));
4848

diskimagebuild/writer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void create_preamble(
127127
cl_dir ent;
128128
ent.attrib = ATTR_DIRECTORY;
129129
ent.filesize = 0;
130+
ent.modified = 0;
130131
// . current directory
131132
memcpy((char*) ent.shortname, ". ", SHORTNAME_LEN);
132133
ent.cluster_hi = fsys.to_cluster_hi(self);
@@ -152,6 +153,7 @@ cl_dir create_entry(const std::string& name, uint8_t attr, uint32_t size)
152153
ent.cluster_hi = 0; /// SET THIS
153154
ent.cluster_lo = 0; /// SET THIS
154155
ent.filesize = size;
156+
ent.modified = 0;
155157
return ent;
156158
}
157159

@@ -163,6 +165,7 @@ void fill_unused(std::vector<cl_dir>& ents, int num)
163165
ent.cluster_hi = 0;
164166
ent.cluster_lo = 0;
165167
ent.filesize = 0;
168+
ent.modified = 0;
166169
while (num-- > 0) ents.push_back(ent);
167170
}
168171
void mod16_test(std::vector<cl_dir>& ents, int& mod16, int long_entries)
@@ -229,7 +232,11 @@ long Dir::write(FileSys& fsys, FILE* file, long pos, long parent)
229232
{
230233
cl_dir last;
231234
last.shortname[0] = 0x0; // last entry
232-
last.attrib = 0;
235+
last.cluster_hi = 0;
236+
last.cluster_lo = 0;
237+
last.attrib = 0;
238+
last.modified = 0;
239+
last.filesize = 0;
233240
ents.push_back(last);
234241
}
235242

lib/LiveUpdate/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 2.8.9)
2+
3+
add_definitions(-DARCH_${ARCH})
4+
add_definitions(-DARCH="${ARCH}")
5+
6+
include_directories(${INCLUDEOS_ROOT}/api/posix)
7+
include_directories(${LIBCXX_INCLUDE_DIR})
8+
include_directories(${NEWLIB_INCLUDE_DIR})
9+
include_directories(${INCLUDEOS_ROOT}/src/include)
10+
include_directories(${INCLUDEOS_ROOT}/api)
11+
include_directories(${INCLUDEOS_ROOT}/mod/GSL/)
12+
13+
add_custom_command(
14+
OUTPUT hotswap64.bin
15+
COMMAND ${CMAKE_ASM_NASM_COMPILER} -f bin -o hotswap64.bin ${CMAKE_CURRENT_SOURCE_DIR}/hotswap64.asm
16+
DEPENDS hotswap64.asm
17+
)
18+
add_custom_target(hotswap64 DEPENDS hotswap64.bin)
19+
20+
# LiveUpdate static library
21+
add_library(liveupdate STATIC
22+
storage.cpp update.cpp resume.cpp rollback.cpp hotswap.cpp
23+
serialize_tcp.cpp hotswap64_blob.asm
24+
)
25+
add_dependencies(liveupdate hotswap64)
26+
install(TARGETS liveupdate DESTINATION includeos/${ARCH}/lib)
27+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/liveupdate.hpp DESTINATION includeos/include RENAME liveupdate)

lib/LiveUpdate/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LiveUpdate

lib/LiveUpdate/hotswap.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Master thesis
3+
* by Alf-Andre Walla 2016-2017
4+
*
5+
**/
6+
asm(".org 0x8000");
7+
#define SOFT_RESET_MAGIC 0xFEE1DEAD
8+
9+
extern "C" __attribute__((noreturn))
10+
void hotswap(const char* base, int len, char* dest, void* start, void* reset_data)
11+
{
12+
// replace old kernel with new
13+
for (int i = 0; i < len; i++)
14+
dest[i] = base[i];
15+
// jump to _start
16+
asm volatile("jmp *%2" : : "a" (SOFT_RESET_MAGIC), "b" (reset_data), "c" (start));
17+
asm volatile(
18+
".global __hotswap_length;\n"
19+
"__hotswap_length:" );
20+
// we can never get here!
21+
__builtin_unreachable();
22+
}

lib/LiveUpdate/hotswap64.asm

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
;
2+
; Master thesis
3+
; by Alf-Andre Walla 2016-2017
4+
;
5+
;
6+
ORG 0x8000
7+
8+
%define code32_segment 0x08
9+
%define data32_segment 0x10
10+
%define SOFT_RESET_MAGIC 0xFEE1DEAD
11+
12+
[BITS 64]
13+
ALIGN 16
14+
;; first six pointer arguments are passed in
15+
;; RDI, RSI, RDX, RCX, R8, and R9
16+
;; hotswap64(
17+
;; RDI: char* dest,
18+
;; RSI: const char* base,
19+
;; RDX: size_t len,
20+
;; RCX: void* entry_function,
21+
;; R8: void* reset_data)
22+
hotswap_amd64:
23+
;; save soft reset data location and entry function
24+
mov rax, r8
25+
mov [startaddr], ecx ; rcx
26+
mov [bootaddr], eax ; r8
27+
28+
;; hotswap 64-bit kernel
29+
;; source: RSI
30+
;; dest: RDI
31+
mov rcx, rdx ;; count
32+
cld
33+
rep movsb
34+
35+
begin_enter_protected:
36+
; load 64-bit GDTR with 32-bit entries
37+
lgdt [gdtr64]
38+
; enter compatibility mode
39+
push data32_segment
40+
push rsp
41+
pushf
42+
push code32_segment
43+
mov ecx, compatibility_mode
44+
push rcx
45+
iretq
46+
47+
startaddr: dd 0
48+
bootaddr: dd 0
49+
50+
[BITS 32]
51+
ALIGN 16
52+
compatibility_mode:
53+
; disable paging
54+
mov ecx, cr0
55+
and ecx, 0x7fffffff ;; clear PG (bit 31)
56+
mov cr0, ecx
57+
; disable LM
58+
mov ecx, 0xC0000080 ; EFER MSR
59+
rdmsr
60+
and eax, ~(1 << 8) ; remove LM-bit
61+
wrmsr
62+
63+
;; enter 32-bit protected mode
64+
jmp code32_segment:protected_mode
65+
protected_mode:
66+
mov cx, data32_segment
67+
mov ss, cx
68+
mov ds, cx
69+
mov es, cx
70+
mov fs, cx
71+
mov gs, cx
72+
73+
;;rdtsc
74+
;;mov DWORD [0x10000], eax
75+
;;mov DWORD [0x10004], edx
76+
77+
;; enter the new service from its entry point
78+
;; in 32-bit protected mode, while passing
79+
;; multiboot parameters in eax and ebx
80+
mov eax, SOFT_RESET_MAGIC
81+
mov ebx, [bootaddr]
82+
jmp DWORD [startaddr]
83+
84+
gdtr:
85+
dw gdt32_end - gdt32 - 1
86+
dd gdt32
87+
gdt32:
88+
;; Entry 0x0: Null descriptor
89+
dq 0x0
90+
;; Entry 0x18: 32-bit Code segment
91+
dw 0xffff ;Limit
92+
dw 0x0000 ;Base 15:00
93+
db 0x00 ;Base 23:16
94+
dw 0xcf9a ;Flags / Limit / Type [F,L,F,Type]
95+
db 0x00 ;Base 32:24
96+
;; Entry 0x20: 32-bit Data segment
97+
dw 0xffff ;Limit
98+
dw 0x0000 ;Base 15:00
99+
db 0x00 ;Base 23:16
100+
dw 0xcf92 ;Flags / Limit / Type [F,L,F,Type]
101+
db 0x00 ;Base 32:24
102+
gdt32_end:
103+
gdtr64:
104+
dw $ - gdt32 - 1 ; Limit
105+
dq gdt32 ; Base

lib/LiveUpdate/hotswap64_blob.asm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
global hotswap64
2+
global hotswap64_len
3+
4+
SECTION .text
5+
hotswap64:
6+
incbin "hotswap64.bin"
7+
8+
hotswap64_len:
9+
dd $ - hotswap64

0 commit comments

Comments
 (0)