feat: irq interrupts; basic kb driver
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
bits 64
|
||||
|
||||
extern isr_handler_c
|
||||
extern irq_handler_c
|
||||
|
||||
section .text
|
||||
|
||||
@@ -22,6 +23,60 @@ isr%1:
|
||||
jmp isr_common_stub
|
||||
%endmacro
|
||||
|
||||
%macro PUSHALL 0
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rbp
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
push rcx
|
||||
push rbx
|
||||
push rax
|
||||
%endmacro
|
||||
|
||||
%macro POPALL 0
|
||||
pop rax
|
||||
pop rbx
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop rbp
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
%endmacro
|
||||
|
||||
%macro IRQ_HANDLER 2
|
||||
global %2
|
||||
%2:
|
||||
push 0 ; dummy err code
|
||||
push %1
|
||||
|
||||
PUSHALL
|
||||
|
||||
mov rdi, rsp
|
||||
cld
|
||||
call irq_handler_c
|
||||
|
||||
POPALL
|
||||
|
||||
add rsp, 16
|
||||
iretq
|
||||
%endmacro
|
||||
|
||||
ISR_NOERRCODE 0 ; Divide by zero
|
||||
ISR_NOERRCODE 1 ; Debug
|
||||
ISR_NOERRCODE 2 ; NMI
|
||||
@@ -56,40 +111,12 @@ ISR_ERRCODE 30 ; Security Exception
|
||||
ISR_NOERRCODE 31 ; Reserved
|
||||
|
||||
isr_common_stub:
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rdi
|
||||
push rsi
|
||||
push rbp
|
||||
push rdx
|
||||
push rcx
|
||||
push rbx
|
||||
push rax
|
||||
PUSHALL
|
||||
|
||||
mov rdi, rsp
|
||||
call isr_handler_c
|
||||
|
||||
pop rax
|
||||
pop rbx
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rbp
|
||||
pop rsi
|
||||
pop rdi
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
POPALL
|
||||
|
||||
add rsp, 16
|
||||
iretq
|
||||
@@ -97,4 +124,7 @@ isr_common_stub:
|
||||
global idt_load
|
||||
idt_load:
|
||||
lidt [rdi]
|
||||
ret
|
||||
ret
|
||||
|
||||
IRQ_HANDLER 32, irq0
|
||||
IRQ_HANDLER 33, irq1
|
||||
+3
-19
@@ -11,19 +11,13 @@
|
||||
|
||||
#include "gdt.h"
|
||||
#include "idt.h"
|
||||
#include "pic.h"
|
||||
#include "pmm.h"
|
||||
#include "vmm.h"
|
||||
|
||||
#include "../data/logo.h"
|
||||
#include "vmm.h"
|
||||
|
||||
|
||||
int rectest(int a) {
|
||||
volatile int b = a + 1;
|
||||
kprintf("%d", b);
|
||||
return rectest(b * 2);
|
||||
}
|
||||
|
||||
extern u64 _kernel_end;
|
||||
extern u8* bitmap;
|
||||
extern u64 bitmap_size_g;
|
||||
@@ -49,6 +43,7 @@ void kmain(Bootinfo* info) {
|
||||
|
||||
gdt_init();
|
||||
idt_init();
|
||||
pic_remap();
|
||||
|
||||
SG_Point logo_point = {0, 10};
|
||||
sg_put_img(&sg_ctx, &logo_point, &logo_img);
|
||||
@@ -68,18 +63,7 @@ void kmain(Bootinfo* info) {
|
||||
vmm_init(info);
|
||||
|
||||
kprintf("\nIM ALIVE :D");
|
||||
|
||||
// kprintf("\nSetting up guard page test");
|
||||
// u64* new_stack_phys = pmm_alloc_page();
|
||||
// u64 stack_top = 0x40000000;
|
||||
// vmm_map_page(pml4_kernel, (u64)new_stack_phys, stack_top, PTE_PRESENT | PTE_RW);
|
||||
|
||||
// __asm__ volatile (
|
||||
// "mov %0, %%rsp \n"
|
||||
// :: "r"(stack_top + 4096)
|
||||
// );
|
||||
|
||||
// rectest(0);
|
||||
__asm__ volatile ("sti");
|
||||
|
||||
while (1) { __asm__("hlt"); }
|
||||
}
|
||||
@@ -15,6 +15,7 @@ extern void isr16(); extern void isr17(); extern void isr18(); extern void isr19
|
||||
extern void isr20(); extern void isr21(); extern void isr22(); extern void isr23();
|
||||
extern void isr24(); extern void isr25(); extern void isr26(); extern void isr27();
|
||||
extern void isr28(); extern void isr29(); extern void isr30(); extern void isr31();
|
||||
extern void irq0(void); extern void irq1(void);
|
||||
|
||||
extern void idt_load(u64); // asm: lidt [rdi] / ret
|
||||
|
||||
@@ -74,5 +75,8 @@ void idt_init() {
|
||||
idt[13].ist = 1;
|
||||
idt[14].ist = 1;
|
||||
|
||||
idt_set_gate(32, (u64)irq0, selector, flags);
|
||||
idt_set_gate(33, (u64)irq1, selector, flags);
|
||||
|
||||
__asm__ volatile ("lidt %0" : : "m"(idt_ptr));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Copyright (c) 2025 0xKarinyash
|
||||
|
||||
#include "io.h"
|
||||
#include "panic.h"
|
||||
#include "keyboard.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
void isr_handler_c(Registers *regs) {
|
||||
panic_exception(regs);
|
||||
}
|
||||
|
||||
void irq_handler_c(Registers *regs) {
|
||||
switch (regs->int_no) {
|
||||
case 32: return outb(MASTER_COMMAND, 0x20);
|
||||
case 33: return kb_handler(regs);
|
||||
default: outb(SLAVE_COMMAND, 0x20); break;
|
||||
}
|
||||
|
||||
outb(MASTER_COMMAND, 0x20);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "keyboard.h"
|
||||
#include "console.h"
|
||||
#include "io.h"
|
||||
#include "types.h"
|
||||
|
||||
void kb_handler(Registers *regs) {
|
||||
u8 scancode = inb(0x60);
|
||||
outb(MASTER_COMMAND, 0x20);
|
||||
kprintf("Key: %x\n", scancode);
|
||||
}
|
||||
@@ -47,7 +47,9 @@ const char* fun_messages[] = {
|
||||
"Pro tip: dont crash",
|
||||
"Stop ricing the kernel you loonixtard, TermOS is NOT Loonix",
|
||||
"Attaboy, Jack. He's good. Really good.",
|
||||
""
|
||||
"Zhenih priehal",
|
||||
"YOUR PC WAS BLOCKED BY FBI FOR WATCHING PORNOGRAPHY SEND 20 US DOLLARS",
|
||||
"fuck off"
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user