Code: Select all
struct regs {
unsigned int gs, fs, es, ds;
unsigned int edi, esi, edp, esp, ebx, edx, ecx, eax;
unsigned int int_no, err_code;
unsigned int eip, cs, eflags, usersp, ss;
};
Error: 13
Error code: 0
CS: 8
DS: 1048592
FS: 1048592
GS: 1048592
SS: 0
EAX: 13
EBX: 65536
ECX: 4
EDI: 0
EDP: 0
EDX: 981
EFlags: 2162710
EIP: 1049116
ES: 65552
ESI: 0
ESP: 1079372
User SP: 32
Code: Select all
.code32
.intel_syntax noprefix
.extern test_print
# This wil set up a segment register.
.global gdt_flush
.extern gp
gdt_flush:
lgdt [gp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
call test_print
ret
.global idt_load
.extern idtp
idt_load:
lidt [idtp]
call test_print
ret
.global isr0
...
.global isr31
isr0:
cli
push 0x0
push 0x0
jmp isr_common_stub
...
isr31:
cli
push 0x0
push 0x1F
jmp isr_common_stub
.extern fault_handler
isr_common_stub:
xchg bx, bx
pusha
push ds
push es
push fs
push gs
xchg bx, bx
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
xchg bx, bx
lea eax, fault_handler
xchg bx, bx
call eax
xchg bx, bx
pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
iret
.global irq0
...
.global irq15
irq0:
cli
push 0x0
push 0x20
jmp irq_common_stub
...
irq15:
cli
push 0x0
push 0x30
jmp irq_common_stub
.extern irq_handler
irq_common_stub:
xchg bx, bx
pusha
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
xchg bx, bx
lea eax, irq_handler
call eax
xchg bx, bx
pop eax
pop gs
pop fs
pop es
pop ds
popa
iret
And just for completion the C functions called:
Code: Select all
void irq_handler(struct Functions::regs* r) {
Terminal::print("function: ");
Terminal::println(Functions::intToChar(r->int_no));
void (*handler) (struct Functions::regs*);
handler = (void (*)(Functions::regs*)) IRQ::irqRoutines[r->int_no - 32];
if(handler){
handler(r);
}
if (r->int_no >= 40){
IO::outb(0xA0, 0x20);
}
IO::outb(0x20, 0x20);
}
void fault_handler(struct Functions::regs* r) {
Terminal::print("Error: ");
Terminal::println(Functions::intToChar(r->int_no));
... Just printing registers
Terminal::print("User SP: ");
Terminal::println(Functions::intToChar(r->usersp));
if(r->int_no < 32){
Terminal::println(exceptionMessages[r->int_no]);
Terminal::println("Exception pausing");
for(;;);
}
}
Please say if you need more information, I completed the set up of the bare bones tutorial from the wiki before trying to use this tutorial on osdever.net to enable GDT, etc