OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 10:20 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:04 pm 
Offline
Member
Member

Joined: Fri Apr 23, 2010 8:27 am
Posts: 47
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:
CODE_DESC = 0x08
DATA_DESC = 0x10
IMAGE_RMODE_BASE = 0x3000
IMAGE_PMODE_BASE = 0x100000


Kernel.c:
Code:
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:
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:
gcc -ffreestanding -c Kernel.c -o KRNL32.BIN


Thanks for taking the time to read this and help me.


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:12 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
Quote:
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:17 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:29 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:31 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:33 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:35 pm 
Offline
Member
Member

Joined: Fri Apr 23, 2010 8:27 am
Posts: 47
Yeah I do. It compiles and assembles the file I specify. -o then can rename it.


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:36 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:38 pm 
Offline
Member
Member

Joined: Fri Apr 23, 2010 8:27 am
Posts: 47
Without -c it would link the file as well as compile. I'm searching for -ffreestanding at the moment.


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:40 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:42 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:45 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 2:49 pm 
Offline
Member
Member

Joined: Fri Apr 23, 2010 8:27 am
Posts: 47
Quote:
How would you try to find out if linking is correct or wrong?

Read the GCC user's manual

Quote:
What does linking do?

Gathers multiple files and puts them all into one file

Quote:
Why would you skip linking?

Didn't think it was needed

Quote:
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."

Quote:
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.

Quote:
Why do I keep asking questions?

To let me know I need to read up on the compiler manual more...


Top
 Profile  
 
 Post subject: This is meant to be annoying
PostPosted: Mon Apr 26, 2010 2:56 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: GPF happening when loading kernel
PostPosted: Mon Apr 26, 2010 3:01 pm 
Offline
Member
Member

Joined: Fri Apr 23, 2010 8:27 am
Posts: 47
Sorry, had to do something. And no I haven't read my manual yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 229 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group