Skip to content

Commit

Permalink
Cross Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Dec 4, 2023
1 parent ce21e1e commit a92e5e2
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 106 deletions.
50 changes: 8 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

GCC_PARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -g
GCC_EXEC ?= gcc
TARGET=i686-elf
GCC_EXEC ?= $$HOME/opt/cross/bin/$(TARGET)-gcc

BUILD_COMPLETE ?= make runQ

Expand Down Expand Up @@ -134,21 +135,6 @@ maxOS.bin: linker.ld $(kernel) $(libraries) $(ports) $(programs)
ld $(LD_PARAMS) -T $< -o $@ $(kernel) $(libraries) $(ports) $(programs)
objcopy --only-keep-debug $@ maxOS.sym

maxOS.iso: maxOS.bin
mkdir iso
mkdir iso/boot
mkdir iso/boot/grub
cp $< iso/boot
echo 'set timeout=0' > iso/boot/grub/grub.cfg
echo 'set default=0' >> iso/boot/grub/grub.cfg
echo '' >> iso/boot/grub/grub.cfg
echo 'menuentry "Max OS" {' >> iso/boot/grub/grub.cfg
echo ' multiboot /boot/maxOS.bin' >> iso/boot/grub/grub.cfg
echo ' boot' >> iso/boot/grub/grub.cfg
echo '}' >> iso/boot/grub/grub.cfg
grub-mkrescue --output=maxOS.iso iso
rm -rf iso

.PHONY: filesystem
filesystem:
toolchain/copy_filesystem.sh
Expand Down Expand Up @@ -176,35 +162,15 @@ build: maxOS.bin
@echo === Made Max OS ===
make incrementVersion



test: build
echo Testing


## QEMU


runQ: build
qemu: build
qemu-system-i386 $(QEMU_PARAMS) $(QEMU_EXTRA_PARAMS)

runQ_W: maxOS.iso
"C:\Program Files\qemu\qemu-system-i386" $(QEMU_PARAMS) $(QEMU_EXTRA_PARAMS)

debugQ: build
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'

guiDebugQ: build
x-terminal-emulator -e make runQ QEMU_EXTRA_PARAMS="-s -S -curses" & gdb -ex 'set remotetimeout 300' -ex 'target remote localhost:1234' -ex 'symbol-file maxOS.sym' -tui

install_dep:
sudo apt-get update -y
sudo apt-get install g++ binutils libc6-i386 grub-pc xorriso mtools

install_run_dep:
sudo apt-get install qemu-system-i386
sudo apt-get install gdb

.PHONY: clean
clean:
rm -rf obj
rm -rf obj

cross_compiler:
cd toolchain && ./make_cross_compiler.sh
6 changes: 1 addition & 5 deletions kernel/include/memory/memorymanagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace maxOS{

void* malloc(common::size_t size);
void free(void* pointer);
int getMemoryUsed();

template<class Type> Type* Instantiate(common::uint32_t numberOfElements=1){
Type* result = (Type*)malloc(sizeof(Type)*numberOfElements);
Expand Down Expand Up @@ -65,11 +66,6 @@ namespace maxOS{
return result;
}






};
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/src/kernel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int buildCount = 466;
int buildCount = 488;
// This is the build counter, it is incremented every time the build script is run. Started 27/09/2023, Commit 129

//Common
Expand Down Expand Up @@ -224,6 +224,7 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi
size_t heap = 10*1024*1024; //Start at 10MB
size_t memSize = memupper*1024 - heap - 10*1024; //Convert memupper into MB, then subtract the hep and some padding
MemoryManager memoryManager(heap, memSize); //Memory Mangement
cout << "Memory: " << (int)memoryManager.getMemoryUsed()/1000000 << "MB used, " << (int)memSize/1000000 << "MB available\n";
cout << "-- Set Up Memory Management\n";
systemSetupHeaderStream << ".";

Expand Down Expand Up @@ -454,7 +455,6 @@ extern "C" void kernelMain(const multiboot_info& multibootHeader, uint32_t multi

#endif

// Run the GUI

//#define GUI
#ifdef GUI
Expand Down
21 changes: 16 additions & 5 deletions kernel/src/memory/memorymanagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ MemoryManager::MemoryManager(common::size_t start, common::size_t size) {
first -> prev = 0;
first -> next = 0;
first -> size = size - sizeof(MemoryChunk);

}



}

MemoryManager::~MemoryManager() {
Expand All @@ -52,7 +48,6 @@ void* MemoryManager::malloc(common::size_t size) {
//Common way of iterating through a linked list
for (MemoryChunk* chunk = first; chunk != 0 && result == 0; chunk = chunk->next) { //Iterate through the list of chunks


if(chunk -> size > size && !chunk -> allocated){ //If the chunk is big enough and not being used
result = chunk;
}
Expand Down Expand Up @@ -149,6 +144,22 @@ void MemoryManager::free(void *pointer) {

}

int MemoryManager::getMemoryUsed() {

int result = 0;

for (MemoryChunk* chunk = first; chunk != 0; chunk = chunk->next) { //Iterate through the list of chunks

if(chunk -> allocated){ //If the chunk is big enough and not being used
result += chunk -> size;
}

}

return result;

}



//Redefine the default object functions with memory orientated ones (defaults disabled in makefile)
Expand Down
11 changes: 0 additions & 11 deletions toolchain/build_via_tc.sh

This file was deleted.

56 changes: 56 additions & 0 deletions toolchain/make_cross_compiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Install Dependencies
sudo apt install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libisl-dev

# Make A Directory For The Cross Compiler
mkdir -p ./cross_compiler
cd ./cross_compiler

# Export the paths
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"

# Store versions in a variable
BINUTILS_VERSION=2.39
GCC_VERSION=12.2.0

# == Build Binutils ==

# Download Binutils if not already downloaded
if [ ! -f binutils-$BINUTILS_VERSION.tar.gz ]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.gz
tar xf binutils-$BINUTILS_VERSION.tar.gz
fi

# Configure binutils
mkdir build-binutils
cd build-binutils
../binutils-$BINUTILS_VERSION/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror

# Build binutils
make
make install
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
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
mkdir build-gcc
cd build-gcc
../gcc-$GCC_VERSION/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers

# Build GCC
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

# Test
$HOME/opt/cross/bin/$TARGET-gcc --version
41 changes: 0 additions & 41 deletions toolchain/make_toolcahin.sh

This file was deleted.

0 comments on commit a92e5e2

Please sign in to comment.