Skip to content

Commit 76e79fc

Browse files
committed
Kernel: Link SMP trampoline as normal ELF object
1 parent 89e09f1 commit 76e79fc

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

Kernel/bintoelf.sh

-3
This file was deleted.

Kernel/linkscript-x86_64.ld

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ SECTIONS
4040
{
4141
_data = .;
4242
*(.data)
43-
_trampoline = .;
44-
*(.trampoline)
45-
_trampoline_end = .;
4643
. = ALIGN(4096);
4744
}
4845

Kernel/meson.build

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ asmg = generator(nasm,
1212
arguments : [
1313
'-f', 'elf64',
1414
'-g', '-F', 'dwarf', '-w+gnu-elf-extensions',
15+
'-i' + meson.current_source_dir() + '/src/Arch/x86_64/',
1516
'@INPUT@',
1617
'-o', '@OUTPUT@'])
1718

18-
bintoelf = find_program('bintoelf.sh', './bintoelf.sh')
19-
bing = generator(bintoelf,
20-
output : '@[email protected]',
21-
arguments : ['@INPUT@','@OUTPUT@', meson.current_source_dir() + '/src/Arch/x86_64/', '@BASENAME@'])
22-
2319
kernel_c_args = [
2420
'-g',
2521
'-Wno-write-strings', '-Wno-unused-parameter', '-Wno-sign-compare',
@@ -145,9 +141,6 @@ kernel_asm_files_x86_64 = [
145141
'src/Arch/x86_64/Memcpy.asm',
146142
'src/Arch/x86_64/SignalTrampoline.asm',
147143
'src/Arch/x86_64/TSS.asm',
148-
]
149-
150-
kernel_asm_bin_files_x86_64 = [
151144
'src/Arch/x86_64/SMPTrampoline.asm',
152145
]
153146

@@ -160,7 +153,7 @@ kernel_link_args = [
160153
kernel_link_args += kernel_c_args
161154

162155
kernel = executable('kernel.sys',
163-
[asmg.process(kernel_asm_files_x86_64), bing.process(kernel_asm_bin_files_x86_64), kernel_cpp_files, kernel_cpp_files_x86_64, lai.get_variable('sources')],
156+
[asmg.process(kernel_asm_files_x86_64), kernel_cpp_files, kernel_cpp_files_x86_64, lai.get_variable('sources')],
164157
include_directories : [kernel_include_dirs],
165158
c_args : kernel_c_args, cpp_args : [kernel_c_args, kernel_cpp_args], link_args: kernel_link_args, link_depends: 'linkscript-x86_64.ld',
166159
install_dir : 'lemon/', install : true)

Kernel/src/Arch/x86_64/SMP.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static inline void wait(uint64_t ms) {
1717
Timer::Wait(ms);
1818
}
1919

20-
extern void* _binary_SMPTrampoline_bin_start;
21-
extern void* _binary_SMPTrampoline_bin_size;
20+
extern void* _smp_trampoline_entry16;
21+
extern void* _smp_trampoline_end;
2222

2323
volatile uint16_t* smpMagic = (uint16_t*)SMP_TRAMPOLINE_DATA_START_FLAG;
2424
volatile uint16_t* smpID = (uint16_t*)SMP_TRAMPOLINE_CPU_ID;
@@ -134,7 +134,7 @@ void Initialize() {
134134

135135
processorCount = ACPI::processorCount;
136136

137-
memcpy((void*)SMP_TRAMPOLINE_ENTRY, &_binary_SMPTrampoline_bin_start, ((uint64_t)&_binary_SMPTrampoline_bin_size));
137+
memcpy((void*)SMP_TRAMPOLINE_ENTRY, &_smp_trampoline_entry16, ((uint64_t)&_smp_trampoline_end) - (uint64_t)(&_smp_trampoline_entry16));
138138

139139
for (int i = 0; i < processorCount; i++) {
140140
if (ACPI::processors[i] != 0) {

Kernel/src/Arch/x86_64/SMPTrampoline.asm

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
%include "smpdefines.inc"
2+
3+
SMP_TRAMPOLINE_ENTRY64 equ (_smp_trampoline_entry64 - _smp_trampoline_entry16 + SMP_TRAMPOLINE_ENTRY)
4+
5+
global _smp_trampoline_entry16
6+
global _smp_trampoline_end
7+
8+
section .data
9+
_smp_trampoline_entry16:
110
BITS 16
211

3-
%include "smpdefines.inc"
12+
; This will get moved to 0x2000 in physical RAM
413

514
cli
615
cld
@@ -26,13 +35,12 @@ mov cr0, eax
2635

2736
lgdt [SMP_TRAMPOLINE_GDT_PTR]
2837

29-
jmp 0x08:(smpentry64 + SMP_TRAMPOLINE_ENTRY)
38+
jmp 0x08:(SMP_TRAMPOLINE_ENTRY64)
3039

3140
hlt
3241

3342
BITS 64
34-
35-
smpentry64:
43+
_smp_trampoline_entry64:
3644
mov ax, 0x10
3745
mov ds, ax
3846
mov es, ax
@@ -58,4 +66,6 @@ smpentry64:
5866
call [SMP_TRAMPOLINE_ENTRY2]
5967

6068
cli
61-
hlt
69+
hlt
70+
71+
_smp_trampoline_end:

0 commit comments

Comments
 (0)