general protection fault

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

general protection fault

Post by Pyrofan1 »

okay, here is the code that i'm sure is causing this

Code: Select all

.type irq0,@function
irq0:
push $0
push $0

pusha
mov %ds, %eax
pushl %eax
mov %es, %eax
pushl %eax
mov %fs, %eax
pushl %eax
mov %gs, %eax
pushl %eax

mov $0x10, %eax
mov %eax, %ds
mov %eax, %es
mov %eax, %fs
mov %eax, %gs

movl %cr0, %eax
pushl %eax

movl %esp, %eax
pushl %eax
cli
call timer_handler
sti

pop %eax
pop %eax

mov %eax, %cr0

pop %eax
mov %eax, %gs
pop %eax
mov %eax, %fs
pop %eax
mov %eax, %es

pop %eax
mov %eax, %ds

popa
iret

.type irq1,@function
irq1:
push $0
push $1

pusha
mov %ds, %eax
pushl %eax
mov %es, %eax
pushl %eax
mov %fs, %eax
pushl %eax
mov %gs, %eax
pushl %eax

mov $0x10, %eax
mov %eax, %ds
mov %eax, %es
mov %eax, %fs
mov %eax, %gs

movl %cr0, %eax
pushl %eax

movl %esp, %eax
pushl %eax
cli
call keyboard_handler
sti

pop %eax
pop %eax

mov %eax, %cr0

pop %eax
mov %eax, %gs
pop %eax
mov %eax, %fs
pop %eax
mov %eax, %es

pop %eax
mov %eax, %ds

popa
iret

Code: Select all

.type isr48,@function
isr48:
push $0
push $48

pusha
mov %ds, %eax
pushl %eax
mov %es, %eax
pushl %eax
mov %fs, %eax
pushl %eax
mov %gs, %eax
pushl %eax

mov $0x10, %eax
mov %eax, %ds
mov %eax, %es
mov %eax, %fs
mov %eax, %gs

movl %cr0, %eax
pushl %eax

movl %esp, %eax
pushl %eax
cli
call syscall
sti

pop %eax
pop %eax

mov %eax, %cr0

pop %eax
mov %eax, %gs
pop %eax
mov %eax, %fs
pop %eax
mov %eax, %es
pop %eax
mov %eax, %ds

popa
iret

Code: Select all

void syscall(struct regs *r)
{
	unsigned char last_key;
	switch(r->eax)
	{
		case 0:
		Printf((char *)r->ebx);
		break;

		case 1:
		r->ebx=(unsigned int)last_key;
		break;

		default:
		break;
	}
}

Code: Select all

void keyboard_handler(struct regs *r)
{
	unsigned char scancode;
	unsigned char last_key;
	unsigned char diff='A'-'a';

	scancode=inportb(0x06);
	if(scancode&0x80)
	{
		if(last_key==ALT)
		{
			alt=0;
		}
		else
		if(last_key==SHIFT)
		{
			shift=0;
		}
		else
		if(last_key==CTRL)
		{
			ctrl=0;
		}
	}
	else
	{
		switch(kb_setup)
		{
			case 0:
			last_key=kb_us[scancode];
			break;

			case 1:
			last_key=kb_dvorak[scancode];
			break;

			default:
			break;
		}

		switch(last_key)
		{
			case CAPS:
			if(caps)
			{
				caps=0;
				while((inportb(0x64)&2)!=0);
				outportb(0x60,0xED);
				outportb(0x60,0x00);
			}
			else
			{
				caps=1;
				while((inportb(0x64)&2)!=0);
				outportb(0x60,0xED);
				outportb(0x60,0x03);
			}
			break;

			case ALT:
			alt=1;
			break;
	
			case SHIFT:
			shift=1;
			break;

			case CTRL:
			ctrl=1;
			break;

			default:
			if(caps || shift)
			{
				if(last_key>='a' && last_key<='z')
				{
					if(caps && shift){}
					else
					{
						last_key+=diff;
					}
				}
				else
				if(!caps && shift)
				{
					switch(last_key)
					{
						case '[':
						last_key='{';
						break;

						case '7':
						last_key='&';
						break;

						case '5':
						last_key='%';
						break;

						case '3':
						last_key='#';
						break;

						case '1':
						last_key='!';
						break;

						case '9':
						last_key='(';
						break;

						case '0':
						last_key=')';
						break;

						case '2':
						last_key='@';
						break;

						case '4':
						last_key='$';
						break;

						case '6':
						last_key='^';
						break;
						
						case '8':
						last_key='*';
						break;

						case ']':
						last_key='}';
						break;

						case '\'':
						last_key='"';
						break;

						case '=':
						last_key='+';
						break;

						case '\\':
						last_key='|';
						break;

						case '-':
						last_key='_';
						break;

						case '/':
						last_key='?';
						break;

						case ',':
						last_key='<';
						break;
	
						case '.':
						last_key='>';
						break;

						default:
						break;
					}
				}
			}
		}
	}

	if(last_key<127)
	{
		Putch(last_key);
	}
	outportb(0x20, 0x20);
}

