Restrucure target folder and move creation of boot.bin to c program

This commit is contained in:
Robbe Van Herck 2020-01-03 14:07:50 +01:00
parent d4ede49d1e
commit 07fbe8ee4c
No known key found for this signature in database
GPG key ID: A66F76F7B81BD784
3 changed files with 71 additions and 10 deletions

View file

@ -1,15 +1,23 @@
run_bootloader: compile_bootloader
run: bin
qemu-system-i386 -drive format=raw,file=target/boot.bin -monitor stdio
run_kernel: compile_kernel
qemu-system-i386 -kernel target/kernel.bin
clean:
rm -r ./target/
mkdir -p ./target/helpers
mkdir ./target/bootloader
mkdir ./target/kernel
compile_bootloader: compile_kernel
rm -rf target/bootloader.bin
nasm -f bin -o target/bootloader.bin bootloader/main.asm
cat target/bootloader.bin target/kernel.bin > target/boot.bin
bin: compile_bootloader compile_kernel compile_helpers
./target/helpers/make_bin
compile_helpers:
gcc -o ./target/helpers/make_bin ./helpers/make_bin.c
compile_bootloader:
rm -rf target/bootloader/bootloader.bin
nasm -f bin -o target/bootloader/bootloader.bin bootloader/main.asm
compile_kernel:
nasm -felf32 kernel/boot.asm -o target/boot.o
i686-elf-gcc -c kernel/kernel.c -o target/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
i686-elf-gcc -T kernel/linker.ld -o target/kernel.bin -ffreestanding -O2 -nostdlib target/boot.o target/kernel.o -lgcc
nasm -felf32 kernel/wrapper.asm -o target/kernel/wrapper.o
i686-elf-gcc -c kernel/kernel.c -o target/kernel/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
i686-elf-gcc -T kernel/linker.ld -o target/kernel/kernel.bin -ffreestanding -O2 -nostdlib target/kernel/wrapper.o target/kernel/kernel.o -lgcc

53
helpers/make_bin.c Normal file
View file

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define KERNEL_SECTORS 64
int main(int argc, char** argv) {
FILE* result_file = fopen("./target/boot.bin", "w+b");
FILE* bootloader_file = fopen("./target/bootloader/bootloader.bin", "rb");
// ------- BOOTLOADER + SFS HEADER -------
char* buffer = calloc(512, sizeof(char));
int i = 0;
int curr_char;
while ((curr_char = fgetc(bootloader_file)) != EOF) {
buffer[i] = (char) curr_char;
i++;
}
// TODO edit SFS header
buffer[0x194] = 0xff;
for (int i = 0; i < 512; i++) {
fputc(buffer[i], result_file);
}
fclose(bootloader_file);
// ------- KERNEL -------
FILE* kernel_file = fopen("./target/kernel/kernel.bin", "rb");
int bytes_written = 0;
while ((curr_char = fgetc(kernel_file)) != EOF) {
fputc((char) curr_char, result_file);
bytes_written++;
}
for (; bytes_written < KERNEL_SECTORS * 512; bytes_written++) {
fputc(0, result_file);
}
fclose(result_file);
return EXIT_SUCCESS;
}