The k project

Binary loading

The path of the binary to load in the ISO is given via the multiboot command line. It’s an ELF file.

In K, since you just need to load an ELF file and execute it, only the segments are interesting. So the first thing is to get the program header table and its size, fortunately, those information are present in the ELF main header. After getting the program header table, you just have to load every segment marked as PT_LOAD at the good memory address.

Don’t forget that in K, the data segment and the code segment are separated, both in memory, with the help of the segmented memory, and in the ELF file. To determine if an ELF segment is a code one, take a look at PF_X defined in the elf.h header. Due to the sbrk() system call, the data segment should physically be located above the code segment, so that this segment could be expanded.

Possible bug causes