Interpreting addresses as signed and "negative half kernel". Is this already a thing?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
ktsnowy
Posts: 1
Joined: Mon Oct 14, 2024 5:46 pm

Interpreting addresses as signed and "negative half kernel". Is this already a thing?

Post by ktsnowy »

I've been reading about the advantages of higher half kernels and the disadvantages of lower half kernels. How higher half makes it more convenient for userspace by allowing the usage of more addresses closer to zero, and lower half makes it more convenient for the kernel (for the same reason) while potentially causing problems for userspace.

However, isn't the notion that "closer to zero" must also mean "above zero" a side effect of interpreting addresses as unsigned? There's no hardware requirement for this to be the case, right? It's simply a convention, the hardware is perfectly capable of jumping to any negative addresses close to zero via sign-extended immediates and may even treat addresses as signed already. As evidenced by x86 having 48-bit sign-extended addresses, which leaves a memory hole between userspace and kernel addresses when interpreted as unsigned.

So if instead we interpreted addresses as signed we could place the kernel immediately below zero and have all the advantages of a higher half kernel (because it is one) while also having the advantages of a lower half kernel (being close to zero). Userspace would grow upwards from zero and the kernel would grow downwards from zero (in stack-like fashion 8)), both starting close to zero.

This fixes the conceptual memory hole caused by interpreting addresses as unsigned, has all the advantages of a higher half kernel and all the advantages of a lower half kernel.

So why is it that I never hear about this specific layout being used? Are there any issues caused by doing this?
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Interpreting addresses as signed and "negative half kernel". Is this already a thing?

Post by Octocontrabass »

I'm not sure why you haven't heard of it before, but it's the recommended memory layout for x86-64 kernels.
User avatar
eekee
Member
Member
Posts: 891
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Interpreting addresses as signed and "negative half kernel". Is this already a thing?

Post by eekee »

As soon as I read the topic, despite never having coded a kernel myself, I said "Yeess" because this is just the sort of thing that low-level programmers do. :) The ease and speed of testing the sign bit -- 1 or 2 instructions in assembly language -- make it a very attractive option.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Post Reply