Skip to content
Merged

Hw #17

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
7776704
Some fixes for the rpi5 and compatibility with 3, but still no uart o…
Jul 10, 2025
03e85e4
Fixes for 3b
Jul 11, 2025
ae8033a
Don't crash if no usb device found
Jul 11, 2025
3010a1a
Added new commands for dump and install
Jul 13, 2025
acfa8dd
SDHCI address fi
Jul 13, 2025
1ca0805
UART fixes
Jul 13, 2025
f22dd28
Fixed GIC address
Jul 13, 2025
f3ddb20
timer fix
Jul 13, 2025
ee904cf
using carriage return in exception handlers
Jul 14, 2025
a09c79d
New GIC addresses for 5
Jul 14, 2025
b3cf580
fixed l0 addressing
Jul 14, 2025
398330e
defined some mmu bits
Jul 14, 2025
6af89bf
cleaned up boot code with defined values
Jul 14, 2025
177e8e8
Added hypervisor timer config to sysregs
Jul 14, 2025
014d718
Newline after system halted, since double exceptions can still happen
Jul 14, 2025
7686516
Removing double disable interrupt
Jul 14, 2025
706497d
SPSR on el3
Jul 14, 2025
89995e1
write32 on irq to prevent a SErrror
Jul 14, 2025
0fead96
Restored one write8
Jul 15, 2025
49809d6
proper table naming
Jul 15, 2025
acd48f3
Made BootSM a pointer
Jul 15, 2025
23ee3ff
Using spsr for currentEL in syscalls
Jul 15, 2025
e9c0aeb
input driver validity check
Jul 15, 2025
0a0517d
Marking gpu framebuffer as reserved
Jul 15, 2025
daf5f9c
Made clear use a normal drawing as opposed to the 32bit version to av…
Jul 15, 2025
6f2597d
Only overwrite x0 in syscall when there's a value to write, save sp b…
Jul 15, 2025
3d139c6
extra safety check in bootsm
Jul 16, 2025
c12b7f4
cleaned up videocore code
Jul 16, 2025
0600301
Tag fixes
Jul 16, 2025
0db48a6
Color fixes
Jul 16, 2025
8a7e19d
all mailbox calls use defined tags & fixed error screen colors
Jul 17, 2025
12efe76
Moved more peripherals to PI5 switch
Jul 17, 2025
5d047b1
v2 sd card fix
Jul 17, 2025
8ebf0ca
Added uint32max
Jul 17, 2025
6f19ff3
read 32 bit memory unaligned, mbr support for fat32
Jul 17, 2025
6372e6e
[UNTESTED] ExFat support for partition offset
Jul 17, 2025
49bb498
Using PCI Base instead of USE_PCI
Jul 18, 2025
696be09
unaligned access improvements
Jul 18, 2025
38a30e9
First iteration xhci improvements for pi compatibility
Jul 18, 2025
09497c1
removed extra wait
Jul 18, 2025
023918b
renamed xhci types to usb types and changed interrupt for xhci to 36
Jul 18, 2025
14dcd94
Fail setup of device if addressing fails
Jul 18, 2025
c151975
Port reset fixes
Jul 18, 2025
603a3f3
updated make, string and kstring
CodeAnarchist Jul 18, 2025
8a70918
Update kstring.c
CodeAnarchist Jul 18, 2025
5578ed5
Update string.c
CodeAnarchist Jul 18, 2025
4cb9557
Update kstring.c
CodeAnarchist Jul 18, 2025
e5e1e15
renamed port_status_control
Jul 19, 2025
749f2e3
Removed wrong TODOs
Jul 19, 2025
0c0ea4c
Renamed XHCI IRQ to input IRQ
Jul 19, 2025
1336a99
Moved xhci structs to own file
Jul 19, 2025
7c70c13
renamed xhci_device_types to usb_device_types
Jul 19, 2025
3af599a
defines in UART for legibility
Jul 19, 2025
c6c4b5a
removed unused property
Jul 19, 2025
da280a9
[xHCI] padding for context, currently compile-time defined
Jul 19, 2025
38d4e8a
[xHCI] fixed variable value
Jul 19, 2025
649e0a0
Fixes for configure endpoints
Jul 20, 2025
5d94bbd
v2 card addressing
Jul 20, 2025
8211381
implemented linked list, chunked list, ring buffer
CodeAnarchist Jul 20, 2025
ad7568c
Merge branch 'hw' into hw
CodeAnarchist Jul 20, 2025
28c285f
Update Makefile
CodeAnarchist Jul 20, 2025
ed32ada
Update Makefile
CodeAnarchist Jul 20, 2025
f69363c
Read correct register size in pci
Jul 21, 2025
6a70547
Don't try to enable other GPUs for RPI
Jul 21, 2025
40b6cfe
Do not attempt to enable virtio net on rpi
Jul 21, 2025
c9cf5b3
[xHCI] Check if driver uses interrupts rather than hardcoding device …
Jul 21, 2025
b958079
[xHCI] restored old timeout of 2 seconds for events
Jul 21, 2025
34930ee
[xHCI] more fail condition logs
Jul 21, 2025
cc34c72
[xHCI] Fixes for PCI
Jul 21, 2025
691e25a
[PCI] enable for PI 5
Jul 21, 2025
79b79a7
[PCI, FAIL] Setup MSIX for RP1
Jul 21, 2025
9a229f0
queues and double linkedlist
CodeAnarchist Jul 21, 2025
888d181
Fix for 0-timeout wait
Jul 22, 2025
e2609cc
return false on interrupt set since it's not working
Jul 22, 2025
76d3efd
[xHCI] allowing for simulating interrupts
Jul 22, 2025
5a7d58b
[UI] login color fixes
Jul 22, 2025
84e3611
[xHCI] do not pass on error events
Jul 22, 2025
b65a56a
[xHCI] repeat request on timeout and set configuration to activate de…
Jul 22, 2025
6c661ef
[PROJ] added dtbs and updated README
Jul 23, 2025
a3a0e0a
[PROJ] fixed run scripts for linux
Jul 22, 2025
23519f8
[PROJ] display fix for mac
Jul 23, 2025
57ea33f
[USB] return true for DWC2 only if there's new input
Jul 23, 2025
6425f5d
USB polling through process
Jul 23, 2025
4f9e2e3
Fixes to allow disk being optional
Jul 23, 2025
1ba3c2c
[USB] init polling process for input
Jul 23, 2025
68fbeba
Fixed issue with sdhci addressing
Jul 23, 2025
20aaf4f
[PROC] test process colors
Jul 24, 2025
a7a9675
[INPUT] use keypad enter as alternative to enter
Jul 24, 2025
a5f68b2
syscall return fix
Jul 24, 2025
35ed200
[FS] reverted wrong offsets
Jul 24, 2025
3ff7a18
[PROC, TEMP] Disable process monitor on real hw due to a weird bug
Jul 24, 2025
fa43484
[UI] fixed process label colors
Jul 24, 2025
0c4f793
[MEM] gpu clear, memset and login optimizations
Jul 24, 2025
f2c432d
Merge branch 'hw' into hw
CodeAnarchist Jul 24, 2025
acb06c7
fixed display variable
Jul 25, 2025
91bc774
Merge branch 'main' into hw
Jul 25, 2025
819bb10
[PROJ] Added variable for GPU
Jul 25, 2025
604fbf6
[MEM] replaced talloc with alloc_in_page in virtio gpu
Jul 25, 2025
662226f
[MEM] using new allocator for virtio framebuffer
Jul 25, 2025
33bd876
[MEM] fixed virtio descriptor alignment issue
Jul 25, 2025
582a73e
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
b9aa116
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
c7a2896
Update kconsole.h
CodeAnarchist Jul 25, 2025
2673f8e
Update kconsole.hpp
CodeAnarchist Jul 25, 2025
9a58907
Update fat32.cpp
CodeAnarchist Jul 25, 2025
38b04b7
Update kstring.c
CodeAnarchist Jul 25, 2025
c0e6bd8
Update chunked_list.cpp
CodeAnarchist Jul 25, 2025
6d5119b
Update chunked_list.hpp
CodeAnarchist Jul 25, 2025
18617b9
Update doubly_linked_list.cpp
CodeAnarchist Jul 25, 2025
b4c7d89
Update doubly_linked_list.hpp
CodeAnarchist Jul 25, 2025
3e0badc
Update linked_list.cpp
CodeAnarchist Jul 25, 2025
31aa644
Update linked_list.hpp
CodeAnarchist Jul 25, 2025
8711102
Update queue.cpp
CodeAnarchist Jul 25, 2025
6aaca80
Update queue.hpp
CodeAnarchist Jul 25, 2025
065b9d1
Update ring_buffer.cpp
CodeAnarchist Jul 25, 2025
1967c8f
Update ring_buffer.hpp
CodeAnarchist Jul 25, 2025
6cf11c5
Update string.c
CodeAnarchist Jul 25, 2025
1292655
Update doubly_linked_list.hpp
CodeAnarchist Jul 25, 2025
38b796c
Update Makefile
CodeAnarchist Jul 25, 2025
4ac1ef8
Update Makefile
CodeAnarchist Jul 25, 2025
4ad766f
Update Makefile
CodeAnarchist Jul 25, 2025
5bd3dfe
Update kconsole.cpp
CodeAnarchist Jul 25, 2025
067282e
Update Makefile
CodeAnarchist Jul 25, 2025
0fb02c5
split data structures in .c/.h and .hpp
CodeAnarchist Jul 25, 2025
0d2d55f
rem xhci types h
CodeAnarchist Jul 25, 2025
29f68f9
Merge pull request #16 from CodeAnarchist/hw
Jul 25, 2025
e1694b6
[VIRT] wait function in virt intialization
Jul 25, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ libshared.a
*.a
dump.dtb
fs
dump
*.cfg
83 changes: 72 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
MODE ?= virt
LOAD_ADDR ?= 0x41000000
#top make
ARCH ?= aarch64-none-elf
CC := $(ARCH)-gcc
LD := $(ARCH)-ld
AR := $(ARCH)-ar
OBJCOPY := $(ARCH)-objcopy

