devc1 wrote:
He will still need some relocations on variables like :
If the linker knows the base address at link time, why would it emit a relocation for that?
devc1 wrote:
First, I don't suggest that you start with this if you're a begineer.
Second, to do this your kernel should be in some relocatable image format like ELF or PE.
I have a higher half kernel standing on the top system area, what I do is that I relocate my kernel on runtime then jump to the new virtual address without identity mapping my kernel.
Requirement steps (in your kernel) for doing so : ...
I think your method is a bit over-complicated. If you have a halfway decent linker, you should us the method I describe below.
devc1 wrote:
However, I am not experienced with x86, My OS is only 64 bit,
You mean your OS ix x86_64? That's still x86
spotracite wrote:
but I'd like to load it to somewhere in the higher half - preferably 0xC0010000 or 0x80010000, but neither of them work.
That's because your VM contains (I'm sure) not that much physical memory to load it to 2GiB or 3GiB.
spotracite wrote:
I don't know enough about the i386's memory addressing to know where my problem is - I'd imagine it's to do with physical vs. virtual addressing, but I don't know how I'd be able to fix that.
Partially. You will need paging to implement a higher half kernel. There's a good bit of reference on paging in the wiki. And there's always the Intel manuals.
spotracite wrote:
(I don't use ELF files but I don't think that's the problem)
I think you could pull off a proper higher half kernel using a flat binary, but you'll need to use a decent linker (like GNU LD).
The simplest way to do a higher half kernel is to put your code that enables paging in a special ELF section, and use linker script trickery for that section's image base to be relative to the kernel's physical mapping, and have the other sections' image bases relative to kernels virtual (i.e., higher-half) mapping. This may sound complicated, but once you understand it, it's a lot simpler than other mechanisms. Look at this article:
https://wiki.osdev.org/Higher_Half_x86_Bare_Bones, that's what is being done there.