System Calls cleanup, multiple Processes and context switch
[cortex-from-scratch] / Makefile
1 # Copyright 2019 - Robin Krens
2 #
3 # TODO: Somehow integrate this assembly start.asm (start.o)
4 #
5
6 # Cross compilers links
7 CC=arm-none-eabi-gcc
8 LD=arm-none-eabi-ld
9 AS=arm-none-eabi-as
10 MKIMG=arm-none-eabi-objcopy
11
12 # Compiler flags
13 LDFLAGS+= -mthumb -mcpu=cortex-m3 
14 ASFLAGS+= -mcpu=cortex-m3 -mthumb
15 CFLAGS+= -mcpu=cortex-m3 -mthumb -ffreestanding 
16 #CFLAGS+= -mcpu=cortex-m3 -mthumb -g -ffreestanding 
17
18 # Include directory
19 INCLUDE+= -Iinclude 
20
21 BIN = bin
22
23 ODIR = obj
24 _OBJ = ivt.o systick.o sysinfo.o term.o main.o clock.o rtc.o heap.o syscall.o 
25 OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
26
27 DDIR = obj/drivers
28 _DRIVERS = uart.o tm1637.o led.o tsensor.o at24c.o mk450_joystick.o st7735s.o
29 DRIVERS = $(patsubst %, $(DDIR)/%,$(_DRIVERS))
30
31 LDIR = obj/lib
32 _LIBS = string.o stdio.o regfunc.o pool.o tinyprintf.o syscall.o 
33 LIBS = $(patsubst %, $(LDIR)/%,$(_LIBS))
34
35 $(DDIR)/%.o: drivers/%.c
36         @mkdir -p $(@D) 
37         $(CC) -c $< $(CFLAGS) $(INCLUDE) -o $@
38
39 $(ODIR)/%.o: %.c 
40         @mkdir -p $(@D)
41         $(CC) -c $< $(CFLAGS) -I./include -o $@
42
43 $(LDIR)/%.o: lib/%.c 
44         @mkdir -p $(@D)
45         $(CC) -c $< $(CFLAGS) -I./include -o $@
46
47 # Start up machine assembly
48 as: 
49         $(AS) $(ASFLAGS) -o start.o start.asm
50
51 # Compile and link all
52 kernel: $(OBJ) $(DRIVERS) $(LIBS) 
53         $(AS) $(ASFLAGS) -o start.o start.asm
54         $(LD) -nostartfiles -Map $(BIN)/$@.MAP -T link.ld -o $(BIN)/$@.ELF start.o $^ --print-memory-usage
55         @echo "Creating binary..."
56         @mkdir -p $(BIN)
57         $(MKIMG) -Obinary $(BIN)/$@.ELF  $(BIN)/$@.bin
58
59 # Run in Qemu; note this is a patched version for stm32-f103c8
60 run:
61         /usr/local/bin/qemu-system-arm -monitor stdio -serial stdio  -M stm32-f103c8 -kernel $(BIN)/kernel.bin
62
63 # Examine all sections
64 examine-all:
65         arm-none-eabi-objdump -D $(BIN)/kernel.ELF | less
66
67 # Examine just headers
68 examine-header:
69         arm-none-eabi-objdump -x $(BIN)/kernel.ELF | less
70
71 # Flash kernel to board
72 flash:
73         stm32flash -w $(BIN)/kernel.bin -v /dev/ttyUSB0
74
75 .PHONY: clean
76
77 clean:
78         rm -rf $(ODIR)/* start.o $(BIN)/kernel.*
79
80 # Altijd handig deze template
81 #%.o: %.c
82 #       $(CC) -c $(CFLAGS) $< -o $@
83 #       $(CC) -MM $(CFLAGS) $< > $*.d
84 #
85 #%.o: %.s
86 #       $(CC) -c $(CFLAGS) $< -o $@
87
88
89
90