1 ; AcessOS Microkernel Version
6 KERNEL_BASE equ 0xC0000000
14 ; Multiboot macros to make a few lines later more readable
15 MULTIBOOT_PAGE_ALIGN equ 1<<0
16 MULTIBOOT_MEMORY_INFO equ 1<<1
17 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
18 MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
19 MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
21 ; This is the GRUB Multiboot header. A boot signature
22 dd MULTIBOOT_HEADER_MAGIC
23 dd MULTIBOOT_HEADER_FLAGS
25 dd mboot; - KERNEL_BASE ;Location of Multiboot Header
29 ; MULTIBOOT2_HEADER_MAGIC equ 0xE85250D6
30 ; MULTIBOOT2_HEADER_ARCH equ 0
31 ; MULTIBOOT2_HEADER_LENGTH equ (mboot2_end-mboot2)
32 ; MULTIBOOT2_CHECKSUM equ -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH + MULTIBOOT2_HEADER_LENGTH)
34 ; dd MULTIBOOT2_HEADER_MAGIC
35 ; dd MULTIBOOT2_HEADER_ARCH
36 ; dd MULTIBOOT2_HEADER_LENGTH
37 ; dd MULTIBOOT2_CHECKSUM
38 ; ; MBoot2 Address Header
41 ; dd mboot2 ; Location of Multiboot Header
42 ; dd __load_addr - KERNEL_BASE ; Kernel Load base
43 ; dd __bss_start - KERNEL_BASE ; Kernel Data End
44 ; dd gKernelEnd - KERNEL_BASE ; Kernel BSS End
45 ; ; MBoot2 Entry Point Tag
48 ; dd start - KERNEL_BASE
49 ; ; MBoot2 Module Alignment Tag
52 ; dd 0 ; Search me, seems it wants padding
62 ; Just show we're here
63 mov WORD [0xB8000], 0x0741 ; 'A'
66 mov esp, Kernel_Stack_Top
69 mov ecx, gaInitPageDir - KERNEL_BASE
72 or ecx, 0x80010000 ; PG and WP
75 mov WORD [0xB8002], 0x0763 ; 'c'
79 mov cx, 0x10 ; PL0 Data
85 mov WORD [0xB8004], 0x0765 ; 'e'
89 mov WORD [0xB8006], 0x0773 ; 's'
90 mov WORD [0xB8008], 0x0773 ; 's'
93 push ebx ; Multiboot Info
94 push eax ; Multiboot Magic Value
95 mov WORD [0xB800A], 0x0732 ; '2'
105 ; Multiprocessing AP Startup Code (Must be within 0 - 0x10FFF0)
109 [extern gpMP_LocalAPIC]
110 [extern giMP_TimerCount]
111 [extern gaAPIC_to_CPU]
113 [extern giNumInitingCPUs]
114 [extern MM_NewKStack]
115 [extern Proc_InitialiseSSE]
117 lGDTPtr: ; Local GDT Pointer
128 [extern Proc_Reschedule]
131 ;xchg bx, bx ; MAGIC BREAK!
135 lgdt [DWORD ds:lGDTPtr-KERNEL_BASE-0xFFFF0]
136 ; Enable PMode in CR0
141 jmp 08h:DWORD .ProtectedMode-KERNEL_BASE
144 ; Load segment registers
152 mov eax, gaInitPageDir - KERNEL_BASE
155 or eax, 0x80010000 ; PG and WP
157 ; Jump to higher half
158 lea eax, [.higherHalf]
161 ; Load True GDT & IDT
165 mov ebp, [gpMP_LocalAPIC]
166 mov ebx, [ebp+0x20] ; Read ID
168 ;xchg bx, bx ; MAGIC BREAK
169 ; BL is now local APIC ID
170 mov cl, BYTE [gaAPIC_to_CPU+ebx]
173 ; BL is now the CPU ID
174 mov dr1, ebx ; Save the CPU number to a debug register
176 mov BYTE [gaCPUs+ebx*8+1], 1
177 ; Decrement the remaining CPU count
178 dec DWORD [giNumInitingCPUs]
182 shl edx, 5+2 ; *32 *4
183 lea esp, [gInitAPStacks+edx]
188 lea ecx, [ebx*8+0x30]
191 ;xchg bx, bx ; MAGIC_BREAK
193 mov DWORD [ebp+0x0F0], 0x000001EF ; Spurious Interrupt Vector (0xEF)
194 mov ecx, DWORD [giMP_TimerCount]
195 mov DWORD [ebp+0x380], ecx ; Set Initial Count
196 mov DWORD [ebp+0x320], 0x000200EE ; Enable timer on IVT#0xEE
197 mov DWORD [ebp+0x330], 0x000100E0 ; ##Enable thermal sensor on IVT#0xE0
198 mov DWORD [ebp+0x340], 0x000100D0 ; ##Enable performance counters on IVT#0xD0
199 mov DWORD [ebp+0x350], 0x000100D1 ; ##Enable LINT0 on IVT#0xD1
200 mov DWORD [ebp+0x360], 0x000100D2 ; ##Enable LINT1 on IVT#0xD2
201 mov DWORD [ebp+0x370], 0x000100E1 ; ##Enable Error on IVT#0xE1
202 mov DWORD [ebp+0x0B0], 0 ; Send an EOI (just in case)
204 ; Initialise SSE support
205 call Proc_InitialiseSSE
207 ; CPU is now marked as initialised
221 ; int CallWithArgArray(void *Ptr, int NArgs, Uint *Args)
222 ; Call a function passing the array as arguments
223 [global CallWithArgArray]
227 mov ecx, [ebp+12] ; Get NArgs
231 mov eax, [edx+ecx*4-4]
243 GDT_SIZE equ (1+2*2+1+MAX_CPUS)*8
248 dd 0x00000000, 0x00000000 ; 00 NULL Entry
249 dd 0x0000FFFF, 0x00CF9A00 ; 08 PL0 Code
250 dd 0x0000FFFF, 0x00CF9200 ; 10 PL0 Data
251 dd 0x0000FFFF, 0x00CFFA00 ; 18 PL3 Code
252 dd 0x0000FFFF, 0x00CFF200 ; 20 PL3 Data
253 dd 26*4-1, 0x00408900 ; 28 Double Fault TSS
254 times MAX_CPUS dd 26*4-1, 0x00408900 ; 30+ TSSes
261 [global gaInitPageDir]
262 [global gaInitPageTable]
265 dd gaInitPageTable-KERNEL_BASE+3 ; 0x000 - Low kernel
266 times 0x300-0x000-1 dd 0
267 dd gaInitPageTable-KERNEL_BASE+3 ; 0xC00 - High kernel
268 times 0x3F0-0x300-1 dd 0
269 dd gaInitPageDir-KERNEL_BASE+3 ; 0xFC0 - Fractal
270 times 0x400-0x3F0-1 dd 0
278 [global Kernel_Stack_Top]
283 times 32*MAX_CPUS dd 0