Skip to content

Commit 754f2d2

Browse files
authored
Merge pull request #1357 from fwsGonzo/dev
Various multiboot fixes
2 parents 978ca8b + af042db commit 754f2d2

28 files changed

Lines changed: 250 additions & 141 deletions

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ else()
4545
set(DEFAULT_VM "vm.cpu_feat.json") # vmrunner
4646
endif(cpu_feat_vanilla)
4747

48+
option(single_threaded "Compile without SMP support" ON)
49+
4850
# create random hex string as stack protector canary
4951
string(RANDOM LENGTH 8 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)
5052

api/kernel/irq_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class alignas(SMP_ALIGN) IRQ_manager {
123123
{ return count_handled; }
124124

125125
/** Initialize for a local APIC */
126-
static void init(int cpuid);
126+
static void init();
127127
IRQ_manager() = default;
128128

129129
private:

api/kernel/os.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,7 @@ class OS {
213213
static void start(uint32_t boot_magic, uint32_t boot_addr);
214214

215215
/** Get "kernel modules", provided by multiboot */
216-
static Span_mods modules() {
217-
auto* bootinfo_ = bootinfo();
218-
if (bootinfo_ and bootinfo_->flags & MULTIBOOT_INFO_MODS) {
219-
220-
Expects(bootinfo_->mods_count < std::numeric_limits<int>::max());
221-
222-
return Span_mods{
223-
reinterpret_cast<multiboot_module_t*>(bootinfo_->mods_addr),
224-
static_cast<int>(bootinfo_->mods_count) };
225-
226-
}
227-
228-
return nullptr;
229-
}
230-
216+
static Span_mods modules();
231217

232218

233219
private:
@@ -281,4 +267,18 @@ class OS {
281267
friend void __platform_init();
282268
}; //< OS
283269

270+
inline OS::Span_mods OS::modules()
271+
{
272+
auto* bootinfo_ = bootinfo();
273+
if (bootinfo_ and bootinfo_->flags & MULTIBOOT_INFO_MODS and bootinfo_->mods_count) {
274+
275+
Expects(bootinfo_->mods_count < std::numeric_limits<int>::max());
276+
277+
return Span_mods{
278+
reinterpret_cast<multiboot_module_t*>(bootinfo_->mods_addr),
279+
static_cast<int>(bootinfo_->mods_count) };
280+
}
281+
return nullptr;
282+
}
283+
284284
#endif //< KERNEL_OS_HPP

cmake/cross_compiled_libraries.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ else(BUNDLE_LOC)
1818
include(ExternalProject)
1919
ExternalProject_Add(PrecompiledLibraries
2020
PREFIX precompiled
21-
URL https://github.com/hioa-cs/IncludeOS/releases/download/v0.10.1-bundle/IncludeOS_dependencies_multiarch_v0-10-1.tar.gz
22-
URL_HASH SHA1=d6c718108b900d098a1576abd815a53ce2307ba1
21+
URL https://github.com/hioa-cs/IncludeOS/releases/download/v0.11.0-bundle/IncludeOS_dependencies_v0-11-0-rc-1.tar.gz
22+
URL_HASH SHA1=f719886bcab5c55957361c024bab54c601d862f5
2323
CONFIGURE_COMMAND ""
2424
BUILD_COMMAND ""
2525
UPDATE_COMMAND ""

cmake/post.service.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ option(stripped "Strip symbols to further reduce size" OFF)
4444

4545
add_definitions(-DARCH_${ARCH})
4646
add_definitions(-DARCH="${ARCH}")
47+
if (single_threaded)
4748
add_definitions(-DINCLUDEOS_SINGLE_THREADED)
49+
endif()
4850

4951
# Compiler optimization
5052
set(OPTIMIZE "-O2")

cmake/pre.service.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ set(TRIPLE ${ARCH}) #-pc-linux-elf
2222
set(DCMAKE_CXX_COMPILER_TARGET ${TRIPLE})
2323
set(DCMAKE_C_COMPILER_TARGET ${TRIPLE})
2424

25+
option(single_threaded "Compile without SMP support" ON)
26+
2527
# include toolchain for arch
2628
include($ENV{INCLUDEOS_PREFIX}/includeos/${ARCH}-elf-toolchain.cmake)

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ enable_language(ASM_NASM)
1313

1414
add_definitions(-DARCH_${ARCH})
1515
add_definitions(-DARCH="${ARCH}")
16+
if (single_threaded)
1617
add_definitions(-DINCLUDEOS_SINGLE_THREADED)
18+
endif()
1719

1820
include_directories(${INCLUDEOS_ROOT}/api/posix)
1921
include_directories(${LIBCXX_INCLUDE_DIR})

src/arch/x86_64/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)
33
### x86_64 arch specific ###
44
set(ARCH_OBJECTS
55
apic_asm.asm
6+
apic_longmode.asm
67
arch_start.asm
78
interrupts.asm
89
fiber_asm.asm

src/arch/x86_64/apic_longmode.asm

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; This file is a part of the IncludeOS unikernel - www.includeos.org
2+
;
3+
; Copyright 2015 Oslo and Akershus University College of Applied Sciences
4+
; and Alfred Bratterud
5+
;
6+
; Licensed under the Apache License, Version 2.0 (the "License");
7+
; you may not use this file except in compliance with the License.
8+
; You may obtain a copy of the License at
9+
;
10+
; http://www.apache.org/licenses/LICENSE-2.0
11+
;
12+
; Unless required by applicable law or agreed to in writing, software
13+
; distributed under the License is distributed on an "AS IS" BASIS,
14+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
; See the License for the specific language governing permissions and
16+
; limitations under the License.
17+
;
18+
global __apic_trampoline:function
19+
extern __gdt64_base_pointer
20+
extern revenant_main
21+
22+
%define P4_TAB 0x1000
23+
24+
[BITS 32]
25+
__apic_trampoline:
26+
pop edi ;; cpuid
27+
28+
;; use same pagetable as CPU 0
29+
mov eax, P4_TAB
30+
mov cr3, eax
31+
32+
;; enable PAE
33+
mov eax, cr4
34+
or eax, 1 << 5
35+
mov cr4, eax
36+
37+
;; enable long mode
38+
mov ecx, 0xC0000080 ; EFER MSR
39+
rdmsr
40+
or eax, 1 << 8 ; Long Mode bit
41+
wrmsr
42+
43+
;; enable paging
44+
mov eax, cr0 ; Set the A-register to control register 0.
45+
or eax, 1 << 31
46+
mov cr0, eax ; Set control register 0 to the A-register.
47+
48+
;; load 64-bit GDT
49+
lgdt [__gdt64_base_pointer]
50+
jmp 0x8:long_mode ;; 0x8 = code seg
51+
52+
[BITS 64]
53+
long_mode:
54+
;; segment regs
55+
mov cx, 0x10 ;; 0x10 = data seg
56+
mov ds, cx
57+
mov es, cx
58+
mov fs, cx
59+
mov gs, cx
60+
mov ss, cx
61+
62+
;; align stack
63+
and rsp, -16
64+
;; retrieve CPU id
65+
mov rax, 1
66+
cpuid
67+
shr rbx, 24
68+
;; geronimo!
69+
mov rdi, rbx
70+
call revenant_main
71+
; stop execution
72+
cli
73+
hlt

src/arch/x86_64/arch_start.asm

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
; See the License for the specific language governing permissions and
1616
; limitations under the License.
1717
global __arch_start:function
18+
global __gdt64_base_pointer
1819
extern kernel_start
1920
extern __multiboot_magic
2021
extern __multiboot_addr
@@ -78,19 +79,16 @@ __arch_start:
7879
;; enable long mode
7980
mov ecx, 0xC0000080 ; EFER MSR
8081
rdmsr
81-
or eax, 1 << 8 ; Long Mode bit
82+
or eax, 1 << 8 ; Long Mode bit
8283
wrmsr
8384

8485
;; enable paging
8586
mov eax, cr0 ; Set the A-register to control register 0.
86-
or eax, 1 << 31
87+
or eax, 1 << 31
8788
mov cr0, eax ; Set control register 0 to the A-register.
8889

89-
mov eax, DWORD[__multiboot_magic] ; Preserve multiboot regs
90-
mov ebx, DWORD[__multiboot_addr]
91-
9290
;; load 64-bit GDT
93-
lgdt [GDT64.Pointer]
91+
lgdt [__gdt64_base_pointer]
9492
jmp GDT64.Code:long_mode
9593

9694

@@ -112,7 +110,7 @@ GDT64:
112110
db 00000000b ; Granularity.
113111
db 0 ; Base (high).
114112
dw 0x0 ;; alignment padding
115-
.Pointer: ; The GDT-pointer.
113+
__gdt64_base_pointer:
116114
dw $ - GDT64 - 1 ; Limit.
117115
dq GDT64 ; Base.
118116

@@ -130,12 +128,12 @@ long_mode:
130128

131129
;; set up new stack for 64-bit
132130
push rsp
133-
mov rsp, STACK_LOCATION
134-
mov rbp, rsp
131+
mov rsp, STACK_LOCATION
132+
mov rbp, rsp
135133

136134
;; geronimo!
137-
mov rdi, rax
138-
mov rsi, rbx
135+
mov edi, DWORD[__multiboot_magic]
136+
mov esi, DWORD[__multiboot_addr]
139137
call kernel_start
140138
pop rsp
141139
ret

0 commit comments

Comments
 (0)