1 ; AcessOS Microkernel Version
6 KERNEL_BASE equ 0xC0000000
13 ; Multiboot macros to make a few lines later more readable
14 MULTIBOOT_PAGE_ALIGN equ 1<<0
15 MULTIBOOT_MEMORY_INFO equ 1<<1
16 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
17 MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
18 MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
20 ; This is the GRUB Multiboot header. A boot signature
21 dd MULTIBOOT_HEADER_MAGIC
22 dd MULTIBOOT_HEADER_FLAGS
24 dd mboot - KERNEL_BASE ;Location of Multiboot Header
28 ; MULTIBOOT2_HEADER_MAGIC equ 0xE85250D6
29 ; MULTIBOOT2_HEADER_ARCH equ 0
30 ; MULTIBOOT2_HEADER_LENGTH equ (mboot2_end-mboot2)
31 ; MULTIBOOT2_CHECKSUM equ -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_HEADER_ARCH + MULTIBOOT2_HEADER_LENGTH)
33 ; dd MULTIBOOT2_HEADER_MAGIC
34 ; dd MULTIBOOT2_HEADER_ARCH
35 ; dd MULTIBOOT2_HEADER_LENGTH
36 ; dd MULTIBOOT2_CHECKSUM
37 ; ; MBoot2 Address Header
40 ; dd mboot2 ; Location of Multiboot Header
41 ; dd __load_addr - KERNEL_BASE ; Kernel Load base
42 ; dd __bss_start - KERNEL_BASE ; Kernel Data End
43 ; dd gKernelEnd - KERNEL_BASE ; Kernel BSS End
44 ; ; MBoot2 Entry Point Tag
47 ; dd start - KERNEL_BASE
48 ; ; MBoot2 Module Alignment Tag
51 ; dd 0 ; Search me, seems it wants padding
63 mov esp, Kernel_Stack_Top
66 mov ecx, gaInitPageDir - KERNEL_BASE
70 or ecx, 0x80010000 ; PG and WP
73 lea ecx, [.higherHalf]
78 push ebx ; Multiboot Info
79 push eax ; Multiboot Magic Value
89 ; Multiprocessing AP Startup Code (Must be within 0x10FFF0)
95 [extern gpMP_LocalAPIC]
96 [extern giMP_TimerCount]
97 [extern gaAPIC_to_CPU]
99 [extern giNumInitingCPUs]
100 lGDTPtr: ; Local GDT Pointer
113 ;xchg bx, bx ; MAGIC BREAK!
116 lgdt [DWORD ds:lGDTPtr-KERNEL_BASE-0xFFFF0]
120 jmp 08h:DWORD .ProtectedMode-KERNEL_BASE
123 ; Load segment registers
131 mov eax, gaInitPageDir - KERNEL_BASE
134 or eax, 0x80010000 ; PG and WP
136 ; Jump to higher half
137 lea eax, [.higherHalf]
140 ; Load True GDT & IDT
144 mov eax, [gpMP_LocalAPIC]
145 mov ecx, [eax+0x20] ; Read ID
147 ;xchg bx, bx ; MAGIC BREAK
148 ; CL is now local APIC ID
149 mov cl, BYTE [gaAPIC_to_CPU+ecx]
150 ; CL is now the CPU ID
151 mov BYTE [gaCPUs+ecx*8+1], 1
152 ; Decrement the remaining CPU count
153 dec DWORD [giNumInitingCPUs]
158 ; Enable Local APIC Timer
159 mov ecx, [giMP_TimerCount]
160 mov [eax+0x380], ecx ; Set Initial Count
161 mov DWORD [eax+0x320], 0x000200EF ; Enable the timer on IVT#0xEF
163 ; CPU is now marked as initialised
165 ;xchg bx, bx ; MAGIC BREAK
176 ; int CallWithArgArray(void *Ptr, int NArgs, Uint *Args)
177 ; Call a function passing the array as arguments
178 [global CallWithArgArray]
182 mov ecx, [ebp+12] ; Get NArgs
186 mov eax, [edx+ecx*4-4]
197 [global gaInitPageDir]
198 [global gaInitPageTable]
201 dd gaInitPageTable-KERNEL_BASE+3 ; 0x00
202 times 1024-256-1 dd 0
203 dd gaInitPageTable-KERNEL_BASE+3 ; 0xC0
212 [global Kernel_Stack_Top]