Page 1 of 2

GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:04 pm
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.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:12 pm
by Combuster
gcc -ffreestanding -c Kernel.c -o KRNL32.BIN
Care to explain to us what those flags do, and why you use them?

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:17 pm
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.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:29 pm
by Combuster
So you don't know what you are doing? :roll:

That needs fixing. I suggest you start with gcc's manuals.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:31 pm
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?

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:33 pm
by Combuster
Apparently you don't know what -c does either.

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

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:35 pm
by HitmanYesman
Yeah I do. It compiles and assembles the file I specify. -o then can rename it.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:36 pm
by Combuster
What then, does the absence of -c do?

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

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:38 pm
by HitmanYesman
Without -c it would link the file as well as compile. I'm searching for -ffreestanding at the moment.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:40 pm
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?

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:42 pm
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.

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:45 pm
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?

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 2:49 pm
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...

This is meant to be annoying

Posted: Mon Apr 26, 2010 2:56 pm
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?

Re: GPF happening when loading kernel

Posted: Mon Apr 26, 2010 3:01 pm
by HitmanYesman
Sorry, had to do something. And no I haven't read my manual yet.