diff --git a/examples/typephp-os/Makefile b/examples/typephp-os/Makefile index 4240f006..96547df5 100644 --- a/examples/typephp-os/Makefile +++ b/examples/typephp-os/Makefile @@ -1,6 +1,7 @@ BUILD := build OBJECT_DIR := $(BUILD)/objects BOOTSTRAP_OBJECT := $(OBJECT_DIR)/bootstrap.o +KERNEL64_ENTRY_OBJECT := $(OBJECT_DIR)/kernel64-entry.o PAYLOAD_ELF := $(BUILD)/kernel64.elf PAYLOAD_BIN := $(BUILD)/kernel64.bin PAYLOAD_OBJECT := $(OBJECT_DIR)/kernel64-payload.o @@ -15,8 +16,10 @@ USER_LIBC_OBJECTS := $(OBJECT_DIR)/user-libc.o $(OBJECT_DIR)/user-syscall.o BOOTFLAGS := -m32 -O2 -ffreestanding -fno-pic -fno-pie \ -fno-stack-protector -Wall -Wextra +KERNEL64_BOOTFLAGS := -m64 -O2 -ffreestanding -fno-builtin -fno-pic -fno-pie \ + -fno-stack-protector -mno-red-zone -mcmodel=small -Wall -Wextra USER_CFLAGS := -m64 -O2 -ffreestanding -fno-builtin -fno-pic -fno-pie \ - -fno-stack-protector -mno-red-zone -Wall -Wextra -Iuser/include -Ifreestanding/abi + -fno-stack-protector -mno-red-zone -Wall -Wextra -Iuser/include -Ikernel/core/abi USER_LDFLAGS := -m elf_x86_64 -nostdlib -static -T user/linker.ld .PHONY: all thirdparty payload objects disk run test clean @@ -29,9 +32,10 @@ thirdparty: payload: thirdparty objects cd ../.. && ./bin/tpc.php --nano examples/typephp-os/project.yml -# Only the 32-bit bootstrap requires flags incompatible with the 64-bit Nano -# payload. Ordinary .c/.cc/.S files stay in project.yml sources. -objects: $(BOOTSTRAP_OBJECT) +# Startup sources are built explicitly by Make. The 64-bit entry object is +# injected into tpc's final link through project.yml; the 32-bit Multiboot +# object participates only in the packaging link. +objects: $(BOOTSTRAP_OBJECT) $(KERNEL64_ENTRY_OBJECT) disk: $(DISK) @@ -49,19 +53,22 @@ $(BUILD): $(OBJECT_DIR): mkdir -p $@ -$(BOOTSTRAP_OBJECT): freestanding/boot.S | $(OBJECT_DIR) +$(BOOTSTRAP_OBJECT): boot/boot.S | $(OBJECT_DIR) gcc $(BOOTFLAGS) -c $< -o $@ -$(OBJECT_DIR)/%.o: user/%.c freestanding/abi/typephp_os_syscall.h | $(OBJECT_DIR) +$(KERNEL64_ENTRY_OBJECT): boot/kernel64-entry.S | $(OBJECT_DIR) + gcc $(KERNEL64_BOOTFLAGS) -c $< -o $@ + +$(OBJECT_DIR)/%.o: user/%.c kernel/core/abi/typephp_os_syscall.h | $(OBJECT_DIR) gcc $(USER_CFLAGS) -c $< -o $@ -$(USER_CRT0_OBJECT): user/crt0.S freestanding/abi/typephp_os_syscall.h | $(OBJECT_DIR) +$(USER_CRT0_OBJECT): user/crt0.S kernel/core/abi/typephp_os_syscall.h | $(OBJECT_DIR) gcc $(USER_CFLAGS) -c $< -o $@ -$(OBJECT_DIR)/user-libc.o: user/libc.c freestanding/abi/typephp_os_syscall.h | $(OBJECT_DIR) +$(OBJECT_DIR)/user-libc.o: user/libc.c kernel/core/abi/typephp_os_syscall.h | $(OBJECT_DIR) gcc $(USER_CFLAGS) -c $< -o $@ -$(OBJECT_DIR)/user-syscall.o: user/syscall.S freestanding/abi/typephp_os_syscall.h | $(OBJECT_DIR) +$(OBJECT_DIR)/user-syscall.o: user/syscall.S kernel/core/abi/typephp_os_syscall.h | $(OBJECT_DIR) gcc $(USER_CFLAGS) -c $< -o $@ $(USER_SH_ELF): $(OBJECT_DIR)/sh.o $(USER_CRT0_OBJECT) $(USER_LIBC_OBJECTS) user/linker.ld | $(BUILD) @@ -75,7 +82,7 @@ $(KERNEL): payload objcopy -I binary -O elf32-i386 -B i386 \ --rename-section .data=.payload,alloc,load,readonly,data,contents \ $(PAYLOAD_BIN) $(PAYLOAD_OBJECT) - ld -m elf_i386 -T freestanding/linker.ld -o $@ \ + ld -m elf_i386 -T boot/linker.ld -o $@ \ $(BOOTSTRAP_OBJECT) $(PAYLOAD_OBJECT) run: all diff --git a/examples/typephp-os/README.md b/examples/typephp-os/README.md index 3fb5f8ac..0954b5bb 100644 --- a/examples/typephp-os/README.md +++ b/examples/typephp-os/README.md @@ -15,6 +15,19 @@ The architectural rules and staged plan are maintained in ## Architecture +The source tree is split by execution role: + +```text +boot/ Make-built startup assembly and linker scripts +kernel/*.php TypePHP kernel implementation +kernel/core/ Native kernel implementation compiled by tpc +kernel/core/abi/ Freestanding C/POSIX and C++ compatibility boundary +user/ Independently built Ring-3 programs and bootstrap libc +``` + +Additional TypePHP kernel files stay directly under `kernel/` until a concrete +subsystem boundary justifies another directory. + There is no kernel-specific tpc mode or reduced PHP Nano profile. The 64-bit payload is compiled with the normal command: @@ -23,7 +36,7 @@ payload is compiled with the normal command: ``` This composes the complete php-nano and PHPX source manifests. The TypePHP OS -project owns the freestanding boundary under `freestanding/abi`: implemented +project owns the freestanding boundary under `kernel/core/abi`: implemented C/POSIX and C++ ABI functions live there, while APIs required for linking but not implemented by the kernel are exported as panic stubs. Consequently an unsupported operation fails immediately with its ABI symbol instead of @@ -79,11 +92,14 @@ Run the automated serial-output smoke test with: make test ``` -The Makefile compiles the 32-bit Multiboot bootstrap externally because its -`-m32` ABI cannot participate in the 64-bit payload link. It also builds the +The Makefile compiles the startup sources under `boot/` directly. The 32-bit +Multiboot bootstrap cannot participate in the 64-bit payload link; the 64-bit +entry object is injected into tpc's final link through the generic `objects` +setting. The Makefile also builds the deliberately small freestanding C userspace ELF files and installs them into the FAT16 image with `mcopy`. All ordinary -64-bit `.c`, `.cc`, and `.S` files remain in `project.yml` and use tpc's generic +kernel `.php`, `.c`, `.cc`, and `.S` files live under `kernel/`, remain in +`project.yml`, and use tpc's generic `c-flags`, `cxx-flags`, and `asm-flags`. The user executables are not linked into the kernel payload. The architecture-changing bootstrap is combined during the final packaging link. diff --git a/examples/typephp-os/ROADMAP.md b/examples/typephp-os/ROADMAP.md index ffdb61a6..42ecfbfa 100644 --- a/examples/typephp-os/ROADMAP.md +++ b/examples/typephp-os/ROADMAP.md @@ -16,11 +16,12 @@ behavior. - Cross-project changes must use generally useful portability contracts such as `PHP_NANO_NO_LIBC`, `PHPX_NO_EXCEPTION`, and `PHPX_NO_RTTI`; product-specific conditionals are not allowed in PHP Nano or PHPX. -- Ordinary same-ABI source files and flags belong in `project.yml`. Translation - units that require incompatible per-file options are built by Make and may - be linked through tpc's generic `objects` facility when their ABI matches. - Architecture packaging and ELF/binary conversion happen after tpc emits the - 64-bit ELF. +- Ordinary kernel sources live under `kernel/`; the TypePHP entry files are at + that directory's top level and the native implementation is under + `kernel/core/`. Same-ABI source files and flags belong in `project.yml`. + Startup sources live under `boot/` and are built by Make; compatible objects + may be linked through tpc's generic `objects` facility. Architecture + packaging and ELF/binary conversion happen after tpc emits the 64-bit ELF. - Every completed milestone must pass the serial-output QEMU smoke test and leave the 64-bit payload with no undefined symbols. diff --git a/examples/typephp-os/freestanding/boot.S b/examples/typephp-os/boot/boot.S similarity index 100% rename from examples/typephp-os/freestanding/boot.S rename to examples/typephp-os/boot/boot.S diff --git a/examples/typephp-os/freestanding/kernel64-entry.S b/examples/typephp-os/boot/kernel64-entry.S similarity index 100% rename from examples/typephp-os/freestanding/kernel64-entry.S rename to examples/typephp-os/boot/kernel64-entry.S diff --git a/examples/typephp-os/freestanding/kernel64.ld b/examples/typephp-os/boot/kernel64.ld similarity index 100% rename from examples/typephp-os/freestanding/kernel64.ld rename to examples/typephp-os/boot/kernel64.ld diff --git a/examples/typephp-os/freestanding/linker.ld b/examples/typephp-os/boot/linker.ld similarity index 100% rename from examples/typephp-os/freestanding/linker.ld rename to examples/typephp-os/boot/linker.ld diff --git a/examples/typephp-os/freestanding/abi/cxx.cpp b/examples/typephp-os/kernel/core/abi/cxx.cpp similarity index 100% rename from examples/typephp-os/freestanding/abi/cxx.cpp rename to examples/typephp-os/kernel/core/abi/cxx.cpp diff --git a/examples/typephp-os/freestanding/abi/libc.c b/examples/typephp-os/kernel/core/abi/libc.c similarity index 100% rename from examples/typephp-os/freestanding/abi/libc.c rename to examples/typephp-os/kernel/core/abi/libc.c diff --git a/examples/typephp-os/freestanding/abi/typephp_os_abi.h b/examples/typephp-os/kernel/core/abi/typephp_os_abi.h similarity index 100% rename from examples/typephp-os/freestanding/abi/typephp_os_abi.h rename to examples/typephp-os/kernel/core/abi/typephp_os_abi.h diff --git a/examples/typephp-os/freestanding/abi/typephp_os_syscall.h b/examples/typephp-os/kernel/core/abi/typephp_os_syscall.h similarity index 100% rename from examples/typephp-os/freestanding/abi/typephp_os_syscall.h rename to examples/typephp-os/kernel/core/abi/typephp_os_syscall.h diff --git a/examples/typephp-os/freestanding/abi/unimplemented.S b/examples/typephp-os/kernel/core/abi/unimplemented.S similarity index 100% rename from examples/typephp-os/freestanding/abi/unimplemented.S rename to examples/typephp-os/kernel/core/abi/unimplemented.S diff --git a/examples/typephp-os/freestanding/ata.c b/examples/typephp-os/kernel/core/ata.c similarity index 100% rename from examples/typephp-os/freestanding/ata.c rename to examples/typephp-os/kernel/core/ata.c diff --git a/examples/typephp-os/freestanding/bridge.cc b/examples/typephp-os/kernel/core/bridge.cc similarity index 100% rename from examples/typephp-os/freestanding/bridge.cc rename to examples/typephp-os/kernel/core/bridge.cc diff --git a/examples/typephp-os/freestanding/filesystem_abi.cc b/examples/typephp-os/kernel/core/filesystem_abi.cc similarity index 100% rename from examples/typephp-os/freestanding/filesystem_abi.cc rename to examples/typephp-os/kernel/core/filesystem_abi.cc diff --git a/examples/typephp-os/freestanding/kernel.c b/examples/typephp-os/kernel/core/kernel.c similarity index 100% rename from examples/typephp-os/freestanding/kernel.c rename to examples/typephp-os/kernel/core/kernel.c diff --git a/examples/typephp-os/freestanding/memory.c b/examples/typephp-os/kernel/core/memory.c similarity index 100% rename from examples/typephp-os/freestanding/memory.c rename to examples/typephp-os/kernel/core/memory.c diff --git a/examples/typephp-os/freestanding/process-entry.S b/examples/typephp-os/kernel/core/process-entry.S similarity index 100% rename from examples/typephp-os/freestanding/process-entry.S rename to examples/typephp-os/kernel/core/process-entry.S diff --git a/examples/typephp-os/freestanding/process.c b/examples/typephp-os/kernel/core/process.c similarity index 100% rename from examples/typephp-os/freestanding/process.c rename to examples/typephp-os/kernel/core/process.c diff --git a/examples/typephp-os/freestanding/time.c b/examples/typephp-os/kernel/core/time.c similarity index 100% rename from examples/typephp-os/freestanding/time.c rename to examples/typephp-os/kernel/core/time.c diff --git a/examples/typephp-os/freestanding/vm.c b/examples/typephp-os/kernel/core/vm.c similarity index 100% rename from examples/typephp-os/freestanding/vm.c rename to examples/typephp-os/kernel/core/vm.c diff --git a/examples/typephp-os/freestanding/vm.h b/examples/typephp-os/kernel/core/vm.h similarity index 100% rename from examples/typephp-os/freestanding/vm.h rename to examples/typephp-os/kernel/core/vm.h diff --git a/examples/typephp-os/freestanding/zend-allocator.c b/examples/typephp-os/kernel/core/zend-allocator.c similarity index 100% rename from examples/typephp-os/freestanding/zend-allocator.c rename to examples/typephp-os/kernel/core/zend-allocator.c diff --git a/examples/typephp-os/src/fat16.php b/examples/typephp-os/kernel/fat16.php similarity index 100% rename from examples/typephp-os/src/fat16.php rename to examples/typephp-os/kernel/fat16.php diff --git a/examples/typephp-os/src/filesystem.php b/examples/typephp-os/kernel/filesystem.php similarity index 100% rename from examples/typephp-os/src/filesystem.php rename to examples/typephp-os/kernel/filesystem.php diff --git a/examples/typephp-os/src/fs_bridge.stub.php b/examples/typephp-os/kernel/fs_bridge.stub.php similarity index 100% rename from examples/typephp-os/src/fs_bridge.stub.php rename to examples/typephp-os/kernel/fs_bridge.stub.php diff --git a/examples/typephp-os/src/hardware.stub.php b/examples/typephp-os/kernel/hardware.stub.php similarity index 100% rename from examples/typephp-os/src/hardware.stub.php rename to examples/typephp-os/kernel/hardware.stub.php diff --git a/examples/typephp-os/src/kernel.php b/examples/typephp-os/kernel/kernel.php similarity index 100% rename from examples/typephp-os/src/kernel.php rename to examples/typephp-os/kernel/kernel.php diff --git a/examples/typephp-os/project.yml b/examples/typephp-os/project.yml index 20deceee..99fe2262 100644 --- a/examples/typephp-os/project.yml +++ b/examples/typephp-os/project.yml @@ -1,27 +1,15 @@ name: typephp_os mode: bin sources: - - src - - freestanding/kernel64-entry.S - - freestanding/process-entry.S - - freestanding/kernel.c - - freestanding/memory.c - - freestanding/vm.c - - freestanding/process.c - - freestanding/time.c - - freestanding/ata.c - - freestanding/zend-allocator.c - - freestanding/bridge.cc - - freestanding/filesystem_abi.cc - - freestanding/abi/libc.c - - freestanding/abi/cxx.cpp - - freestanding/abi/unimplemented.S + - kernel - thirdparty/openlibm/src +objects: + - build/objects/kernel64-entry.o build-dir: build/generated output: build/kernel64.elf cxx-std: c++17 include-paths: - - freestanding/abi + - kernel/core/abi - thirdparty/openlibm/include - thirdparty/openlibm/src - thirdparty/openlibm/amd64 @@ -64,5 +52,5 @@ ld-flags: - -no-pie - -Wl,-m,elf_x86_64 - -Wl,--build-id=none - - -Wl,-T,examples/typephp-os/freestanding/kernel64.ld + - -Wl,-T,examples/typephp-os/boot/kernel64.ld - -lgcc