GPF happening when loading kernel

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.
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

GPF happening when loading kernel

Post by HitmanYesman »

So, I have my kernel which is Kernel.c. I have my second bootloader which loads my kernel and copies it to the 1 MB after i enter Protected Mode. Bochs has a GPF and infinitely reboots. It's not that it can't find the file because I added in a way to display a message if the file didn't exist. So if you guys could take a look at it I'd be grateful.

These are the variables that I use and I show what they are so you guys can get a better understanding of it.:

Code: Select all

CODE_DESC = 0x08
DATA_DESC = 0x10
IMAGE_RMODE_BASE = 0x3000
IMAGE_PMODE_BASE = 0x100000
Kernel.c:

Code: Select all

void ClrScr();

int main(void)
{
	ClrScr();
	
	for (;;);
}

void ClrScr()
{
	char *vidmem = (char*)0xB8000;
	unsigned int i;
	
	for (i = 0; i < (80*25); i++) {
		*vidmem++ = 0;
		*vidmem++ = 0xF;
	}
}

From when I enter PMode from second bootloader:

Setup.asm:

Code: Select all

Loader:
	mov	ax, DATA_DESC
	mov	ds, ax
	mov	ss, ax
	mov	es, ax
	mov	esp, 0x90000
	
Copy_Image:
	mov eax, DWORD [ImageSize]
	movzx ebx, WORD [bpbBytesPerSector]
	mul ebx
	mov ebx, 4
	div ebx
	cld
	mov esi, IMAGE_RMODE_BASE
	mov edi, IMAGE_PMODE_BASE
	mov ecx, eax
	rep movsd
	
	jmp	CODE_DESC:IMAGE_PMODE_BASE
	
	cli
	hlt
And this is how I'm compiling the Kernel.c file if it matters at all. By the way Setup.asm looks for the file called "KRNL32.BIN".

GCC Code:

Code: Select all

gcc -ffreestanding -c Kernel.c -o KRNL32.BIN
Thanks for taking the time to read this and help me.
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:

Re: GPF happening when loading kernel

Post by Combuster »

gcc -ffreestanding -c Kernel.c -o KRNL32.BIN
Care to explain to us what those flags do, and why you use them?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

Well, I've read a few tutorials on compiling with gcc and some have -ffreestanding some don't. As for -c if I don't put that it says no input files were listed and -o is the output file name.
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:

Re: GPF happening when loading kernel

Post by Combuster »

So you don't know what you are doing? :roll:

That needs fixing. I suggest you start with gcc's manuals.
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

I just don't know what -ffreestanding does but I can find that out quickly. But any idea as to why it causes a GPF?
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:

Re: GPF happening when loading kernel

Post by Combuster »

Apparently you don't know what -c does either.

Also, why didn't you look up -ffreestanding before posting?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

Yeah I do. It compiles and assembles the file I specify. -o then can rename it.
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:

Re: GPF happening when loading kernel

Post by Combuster »

What then, does the absence of -c do?

Also, why didn't you look up -ffreestanding yet?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

Without -c it would link the file as well as compile. I'm searching for -ffreestanding at the moment.
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:

Re: GPF happening when loading kernel

Post by Combuster »

Would linking be the correct behaviour?

What would be the reasons that you would you linking over?

Also, why didn't you look up -ffreestanding before posting?

Why did I have to ask that three times?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

I'm not sure if linking would be the correct behaviour or not.

I didn't look it up because honestly I didn't think it was that important at the time and I really just want the kernel to be able to clear the screen at the moment.
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:

Re: GPF happening when loading kernel

Post by Combuster »

How would you try to find out if linking is correct or wrong?
What does linking do?
Why would you skip linking?
Also, why didn't you look up -ffreestanding before posting?
Why did I have to ask that four times?
Why do I keep asking questions?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

How would you try to find out if linking is correct or wrong?
Read the GCC user's manual
What does linking do?
Gathers multiple files and puts them all into one file
Why would you skip linking?
Didn't think it was needed
Also, why didn't you look up -ffreestanding before posting?
"I didn't look it up because honestly I didn't think it was that important at the time and I really just want the kernel to be able to clear the screen at the moment."
Why did I have to ask that four times?
Because I posted right away to answer your initial question and failed to see you asked that.
Why do I keep asking questions?
To let me know I need to read up on the compiler manual more...
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:

This is meant to be annoying

Post by Combuster »

Then why didn't you look linking up in the GCC manual?
Does linking do anything else?
Why would you make a decision based on something you didn't know for sure?
Why didn't you explain -ffreestanding yet?
Why did I have to ask that three times after you saw it?
Why am I still asking this question?
Why are you still replying if you think you should be reading the manual first?
"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 ]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: GPF happening when loading kernel

Post by HitmanYesman »

Sorry, had to do something. And no I haven't read my manual yet.
Post Reply