# Home, sweet home example

This package builds the Tutorial 14 user program as a freestanding AArch64 ELF64 image, converts the whole ELF file into a C byte array, links that array into a small bare-metal kernel, loads the ELF segments into memory, and runs the program at EL0.

It deliberately does not link glibc. The program contains its own tiny `printf` and Linux-shaped syscall wrappers, so Alquist can load the ELF from an embedded array and implement only the few syscalls the example uses.

The boot config follows the previous examples: UART stays enabled for the kernel log, the core clock is fixed for a stable mini UART baud rate, the HDMI rainbow splash is disabled, and Raspberry Pi second-stage firmware logging stays off. On hardware the ACT LED is paced by the generic timer while the EL0 program yields and keeps blinking after `exit(7)`.

## Build

```sh
make
```

Outputs:

- `build/hello_home.elf` - the ELF64 user program
- `build/user_image.c` - generated C byte array containing the ELF file
- `build/user_image.h` - declarations for the generated array
- `build/kernel8.elf` - the bare-metal kernel with the embedded user ELF
- `boot/kernel8.img` - the Raspberry Pi boot image

You can inspect the load plan with:

```sh
make readelf
```

The generated `user_image.c` is meant to be linked into the kernel tutorial code later, so the kernel can parse ELF headers directly from memory instead of reading from storage.

## Run in QEMU

```sh
timeout 10s qemu-system-aarch64 -M raspi4b -cpu cortex-a72 -m 2G \
	-nographic -monitor none -serial null -serial stdio \
	-kernel build/kernel8.elf
```

Expected output:

```text
Home, sweet home kernel
ELF64 AArch64 executable accepted
entry=0x0000000000400380 phnum=2
	PT_LOAD R-X va=0x0000000000400000 filesz=1292 memsz=1292
	PT_LOAD RW- va=0x0000000000401000 filesz=4 memsz=48
user stack 0x00000000004f0000..0x0000000000500000
entering EL0
Home, sweet home
data=42 bss=OK
pid=3 uptime=0 ticks
loop 0, yielding from user space
loop 1, yielding from user space
loop 2, yielding from user space
goodbye from ELF64
process 3 exited with status 7
```
