timer works in bochs and on physical machine. need global definition for bochs...
[akaros.git] / kern / Makefrag
1 #
2 # Makefile fragment for ROS kernel.
3 # This is NOT a complete makefile;
4 # you must run GNU make in the top-level directory
5 # where the GNUmakefile is located.
6 #
7
8 OBJDIRS += kern
9 CC=ivycc --deputy
10
11 KERN_LDFLAGS := $(LDFLAGS) -Lobj/ivylib -T kern/kernel.ld -nostdlib
12
13 # entry.S must be first, so that it's the first code in the text segment!!!
14 #
15 # We also snatch the use of a couple handy source files
16 # from the lib directory, to avoid gratuitous code duplication.
17 KERN_SRCFILES :=        kern/entry.S \
18                         kern/smp_entry.S \
19                         kern/init.c \
20                         kern/console.c \
21                         kern/monitor.c \
22                         kern/pmap.c \
23                         kern/env.c \
24                         kern/kclock.c \
25                         kern/picirq.c \
26                         kern/printf.c \
27                         kern/trap.c \
28                         kern/trapentry.S \
29                         kern/sched.c \
30                         kern/syscall.c \
31                         kern/kdebug.c \
32                         kern/apic.c \
33                         kern/testing.c \
34                         kern/atomic.c \
35                         kern/smp.c \
36                         lib/printfmt.c \
37                         lib/readline.c \
38                         lib/string.c
39
40 # Only build files if they exist.
41 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
42
43 KERN_BINFILES :=        user/hello \
44                         user/buggyhello \
45                         user/evilhello \
46                         user/testbss \
47                         user/divzero \
48                         user/breakpoint \
49                         user/softint \
50                         user/badsegment \
51                         user/faultread \
52                         user/faultreadkernel \
53                         user/faultwrite \
54                         user/faultwritekernel
55
56 KERN_OBJFILES := $(patsubst %.c, $(OBJDIR)/%.o, $(KERN_SRCFILES))
57 KERN_OBJFILES := $(patsubst %.S, $(OBJDIR)/%.o, $(KERN_OBJFILES))
58 KERN_OBJFILES := $(patsubst obj/lib/%, obj/kern/%, $(KERN_OBJFILES))
59
60 KERN_BINFILES := $(patsubst %, $(OBJDIR)/%, $(KERN_BINFILES))
61
62 # How to build kernel object files
63 $(OBJDIR)/kern/%.o: kern/%.c
64         @echo + cc $<
65         @mkdir -p $(@D)
66         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
67
68 $(OBJDIR)/kern/%.o: kern/%.S
69         @echo + as $<
70         @mkdir -p $(@D)
71         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
72
73 $(OBJDIR)/kern/%.o: lib/%.c
74         @echo + cc $<
75         @mkdir -p $(@D)
76         $(V)$(CC) -nostdinc $(KERN_CFLAGS) -c -o $@ $<
77
78 # How to build the kernel itself
79 $(OBJDIR)/kern/kernel: $(KERN_OBJFILES) $(KERN_BINFILES) kern/kernel.ld $(OBJDIR)/ivylib/libivykern.a
80         @echo + ld $@
81         $(V)$(LD) -o $@ $(KERN_LDFLAGS) $(KERN_OBJFILES) -livykern $(GCC_LIB) -b binary $(KERN_BINFILES)
82         $(V)$(OBJDUMP) -S $@ > $@.asm
83         $(V)$(NM) -n $@ > $@.sym
84
85 # How to build the Bochs disk image
86 $(OBJDIR)/kern/bochs.img: $(OBJDIR)/kern/kernel $(OBJDIR)/boot/boot
87         @echo + mk $@
88         $(V)dd if=/dev/zero of=$(OBJDIR)/kern/bochs.img~ count=10000 2>/dev/null
89         $(V)dd if=$(OBJDIR)/boot/boot of=$(OBJDIR)/kern/bochs.img~ conv=notrunc 2>/dev/null
90         $(V)dd if=$(OBJDIR)/kern/kernel of=$(OBJDIR)/kern/bochs.img~ seek=1 conv=notrunc 2>/dev/null
91         $(V)mv $(OBJDIR)/kern/bochs.img~ $(OBJDIR)/kern/bochs.img
92
93 all: $(OBJDIR)/kern/bochs.img
94
95 kvm: $(OBJDIR)/kern/kernel
96         $(V)echo "+ (KVM) Copying to mnt/hdd"
97         $(V)cp $(OBJDIR)/kern/kernel mnt/hdd/texas
98         $(V)sync
99
100 usb: $(OBJDIR)/kern/kernel
101         $(V)echo "+ (USB) Copying to /dev/sdb4"
102         $(V)cp $(OBJDIR)/kern/kernel /media/disk/texas
103         $(V)sync
104         $(V)umount /media/disk
105
106 grub: $(OBJDIR)/jos-grub
107
108 $(OBJDIR)/jos-grub: $(OBJDIR)/kern/kernel
109         @echo + oc $@
110         $(V)$(OBJCOPY) --adjust-vma=0x10000000 $^ $@