Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f07a0ba
Fix UEFI Page Fault -32 by using GPT partition table
google-labs-jules[bot] Mar 16, 2026
420b29a
Fix UEFI boot crash by using GPT partitioning and correct device handle
google-labs-jules[bot] Mar 17, 2026
edfc917
Fix UEFI Page Fault and add self-contained ISO support
google-labs-jules[bot] Mar 17, 2026
559f6df
Fix UEFI Page Fault and implement robust self-contained ISO boot
google-labs-jules[bot] Mar 17, 2026
7a3ce21
Fix UEFI boot, memory allocation, and implement self-contained ISO
google-labs-jules[bot] Mar 17, 2026
29621e9
Implement robust UEFI boot and self-contained ISO architecture
google-labs-jules[bot] Mar 17, 2026
b247183
Fix UEFI boot Page Fault and implement robust FAT-based RAM disk and ISO
google-labs-jules[bot] Mar 18, 2026
e123316
Fix UEFI boot crash and implement True Hybrid ISO with FAT RAM disk
google-labs-jules[bot] Mar 20, 2026
f0c3161
Fix UEFI boot crash and implement multi-partition system support
google-labs-jules[bot] Mar 20, 2026
5619a0e
Fix UEFI Page Fault -32 and 512MB+ volume compatibility
google-labs-jules[bot] Mar 20, 2026
91ecb44
Implement UEFI protocol safety checks and FAT32 compatibility
google-labs-jules[bot] Mar 20, 2026
e777f82
Fix UEFI Page Fault and implement multi-partition FAT32 system
google-labs-jules[bot] Mar 20, 2026
6cdfc69
Implement multi-partition UEFI boot and advanced GDB debugging
google-labs-jules[bot] Mar 21, 2026
ecdba66
Implement Pure Flat Binary architecture and FAT-only VFS
google-labs-jules[bot] Mar 21, 2026
e9aaeee
Fix UEFI boot crash and implement Hybrid-Strong multi-partition ISO
google-labs-jules[bot] Mar 21, 2026
e46d54e
Fix UEFI boot page fault by implementing GPT-ESP layout and OpenProtocol
google-labs-jules[bot] Mar 22, 2026
a51a3db
Fix UEFI boot page fault, implement GPT-ESP layout, and enable early …
google-labs-jules[bot] Mar 22, 2026
c8a1168
Fix UEFI boot crash, implement GPT-ESP layout, and establish freestan…
google-labs-jules[bot] Mar 22, 2026
bbf8ace
Ensure fully freestanding kernel and fix post-ExitBootServices UEFI a…
google-labs-jules[bot] Mar 22, 2026
e245226
Fix UEFI boot crash, implement GPT-ESP layout, and establish freestan…
google-labs-jules[bot] Mar 22, 2026
29f07cd
Enforce strict UEFI/RSL separation and fix boot crash
google-labs-jules[bot] Mar 22, 2026
5d11fa4
Fix UEFI boot crash, enforce 4KB alignment, and strict separation
google-labs-jules[bot] Mar 23, 2026
37027b1
Fix UEFI boot crash, align sections to 4KB, and enforce flat binary
google-labs-jules[bot] Mar 23, 2026
eb839d1
Fix UEFI boot crash, align sections to 4KB, and ensure GOP mapping
google-labs-jules[bot] Mar 23, 2026
857bbc1
Implement Sovereign Paging, fix alignment, and ensure robust handover
google-labs-jules[bot] Mar 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CONFIG_DEBUG_LOGS=y
CONFIG_KERNEL_BASE=0x100000
CONFIG_HEAP_BASE=0x2000000
CONFIG_HEAP_SIZE_MB=8
CONFIG_SCROLL_SPEED=10
CONFIG_EMERALD_MODE=y
CONFIG_FG_COLOR=0xff88
CONFIG_BG_COLOR=0x0
CONFIG_LOAD_SHELL=y
CONFIG_OPTIMIZATION=0
CONFIG_STRICT_CHECKS=y
55 changes: 55 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# OSx2 (RTECH dos) Architecture Rules

## 1. Directory Structure
- `/boot`: UEFI bootloader types and linker scripts.
- `/include`: Public headers and RSL (RTECH Standard Library) definitions.
- `/kernel/unice64`: Core kernel logic and entry points (mains).
- `/kernel/libs`: Internal kernel services and drivers.
- `/programs`: User-space programs (e.g., shell).