.PHONY: all kernel user shared clean raspi virt run debug
#common flags
CFLAGS_BASE ?= -g -O0 -std=c17 -nostdlib -ffreestanding \
-fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables \
-Wall -Wextra -mcpu=cortex-a72
LDFLAGS_BASE ?=

#build vars
LOAD_ADDR ?= 0x41000000
XHCI_CTX_SIZE ?= 32
QEMU ?= true
MODE ?= virt

#export
export ARCH CC LD AR OBJCOPY CFLAGS_BASE LDFLAGS_BASE LOAD_ADDR XHCI_CTX_SIZE QEMU

#config filesystem
OS := $(shell uname)
FS_DIRS := fs/redos/user

ifeq ($(OS),Darwin)
BOOTFS := /Volumes/bootfs
else
BOOTFS := /media/bootfs
endif

#targets
.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install

all: shared user kernel
@echo "Build complete."
Expand All @@ -10,27 +40,58 @@ all: shared user kernel
shared:
$(MAKE) -C shared

user:
user: prepare-fs
$(MAKE) -C user

kernel:
$(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR)
$(MAKE) -C kernel LOAD_ADDR=$(LOAD_ADDR) XHCI_CTX_SIZE=$(XHCI_CTX_SIZE) QEMU=$(QEMU)