Code: Select all

void timer_handler(struct regs *r)
{
    	timer_ticks++;
	outportb(0x20,0x20);
}
and a screenshot, http://pyros.googlecode.com/files/100_1999.JPG
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

:( can't anybody help?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Could you use bochs and establish exactly which instruction is causing the GPF?
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

yeah, i could never figure out how to use bochs.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Bochs' manuals contain everything you would want to know.

Assuming that you have read them, where are you stuck?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

well, i'm stuck on telling bochs where the file is on my hard drive.
my bochsrc

Code: Select all

config_interface: textconfig
display_library: sdl
romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
megs: 32
vgaromimage: file=/usr/share/vgabios/vgabios.bin
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=0, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata2: enabled=0, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11
ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9
ata0-master: type=disk, path="/dev/sda2", mode=flat, cylinders=1024, heads=16, spt=63
ata0-slave: type=cdrom, path="/dev/cdrom", status=inserted

boot: disk
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

where do you boot from? cd? floppy? harddisk image?
what error does it give?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

where do you boot from?
hard drive
what error does it give?
it tells me that it can't find the file
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Using a physical disk for testing is considered bad practice. Secondly, you'll need root privileges to access /dev/sda2
Also you are referring to a partition instead of a complete disk.

Use bximage to create a hard disk image and use that.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

okay, well now i get this error
00000000000i[ ] lt_dlhandle is (nil)
00000000000p[ ] >>PANIC<< dlopen failed for module 'sdl': file not found
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

display_library: sdl
you said in you script that u use sdl for display. change it to x. see bochs ./configure --help
Author of COBOS
User avatar
astrocrep
Member
Member
Posts: 127
Joined: Sat Apr 21, 2007 7:21 pm

Post by astrocrep »

Why are you poping eax twice out of the return?

This is what I use as my ISR ...

This is attached to int 0x81 and when called does a task switch.

Code: Select all

[BITS 32]
global YieldThread

extern TaskSwitch

YieldThread:
 pusha          ;Push all standard registers
 push ds        ;Push segment d
 push es        ;Push segmetn e
 push fs        ; ''
 push gs        ; ''
 
 mov eax, 0x10  ;Get kernel data segment
 mov ds, eax    ;Put it in the data segment registers
 mov es, eax
 mov fs, eax
 mov gs, eax
 
 push esp       ;Push pointer to all the stuff we just pushed
 call TaskSwitch ;Call C code
 
 mov esp, eax   ;Replace the stack with what the C code gave us
 
 mov al, 0x20   ;Port number AND command number to Acknowledge IRQ
 out 0x20, al     ;Acknowledge IRQ, so we keep getting interrupts
 
 pop gs         ;Put the data segments back
 pop fs
 pop es
 pop ds
 
 popa           ;Put the standard registers back
 
 iret           ;Interrupt-Return
Good luck,
Rich
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

you said in you script that u use sdl for display. change it to x.
00000000000i[ ] lt_dlhandle is (nil)
00000000000p[ ] >>PANIC<< dlopen failed for module 'x': file not found
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Have you tried building Bochs from sources? There is a --with-all-libs option that looks useful.

the complete configure line you may want to try:

Code: Select all

/usr/src/bochs-2.3>./configure --enable-cpu-level=6 --enable-apic --enable-ne2k
--enable-vbe --enable-debugger --enable-clgd54xx --enable-cdrom --with-all-libs 
--enable-magic-breakpoints --enable-all-optimisations
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

i still get
00000000000i[ ] lt_dlhandle is (nil)
00000000000p[ ] >>PANIC<< dlopen failed for module 'x': file not found
Post Reply