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
Code:
asm volatile ("int $0x3");
asm volatile ("int $0x4");
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:
#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 for printing decimal
Code:
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);
}
ISR Registers code
Code:
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);
The code that actually prints the interrupt number
Code:
void isr_handler(registers_t regs)
{
puts("Recieved interrupt: ");
puth(regs.int_num);
putch('\n');
}