|
1 |
| -# Automatically generate lists of sources using wildcard. |
2 |
| -C_SOURCES = $(wildcard kernel/*.c kernel/drivers/vga/*.c drivers/*.c kernel/drivers/io/*.c) |
3 |
| -HEADERS = $(wildcard kernel/*.h kernel/drivers/vga/*.h drivers/*.h kernel/drivers/io/*.h) |
| 1 | +all: |
| 2 | + # actual bootloader |
| 3 | + nasm -f elf stage2/start_loader.asm -o start_loader.o |
| 4 | + |
| 5 | + x86_64-elf-gcc -m32 -ffreestanding -c stage2/fs.c -o fs.o |
| 6 | + x86_64-elf-gcc -m32 -ffreestanding -c stage2/mbr.c -o mbr.o |
| 7 | + x86_64-elf-gcc -m32 -ffreestanding -c stage2/loader.c -o loader.o |
4 | 8 |
|
5 |
| -# Convert *.c filenames to *.o as a list of object files to build. |
6 |
| -OBJ = ${C_SOURCES:.c=.o} |
| 9 | + x86_64-elf-ld -melf_i386 -o bootloader.bin -Ttext 0x1000 --oformat binary start_loader.o loader.o fs.o mbr.o |
7 | 10 |
|
8 |
| -# Clean, build, and run. |
9 |
| -all: clean os-image run |
| 11 | + # stage1 |
| 12 | + nasm -f bin stage1/load_kernel.asm -o load_kernel.bin -D USE_GRAPHICS |
10 | 13 |
|
11 |
| -# Removes all built files. |
12 | 14 | clean:
|
13 |
| - rm -f boot/*.bin |
14 |
| - rm -f drivers/*.o |
15 |
| - rm -f example/*.bin example/*.o |
16 |
| - rm -f kernel/*.bin kernel/*.o |
17 |
| - rm -f kernel/drivers/vga/*.o |
18 |
| - rm -f os-image |
19 |
| - |
20 |
| -# Kernel code -------------------------------------------------------------------------------------- |
21 |
| - |
22 |
| -# Create kernel binary by linking kernel entry code, kernel main, and other object files. |
23 |
| -kernel/kernel.bin: kernel/enter_kernel.o $(OBJ) |
24 |
| - x86_64-elf-ld -melf_i386 -o $@ -Ttext 0x1000 --oformat binary $^ |
25 |
| - |
26 |
| -# Create executable image by prepending kernel binary with boot sector. |
27 |
| -os-image: boot/load_kernel.bin kernel/kernel.bin |
28 |
| - cat $^ > $@ |
29 |
| - |
30 |
| -# Compile assembly sources into binary. |
31 |
| -%.bin: %.asm |
32 |
| - nasm $< -f bin -o $@ -D USE_GRAPHICS |
33 |
| - #nasm $< -f bin -o $@ |
34 |
| - |
35 |
| -# Assemble the kernel entry to an object file. |
36 |
| -%.o: %.asm |
37 |
| - nasm $< -f elf -o $@ |
38 |
| - |
39 |
| -# Compile C sources into object files. |
40 |
| -%.o: %.c |
41 |
| - x86_64-elf-gcc -m32 -ffreestanding -c $< -o $@ |
42 |
| - |
43 |
| -# -------------------------------------------------------------------------------------------------- |
44 |
| - |
45 |
| -# Run operating system on emulated x86. |
46 |
| -run: os-image |
47 |
| - qemu-system-x86_64 -drive file=$<,format=raw -net none -no-reboot -no-shutdown -monitor stdio --enable-kvm |
| 15 | + rm -f load_kernel.bin |
| 16 | + rm -f start_loader.o |
| 17 | + rm -f loader.o |
| 18 | + rm -f bootloader.bin |
| 19 | + rm -f fs.o |
| 20 | + rm -f mbr.o |
0 commit comments