Getting odd interrupt code from ISR
Posted: Mon Feb 20, 2023 3:48 pm
Hello, I have been following along Bran's Kernel development and James Molloy's OS development guide, nearly to a T, with my boot code being the only exception. I have successfully loaded the GDT and IDT, and created a few ISRs. Everything seems to work perfectly, up until I try to test it out. He writes in his kernel main
His output is 0x03, where the output I am getting is 0x102840. I have followed his code for printing decimal and hex, so it would seem to me that I would get the same output. Is what I am getting normal? Is it because I'm on QEMU and he is using BOCHS? Any insight would be greatly appreciated, thanks!
My kernel code
Code for printing decimal
ISR Registers code
The code that actually prints the interrupt number
Code: Select all
asm volatile ("int $0x3");
asm volatile ("int $0x4");
My kernel code
Code: Select all
#include "utils/system.h"
#include "utils/print.h"
#include "cpu/gdt.h"
#include "cpu/idt.h"
void kernel_main()
{
init_video();
init_gdt();
init_idt();
/* Test our interrupt handlers */
asm volatile ("int $0x3");
asm volatile ("int $0x4");
puts("Hello World");
for (;;);
}
Code: Select all
void putn(uint32_t n)
{
if (n == 0)
{
putch('0');
return;
}
int32_t acc = n;
char c[32];
int i = 0;
while (acc > 0)
{
c[i] = '0' + acc%10;
acc /= 10;
i++;
}
c[i] = 0;
char c2[32];
c2[i--] = 0;
int j = 0;
while(i >= 0)
{
c2[i--] = c[j++];
}
puts(c2);
}
Code: Select all
typedef struct
{
uint32_t ds;
uint32_t edi, esi, esp, ebx, edx, ecx, eax;
uint32_t int_num, err_code;
uint32_t eip, cs, eflags, useresp, ss;
} __attribute__((packed)) registers_t;
void isr_handler(registers_t regs);
Code: Select all
void isr_handler(registers_t regs)
{
puts("Recieved interrupt: ");
puth(regs.int_num);
putch('\n');
}