## 2. Kernel Lifecycle (The Ritual)
- `main.c` is strictly an orchestrator. It must NOT contain hardware, filesystem, or memory logic.
- Services are registered via `register_service(InitFunction)`.
- The kernel uses an event-driven flow:
- `EVENT_INIT`: Service initialization and setup.
- `EVENT_MAIN`: Main event loop execution.
- `EVENT_CLEANUP`: Shutdown preparation.
- `EVENT_EXIT`: Final termination.

## 3. RSL (RTECH Standard Library)
- RSL is the native system language for OSx2.
- Programs must include ONLY `<rsl.h>` and never internal kernel headers.
- High-level APIs like `readline()` and `color()` are provided for ease of use.

## 4. Memory Model (ARC & Managed RAM)
- OSx2 implements an Automatic Reference Counting (ARC) system for managed heap objects.
- High-level RSL functions (e.g., `readline`, `str_create`) return managed pointers with an initial ref-count of 1.
- Developers use `retain()` to increment and `release()` to decrement reference counts.
- **Note:** In the current v0.x implementation, the backing store is a high-speed bump allocator. While ref-counts are tracked, memory is not yet recycled for reuse. Manual `release()` calls are currently required for future-proofing and consistency with the RSL standard.

## 5. Storage Architecture (/CONNECT & VDISK)
- **Source of Truth**: The `/CONNECT` registry tracks all physical storage (Platters, RAM, USB).
- **Physical nodes**: Each device node has a configuration defining its Sector Size and Total LBA.
- **VDISK Suit**: A Virtual Disk abstraction layer that provides relative LBA access.
- **Signature Handshake**: VDISKs must contain the `0xDEADBEEF` signature at LBA 0 to be considered valid for mounting.
- **Error Handling**: Missing hardware or signature mismatches trigger a `CANNOT FIND DISK` or `Access Denied` error.

## 5. Console & Input
- Console supports full vertical scrolling and manual 8x8 font rendering to the GOP framebuffer.
- Advanced color selection is supported via `color(fg, bg)`.
- Input uses a freestanding PS/2 keyboard driver with Shift support.

## 6. Build Rules
- NO precompiled binaries or object files are allowed in the repository.
- The system must be buildable from pure source using the provided `Makefile`.
- Use `make menuconfig` to configure the kernel features and heap settings.

## 7. Forensic Panic System
- In the event of a fatal loader or kernel error, the system enters an "Autopsy" state.
- CPU registers (RAX-R15) are captured and displayed alongside error messages and status codes.
- Diagnostic data is mirrored to the serial COM1 port (0x3f8) for headless monitoring and logging.

## 8. Development Tools
- `tools/fontgen.html`: A pro-grade web studio to draw fonts and preview colors.
- `scripts/menuconfig.py`: Terminal-based configuration utility (LFS-style).
- `scripts/rnafs_tool.py`: Host-side tool to manage RNAFS disk images and inject files.
79 changes: 79 additions & 0 deletions CODEBASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# OSx2 (RTECH dos) Technical Implementation Blueprint (CODEBASE.md)

This document provides an exhaustive, low-level technical specification of the OSx2 codebase. It describes the implementation logic of every file with enough detail to allow for a complete system reconstruction.

---

## 1. Boot & Entry Layer (`/kernel/unice64`)

### `kernel/unice64/efi_entry.c` (Native UEFI Entry)
- **Purpose**: The "Native Diplomat". Serves as the PE32+ entry point for the firmware.
- **In-Code Logic**:
- **Initialization**: Calls `InitializeLib` (gnu-efi) to setup the UEFI environment.
- **Protocols**:
- Locates `EFI_GRAPHICS_OUTPUT_PROTOCOL` (GOP) to extract the linear framebuffer address, resolution, and scanline width into a `boot_params_t` struct.
- Handles `LOADED_IMAGE_PROTOCOL` and `SIMPLE_FILE_SYSTEM_PROTOCOL` to open the boot volume.
- **File Loading**: Loads `shell.bin` from the ESP into a 48MB fixed memory location (`0x3000000`).
- **Environment Prep**: Allocates memory for the ARC heap and the system ramdisk using `AllocatePages`.
- **The Transition**: Calls `ExitBootServices` to terminate UEFI's control over the hardware, then immediately calls `kernel_main` (passing the populated `boot_params_t`).

---

