30 # Cross-compiling (e.g., on Mac OS X)
31 #TOOLPREFIX = i386-jos-elf-
33 # Using native tools (e.g., on X86 Linux)
36 # Try to infer the correct TOOLPREFIX if not set
38 TOOLPREFIX
:= $(shell if i386-jos-elf-objdump
-i
2>&1 | grep
'^elf32-i386$$' >/dev
/null
2>&1; \
39 then echo
'i386-jos-elf-'; \
40 elif objdump
-i
2>&1 | grep
'elf32-i386' >/dev
/null
2>&1; \
42 else echo
"***" 1>&2; \
43 echo
"*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
44 echo
"*** Is the directory with i386-jos-elf-gcc in your PATH?" 1>&2; \
45 echo
"*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
46 echo
"*** prefix other than 'i386-jos-elf-', set your TOOLPREFIX" 1>&2; \
47 echo
"*** environment variable to that prefix and run 'make' again." 1>&2; \
48 echo
"*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
49 echo
"***" 1>&2; exit
1; fi
)
52 # If the makefile can't find QEMU, specify its path here
55 # Try to infer the correct QEMU
57 QEMU
= $(shell if which qemu
> /dev
/null
; \
58 then echo qemu
; exit
; \
60 qemu
=/Applications
/Q.app
/Contents
/MacOS
/i386-softmmu.app
/Contents
/MacOS
/i386-softmmu
; \
61 if
test -x
$$qemu; then echo
$$qemu; exit
; fi
; fi
; \
63 echo
"*** Error: Couldn't find a working QEMU executable." 1>&2; \
64 echo
"*** Is the directory containing the qemu binary in your PATH" 1>&2; \
65 echo
"*** or have you tried setting the QEMU variable in Makefile?" 1>&2; \
66 echo
"***" 1>&2; exit
1)
72 OBJCOPY
= $(TOOLPREFIX
)objcopy
73 OBJDUMP
= $(TOOLPREFIX
)objdump
74 CFLAGS
= -fno-pic
-static
-fno-builtin
-fno-strict-aliasing
-O2
-Wall
-MD
-ggdb
-m32
-Werror
75 CFLAGS
+= $(shell $(CC
) -fno-stack-protector
-E
-x c
/dev
/null
>/dev
/null
2>&1 && echo
-fno-stack-protector
)
76 ASFLAGS
= -m32
-gdwarf-2
77 # FreeBSD ld wants ``elf_i386_fbsd''
78 LDFLAGS
+= -m
$(shell $(LD
) -V | grep elf_i386
2>/dev
/null
)
80 xv6.img
: bootblock kernel fs.img
81 dd if
=/dev
/zero of
=xv6.img count
=10000
82 dd if
=bootblock of
=xv6.img conv
=notrunc
83 dd if
=kernel of
=xv6.img seek
=1 conv
=notrunc
85 xv6memfs.img
: bootblock kernelmemfs
86 dd if
=/dev
/zero of
=xv6memfs.img count
=10000
87 dd if
=bootblock of
=xv6memfs.img conv
=notrunc
88 dd if
=kernelmemfs of
=xv6memfs.img seek
=1 conv
=notrunc
90 bootblock
: bootasm.S bootmain.c
91 $(CC
) $(CFLAGS
) -fno-pic
-O
-nostdinc
-I.
-c bootmain.c
92 $(CC
) $(CFLAGS
) -fno-pic
-nostdinc
-I.
-c bootasm.S
93 $(LD
) $(LDFLAGS
) -N
-e start
-Ttext
0x7C00 -o bootblock.o bootasm.o bootmain.o
94 $(OBJDUMP
) -S bootblock.o
> bootblock.asm
95 $(OBJCOPY
) -S
-O binary
-j .text bootblock.o bootblock
98 bootother
: bootother.S
99 $(CC
) $(CFLAGS
) -nostdinc
-I.
-c bootother.S
100 $(LD
) $(LDFLAGS
) -N
-e start
-Ttext
0x7000 -o bootother.out bootother.o
101 $(OBJCOPY
) -S
-O binary bootother.out bootother
102 $(OBJDUMP
) -S bootother.o
> bootother.asm
105 $(CC
) $(CFLAGS
) -nostdinc
-I.
-c initcode.S
106 $(LD
) $(LDFLAGS
) -N
-e start
-Ttext
0 -o initcode.out initcode.o
107 $(OBJCOPY
) -S
-O binary initcode.out initcode
108 $(OBJDUMP
) -S initcode.o
> initcode.asm
110 kernel
: $(OBJS
) multiboot.o data.o bootother initcode
111 $(LD
) $(LDFLAGS
) -Ttext
0x100000 -e main
-o kernel multiboot.o data.o
$(OBJS
) -b binary initcode bootother
112 $(OBJDUMP
) -S kernel
> kernel.asm
113 $(OBJDUMP
) -t kernel | sed
'1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernel.sym
115 # kernelmemfs is a copy of kernel that maintains the
116 # disk image in memory instead of writing to a disk.
117 # This is not so useful for testing persistent storage or
118 # exploring disk buffering implementations, but it is
119 # great for testing the kernel on real hardware without
120 # needing a scratch disk.
121 MEMFSOBJS
= $(filter-out ide.o
,$(OBJS
)) memide.o
122 kernelmemfs
: $(MEMFSOBJS
) multiboot.o data.o bootother initcode fs.img
123 $(LD
) $(LDFLAGS
) -Ttext
0x100000 -e main
-o kernelmemfs multiboot.o data.o
$(MEMFSOBJS
) -b binary initcode bootother fs.img
124 $(OBJDUMP
) -S kernelmemfs
> kernelmemfs.asm
125 $(OBJDUMP
) -t kernelmemfs | sed
'1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > kernelmemfs.sym
127 tags: $(OBJS
) bootother.S _init
130 vectors.S
: vectors.pl
131 perl vectors.pl
> vectors.S
133 ULIB
= ulib.o usys.o printf.o umalloc.o
136 $(LD
) $(LDFLAGS
) -N
-e main
-Ttext
0 -o
$@
$^
137 $(OBJDUMP
) -S
$@
> $*.asm
138 $(OBJDUMP
) -t
$@ | sed
'1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym
140 _forktest
: forktest.o
$(ULIB
)
141 # forktest has less library code linked in - needs to be small
142 # in order to be able to max out the proc table.
143 $(LD
) $(LDFLAGS
) -N
-e main
-Ttext
0 -o _forktest forktest.o ulib.o usys.o
144 $(OBJDUMP
) -S _forktest
> forktest.asm
147 gcc
-m32
-Werror
-Wall
-o mkfs mkfs.c
166 fs.img
: mkfs README
$(UPROGS
)
167 .
/mkfs fs.img README
$(UPROGS
)
172 rm -f
*.
tex *.
dvi *.idx
*.aux
*.log
*.ind
*.ilg \
173 *.o
*.d
*.asm
*.sym vectors.S parport.out \
174 bootblock kernel xv6.img fs.img mkfs \
178 FILES
= $(shell grep
-v
'^\#' runoff.list
)
179 PRINT
= runoff.list runoff.spec
$(FILES
)
189 bochs
: fs.img xv6.img
190 if
[ ! -e .bochsrc
]; then ln
-s dot-bochsrc .bochsrc
; fi
193 # try to generate a unique GDB port
194 GDBPORT
= $(shell expr
`id -u` % 5000 + 25000)
195 # QEMU's gdb stub command line changed in 0.11
196 QEMUGDB
= $(shell if
$(QEMU
) -help | grep
-q
'^-gdb'; \
197 then echo
"-gdb tcp::$(GDBPORT)"; \
198 else echo
"-s -p $(GDBPORT)"; fi
)
202 QEMUOPTS
= -hdb fs.img xv6.img
-smp
$(CPUS
)
205 $(QEMU
) -serial mon
:stdio
$(QEMUOPTS
)
207 qemu-memfs
: xv6memfs.img
208 $(QEMU
) xv6memfs.img
-smp
$(CPUS
)
210 qemu-nox
: fs.img xv6.img
211 $(QEMU
) -nographic
$(QEMUOPTS
)
213 .gdbinit
: .gdbinit.tmpl
214 sed
"s/localhost:1234/localhost:$(GDBPORT)/" < $^
> $@
216 qemu-gdb
: fs.img xv6.img .gdbinit
217 @echo
"*** Now run 'gdb'." 1>&2
218 $(QEMU
) -serial mon
:stdio
$(QEMUOPTS
) -S
$(QEMUGDB
)
220 qemu-nox-gdb
: fs.img xv6.img .gdbinit
221 @echo
"*** Now run 'gdb'." 1>&2
222 $(QEMU
) -nographic
$(QEMUOPTS
) -S
$(QEMUGDB
)