close

Compiling Xv6 on Mac OS X

 

First, to download the source code of xv6(x86 version 6, which is a re-implementation of Unix version 6) by following command:

$ git clone git://pdos.csail.mit.edu/xv6/xv6.git


Now, to prepare the toolchain and build it, then compling xv6.

 

$ wget -c http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2

$ wget -c http://ftpmirror.gnu.org/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2

$ wget -c http://ftpmirror.gnu.org/gdb/gdb-6.8a.tar.gz

$ tar jxvf binutils-2.21.1.tar.bz2 && cd binutils-2.21.1

$ ./configure --target=i386-jos-elf --disable-nls && make && sudo make install

cd../ && tar jxvf gcc-core-4.5.1.tar.bz2 && cd gcc-4.5.1 && mkdir build && cd build && ../configure --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --target=i386-jos-elf --disable-nls --without-headers --with-newlib --disable-threads --disable-shared --disable-libmudflap --disable-libssp && time make

 

then you should(or maybe) get the following error message:

 

Undefined symbols for architecture x86_64:

  "_iconv", referenced from:

      _convert_using_iconv in libcpp.a(charset.o)

     (maybe you meant: __cpp_destroy_iconv, _cpp_init_iconv )

  "_iconv_close", referenced from:

      __cpp_destroy_iconv in libcpp.a(charset.o)

      __cpp_convert_input in libcpp.a(charset.o)

  "_iconv_open", referenced from:

      _init_iconv_desc in libcpp.a(charset.o)

ld: symbol(s) not found for architecture x86_64

collect2: ld returned 1 exit status

make[2]: *** [cc1-dummy] Error 1

make[2]: Leaving directory `/Users/jackie/test/opensource/xv6/resources/gcc-4.5.1/host-x86_64-apple-darwin12.3.0/gcc'

make[1]: *** [all-gcc] Error 2

make[1]: Leaving directory `/Users/jackie/test/opensource/xv6/resources/gcc-4.5.1'

make: *** [all] Error 2

 

real    9m36.001s

user    7m0.802s

sys     1m0.791s


To fix this issue,you should to modify these files 「./intl/loadmsgcat.c」、「./libcpp/charset.c」 and 「./gcc/pretty-print.c」. To replace the 「iconv()/iconv_open()/iconv_close()」 functions by 「libiconv()/libiconv_open()/libiconv_close() in these c files then compiling again.

$ make && sudo make install

$ cd../ && tar zxvf gdb-6.8a.tar.gz && cd gdb-6.8

$ ./configure --target=i386-jos-elf --program-prefix=i386-jos-elf- --disable-werror && make && sudo make install

 

 

After finish building tool-chain, you can compilg xv6 now...

$ cd../ && make TOOLPREFIX=i386-jos-elf-

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -O -nostdinc -I. -c bootmain.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -nostdinc -I. -c bootasm.S

i386-jos-elf-ld  -m    elf_i386 -N -e start -Ttext 0x7C00 -o bootblock.o bootasm.o bootmain.o

i386-jos-elf-objdump -S bootblock.o > bootblock.asm

i386-jos-elf-objcopy -S -O binary -j .text bootblock.o bootblock

./sign.pl bootblock

boot block is 429 bytes (max 510)

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o bio.o bio.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o console.o console.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o exec.o exec.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o file.o file.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o fs.o fs.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o ide.o ide.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o ioapic.o ioapic.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o kalloc.o kalloc.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o kbd.o kbd.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o lapic.o lapic.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o log.o log.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o main.o main.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o mp.o mp.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o picirq.o picirq.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o pipe.o pipe.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o proc.o proc.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o spinlock.o spinlock.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o string.o string.c

i386-jos-elf-gcc -m32 -gdwarf-2 -Wa,-divide   -c -o swtch.o swtch.S

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o syscall.o syscall.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o sysfile.o sysfile.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o sysproc.o sysproc.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o timer.o timer.c

i386-jos-elf-gcc -m32 -gdwarf-2 -Wa,-divide   -c -o trapasm.o trapasm.S

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o trap.o trap.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o uart.o uart.c

perl vectors.pl > vectors.S

i386-jos-elf-gcc -m32 -gdwarf-2 -Wa,-divide   -c -o vectors.o vectors.S

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o vm.o vm.c

i386-jos-elf-gcc -m32 -gdwarf-2 -Wa,-divide   -c -o entry.o entry.S

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pic -nostdinc -I. -c entryother.S

i386-jos-elf-ld  -m    elf_i386 -N -e start -Ttext 0x7000 -o bootblockother.o entryother.o

i386-jos-elf-objcopy -S -O binary -j .text bootblockother.o entryother

i386-jos-elf-objdump -S bootblockother.o > entryother.asm

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -nostdinc -I. -c initcode.S

