2007-12-11
从何开始
有个新的CPU, 或者新的操作系统,该怎么样搞个tool chain出来? 如何构建一个 self host的操作系统? 或许不为真的要去构造, 仅仅 满足一下好奇心而已. 当然打算从gnu toolchain入手, 又不是为了写编译器.
(来自互联网的内容已尽力标明出处)
tool chain 的结构 GCC的tool chain 包括几个部分? 根据印象,应是有gcc,cpp,cc1,gas,ld,gdb, ar, nm,strip,objdump ....emulator? 忘了,还有重 要的libc... 汗.. 看一个以上几部分都已经都存在的tool chain的构建,我们需要下面的几个部分才能构建一个完整的tool chain: binutils :gas,ld,ar,nm,strip,objdump.... gun-gcc: gcc,cpp,cc1, libc: a c lib for applications gdb: for debugging ... 模拟器... 以上各个部分,缺了就不好受...
Binutils 估计as是我们最想搞到的部分.... 没有as,ld,nm,ar... 即使移植了Gcc也是不能工作... binutils包含如下各个部分:
主要部分:
-
ld - the GNU linker.
-
as - the GNU assembler.
其他(很有用哦):
-
addr2line - Converts addresses into filenames and line numbers.
-
ar - A utility for creating, modifying and extracting from archives.
-
c++filt - Filter to demangle encoded C++ symbols.
-
gprof - Displays profiling information.
-
nlmconv - Converts object code into an NLM.
-
nm - Lists symbols from object files.
-
objcopy - Copys and translates object files.
-
objdump - Displays information from object files.
-
ranlib - Generates an index to the contents of an archive.
-
readelf - Displays information from any ELF format object file.
-
size - Lists the section sizes of an object or archive file.
-
strings - Lists printable strings from files.
-
strip - Discards symbols.
-
windres - A compiler for Windows resource files.
预备知识: 1.阅读如binutils自己的文档 gas/doc/internals.texi bfd/doc/bfdint.texi Preliminary Notes on Porting BFD 2.读源代码....?? 3.找个cpu的实例来分析,比如这个Add new target to Binutils 还有PS3的cell CPU的proting: New port to Cell SPU 也比 较全面. 移植的基本步骤,建议仔细阅读 CGEN, the Cpu tools GENerator 的各种文档: 移植完整的Tool chain到一个CPU(target),需要按顺序(不一定,但是这么做是有道理的)移植如下模块:
可以看到CGEN的重要作用,困难的Opcodes部分他已经帮着做了..... 对于binutils, CGEN为CPU产生如下文件:
Opcodes:
include/opcodes/FOO.h - Port specific ISA encoding opcodes/FOO-dis.c - Port specific disassembler routines opcodes/FOO-opc.c - Port specific ISA encoding
ISA: Instruction Set
Architecture .... 然后,by hand吧,最头痛的部分可能是BFD/*-Foo.c的编写了,好像是重定位的方式很
是不好,RedHat为此搞了一个新的重定位的方式,但是,没有公开...:
BFD:
bfd/{elf32|coff}-FOO.c - Port specific relocation handlers bfd/cpu-FOO.c - Port specific description of the CPU
GAS: gas/config/tc-FOO.h - Customisation of generic parts of the assembler gas/config/tc-FOO.c - Port specific parts of the assembler include/{coff|elf}/FOO.h - Port specific header file
LD: ld/scripttempl/FOO.sc - Port specific linker template file ld/emulparam/FOO.sh - Port specific linker customisation
最后是各种配置文件的修改: opcodes/configure.in opcodes/disassemble.c opcodes/Makefile.am
bfd/configure.in bfd/config.bfd bfd/archures.c bfd/reloc.c bfd/targets.c bfd/Makefile.am Run "make dep-am".
gas/configure.in gas/configure.tgt Add new cpu support. gas/Makefile.am Run "make dep-am"
ld/configure.in ld/makefile.am
include/dis-asm.h binutils/readelf.c: Add SPU support. binutils/Makefile.am: Run "make dep-am". include/elf/common.h (EM_foo): Define. 更详细的请参考New port to Cell SPU 或者Add new target to Binutils:Score.
这个是个不小的工程.....
Porting GNU GCC GCC的porting, 文档要比binutils全面的多了. 现得看看下面几个文档: Using and Porting the GNU Compiler Collection (GCC) GCC移植权威文档... GCC Internals Manual 权威啊权威... Porting GCC for Dunces
其他推荐阅读的文档: Futher Reading of GCC
(以下资料部分来自gcc.cookys.org) 首先,gcc的的基本编译流程是这样的: gcc把编译器分成前端 后端等几个部分, 中间的编译和大部分优化工作都是使用统一的"汇编码" RTL(register tranfer langage)来表 达的,RTL可以参考linuxforum上的这篇文章RTL中文版. 最后使用MD(mechine description)转换成特定target的汇编语言.再剩下的工 作交给binutil了. gcc的结构如下:
我们要移植一个GCC到新的cpu的话, 只需要生成新cpu的Machine Description和Macro Definition两个部分就好了. 其实就是下面三个文件: 在目录gcc-xxx/gcc/config/machine/下写三个文件: target.h Contain C macros that define general attributes of the machine. target.md Contain RTL expressions that define the instruction set. Input to programs that procude .h and .c files. target.c Machine-dependent functions; normally things too large to cleanly put into above two files.
写好了,编译的时候,由这三个文件生成一堆的文件,这些文件构成gcc的back end部分, 整个gcc就算初步移植完成了.这里最主要的就是 target.md的内容,是由许多的RLT语言构成的模板,指导gcc优化和生成target的汇编语言. RTX:RTL expresion 要注意的是, target.md中的并不是RTL,而是为了生成ASM的指令模板,应该是RTL的一部分. 要理解md中的内容,恐怕这里搞不完.并且 me也不甚清楚...ft.(所以要学啊). 不过还是来看看一个指令模板是啥样子吧,找了个最熟悉的cpu x86,找了一个最简单的指令,xor:
看到这个你是否想起了LISP,前缀表到式之类的东西呢? 没有的话看看lisp的哲学吧:跨越边界,lisp之美.(IBM linux) (注:这个例子是RTL模板,而不是RTL表达式, RTX才是真正的类前缀表达式) 这个模板指导gcc将中间语言的标准指令xorqi3 (qi: 四分之一个interger,即byte, 3:有三个操作数), 转换为i386的对应汇编码. gcc最终会根据指令模板 xor%B0, %2, %0 来生成对应的i386指令:xorb %2,%0 (%2,%0会替换成对应的寄存器或者常量/内存). 关于%B0: 这是个非标准的输出模板,参考gcc/config/i386/i386.c print_operand (file, x, code),就是输出'b'到汇编文件. %B0后面跟的0,实际上对应一个rtx(即一个指令),但是i386里B后面这个数字看来是没有意义的. 根据我的理解(fixme)%B0 意思是根据操作数0的属性,来决定'%B'应该输出的具体格式.(%B总是输出字符'b'-:) AS2定义在i386/unix.h里,很简单. 参考下面的列出的函数:
这不过是冰山的一角,移植gcc到新cpu, 这些模板的设计占了很大的工作量...
这里仅仅是个序言,要学习的东西,实在是很多....
Self-host OS 和 Toolchain Porting 移植libc,其实上是为GCC构建一个target的必经之路.如果你有个新的OS,比如建立在i386之上,你当然不必要去移植GCC和binutil到新 的cpu.那些都是现有的东西.要得到一个self host的OS,大致要经过如下几个步骤: 1.你的OS已经有了足够的系统调用接口(至少满足gcc对libc的要求吧).然后就可以考虑移植GCC,成为一个self host的OS了. 2.为你的OS做一个GCC Cross Compiler: 主要是制作自己的platform description. 3.移植一个libc到你的系统.(至少这个libc应该实现GCC要求的那几个接口才成. 4.使用你的Cross Compiler和移植的libc去编译GCC. 这样就有了一个可以在你的系统上运行的GCC了. 5.使用你自己OS上的gcc去编译gcc自己.(就是看看是否真的移植成功了...)
可以看到第2步和第3步才是核心.我们不妨先看看一个纯粹的cross Compiler toolchain的制作过程,然后分别详述第二步和第三步. (google下,很多参考资料,主要参考资料来自www.osdev.org).
Pure Cross-Compiler Toolchain step by step 1)下载 binutils 和 GCC packages:gcc core 就可以了 http://ftp.gnu.org/gnu/ 2)配置 export PREFIX=/usr/cross cross gcc的bin会放到这个目录 export TARGET=i586-elf 假设你的OS运行在i386上,并且使用elf格式的binfmt cd /usr/src 假设你下载的gcc 和binutil在这个目录(你当然要解压缩了) mkdir build-binutils build-gcc 3)制作GCC Cross Compiler: (要分清host和target啊...) cd /usr/src/build-binutils ../binutils-x.xx/configure --target=$TARGET --prefix=$PREFIX --disable-nls make all make install
--disable-nls :不要使用汉语吧, 用英语就行了. 这个选项让gcc不输出汉语的提示... cd /usr/src/build-gcc export PATH=$PATH:$PREFIX/bin ../gcc-x.x.x/configure --target=$TARGET --prefix=$PREFIX --disable-nls \ --enable-languages=c,c++ --without-headers --with-newlib make all-gcc make install-gcc
-without-headers :这个选项使你编译出的GCC不能使用标准库.(host cpu和target cpu一样的话,基本不用cross toolchain系统 通过编译选项也能实现这个功能). --with-newlib 这只是个bug的work around,和newlib没有关系的. This is only necessary if you are compiling GCC <= 3.3.x. That version has a known bug that keeps --without-headers from working correctly. Additionally setting --with-newlib is a workaround for that bug. --enable-languages :高速gcc需要哪些语言支持:font end tells GCC not to compile all the other language frontends it supports, but only C。
Full Pure Cross-Compiler ToolChain 这里搞出的cross gcc用来编译内核还凑合, 因为没有libc,当然无从编译应用程序了.C标准定义了两个运行环境"freestanding"和 "hosted". 你的内核是freestanding的,而你的OS上的应用程序就是hosted的.使用用这个cross gcc编译你的内核,按照C标准,你需要 准备下面的文件:(C99标准, 很少)(btw:个人做os实验的时候没有依此进行) float.h, iso646.h, limits.h,stdarg.h, stdbool.h, stddef.h, and stdint.h 如要用cross gcc 编译你自己OS上的应用程序,你需要移植libc.最好的选择可能是newlibc,为啥? 因为他的移植实在是方便啊,十几 个接口就够了,其他的libc还有glic,uclibc,diet libc..... 即使是采用newlibc,估计也不是非常简单的.移植libc之后,需要重新 生成cross-compiler toolchain这次为gcc指定参数: --with-headers foo/include... 指明哪里去找头文件. 这样重新编译出来的gcc就可以使用你移植的libc.这里先不说libc如何移植.我们是想做一个self hosted的OS,那么我们也应该制作自己 的toolchain TARGET. 比如叫 i586-pc-myos.这也是移植一个toolchain到新的HOST时需要做的一个事情.
下面的一系列章节就详述如何为新的OS制作一个self host的GCC.
OS Specific ToolChain - Prepare 对比pure cross-compiler tool chian的制作过程,这里主要解决的问题是给ToolChain增加一个新的TARGET.下面就来学习下前辈的 经验: (原文链接:OS Specific Toolchain ) 1)下载 binutils, gcc-core and newlib并解压缩到/usr/src 的某个目录(你随意...)
2)配置环境变量并准备编译目录 export TARGET=i586-pc-myos export PREFIX=/usr/cross cd /usr/src ... mkdir build-binutils build-gcc build-newlib
OS Specific ToolChain - BinUtils 和 GCC
1)Add target to binutils 修改config.sub: 这是一个autoconf使用的配置文件,i586-pc-myos是一个规格化的名字,在config.sub中分别描述 可以接受的cpu/vrendor/os.我们只需要吧myos加入os列表即可:搜索"First accept the basic system types",加入 '-myos*'到列表即可.
配置bfd/config.bfd: 搜索字符串"WHEN ADDING ENTRIES TO THIS MATRIX",照样子加入如下的一段即可: i[3-7]86-*-myos*) targ_defvec=bfd_elf32_i386_vec targ_selvecs=i386coff_vec ;;
配置gas/configure.tgt: 找到'Assign object file format ... case ${generic_target} in',添加如下内容, i386-*-myos*) fmt=elf ;; 这里只用 i386即可,即便是你的规格化的target名字是x86-64...(?)
配置ld/configure.tgt:搜索'Please try to keep this table in alphabetical order ... case "${targ}" in', 加入新的"emulation"名称 i[3-7]86-*-myos*) targ_emul=myos_i386 ;;
增加 新文件ld/emulparams/myos_i386.sh : 这是上面一个步骤新加进来的ld
emulation的具体定义.因为我们并没有
增加新的binfmt,所以copy一个elf的过来就应可以了.这些参数看来都是为了linker准备的一些参数,并不是难以理解,大部分和
link script的内容类似.
ld/Makefile.in :
在ld/configure.tgt中加入targ_emul=myos_i386',意味着你的OS的linker会吧ld和一个叫做emyos_i386.o
的文件链接在一起.我们需要做的是,定义如何产生这个C文件,当然有现成的脚本,这里只需要一个make target/rule而已.
emyos_i386.c: $(srcdir)/emulparams/myos_i386.sh
$(ELF_DEPS) $(srcdir)/scripttempl/elf.sc \
${GEN_DEPENDS}
${GENSCRIPTS} myos_i386 "$(tdir_myos_i386)"
然后吧 'emyos_i386.o'增加到'ALL_EMULATIONS'就可以了.
2)Add target to
GCC
config.sub :类似Binutils, 略.
gcc/config.gcc: 找到'Common parts for widely ported systems ...
case ${target} in' 增加如下部分:
*-*-myos*)
extra_parts="crtbegin.o crtend.o"
gas=yes
gnu_ld=yes
default_use_cxa_atexit=yes
;;
上面的配置基本含义是说,编译静态的 crtbegin crtend
(对libgcc很重要),我们的OS使用GNU的linker和assembler并且提供
__cxa_atexit(其实上是newlib提供的).然后找到'case ${target} in ... Support
site-specific machine types'加入如下
部分:
i[3-7]86-*-myos*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h
i386/i386elf.h myos.h"
tmake_file="i386/t-i386elf t-svr4"
use_fixproto=yes
;;
然后,需要创建myos.h.
gcc/config/myos.h:
#undef TARGET_OS_CPP_BUILTINS
#define TARGET_OS_CPP_BUILTINS()
\
do {
\
builtin_define_std ("myos"); \
builtin_define_std ("unix"); \
builtin_assert ("system=myos"); \
builtin_assert ("system=unix"); \
} while(0);
#undef TARGET_VERSION
#define
TARGET_VERSION fprintf(stderr, " (i386 myos)");
这些宏的含义高速与处理器一些东西:定义宏,asserts,default system name(编译app的默认名字)
libstdc++-v3/crossconfig.m4:
在你需要交叉编译你的标准C++lib的时候才需要.大概如下,可以参考linux的定义:
*-myos*)
AC_CHECK_HEADERS([sys/types.h locale.h float.h])
GLIBCXX_CHECK_BUILTIN_MATH_SUPPORT
GLIBCXX_CHECK_COMPLEX_MATH_SUPPORT
GLIBCXX_CHECK_STDLIB_SUPPORT
;;
如果修改了请在目录libstdc++-v3 下运行 'autoconf'.
OS Specific ToolChain -- Porting newlib
1)config.sub:Same as for binutils
2)newlib/configure.host: 找到'Get the source directories to use
for the host ... case "${host}" in',添加如下代码
i[3-7]86-*-myos*) sys_dir=myos ;; 3)newlib/libc/sys/configure.in: 到'case ${sys_dir} in' 添加 myos) AC_CONFIG_SUBDIRS(myos) ;; 然后在 newlib/libc/sys 下运行autoconf'
4)创建目录newlib/libc/sys/myos: 然后至少创建四个文件:ctr0.s, syscalls.c configure.in Makefile.am 这便是你的 OS和libc.a的接口了:
crt0.S 最少包含以下内容: 包含符号_start, 调用main函数,main结束后调用exit,也许需要设置ds/ss啥的,看你的OS了. .global _start .extern main .extern exit _start: call main call exit .wait: hlt jmp .wait
syscalls.c :在这里实现你的系统调用,看你的newlib版本了,记得到newlib网站去查找一下,这里的不一定全. /* note these headers are all provided by newlib - you don't need to provide them */ #include <sys/stat.h> #include <sys/types.h> #include <sys/fcntl.h> #include <sys/times.h> #include <sys/errno.h> #include <sys/time.h> #include <stdio.h>
void _exit(); int close(int file); char **environ; /* pointer to array of char * strings that define the current environment variables */ int execve(char *name, char **argv, char **env); int fork(); int fstat(int file, struct stat *st); int getpid(); int isatty(int file); int kill(int pid, int sig); int link(char *old, char *new); int lseek(int file, int ptr, int dir); int open(const char *name, int flags, ...); int read(int file, char *ptr, int len); caddr_t sbrk(int incr); int stat(const char *file, struct stat *st); clock_t times(struct tms *buf); int unlink(char *name); int wait(int *status); int write(int file, char *ptr, int len); int gettimeofday(struct timeval *p, struct timezone *z);
configure.in
AC_PREREQ(2.59)
AC_INIT([newlib], [NEWLIB_VERSION]) AC_CONFIG_SRCDIR([crt0.S]) AC_CONFIG_AUX_DIR(../../../..) NEWLIB_CONFIGURE(../../..) AC_CONFIG_FILES([Makefile]) AC_OUTPUT
Makefile.am
AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) AM_CCASFLAGS = $(INCLUDES)
noinst_LIBRARIES = lib.a
if MAY_SUPPLY_SYSCALLS extra_objs = $(lpfx)syscalls.o else extra_objs = endif
lib_a_SOURCES = lib_a_LIBADD = $(extra_objs) EXTRA_lib_a_SOURCES = syscalls.c crt0.S lib_a_DEPENDENCIES = $(extra_objs) lib_a_CCASFLAGS = $(AM_CCASFLAGS) lib_a_CFLAGS = $(AM_CFLAGS)
if MAY_SUPPLY_SYSCALLS all: crt0.o endif
ACLOCAL_AMFLAGS = -I ../../.. CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host 最后记得运行autoconf
newlib的signal处理: please man signal/raise 1)使用内建的signal emulation: 在crt0调用main之前,调用'_init_signal'即可.局限是,只能响应本进程的内发送的signal. 2)在syscalls.c 中定义自己的signal()函数,注册一个signal handle到内核(OS specific),当然得处理好当前的进程堆栈等一系列 的事情. 然后再创建系统调用:kill(),这个函数发送一个信号到其他线程/进程.newlib提供一个raise()函数,但是仅仅调用你写的kill 而已.最后在newlib/configure.host中添加一个cflag: newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED" 当然,可以定义sigaction(),然后把signal()最为一个包装函数,另外OpenGroup 发表的声明说: 1) sigaction 会替代 signal, 2)应用程序不能使同时使用这两个接口去操作同一个信号.
OS Specific ToolChain -- Building 记得要在build-binutils build-gcc build-newlib中编译,不能在源文件目录编译(这个得研究autoconf,automake).这里的工作类 似Cross build ToolChain的过程.
1)Bootstrap
BinUtils /usr/src/build-binutils, run ../binutils-2.18/configure --target=$TARGET --prefix=$PREFIX make make install export PATH=$PATH:$PREFIX/bin
GCC From /usr/src/build-gcc, run (only use --enable-languages=c if you haven't downloaded and unpacked gcc-g++!) ../gcc-4.2.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,--without-headers make all-gcc make install-gcc
2)Build newlib with Bootstrap Newlib
From /usr/src/build-newlib, run
../newlib-1.15.0/configure --target=$TARGET --prefix=$PREFIX
make
make install
and optionally
make install-info
Libstdc++
From /usr/src/build-gcc, run
make
make install
Note that libstdc++ can only be built after installing newlib, as it
depends on libc.
3) Rebuild GCC
在/usr/src/build-gcc下,运行 ../gcc-4.2.1/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,\ --with-headers=newlib/libc/include make all-gcc make install-gcc further check: --with-local-prefix = newlib/libc/include
OS Specific ToolChain --总结 回头看看 Self-host OS 和 Toolchain Porting 到这里为止,我们完成了几步?(当前host和target host的cpu相同).
现在有了一个Coss Build 的toolchain,并且有自己的libc,但是gcc还是运行在当前的host,而不是我们的平台,我们需要再一次的使用这 个cross toolchain去编译binutil和gcc.然后拿到自己OS上,为了测试,再一次编译GCC....ft.
使用cross-toolchain编译运行在target上的gcc时,最好先研究下gcc编译的一些细节,下面列出些参考资料: http://gcc.gnu.org/install/configure.html 官方的gcc编译配置说明 http://sdn.vlsm.org/share/LDP/lfs/chapter05/toolchaintechnotes.html LFS的toolchain Notes http:///man.chinaunix.net/linux/lfs/htmlbook/chapter05/toolchaintechnotes.html LFS toolchain Notes 中文版
这些资料是创建linux的发行版所使用的技术,但是对制作self hosted 的tool chain也大有裨益,不妨看看. 下面是一些基本的调试技术和说明: 1.确定当前的工作平台(估计你是i686-pc-linux-gnu吧?) 找个config.guess运行下试试就行了
2.确定当前平台的动态链接器 一般由glibc提供,名称是ld-linux.so.2或者ld.so.1 (64位平台可能还不一样).常规的办法是 readelf -l <name of binary> | grep interpreter
3.关键的地方 比如你的cross-toolchian在usr/cross目录下,的确认一下,ld和gcc所有的搜索路径都只在/usr/cross下.否则编译出来的self-host gcc含有对当前host的lib的引用就麻烦了.下面两个是必须检查确认的: ld的搜索路径,以保证程序只连接到我们选择的库上,确认方式:ld --verbose | grep SEARCH gcc的specs文件,告诉编译器该使用哪个动态连接器.(对于我们可以使用静态链接先)确认方式为: readelf -l <name of binary> | grep interprete 看一个这个cross-toolchain编译出来的bin文件 gcc dummy.c -Wl,--verbose 2>&1 | grep succeeded 确认gcc编译过程中打开的文件 gcc -print-prog-name=ld 确认gcc将要使用的ld ./configure 运行gcc的configure,其中会有这次编译所需要的ld,as的信息,类似于: checking what assembler to use... /tools/i686-pc-linux-gnu/bin/as checking what linker to use... /tools/i686-pc-linux-gnu/bin/ld
最后,来看看libgloss库是个什么东西:(讲newlib的时候,总会提到这个库) Libgloss: 这个library 来自newlib,以往,这些部分也在newlib source中,在newlib只有一个target時还行.但是后来原来越多的target得到支 持,就比较麻烦.以前target相关的sourcecode在"stub"目录.后来library 中和hardware (targt)相关的函数都放到了stub 下。 然后,gdb, glibc也发现这个stub很有用,所以就把stub 目从newlib source code中移出,形成了现在的libgloss. Libgloss : Gnu Low-level OS support.
另: newlib是RedHat弄的..... http://sourceware.org/newlib/ newlib的homepage
OS Specific ToolChain -- self Bootstrap 利用上面的cross-toolchain,我们可以编译一个可以运行在myos上的GCC. BinUtils /usr/src/build-binutils, run ../binutils-2.18/configure --host=$TARGET --target=$TARGET --prefix=$PREFIX-BOOTSTRAP --with-lib-path=$PREFIX/newlib make install export PATH=$PATH:$PREFIX/bin
要指定一个正确的--with-lib-path才行(这里的$PREFIX/newlib可能不对,得换成真实路径), 安装路径应该换一个才对,比如存在环境 变量$PREFIX-BOOTSTRAP中.
GCC From /usr/src/build-gcc, run (only use --enable-languages=c if you haven't downloaded and unpacked gcc-g++!) ../gcc-4.2.1/configure --host=$TARGET--target=$TARGET --prefix=$PREFIX-BOOTSTRAP --disable-nls \ --enable-languages=c --without-headers --disable-shared make all-gcc make install-gcc more option :--with-sysroot --with-libs ... --host:虽然未在gun的官方文档中发现这个选项的说明,但是确实有的,通过这个选 项,gcc选取指定host下的as/ld/lib http://gcc.gnu.org/install/configure.html
通过这两个步骤生成的gcc和binutils应该可以运行于myos了!!!
以上步骤未经证实,仅供参考.
GDB Porting 系统self hosted以后,最重要的基础设施就是debug了. GDB无疑是我们的选择(都porting了gcc了,当然debug 选GDB...-:) 首先看看官方文档,GDB internal http://sourceware.org/gdb/download/onlinedocs/gdbint.html 然后这里有个GDB remote stub的协议说明: http://sca.uwaterloo.ca/coldfire/gcc-doc/docs/porting_4.html 最重要的是,我们的linuxfourm有teewater这样一批热心人,看看笔者的几遍文章吧: 移植GDB(1) arch和frame v0.3 更新时间:2006-04-01 http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=program&Number=603645 移植GDB(2) native v0.0 更新时间:2006-02-21 http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=program&Number=595833 移植GDB(3) init.c和target_ops v0.0 更新时间:2006-02-27 http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=program&Number=596941 移植GDB(4) gdbserver v0.0 更新时间:2006-03-03 http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=program&Number=597734
GDBINT梗概 :实在是太长,另起文章 http://docs.google.com/Doc?id=dcbsxfpf_68fjrhsnch
Refrence DISCUSS: porting tool chain to new cpu 不是只有我们才有疑惑.... Building a GNU/Linux ARM Toolchain (from scratch) 为已有体系结构建立tool chain
GNU binutils binutils 的老家 Preliminary Notes on Porting BFD BFD proting 预备知识 Untitled Document for GAS 这个比较好,讨论了如何移植一个GAS到新的CPU DISCUSS:Porting binutils to new CPU 一个讨论, 如何porting binutils 到一个新的cpu: CGEN的作用... Add new target to Binutils:Score 这是一个移植Binutils到新CPU的比较完整的例子,有移植相关的全部代码 [PATCH]:new target SCore 上面例子的参靠资料 New port to Cell SPU 这是啥?这就是大名顶顶的PS3游戏机的Cell CPU啊 berkeley Cell CPU wiki CELL cpu的一个论坛
Using and Porting the GNU Compiler Collection (GCC) GCC移植权威文档... GCC Internals Manual 权威啊权威...
Compiler 一个实例(没有涉及binutils) CGEN, the Cpu tools GENerator 为CPU创建assemblers, disassemblers and simulator的工具
gcc.cookys.org 台湾gcc研究工作室....(有点老) CCRG:咱们自己的gcc研究室(863计划???) 中文gcc资料大大的... http://www.cse.iitb.ac.in/~uday/gcc-workshop/?file=downloads GCC internal workshop 印度
http://www.osdev.org/wiki/OS_Specific_Toolchain 移植tool chain到new host http://www.osdev.org/wiki/Porting_Newlib 移植new lib到你的OS http://www.osdev.org/wiki/GCC_Cross-Compiler GCC Cross Compiler
|