I often came here writing a long paragraph of an issue I can't fix after much googling. But then end up not submitting my post because somehow I found the answer. This time I need you. OS-Dever Assemble! (please).
I am currently reading two related tutorial on the same subject : Kernel Development. More specifically GDT, IDT, ISR, IRQ, PIT and user space. (I didn't need them before because I was working on VESA , mouse and keyboard, and GUI Programming. The tutorials in question are Bran's kernel development and James Molloy's kernel development tutorials (the latter is based on the former). In both tutorials they reload a GDT (even thought GRUB has loaded one before and entered protected mode) that they can "track"/point to. For this part I used Bran's way (which is not always the case. I usually take the most readable of the two). Don't want to be rude but I'm gonna post lots of code:
so my kernel entry point assembly file (the one that is linked with the kernel main file and where I jump to after I entered protected mode) looks like this:
Code: Select all
[BITS 32]
[GLOBAL _start]
_start:
[EXTERN kernelmain]
CALL kernelmain
JMP $
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
JMP 0x08:flush2
flush2:
RET
Code: Select all
#include "gdt.h"
struct gdt_entry gdt[3];
struct gdt_ptr gp;
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
{
gdt[num].base_low = (base & 0xFFFF);
gdt[num].base_middle = (base >> 16) & 0xFF;
gdt[num].base_high = (base >> 24) & 0xFF;
gdt[num].limit_low = (limit & 0xFFFF);
gdt[num].granularity = ((limit >> 16) & 0x0F);
gdt[num].granularity != (gran & 0xF0);
gdt[num].access = access;
}
void gdt_install()
{
gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
gp.base = (unsigned int)&gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_flush();
}
I need help please!