summaryrefslogtreecommitdiff
path: root/src/Makefile
blob: 52a628bb7fe59f845e3082c4fc9c4089a92f93ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
CC := gcc
CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror
LD := ld

all: image.bin

image.bin: boot.bin kernel.bin magic.bin
	cat boot.bin kernel.bin > image.tmp
	# truncate to correct number of sectors, we have
	# 512 (boot, stage 1) + N * 512 (N currenty is 3, stage 2) = 2048 for boot.bin
	# + M * 512 (M is currently 7) = 3144 for kernel.bin
	# + 1 * 512 = 512 for magic.bin
	# (M + N + 1 is the number of sectors to be read in stage 2, as stage 1
	# loads only the first sector, so adapt NOF_LOAD_SECTORS to 10)
	truncate -s 5632 image.tmp
	cat image.tmp magic.bin > image.bin
	
boot.bin: boot.asm gdt.asm stage1_functions.asm stage2_functions.asm switch_mode.asm
	nasm boot.asm -f bin -o boot.bin

kernel.bin: kernel.o console.o vga.o serial.o port.o port_asm.o string.o stdlib.o
	$(LD) -o kernel.bin -N -n -Ttext 0x8400 --oformat binary \
		kernel.o console.o vga.o serial.o port.o port_asm.o \
		string.o stdlib.o

magic.bin: magic.asm
	nasm magic.asm -f bin -o magic.bin
	
kernel.o: kernel.c
	$(CC) $(CFLAGS) -c -o kernel.o kernel.c

port.o: port.c port.h
	$(CC) $(CFLAGS) -c -o port.o port.c

console.o: console.c console.h vga.h serial.h
	$(CC) $(CFLAGS) -c -o console.o console.c

vga.o: vga.c vga.h
	$(CC) $(CFLAGS) -c -o vga.o vga.c

serial.o: serial.c serial.h
	$(CC) $(CFLAGS) -c -o serial.o serial.c

port_asm.o: port.asm
	nasm port.asm -f elf32 -o port_asm.o

string.o: string.c string.h
	$(CC) $(CFLAGS) -c -o string.o string.c

stdlib.o: stdlib.c stdlib.h
	$(CC) $(CFLAGS) -c -o stdlib.o stdlib.c

clean:
	-rm -f boot.bin kernel.bin image.bin magic.bin *.o kernel.map image.tmp

run-qemu: image.bin
	qemu-system-i386 -m 32 -drive "file=image.bin,if=ide,format=raw" \
		-serial file:serial.log

run-bochs:
	bochs -q -f bochs.config 'boot:floppy' 'floppya: 1_44=image.bin, status=inserted'