GPF happening when loading kernel
- Combuster
- 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
How many posts do I need before you actually do that?
-
- Member
- Posts: 47
- Joined: Fri Apr 23, 2010 8:27 am
Re: GPF happening when loading kernel
You keep replying while I'm trying to read it so I reply back...
- Combuster
- 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
Does your problem get solved when you keep replying to my posts instead of doing other things?
-
- Member
- Posts: 47
- Joined: Fri Apr 23, 2010 8:27 am
Re: GPF happening when loading kernel
Okay, -ffreestanding is setting the executing environment for C where everything I do is in userspace.
A linker is a way to parse and link according to the files specified
A linker is a way to parse and link according to the files specified
- Combuster
- 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 also meant to be annoying
Why is your first answer wrong?
How did you get to that answer?
What does freestanding have to do with userspace?
What does "to link" mean?
Why are you making a definition in terms of itself?
Does that help you?
What does linking do besides putting multiple files into one?
What makes linking different from other methods that turn multiple files in to one?
Why does the staff want to lock this thread?
How did you get to that answer?
What does freestanding have to do with userspace?
What does "to link" mean?
Why are you making a definition in terms of itself?
Does that help you?
What does linking do besides putting multiple files into one?
What makes linking different from other methods that turn multiple files in to one?
Why does the staff want to lock this thread?
-
- Member
- Posts: 47
- Joined: Fri Apr 23, 2010 8:27 am
Re: GPF happening when loading kernel
Ehh, free-standing is an environment where all the standard libraries have been removed except the subset of the C library (stdint, float, etc) for a 'stand-alone' program such as an OS
I got that first answers from here: http://wiki.osdev.org/GCC_Cross-Compiler
At the Step 2 C library in the 3rd paragraph.
Well, since my answer was wrong nothing then.
The linker puts the machine code from the files in order according to how they were presented to the linker by the compiler. And this order is the basis for some files (ELF, EXE, etc) The linker also replaces all variable names with exact memory address so the OS can find stuff in memory. After this (without any errors) the files can then be used for execution.
Well, no it does make things harder to define when you use the word inside it's definition.
Hm, possibly because I didn't search before I posted.
I got that first answers from here: http://wiki.osdev.org/GCC_Cross-Compiler
At the Step 2 C library in the 3rd paragraph.
Well, since my answer was wrong nothing then.
The linker puts the machine code from the files in order according to how they were presented to the linker by the compiler. And this order is the basis for some files (ELF, EXE, etc) The linker also replaces all variable names with exact memory address so the OS can find stuff in memory. After this (without any errors) the files can then be used for execution.
Well, no it does make things harder to define when you use the word inside it's definition.
Hm, possibly because I didn't search before I posted.
- Combuster
- 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 too
Why can't I find your answer in the text mentioned?
What does freestanding have to do with userspace?
What does the kernel have to do with userspace?
What does the bootloader have to do with userspace?
Why does a linker output variable names if they are all replaced?
Why does a linker not replace function names?
Why does the linker preserve order?
Does the linker preserve order?
How would the OS find stuff in memory?
How would the output have to be used?
Why are you using the term OS when there is none (at this point in time)?
What are the properties of ELFs, EXEs, etc?
Can you be more specific than a list of ELFs, EXEs, etc?
What does freestanding have to do with userspace?
What does the kernel have to do with userspace?
What does the bootloader have to do with userspace?
Why does a linker output variable names if they are all replaced?
Why does a linker not replace function names?
Why does the linker preserve order?
Does the linker preserve order?
How would the OS find stuff in memory?
How would the output have to be used?
Why are you using the term OS when there is none (at this point in time)?
What are the properties of ELFs, EXEs, etc?
Can you be more specific than a list of ELFs, EXEs, etc?
-
- Member
- Posts: 47
- Joined: Fri Apr 23, 2010 8:27 am
Re: GPF happening when loading kernel
Well, that depends what you mean. By organization or I just didn't give the right answer.Why can't I find your answer in the text mentioned?
It provides the base environment for the usermode applications that will be in userspaceWhat does freestanding have to do with userspace?
Basic operating systems divide virtual memory into kernel space and userspace. The kernel space is used for running and maintaining the operating system, which in term run and maintains the userspace applications.What does the kernel have to do with userspace?
Nothing since userspace is virtual memory and virtual memory isn't available in real mode where we enter with the bootloader.What does the bootloader have to do with userspace?
So that we can understand them since we don't actually know their exact memory addresses.Why does a linker output variable names if they are all replaced?
Searched for this and couldn't find it. I'm going to have to say what I think. I think it doesn't because certain functions take parameters. But then the linker could just send the parameter to that actual memory address so I'm not sure on this one.Why does a linker not replace function names?
Yes.Does the linker preserve order?
It uses functions that we make that uses the FDC or some other device to effectively find the memory we are looking for.How would the OS find stuff in memory?
Of the linker? Well, the linker is the last step in compiling so it could be run.How would the output have to be used?
To have a more general idea on the subject and to directly relate what I was saying to OS development.Why are you using the term OS when there is none (at this point in time)?
Size, type, and what programs are capable of opening them.What are the properties of ELFs, EXEs, etc?
I'm not sure what you mean than a list of ELFs, EXEs, etc...Can you be more specific than a list of ELFs, EXEs, etc?
- Combuster
- 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
What is the opposite of freestanding?
What are the key differences between both?
What does this base environment mean?
What is required for this base environment?
What is the opposite of userspace?
What are the key differences between both?
If the virtual memory is divided, why can both userspace and kernel space access all 4GB of it?
Why is userspace equivalent to virtual memory?
How does the linker replace all variables with exact addresses when it doesn't know them?
What proof do you have of the fact that the linker preserves order?
Why is there no step between linking and executing?
If the kernel can be executed immediately after linking, why is there a bootloader involved?
What makes that some programs can only open ELFs and some only EXEs?
Is your compiler one of those limited programs?
How did you manage to store your RAM on the floppy disk?
Did you actually search before posting?
What are the key differences between both?
What does this base environment mean?
What is required for this base environment?
What is the opposite of userspace?
What are the key differences between both?
If the virtual memory is divided, why can both userspace and kernel space access all 4GB of it?
Why is userspace equivalent to virtual memory?
How does the linker replace all variables with exact addresses when it doesn't know them?
What proof do you have of the fact that the linker preserves order?
Why is there no step between linking and executing?
If the kernel can be executed immediately after linking, why is there a bootloader involved?
What makes that some programs can only open ELFs and some only EXEs?
Is your compiler one of those limited programs?
How did you manage to store your RAM on the floppy disk?
Did you actually search before posting?
-
- Member
- Posts: 47
- Joined: Fri Apr 23, 2010 8:27 am
Re: GPF happening when loading kernel
Hosted environment is when all standard C libraries are available but freestanding is when only the subset C library is availiable (float, stdint, ect)
The opposite of userspace is kernel space where all the core Operating System programs are run.
Userspace is where user applications are run, like games and microsoft word
Because the userspace needs to be able to access the kernel programs to be able to give the Operating System important data and the kernel space is needed to able to access the userspace to control the programs to make sure they don't try to access anything outside their ring.
It replaces the variables WE define in the code.
EXE and ELF require a certain basis to be able to be run. If the linker didn't preserve order than the files wouldn't be able to be run properly.
It depends on what is the format of the file. If the program is designed to open up that particular format it can open it up. As for the bootloader, C can not be loaded in flat binary (I think).
No... I just didn't compile right.
There is no RAM on the floppy disk (as far as I know), all memory that can be stored for a long time.
Most of it yes, but I am doing other things other than searching about all of this.
The opposite of userspace is kernel space where all the core Operating System programs are run.
Userspace is where user applications are run, like games and microsoft word
Because the userspace needs to be able to access the kernel programs to be able to give the Operating System important data and the kernel space is needed to able to access the userspace to control the programs to make sure they don't try to access anything outside their ring.
It replaces the variables WE define in the code.
EXE and ELF require a certain basis to be able to be run. If the linker didn't preserve order than the files wouldn't be able to be run properly.
It depends on what is the format of the file. If the program is designed to open up that particular format it can open it up. As for the bootloader, C can not be loaded in flat binary (I think).
No... I just didn't compile right.
There is no RAM on the floppy disk (as far as I know), all memory that can be stored for a long time.
Most of it yes, but I am doing other things other than searching about all of this.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: GPF happening when loading kernel
I think registration on this forum should require an IQ test.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: GPF happening when loading kernel
I'm sorry, this thread is really going nowhere at all.
@OP, you have some serious reading and research to do, and plenty of knowledge to learn. OS development is NOT a good way to learn how to code, or to learn any new programming language. You must be intimately familiar with your CPU, compiler toolchain, and various other things, most especially the art of debugging.
Spend some time writing various userspace applications. Calculators, hex editors, etc. After a while, try writing a memory allocator in userspace (and learn how to hook it in to the system). If that comes easy to you, try implementing a new filesystem under linux. Or implement one from scratch that's already there (fat and iso9660 are good choices).
At that point you'll be much more advanced and ready to begin this adventure we call OS development. In fact, you'll be halfway there, having already implemented some challenging things in userspace.
@OP, you have some serious reading and research to do, and plenty of knowledge to learn. OS development is NOT a good way to learn how to code, or to learn any new programming language. You must be intimately familiar with your CPU, compiler toolchain, and various other things, most especially the art of debugging.
Spend some time writing various userspace applications. Calculators, hex editors, etc. After a while, try writing a memory allocator in userspace (and learn how to hook it in to the system). If that comes easy to you, try implementing a new filesystem under linux. Or implement one from scratch that's already there (fat and iso9660 are good choices).
At that point you'll be much more advanced and ready to begin this adventure we call OS development. In fact, you'll be halfway there, having already implemented some challenging things in userspace.
Re: GPF happening when loading kernel
OK, I'm going to abuse my moderator powers and reply to this as this thread really is taking the piss.
James
Good post, well written and with the correct information; There are several things wrong here.HitmanYesman wrote: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.
...
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:Thanks for taking the time to read this and help me.Code: Select all
gcc -ffreestanding -c Kernel.c -o KRNL32.BIN
- The -c option to gcc skips the linking phase, leaving you with an unlinked ELF object file. This is unusable until it is linked. There are placeholders
all over the file for functions to be linked in. You need to remove the -c option. - As noted above, you obtain an ELF file. This is not raw binary, it is the format used by *NIX operating systems (if you're on cygwin, it produces a Windows PE file; again not raw binary). It contains extra segments and information to enable a load of runtime linking and optimisation stuff. You need to use a Linker script to force the output to raw binary.
- When your bootloader passes control to your kernel, there is no assembler bootstrap code - or at least if you are trying to do this all in the bootloader, you don't set up a stack before jumping to the C code.
James