]> pd.if.org Git - zos/blobdiff - Makefile
klib and makefile
[zos] / Makefile
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..e4cab80
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,129 @@
+AFLAGS=-felf64
+AS=yasm $(AFLAGS)
+CFLAGS= -ffreestanding -mno-red-zone  -mcmodel=large
+CFLAGS= -Wall -Iinclude -Ipci -Iklib -I. -std=c99 -nostdlibinc -Wno-parentheses -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fomit-frame-pointer
+LDFLAGS= -L. -Tlink64.ld
+CFLAGS32= -ffreestanding -mno-red-zone -mno-mmx -mno-sse -mno-sse2
+OS=$(shell uname -s)
+
+DIS= objdump -M intel -d
+
+LIBSRC=$(wildcard klib/*.c)
+#LIBOBJS:=$(addsuffix .o,$(basename, $(wildcard klib/*.c)))
+LIBOBJS:=$(addsuffix .o, $(basename $(wildcard klib/*.c)))
+#LIBOBJS:=$(addprefix klib/, $(LIBOBJS))
+
+#PATH:=/home/nw/src/kernel/cc/sysroot/bin:$(PATH)
+#export PATH
+
+CC=clang -target amd64-elf-zos
+LD=ld
+OBJCOPY=objcopy
+
+ifeq ($(OS),Darwin)
+#      CC=/opt/local/libexec/llvm-3.9/bin/clang
+       LD=x86_64-elf-ld
+       AR=x86_64-elf-ar
+       OBJCOPY=x86_64-elf-objcopy
+endif
+
+zos: zos64
+       $(OBJCOPY) $< -O elf32-i386 $@
+
+usermode.o: usermode.c
+       $(CC) $(CFLAGS) -fpic -c -o $@ $<
+
+include/errno.h: include/errno.in tools/mkerrno
+       tools/mkerrno $< > $@
+
+libklib.a: CFLAGS+=-D_PDCLIB_restrict=restrict
+libklib.a: $(LIBOBJS)
+       $(AR) rcu $@ $(LIBOBJS)
+
+vfs/vfs.o: vfs/vfs.c vfs/vfs.h | include/errno.h
+vfs/pipes.o: vfs/pipes.c vfs/vfs.h | include/errno.h
+
+libvfs.a: vfs/pipes.o vfs/vfs.o
+       $(AR) rcu $@ $+
+
+pci/func.o: pci/func.c
+
+libpci.a: pci/pci.o pci/func.o
+       $(AR) rcu $@ $+
+
+pic.o: pic.h interrupt.h
+
+zos64: libklib.a
+zos64: link64.ld
+
+KOBJS= boot32.o bootz.o kernel.o interrupt.o idt.o \
+       pic.o ioport.o timer.o tty.o mem.o \
+       memx64.o spinlock.o process.o taskx64.o kbd.o \
+       cpu.o syscalls.o smp.o \
+       usermain.o
+KLIBS=libpci.a libklib.a
+
+zos64: $(KOBJS) $(KLIBS) link64.ld
+       $(LD) $(LDFLAGS) -z max-page-size=0x1000 -nostdlib $(KOBJS) $(KLIBS) -o $@
+
+zemu: zos
+       #qemu-system-x86_64 -d in_asm,op -m 512M -kernel $< -vnc :0
+       qemu-system-x86_64 -monitor stdio -m 256MB -kernel $< -vnc :0 -append 'mboot hb' \
+                   -drive file=rdisk.img,if=none,id=mydisk \
+                       -device ich9-ahci,id=ahci \
+                           -device ide-drive,drive=mydisk,bus=ahci.0
+                   #-device ide-hd,drive=mydisk
+cemu: zos
+       #qemu-system-x86_64 -d in_asm,op -m 512M -kernel $< -vnc :0
+       qemu-system-x86_64 -monitor stdio -m 256MB -kernel $< -display curses -append 'mboot hb' \
+                   -drive file=rdisk.img,if=none,id=mydisk \
+                       -device ich9-ahci,id=ahci \
+                           -device ide-drive,drive=mydisk,bus=ahci.0
+                   #-device ide-hd,drive=mydisk
+
+rdisk.img:
+       qemu-img create -f qcow2 $@ 1G
+
+mem.o: mem.c mem.h multiboot.h
+interrupt.o: interrupt.c interrupt.h
+process.o: process.c process.h
+
+#              -initrd TODO
+memu: zos rdisk.img
+       #qemu-system-x86_64 -d in_asm,op -m 512M -kernel $< -vnc :0
+       qemu-system-x86_64 $(SMP) -d cpu_reset -monitor stdio -m 256MB \
+               -kernel $< -append 'mboot hb' \
+                   -drive file=rdisk.img,if=none,id=mydisk \
+                       -device ich9-ahci,id=ahci \
+                           -device ide-drive,drive=mydisk,bus=ahci.0
+                   #-device ide-hd,drive=mydisk
+
+cemu2: zos
+       qemu-system-x86_64 -display curses -m 512M -kernel $< -append 'mboot hb'
+
+kernel.o: kernel.c multiboot.h
+       $(CC) $(CFLAGS) -o $@ -c $<
+
+clean:
+       rm -f *.o *.a zos64 zos klib/*.o vfs/*.o pci/*.o ahci/*.o
+
+%.o%.s:
+       $(AS) -o $@ $<
+
+%.o%.c:
+       $(CC) $(CFLAGS) -c -o $@ $<
+
+tprintk.o: printk.c
+       cc -Wall -Wno-parentheses -I. -c -o $@ $+
+
+test: t/t_printk tprintk.o
+       t/t_printk
+
+t/t_printk.o: t/t_printk.c
+       cc -Wall -I. -c -o $@ $+
+
+t/t_printk: tprintk.o t/t_printk.o
+       cc -Wall -o $@ $+
+
+%.d%.o:
+       $(DIS) $<