5 ; TODO if this were aligned to a page, the kernel
6 ; could reclaim the memory below it from 0x100000 to the start of this section
8 ; import some symbols from boot32.s
11 extern multiboot_infoptr
12 extern multiboot_magic
14 ; export so that boot32.s can find it
15 global kernel_bootstrap:function
17 ; export for the kernel
18 global _asm_physmap:data
20 ; I think from here the code expects to be using the high memory addresses
22 ; zero the other segment registers, we aren't going to use them
27 ; enable the floating point unit
34 ; Enable Streaming SIMD Extensions
43 ; TODO might as well just enable syscall/sysret here
47 size kernel_bootstrap (kernel_bootstrap.end - kernel_bootstrap)
55 type beginkernel function
57 ; initialize the stack pointer
58 ; hard coded kernel stack. could be freed later with
59 ; a dynamic stack, but 64 KB should be enough, and I'd
60 ; like to not page fault the kernel, especially for
62 ; TODO this stack pretty much leaks once tasking is set
63 ; up. the initial task should probably be freed, and
64 ; the 64 KB handed over to the pmm, or used for DMA or
67 add rsp, 65536 ; 64 KB, see kernel.c
69 ; sets up the 1 GB page maps for the first 512 GB
70 ; doing this early makes the pmm's job easier
73 ; reload GDT to high memory
74 mov rax, [ qword _asm_physmap ]
76 mov qword [GDT_load + 2], rax
79 ; SysV ABI args for kernel_main, which is written in C
80 mov edi, [multiboot_infoptr]
81 mov esi, [multiboot_magic]
84 size beginkernel beginkernel.end - beginkernel
87 ; rdi, rsi, rdx, rcx, r8, r9
88 ; scratch rax, rdi, rsi, rdx, rcx, r8, r9, r10, r11
90 ; now that we're in 64 bit mode, map in the physical memory to
92 ; set up 1GB PDPT for physical map at 0xFFFFC00000000000
94 ; 512 GB = 0x 80 0000 0000
96 ; rax = physical address and bits
97 mov eax, 0x183 ; Global, 1 GB PS, RW, and Present bits
98 ; rdi = pdpt slot address, i.e. pdpe address
100 ; rsi = (1<<30) i.e. 1 GB
101 mov rsi, 0x40000000 ; 1 GB
107 add rax, rsi ; next physical address
109 cmp ecx, 512 ; could not use ecx and just cmp rdi to 0x2B000
110 jl .nextgb ; I think I can just do a loop .nextgb and skip the inc and cmp
112 ; calculate the pml4t offset
113 mov rax, [qword _asm_physmap]
116 and edx, 0x1ff ; edx is now 384 if the physmap offset is still 0xffffc000000000
117 mov rax, 0x19003 ; physical address of pdpt + ReadWrite and Present
120 mov [rdi + rdx*8], rax
124 global allstop:function
132 size allstop, allstop.end - allstop
136 sti ; ensure that we can receive interrupts
144 dq 0xFFFFC00000000000