From 60cc7e9eae3c2b40bf150a7448b9e5f3f9ef10be Mon Sep 17 00:00:00 2001 From: Max Tyson <98maxt98@gmail.com> Date: Sat, 16 Dec 2023 21:15:36 +1300 Subject: [PATCH] Rewrite Scripts --- Makefile | 162 ++++-------------- filesystem/home/Guest/Desktop/.gitkeep | 0 filesystem/home/Guest/Documents/.gitkeep | 0 filesystem/home/Guest/Downloads/.gitkeep | 0 filesystem/home/Guest/Music/.gitkeep | 0 filesystem/home/Guest/Pictures/.gitkeep | 0 filesystem/home/Guest/Videos/.gitkeep | 0 .../src/drivers/ethernet/rawdatahandler.cpp | 1 - kernel/src/kernel.cpp | 21 ++- toolchain/copy_filesystem.sh | 34 ++-- toolchain/create_disk_img.sh | 62 +++---- toolchain/increment_version.sh | 27 --- toolchain/make_cross_compiler.sh | 32 ++-- toolchain/maxOS.sh | 36 ++++ toolchain/run_qemu.sh | 126 ++++++++++++++ toolchain/version.sh | 66 +++++++ 16 files changed, 344 insertions(+), 223 deletions(-) delete mode 100644 filesystem/home/Guest/Desktop/.gitkeep delete mode 100644 filesystem/home/Guest/Documents/.gitkeep delete mode 100644 filesystem/home/Guest/Downloads/.gitkeep delete mode 100644 filesystem/home/Guest/Music/.gitkeep delete mode 100644 filesystem/home/Guest/Pictures/.gitkeep delete mode 100644 filesystem/home/Guest/Videos/.gitkeep delete mode 100755 toolchain/increment_version.sh create mode 100755 toolchain/maxOS.sh create mode 100755 toolchain/run_qemu.sh create mode 100755 toolchain/version.sh diff --git a/Makefile b/Makefile index 6100532b..f90ec359 100644 --- a/Makefile +++ b/Makefile @@ -1,83 +1,22 @@ - TARGET=i686-elf GCC_EXEC ?= toolchain/cross_compiler/cross/bin/$(TARGET)-gcc GCC_PARAMS = -ffreestanding -fno-exceptions -fno-rtti -nostdlib -Wall -Wextra AS_EXEC ?= toolchain/cross_compiler/cross/bin/$(TARGET)-as - LD_EXEC ?= toolchain/cross_compiler/cross/bin/$(TARGET)-ld -QEMU_PARAMS = -device pcnet,netdev=net0 \ - -netdev user,id=net0,hostfwd=tcp::1234-:1234 \ - -m 512 \ - -hda maxOS.img \ - -vga std \ - -serial stdio +QEMU_PARAMS = -hda maxOS.img -vga std -serial stdio \ + -device pcnet,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::1234-:1234 QEMU_EXTRA_PARAMS? = "" -#For intel_i217 ethernet: -nic tap,model=e1000 \ -#For amd_am79c973 ethernet: -net user -net nic,model=pcnet \ -#Boot iso: -boot d -cdrom maxOS.iso \ -#Boot from hdd: -boot c -hda /dev/loop0 \ -#VESA graphics: -vga std \ - -kernel = obj/kernel/loader.o \ - obj/kernel/system/gdt.o \ - obj/kernel/memory/memorymanagement.o \ - obj/kernel/memory/memoryIO.o \ - obj/kernel/drivers/driver.o \ - obj/kernel/hardwarecommunication/port.o \ - obj/kernel/hardwarecommunication/interruptstubs.o \ - obj/kernel/hardwarecommunication/interrupts.o \ - obj/kernel/hardwarecommunication/serial.o \ - obj/kernel/system/syscalls.o \ - obj/kernel/system/multithreading.o \ - obj/kernel/system/process.o \ - obj/kernel/hardwarecommunication/pci.o \ - obj/kernel/system/multitasking.o \ - obj/kernel/drivers/peripherals/keyboard.o \ - obj/kernel/drivers/peripherals/mouse.o \ - obj/kernel/drivers/video/video.o \ - obj/kernel/drivers/video/vga.o \ - obj/kernel/drivers/video/vesa.o \ - obj/kernel/drivers/ata.o \ - obj/kernel/drivers/ethernet/amd_am79c973.o \ - obj/kernel/drivers/ethernet/intel_i217.o \ - obj/kernel/drivers/ethernet/ethernet.o \ - obj/kernel/drivers/clock/clock.o \ - obj/kernel/drivers/console/console.o \ - obj/kernel/drivers/console/textmode.o \ - obj/kernel/drivers/console/vesaboot.o \ - obj/kernel/filesystem/filesystem.o \ - obj/kernel/filesystem/fat32.o \ - obj/kernel/filesystem/msdospart.o \ - obj/kernel/gui/widget.o \ - obj/kernel/gui/window.o \ - obj/kernel/gui/desktop.o \ - obj/kernel/gui/font.o \ - obj/kernel/gui/widgets/text.o \ - obj/kernel/gui/widgets/button.o \ - obj/kernel/gui/widgets/inputbox.o \ - obj/kernel/common/graphicsContext.o \ - obj/kernel/common/colour.o \ - obj/kernel/common/inputStream.o \ - obj/kernel/common/outputStream.o \ - obj/kernel/net/ethernetframe.o \ - obj/kernel/net/arp.o \ - obj/kernel/net/ipv4.o \ - obj/kernel/net/icmp.o \ - obj/kernel/net/udp.o \ - obj/kernel/net/tcp.o \ - obj/kernel/kernel.o - -libraries = -ports = -programs = - - -.PHONY: default -default: build; +# Find all the .cpp and .s files in the kernel directory and replace them with .o +KERNEL_SOURCES := $(shell find kernel/src -name '*.cpp' -o -name '*.s') +kernel = $(KERNEL_SOURCES:kernel/src/%=%) +kernel := $(kernel:.cpp=.o) +kernel := $(kernel:.s=.o) +kernel := $(addprefix obj/kernel/, $(kernel)) ### Kernel ### @@ -89,85 +28,56 @@ obj/kernel/%.o: kernel/src/%.s mkdir -p $(@D) $(AS_EXEC) $(AS_PARAMS) -Ikernel/include -o $@ $< -### Libraries ### - -obj/libraries/%.o: libraries/src/%.cpp - mkdir -p $(@D) - $(GCC_EXEC) $(GCC_PARAMS) -Ilibraries/include -c -o $@ $< - -obj/libraries/%.o: libraries/src/%.s - mkdir -p $(@D) - $(AS_EXEC) $(AS_PARAMS) -Ilibraries/include -o $@ $< - -buildLibraries: $(libraries) - echo Libraries Built - - -### Ports ### - -obj/ports/%.o: ports/src/%.cpp - mkdir -p $(@D) - $(GCC_EXEC) $(GCC_PARAMS) -Iports/include -c -o $@ $< - -obj/ports/%.o: ports/src/%.s - mkdir -p $(@D) - $(AS_EXEC) $(AS_PARAMS) -Iports/include -o $@ $< - -buildPorts: $(ports) - echo Ports Built - - -### Programs ### - -obj/programs/%.o: programs/src/%.cpp - mkdir -p $(@D) - $(GCC_EXEC) $(GCC_PARAMS) -Iprograms/include -c -o $@ $< - -obj/programs/%.o: programs/src/%.s - mkdir -p $(@D) - $(AS_EXEC) $(AS_PARAMS) -Iprograms/include -o $@ $< - -buildPrograms: $(programs) - echo Programs Built - ### Build ### -maxOS.bin: linker.ld $(kernel) $(libraries) $(ports) $(programs) - $(LD_EXEC) $(LD_PARAMS) -T $< -o $@ $(kernel) $(libraries) $(ports) $(programs) +maxOS.bin: linker.ld $(kernel) + $(LD_EXEC) $(LD_PARAMS) -T $< -o $@ $(kernel) objcopy --only-keep-debug $@ maxOS.sym .PHONY: filesystem filesystem: - toolchain/copy_filesystem.sh + cd toolchain && ./copy_filesystem.sh sync -incrementVersion: - toolchain/increment_version.sh +updateVersion: + cd toolchain && ./version.sh + +.PHONY: default +default: build; build: # Check if the cross compiler is made - (ls $$HOME/opt/cross/bin/$(TARGET)-gcc && echo yes) || make cross_compiler + (ls toolchain/cross_compiler/cross/bin/$(TARGET)-gcc && echo yes) || make cross_compiler + + # Set the version + make updateVersion # Make the kernel make maxOS.bin # Make the disk image - (ls maxOS.img && echo yes) || toolchain/create_disk_img.sh + ls maxOS.img || make disk_img make filesystem - @echo === Made Max OS === - make incrementVersion +all: $(kernel) + +### Run ### qemu: build - qemu-system-i386 $(QEMU_PARAMS) $(QEMU_EXTRA_PARAMS) + cd toolchain && ./run_qemu.sh -debug_qemu: build - x-terminal-emulator -e make runQ QEMU_EXTRA_PARAMS="-s -S" & gdb -ex 'set remotetimeout 300' -ex 'target remote localhost:1234' -ex 'symbol-file maxOS.sym' +qemuDebug: build + cd toolchain && ./run_qemu.sh USE_DEBUG=1 + +qemuGDB: build + x-terminal-emulator -e make qemuDebug & gdb -ex 'set remotetimeout 300' -ex 'target remote localhost:1234' -ex 'symbol-file maxOS.sym' + +### Other Tools ### .PHONY: clean clean: rm -rf obj - rm -f maxOS.bin maxOS.sym + rm -f maxOS.bin maxOS.sym maxOS.img cross_compiler: cd toolchain && ./make_cross_compiler.sh @@ -177,4 +87,6 @@ disk_img: install_deps: sudo apt-get update -y - sudo apt-get install -y grub-pc qemu-system-i386 gdb \ No newline at end of file + sudo apt-get install -y grub-pc qemu-system-i386 gdb dosfstools + + diff --git a/filesystem/home/Guest/Desktop/.gitkeep b/filesystem/home/Guest/Desktop/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/filesystem/home/Guest/Documents/.gitkeep b/filesystem/home/Guest/Documents/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/filesystem/home/Guest/Downloads/.gitkeep b/filesystem/home/Guest/Downloads/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/filesystem/home/Guest/Music/.gitkeep b/filesystem/home/Guest/Music/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/filesystem/home/Guest/Pictures/.gitkeep b/filesystem/home/Guest/Pictures/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/filesystem/home/Guest/Videos/.gitkeep b/filesystem/home/Guest/Videos/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/kernel/src/drivers/ethernet/rawdatahandler.cpp b/kernel/src/drivers/ethernet/rawdatahandler.cpp index 979532a6..3ecf7bc4 100644 --- a/kernel/src/drivers/ethernet/rawdatahandler.cpp +++ b/kernel/src/drivers/ethernet/rawdatahandler.cpp @@ -5,7 +5,6 @@ #include using namespace maxOS; -using namespace maxOS::common; using namespace maxOS::drivers; using namespace maxOS::drivers::ethernet; diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 26a6793f..fbd11984 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,6 +1,7 @@ //Common #include #include +#include //Hardware com #include @@ -186,8 +187,7 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi ConsoleStream headerStream(&consoleHeader); // Write the header - int buildCount = 495; - headerStream << " Max OS v0.01 [build " << buildCount << "] " ; + headerStream << " Max OS v" << VERSION_STRING <<" [build " << BUILD_NUMBER << "] " ; // Make a main console area at the top of the screen ConsoleArea mainConsoleArea(&console, 0, 1, console.getWidth(), console.getHeight(), ConsoleColour::DarkGrey, ConsoleColour::Black); @@ -204,10 +204,21 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi cout << "Got Magic: " << (uint32_t)multiboot_magic << ", Expected Magic: " << MULTIBOOT_BOOTLOADER_MAGIC; return; } + cout << "BUILD INFO: " << VERSION_NAME << " on " + << BUILD_DATE.year << "-" + << BUILD_DATE.month << "-" + << BUILD_DATE.day + << " at " << BUILD_DATE.hour << ":" + << BUILD_DATE.minute << ":" << BUILD_DATE.second << " " + << " (commit " << GIT_REVISION << " on " << GIT_BRANCH << " by " << GIT_AUTHOR << ")\n"; cout << "\n"; + cout << "\n"; + + // Where the areas should start + uint32_t areaStart = cout.cursorY; // Make the system setup stream - ConsoleArea systemSetupHeader(&console, 0, cout.cursorY, console.getWidth(), 1, ConsoleColour::LightGrey, ConsoleColour::Black); + ConsoleArea systemSetupHeader(&console, 0, areaStart, console.getWidth(), 1, ConsoleColour::LightGrey, ConsoleColour::Black); ConsoleStream systemSetupHeaderStream(&systemSetupHeader); systemSetupHeaderStream << "Setting up system"; @@ -273,9 +284,9 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi Vector driverSelectors; //Make the stream on the side for the PCI - ConsoleArea pciConsoleArea(&console, console.getWidth() - 45, 2, 45, console.getHeight()/2, ConsoleColour::DarkGrey, ConsoleColour::Black); + ConsoleArea pciConsoleArea(&console, console.getWidth() - 45, areaStart+1, 45, console.getHeight()/2, ConsoleColour::DarkGrey, ConsoleColour::Black); ConsoleStream pciConsoleStream(&pciConsoleArea); - console.putString(console.getWidth() - 45, 1, " PCI Devices ", ConsoleColour::LightGrey, ConsoleColour::Black); + console.putString(console.getWidth() - 45, areaStart, " PCI Devices ", ConsoleColour::LightGrey, ConsoleColour::Black); //PCI PeripheralComponentInterconnectController PCIController(&pciConsoleStream); diff --git a/toolchain/copy_filesystem.sh b/toolchain/copy_filesystem.sh index f03ef50b..6f1130ce 100755 --- a/toolchain/copy_filesystem.sh +++ b/toolchain/copy_filesystem.sh @@ -1,19 +1,25 @@ +#!/bin/bash +source ./maxOS.sh + +msg "Copying boot files to image" + #Boot -sudo rm -rf /mnt/maxOS_img_1/boot/maxOS.bin -sudo cp maxOS.bin /mnt/maxOS_img_1/boot +sudo rm -rf /mnt/maxOS_img_1/boot/maxOS.bin || warn "Could not remove old kernel" +sudo cp ../maxOS.bin /mnt/maxOS_img_1/boot || fail "Could not copy kernel" #Grub Config -sudo rm -rf /mnt/maxOS_img_1/boot/grub/grub.cfg -sudo cp filesystem/boot/grub.cfg /mnt/maxOS_img_1/boot/grub +sudo rm -rf /mnt/maxOS_img_1/boot/grub/grub.cfg || warn "Could not remove old grub config" +sudo cp ../filesystem/boot/grub.cfg /mnt/maxOS_img_1/boot/grub || fail "Could not copy grub config" #Copy filesystem -sudo rm -rf /mnt/maxOS_img_1/bin && sudo cp -r filesystem/bin /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/dev && sudo cp -r filesystem/dev /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/etc && sudo cp -r filesystem/etc /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/home && sudo cp -r filesystem/home /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/lib && sudo cp -r filesystem/lib /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/media && sudo cp -r filesystem/media /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/opt && sudo cp -r filesystem/opt /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/tmp && sudo cp -r filesystem/tmp /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/usr && sudo cp -r filesystem/usr /mnt/maxOS_img_1 -sudo rm -rf /mnt/maxOS_img_1/var && sudo cp -r filesystem/var /mnt/maxOS_img_1 \ No newline at end of file +msg "Copying filesystem to image" +sudo rm -rf /mnt/maxOS_img_1/bin && sudo cp -r ../filesystem/bin /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/dev && sudo cp -r ../filesystem/dev /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/etc && sudo cp -r ../filesystem/etc /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/home && sudo cp -r ../filesystem/home /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/lib && sudo cp -r ../filesystem/lib /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/media && sudo cp -r ../filesystem/media /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/opt && sudo cp -r ../filesystem/opt /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/tmp && sudo cp -r ../filesystem/tmp /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/usr && sudo cp -r ../filesystem/usr /mnt/maxOS_img_1 +sudo rm -rf /mnt/maxOS_img_1/var && sudo cp -r ../filesystem/var /mnt/maxOS_img_1 \ No newline at end of file diff --git a/toolchain/create_disk_img.sh b/toolchain/create_disk_img.sh index 21e26567..5157e6a7 100755 --- a/toolchain/create_disk_img.sh +++ b/toolchain/create_disk_img.sh @@ -1,11 +1,15 @@ +#!/bin/bash +source ./maxOS.sh + #Remove Old image -rm -rf maxOS.img +rm -rf ../maxOS.img || warn "Could not remove old image" #Create a 2GB image -qemu-img create maxOS.img 2G +qemu-img create ../maxOS.img 2G || fail "Could not create image" #Partion the image -fdisk maxOS.img -u=cylinders << EOF +msg "Partioning image" +fdisk ../maxOS.img -u=cylinders << EOF o n p @@ -22,52 +26,34 @@ a w EOF -#Install Filesystem Tools -sudo apt-get install dosfstools - #Try and unmount the old mount points -sudo umount /mnt/maxOS_img_1 || echo "umount failed but not to worry" +sudo umount /mnt/maxOS_img_1 || warn "Couldn't unmount old mount point" +sudo umount /mnt/maxOS_img_2 || warn "Couldn't unmount old mount point" -#Try and unmount the old mount points -sudo umount /mnt/maxOS_img_2 || echo "umount failed but not to worry" - -#Close the loop devices +#Close the loop devices and attach the image to a loop device +msg "Attaching image to loop device" sudo losetup -D - -#Mount the image to a loop device -sudo losetup --partscan /dev/loop0 maxOS.img +sudo losetup --partscan /dev/loop0 ../maxOS.img || fail "Could not mount image to loop device" ## IMAGE 1 +msg "Creating filesystem for partition 1" -#Create a FAT32 Filesystem (partion 1) -sudo mkfs.vfat -F 32 /dev/loop0p1 +#Create a FAT32 Filesystem +sudo mkfs.vfat -F 32 /dev/loop0p1 || fail "Could not create filesystem" -#Create a directory for the mount point -sudo mkdir -p /mnt/maxOS_img_1 - -#Mount the image to the mount point -sudo mount -o loop /dev/loop0p1 /mnt/maxOS_img_1 - -#Echo some test files -cd /mnt/maxOS_img_1 -sudo echo 'this is partition 1, file 1' | sudo tee file1.txt -sudo echo 'this is partition 1, file 2' | sudo tee file2.txt +#Create a directory for the mount point and mount the image to the mount point +sudo mkdir -p /mnt/maxOS_img_1 || fail "Could not create mount point" +sudo mount -o loop /dev/loop0p1 /mnt/maxOS_img_1 || fail "Could not mount image to mount point" ## IMAGE 2 +msg "Creating filesystem for partition 2" #Create a FAT32 Filesystem (partion 2) -sudo mkfs.vfat -F 32 /dev/loop0p2 +sudo mkfs.vfat -F 32 /dev/loop0p2 || fail "Could not create filesystem" #Create a directory for the mount point -sudo mkdir -p /mnt/maxOS_img_2 - -#Mount the image to the mount point -sudo mount -o loop /dev/loop0p2 /mnt/maxOS_img_2 - -#Echo some test files -cd /mnt/maxOS_img_2 -sudo echo 'this is partition 2, file 1. file 2 will span multiple clusters' | sudo tee file1.txt -sudo echo 'END OF FILE2' | sudo tee -a file2.txt +sudo mkdir -p /mnt/maxOS_img_2 || fail "Could not create mount point" +sudo mount -o loop /dev/loop0p2 /mnt/maxOS_img_2 || fail "Could not mount image to mount point" -#Install grub -sudo grub-install --root-directory=/mnt/maxOS_img_1 --no-floppy --modules="normal part_msdos ext2" /dev/loop0 \ No newline at end of file +#Install grub to the image +sudo grub-install --root-directory=/mnt/maxOS_img_1 --no-floppy --modules="normal part_msdos ext2" /dev/loop0 || fail "Could not install grub" \ No newline at end of file diff --git a/toolchain/increment_version.sh b/toolchain/increment_version.sh deleted file mode 100755 index 24745f24..00000000 --- a/toolchain/increment_version.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Define the file path -file_path="kernel/src/kernel.cpp" - -# Check if the file exists -if [ ! -f "$file_path" ]; then - echo "Error: File $file_path does not exist." - exit 1 -fi - -# Read the current value of buildCount -current_value=$(grep -oP 'int buildCount = \K\d+' "$file_path") - -# Check if the current value is a valid integer -if ! [[ "$current_value" =~ ^[0-9]+$ ]]; then - echo "Error: Unable to read the current buildCount value." - exit 1 -fi - -# Increment the current value by 1 -new_value=$((current_value + 1)) - -# Replace the old buildCount value with the new one in the file -sed -i "s/int buildCount = $current_value;/int buildCount = $new_value;/" "$file_path" - -echo "Incremented buildCount in $file_path from $current_value to $new_value." diff --git a/toolchain/make_cross_compiler.sh b/toolchain/make_cross_compiler.sh index d0dce62f..c51444d5 100755 --- a/toolchain/make_cross_compiler.sh +++ b/toolchain/make_cross_compiler.sh @@ -1,5 +1,9 @@ +#!/bin/bash +source ./maxOS.sh + # Install Dependencies if not told otherwise if [ "$1" != "--no-deps" ]; then + msg "Installing extra dependencies" sudo apt update sudo apt install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libisl-dev fi @@ -18,46 +22,48 @@ BINUTILS_VERSION=2.39 GCC_VERSION=12.2.0 # Print what we are doing -echo "Installing binutils-$BINUTILS_VERSION and gcc-$GCC_VERSION for $TARGET to $PREFIX" +msg "Installing binutils-$BINUTILS_VERSION and gcc-$GCC_VERSION for $TARGET to $PREFIX" # == Build Binutils == # Download Binutils if not already downloaded if [ ! -f binutils-$BINUTILS_VERSION.tar.gz ]; then + msg "Downloading binutils-$BINUTILS_VERSION" wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.gz tar xf binutils-$BINUTILS_VERSION.tar.gz fi # Configure binutils +msg "Configuring binutils-$BINUTILS_VERSION" mkdir build-binutils cd build-binutils -../binutils-$BINUTILS_VERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror +../binutils-$BINUTILS_VERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror || fail "Configuring binutils failed" # Build binutils -make -make install +msg "Building binutils-$BINUTILS_VERSION" +make || fail "Building binutils failed" +make install || fail "Installing binutils to $PREFIX failed" cd ../ # == Build GCC == -which -- $TARGET-as || echo $TARGET-as is not in the PATH # Download GCC if not already downloaded if [ ! -f gcc-$GCC_VERSION.tar.gz ]; then + msg "Downloading gcc-$GCC_VERSION" wget https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz tar xf gcc-$GCC_VERSION.tar.gz fi # Configure GCC +msg "Configuring gcc-$GCC_VERSION" mkdir build-gcc cd build-gcc -../gcc-$GCC_VERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers +../gcc-$GCC_VERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers || fail "Configuring gcc failed" # Build GCC -make all-gcc -make all-target-libgcc -make install-gcc -make install-target-libgcc - -# Test -$PREFIX/bin/$TARGET-gcc --version \ No newline at end of file +msg "Building gcc-$GCC_VERSION" +make all-gcc || fail "Building gcc failed" +make all-target-libgcc || fail "Building libgcc failed" +make install-gcc || fail "Installing gcc failed" +make install-target-libgcc || fail "Installing libgcc failed" \ No newline at end of file diff --git a/toolchain/maxOS.sh b/toolchain/maxOS.sh new file mode 100755 index 00000000..9005dae2 --- /dev/null +++ b/toolchain/maxOS.sh @@ -0,0 +1,36 @@ +err () { + printf "\e[31m[ERROR] $1 \e[39m\n" +} + +msg () { + printf "\e[36m[INFO] $1 \e[39m\n" +} + +warn () { + printf "\e[33m[WARN] $1 \e[39m\n" +} + +success () { + printf "\e[32m[SUCCESS] $1 \e[39m\n" +} + +fail () { + + # Print error message + err "$1" + + # If there is something to do on fail, do it (and only once) + if [ -z "$FAILING" ]; then + FAILING=1 + if [ ! -z "$ON_FAIL" ]; then + $ON_FAIL + fi + fi + + # Exit with error code + if [ $? -eq 0 ]; then + exit 1 + else + exit $? + fi +} \ No newline at end of file diff --git a/toolchain/run_qemu.sh b/toolchain/run_qemu.sh new file mode 100755 index 00000000..46b49d19 --- /dev/null +++ b/toolchain/run_qemu.sh @@ -0,0 +1,126 @@ +#!/bin/bash +source ./maxOS.sh + +# Check if KVM is supported +USE_KVM=0 +if [ -r /dev/kvm ]; then + msg "KVM is supported on this machine." + USE_KVM=1 +fi + +# Check if in WSL +IN_WSL=0 +if command -v wslpath >/dev/null; then + msg "WSL detected." + IN_WSL=1 +fi + +# Get the image path +if [ -z "$IMAGE_PATH" ]; then + msg "Using default image path." + IMAGE_PATH="../maxOS.img" +else + + # Check if the image path is valid + if [ ! -f "$IMAGE_PATH" ]; then + fail "Error: Image path $IMAGE_PATH does not exist." + fi + +fi + +# If in WSL, convert the image path to a windows path +if [ "$IN_WSL" -ne "0" ]; then + msg "Converting image path to windows path." + IMAGE_PATH=$(wslpath -w "$IMAGE_PATH") +fi + +# Check what accelerator to use +ACCELERATOR="" +if [ "$IN_WSL" -ne "0" ]; then + msg "Using windows accelerator." + ACCELERATOR="-accel whpx,kernel-irqchip=off -accel tcg" +else + + # Check if KVM is supported + if [ "$USE_KVM" -ne "0" ]; then + msg "Using KVM accelerator." + ACCELERATOR="-enable-kvm" + #TODO: TEST + fi + +fi + +# Find the qemu executable +QEMU_EXECUTABLE="" + +# Check if on linux or windows +if [ "$IN_WSL" -ne "0" ]; then + msg "Using windows qemu." + QEMU_EXECUTABLE="/mnt/c/Program Files/qemu/qemu-system-i386.exe" +else + msg "Using linux qemu." + QEMU_EXECUTABLE="qemu-system-i386" +fi + +# Check if the qemu executable exists +if [ ! -f "$QEMU_EXECUTABLE" ]; then + fail "Error: QEMU executable $QEMU_EXECUTABLE does not exist." +fi + +# Check what display type to use +DISPLAY_TYPE="" +if "$QEMU_EXECUTABLE" --display help | grep -q "sdl"; then + msg "Using sdl display." + DISPLAY_TYPE="-display sdl" +elif "$QEMU_EXECUTABLE" --display help | grep -q "cococa"; then + msg "Using cocoa display." + DISPLAY_TYPE="-display cocoa" +else + fail "Error: No display type found." +fi + +# Get the network interface +if [ -z "$NETWORK_DEVICE" ]; then + msg "Using default network device." + NETWORK_DEVICE="pcnet" +else + if ! "$QEMU_EXECUTABLE" -netdev help | grep -q "$NETWORK_DEVICE"; then + fail "Error: Network device $NETWORK_DEVICE not found." + fi +fi + +# Check if port forwarding is enabled +PORT_FORWARDING="" +if [ -n "$PORT_FORWARDING_HOST" ] && [ -n "$PORT_FORWARDING_GUEST" ]; then + msg "Port forwarding enabled." + PORT_FORWARDING=",hostfwd=tcp::$PORT_FORWARDING_HOST-:$PORT_FORWARDING_GUEST" +fi + +# Check if we are debugging +DEBUG="-s" +if [ "$USE_DEBUG" -ne "0" ]; then + msg "Debugging enabled." + DEBUG="-s -S" +fi + +# IF using the windows accelerator, disable debugging +if [ "$ACCELERATOR" == "-accel whpx,kernel-irqchip=off -accel tcg" ]; then + msg "Disabling debugging for windows accelerator." + DEBUG="" +fi + +# Create the args +QEMU_ARGS="" +QEMU_ARGS="$QEMU_ARGS -m 512" # 512 MB of RAM +QEMU_ARGS="$QEMU_ARGS -serial stdio" # Use stdio for serial +QEMU_ARGS="$QEMU_ARGS $DEBUG" # Enable debugging +QEMU_ARGS="$QEMU_ARGS $ACCELERATOR" # Enable acceleration +QEMU_ARGS="$QEMU_ARGS $DISPLAY_TYPE" # Enable display +QEMU_ARGS="$QEMU_ARGS -device $NETWORK_DEVICE,netdev=net0" # Add a network device +QEMU_ARGS="$QEMU_ARGS -netdev user,id=net0$PORT_FORWARDING" # Add a user network device +QEMU_ARGS="$QEMU_ARGS -drive file=$IMAGE_PATH,format=raw" # Add the image as a drive +QEMU_ARGS="$QEMU_ARGS,if=ide,cache=directsync,id=disk0" # Configure the drive to be an ide drive with direct sync caching + +# Run qemu +msg "Running qemu with args: $QEMU_ARGS" +"$QEMU_EXECUTABLE" $QEMU_ARGS \ No newline at end of file diff --git a/toolchain/version.sh b/toolchain/version.sh new file mode 100755 index 00000000..b6626916 --- /dev/null +++ b/toolchain/version.sh @@ -0,0 +1,66 @@ +#!/bin/bash +source ./maxOS.sh + +# If the buildCount file doesn't exist, create it +if [ ! -f ".buildCount" ]; then + echo "0" > .buildCount +fi + +# Increment the buildCount by 1 +new_value=$(($(cat .buildCount) + 1)) +echo "$new_value" > .buildCount + +# Version data +MAJOR_VERSION="0" +MINOR_VERSION="1" +VERSION_NAME="Development Version" +BUILD_NUMBER=$(cat .buildCount) +BUILD_YEAR="$(date +'%Y')" +BUILD_MONTH="$(date +'%m')" +BUILD_DAY="$(date +'%d')" +BUILD_HOUR="$(date +'%H')" +BUILD_MINUTE="$(date +'%M')" +BUILD_SECOND="$(date +'%S')" +GIT_REVISION="$(git rev-parse --short HEAD)" +GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" +GIT_COMMIT="$(git rev-list --count HEAD)" +GIT_AUTHOR="$(git log -1 --pretty=format:'%an')" + + + +# Write the version header +cat > "../kernel/include/common/version.h" << EOF +// +// This file is generated automatically by the maxOS build system. +// + +#ifndef MAX_OS_COMMON_VERSION_H +#define MAX_OS_COMMON_VERSION_H + + +#include +#include +#include + +namespace maxOS{ + + namespace common + { + + const uint8_t MAJOR_VERSION = ${MAJOR_VERSION}; + const uint8_t MINOR_VERSION = ${MINOR_VERSION}; + const string VERSION_STRING = "${MAJOR_VERSION}.${MINOR_VERSION}"; + const string VERSION_NAME = "${VERSION_NAME}"; + const int BUILD_NUMBER = ${BUILD_NUMBER}; + const Time BUILD_DATE = {${BUILD_YEAR}, ${BUILD_MONTH}, ${BUILD_DAY}, ${BUILD_HOUR}, ${BUILD_MINUTE}, ${BUILD_SECOND}}; + const string GIT_REVISION = "${GIT_REVISION}"; + const string GIT_BRANCH = "${GIT_BRANCH}"; + const int GIT_COMMIT = ${GIT_COMMIT}; + const string GIT_AUTHOR = "${GIT_AUTHOR}"; + + } + +} + +#endif //MAX_OS_VERSION_H +EOF \ No newline at end of file