Feat: Keyboard strokes working and in buffer

This commit is contained in:
AfonsoCMSousa
2026-08-05 02:23:54 +01:00
parent fb27ad1e0c
commit ba16f38c79
6 changed files with 161 additions and 56 deletions
+65
View File
@@ -2,14 +2,79 @@
; Assembly entry point for the kernel
[bits 64]
[extern kmain] ; kmain is defined in kernel.c
[extern __keyboard_handle_scancode]
[extern __bss_start]
[extern __bss_end]
global _start ; Make _start visible to linker
_start:
call fill_idt
; IMPORTANT
; Zero out the .bss section
cld
mov rdi, __bss_start
mov rcx, __bss_end
sub rcx, rdi
xor rax, rax
rep stosb
; We're already in 64-bit mode with stack set up
; Just call the C kernel
sti
call kmain
; If kmain returns, hang
jmp $
hlt
; Set up a minimal IDT
fill_idt:
; Fill IDT with different handlers for different exceptions
mov rdi, 0x4210 ; IDT location
mov rax, keyboard_handler
mov word [rdi], ax ; Offset low
mov word [rdi + 2], 0x18 ; Code segment
mov byte [rdi + 4], 0 ; IST
mov byte [rdi + 5], 0x8E ; Present, interrupt gate
shr rax, 16
mov word [rdi + 6], ax ; Offset middle
shr rax, 16
mov dword [rdi + 8], eax ; Offset high
mov dword [rdi + 12], 0 ; Reserved
ret
; keyboard handler - Catch PIC interrupt
keyboard_handler:
push rax
push rdx
push rdi
push rcx
push rsi
push r8
push r9
push r10
push r11
mov dx, 0x60
in al, dx
mov dil, al
call __keyboard_handle_scancode
mov al, 0x20
out 0x20, al
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rcx
pop rdi
pop rdx
pop rax
iretq