Skip to content

Commit

Permalink
updating idt_load.asm
Browse files Browse the repository at this point in the history
  • Loading branch information
baponkar committed Dec 15, 2024
1 parent 90ba3a1 commit 5ea07cf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 96 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ $(BUILD_DIR)/kernel.o: $(SRC_DIR)/kernel/kernel.c
$(GCC) $(GCC_FLAG) -c $(SRC_DIR)/x86_64/idt.c -o $(BUILD_DIR)/idt.o
$(NASM) $(NASM_FLAG) $(SRC_DIR)/x86_64/idt_load.asm -o $(BUILD_DIR)/idt_load.o
$(NASM) $(NASM_FLAG) $(SRC_DIR)/x86_64/idt_load.asm -o $(BUILD_DIR)/idt_load.o
$(NASM) $(NASM_FLAG) $(SRC_DIR)/x86_64/store_and_restore_registers.asm -o $(BUILD_DIR)/store_and_restore_registers.o

$(GCC) $(GCC_FLAG) -c $(SRC_DIR)/x86_64/pit_timer.c -o $(BUILD_DIR)/pit_timer.o

Expand Down Expand Up @@ -90,7 +89,6 @@ $(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.o \
$(BUILD_DIR)/gdt_load.o \
$(BUILD_DIR)/idt.o \
$(BUILD_DIR)/idt_load.o \
$(BUILD_DIR)/store_and_restore_registers.o \
$(BUILD_DIR)/pit_timer.o \
$(BUILD_DIR)/keyboard.o \
$(BUILD_DIR)/speaker.o \
Expand All @@ -116,7 +114,6 @@ $(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.o \
$(BUILD_DIR)/gdt_load.o \
$(BUILD_DIR)/idt.o \
$(BUILD_DIR)/idt_load.o \
$(BUILD_DIR)/store_and_restore_registers.o \
$(BUILD_DIR)/pit_timer.o \
$(BUILD_DIR)/keyboard.o \
$(BUILD_DIR)/speaker.o \
Expand Down
Binary file modified iso_root/boot/kernel.bin
Binary file not shown.
10 changes: 5 additions & 5 deletions src/kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ void kmain(void){
// check_gdt();

init_idt();
test_interrupt();
// test_interrupt();

// initialise_paging();
initialise_paging();

// init_timer();
// initKeyboard();
init_timer();
initKeyboard();



// Test paging
// test_paging();
test_paging();

hcf();
}
Expand Down
79 changes: 66 additions & 13 deletions src/x86_64/idt_load.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,70 @@
;


[extern save_registers] ; defined in store_and_restore_registers.asm
[extern restore_registers] ; defined in store_and_restore_registers.asm
[extern isr_handler] ; defined in idt.c
[extern irq_handler] ; defined in idt.c



;
; These macros will store the current registers into stack and restore from stack
; The order is follow by registers_t structure defined in util.h
;

; Save all segment and general purpose registers
%macro SAVE_REGISTERS 0
push rax
push rbx
push rcx
push rdx
push rbp
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push gs
push fs
mov ax, es
push rax

mov ax, ds
push rax
%endmacro


; Restore all segment and general purpose registers
%macro RESTORE_REGISTERS 0
pop rax
mov ds, ax

pop rax
mov es, ax
pop fs
pop gs
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rbp
pop rdx
pop rcx
pop rbx
pop rax
%endmacro


section .text
[global idt_flush]
idt_flush:
Expand All @@ -37,7 +95,7 @@ idt_flush:


isr_common_stub:
call save_registers
SAVE_REGISTERS

mov eax, 0x10 ; Load the kernel data segment descriptor
mov ds, eax
Expand All @@ -50,8 +108,7 @@ isr_common_stub:
call isr_handler
add rsp, 16
call restore_registers
sti
RESTORE_REGISTERS
iretq ; Return from Interrupt


Expand Down Expand Up @@ -97,16 +154,15 @@ ISR_NOERRCODE 177 ; System Call
%macro IRQ 2
[global irq%1]
irq%1:
push 0 ; Push a dummy error code
mov rax, %2
push rax ; Push irq code
push 0 ; Push a dummy error code
push %2 ; Push irq code
jmp irq_common_stub
%endmacro


; This is a stub that we have created for IRQ based ISRs. This calls
irq_common_stub:
call save_registers
SAVE_REGISTERS

mov ax, 0x10 ; Load the Kernel Data Segment descriptor!
mov ds, ax
Expand All @@ -119,8 +175,7 @@ irq_common_stub:
call irq_handler

add rsp, 16 ; Clean up pushed error code and IRQ number
call restore_registers
sti
RESTORE_REGISTERS
iretq ; Return from Interrupt

IRQ 0, 32
Expand All @@ -143,5 +198,3 @@ IRQ 15, 47





75 changes: 0 additions & 75 deletions src/x86_64/store_and_restore_registers.asm

This file was deleted.

0 comments on commit 5ea07cf

Please sign in to comment.