Brendan wrote:
Because virtual 8086 tasks must use the lowest 1 MB of linear memory, so if you plan on having several "DOS boxes" or something you'll be screwed if the lowest 1 MB is mapped the same into every address space (e.g. treated the same as kernel space). There are ways around this, but in general leaving the lowest N MB for user applications would make it easier to allow any user-level processes to contain virtual 8086 code.
Hmm... I may have a misconception, then. I was under the impression vm86 used the lowest 1MB of *physical* memory. In fact, I seem to recall someone saying it was actually 16MB, but I've never heard that again, nor have I consulted the Intel manual to prove/disprove it.
In any event, I'm narrowminded in my usage, thinking only of my OS, in which case this is actually a reason *for* having the OS at the bottom end. Your definition of "thunking" would be my only use for vm86 (as fallback drivers for video, etc).
2. More generically, user applications are not dependent of how many memory is kernel space (your app can be linked for 0x400000 regardless of whether kernel is at 0xC0000000, 0x80000000 or 0xE0000000 ...), which makes ABIs nicer.
Brendan wrote:
So if the kernel is from 0x00000000 to 0x3FFFFFFFF you'd have applications code starting at 0x40000000 with application data above the application's code. Then, if the kernel happens to be from 0x00000000 to 0x1FFFFFFFF would you have the application at 0x40000000 with the application's data above this and wasted space from 0x20000000 to 0x3FFFFFFFF, or would you have a fragmented system with data above the applications code and below it? How about if the kernel grew and used from 0x00000000 to 0x7FFFFFFFF - would you still be able to run applications that are designed to be at 0x40000000?
All the kernel's I've seen that have their kernel mapped high map it to something similar to 0xC0000000, and occupy the top 1GB. Due to this, apps can only span 3GB.
If the kernel were loaded at the lower end, it may occupy up to 0x40000000. Thus, apps are still limited to 3GB.
Unless I'm missing something, I don't see the difference. If the kernel grows larger from the top, applications are then limited in size as well.
If PIC is, indeed, a hack on Intel, then I guess I can see that picking an arbitrary value to load apps in can be a problem... if your kernel grows above 1GB... this seems unlikely, esp. given a microkernel who's servers will exist in userspace, anyway.
So, yes, perhaps I'm wasting some address space in only allowing apps 3GB. All the examples of higherhalf kernels seem to do the same thing, however.
Brendan wrote:
IMHO the 80x86 CPU is not designed for 32 bit position independant code (at least not without using segmentation), and therefore all attempts at making it run 32 bit position independant code are ugly hacks. I don't like ugly hacks, and I don't agree that all applications should be ugly hacks (even if your compiler hides these hacks, they still exist).
I must admit, I haven't much tried it, so I can't comment on this.
Brendan wrote:
If the OS is designed well it's easy to remove all of the kernel from the 32 bit part of the address space. Problems come from a badly designed ABI - for e.g. allowing (or expecting) applications to access kernel data directly would cause problems (but then you've got problems with any design change that effect the structure or location of this data, and the kernel can't safely modify the data in a multi-CPU environment).
Indeed, I wasn't suggesting the app actually be able to access or modify the OS structure, but rather thinking of a setup whereby calling the OS would result in a pager context switch followed by a jump to a specific kernel function. Upon further though, however, this isn't feasable anyway...
so, yes, I'll conceed that a higher-half kernel has the advantage of allowing 32-bit apps on a 64-bit OS to have the full 32-bit memory space.
Brendan wrote:
Let's consider this from the opposite perspective - is there any benefit from having the kernel in the lower part of the address space?
The only benefit I can think of is that it makes it easy for people to pretend they are writing an OS (e.g. slapping a "hello world" kernel on top of GRUB and then having a party to celebrate). Maybe I've missed something...
I'm not suggesting lower half kernels have an advantage over anything. I was suggesting neither have advantages over the other.
And I hope you're not hinting that I might be one of those "hello world" developers...
--Jeff