clean:
$(MAKE) -C shared clean
$(MAKE) -C user clean
$(MAKE) -C kernel clean
$(MAKE) -C user clean
@echo "removing fs dirs"
rm -rf $(FS_DIRS)
@echo "removing images"
rm -f kernel.img kernel.elf disk.img dump

raspi:
$(MAKE) LOAD_ADDR=0x80000 all
$(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=true all

virt:
$(MAKE) LOAD_ADDR=0x41000000 all
$(MAKE) LOAD_ADDR=0x41000000 XHCI_CTX_SIZE=32 QEMU=true all

run:
$(MAKE) $(MODE)
./run_$(MODE)

debug:
$(MAKE) $(MODE)
./rundebug MODE=$(MODE) $(ARGS)

dump:
$(OBJCOPY) -O binary kernel.elf kernel.img
aarch64-none-elf-objdump -D kernel.elf > dump

install:
$(MAKE) clean
$(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=false all
cp kernel.img $(BOOTFS)/kernel8.img
cp kernel.img $(BOOTFS)/kernel_2712.img
cp config.txt $(BOOTFS)/config.txt

run:
$(MAKE) $(MODE)
./run_$(MODE)
prepare-fs:
@echo "creating dirs"
@mkdir -p $(FS_DIRS)

help:
@printf "usage:\n\
make all build the os\n\
make clean remove all build artifacts\n\
make raspi build for raspberry\n\
make virt build for qemu virt board\n\
make run build and run in virt mode\n\
make debug build and run with debugger\n\
make dump disassemble kernel.elf\n\
make install create raspi kernel and mount it on a bootable partition\n\
make prepare-fs create directories for the filesystem\n\n"
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Summary

The REDACTED Operating System is a 64 bit operating system meant to run on ARM processors.
It currently runs entirely in QEMU, either in an entirely virtual machine using QEMU's `virt` board, or emulating a Raspberry Pi 4B. It currently most likely will not work on real hardware (not on the raspi 5 anyway, haven't tested on a 4B)
It can run entirely in QEMU, either in an entirely virtual machine using QEMU's `virt` board, or emulating a Raspberry Pi 4B.
It also has preliminary support for the Raspberry Pi 5, and possibly 4B and 3B, though these last two are largely untested.
Its GUI is heavily inspired by video game consoles, and the OS is entirely controllable via keyboard (with future mouse and possibly gamepad support)
It has limited support for third party processes, currently limited to entirely self-contained programs. The `shared` library is provided for syscalls and common functions but it should be used as a static library embedded into the final executable `.elf` file.

Expand Down Expand Up @@ -53,7 +54,7 @@ In addition to the code located in the system's 3 main folders, a few other file
- debug: attaches gdb to an instance of QEMU running REDACTED OS. The instance must be run with the `debug` argument as `./run debug` in order for gdb to attach and control its execution. It can support automatically running a command inside gdb such as adding a breakpoint by passing it as an argument as `./debug b kernel_main`
- rundebug: a shortcut for running both the `run` and `debug` commands. It can pass arguments for the debug command, which in turn will pass them to gdb
- createfs: creates a filesystem image for the system to read. The image does not contain kernel code and is not used to boot the system, but is still required to boot the system, and contains user processes. The script is written specifically for macOS, as it relies on the diskutil commands to create the image. There isn't a linux or windows version for it, but a filesystem image can be created manually and placed in the root directory with the name disk.img
- Makefile: can compile and run the system. `make run` compiles the system for the virt board, passing MODE=virt/raspi specifies which board to compile for. It creates the filesystem image and executes the correct `./run` command. `make debug` compiles the system, creates the filesystem and executes the OS and gdb, through the `./rundebug` command. `make all` simply compiles and creates the filesystem image. `make clean` cleans compiled files.
- Makefile: can compile and run the system. `make run` compiles the system for the virt board, passing MODE=virt/raspi specifies which board to compile for, default is virt. It creates the filesystem image and executes the correct `./run` command. `make debug` compiles the system, creates the filesystem and executes the OS and gdb, through the `./rundebug` command. `make all` simply compiles and creates the filesystem image. `make clean` cleans compiled files. The `make install` command performs a clean build and attempts to install onto a raspberry-pi-formatted sd card in its `bootfs` partition.

## Compiling

Expand All @@ -62,6 +63,7 @@ The OS currently only runs on QEMU, so QEMU needs to be installed as well. The s
Running `make run` or `make all` followed by `./run` is the fastest way to run the system, using the default configuration (virt board for QEMU). Further explanations on these commands and their options provided in the Supporting Files section.
Running `make run MODE=virt/raspi` can select which board to compile the code for.
In order to run the OS, you'll need to create a folder called fs inside the project's root directory. This folder will contain user processes. It must have the following subfolders: /redos/user/, with user processes placed inside with the .elf extension. The `user` process will automatically be placed in that folder when compiling. A script called `createfs` will run automatically to create an image from the fs folder. This script currently only works on MacOS and Linux host systems, it will need to be adapted to run on Windows systems. Since my main host system is Mac, there's a chance the linux version won't be up to date if any changes need to be made.
Running `make install` will perform a clean build for the raspberry pi and copy the resulting kernel image and the provided `config.txt` file to a partition called `bootfs`, which should be created using Raspberry Pi Imager on an SD card. It should be possible to then boot the system onto a Raspberry Pi 5, 4B or 3B, although support may be limited. It is recommended to use a UART debug probe along with the `screen` command running on the development machine to see the system's console output and debug potential issues.

Github Actions should automatically compile changes made to the `main` branch using Mac, so a compiled version of the system with all the files needed to run it should be found there. This includes the fs folder, containing the filesystem, but you'll need to recompile the `disk.img` filesystem with `createfs` for any changes made to this folder to be reflected. Currently it only builds a version for the virt board.

Expand Down
55 changes: 55 additions & 0 deletions config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Automatically load initramfs files, if found
auto_initramfs=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1

# Run in 64-bit mode
arm_64bit=1

# Disable compensation for displays with overscan
disable_overscan=1

# Run as fast as firmware / board allows
arm_boost=1

pciex4_reset=0

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[cm5]
#dtoverlay=dwc2,dr_mode=host

[all]
gpu_mem=512
framebuffer_depth=32
Loading