diff --git a/Makefile b/Makefile deleted file mode 100644 index 9c88790..0000000 --- a/Makefile +++ /dev/null @@ -1,115 +0,0 @@ -# Makefile for kernel with picolibc -.PHONY: all clean picolibc kernel run help - -# Paths -PICOLIBC_INSTALL := $(CURDIR)/picolibc-install -BUILD_DIR := build -OUT_DIR := $(BUILD_DIR)/out -SRC_DIR := src - -# Check if picolibc exists -PICOLIBC_EXISTS := $(shell test -d $(PICOLIBC_INSTALL) && echo 1 || echo 0) - -# Compiler and flags -CC := gcc -AS := nasm -LD := ld - -CFLAGS := -m32 -march=i686 -ffreestanding -nostdlib -fno-builtin -CFLAGS += -I$(PICOLIBC_INSTALL)/include -CFLAGS += -I$(SRC_DIR)/lib -CFLAGS += -I$(SRC_DIR) -CFLAGS += -Wall -Wextra -O2 - -ASFLAGS := -f elf32 - -LDFLAGS := -m elf_i386 -nostdlib -LDFLAGS += -L$(PICOLIBC_INSTALL)/lib -LDFLAGS += -T $(SRC_DIR)/link.ld - -# Get libgcc path for compiler runtime support -LIBGCC := $(shell $(CC) -m32 -print-libgcc-file-name) - -# Object files -OBJS := $(BUILD_DIR)/kasm.o $(BUILD_DIR)/kc.o $(BUILD_DIR)/duktape.o $(BUILD_DIR)/syscalls.o - -# Default target -all: check-picolibc kernel - -# Help target -help: - @echo "Makefile for kernel with picolibc" - @echo "" - @echo "Targets:" - @echo " picolibc - Download and build picolibc" - @echo " kernel - Build the kernel (requires picolibc)" - @echo " run - Build and run the kernel in QEMU" - @echo " clean - Clean build artifacts" - @echo " clean-all - Clean everything including picolibc" - @echo " help - Show this help message" - -# Build picolibc -picolibc: - @echo "Building picolibc..." - @chmod +x build-picolibc.sh - @./build-picolibc.sh - -# Check if picolibc is built -check-picolibc: -ifneq ($(PICOLIBC_EXISTS),1) - @echo "Error: Picolibc not found. Building it now..." - @$(MAKE) picolibc -endif - -# Create build directories -$(BUILD_DIR): - @mkdir -p $(BUILD_DIR) - -$(OUT_DIR): | $(BUILD_DIR) - @mkdir -p $(OUT_DIR) - -# Build boot assembly -$(BUILD_DIR)/kasm.o: $(SRC_DIR)/boot/kernel.asm | $(BUILD_DIR) - @echo "Assembling boot code..." - @$(AS) $(ASFLAGS) $< -o $@ - -# Build duktape -$(BUILD_DIR)/duktape.o: $(SRC_DIR)/lib/duktape.c $(SRC_DIR)/lib/duktape.h | $(BUILD_DIR) - @echo "Building Duktape..." - @$(CC) $(CFLAGS) -c $< -o $@ - -# Build kernel -$(BUILD_DIR)/kc.o: $(SRC_DIR)/kernel/kernel.c | $(BUILD_DIR) - @echo "Building kernel..." - @$(CC) $(CFLAGS) -c $< -o $@ - -# Build syscalls -$(BUILD_DIR)/syscalls.o: $(SRC_DIR)/lib/syscalls.c | $(BUILD_DIR) - @echo "Building syscalls..." - @$(CC) $(CFLAGS) -c $< -o $@ - -# Link kernel -$(OUT_DIR)/kernel: $(OBJS) | $(OUT_DIR) - @echo "Linking kernel..." - @$(LD) $(LDFLAGS) -o $@ $(OBJS) -lc $(LIBGCC) - @echo "Build complete: $@" - -# Main kernel target -kernel: check-picolibc $(OUT_DIR)/kernel - -# Run in QEMU -run: kernel - @echo "Running kernel in QEMU..." - @qemu-system-i386 -kernel $(OUT_DIR)/kernel - -# Clean build artifacts -clean: - @echo "Cleaning build artifacts..." - @rm -rf $(BUILD_DIR) - -# Clean everything including picolibc -clean-all: clean - @echo "Cleaning picolibc..." - @rm -rf picolibc picolibc-install - -.DEFAULT_GOAL := help diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..eca7114 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,17 @@ +FROM fedora:41 + +RUN dnf install -y \ + gcc \ + gcc-c++ \ + make \ + nasm \ + python3 \ + git \ + qemu-system-x86 \ + wget \ + meson \ + && dnf clean all + +WORKDIR /workspace + +CMD ["bash", "-c", "/workspace/scripts/build-picolibc.sh && /workspace/scripts/build-kernel.sh"] \ No newline at end of file diff --git a/picolibc-i686.txt b/picolibc-i686.txt index bb0ccb9..8b6b6a5 100644 --- a/picolibc-i686.txt +++ b/picolibc-i686.txt @@ -15,4 +15,4 @@ endian = 'little' [properties] c_args = ['-m32', '-march=i686'] c_link_args = ['-m32'] -skip_sanity_check = true +skip_sanity_check = true \ No newline at end of file diff --git a/quickstart.sh b/quickstart.sh deleted file mode 100755 index 81e19c6..0000000 --- a/quickstart.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -# Quick start script - builds picolibc and kernel, then runs it - -set -e - -echo "==========================================" -echo " Kernel with Picolibc - Quick Start" -echo "==========================================" -echo "" - -# Check for required tools -echo "Checking prerequisites..." - -command -v gcc >/dev/null 2>&1 || { echo "Error: gcc not found"; exit 1; } -command -v nasm >/dev/null 2>&1 || { echo "Error: nasm not found"; exit 1; } -command -v ld >/dev/null 2>&1 || { echo "Error: ld not found"; exit 1; } -command -v qemu-system-i386 >/dev/null 2>&1 || { echo "Error: qemu-system-i386 not found"; exit 1; } - -if ! command -v meson >/dev/null 2>&1; then - echo "Warning: meson not found" - echo "Install with: pip install --user meson ninja" - echo "or: sudo apt install meson ninja-build" - exit 1 -fi - -echo "✓ All prerequisites found" -echo "" - -# Build picolibc if not already built -if [ ! -d "picolibc-install" ]; then - echo "Step 1: Building picolibc (this may take a few minutes)..." - ./build-picolibc.sh -else - echo "Step 1: Picolibc already built (skipping)" -fi - -echo "" -echo "Step 2: Building kernel..." -make kernel - -echo "" -echo "Step 3: Running kernel in QEMU..." -echo "(Press Ctrl+A then X to exit QEMU)" -echo "" -sleep 2 - -make run diff --git a/scripts/run.sh b/scripts/build-kernel.sh similarity index 97% rename from scripts/run.sh rename to scripts/build-kernel.sh index b7b68ad..53e75c5 100755 --- a/scripts/run.sh +++ b/scripts/build-kernel.sh @@ -72,6 +72,4 @@ echo "=== Build complete! ===" echo "" echo "Running kernel in QEMU..." echo "(Press Ctrl+A then X to exit)" -echo "" - -qemu-system-i386 -kernel "$OUT_DIR/kernel" \ No newline at end of file +echo "" \ No newline at end of file diff --git a/build-picolibc.sh b/scripts/build-picolibc.sh old mode 100644 new mode 100755 similarity index 91% rename from build-picolibc.sh rename to scripts/build-picolibc.sh index 6f52b2d..2df35ee --- a/build-picolibc.sh +++ b/scripts/build-picolibc.sh @@ -12,9 +12,8 @@ echo "=== Building Picolibc for i686 freestanding ===" # Check if picolibc exists if [ ! -d "$PICOLIBC_DIR" ]; then echo "Error: Picolibc source not found at $PICOLIBC_DIR" - echo "Please clone picolibc manually:" - echo " git clone https://github.com/picolibc/picolibc.git" - exit 1 + echo "Cloning..." + git clone --branch 1.8.10 https://github.com/picolibc/picolibc.git "$PICOLIBC_DIR" fi # Get current version diff --git a/scripts/build-with-picolibc.sh b/scripts/build-with-picolibc.sh deleted file mode 100644 index dbf3040..0000000 --- a/scripts/build-with-picolibc.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -# Build script for kernel with picolibc - -set -e - -# Paths -PICOLIBC_INSTALL="$(pwd)/picolibc-install" -BUILD_DIR="build" -OUT_DIR="$BUILD_DIR/out" - -# Check if picolibc is installed -if [ ! -d "$PICOLIBC_INSTALL" ]; then - echo "Error: Picolibc not found at $PICOLIBC_INSTALL" - echo "Please run ./build-picolibc.sh first" - exit 1 -fi - -# Create build directories -mkdir -p "$BUILD_DIR" -mkdir -p "$OUT_DIR" - -# Compiler flags -CFLAGS="-m32 -march=i686 -ffreestanding -nostdlib -fno-builtin" -CFLAGS="$CFLAGS -I$PICOLIBC_INSTALL/include" -CFLAGS="$CFLAGS -I./src/lib" -CFLAGS="$CFLAGS -I./src" -CFLAGS="$CFLAGS -Wall -Wextra" - -LDFLAGS="-m elf_i386 -nostdlib" -LDFLAGS="$LDFLAGS -L$PICOLIBC_INSTALL/lib" - -echo "=== Building kernel with picolibc ===" - -# Build boot assembly -echo "Assembling boot code..." -nasm -f elf32 src/boot/kernel.asm -o "$BUILD_DIR/kasm.o" - -# Build duktape with picolibc -echo "Building Duktape..." -gcc $CFLAGS -c src/lib/duktape.c -o "$BUILD_DIR/duktape.o" - -# Build kernel -echo "Building kernel..." -gcc $CFLAGS -c src/kernel/kernel.c -o "$BUILD_DIR/kc.o" - -# Link everything together -echo "Linking kernel..." -ld $LDFLAGS -T src/link.ld -o "$OUT_DIR/kernel" \ - "$BUILD_DIR/kasm.o" \ - "$BUILD_DIR/kc.o" \ - "$BUILD_DIR/duktape.o" \ - -lc - -echo "" -echo "=== Build complete! ===" -echo "Kernel binary: $OUT_DIR/kernel" -echo "" -echo "To run the kernel:" -echo " qemu-system-i386 -kernel $OUT_DIR/kernel" diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..71adfa2 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,2 @@ +docker build -t lints-dev -f docker/Dockerfile . +docker run -it --rm -v "$(pwd)":/workspace -w /workspace lints-dev \ No newline at end of file diff --git a/scripts/run-kernel.sh b/scripts/run-kernel.sh new file mode 100755 index 0000000..7f45ffd --- /dev/null +++ b/scripts/run-kernel.sh @@ -0,0 +1,3 @@ +./scripts/build.sh + +qemu-system-i386 -kernel "build/out/kernel" \ No newline at end of file diff --git a/src/os/index.js b/src/os/index.js index ec7cc6b..84b6776 100644 --- a/src/os/index.js +++ b/src/os/index.js @@ -1,20 +1,5 @@ clearScreen(); -print("Hello World!"); - -// writeMemory(0xb8000, 0x48); -// writeMemory(0xb8001, 0x0f); - -// writeMemory(0xb8002, 0x65); -// writeMemory(0xb8003, 0x0f); - -// writeMemory(0xb8004, 0x6c); -// writeMemory(0xb8005, 0x0f); - -// writeMemory(0xb8006, 0x6c); -// writeMemory(0xb8007, 0x0f); - -// writeMemory(0xb8008, 0x6f); -// writeMemory(0xb8009, 0x0f); +print("Hello, World!"); function clearScreen() { var i = 0;