Invalid opcode
Posted: Fri Jun 29, 2007 11:06 pm
I keep getting this exception and i can't see why. cr0 and eflags contain the values i expect them to.
Code: Select all
int x_pos;
int y_pos;
Code: Select all
int x_pos = 0;
int y_pos = 0;
Code: Select all
_loader:
mov $(stack + STACKSIZE), %esp # set up the stack
push %esp
mov %esp, %ebp
push %eax # Multiboot magic number
push %ebx # Multiboot data structure
call _main # call kernel proper
nop
hlt
Code: Select all
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
void puts(char *message, unsigned int x, unsigned int y, unsigned char color)
{
unsigned int i;
unsigned short *vmem = (unsigned short*)0xB8000;
for(i = 0; message[i] != 0; ++i)
{
vmem[x + (y * VGA_WIDTH) + i] = (color << 8) | message[i];
}
return;
}
void _main(void* mbd,unsigned int magic)
{
unsigned short *vmem = (unsigned short*)0xB8000;
vmem[0] = (1 << 8) | 'a';
gdt_install();
idt_install();
//text_color(WHITE,BLACK);
clrscr();
puts("Hello World", 0, 0, 0x12);
}
Code: Select all
#ifndef _PYROS_GDT
#define _PYROS_GDT
void gdt_flush();
void gdt_set_gate(int num,unsigned long base, unsigned long limit, unsigned char access, unsigned char gran);
void gdt_install();
#endif
Code: Select all
/// Global Descriptor Table Utility Functions
/// gdt.c
///
struct gdt_entry gdt[3];
struct gdt_ptr gp;
void gdt_flush()
{
asm("lgdt %0":"=g"(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();
}