apsun / loliOS

Lightweight & operational Linux-inspired OS.
33 stars 1 forks source link

Support real ELF loading #18

Closed apsun closed 3 years ago

apsun commented 5 years ago

It would be great to get rid of the elfconvert black box binary, one way would be to load real x86 ELF binaries. The post-elfconvert binaries seem to be valid ELF, as they can be executed natively on Linux (cat for instance), so we can transparently replace the old implementation.

elf.h: https://github.com/torvalds/linux/blob/master/include/uapi/linux/elf.h

Unfortunately the x86 ABI specifies that addresses 4MB~3GB are available for usage. There are two solutions: a. move the kernel to virtual address 3GB b. write a custom linker script to avoid the 4-8MB page

Currently there are no plans to support a dynamic linker. All binaries should be statically linked.

apsun commented 5 years ago

Moving the kernel to vaddr 3GB might be an issue, we would have to create a stub for GRUB to enable paging and jump into the real kernel since we can't load at paddr 3GB (not enough RAM) and we can't load at paddr 4MB (enabling paging would break all our addresses)

A workaround might be to have the kernel loaded at both 3GB and 4MB (two PDEs pointing to paddr 4MB), and swap out the 4MB PDE when transitioning between user/kernel space.

apsun commented 5 years ago

We can probably also use segment registers to redirect CS/DS/SS to 3GB for the kernel, but this seems like a hack

apsun commented 4 years ago

Seems the way Linux does this is by specifying a different VMA/LMA in the linker script, offset by PAGE_OFFSET. Reference for LMA here: https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html#Output-Section-LMA

apsun commented 3 years ago

Implemented in 91c5db3040b7a2cac2770bad1daa9ec763ed0b2a.