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 \ |
swissChili | 1e8b756 | 2021-12-22 21:22:57 -0800 | [diff] [blame^] | 42 | tss_flush.o \ |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 43 | idt.o \ |
| 44 | log.o \ |
| 45 | irq.o \ |
| 46 | pic.o \ |
| 47 | timer.o \ |
| 48 | paging.o \ |
| 49 | switch_table.o \ |
| 50 | scan_codes.o \ |
| 51 | kheap.o \ |
| 52 | alloc.o \ |
| 53 | vfs.o \ |
| 54 | multiboot.o \ |
swissChili | 6422869 | 2021-03-16 08:19:23 -0700 | [diff] [blame] | 55 | vfs_initrd.o \ |
swissChili | e20b79b | 2021-03-17 21:20:13 -0700 | [diff] [blame] | 56 | syscall.o \ |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 57 | task.o \ |
swissChili | 1a3f07f | 2021-04-05 20:01:55 -0700 | [diff] [blame] | 58 | task_api.o \ |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 59 | faults.o \ |
swissChili | 52a03d8 | 2021-07-18 15:22:14 -0700 | [diff] [blame] | 60 | sync.o \ |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 61 | lib(ext2) \ |
swissChili | e5adca5 | 2021-06-16 21:00:31 -0700 | [diff] [blame] | 62 | lib(ide) \ |
swissChili | e849174 | 2021-04-08 20:38:06 -0700 | [diff] [blame] | 63 | lib(ata_pio) \ |
swissChili | 52a03d8 | 2021-07-18 15:22:14 -0700 | [diff] [blame] | 64 | lib(pci) \ |
| 65 | lib(sys) |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 66 | |
| 67 | type(custom_link) |
| 68 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 69 | debug-wait: kernel.elf |
swissChili | b7ef65d | 2021-07-17 12:51:52 -0700 | [diff] [blame] | 70 | qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 71 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 72 | debug: kernel.elf |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 73 | qemu-system-i386 -s -S $(QEMUFLAGS) -kernel kernel.elf & |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 74 | @echo run "target remote localhost:1234" to connect to qemu |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 75 | gdb $< |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 76 | @pkill qemu-system-i38 |
| 77 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 78 | hd0_%.img: |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 79 | status_log(MKFS, $@) |
| 80 | @dd bs=4M count=8 if=/dev/zero of=$@ |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 81 | @$(patsubst hd0_%.img,mkfs.%,$@) $@ |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 82 | |
swissChili | caa2478 | 2021-07-19 14:29:58 -0700 | [diff] [blame] | 83 | fs-info: hd0_$(FS).img |
| 84 | tune2fs -l $< | grep -i inode |
| 85 | |
swissChili | 36ed5d7 | 2021-07-23 14:56:36 -0700 | [diff] [blame] | 86 | reset-fs: |
| 87 | @rm hd0_ext2.img |
| 88 | @$(MAKE) hd0_ext2.img |
| 89 | @sudo $(MAKE) mount |
| 90 | @echo 'hi' | sudo tee $(ROOT)/mnt/hello.txt |
| 91 | @sudo $(MAKE) umount |
| 92 | @$(MAKE) qemu |
| 93 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 94 | qemu: kernel.elf hd0_$(FS).img |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 95 | 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] | 96 | |
| 97 | qemu-iso: install |
| 98 | qemu-system-i386 $(QEMUFLAGS) -monitor stdio $(ROOT)/bin/bluejay.iso |
| 99 | |
| 100 | scan_codes.c: gen_scan_codes.py scan_codes.tsv |
| 101 | python3 $< > $@ |
| 102 | |
swissChili | 4418ca5 | 2021-06-14 17:36:00 -0700 | [diff] [blame] | 103 | mount: hd0_$(FS).img |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 104 | status_log(MOUNT, $^ $(ROOT)/mnt) |
| 105 | @mkdir -p $(ROOT)/mnt |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 106 | @mount $^ $(ROOT)/mnt |
swissChili | ef829f3 | 2021-06-13 20:00:54 -0700 | [diff] [blame] | 107 | |
| 108 | umount: |
| 109 | status_log(UMOUNT, $(ROOT)/mnt) |
| 110 | @umount $(ROOT)/mnt |
| 111 | |
swissChili | 2b5acc8 | 2021-03-13 17:06:42 -0800 | [diff] [blame] | 112 | install: kernel.elf lib(initrd) |
| 113 | cp kernel.elf $(ROOT)/boot/ |
| 114 | rm -f $(ROOT)/bin/bluejay.iso |
| 115 | grub-mkrescue -o $(ROOT)/bin/bluejay.iso $(ROOT) |
| 116 | |
| 117 | finish |