blob: 09ebdfd8bbcc59854b00a5799302ad6df3e888ba [file] [log] [blame]
swissChilid98781b2021-07-25 21:04:17 -07001# -*- mode:makefile -*-
2
swissChili2b5acc82021-03-13 17:06:42 -08003init(kernel, kernel.elf)
4
5preset(freestanding)
swissChilib7ef65d2021-07-17 12:51:52 -07006# This makes debugging hard :(
7# preset(optimize)
swissChili2b5acc82021-03-13 17:06:42 -08008preset(debug)
9preset(32)
10preset(warn)
11preset(nasm)
12
13archetype(c)
14archetype(asm)
15
swissChili52a03d82021-07-18 15:22:14 -070016depends(sys, $(ROOT)/src/libsys, libsys.a)
swissChili2b5acc82021-03-13 17:06:42 -080017depends(initrd, $(ROOT)/boot/initrd, initrd.img)
swissChili1a3f07f2021-04-05 20:01:55 -070018depends(ata_pio, dri/ata_pio, ata_pio.a)
swissChilie8491742021-04-08 20:38:06 -070019depends(pci, dri/pci, pci.a)
swissChili5fe85a12021-05-31 08:10:27 -070020depends(ide, dri/ide, ide.a)
swissChili4418ca52021-06-14 17:36:00 -070021depends(ext2, dri/fs/ext2, ext2.a)
swissChilie8491742021-04-08 20:38:06 -070022# AHCI not yet implemented
23# depends(ahci, dri/ahci, ahci.a)
swissChili1a3f07f2021-04-05 20:01:55 -070024
swissChili402a3832021-05-29 21:41:31 -070025TEST ?=
26test_defines = $(TEST:%=-DTEST_%)
27
swissChili4418ca52021-06-14 17:36:00 -070028FS ?= ext2
29
swissChilid98781b2021-07-25 21:04:17 -070030CFLAGS += -I$(ROOT)/include/kernel $(test_defines) -O0
swissChili2b5acc82021-03-13 17:06:42 -080031
swissChili64228692021-03-16 08:19:23 -070032LDFLAGS += -Tlink.ld -melf_i386
swissChili7be32742021-04-03 21:17:24 -070033ASMFLAGS += -felf -Fdwarf
swissChili36ed5d72021-07-23 14:56:36 -070034QEMUFLAGS = -drive file=hd0_ext2.img,format=raw
swissChili2b5acc82021-03-13 17:06:42 -080035
36OBJECTS = boot.o \
37 main.o \
38 descriptor_tables.o \
39 io.o \
40 vga.o \
41 gdt_flush.o \
42 idt.o \
43 log.o \
44 irq.o \
45 pic.o \
46 timer.o \
47 paging.o \
48 switch_table.o \
49 scan_codes.o \
50 kheap.o \
51 alloc.o \
52 vfs.o \
53 multiboot.o \
swissChili64228692021-03-16 08:19:23 -070054 vfs_initrd.o \
swissChilie20b79b2021-03-17 21:20:13 -070055 syscall.o \
swissChilicfd3c3c2021-04-03 15:04:24 -070056 task.o \
swissChili1a3f07f2021-04-05 20:01:55 -070057 task_api.o \
swissChiliaed6ff32021-05-29 17:51:04 -070058 faults.o \
swissChili52a03d82021-07-18 15:22:14 -070059 sync.o \
swissChili4418ca52021-06-14 17:36:00 -070060 lib(ext2) \
swissChilie5adca52021-06-16 21:00:31 -070061 lib(ide) \
swissChilie8491742021-04-08 20:38:06 -070062 lib(ata_pio) \
swissChili52a03d82021-07-18 15:22:14 -070063 lib(pci) \
64 lib(sys)
swissChili2b5acc82021-03-13 17:06:42 -080065
66type(custom_link)
67
swissChilicfd3c3c2021-04-03 15:04:24 -070068debug-wait: kernel.elf
swissChilib7ef65d2021-07-17 12:51:52 -070069 qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf
swissChilicfd3c3c2021-04-03 15:04:24 -070070
swissChili2b5acc82021-03-13 17:06:42 -080071debug: kernel.elf
swissChili9bd74de2021-06-15 20:30:48 -070072 qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf &
swissChili2b5acc82021-03-13 17:06:42 -080073 @echo run "target remote localhost:1234" to connect to qemu
swissChilicfd3c3c2021-04-03 15:04:24 -070074 gdb $<
swissChili2b5acc82021-03-13 17:06:42 -080075 @pkill qemu-system-i38
76
swissChili4418ca52021-06-14 17:36:00 -070077hd0_%.img:
swissChilief829f32021-06-13 20:00:54 -070078 status_log(MKFS, $@)
79 @dd bs=4M count=8 if=/dev/zero of=$@
swissChili4418ca52021-06-14 17:36:00 -070080 @$(patsubst hd0_%.img,mkfs.%,$@) $@
swissChilief829f32021-06-13 20:00:54 -070081
swissChilicaa24782021-07-19 14:29:58 -070082fs-info: hd0_$(FS).img
83 tune2fs -l $< | grep -i inode
84
swissChili36ed5d72021-07-23 14:56:36 -070085reset-fs:
86 @rm hd0_ext2.img
87 @$(MAKE) hd0_ext2.img
88 @sudo $(MAKE) mount
89 @echo 'hi' | sudo tee $(ROOT)/mnt/hello.txt
90 @sudo $(MAKE) umount
91 @$(MAKE) qemu
92
swissChili4418ca52021-06-14 17:36:00 -070093qemu: kernel.elf hd0_$(FS).img
swissChili9bd74de2021-06-15 20:30:48 -070094 qemu-system-i386 $(QEMUFLAGS) -d cpu_reset -monitor stdio -kernel kernel.elf -no-reboot
swissChili2b5acc82021-03-13 17:06:42 -080095
96qemu-iso: install
97 qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(ROOT)/bin/bluejay.iso
98
99scan_codes.c: gen_scan_codes.py scan_codes.tsv
100 python3 $< > $@
101
swissChili4418ca52021-06-14 17:36:00 -0700102mount: hd0_$(FS).img
swissChilief829f32021-06-13 20:00:54 -0700103 status_log(MOUNT, $^ $(ROOT)/mnt)
104 @mkdir -p $(ROOT)/mnt
swissChili9bd74de2021-06-15 20:30:48 -0700105 @mount $^ $(ROOT)/mnt
swissChilief829f32021-06-13 20:00:54 -0700106
107umount:
108 status_log(UMOUNT, $(ROOT)/mnt)
109 @umount $(ROOT)/mnt
110
swissChili2b5acc82021-03-13 17:06:42 -0800111install: kernel.elf lib(initrd)
112 cp kernel.elf $(ROOT)/boot/
113 rm -f $(ROOT)/bin/bluejay.iso
114 grub-mkrescue -o $(ROOT)/bin/bluejay.iso $(ROOT)
115
116finish