11BL_SRC_DIR = src/bootloader
2+ KERNEL_SRC_DIR = src/kernel
23SYSCALLS_SRC_DIR = src/lib/syscalls
34LIB_SRC_DIR = src/lib
45UTIL_SRC_DIR = src/lib/util
@@ -15,6 +16,11 @@ bt_stage2 = $(BUILD_DIR)/bt_stage2
1516image_vmdk = $(BUILD_DIR ) /image.vmdk
1617app_entry_o = $(BUILD_DIR ) /app_entry.o
1718
19+ # Kernel
20+ kernel_core = $(BUILD_DIR ) /kernel_core
21+ kernel_core_c_o = $(BUILD_DIR ) /kernel_core_c.o
22+ kernel_core_asm_o = $(BUILD_DIR ) /kernel_core_asm.o
23+
1824# Apps
1925app_calc = $(BUILD_DIR ) /calc
2026app_ttt = $(BUILD_DIR ) /ttt
@@ -32,25 +38,33 @@ all: images binaries
3238
3339images : $(image_vmdk )
3440
35- binaries : $(bt_stage1 ) $(bt_stage2 )
41+ binaries : $(bt_stage1 ) $(bt_stage2 ) $( kernel_core )
3642
37- $(image_vmdk ) : $(bt_stage1 ) $(bt_stage2 ) $(app_calc ) $(app_ttt )
43+ $(image_vmdk ) : $(bt_stage1 ) $(bt_stage2 ) $( kernel_core ) $(app_calc ) $(app_ttt )
3844 dd bs=512 count=2 if=$(bt_stage1 ) of=$@
3945 /bin/echo -ne " \x55\xaa" | dd seek=510 bs=1 of=$@
40- cat $(bt_stage2 ) >> $@
41- cat $(app_calc ) >> $@
42- cat $(app_ttt ) >> $@
4346 @echo " Stage 1 Size : " $$(stat -c %s $(bt_stage1 ) )
47+ @echo " BT_STAGE2_SECTOR_START : " $$(( 1 + $$(stat -c %s $(image_vmdk ) ) / 512 ) )
48+ cat $(bt_stage2 ) >> $@
4449 @echo " Stage 2 Size : " $$(stat -c %s $(bt_stage2 ) )
45- @echo " App Calc Size : " $$(stat -c %s $(app_calc ) )
46- @echo " App TTT Size : " $$(stat -c %s $(app_ttt ) )
47- @echo " Image Size : " $$(stat -c %s $@ )
4850 @echo " Want BT_STAGE2_SECTOR_COUNT : 0x" $$(printf "%x\n" $$(( $$(stat -c %s $(bt_stage2 ) ) / 512 ) ) )
4951 @echo " Got BT_STAGE2_SECTOR_COUNT : 0x" $(BT_STAGE2_SECTOR_COUNT )
52+
53+ @echo " AppCalc Sector Start : " $$(( 1 + $$(stat -c %s $(image_vmdk ) ) / 512 ) )
54+ cat $(app_calc ) >> $@
5055 @echo " AppCalc Sector Count : " $$(( $$(stat -c %s $(app_calc ) ) / 512 ) )
51- @echo " AppCalc Sector Start : " $$(( 1 + $$(stat -c %s $(bt_stage1 ) ) / 512 + $$(stat -c %s $(bt_stage2 ) ) / 512 ) )
56+ @echo " App Calc Size : " $$(stat -c %s $(app_calc ) )
57+
58+ @echo " AppTTT Sector Start : " $$(( 1 + $$(stat -c %s $(image_vmdk ) ) / 512 ) )
59+ cat $(app_ttt ) >> $@
5260 @echo " AppTTT Sector Count : " $$(( $$(stat -c %s $(app_ttt ) ) / 512 ) )
53- @echo " AppTTT Sector Start : " $$(( 1 + $$(stat -c %s $(bt_stage1 ) ) / 512 + $$(stat -c %s $(bt_stage2 ) ) / 512 + $$(stat -c %s $(app_calc ) ) / 512 ) )
61+ @echo " App TTT Size : " $$(stat -c %s $(app_ttt ) )
62+
63+ @echo " Kernel Core Sector Start : " $$(( 1 + $$(stat -c %s $(image_vmdk ) ) / 512 ) )
64+ cat $(kernel_core ) >> $@
65+ @echo " Kernel Core Sector Count : " $$(( $$(stat -c %s $(kernel_core ) ) / 512 ) )
66+ @echo " Kernel Core Size : " $$(stat -c %s $(kernel_core ) )
67+ @echo " Image Size : " $$(stat -c %s $@ )
5468
5569$(bt_stage1 ) : $(BL_SRC_DIR ) /stage1.asm $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(BL_SRC_DIR ) /disk.asm
5670 nasm -o $@ -f bin -i $(BL_SRC_DIR ) / -D BT_STAGE2_SECTOR_COUNT=$(BT_STAGE2_SECTOR_COUNT ) $<
@@ -63,18 +77,28 @@ $(bt_stage2): $(bt_stage2_asm_o) $(bt_stage2_c_o)
6377$(bt_stage2_c_o ) : $(BL_SRC_DIR ) /stage2.c $(SYSCALLS_SRC_DIR ) /basic.h $(SYSCALLS_SRC_DIR ) /io.h $(SYSCALLS_SRC_DIR ) /time.h $(SYSCALLS_SRC_DIR ) /color.h $(UTIL_SRC_DIR ) /string.h $(APP_DIR ) /dashboard.c
6478 gcc -m16 -fno-pie -c -Isrc -o $@ $<
6579
66- $(bt_stage2_asm_o ) : $(BL_SRC_DIR ) /stage2.asm $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_syscall .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm $(bt_stage2_o ) $(SYSCALLS_SRC_DIR ) /disk_syscall.asm
80+ $(bt_stage2_asm_o ) : $(BL_SRC_DIR ) /stage2.asm $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_interface_bios .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm $(bt_stage2_o ) $(SYSCALLS_SRC_DIR ) /disk_syscall.asm
6781 nasm -o $@ -f elf32 -i $(BL_SRC_DIR ) / -i$(SYSCALLS_SRC_DIR ) / $<
6882
69- $(app_entry_o ) : $(LIB_SRC_DIR ) /app/entry.asm $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_syscall.asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
83+ $(kernel_core ) : $(kernel_core_asm_o ) $(kernel_core_c_o )
84+ ld --oformat binary -m elf_i386 -Ttext 0xC000 --strip-all -o $@ $^
85+ truncate --size=%512 $@
86+
87+ $(kernel_core_asm_o ) : $(KERNEL_SRC_DIR ) /core.asm
88+ nasm -o $@ -f elf32 -i $(KERNEL_SRC_DIR ) / -i$(SYSCALLS_SRC_DIR ) / $<
89+
90+ $(kernel_core_c_o ) : $(KERNEL_SRC_DIR ) /core.c
91+ gcc -m16 -fno-pie -c -Isrc -o $@ $<
92+
93+ $(app_entry_o ) : $(LIB_SRC_DIR ) /app/entry.asm $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_interface_bios.asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
7094 nasm -o $@ -f elf32 -i $(BL_SRC_DIR ) / -i$(SYSCALLS_SRC_DIR ) / $<
7195
72- $(app_calc ) : $(app_entry_o ) $(APP_DIR ) /calc.c $(SYSCALLS_SRC_DIR ) /basic.h $(SYSCALLS_SRC_DIR ) /io.h $(SYSCALLS_SRC_DIR ) /time.h $(SYSCALLS_SRC_DIR ) /color.h $(UTIL_SRC_DIR ) /string.h $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_syscall .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
96+ $(app_calc ) : $(app_entry_o ) $(APP_DIR ) /calc.c $(SYSCALLS_SRC_DIR ) /basic.h $(SYSCALLS_SRC_DIR ) /io.h $(SYSCALLS_SRC_DIR ) /time.h $(SYSCALLS_SRC_DIR ) /color.h $(UTIL_SRC_DIR ) /string.h $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_interface_bios .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
7397 gcc -m16 -fno-pie -c -Isrc -o $(BUILD_DIR ) /calc.o $(APP_DIR ) /calc.c
74- ld --oformat binary -m elf_i386 -Ttext 0xC000 --strip-all -o $@ $(app_entry_o ) $(BUILD_DIR ) /calc.o
98+ ld --oformat binary -m elf_i386 -Ttext 0x2000 --strip-all -o $@ $(app_entry_o ) $(BUILD_DIR ) /calc.o
7599 truncate --size=%512 $@
76100
77- $(app_ttt ) : $(app_entry_o ) $(APP_DIR ) /tic_tac_toe.c $(SYSCALLS_SRC_DIR ) /basic.h $(SYSCALLS_SRC_DIR ) /io.h $(SYSCALLS_SRC_DIR ) /time.h $(SYSCALLS_SRC_DIR ) /color.h $(UTIL_SRC_DIR ) /string.h $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_syscall .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
101+ $(app_ttt ) : $(app_entry_o ) $(APP_DIR ) /tic_tac_toe.c $(SYSCALLS_SRC_DIR ) /basic.h $(SYSCALLS_SRC_DIR ) /io.h $(SYSCALLS_SRC_DIR ) /time.h $(SYSCALLS_SRC_DIR ) /color.h $(UTIL_SRC_DIR ) /string.h $(BL_SRC_DIR ) /constants.asm $(BL_SRC_DIR ) /io.asm $(SYSCALLS_SRC_DIR ) /io_interface_bios .asm $(SYSCALLS_SRC_DIR ) /time_syscall.asm
78102 gcc -m16 -fno-pie -c -Isrc -o $(BUILD_DIR ) /ttt.o $(APP_DIR ) /tic_tac_toe.c
79103 ld --oformat binary -m elf_i386 -Ttext 0xC000 --strip-all -o $@ $(app_entry_o ) $(BUILD_DIR ) /ttt.o
80104 truncate --size=%512 $@
@@ -95,11 +119,23 @@ debug_stage2_asm: $(bt_stage2_asm_o)
95119 objdump -d -Maddr16,data16 $<
96120 xxd $<
97121
122+ debug_kernel : $(kernel_core )
123+ objdump -b binary -mi386 -Maddr16,data16 -D $<
124+ xxd $<
125+
126+ debug_kernel_c : $(kernel_core_c_o )
127+ objdump -d -Maddr16,data16 $<
128+ xxd $<
129+
130+ debug_kernel_asm : $(kernel_core_asm_o )
131+ objdump -d -Maddr16,data16 $<
132+ xxd $<
133+
98134qemu : $(image_vmdk ) images
99135 cpulimit -f -l 10 -- qemu-system-x86_64 -smp 1 -m 128M -hda $< -no-shutdown -no-reboot
100136
101137qemu_debug : $(image_vmdk ) images
102138 qemu-system-x86_64 -smp 1 -m 128M -hda $< -no-shutdown -no-reboot -d cpu,exec,in_asm
103139
104140clean :
105- rm -f $(image_vmdk ) $(bt_stage1 ) $(bt_stage2 ) $(bt_stage2_c_o ) $(bt_stage2_asm_o )
141+ rm -f $(image_vmdk ) $(bt_stage1 ) $(bt_stage2 ) $(bt_stage2_c_o ) $(bt_stage2_asm_o ) $( kernel_core ) $( kernel_core_c_o ) $( kernel_core_asm_o ) $( app_calc ) $( app_ttt )
0 commit comments