i386-jos-elf-ld  -m    elf_i386 -N -e start -Ttext 0 -o initcode.out initcode.o

i386-jos-elf-objcopy -S -O binary initcode.out initcode

i386-jos-elf-objdump -S initcode.o > initcode.asm

i386-jos-elf-ld  -m    elf_i386 -T kernel.ld -o kernel entry.o bio.o console.o exec.o file.o fs.o ide.o ioapic.o kalloc.o kbd.o lapic.o log.o main.o mp.o picirq.o pipe.o proc.o spinlock.o string.o swtch.o syscall.o sysfile.o sysproc.o timer.o trapasm.o trap.o uart.o vectors.o vm.o  -b binary initcode entryother

i386-jos-elf-objdump -S kernel > kernel.asm

i386-jos-elf-objdump -t kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > kernel.sym

gcc -m32 -Werror -Wall -o mkfs mkfs.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o ulib.o ulib.c

i386-jos-elf-gcc -m32 -gdwarf-2 -Wa,-divide   -c -o usys.o usys.S

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o printf.o printf.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o umalloc.o umalloc.c

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o cat.o cat.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _cat cat.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _cat > cat.asm

i386-jos-elf-objdump -t _cat | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > cat.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o echo.o echo.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _echo echo.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _echo > echo.asm

i386-jos-elf-objdump -t _echo | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > echo.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o forktest.o forktest.c

# forktest has less library code linked in - needs to be small

# in order to be able to max out the proc table.

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _forktest forktest.o ulib.o usys.o

i386-jos-elf-objdump -S _forktest > forktest.asm

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o grep.o grep.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _grep grep.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _grep > grep.asm

i386-jos-elf-objdump -t _grep | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > grep.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o init.o init.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _init init.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _init > init.asm

i386-jos-elf-objdump -t _init | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > init.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o kill.o kill.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _kill kill.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _kill > kill.asm

i386-jos-elf-objdump -t _kill | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > kill.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o ln.o ln.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _ln ln.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _ln > ln.asm

i386-jos-elf-objdump -t _ln | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > ln.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o ls.o ls.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _ls ls.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _ls > ls.asm

i386-jos-elf-objdump -t _ls | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > ls.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o mkdir.o mkdir.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _mkdir mkdir.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _mkdir > mkdir.asm

i386-jos-elf-objdump -t _mkdir | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > mkdir.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o rm.o rm.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _rm rm.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _rm > rm.asm

i386-jos-elf-objdump -t _rm | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > rm.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o sh.o sh.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _sh sh.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _sh > sh.asm

i386-jos-elf-objdump -t _sh | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > sh.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o stressfs.o stressfs.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _stressfs stressfs.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _stressfs > stressfs.asm

i386-jos-elf-objdump -t _stressfs | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > stressfs.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o usertests.o usertests.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _usertests usertests.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _usertests > usertests.asm

i386-jos-elf-objdump -t _usertests | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > usertests.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o wc.o wc.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _wc wc.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _wc > wc.asm

i386-jos-elf-objdump -t _wc | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > wc.sym

i386-jos-elf-gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector   -c -o zombie.o zombie.c

i386-jos-elf-ld  -m    elf_i386 -N -e main -Ttext 0 -o _zombie zombie.o ulib.o usys.o printf.o umalloc.o

i386-jos-elf-objdump -S _zombie > zombie.asm

i386-jos-elf-objdump -t _zombie | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$/d' > zombie.sym

./mkfs fs.img README _cat _echo _forktest _grep _init _kill _ln _ls _mkdir _rm _sh _stressfs _usertests _wc _zombie 

used 29 (bit 1 ninode 26) free 29 log 10 total 1024

balloc: first 447 blocks have been allocated

balloc: write bitmap block at sector 28

dd if=/dev/zero of=xv6.img count=10000

10000+0 records in

10000+0 records out

5120000 bytes (5.1 MB) copied, 0.047726 s, 107 MB/s

dd if=bootblock of=xv6.img conv=notrunc

1+0 records in

1+0 records out

512 bytes (512 B) copied, 7.2e-05 s, 7.1 MB/s

dd if=kernel of=xv6.img seek=1 conv=notrunc

306+1 records in

306+1 records out

156849 bytes (157 kB) copied, 0.001244 s, 126 MB/s

rm wc.o grep.o mkdir.o rm.o ln.o stressfs.o kill.o echo.o init.o usertests.o zombie.o cat.o sh.o ls.o

$

It's done.

 

You can also using Makefile or shell script only to build the tool-chain without do anything by manual.

 

Installing xv6 on MacOS X


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Bluelove1968 的頭像
    Bluelove1968

    藍色情懷

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()