Major refactoring, added Makefile
This commit is contained in:
parent
0193c26413
commit
b812a9899f
|
@ -58,7 +58,6 @@ CMakeCache.txt
|
||||||
CMakeFiles
|
CMakeFiles
|
||||||
CMakeScripts
|
CMakeScripts
|
||||||
Testing
|
Testing
|
||||||
Makefile
|
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
install_manifest.txt
|
install_manifest.txt
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Linux",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"${workspaceFolder}/include/"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"cStandard": "gnu17",
|
||||||
|
"cppStandard": "gnu++17",
|
||||||
|
"intelliSenseMode": "linux-gcc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
# Note: Your cross-compilation toolchain must be in PATH for this
|
||||||
|
# to work. Change these variables if it isn't (it should be, trust me)
|
||||||
|
|
||||||
|
.SUFFIXES:
|
||||||
|
|
||||||
|
CC := i386-elf-gcc
|
||||||
|
GDB := i386-elf-gdb
|
||||||
|
LD := i386-elf-ld
|
||||||
|
AS := nasm
|
||||||
|
IDIR := include
|
||||||
|
SRCDIR := src
|
||||||
|
BUILDDIR := build
|
||||||
|
OBJDIR := obj
|
||||||
|
DISTDIR := dist
|
||||||
|
CFLAGS := -g -I $(IDIR) -Wall -pedantic -Wno-builtin-declaration-mismatch -ffreestanding
|
||||||
|
KERNEL_SOURCES := $(shell find src/kernel -name '*.c' -type f)
|
||||||
|
KERNEL_OBJS := $(KERNEL_SOURCES:.c=.o)
|
||||||
|
KERNEL_OBJS := $(subst src/,$(OBJDIR)/,$(KERNEL_OBJS))
|
||||||
|
|
||||||
|
DRIVERS_SOURCES := $(shell find src/kernel/drivers -name '*.c' -type f)
|
||||||
|
DRIVERS_OBJS := $(DRIVERS_SOURCES:.c=.o)
|
||||||
|
DRIVERS_OBJS := $(subst src/,$(OBJDIR)/,$(DRIVERS_OBJS))
|
||||||
|
|
||||||
|
|
||||||
|
BOOTLOADER_SOURCES := $(shell find src/boot -name '*.s' -type f)
|
||||||
|
BOOTLOADER_OBJS := $(BOOTLOADER_SOURCES:.s=.o)
|
||||||
|
BOOTLOADER_OBJS := $(subst src/,$(OBJDIR)/,$(BOOTLOADER_OBJS))
|
||||||
|
|
||||||
|
|
||||||
|
BUILD_PATHS := $(subst src/,$(OBJDIR),$(dir $(KERNEL_OBJS)))
|
||||||
|
BUILD_PATHS += $(subst src/,$(OBJDIR),$(dir $(DRIVERS_OBJS)))
|
||||||
|
|
||||||
|
|
||||||
|
prepare:
|
||||||
|
mkdir -p $(BUILD_PATHS)
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf obj/
|
||||||
|
rm -rf build/
|
||||||
|
rm -rf dist/
|
||||||
|
|
||||||
|
|
||||||
|
# Produce obj/path/to/file.o in the ELF format
|
||||||
|
# if src/path/to/file.s exists
|
||||||
|
$(OBJDIR)/%.o: prepare $(SRCDIR)/%.s
|
||||||
|
$(AS) -f elf $(word 2,$^) -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Produce build/path/to/file.bin in the binary
|
||||||
|
# format if src/path/to/file.s exists
|
||||||
|
$(BUILDDIR)/%.bin: prepare $(SRCDIR)/%.s
|
||||||
|
$(AS) -f bin $(word 2,$^) -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Special case for our master boot record
|
||||||
|
$(BUILDDIR)/mbr.bin: prepare $(SRCDIR)/boot/mbr.s
|
||||||
|
$(AS) -f bin $(word 2,$^) -o $(BUILDDIR)/mbr.bin
|
||||||
|
|
||||||
|
|
||||||
|
# Produce obj/path/to/file.o using gcc if
|
||||||
|
# src/path/to/file.c exists
|
||||||
|
$(OBJDIR)/%.o: prepare $(SRCDIR)/%.c
|
||||||
|
$(CC) $(CFLAGS) -c $(word 2,$^) -o $@
|
||||||
|
|
||||||
|
|
||||||
|
# Compile kernel drivers
|
||||||
|
drivers: $(DRIVERS_OBJS)
|
||||||
|
|
||||||
|
# Compile and link the kernel
|
||||||
|
$(BUILDDIR)/kernel.bin: $(OBJDIR)/entrypoint.o $(KERNEL_OBJS) $(DRIVERS_OBJS)
|
||||||
|
$(LD) -o $@ -Ttext 0x1000 $^ --oformat binary
|
||||||
|
|
||||||
|
|
||||||
|
kernel: $(BUILDDIR)/kernel.bin
|
||||||
|
|
||||||
|
# Compile the bootloader
|
||||||
|
bootloader: $(BUILDDIR)/mbr.bin
|
||||||
|
|
||||||
|
|
||||||
|
# Compile and link everything
|
||||||
|
all: bootloader drivers kernel
|
||||||
|
|
||||||
|
|
||||||
|
image: $(BUILDDIR)/mbr.bin $(BUILDDIR)/kernel.bin
|
||||||
|
mkdir -p $(DISTDIR)/
|
||||||
|
cat $^ > $(DISTDIR)/os.img
|
||||||
|
|
||||||
|
|
||||||
|
run: image
|
||||||
|
qemu-system-x86_64 -drive format=raw,file=$(DISTDIR)/os.img,index=0,media=disk
|
|
@ -1,19 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
mkdir /tmp/src
|
|
||||||
cd /tmp/src
|
|
||||||
curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.gz
|
|
||||||
tar xf binutils-2.39.tar.gz
|
|
||||||
mkdir binutils-build
|
|
||||||
cd binutils-build
|
|
||||||
../binutils-2.39/configure --target=$TARGET --enable-interwork --enable-multilib --disable-nls --disable-werror --prefix=$PREFIX 2>&1 | tee configure.log
|
|
||||||
sudo make all install 2>&1 | tee make.log
|
|
||||||
cd /tmp/src
|
|
||||||
curl -O https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.gz
|
|
||||||
tar xf gcc-12.2.0.tar.gz
|
|
||||||
mkdir gcc-build
|
|
||||||
cd gcc-build
|
|
||||||
../gcc-12.2.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --disable-libssp --enable-languages=c --without-headers
|
|
||||||
sudo make all-gcc
|
|
||||||
sudo make all-target-libgcc
|
|
||||||
sudo make install-gcc
|
|
||||||
sudo make install-target-libgcc
|
|
12
build.sh
12
build.sh
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# Compile the kernel and its drivers
|
|
||||||
i386-elf-gcc -ffreestanding -I src/ -c src/kernel/main.c -o obj/kernel.o
|
|
||||||
i386-elf-gcc -ffreestanding -I src/ -c src/kernel/drivers/vga/screen.c -o obj/screen.o
|
|
||||||
i386-elf-gcc -ffreestanding -I src/ -c src/kernel/drivers/ports/ports.c -o obj/ports.o
|
|
||||||
# Compile the assembly entry point and the MBR
|
|
||||||
nasm -f elf src/entrypoint.s -o obj/entry.o
|
|
||||||
nasm -f bin src/boot/mbr.s -o build/mbr.bin
|
|
||||||
# Link everything together
|
|
||||||
i386-elf-ld -o build/kernel.bin -Ttext 0x1000 entry.o kernel.o ports.o screen.o --oformat binary
|
|
||||||
# Produce a bootable image
|
|
||||||
cat build/mbr.bin build/kernel.bin > build/os.img
|
|
6
env.sh
6
env.sh
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
export CC=/usr/bin/gcc
|
|
||||||
export LD=/usr/bin/gcc
|
|
||||||
export PREFIX="/usr/local/i386elfgcc"
|
|
||||||
export TARGET=i386-elf
|
|
||||||
export PATH=$PATH:$PREFIX/bin
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "kernel/ktypes.h"
|
#include "kernel/ktypes.h"
|
||||||
#include "kernel/drivers/ports/ports.h"
|
#include "kernel/drivers/ports/ports.h"
|
||||||
|
|
||||||
|
|
||||||
#define VMEM_ADDRESS 0xb8000
|
#define VMEM_ADDRESS 0xb8000
|
||||||
#define VMEM_BUF ((byte*)VMEM_ADDRESS)
|
#define VMEM_BUF ((byte*)VMEM_ADDRESS)
|
||||||
#define MAX_ROWS 25
|
#define MAX_ROWS 25
|
||||||
|
@ -21,8 +22,8 @@
|
||||||
|
|
||||||
// Public API
|
// Public API
|
||||||
void clearScreen(void);
|
void clearScreen(void);
|
||||||
void kprintAt(byte* message, i32 col, i32 row);
|
void kprintAt(char* message, i32 col, i32 row);
|
||||||
void kprint(byte* message);
|
void kprint(char* message);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
2
run.sh
2
run.sh
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
qemu-system-x86_64 -drive format=raw,file=build/os.bin,index=0,media=disk
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Utilities for writing to and reading from I/O ports
|
// Utilities for writing to and reading from I/O ports
|
||||||
|
|
||||||
#include "ports.h"
|
#include "kernel/drivers/ports/ports.h"
|
||||||
|
|
||||||
|
|
||||||
// Note: We use the volatile modifier everywhere because
|
// Note: We use the volatile modifier everywhere because
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Implementation of a simple text-only VGA driver
|
// Implementation of a simple text-only VGA driver
|
||||||
#include "screen.h"
|
#include "kernel/drivers/vga/screen.h"
|
||||||
#include "kernel/ktypes.h"
|
#include "kernel/ktypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ i32 getColumn(i32 offset);
|
||||||
|
|
||||||
// Public API below
|
// Public API below
|
||||||
|
|
||||||
void kprintAt(byte* message, i32 col, i32 row) {
|
void kprintAt(char* message, i32 col, i32 row) {
|
||||||
/*
|
/*
|
||||||
Prints a null-terminated string to the VGA
|
Prints a null-terminated string to the VGA
|
||||||
text buffer at the specified row and column.
|
text buffer at the specified row and column.
|
||||||
|
@ -42,7 +42,7 @@ void kprintAt(byte* message, i32 col, i32 row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void kprint(byte* message) {
|
void kprint(char* message) {
|
||||||
/*
|
/*
|
||||||
Prints a null-terminated string to the
|
Prints a null-terminated string to the
|
||||||
VGA text buffer
|
VGA text buffer
|
||||||
|
|
Loading…
Reference in New Issue