📄 proting-uclinux-to-mips-e.txt
字号:
not the best way because it slows down the system. In function memcpy will use these instructions,
imaging what will happen when you do memory copy. We must remove these legal but not
implemented instructions from our MIPS uclinux.
Gcc will emit these instructions too. We had better to modify Gcc to avoid this problem.
4.7 Memory page fault handle
When page fault happens, linux will try to find out the corresponding VMA. And then try to fix up
the fault. This is not be necessary in uclinux. Therefore the code handle page fault can be
removed.
5. Porting GNU toolchain
5.1 GNU toolchain and uclinux
As we discuss before, GNU toolchain can be used to develop MIPS uclinux kernel and AP. The
only thing we need to do is porting elf2flt.
Thanks for the great job done by Erik Andersen (andersen@uclibc.org), we can donwload, config,
compile and install GNU toolchain easily. And his job is the base of ours.
5.2 Porting ELF2FLT
GNU toolchain doesn't support flat format. Ld will generate ELF format file, and then use elf2flt
to convert it to flat file.
Now we introduce the flat format in brief.
A flat file has 5 parts, they are file header, text section, data section, bss section and relocate table.
The file header includes the sizes and offsets of other parts, also includes the entry point and
characteristics of the file. The relocate table includes a got table and some other relocate items.
The got table is located at the beginning of data section, end ends with a dword –1.
After install elf2flt, a script file ld-elf2flt takes the place of the original ld, the old ld is renamed to
mipsel-uclibc-ld.real. To create a flat file, we need to do like this,
mipsel-uclibc-gcc –Wl,-elf2flt foo.c –o foo
Gcc will call ld (in fact it calls ld-elf2flt) to link after compile foo.c. And ld-elf2flt will call the old
ld twice to create two ELF files, foo.elf and foo.gdb. foo.elf is an object file, includes reloc section.
foo.gdb is executable file, includes got table. ld-elf2flt then call elf2flt, uses foo.elf and foo.gdb as
input. Elf2flt uses information from these two ELF file to create relocate table. We must notice
that the memory map of two ELF file is not the same, because of the existing of got table.
Elf2flt will calculate the got table size. The original version of elf2flt assumes every data section
in object file align at 4 bytes. This condition can not be guaranteed in MIPS object file. We have
fixed it.
Elf2flt uses elf2flt.ld as ld script. Base address of the whole module is set to 0 in elf2flt.ld. It cause
got table contains some zero value item. binfmt_flat.c won't handle these items because it need to
support c++ programs. We change the base address to 0x40000 and solve this problem.
5.3 Reserve instructions and toolchain
As we descript in 4.6, sometimes GNU toolchain need to be modified to avoid emitting some
instructions. How to do this is a large issue, we won't talk about it in this document. The paper
"GNU Compiler Collection (GCC) Internals" will be a good reference for doing this job.
If you only want to remove unaligned memory access instructions, you can change tc-mips.c in
GAS. But you had best to change gcc to generate more efficient code.
5.4 Soft floating
gcc supports soft-floating. You only need to add –msoft-float to your Makefile.
6. Porting uclibc
6.1 Introduction of uclibc
uClibc can work on MIPS platform without many porting job. Though we still have some thing to do.
6.2 Stack align to 8 bytes
The MIPS version gcc has a macro va_arg, just like other versions. The stack pointer need to be
aligned at 8 bytes when use this macro in MIPS. It will cause error when the macro handles 8
bytes long parameter otherwise. We make the stack pointer align to 8 bytes in uClibc startup code.
6.3 Pthread
Pthread code in uClibc use MIPS II instruction in function testandset. If the CPU only supports
MIPS I, we should remove them. We use sysmips(MIPS_ATOMIC_SET…) instead of the MIPS
II instructions.
6.4 float-point instruction
MIPS version uClibc will save and restore floating-point registers in setjmp and longjmp. We
must remove the code if the CPU has no floating-point processor. (see
libc/linux/mips/__longjmp.c and libc/linux/mips/setjmp_aux.c )
7. JIT Simulator
7.1 Introduction
The best way to be a expert of porting uclinux to MIPS is to do all porting job by yourself. But
every one cannot get a MIPS hardware. Even you have one, it's wasting time to download and
write the code to flash rom.
We would like to introduce our "Xiptech Simulator for MIPS" to you. It is an instruction set
system level simulator. It emulates a MIPSR3000 CPU and some virtual devices. It can run MIPS
binary code directly, including linux/uclinux kernel, libs and applications. The main feature of our
simulator is its world leading performance. It uses a just in time compile engine and can run faster
than 50 mips on a P3 650 notebook.
We offer a demo version to personal users. This version doesn't contain some advance functions,
but it's enough to learn how to porting linux/uclinux/libs/GUI/application/GDB to MIPS platform.
Please don't use it in business without permit.
7.2 How to use it?
The demo version simulator runs on MS Windows 98/Me/2000/XP. If you need linux version
please contact us. A user guide document is included in the package. In fact, using simulator just
like use the hardware. You need to build an OS kernel image and give it to the simulator. Then
simulator will boot and run your kernel.
Our patch file for MIPS uclinux contains all drivers for simulator. You can find them in
arch/mipnommu/mach-xipos.
7.3 Where can I get it?
www.xiptech.com
8. Other issue
8.1 Share lib on uclinux
Modern OS provide share lib or DLL. Some DLL systems don't support process independent data
section, such as MS Win3.1. Some others do, such as linux. In no MMU systems, it's not easy to
provide the second type of DLL. Therefore normal linux share libs cannot be used in uclinux. As
we know, some companies have expanded uclinux to support share lib under arm and m68k
platform. We do the same job on MIPS platform. But the code is under testing, we will release it
in next version.
8.2 PIC or NO-PIC ?
Linux uses PIC code in its share lib and applications. In uclinux we have choices, PIC or NO-PIC?
Based on our testing, NO-PIC code run faster than PIC code. (About 30%) Using NO-PIC will
improve the system's performance. But NO-PIC code will cause two problems, much bigger
executable file size and more time to load the program. You can make decision based on your
situation.
By the way, to use NO-PIC code, some reloc types, such as REL_HI16, should be handled in
elf2flt.
9. Get and build packages
Build toolchain
At first you MUST connect to Internet when you build the toolchain. Download toolchain.tar.gz
from www.xiptech.com, then unzip it and make. All the source code of toolchain will be
download and config automatically.
The toolchain will be installed to /opt/toolcahin by default. Before you use it, You need to
export PATH=/opt/toolchain/bin:$PATH
If you want to change the install path, you need to change TARGET_PATH in Makefile before
you make.
Maybe you need to modify uClibc for your platform, please do it after the make process. Do your
change and then
make uclibc
This operation will rebuild and install the uclibc.
toolchain.tar.gz comes from Erik Andersen. We just do a little change and use our elf2flt for MIPS.
More information and the newest version of this package can be get on www.uclibc.org.
Build uclinux
Dowdload the following files,
http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.19.tar.bz2
http://www.uclinux.org/pub/uClinux/uClinux-2.4.x/uClinux-2.4.19-uc1.diff.gz
http://www.xiptech.com/download/uClinux-2.4.19-uc1-mips.diff.gz
http://www.xiptech.com/download/romfs.tar.gz
Unzip and patch,
mkdir mips-uclinux
cd mips-uclinux
bunzip2 < ../linux-2.4.19.tar.gz2 | tar xvf -
gunzip ../uClinux-2.4.19-uc1.diff.gz
gunzip ../uClinux-2.4.19-uc1-mips.diff.gz
tar zxvf ../romfs.tar.gz
cd linux-2.4.19
patch -p1 < ../uClinux-2.4.19-uc1.diff
patch -p1 < ../uClinux-2.4.19-uc1-mips.diff
Build kernel
make mrproper
cp xipos.config .config
make menuconfig
make dep
make
The file uclinux.bin will be created, and then use our Xiptech simulator for MIPS to run it.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -