Feat: Keyboard strokes working and in buffer
This commit is contained in:
+8
-31
@@ -1,6 +1,10 @@
|
||||
; File: elevator.asm
|
||||
; Stage 2 Bootloader - No size limit!
|
||||
; Job: Load kernel, set up GDT, switch to 64-bit mode, jump to kernel
|
||||
%ifndef KERNEL_SECTORS
|
||||
%define KERNEL_SECTORS 10 ; fallback default if build.sh doesn't override it
|
||||
%endif
|
||||
|
||||
[org 0x7e00]
|
||||
[bits 16]
|
||||
|
||||
@@ -104,7 +108,7 @@ load_kernel:
|
||||
|
||||
; Set up DAP (Disk Address Packet)
|
||||
mov word [dap_size], 0x10
|
||||
mov word [dap_sectors], 10
|
||||
mov word [dap_sectors], KERNEL_SECTORS
|
||||
mov word [dap_offset], 0x0000
|
||||
mov word [dap_segment], 0x1000
|
||||
mov dword [dap_lba_low], 6 ; LBA 6 = bytes 3072+ (sector 7 in CHS)
|
||||
@@ -136,7 +140,7 @@ load_kernel:
|
||||
|
||||
; Read using CHS
|
||||
mov ah, 0x02 ; Read function
|
||||
mov al, 10 ; Number of sectors
|
||||
mov al, KERNEL_SECTORS ; Number of sectors
|
||||
mov ch, 0 ; Cylinder 0
|
||||
mov cl, 7 ; Sector 7
|
||||
mov dh, 0 ; Head 0
|
||||
@@ -490,7 +494,6 @@ pm_msg: db '[PM32] Setting up Long Mode...', 0
|
||||
; 64-BIT LONG MODE
|
||||
; ============================================================
|
||||
[bits 64]
|
||||
[extern __keyboard_buffer_push] ; External function to push key into keyboard buffer
|
||||
long_mode:
|
||||
; Set up segments
|
||||
mov ax, 0x20
|
||||
@@ -518,8 +521,6 @@ long_mode:
|
||||
mov rsi, before_kernel_msg
|
||||
call print_64
|
||||
|
||||
sti ; Enable interrupts before jumping to kernel
|
||||
|
||||
; JUMP TO KERNEL!
|
||||
call KERNEL_OFFSET
|
||||
|
||||
@@ -624,32 +625,6 @@ setup_pic:
|
||||
|
||||
ret
|
||||
|
||||
; keyboard handler - Catch PIC interrupt
|
||||
keyboard_handler:
|
||||
push rax
|
||||
push rdx
|
||||
push rdi
|
||||
push r8
|
||||
|
||||
mov dx, 0x60
|
||||
in al, dx
|
||||
|
||||
; convert ASCII
|
||||
; assuming output on r8 (as an example)
|
||||
|
||||
; Acording to x86_64 SystemV
|
||||
mov rdi, r8
|
||||
call __keyboard_buffer_push
|
||||
|
||||
mov al, 0x20
|
||||
out 0x20, al
|
||||
|
||||
pop r8
|
||||
pop rdi
|
||||
pop rdx
|
||||
pop rax
|
||||
iretq
|
||||
|
||||
; Exception handler - shows what went wrong
|
||||
exception_handler:
|
||||
; Save registers
|
||||
@@ -707,6 +682,8 @@ exception_handler:
|
||||
|
||||
; Dummy interrupt handler for IRQs (not CPU exceptions)
|
||||
dummy_handler:
|
||||
mov al, 0x20
|
||||
out 0x20, al ; Send EOI to PIC
|
||||
iretq
|
||||
|
||||
idt_descriptor:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user