Skip to content

so3: x86_64 port on the QEMU PC (pc64), booted by GRUB - #380

Merged
daniel-rossier merged 4 commits into
mainfrom
feat/x86
Nov 15, 2026
Merged

daniel-rossier merged 4 commits into
mainfrom
feat/x86

Conversation

@daniel-rossier

Copy link
Copy Markdown
Contributor

Ports SO3 to x86_64, on a new pc64 platform (QEMU PC). GRUB boots SO3 from the disk image to the user shell.

Kernel (arch/x86)

  • multiboot2 entry from GRUB, 32 → 64-bit switch, kernel in the top 2 GB (-mcmodel=kernel), built without FPU/SSE
  • the device tree and rootfs.fat arrive as GRUB modules; the boot code writes the memory size and the initrd location into the device tree, as U-Boot does on ARM, so the generic code is unchanged there
  • single page-table root, as on AArch32: the kernel half is shared by every process and re-synced on each switch
  • syscall entry, return through iretq; FPU/SSE state and callee-saved registers kept on the kernel stack across __switch_to; FS base per thread
  • drivers: 8259 PIC, 8254 PIT tick + TSC clocksource, COM1 16550 in the I/O port space

Generic code, x86-only differences (the ARM build is untouched)

  • musl x86_64 follows the generic Linux ABI: other O_DIRECTORY/O_NOFOLLOW/O_DIRECT/O_LARGEFILE values, another struct stat layout, clone() with ctid before tls, arch_prctl(), and stat/lstat/mkdir/rmdir/unlink/rename instead of their *at versions
  • strtod and libroxml compute in floating point and serve only SOO: left out on x86
  • -mlittle-endian and -no-enum-size-warning moved to the ARM flags

Build

  • new boot stage grub in IB_BOOT_CHAIN, exclusive with uboot; U-Boot is now built only when the chain names it (no change for the ARM platforms)
  • bsp_pc64.inc: GRUB goes into the raw area of sdcard.img.pc64 (boot.img in the MBR, core image from sector 1), with no grub-install and no root; p1 holds the kernel, the DTB, rootfs.fat and grub.cfg
  • QEMU builds the x86_64 target; st.sh/build.sh know pc64; the build image gains grub-pc-bin and grub-common; x86_64 musl toolchain and CMake file
  • the dead x86-qemu/x86-pc leftovers are removed (BSP stub, two storage classes, the bzImage branch of linux_6.12.bb)

Tested

  • IB_PLATFORM = "pc64": build.sh bsp-so3 + deploy.sh bsp-so3 + st.sh boots to the shell (on the host, not yet in the container)
  • in the shell: ls -l, mkdir, cat, fork/exec, thread_example (clone, TLS, futex, mutex), Ctrl-C on time
  • a 2 s nanosleep lasts 2.01 s under both TCG and KVM
  • virt64, virt32, rpi4_64 and virt64_avz_soo still build and link

Not covered yet: SMP (uniprocessor port), LAPIC/IOAPIC, network, framebuffer, documentation page.

GRUB loads the kernel with multiboot2, together with the device tree and
the root filesystem as modules. The boot code writes the memory size and
the initrd location into the device tree, as U-Boot does on ARM, so the
generic code sees the same input on both. It also moves the root
filesystem to the top of the RAM: GRUB may load it right after the
image, where the device tree and the frame table go.

The kernel runs in the top 2 GB (-mcmodel=kernel) without the FPU, which
belongs to user space and is switched with the callee-saved registers on
the kernel stack. As with AArch32 there is a single page table root, so
every process carries the kernel half, kept in sync on each switch.

PC devices: 8259 PIC, 8254 PIT tick, TSC clocksource and the COM1 16550
in the I/O port space.

musl on x86_64 follows the generic Linux ABI: other open() flag values
and struct stat layout, clone() with ctid before tls, arch_prctl for the
thread pointer, and stat/mkdir/unlink/rmdir/rename in place of their *at
versions. strtod and libroxml compute in floating point and only serve
SOO, so x86 leaves them out.
The usr-so3 recipe picks <IB_PLAT_CPU>-linux-musl.cmake, so the pc64
platform needs its x86_64 counterpart of the aarch64 one.
GRUB is a new stage of IB_BOOT_CHAIN, the x86 counterpart of U-Boot, so
it runs alone. U-Boot is now built only when the chain names it, which
changes nothing for the ARM platforms.

The deploy installs GRUB in the raw area of the disk image, boot.img in
the MBR and the core image from sector 1 where both expect it, so
neither grub-install nor root is needed. p1 holds the kernel, the device
tree, rootfs.fat and grub.cfg; there is no ITB.

QEMU gains the x86_64 target, st.sh and build.sh the pc64 platform, and
the build image the GRUB tools.
They described a Linux x86 platform that no longer builds: the BSP only
printed a message and the two storage classes defined a hook that
nothing calls any more. pc64 is the x86 platform now.
@daniel-rossier
daniel-rossier merged commit 9053b19 into main Nov 15, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant