working on kernel
This commit is contained in:
+69
-9
@@ -12,6 +12,10 @@ NC='\033[0m' # No Color
|
||||
set -e
|
||||
trap 'echo -e "${RED}${BOLD}error${NC}: build failed" >&2' ERR
|
||||
|
||||
# Get absolute path to project root
|
||||
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
project_root=$(cd "$script_dir/.." &>/dev/null && pwd)
|
||||
|
||||
# Logging functions
|
||||
info() {
|
||||
echo -e "${BLUE}${BOLD}info${NC}: $1"
|
||||
@@ -25,15 +29,29 @@ warning() {
|
||||
echo -e "${YELLOW}${BOLD}warning${NC}: $1" >&2
|
||||
}
|
||||
|
||||
building() {
|
||||
echo -e "${GREEN}${BOLD}Building${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}${BOLD}error${NC}: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
build_dir=build
|
||||
iso_root=$build_dir/iso_root
|
||||
kernel_path=$1
|
||||
kernel_name=$(basename $kernel_path)
|
||||
build_dir="$project_root/build"
|
||||
iso_root="$build_dir/iso_root"
|
||||
|
||||
# Check if we're running tests
|
||||
is_test=0
|
||||
if [[ $1 == *"deps"* ]]; then
|
||||
is_test=1
|
||||
kernel_path="$1"
|
||||
else
|
||||
# Build the kernel normally
|
||||
cd "$project_root"
|
||||
cargo build
|
||||
kernel_path="$build_dir/target/x86_64-kernel/debug/kernel"
|
||||
fi
|
||||
|
||||
# Check for required tools
|
||||
check_tools() {
|
||||
@@ -57,21 +75,23 @@ mkdir -p "$iso_root/EFI/BOOT"
|
||||
# Clone Limine if needed
|
||||
if [ ! -d "$build_dir/limine" ]; then
|
||||
compiling "limine bootloader"
|
||||
cd "$build_dir"
|
||||
git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1 "$build_dir/limine" || error "failed to clone limine"
|
||||
make -C "$build_dir/limine" || error "failed to build limine"
|
||||
cd "$project_root"
|
||||
fi
|
||||
|
||||
# Copy files
|
||||
info "Copying files to ISO root"
|
||||
cp -v "$kernel_path" "$iso_root/boot/kernel" || error "failed to copy kernel"
|
||||
cp -v config/limine.conf "$iso_root/boot/limine/" || error "failed to copy limine config"
|
||||
cp -v "$project_root/config/limine.conf" "$iso_root/boot/limine/limine.conf" || error "failed to copy limine config"
|
||||
cp -v "$build_dir/limine/limine-bios.sys" "$build_dir/limine/limine-bios-cd.bin" \
|
||||
"$build_dir/limine/limine-uefi-cd.bin" "$iso_root/boot/limine/" || error "failed to copy limine files"
|
||||
cp -v "$build_dir/limine/BOOTX64.EFI" "$iso_root/EFI/BOOT/" || error "failed to copy BOOTX64.EFI"
|
||||
cp -v "$build_dir/limine/BOOTIA32.EFI" "$iso_root/EFI/BOOT/" || error "failed to copy BOOTIA32.EFI"
|
||||
|
||||
# Create ISO
|
||||
compiling "bootable ISO image"
|
||||
building "bootable ISO image"
|
||||
xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
|
||||
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
|
||||
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
|
||||
@@ -94,6 +114,22 @@ else
|
||||
kvm_flag=""
|
||||
fi
|
||||
|
||||
# Check if we're running in debug mode
|
||||
if [[ "$(cargo metadata --format-version=1 | jq -r '.workspace_members[0]' | cut -d' ' -f2)" == "(debug)" ]]; then
|
||||
debug_flags="-s -S"
|
||||
else
|
||||
debug_flags=""
|
||||
fi
|
||||
|
||||
# Set up test-specific flags
|
||||
if [ $is_test -eq 1 ]; then
|
||||
test_flags="-device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none"
|
||||
serial_flags="-serial stdio"
|
||||
else
|
||||
test_flags=""
|
||||
serial_flags="-serial tcp:127.0.0.1:1234,server,nowait"
|
||||
fi
|
||||
|
||||
# Run in QEMU
|
||||
if [[ ${QEMU_FLAGS} == *-S* ]]; then
|
||||
info "Running OS in QEMU with GDB debugging enabled"
|
||||
@@ -103,12 +139,36 @@ else
|
||||
info "Running OS in QEMU..."
|
||||
fi
|
||||
|
||||
exec qemu-system-x86_64 -M q35 \
|
||||
echo "test: " $is_test
|
||||
|
||||
cd "$project_root"
|
||||
qemu-system-x86_64 -M q35 \
|
||||
${kvm_flag} \
|
||||
-cdrom "$build_dir/image.iso" \
|
||||
-boot d \
|
||||
-m 2G \
|
||||
-serial stdio \
|
||||
${serial_flags} \
|
||||
-no-reboot \
|
||||
-no-shutdown \
|
||||
${test_flags} \
|
||||
${debug_flags} \
|
||||
${QEMU_FLAGS:-}
|
||||
|
||||
# Get QEMU's exit code
|
||||
qemu_exit_code=$?
|
||||
|
||||
# If this is a test run, translate QEMU exit codes to test exit codes
|
||||
if [ $is_test -eq 1 ]; then
|
||||
if [ $qemu_exit_code -eq 33 ]; then
|
||||
# Success case (0x10 << 1) | 1 = 33
|
||||
exit 0
|
||||
elif [ $qemu_exit_code -eq 35 ]; then
|
||||
# Failure case (0x11 << 1) | 1 = 35
|
||||
exit 1
|
||||
else
|
||||
# Any other exit code is treated as a failure
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# For non-test runs, pass through the exit code
|
||||
exit $qemu_exit_code
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user