calcite/src/kernel/paging.asm

49 lines
1.3 KiB
NASM

; Calcite, src/kernel/paging.asm
; Copyright 2025 Benji Dial
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
; for more details.
;
; You should have received a copy of the GNU General Public License along
; with this program. If not, see <https://www.gnu.org/licenses/>.
bits 64
default rel
;both defined in paging.c
extern kernel_p4_physical_address
extern init_stack
init_stack_length equ 16384
section .text
;referenced in paging.c
extern invlpg
invlpg:
invlpg byte [rdi]
ret
extern switch_to_kernel_page_tables
switch_to_kernel_page_tables:
;switch the page table
mov rax, qword [kernel_p4_physical_address]
mov cr3, rax
;set the stack
mov rsp, init_stack + init_stack_length
;push 0 before jumping to continuation so that if the continuation
;does return (which it shouldn't), it returns to null instead of
;popping garbage and returning there
push qword 0
jmp rdi