3 include ../Makefile.vars
8 # On a system where i386-elf is native (e.g. on an x86 GNU/Linux
9 # machine) you want to set BINUTIL_PREFIX to expand to null, as shown
10 # in the line that's commented out.
11 BINUTIL_PREFIX = i386-elf-
13 CC = $(BINUTIL_PREFIX)gcc
14 LD = $(BINUTIL_PREFIX)ld
15 OBJCOPY = $(BINUTIL_PREFIX)objcopy
20 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
21 INCLUDES = -nostdinc -I../.. -I- -I../../lib -I../../lib/kernel
22 CFLAGS = -g -O3 -MMD -msoft-float $(INCLUDES) $(WARNINGS) $(DEFINES)
23 ASFLAGS = -Wa,--gstabs -MMD $(INCLUDES) $(DEFINES)
26 threads_SRC = threads/init.c # Main program.
27 threads_SRC += threads/thread.c # Thread management core.
28 threads_SRC += threads/switch.S # Thread switch routine.
29 threads_SRC += threads/interrupt.c # Interrupt core.
30 threads_SRC += threads/intr-stubs.S # Interrupt stubs.
31 threads_SRC += threads/synch.c # Synchronization.
32 threads_SRC += threads/paging.c # Page tables.
33 threads_SRC += threads/palloc.c # Page allocator.
34 threads_SRC += threads/malloc.c # Subpage allocator.
35 threads_SRC += threads/start.S # Startup code.
36 threads_SRC += threads/test.c # Test code.
39 devices_SRC = devices/timer.c # Timer device.
40 devices_SRC += devices/kbd.c # Keyboard device.
41 devices_SRC += devices/vga.c # Video device.
42 devices_SRC += devices/serial.c # Serial port device.
43 devices_SRC += devices/disk.c # IDE disk device.
44 devices_SRC += devices/intq.c # Interrupt queue.
46 # Library code shared between kernel and user programs.
47 lib_SRC = lib/debug.c # Debug helpers.
48 lib_SRC += lib/random.c # Pseudo-random numbers.
49 lib_SRC += lib/stdio.c # I/O library.
50 lib_SRC += lib/stdlib.c # Utility functions.
51 lib_SRC += lib/string.c # String functions.
53 # Kernel-specific library code.
54 lib_kernel_SRC += lib/kernel/list.c # Doubly-linked lists.
55 lib_kernel_SRC += lib/kernel/bitmap.c # Bitmaps.
56 lib_kernel_SRC += lib/kernel/hash.c # Hash tables.
57 lib_kernel_SRC += lib/kernel/console.c # printf(), putchar().
60 filesys_SRC = filesys/filesys.c # Filesystem core.
61 filesys_SRC += filesys/file.c # Files.
62 filesys_SRC += filesys/directory.c # Directories.
63 filesys_SRC += filesys/inode.c # File headers.
64 filesys_SRC += filesys/fsutil.c # Utilities.
67 userprog_SRC = userprog/addrspace.c # Address spaces.
68 userprog_SRC += userprog/exception.c # User exception handler.
69 userprog_SRC += userprog/syscall.c # System call handler.
70 userprog_SRC += userprog/gdt.c # GDT initialization.
71 userprog_SRC += userprog/tss.c # TSS management.
73 SOURCES = $(foreach dir,$(SUBDIRS),$($(subst /,_,$(dir))_SRC))
74 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
75 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
79 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
82 threads/kernel.lds.s: CPPFLAGS += -P -C
83 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
85 kernel.o: threads/kernel.lds.s $(OBJECTS)
86 $(LD) -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
89 $(OBJCOPY) -O binary -R .note -R .comment -S $< $@.tmp
90 ../../pad 4096 < $@.tmp > $@
93 threads/loader.o: threads/loader.S kernel.bin
94 $(CC) -c $< -o $@ $(ASFLAGS) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
96 loader.bin: threads/loader.o
97 $(LD) -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
99 os.dsk: loader.bin kernel.bin
103 rm -f $(OBJECTS) $(DEPENDS)
104 rm -f threads/intr-stubs.S threads/loader.o
105 rm -f kernel.o kernel.lds.s
106 rm -f kernel.bin loader.bin