## 2. Kernel Core Layer (`/kernel/unice64`)

### `kernel/unice64/main.c` (The Orchestrator)
- **Purpose**: Kernel initialization, service registry, and event loop.
- **In-Code Logic**:
- **GDT Reset**: Calls `gdt_init` to re-establish segment descriptors for 64-bit mode after exiting UEFI services.
- **Service Registry**: Iterates through `registered_services` (Console, Memory, Input, FS, etc.) and calls their init functions.
- **Syscall Bridge**: Populates `rsl_syscall_table_t` with function pointers to kernel services.
- **Execution**: Hands over control to the user-space shell by calling `loader_run_shell`.
- **Event Loop**: Enters a `while(running)` loop that triggers `EVENT_MAIN`, allowing for asynchronous background processing.

### `kernel/unice64/gdt.c`
- **Purpose**: CPU segmentation for long mode.
- **In-Code Logic**: Defines a static GDT with Null, Code, and Data descriptors. Loads the GDT using the `lgdt` instruction to ensure the kernel runs in a controlled environment.

---

## 3. Kernel Services Layer (`/kernel/libs`)

### `kernel/libs/connect.c`
- **Purpose**: Physical hardware inventory. Maintains a registry of memory-mapped I/O and RAM regions.

### `kernel/libs/vdisk.c`
- **Purpose**: Storage virtualization layer. Translates virtual LBA requests to physical offsets on the ramdisk or other hardware.

### `kernel/libs/memory.c` (ARC System)
- **Purpose**: Reference-counted memory management.
- **In-Code Logic**: Implements a 'Free List' allocator on top of the UEFI-allocated heap. `alloc` returns ref-counted pointers; `release` decrements the count and returns the block to the free list if it hits zero.

### `kernel/libs/diskman.c`
- **Purpose**: Partition management. Parses GPT (GUID Partition Table) headers and manages VDISK partition mapping.

### `kernel/libs/fs.c` (FAT32 Opaque FS)
- **Purpose**: Universal filesystem layer for VDISKs.
- **In-Code Logic**: Implements a standard FAT32-compatible driver that operates through the VDISK abstraction. This ensures the system can read and write to standard partitions created by external tools like `mtools`.

### `kernel/libs/console.c`
- **Purpose**: Graphics-mode text rendering. Draws 8x8 font characters directly to the GOP framebuffer.

### `kernel/libs/kutils.c` & `kutils.h`
- **Purpose**: Internal utility library. Uses `k_` prefixes (e.g., `k_memcpy`, `k_memset`) to avoid naming collisions with gnu-efi/UEFI symbols.

---

## 4. User Programs Layer (`/programs`)

### `programs/libsystem.c`
- **Purpose**: RTECH Standard Library (RSL) implementation for user-space. Caches the syscall table passed by the kernel.

### `programs/shell.c`
- **Purpose**: Native OSx2 Shell. Provides an interactive interface for file management and system commands.

---

## 5. Build System (`Makefile`)

- **Architecture**: Links all kernel components into a single `kernel.so` shared object, which is then converted to a `BOOTX64.EFI` application using `objcopy`.
- **Emulation**: Uses `qemu-system-x86_64` with the Q35 chipset and OVMF firmware to provide a modern UEFI boot environment.
197 changes: 197 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# OSx2 (RTECH dos) Root Makefile - Native UEFI Edition

CC = gcc
LD = ld
OBJCOPY = objcopy

# Load Configuration
-include .config

# Set defaults if not configured
CONFIG_KERNEL_BASE ?= 0x100000
CONFIG_HEAP_BASE ?= 0x2000000
CONFIG_OPTIMIZATION ?= 0

# Paths
BOOT_DIR = boot
EFI_DIR = $(BOOT_DIR)/EFI/BOOT
KERNEL_DIR = kernel/unice64
LIBS_DIR = kernel/libs

# GNU-EFI Paths
EFI_LIB = /usr/lib
EFI_LDS = /usr/lib/elf_x86_64_efi.lds
EFI_CRT0 = /usr/lib/crt0-efi-x86_64.o

# Flags
# Use EFI flags for the entire kernel now
CFLAGS_EFI = -Iinclude -fno-stack-protector -mno-red-zone -Wall -fno-builtin -m64 -O$(CONFIG_OPTIMIZATION) \
-fpic -fshort-wchar -DEFI_FUNCTION_WRAPPER -I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/efi/protocol

