Kernel location

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.
albeva
Member
Member
Posts: 42
Joined: Thu Aug 21, 2008 8:31 pm

Kernel location

Post by albeva »

Some kernels say they load themselves to 2GB point. Why is that. Is there a practical reason for this?
itisiuk
Member
Member
Posts: 98
Joined: Mon Mar 24, 2008 1:46 pm

Re: Kernel location

Post by itisiuk »

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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Kernel location

Post by AJ »

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.
If you plan to use paging, that really doesn't matter unless you intend to identity map your kernel.

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
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel location

Post by egos »

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.
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.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Kernel location

Post by Stevo14 »

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

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.
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
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel location

Post by egos »

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 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.
If you have seen bad English in my words, tell me what's wrong, please.
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: Kernel location

Post by Combuster »

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 :)
"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 ]
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Kernel location

Post by AJ »

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

Cheers,
Adam
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Kernel location

Post by Stevo14 »

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.
Unless the applications were compiled in the first place to be as far away from the kernel as possible. Like this:

Code: Select all

     <-- The kernel is as far this ways as possible.
                      Applications are as far this way as possible. -->
|--------------------------------- Memory --------------------------------|
It doesn't matter if it's a higher half kernel or a lower half kernel. The idea is the same.

But I like what Combuster pointed out: position independent code fixes all of these problems.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel location

Post by egos »

Stevo14 wrote:position independent code fixes all of these problems.
Yes, but not relocations because it descent performance.
If you have seen bad English in my words, tell me what's wrong, please.
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: Kernel location

Post by Combuster »

but not relocations because it descent performance.
Position independent code impacts performance since it must recompute all offsets to a known base every other instruction at runtime.
Relocatable code impacts performance since it must recompute all offsets to a known base at load time only.
"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 ]
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel location

Post by egos »

Combuster wrote:it must recompute all offsets to a known base at load time only.
And exactly this descends performance. Why to relocate code when it is possible not to make this :)
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Kernel location

Post by Stevo14 »

egos wrote:
Combuster wrote:it must recompute all offsets to a known base at load time only.
And exactly this descends performance. Why to relocate code when it is possible not to make this :)
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
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Kernel location

Post by egos »

Stevo14 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.
I'm continuing... great problems with mapping directly from executable files and so on :)
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
AndrewAPrice
Member
Member
Posts: 2327
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Kernel location

Post by AndrewAPrice »

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.
Post Reply