Optimize directory structure

master
韩天峰 4 weeks ago
parent e5dd06b289
commit d1085f68f8
  1. 27
      examples/typephp-os/Makefile
  2. 24
      examples/typephp-os/README.md
  3. 11
      examples/typephp-os/ROADMAP.md
  4. 0
      examples/typephp-os/boot/boot.S
  5. 0
      examples/typephp-os/boot/kernel64-entry.S
  6. 0
      examples/typephp-os/boot/kernel64.ld
  7. 0
      examples/typephp-os/boot/linker.ld
  8. 0
      examples/typephp-os/kernel/core/abi/cxx.cpp
  9. 0
      examples/typephp-os/kernel/core/abi/libc.c
  10. 0
      examples/typephp-os/kernel/core/abi/typephp_os_abi.h
  11. 0
      examples/typephp-os/kernel/core/abi/typephp_os_syscall.h
  12. 0
      examples/typephp-os/kernel/core/abi/unimplemented.S
  13. 0
      examples/typephp-os/kernel/core/ata.c
  14. 0
      examples/typephp-os/kernel/core/bridge.cc
  15. 0
      examples/typephp-os/kernel/core/filesystem_abi.cc
  16. 0
      examples/typephp-os/kernel/core/kernel.c
  17. 0
      examples/typephp-os/kernel/core/memory.c
  18. 0
      examples/typephp-os/kernel/core/process-entry.S
  19. 0
      examples/typephp-os/kernel/core/process.c
  20. 0
      examples/typephp-os/kernel/core/time.c
  21. 0
      examples/typephp-os/kernel/core/vm.c
  22. 0
      examples/typephp-os/kernel/core/vm.h
  23. 0
      examples/typephp-os/kernel/core/zend-allocator.c
  24. 0
      examples/typephp-os/kernel/fat16.php
  25. 0
      examples/typephp-os/kernel/filesystem.php
  26. 0
      examples/typephp-os/kernel/fs_bridge.stub.php
  27. 0
      examples/typephp-os/kernel/hardware.stub.php
  28. 0
      examples/typephp-os/kernel/kernel.php
  29. 22
      examples/typephp-os/project.yml

