diff --git a/src/cpu.c b/src/cpu.c index 872b614..177c593 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -2821,6 +2821,20 @@ void cpu_exec(cpu *c, u8 opcode) { (c->ip)+=2; break; + case 0xcd: + u8 operand = cpu_fetch(c); + printf("Interrupt called with argument %d",operand); + interrupt(c,operand); + break; + + case 0xcc: + interrupt(c,3); + break; + + case 0xcf: + iret(c); + break; + default: break; /* nops and unused */ } /* setting the segment override to 0 after executing every instruction */ diff --git a/src/cpu.h b/src/cpu.h index f9ccb78..0eda0be 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -40,7 +40,7 @@ #include "jumps.h" #include "mul_div.h" #include "push_pop.h" - +#include "interrupts.h" /* cpu procs */ cpu* cpu_make(); void cpu_init(cpu* c); diff --git a/src/interrupts.c b/src/interrupts.c new file mode 100644 index 0000000..ad8559f --- /dev/null +++ b/src/interrupts.c @@ -0,0 +1,20 @@ +#include "interrupts.h" + +void interrupt(cpu* c, u8 interrupt_type){ + push16(c,c->flags); + resetTF(c); + resetIF(c); + push_r(c,c->cs); + push_r(c,c->ip); + u32 interrupt_pointer = interrupt_type*4; + c->ip = cpu_read_u16_at(c,interrupt_pointer); + c->cs = cpu_read_u16_at(c,interrupt_pointer+2); + return; +} + +void iret(cpu* c){ + c->ip = pop16(c); + c->cs = pop16(c); + c->flags = pop16(c); + return; +} \ No newline at end of file diff --git a/src/interrupts.h b/src/interrupts.h new file mode 100644 index 0000000..a16b523 --- /dev/null +++ b/src/interrupts.h @@ -0,0 +1,23 @@ + +#ifndef INT_H +#define INT_H +#include "push_pop.h" +#include "flagops.h" +#include "cpu.h" +// case 0x90 NOP No operation + +// case 0xcd INT interrupt +// case 0xce INTO interrupt on overflow +// case 0xcf IRET interrupt return + +// case 0xf4 HLT halt +// case 0xfa CLI clear if ---> Already implemented +// case 0xfb STI set if ---> Already implemented + +void interrupt(cpu* c,u8 interrupt_type); +void into(void); +void iret(cpu* c); +void halt(void); + + +#endif \ No newline at end of file