Skip to content

Commit

Permalink
Rewrite Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Dec 16, 2023
1 parent 87b587f commit 60cc7e9
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 223 deletions.
162 changes: 37 additions & 125 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ###

Expand All @@ -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
Expand All @@ -177,4 +87,6 @@ disk_img:

install_deps:
sudo apt-get update -y
sudo apt-get install -y grub-pc qemu-system-i386 gdb
sudo apt-get install -y grub-pc qemu-system-i386 gdb dosfstools


Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 0 additions & 1 deletion kernel/src/drivers/ethernet/rawdatahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <drivers/ethernet/rawdatahandler.h>

using namespace maxOS;
using namespace maxOS::common;
using namespace maxOS::drivers;
using namespace maxOS::drivers::ethernet;

Expand Down
21 changes: 16 additions & 5 deletions kernel/src/kernel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//Common
#include <stdint.h>
#include <common/logo.h>
#include <common/version.h>

//Hardware com
#include <hardwarecommunication/interrupts.h>
Expand Down Expand Up @@ -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);
Expand All @@ -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";

Expand Down Expand Up @@ -273,9 +284,9 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi
Vector<DriverSelector*> 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);
Expand Down
34 changes: 20 additions & 14 deletions toolchain/copy_filesystem.sh
Original file line number Diff line number Diff line change
@@ -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
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
Loading

0 comments on commit 60cc7e9

Please sign in to comment.