Restrucure target folder and move creation of boot.bin to c program
This commit is contained in:
parent
d4ede49d1e
commit
07fbe8ee4c
3 changed files with 71 additions and 10 deletions
28
Makefile
28
Makefile
|
@ -1,15 +1,23 @@
|
||||||
run_bootloader: compile_bootloader
|
run: bin
|
||||||
qemu-system-i386 -drive format=raw,file=target/boot.bin -monitor stdio
|
qemu-system-i386 -drive format=raw,file=target/boot.bin -monitor stdio
|
||||||
|
|
||||||
run_kernel: compile_kernel
|
clean:
|
||||||
qemu-system-i386 -kernel target/kernel.bin
|
rm -r ./target/
|
||||||
|
mkdir -p ./target/helpers
|
||||||
|
mkdir ./target/bootloader
|
||||||
|
mkdir ./target/kernel
|
||||||
|
|
||||||
compile_bootloader: compile_kernel
|
bin: compile_bootloader compile_kernel compile_helpers
|
||||||
rm -rf target/bootloader.bin
|
./target/helpers/make_bin
|
||||||
nasm -f bin -o target/bootloader.bin bootloader/main.asm
|
|
||||||
cat target/bootloader.bin target/kernel.bin > target/boot.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:
|
compile_kernel:
|
||||||
nasm -felf32 kernel/boot.asm -o target/boot.o
|
nasm -felf32 kernel/wrapper.asm -o target/kernel/wrapper.o
|
||||||
i686-elf-gcc -c kernel/kernel.c -o target/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
|
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.bin -ffreestanding -O2 -nostdlib target/boot.o target/kernel.o -lgcc
|
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
53
helpers/make_bin.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue