swissChili | d98781b | 2021-07-25 21:04:17 -0700 | [diff] [blame^] | 1 | # -*- mode:makefile -*- |
| 2 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 3 | init(kernel, kernel.elf) |
| 4 | |
| 5 | preset(freestanding) |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 6 | # This makes debugging hard :( |
| 7 | # preset(optimize) |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 8 | preset(debug) |
| 9 | preset(32) |
| 10 | preset(warn) |
| 11 | preset(nasm) |
| 12 | |
| 13 | archetype(c) |
| 14 | archetype(asm) |
| 15 | |
swissChili | 52a03d8 | 2021-07-18 15:22:14 -0700 | [diff] [blame] | 16 | depends(sys, $(ROOT)/src/libsys, libsys.a) |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 17 | depends(initrd, $(ROOT)/boot/initrd, initrd.img) |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 18 | depends(ata_pio, dri/ata_pio, ata_pio.a) |
swissChili | e849174 | 2021-04-08 20:38:06 -0700 | [diff] [blame] | 19 | depends(pci, dri/pci, pci.a) |
swissChili | 5fe85a1 | 2021-05-31 08:10:27 -0700 | [diff] [blame] | 20 | depends(ide, dri/ide, ide.a) |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 21 | depends(ext2, dri/fs/ext2, ext2.a) |
swissChili | e849174 | 2021-04-08 20:38:06 -0700 | [diff] [blame] | 22 | # AHCI not yet implemented |
| 23 | # depends(ahci, dri/ahci, ahci.a) |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 24 | |
swissChili | 402a383 | 2021-05-29 21:41:31 -0700 | [diff] [blame] | 25 | TEST ?= |
| 26 | test_defines = $(TEST:%=-DTEST_%) |
| 27 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 28 | FS ?= ext2 |
| 29 | |
swissChili | d98781b | 2021-07-25 21:04:17 -0700 | [diff] [blame^] | 30 | CFLAGS += -I$(ROOT)/include/kernel $(test_defines) -O0 |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 31 | |
swissChili | 6422869 | 2021-03-16 08:19:23 -0700 | [diff] [blame] | 32 | LDFLAGS += -Tlink.ld -melf_i386 |
swissChili | 7be3274 | 2021-04-03 21:17:24 -0700 | [diff] [blame] | 33 | ASMFLAGS += -felf -Fdwarf |
swissChili | 36ed5d7 | 2021-07-23 14:56:36 -0700 | [diff] [blame] | 34 | QEMUFLAGS = -drive file=hd0_ext2.img,format=raw |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 35 | |
| 36 | OBJECTS = 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 \ |
swissChili | 6422869 | 2021-03-16 08:19:23 -0700 | [diff] [blame] | 54 | vfs_initrd.o \ |
swissChili | e20b79b | 2021-03-17 21:20:13 -0700 | [diff] [blame] | 55 | syscall.o \ |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 56 | task.o \ |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 57 | task_api.o \ |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 58 | faults.o \ |
swissChili | 52a03d8 | 2021-07-18 15:22:14 -0700 | [diff] [blame] | 59 | sync.o \ |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 60 | lib(ext2) \ |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 61 | lib(ide) \ |
swissChili | e849174 | 2021-04-08 20:38:06 -0700 | [diff] [blame] | 62 | lib(ata_pio) \ |
swissChili | 52a03d8 | 2021-07-18 15:22:14 -0700 | [diff] [blame] | 63 | lib(pci) \ |
| 64 | lib(sys) |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 65 | |
| 66 | type(custom_link) |
| 67 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 68 | debug-wait: kernel.elf |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 69 | qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 70 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 71 | debug: kernel.elf |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 72 | qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf & |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 73 | @echo run "target remote localhost:1234" to connect to qemu |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 74 | gdb $< |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 75 | @pkill qemu-system-i38 |
| 76 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 77 | hd0_%.img: |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 78 | status_log(MKFS, $@) |
| 79 | @dd bs=4M count=8 if=/dev/zero of=$@ |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 80 | @$(patsubst hd0_%.img,mkfs.%,$@) $@ |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 81 | |
swissChili | caa2478 | 2021-07-19 14:29:58 -0700 | [diff] [blame] | 82 | fs-info: hd0_$(FS).img |
| 83 | tune2fs -l $< | grep -i inode |
| 84 | |
swissChili | 36ed5d7 | 2021-07-23 14:56:36 -0700 | [diff] [blame] | 85 | reset-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 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 93 | qemu: kernel.elf hd0_$(FS).img |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 94 | qemu-system-i386 $(QEMUFLAGS) -d cpu_reset -monitor stdio -kernel kernel.elf -no-reboot |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 95 | |
| 96 | qemu-iso: install |
| 97 | qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(ROOT)/bin/bluejay.iso |
| 98 | |
| 99 | scan_codes.c: gen_scan_codes.py scan_codes.tsv |
| 100 | python3 $< > $@ |
| 101 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 102 | mount: hd0_$(FS).img |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 103 | status_log(MOUNT, $^ $(ROOT)/mnt) |
| 104 | @mkdir -p $(ROOT)/mnt |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 105 | @mount $^ $(ROOT)/mnt |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 106 | |
| 107 | umount: |
| 108 | status_log(UMOUNT, $(ROOT)/mnt) |
| 109 | @umount $(ROOT)/mnt |
| 110 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 111 | install: 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 | |
| 116 | finish |