Make EFI port primary

This commit is contained in:
2025-11-29 20:00:51 +01:00
parent e2184bdc27
commit c222cae16f
104 changed files with 3 additions and 5187 deletions

View File

@@ -1,98 +0,0 @@
#!/bin/bash
# Build and run kernel with picolibc
set -e
mkdir -p lib
./scripts/get_duktape.sh
# 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: make picolibc"
exit 1
fi
# Create build directories
mkdir -p "$BUILD_DIR"
mkdir -p "$OUT_DIR"
# Build TypeScript to JavaScript
cd src/os
echo "Compiling TypeScript to JavaScript..."
bun build --outdir ../../build --target node --bundle src/index.ts
cd ../../
# Generate embedded JavaScript header
echo "Generating embedded JavaScript..."
bun scripts/build_js.js
python3 scripts/embed_js.py build/index.js > "$BUILD_DIR/embedded_js.h"
# Compiler flags
CFLAGS="-m32 -march=i686 -ffreestanding -nostdlib -fno-builtin"
CFLAGS="$CFLAGS -mno-sse -mno-sse2 -mno-mmx -mno-3dnow"
CFLAGS="$CFLAGS -I$PICOLIBC_INSTALL/include"
CFLAGS="$CFLAGS -I./lib/duktape/src"
CFLAGS="$CFLAGS -I./src/lib"
CFLAGS="$CFLAGS -I./src"
CFLAGS="$CFLAGS -I$BUILD_DIR"
CFLAGS="$CFLAGS -Wall -Wextra"
LDFLAGS="-m elf_i386 -nostdlib"
LDFLAGS="$LDFLAGS -L$PICOLIBC_INSTALL/lib"
# Get libgcc path
LIBGCC=$(gcc -m32 -print-libgcc-file-name)
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 interrupt assembly
echo "Assembling interrupt handlers..."
nasm -f elf32 src/kernel/interrupt/interrupt.asm -o "$BUILD_DIR/interrupt.o"
# Build duktape
echo "Building Duktape..."
gcc $CFLAGS -c lib/duktape/src/duktape.c -o "$BUILD_DIR/duktape.o"
# Build interrupt system
echo "Building interrupt system..."
gcc $CFLAGS -c src/kernel/interrupt/idt.c -o "$BUILD_DIR/idt.o"
gcc $CFLAGS -c src/kernel/interrupt/isr.c -o "$BUILD_DIR/isr.o"
# Build kernel
echo "Building kernel..."
gcc $CFLAGS -c src/kernel/kernel.c -o "$BUILD_DIR/kc.o"
# Build syscalls
echo "Building syscalls..."
gcc $CFLAGS -c src/lib/syscalls.c -o "$BUILD_DIR/syscalls.o"
# Link everything together
echo "Linking kernel..."
ld $LDFLAGS -T src/link.ld -o "$OUT_DIR/kernel" \
"$BUILD_DIR/kasm.o" \
"$BUILD_DIR/interrupt.o" \
"$BUILD_DIR/idt.o" \
"$BUILD_DIR/isr.o" \
"$BUILD_DIR/kc.o" \
"$BUILD_DIR/duktape.o" \
"$BUILD_DIR/syscalls.o" \
-lc "$LIBGCC"
echo ""
echo "=== Build complete! ==="
echo ""
echo "Running kernel in QEMU..."
echo "(Press Ctrl+A then X to exit)"
echo ""

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Script to build picolibc for i686 freestanding environment
set -e
PICOLIBC_DIR="picolibc"
BUILD_DIR="build/picolibc"
INSTALL_DIR="$(pwd)/picolibc-install"
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 "Cloning..."
git clone --branch 1.8.10 https://github.com/picolibc/picolibc.git "$PICOLIBC_DIR"
fi
# Get current version
cd "$PICOLIBC_DIR"
CURRENT_VERSION=$(git describe --tags 2>/dev/null || echo "unknown")
echo "Using picolibc version: $CURRENT_VERSION"
cd ..
# Create build directory
mkdir -p "$BUILD_DIR"
echo "Configuring picolibc with meson..."
meson setup "$BUILD_DIR" "$PICOLIBC_DIR" \
--cross-file picolibc-i686.txt \
--prefix="$INSTALL_DIR" \
--wipe \
-Dmultilib=false \
-Dpicocrt=false \
-Dsemihost=false \
-Dspecsdir=none \
-Dtinystdio=true \
-Dio-long-long=true \
-Dformat-default=double \
-Dtests=false
echo "Building picolibc..."
meson compile -C "$BUILD_DIR"
echo "Installing picolibc..."
meson install -C "$BUILD_DIR"
echo ""
echo "=== Picolibc build complete! ==="
echo "Installation directory: $INSTALL_DIR"
echo ""
echo "To use picolibc in your kernel:"
echo " Include path: -I$INSTALL_DIR/include"
echo " Library path: -L$INSTALL_DIR/lib"
echo " Link with: -lc"