LDFLAGS_EFI = -nostdlib -znocombreloc -z max-page-size=0x1000 -T $(EFI_LDS) -shared -Bsymbolic -L $(EFI_LIB) $(EFI_CRT0)
LDFLAGS_SHELL = -nostdlib -T programs/linker.ld

LIBS_EFI = -lefi -lgnuefi

# Source Files
KERNEL_OBJS = $(KERNEL_DIR)/efi_entry.o \
$(KERNEL_DIR)/main.o \
$(KERNEL_DIR)/gdt.o \
$(KERNEL_DIR)/paging.o \
$(LIBS_DIR)/kutils.o \
$(LIBS_DIR)/console.o \
$(LIBS_DIR)/font_data.o \
$(LIBS_DIR)/input.o \
$(LIBS_DIR)/connect.o \
$(LIBS_DIR)/vdisk.o \
$(LIBS_DIR)/disk.o \
$(LIBS_DIR)/diskman.o \
$(LIBS_DIR)/memory.o \
$(LIBS_DIR)/fs.o \
$(LIBS_DIR)/loader.o \
$(LIBS_DIR)/core/event.o

SHELL_SRCS = programs/entry.S programs/libsystem.c programs/shell.c
SHELL_OBJS = programs/entry.o programs/libsystem.o programs/shell.o

HEADERS = $(shell find include kernel -name "*.h")

# Default Target
all: info prepare $(EFI_DIR)/BOOTX64.EFI $(BOOT_DIR)/os2.bin

info:
@echo "------------------------------------------------"
@echo " OSx2 / RTECH dos Build System (Native UEFI)"
@echo " Optimization Level: -O$(CONFIG_OPTIMIZATION)"
@echo "------------------------------------------------"

prepare:
@if [ ! -f .config ]; then \
python3 scripts/menuconfig.py --save; \
fi

menuconfig:
@python3 scripts/menuconfig.py

# Unified Kernel (Native EFI App)
$(EFI_DIR)/BOOTX64.EFI: kernel.so
@mkdir -p $(EFI_DIR)
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
-j .rodata* --target=efi-app-x86_64 \
--section-alignment 4096 kernel.so $(EFI_DIR)/BOOTX64.EFI

kernel.so: $(KERNEL_OBJS)
$(LD) $(LDFLAGS_EFI) $(KERNEL_OBJS) -o kernel.so $(LIBS_EFI)

$(KERNEL_DIR)/%.o: $(KERNEL_DIR)/%.c $(HEADERS)
$(CC) $(CFLAGS_EFI) -c $< -o $@

$(LIBS_DIR)/%.o: $(LIBS_DIR)/%.c $(HEADERS)
$(CC) $(CFLAGS_EFI) -c $< -o $@

$(LIBS_DIR)/core/%.o: $(LIBS_DIR)/core/%.c $(HEADERS)
$(CC) $(CFLAGS_EFI) -c $< -o $@

# Programs (Pure Flat Binary)
$(BOOT_DIR)/os2.bin: os2.elf
$(OBJCOPY) -O binary --strip-all os2.elf $(BOOT_DIR)/os2.bin
@# Pad to 4KB boundary
@truncate -s %4096 $(BOOT_DIR)/os2.bin

os2.elf: $(SHELL_OBJS)
$(LD) $(LDFLAGS_SHELL) $(SHELL_OBJS) -o os2.elf

programs/%.o: programs/%.c $(HEADERS)
$(CC) -Iinclude -ffreestanding -fno-stack-protector -mno-red-zone -Wall -fno-builtin -m64 -nostdlib -static -c $< -o $@

programs/%.o: programs/%.S
$(CC) -Iinclude -c $< -o $@

# Advanced Tools: Create Bootable UEFI Disk Image (GPT-ESP Edition)
disk: all $(BOOT_DIR)/ramdisk.img
@echo "Creating bootable UEFI disk image (GPT-ESP)..."
dd if=/dev/zero of=disk.img bs=1M count=256
parted disk.img -s mklabel gpt
# Create one large ESP
parted disk.img -s mkpart primary fat32 2048s 100%
parted disk.img -s set 1 esp on

