File tree Expand file tree Collapse file tree 2 files changed +35
-30
lines changed
Expand file tree Collapse file tree 2 files changed +35
-30
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ org 0x1000
4040; Real mode
4141BITS 16
4242startup:
43+ ; No interrupts & clear segments
44+ cli
45+ xor ax , ax
46+ mov ds , ax
47+ mov es , ax
48+ mov ss , ax
49+
4350 ; Load the GDT
4451 lgdt [ gdtPointer ]
4552
@@ -68,20 +75,15 @@ protectedStart:
6875 lock bts dword [ interlock ], 0
6976 jc acquireLock
7077
71- ; Enable PAE
78+ ; Enable PAE and PGE
7279 mov eax , cr4
73- or eax , 1 << 5
80+ or eax , ( 1 << 5 ) | ( 1 << 7 )
7481 mov cr4 , eax
7582
7683 ; Set page directory
7784 mov eax , [ 0x500 ]
7885 mov cr3 , eax
7986
80- ; Enable PGE
81- mov eax , cr4
82- or eax , 1 << 7
83- mov cr4 , eax
84-
8587 ; Set up EFER MSR to enable long mode (EFER.LME)
8688 mov ecx , 0xC0000080
8789 rdmsr
@@ -106,17 +108,20 @@ protectedStart:
106108; Long mode
107109[BITS 64]
108110longStart:
109- ; Set data segments
110- mov bx , 0x20
111- mov ds , bx
112- mov ss , bx
113-
114111 ; 32-bit code provides AP index in EAX
115112 ; From the stack array, take the entry at offset multiplied by 8
116113 shl rax , 3
117- mov rsp , [ 0x518 + rax ]
114+ mov rsp , [ 0x518 + rax ]
118115 mov rbp , rsp
119116
117+ ; Set data segments
118+ mov bx , 0x20
119+ mov ds , bx
120+ mov es , bx
121+ mov fs , bx
122+ mov gs , bx
123+ mov ss , bx
124+
120125 ; Jump into kernel code
121126 mov rax , [ 0x508 ]
122127 jmp rax
@@ -125,12 +130,6 @@ longStart:
125130interlock:
126131 dd 0
127132
128-
129- ; Pointer to the GDT
130- gdtPointer:
131- dw 39
132- dd gdt
133-
134133; Basic setup GDT
135134gdt:
136135 ; null descriptor
@@ -151,14 +150,21 @@ gdt:
151150 dw 0x9200
152151 dw 0x00CF
153152
154- ; code descriptor ( 64-bit)
155- dw 0xFFFF
156- dw 0x0000
157- dw 0x9A00
158- dw 0x00A0
153+ ; 64-bit code descriptor
154+ dw 0x0000
155+ dw 0x0000
156+ dw 0x9A00
157+ dw 0x0020
159158
160- ; data descriptor ( 64-bit)
161- dw 0xFFFF
159+ ; 64-bit data descriptor
160+ dw 0x0000
162161 dw 0x0000
163162 dw 0x9200
164- dw 0x00A0
163+ dw 0x0000
164+
165+ gdtEnd:
166+
167+ align 4
168+ gdtPointer:
169+ dw gdtEnd - gdt - 1
170+ dd gdt
Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ void smpInitialize(g_physical_address initialPageDirectoryPhysical)
3838 for (g_address phys = 0 ; phys < G_SMP_STARTUP_AREA_END; phys += G_PAGE_SIZE)
3939 {
4040 pagingMapPage (phys, phys, G_PAGE_TABLE_KERNEL_DEFAULT, G_PAGE_KERNEL_DEFAULT);
41- logInfo (" Identitiy map %x to %x: %x" , phys, phys, pagingVirtualToPhysical (phys));
4241 }
4342
4443 // Map it so we can write it here
@@ -62,7 +61,7 @@ void smpInitialize(g_physical_address initialPageDirectoryPhysical)
6261
6362 // Create enough stacks for all APs
6463 auto stackArray = (g_physical_address*) (mappedLower + G_SMP_STARTUP_AREA_AP_STACK_ARRAY);
65- for (uint32_t i = 0 ; i < processorGetNumberOfProcessors (); i++)
64+ for (uint32_t i = 0 ; i < processorGetNumberOfProcessors () - 1 ; i++)
6665 {
6766 g_physical_address stackPhysical = memoryPhysicalAllocate ();
6867 if (stackPhysical == 0 )
@@ -72,7 +71,7 @@ void smpInitialize(g_physical_address initialPageDirectoryPhysical)
7271 }
7372
7473 g_virtual_address stackVirtual = addressRangePoolAllocate (memoryVirtualRangePool, 1 );
75- if (stackPhysical == 0 )
74+ if (stackVirtual == 0 )
7675 {
7776 logInfo (" %*%! could not allocate virtual range for AP stack" , 0x0C , " smp" );
7877 return ;
You can’t perform that action at this time.
0 commit comments