View File

@@ -1,2 +0,0 @@
docker build -t lints-dev -f docker/Dockerfile .
docker run -it --rm -v "$(pwd)":/workspace -w /workspace lints-dev

11
scripts/build_c.sh Executable file
View File

@@ -0,0 +1,11 @@
mkdir -p out
mkdir -p out/core
mkdir -p out/img/EFI/BOOT
mkdir -p out/lib
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -c core/src/efi.c -o out/core/efi.o
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Icore/compat -Icore/lib/duktape/src -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -c core/src/main.c -o out/core/main.o
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -DDUK_F_GENERIC -U_WIN32 -UWIN32 -U_WIN64 -UWIN64 -Icore/compat -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -c core/lib/duktape/src/duktape.c -o out/lib/duktape.o
clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -Icore/compat -Iedk2/MdePkg/Include -Iedk2/MdePkg/Include/X64 -Iedk2/CryptoPkg/Library/Include -c core/src/compat.c -o out/core/compat.o
lld-link -filealign:16 -subsystem:efi_application -nodefaultlib -dll -entry:efi_main out/core/main.o out/core/efi.o out/lib/duktape.o out/core/compat.o -out:out/img/EFI/BOOT/BOOTX64.EFI

View File

@@ -1,11 +0,0 @@
#! /usr/bin/env bun
import { readFileSync, writeFileSync } from "fs";
writeFileSync(
"build/index.js",
readFileSync("build/index.js", "utf-8")
.replaceAll("let ", "var ")
.replaceAll("const ", "var ")
.replaceAll("\n`", "\\n`")
.replaceAll("`", "'")
);

View File

@@ -1,58 +0,0 @@
#!/usr/bin/env python3
"""
Embed JavaScript file as a C string constant
"""
import sys
def escape_c_string(s):
"""Escape a string for use in C source code"""
result = []
for char in s:
if char == "\n":
result.append("\\n")
elif char == "\r":
result.append("\\r")
elif char == "\t":
result.append("\\t")
elif char == "\\":
result.append("\\\\")
elif char == '"':
result.append('\\"')
elif ord(char) < 32 or ord(char) > 126:
result.append(f"\\x{ord(char):02x}")
else:
result.append(char)
return "".join(result)
def main():
if len(sys.argv) != 2:
print("Usage: embed_js.py <input.js>", file=sys.stderr)
sys.exit(1)
input_file = sys.argv[1]
try:
with open(input_file, "r") as f:
js_code = f.read()
except FileNotFoundError:
print(f"Error: File not found: {input_file}", file=sys.stderr)
sys.exit(1)
# Generate C header file
print("/* Auto-generated file - do not edit */")
print("#ifndef EMBEDDED_JS_H")
print("#define EMBEDDED_JS_H")
print()
escaped = escape_c_string(js_code)
print(f'const char *embedded_js_code = "{escaped}";')
print()
print("#endif /* EMBEDDED_JS_H */")
if __name__ == "__main__":
main()

View File

@@ -1,28 +0,0 @@
#!/bin/bash
# Script to download Duktape library if not present
set -e
DUKTAPE_DIR="lib/duktape"
DUKTAPE_REPO="https://github.com/joeqread/arduino-duktape.git"
TEMP_DIR="lib/temp_duktape"
echo "=== Checking for Duktape library ==="
if [ -d "$DUKTAPE_DIR" ]; then
echo "Duktape already exists at $DUKTAPE_DIR"
else
echo "Duktape not found. Cloning from $DUKTAPE_REPO..."
git clone "$DUKTAPE_REPO" "$TEMP_DIR"
echo "Extracting src folder..."
mkdir -p "$DUKTAPE_DIR"
mv "$TEMP_DIR/src" "$DUKTAPE_DIR/"
echo "Cleaning up temporary directory..."
rm -rf "$TEMP_DIR"
echo "Duktape cloned successfully!"
fi
echo "Done."

19
scripts/out_to_iso.sh Executable file
View File

@@ -0,0 +1,19 @@
# Create a FAT12 image
dd if=/dev/zero of=out/fat.img bs=1k count=1440
mformat -i out/fat.img -f 1440 ::
# Create EFI directory structure
mmd -i out/fat.img ::/EFI
mmd -i out/fat.img ::/EFI/BOOT
# Copy the EFI application
mcopy -i out/fat.img out/img/EFI/BOOT/BOOTX64.EFI ::/EFI/BOOT
# Verify content
echo "Verifying FAT image content:"
mdir -i out/fat.img -/ ::
# Create the ISO
# -e specifies the boot image (the FAT image)
# -no-emul-boot is required for UEFI
xorriso -as mkisofs -R -f -e /fat.img -no-emul-boot -volid LintsEFI -o out/lints.iso out/img out/fat.img

View File

@@ -1,69 +0,0 @@
./scripts/build.sh
# Create disk image if it doesn't exist
if [ ! -f hdd.img ]; then
echo "Creating disk image..."
qemu-img create -f raw hdd.img 10M
# Create a proper MBR partition table with one FAT32 partition
# Using fdisk commands
(
echo o # Create new DOS partition table
echo n # New partition
echo p # Primary partition
echo 1 # Partition number 1
echo # Default first sector
echo # Default last sector (use all space)
echo t # Change partition type
echo c # FAT32 LBA
echo a # Make bootable
echo w # Write changes
) | fdisk hdd.img >/dev/null 2>&1
# Format the partition as FAT32
# First, get the partition offset using sfdisk
OFFSET=$(sfdisk -l hdd.img 2>/dev/null | grep 'hdd.img1' | awk '{print $2}')
# Check if OFFSET is empty or non-numeric and set default if needed
if [ -z "$OFFSET" ] || ! [[ "$OFFSET" =~ ^[0-9]+$ ]]; then
OFFSET=2048 # Default first sector for most partition tables
fi
# Create FAT32 filesystem on the partition
echo "Formatting partition as FAT32..."
mkfs.vfat -F 32 -n "TESTDISK" --offset $OFFSET hdd.img
echo "Disk image created with FAT32 partition"
fi
# Get the partition offset for file operations
OFFSET=$(sfdisk -l hdd.img 2>/dev/null | grep 'hdd.img1' | awk '{print $2}')
if [ -z "$OFFSET" ] || ! [[ "$OFFSET" =~ ^[0-9]+$ ]]; then
OFFSET=2048
fi
# Copy test-hdd contents into the disk image
if [ -d "test-hdd" ]; then
echo "Copying test-hdd contents to disk image..."
# Use mcopy to copy files to the FAT32 partition
MTOOLS_SKIP_CHECK=1 mcopy -i hdd.img@@$((OFFSET * 512)) -s test-hdd/* :: || {
echo "Warning: mcopy failed, retrying individual files..."
for file in test-hdd/*; do
if [ -f "$file" ]; then
MTOOLS_SKIP_CHECK=1 mcopy -i hdd.img@@$((OFFSET * 512)) "$file" :: && echo "Copied $(basename "$file")"
fi
done
}
fi
# Create CD-ROM image if it doesn't exist
if [ ! -f cdrom.iso ]; then
mkdir -p /tmp/cdrom_content
echo "Test CD-ROM" > /tmp/cdrom_content/readme.txt
genisoimage -o cdrom.iso -V "TESTCD" -r -J /tmp/cdrom_content 2>/dev/null || touch cdrom.iso
fi
qemu-system-i386 -serial stdio -kernel "build/out/kernel" \
-drive file=hdd.img,if=ide,format=raw,index=0,media=disk \
-drive file=cdrom.iso,if=ide,format=raw,index=1,media=cdrom

22
scripts/run_vbox.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
VM_NAME="LintsEFI"
ISO_PATH="$(pwd)/out/lints.iso"
# Check if VM exists
if VBoxManage list vms | grep -q "\"$VM_NAME\""; then
echo "VM '$VM_NAME' already exists."
else
echo "Creating VM '$VM_NAME'..."
VBoxManage createvm --name "$VM_NAME" --ostype "Other_64" --register
VBoxManage modifyvm "$VM_NAME" --memory 128 --firmware efi --graphicscontroller vmsvga
VBoxManage storagectl "$VM_NAME" --name "IDE Controller" --add ide
fi
# Attach ISO (force unmount first just in case)
echo "Attaching ISO..."
VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium emptydrive --forceunmount
VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO_PATH"
# Start VM
echo "Starting VM..."
VBoxManage startvm "$VM_NAME"