Kernel location
Kernel location
Some kernels say they load themselves to 2GB point. Why is that. Is there a practical reason for this?
Re: Kernel location
this is so that the kernel does not mess with the mem below 16mb as it is used for dma, vm86 and other stuff.
however it is up to up where u want to put you kernel in memory.
you should read up on the higher half tutorials on the wiki. also i recommend reading up on dma and the floppy drivers.
however it is up to up where u want to put you kernel in memory.
you should read up on the higher half tutorials on the wiki. also i recommend reading up on dma and the floppy drivers.
Re: Kernel location
If you plan to use paging, that really doesn't matter unless you intend to identity map your kernel.itisiuk wrote:this is so that the kernel does not mess with the mem below 16mb as it is used for dma, vm86 and other stuff.
One of the main reasons is that many kernels map the kernel in to each application's memory space. This means that if an application makes a system call, that system call can be handled in the current memory context without needing a potentially expensive memory space switch.
There is no reason why you can't have the kernel at a low address and applications in the higher half using this system, but this would require your app programmers to link their programs to somewhere like 0x80000000.
Cheers,
Adam
Re: Kernel location
There's one reason why kernel places at high address. It's simplest way to change proportions between app space and kernel space for statically compiled applications.AJ wrote:There is no reason why you can't have the kernel at a low address and applications in the higher half using this system, but this would require your app programmers to link their programs to somewhere like 0x80000000.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Kernel location
Which really isn't an issue if you have all of your developers use a standard linker script (I believe this is recommended for several reasons in the article about porting newlib). Then the programmer won't need to care where his/her program is linked and the kernel developers have some control over the locations of programs relative to the kernel.AJ wrote: There is no reason why you can't have the kernel at a low address and applications in the higher half using this system, but this would require your app programmers to link their programs to somewhere like 0x80000000.
I'm not sure If I fully understand what you mean. If you have application programmers statically link programs to 0x80000000 then the kernel developers still have the freedom to put the kernel at either 0x100000 mark or somewhere higher like 0xC0000000 or 0xF0000000 (as long as the statically compiled binary is not extraordinarily large of course). Again, standard linker script to the rescue.egos wrote:There's one reason why kernel places at high address. It's simplest way to change proportions between app space and kernel space for statically compiled applications.
~[Fluidium]~
Re: Kernel location
If kernel places at low address and there is a need to make kernel space larger or smaller, it's necessary to recompile all application binaries with new image base. If kernel places at high address then applications don't need recompiling.Stevo14 wrote:I'm not sure If I fully understand what you mean. If you have application programmers statically link programs to 0x80000000 then the kernel developers still have the freedom to put the kernel at either 0x100000 mark or somewhere higher like 0xC0000000 or 0xF0000000 (as long as the statically compiled binary is not extraordinarily large of course).
If you have seen bad English in my words, tell me what's wrong, please.
- 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:
Re: Kernel location
If you look at it from the other side:
a kernel at 0xC000000 will have one GB reserved for itself by default.
a kernel at 0x100000 might only reserve what it needs, leaving more space free for application's use.
and you can always compile a binary to a sufficiently high address so that you will never have problems expanding the kernel area, i.e. for a lower half kernel, compile to at least 1GB.
Or compile applications with relocations enabled like I do
a kernel at 0xC000000 will have one GB reserved for itself by default.
a kernel at 0x100000 might only reserve what it needs, leaving more space free for application's use.
and you can always compile a binary to a sufficiently high address so that you will never have problems expanding the kernel area, i.e. for a lower half kernel, compile to at least 1GB.
Or compile applications with relocations enabled like I do
Re: Kernel location
If something in the future means that you want to change the amount of virtual address space belonging to the kernel, this system means that every app, not just the kernel itself needs a recompile (assuming position dependent code). Not likely, but still may as well take this in to account in the design phase.Combuster wrote:and you can always compile a binary to a sufficiently high address so that you will never have problems expanding the kernel area, i.e. for a lower half kernel, compile to at least 1GB.
Cheers,
Adam
Re: Kernel location
Unless the applications were compiled in the first place to be as far away from the kernel as possible. Like this:egos wrote: If kernel places at low address and there is a need to make kernel space larger or smaller, it's necessary to recompile all application binaries with new image base. If kernel places at high address then applications don't need recompiling.
Code: Select all
<-- The kernel is as far this ways as possible.
Applications are as far this way as possible. -->
|--------------------------------- Memory --------------------------------|
But I like what Combuster pointed out: position independent code fixes all of these problems.
~[Fluidium]~
Re: Kernel location
Yes, but not relocations because it descent performance.Stevo14 wrote:position independent code fixes all of these problems.
If you have seen bad English in my words, tell me what's wrong, please.
- 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:
Re: Kernel location
Position independent code impacts performance since it must recompute all offsets to a known base every other instruction at runtime.but not relocations because it descent performance.
Relocatable code impacts performance since it must recompute all offsets to a known base at load time only.
Re: Kernel location
And exactly this descends performance. Why to relocate code when it is possible not to make thisCombuster wrote:it must recompute all offsets to a known base at load time only.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Kernel location
Because, for a small cost (fractions of a second each time a binary is loaded), you can have very large benefits such as being able to control at runtime where a binary is located, seamless changes in the amount and location of reserved kernel space, greater flexibility overall etc.egos wrote:And exactly this descends performance. Why to relocate code when it is possible not to make thisCombuster wrote:it must recompute all offsets to a known base at load time only.
~[Fluidium]~
Re: Kernel location
I'm continuing... great problems with mapping directly from executable files and so onStevo14 wrote:Because, for a small cost (fractions of a second each time a binary is loaded), you can have very large benefits such as being able to control at runtime where a binary is located, seamless changes in the amount and location of reserved kernel space, greater flexibility overall etc.
If you have seen bad English in my words, tell me what's wrong, please.
- AndrewAPrice
- Member

- Posts: 2327
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: Kernel location
I load my kernel at 3GB. This is because in the future if I decide I want to give my applications more memory, or my kernel more memory, I can move my kernel up/down (it's actually a C #define that sets my kernel's entry address, and another value in the linker script), and my applications can just load from 0x0 (in practice they load from 1MB, but I'm going to change it to 0, so there's no chance of pointers pointing to 0, since a lot of [my] code assume's that's unallocated) regardless of where I place my kernel in the future.
My OS is Perception.



