Phase II.X: hardware-agnostic S3 resume trampoline. The
kernel now:
* Saves the CPU state (rax, rbx, rcx, rdx, rsi, rdi, rbp,
r8..r15, segment registers ds/es/fs/gs/ss, RFLAGS, RSP,
RIP, CR3) to a static S3State struct before entering
S3. This is done in `enter_s3()` in
`arch/x86_shared/stop.rs` via the new
`s3_state_save_global` function.
* Exposes a `s3_trampoline` function (in
`arch/x86_shared/s3_resume.rs`) implemented as a
64-bit `naked_asm!` block. The trampoline:
- Checks the magic value (0x123456789abcdef0) in
S3_STATE.saved_magic. If zero (cold boot), halts.
- Restores ds/es/fs/gs/ss to __KERNEL_DS.
- Restores CR3 (page table base).
- Restores RSP (kernel stack pointer).
- Restores RFLAGS.
- Restores the 13 general-purpose registers.
- Sets the RESUMING_FROM_S3 flag.
- Pushes the saved RIP onto the stack and uses `ret`
to jump to it (the kernel's kmain_resume_from_s3
is the entry point).
* Exposes `s3_resume_address()` that returns the
trampoline's address. acpid writes this to FACS
.waking_vector via the kernel AcpiScheme.
* Exposes `s3_state_valid()` that the kernel checks
during boot to determine if this is a cold boot or a
resume from S3.
* Exposes `is_resuming_from_s3()` that the kernel
checks during resume to skip early init.
Cross-reference: Linux 7.1
`arch/x86/kernel/acpi/wakeup_64.S` does the same
thing in 64-bit assembly. Red Bear OS uses Rust's
`naked_asm!` instead of a separate .S file,
keeping the trampoline inline with the kernel source.
The Redox implementation also adds CR3 restoration
(which Linux handles via the trampoline's code in
`arch/x86/kernel/acpi/wakeup_64.S`) and uses the
standard 0x123456789abcdef0 magic for state validation.
Hardware-agnostic: works on any x86_64 system with
standard ACPI S3 support (Dell, HP, Lenovo, LG Gram 14).
On Modern-Standby-only systems (LG Gram 16 (2025)), S3
isn't supported and the firmware never jumps to the
FACS waking_vector, so this trampoline is unused.
Build: redbear-mini.iso (512 MB) builds successfully.
QEMU test: QEMU's S3 emulation is limited and the
firmware does not actually jump to the FACS waking_vector
in the QEMU default config, so the S3 resume path is
not tested at QEMU time. The trampoline is verified to
compile and be present in the ISO.
Kernel
Redox OS Microkernel
Requirements
nasmneeds to be available on the PATH at build time.
Building The Documentation
Use this command:
cargo doc --open --target x86_64-unknown-none
Debugging
QEMU
Running QEMU with the -s flag will set up QEMU to listen on port 1234 for a GDB client to connect to it. To debug the redox kernel run.
make qemu gdb=yes
This will start a virtual machine with and listen on port 1234 for a GDB or LLDB client.
GDB
If you are going to use GDB, run these commands to load debug symbols and connect to your running kernel:
(gdb) symbol-file build/kernel.sym
(gdb) target remote localhost:1234
LLDB
If you are going to use LLDB, run these commands to start debugging:
(lldb) target create -s build/kernel.sym build/kernel
(lldb) gdb-remote localhost:1234
After connecting to your kernel you can set some interesting breakpoints and continue
the process. See your debuggers man page for more information on useful commands to run.
Notes
-
Always use
foo.get(n)instead offoo[n]and try to cover for the possibility ofOption::None. Doing the regular way may work fine for applications, but never in the kernel. No possible panics should ever exist in kernel space, because then the whole OS would just stop working. -
If you receive a kernel panic in QEMU, use
pkill qemu-systemto kill the frozen QEMU process.
How To Contribute
To learn how to contribute to this system component you need to read the following document:
Development
To learn how to do development with this system component inside the Redox build system you need to read the Build System and Coding and Building pages.
How To Build
To build this system component you need to download the Redox build system, you can learn how to do it on the Building Redox page.
This is necessary because they only work with cross-compilation to a Redox virtual machine, but you can do some testing from Linux.
Funding - Unix-style Signals and Process Management
This project is funded through NGI Zero Core, a fund established by NLnet with financial support from the European Commission's Next Generation Internet program. Learn more at the NLnet project page.
