When trying to setup a new GDT using C code following Bran's tuto
http://www.osdever.net/tutorials/view/b ... t-tutorial
I get a triple fault.
here is the code:
Code: Select all
#define GDTBASE 0x800
struct gdt_entry
{
unsigned short limit_low;
unsigned short base_low;
unsigned char base_middle;
unsigned char access;
unsigned char granularity;
unsigned char base_high;
} __attribute__((packed));
struct gdt_ptr
{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
struct gdt_entry gdt[3];
struct gdt_ptr gdtp;
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()
{
gdtp.limit = (sizeof(struct gdt_entry) * 3) - 1;
gdtp.base = GDTBASE ;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
memcpy((char *)gdtp.base, (char *)gdt, gdtp.limit);
load_gdtr();
}
Code: Select all
global _load_gdtr
extern _gdtp
_load_gdtr:
lgdt [_gdtp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:next
next:
ret
Code: Select all
00014963370i[BIOS ] Booting from 0000:7c00
00015845034i[FLOPPY] partial read() on floppy image returns 180/512
00015933925i[FLOPPY] read() on floppy image returns 0
.....................................................
00017711733i[FLOPPY] read() on floppy image returns 0
00017826504e[CPU0 ] load_seg_reg(SS): not writable data segment
00017826504e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00017826504e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00017826504i[CPU0 ] CPU is in protected mode (active)
00017826504i[CPU0 ] CS.mode = 32 bit
00017826504i[CPU0 ] SS.mode = 32 bit
00017826504i[CPU0 ] EFER = 0x00000000
00017826504i[CPU0 ] | EAX=00000010 EBX=00007d04 ECX=00000016 EDX=00000816
00017826504i[CPU0 ] | ESP=0008ffa4 EBP=0008ffd0 ESI=000e0000 EDI=0000ffac
00017826504i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00017826504i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00017826504i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00017826504i[CPU0 ] | DS:0010( 0002| 0| 0) ffffffff ffffffff 1 1
00017826504i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00017826504i[CPU0 ] | ES:0010( 0002| 0| 0) ffffffff ffffffff 1 1
00017826504i[CPU0 ] | FS:0010( 0002| 0| 0) ffffffff ffffffff 1 1
00017826504i[CPU0 ] | GS:0010( 0002| 0| 0) ffffffff ffffffff 1 1
00017826504i[CPU0 ] | EIP=0000101d (0000101d)
00017826504i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00017826504i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00017826504i[CPU0 ] 0x000000000000101d>> mov ss, ax : 8ED0
00017826504p[CPU0 ] >>PANIC<< exception(): 3rd (13) exception with no resolution
I've spent many hours trying to fix it, alas with no success.
Edit:
Unlike Bran, I'm not loading the kernel with GRUB, I'm using Blundell's bootsector.
Many thanks for your help