# Format the partition at 1MB offset
mformat -i disk.img@@1M -F -v "OSX2" ::
mmd -i disk.img@@1M ::/EFI
mmd -i disk.img@@1M ::/EFI/BOOT
mcopy -i disk.img@@1M $(EFI_DIR)/BOOTX64.EFI ::/EFI/BOOT/BOOTX64.EFI
mcopy -i disk.img@@1M $(BOOT_DIR)/os2.bin ::/os2.bin
mcopy -i disk.img@@1M $(BOOT_DIR)/ramdisk.img ::/ramdisk.img
echo "FS0:\\EFI\\BOOT\\BOOTX64.EFI" > startup.nsh
mcopy -i disk.img@@1M startup.nsh ::/startup.nsh
rm startup.nsh
@echo "OSx2 UEFI GPT Disk Image Ready (disk.img)."

$(BOOT_DIR)/ramdisk.img:
@echo "Generating system ramdisk..."
dd if=/dev/zero of=$(BOOT_DIR)/ramdisk.img bs=1M count=16
mkfs.vfat -F 32 -n "OSX2_RAM" $(BOOT_DIR)/ramdisk.img

# Create a bootable UEFI ISO (GPT-Hybrid Edition)
iso: all $(BOOT_DIR)/ramdisk.img
@echo "Creating bootable UEFI ISO image (GPT Hybrid)..."
mkdir -p iso/EFI/BOOT

# 1. Create the unified ESP image (includes Loader and Kernel)
dd if=/dev/zero of=esp.img bs=1M count=128
mkfs.vfat -F 32 -n "OSX2" esp.img
mmd -i esp.img ::/EFI
mmd -i esp.img ::/EFI/BOOT
mcopy -i esp.img $(EFI_DIR)/BOOTX64.EFI ::/EFI/BOOT/BOOTX64.EFI
mcopy -i esp.img $(BOOT_DIR)/os2.bin ::/os2.bin
mcopy -i esp.img $(BOOT_DIR)/ramdisk.img ::/ramdisk.img
echo "FS0:\\EFI\\BOOT\\BOOTX64.EFI" > startup.nsh
mcopy -i esp.img startup.nsh ::/startup.nsh
rm startup.nsh

# 2. Create Hybrid ISO
mv esp.img iso/esp.img
xorriso -as mkisofs \
-R -J -V "OSX2_INSTALL" \
-eltorito-platform efi \
-e esp.img -no-emul-boot \
-append_partition 2 0xef iso/esp.img \
-isohybrid-gpt-basdat \
-o boot.iso iso/
@echo "OSx2 Boot ISO Ready (boot.iso)."

run: iso
qemu-system-x86_64 -machine q35 -bios /usr/share/ovmf/OVMF.fd -cdrom boot.iso -m 256M -serial stdio -net none

debug: iso
qemu-system-x86_64 -machine q35 -bios /usr/share/ovmf/OVMF.fd \
-drive file=boot.iso,format=raw \
-m 2G \
-no-reboot -no-shutdown \
-d int,cpu_reset,guest_errors \
-D qemu.log \
-serial stdio \
-monitor vc \
-s -S

gdb:
gdb -ex "target remote localhost:1234" \
-ex "symbol-file kernel.so" \
-ex "set architecture i386:x86-64" \
-ex "layout src" \
-ex "break kernel_main"

setup:
sudo apt-get update
sudo apt-get install -y gnu-efi build-essential qemu-system-x86 ovmf mtools dosfstools xorriso parted gdb

# Cleanup
clean:
@find . -name "*.o" -delete
@rm -f kernel.so $(BOOT_DIR)/os2.bin $(BOOT_DIR)/ramdisk.img disk.img boot.iso
@rm -rf $(BOOT_DIR)/EFI iso
@echo "Build artifacts removed."

.PHONY: all clean disk iso prepare menuconfig info run
18 changes: 18 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef CONFIG_H
#define CONFIG_H

/* Auto-generated by OSx2 menuconfig Professional */

#define CONFIG_DEBUG_LOGS 1
#define CONFIG_KERNEL_BASE 0x100000
#define CONFIG_HEAP_BASE 0x2000000
#define CONFIG_HEAP_SIZE_MB 8
#define CONFIG_SCROLL_SPEED 10
#define CONFIG_EMERALD_MODE 1
#define CONFIG_FG_COLOR 0xff88
#define CONFIG_BG_COLOR 0
#define CONFIG_LOAD_SHELL 1
#define CONFIG_OPTIMIZATION 0
#define CONFIG_STRICT_CHECKS 1

#endif
Loading