3 include ../Makefile.vars
8 # If the host appears to be x86, use the normal tools.
9 # Otherwise assume cross-tools are installed as i386-elf-*.
10 X86 = i.86\|pentium.*\|[pk][56]\|nexgen\|viac3\|6x86\|athlon.*
11 ifneq (0, $(shell expr `uname -m` : '$(X86)'))
18 OBJCOPY = i386-elf-objcopy
28 # Compiler and assembler options.
30 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes
31 CPPFLAGS = -nostdinc -I../.. -I- -I../../lib -I../../lib/kernel \
33 CFLAGS = -g -O3 -MMD -msoft-float
34 ASFLAGS = -Wa,--gstabs -MMD
37 threads_SRC = threads/init.c # Main program.
38 threads_SRC += threads/thread.c # Thread management core.
39 threads_SRC += threads/switch.S # Thread switch routine.
40 threads_SRC += threads/interrupt.c # Interrupt core.
41 threads_SRC += threads/intr-stubs.S # Interrupt stubs.
42 threads_SRC += threads/synch.c # Synchronization.
43 threads_SRC += threads/palloc.c # Page allocator.
44 threads_SRC += threads/malloc.c # Subpage allocator.
45 threads_SRC += threads/start.S # Startup code.
46 threads_SRC += threads/test.c # Test code.
49 devices_SRC = devices/timer.c # Timer device.
50 devices_SRC += devices/kbd.c # Keyboard device.
51 devices_SRC += devices/vga.c # Video device.
52 devices_SRC += devices/serial.c # Serial port device.
53 devices_SRC += devices/disk.c # IDE disk device.
54 devices_SRC += devices/intq.c # Interrupt queue.
56 # Library code shared between kernel and user programs.
57 lib_SRC = lib/debug.c # Debug helpers.
58 lib_SRC += lib/random.c # Pseudo-random numbers.
59 lib_SRC += lib/stdio.c # I/O library.
60 lib_SRC += lib/stdlib.c # Utility functions.
61 lib_SRC += lib/string.c # String functions.
63 # Kernel-specific library code.
64 lib_kernel_SRC += lib/kernel/list.c # Doubly-linked lists.
65 lib_kernel_SRC += lib/kernel/bitmap.c # Bitmaps.
66 lib_kernel_SRC += lib/kernel/hash.c # Hash tables.
67 lib_kernel_SRC += lib/kernel/console.c # printf(), putchar().
70 filesys_SRC = filesys/filesys.c # Filesystem core.
71 filesys_SRC += filesys/file.c # Files.
72 filesys_SRC += filesys/directory.c # Directories.
73 filesys_SRC += filesys/inode.c # File headers.
74 filesys_SRC += filesys/fsutil.c # Utilities.
77 userprog_SRC = userprog/addrspace.c # Address spaces.
78 userprog_SRC += userprog/pagedir.c # Page directories.
79 userprog_SRC += userprog/exception.c # User exception handler.
80 userprog_SRC += userprog/syscall.c # System call handler.
81 userprog_SRC += userprog/gdt.c # GDT initialization.
82 userprog_SRC += userprog/tss.c # TSS management.
84 SOURCES = $(foreach dir,$(SUBDIRS),$($(subst /,_,$(dir))_SRC))
85 OBJECTS = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(SOURCES)))
86 DEPENDS = $(patsubst %.o,%.d,$(OBJECTS))
90 threads/intr-stubs.S: threads/intr-stubs.pl threads/loader.h
93 threads/kernel.lds.s: CPPFLAGS += -P -C
94 threads/kernel.lds.s: threads/kernel.lds.S threads/loader.h
96 kernel.o: threads/kernel.lds.s $(OBJECTS)
97 $(LD) -T $< -o $@ $(OBJECTS) `$(CC) -print-libgcc-file-name`
100 $(OBJCOPY) -O binary -R .note -R .comment -S $< $@.tmp
101 $(DD) if=$@.tmp of=$@ bs=4096 conv=sync
104 threads/loader.o: threads/loader.S kernel.bin
105 $(CC) -c $< -o $@ $(ASFLAGS) $(CPPFLAGS) $(DEFINES) -DKERNEL_LOAD_PAGES=`perl -e 'print +(-s "kernel.bin") / 4096;'`
107 loader.bin: threads/loader.o
108 $(LD) -N -e start -Ttext 0x7c00 --oformat binary -o $@ $<
110 os.dsk: loader.bin kernel.bin
114 $(RM) -f $(OBJECTS) $(DEPENDS)
115 $(RM) -f threads/intr-stubs.S threads/loader.o
116 $(RM) -f kernel.o kernel.lds.s
117 $(RM) -f kernel.bin loader.bin
119 Makefile: ../../Makefile.build
123 $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(WARNINGS) $(DEFINES)
126 $(CC) -c $< -o $@ $(ASFLAGS) $(CPPFLAGS) $(DEFINES)