Add docker build system
This commit is contained in:
115
Makefile
115
Makefile
@@ -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
|
|
||||||
17
docker/Dockerfile
Normal file
17
docker/Dockerfile
Normal file
@@ -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"]
|
||||||
@@ -15,4 +15,4 @@ endian = 'little'
|
|||||||
[properties]
|
[properties]
|
||||||
c_args = ['-m32', '-march=i686']
|
c_args = ['-m32', '-march=i686']
|
||||||
c_link_args = ['-m32']
|
c_link_args = ['-m32']
|
||||||
skip_sanity_check = true
|
skip_sanity_check = true
|
||||||
@@ -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
|
|
||||||
@@ -72,6 +72,4 @@ echo "=== Build complete! ==="
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Running kernel in QEMU..."
|
echo "Running kernel in QEMU..."
|
||||||
echo "(Press Ctrl+A then X to exit)"
|
echo "(Press Ctrl+A then X to exit)"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
qemu-system-i386 -kernel "$OUT_DIR/kernel"
|
|
||||||
5
build-picolibc.sh → scripts/build-picolibc.sh
Normal file → Executable file
5
build-picolibc.sh → scripts/build-picolibc.sh
Normal file → Executable file
@@ -12,9 +12,8 @@ echo "=== Building Picolibc for i686 freestanding ==="
|
|||||||
# Check if picolibc exists
|
# Check if picolibc exists
|
||||||
if [ ! -d "$PICOLIBC_DIR" ]; then
|
if [ ! -d "$PICOLIBC_DIR" ]; then
|
||||||
echo "Error: Picolibc source not found at $PICOLIBC_DIR"
|
echo "Error: Picolibc source not found at $PICOLIBC_DIR"
|
||||||
echo "Please clone picolibc manually:"
|
echo "Cloning..."
|
||||||
echo " git clone https://github.com/picolibc/picolibc.git"
|
git clone --branch 1.8.10 https://github.com/picolibc/picolibc.git "$PICOLIBC_DIR"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get current version
|
# Get current version
|
||||||
@@ -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"
|
|
||||||
2
scripts/build.sh
Executable file
2
scripts/build.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
docker build -t lints-dev -f docker/Dockerfile .
|
||||||
|
docker run -it --rm -v "$(pwd)":/workspace -w /workspace lints-dev
|
||||||
3
scripts/run-kernel.sh
Executable file
3
scripts/run-kernel.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
./scripts/build.sh
|
||||||
|
|
||||||
|
qemu-system-i386 -kernel "build/out/kernel"
|
||||||
@@ -1,20 +1,5 @@
|
|||||||
clearScreen();
|
clearScreen();
|
||||||
print("Hello World!");
|
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);
|
|
||||||
|
|
||||||
function clearScreen() {
|
function clearScreen() {
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user