Master the fundamental concepts of boot sector development through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksKernels often ship as ELF binaries with program headers describing loadable segments. A bootloader reads each PT_LOAD segment from disk to its p_paddr or p_vaddr and jumps to e_entry. For example, a ET_EXEC kernel at LBA 100 might place .text at 0x100000 and entry at 0x101000.
cLoading…
Verify e_ident[EI_MAG] bytes and e_machine == EM_386 before trusting headers. p_paddr may be zero for some objects; fall back to p_vaddr when loading a linked kernel expecting low memory. Read sectors in chunks if your DAP cannot span the whole segment in one BIOS call. Clear the BSS portion when p_memsz > p_filesz so global variables start at zero.
You will parse ELF headers and load at least one PT_LOAD segment from disk. This exercise requires computing file offsets, physical addresses, and the entry point before transfer of control.
Parse a hex dump of an ELF32 kernel image and emit the load plan.
Input (stdin): one line of whitespace-separated hex byte pairs: a little-endian ELF32 image: 52-byte ELF header followed by 32-byte program header entries (as stored on disk before a bootloader parses it).
ELF32 header fields you need (after the 16-byte e_ident, all little-endian): e_type@16, e_machine@18, e_entry@24, e_phoff@28, e_phentsize@42, e_phnum@44. ELF32 program header: p_type@0, p_offset@4, p_vaddr@8, p_paddr@12, p_filesz@16, p_memsz@20, p_flags@24 (bit2=R, bit1=W, bit0=X).
Requirements:
Test with the sample dumps; a truncated or non-ELF image must print bad_magic.