@ -1,6 +1,7 @@
BUILD := build BUILD := build
OBJECT_DIR := $(BUILD)/objects OBJECT_DIR := $(BUILD)/objects
BOOTSTRAP_OBJECT := $(OBJECT_DIR)/bootstrap.o BOOTSTRAP_OBJECT := $(OBJECT_DIR)/bootstrap.o
KERNEL64_ENTRY_OBJECT := $(OBJECT_DIR)/kernel64-entry.o
PAYLOAD_ELF := $(BUILD)/kernel64.elf PAYLOAD_ELF := $(BUILD)/kernel64.elf
PAYLOAD_BIN := $(BUILD)/kernel64.bin PAYLOAD_BIN := $(BUILD)/kernel64.bin
PAYLOAD_OBJECT := $(OBJECT_DIR)/kernel64-payload.o 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 \ BOOTFLAGS := -m32 -O2 -ffreestanding -fno-pic -fno-pie \
-fno-stack-protector -Wall -Wextra -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 \ 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 USER_LDFLAGS := -m elf_x86_64 -nostdlib -static -T user/linker.ld
.PHONY: all thirdparty payload objects disk run test clean .PHONY: all thirdparty payload objects disk run test clean
@ -29,9 +32,10 @@ thirdparty:
payload: thirdparty objects payload: thirdparty objects
cd ../.. && ./bin/tpc.php --nano examples/typephp-os/project.yml cd ../.. && ./bin/tpc.php --nano examples/typephp-os/project.yml
# Only the 32-bit bootstrap requires flags incompatible with the 64-bit Nano # Startup sources are built explicitly by Make. The 64-bit entry object is
# payload. Ordinary .c/.cc/.S files stay in project.yml sources. # injected into tpc's final link through project.yml; the 32-bit Multiboot
objects: $(BOOTSTRAP_OBJECT) # object participates only in the packaging link.
objects: $(BOOTSTRAP_OBJECT) $(KERNEL64_ENTRY_OBJECT)
disk: $(DISK) disk: $(DISK)
@ -49,19 +53,22 @@ $(BUILD):
$(OBJECT_DIR): $(OBJECT_DIR):
mkdir -p $@ mkdir -p $@
$(BOOTSTRAP_OBJECT): freestanding/boot.S | $(OBJECT_DIR) $(BOOTSTRAP_OBJECT): boot/boot.S | $(OBJECT_DIR)
gcc $(BOOTFLAGS) -c $< -o $@ 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 $@ 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 $@ 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 $@ 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 $@ gcc $(USER_CFLAGS) -c $< -o $@
$(USER_SH_ELF): $(OBJECT_DIR)/sh.o $(USER_CRT0_OBJECT) $(USER_LIBC_OBJECTS) user/linker.ld | $(BUILD) $(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 \ objcopy -I binary -O elf32-i386 -B i386 \
--rename-section .data=.payload,alloc,load,readonly,data,contents \ --rename-section .data=.payload,alloc,load,readonly,data,contents \
$(PAYLOAD_BIN) $(PAYLOAD_OBJECT) $(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) $(BOOTSTRAP_OBJECT) $(PAYLOAD_OBJECT)
run: all run: all

@ -15,6 +15,19 @@ The architectural rules and staged plan are maintained in
## Architecture ## 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 There is no kernel-specific tpc mode or reduced PHP Nano profile. The 64-bit
payload is compiled with the normal command: 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 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 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 not implemented by the kernel are exported as panic stubs. Consequently an
unsupported operation fails immediately with its ABI symbol instead of unsupported operation fails immediately with its ABI symbol instead of
@ -79,11 +92,14 @@ Run the automated serial-output smoke test with:
make test make test
``` ```
The Makefile compiles the 32-bit Multiboot bootstrap externally because its The Makefile compiles the startup sources under `boot/` directly. The 32-bit
`-m32` ABI cannot participate in the 64-bit payload link. It also builds the 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 deliberately small freestanding C userspace ELF files and installs them into
the FAT16 image with `mcopy`. All ordinary 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 `c-flags`, `cxx-flags`, and `asm-flags`. The user executables are not linked
into the kernel payload. The architecture-changing bootstrap is combined into the kernel payload. The architecture-changing bootstrap is combined
during the final packaging link. during the final packaging link.

@ -16,11 +16,12 @@ behavior.
- Cross-project changes must use generally useful portability contracts such - Cross-project changes must use generally useful portability contracts such
as `PHP_NANO_NO_LIBC`, `PHPX_NO_EXCEPTION`, and `PHPX_NO_RTTI`; product-specific as `PHP_NANO_NO_LIBC`, `PHPX_NO_EXCEPTION`, and `PHPX_NO_RTTI`; product-specific
conditionals are not allowed in PHP Nano or PHPX. conditionals are not allowed in PHP Nano or PHPX.
- Ordinary same-ABI source files and flags belong in `project.yml`. Translation - Ordinary kernel sources live under `kernel/`; the TypePHP entry files are at
units that require incompatible per-file options are built by Make and may that directory's top level and the native implementation is under
be linked through tpc's generic `objects` facility when their ABI matches. `kernel/core/`. Same-ABI source files and flags belong in `project.yml`.
Architecture packaging and ELF/binary conversion happen after tpc emits the Startup sources live under `boot/` and are built by Make; compatible objects
64-bit ELF. 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 - Every completed milestone must pass the serial-output QEMU smoke test and
leave the 64-bit payload with no undefined symbols. leave the 64-bit payload with no undefined symbols.

@ -1,27 +1,15 @@
name: typephp_os name: typephp_os
mode: bin mode: bin
sources: sources:
- src - kernel
- 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
- thirdparty/openlibm/src - thirdparty/openlibm/src
objects:
- build/objects/kernel64-entry.o
build-dir: build/generated build-dir: build/generated
output: build/kernel64.elf output: build/kernel64.elf
cxx-std: c++17 cxx-std: c++17
include-paths: include-paths:
- freestanding/abi - kernel/core/abi
- thirdparty/openlibm/include - thirdparty/openlibm/include
- thirdparty/openlibm/src - thirdparty/openlibm/src
- thirdparty/openlibm/amd64 - thirdparty/openlibm/amd64
@ -64,5 +52,5 @@ ld-flags:
- -no-pie - -no-pie
- -Wl,-m,elf_x86_64 - -Wl,-m,elf_x86_64
- -Wl,--build-id=none - -Wl,--build-id=none
- -Wl,-T,examples/typephp-os/freestanding/kernel64.ld - -Wl,-T,examples/typephp-os/boot/kernel64.ld
- -lgcc - -lgcc

Loading…
Cancel
Save