Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15310248
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2010-04-22 14:40:35

luther@gliethttp:~$ . CPU_KEYS.env
luther@gliethttp:~$ make zbimage-linux-xload
luther@gliethttp:~$ ll arch/mips/boot/ 该目录为生成的xload文件
luther@gliethttp:~$ nm vmlinux|grep kernel_entry|cut -d' ' -f 1
8434f000
这个数值就是
genzbf -l load_addr -s start_addr -a lexfs -e enc_hdr_size -o outfile -z infile
               -z modify existing zbf file
就是genzbf使用到的vmlinux.bin内核exec运行地址值
luther@gliethttp:~$ mipsel-linux-objdump -DS vmlinux |more
看到的第一个语句就是
84000000:    090d3c00     j    8434f000 <__init_begin>

luther@gliethttp:~$ vim arch/mips/kernel/head.S
#if defined(CONFIG_TANGOX) // 我们的就是TANGOX3
    j    kernel_entry  ######## 要不vmlinux的第一个语句也是跳转到kernel_entry
    nop
    .fill    0x400-0x8 ######## 填充空间,和ep9315类似,都要在前面作多余填充[luther.gliethttp]
#if defined(CONFIG_TANGO3)
    .org    0x2000    ######## 对于TANGO3起始地址设为0x2000,这和反汇编的数值一致
#endif
    __INIT            ######## 展开之后为一个.section ".init.text","ax"字段属性,用来指导字段存储
NESTED(kernel_entry, 16, sp) # kernel entry point ######## 这就是我们一直要找的kernel_entry入口地址了
    kernel_entry_setup         # cpu specific setup


luther@gliethttp:~$ mipsel-linux-objdump -DS arch/mips/kernel/head.o

arch/mips/kernel/head.o:     file format elf32-tradlittlemips

Disassembly of section .text:

00000000 <_stext-0x2000>:
       0:    08000000     j    0 <_stext-0x2000>
       4:    00000000     nop
    ...
Disassembly of section .reginfo:

00000000 <.reginfo>:
   0:    300003f2     andi    zero,zero,0x3f2
    ...
Disassembly of section .pdr:

00000000 <.pdr>:
    ...
  14:    00000010     mfhi    zero
  18:    0000001d     0x1d
  1c:    0000001d     0x1d
Disassembly of section .init.text:

00000000 :
   0:    40086000     mfc0    t0,c0_status
   4:    3c011000     lui    at,0x1000
   8:    3421001f     ori    at,at,0x1f
   c:    01014025     or    t0,t0,at
  10:    3908001f     xori    t0,t0,0x1f
  14:    40886000     mtc0    t0,c0_status
  18:    000000c0     ehb
  1c:    3c080000     lui    t0,0x0
  20:    25080000     addiu    t0,t0,0
  24:    ad000000     sw    zero,0(t0)
  28:    3c090000     lui    t1,0x0
  2c:    2529fffc     addiu    t1,t1,-4
  30:    25080004     addiu    t0,t0,4
  34:    1509fffe     bne    t0,t1,30
  38:    ad000000     sw    zero,0(t0)
  3c:    3c010000     lui    at,0x0
  40:    ac240000     sw    a0,0(at)
  44:    3c010000     lui    at,0x0
  48:    ac250000     sw    a1,0(at)
  4c:    3c010000     lui    at,0x0
  50:    ac260000     sw    a2,0(at)
  54:    3c010000     lui    at,0x0
  58:    ac270000     sw    a3,0(at)
  5c:    40802000     mtc0    zero,c0_context
  60:    3c1c0000     lui    gp,0x0
  64:    279c0000     addiu    gp,gp,0
  68:    241d1fe0     li    sp,8160
  6c:    03bce821     addu    sp,sp,gp
  70:    3c010000     lui    at,0x0
  74:    ac3d0000     sw    sp,0(at)
  78:    08000000     j    0
  7c:    27bdfff0     addiu    sp,sp,-16

让我们来预处理head.s文件
arch/mips/kernel/Makefile
extra-y        := head.o init_task.o vmlinux.lds 使用上面由arch/mips/kernel/vmlinux.lds.S生成出来的vmlinux.lds

luther@gliethttp:~$ vim arch/mips/kernel/.head.o.cmd 里面包含编译指令
mips-linux-gnu-gcc -Wp,-MD,arch/mips/kernel/.head.o.d  -nostdinc -isystem /vobs/ftp_dir/uploads/1.3k/smp2/mips-4.3/bin/../lib/gcc/mips-linux-gnu/4.3.2/include -D__KERNEL__ -Iinclude  -include include/linux/autoconf.h -D__ASSEMBLY__  -mabi=32 -G 0 -mno-abicalls -fno-pic -pipe -ffreestanding -EL -UMIPSEB -U_MIPSEB -U__MIPSEB -U__MIPSEB__ -UMIPSEL -U_MIPSEL -U__MIPSEL -U__MIPSEL__ -DMIPSEL -D_MIPSEL -D__MIPSEL -D__MIPSEL__ -march=mips32r2 -Wa,-mips32r2 -Wa,--trap -Iinclude/asm-mips/mach-tango3 -DEM86XX_CHIP=EM86XX_CHIPID_TANGO3 -DEM86XX_REVISION=3 -DCPU_REMAP_SPACE=0x4000000  -Iinclude/asm-mips/mach-generic    -c -o arch/mips/kernel/head.o arch/mips/kernel/head.S

加入-E参数来预处理宏展开和删除代码,生成head.o.s
mips-linux-gnu-gcc -Wp,-MD,arch/mips/kernel/.head.o.d  -nostdinc -isystem /vobs/ftp_dir/uploads/1.3k/smp2/mips-4.3/bin/../lib/gcc/mips-linux-gnu/4.3.2/include -D__KERNEL__ -Iinclude  -include include/linux/autoconf.h -D__ASSEMBLY__  -mabi=32 -G 0 -mno-abicalls -fno-pic -pipe -ffreestanding -EL -UMIPSEB -U_MIPSEB -U__MIPSEB -U__MIPSEB__ -UMIPSEL -U_MIPSEL -U__MIPSEL -U__MIPSEL__ -DMIPSEL -D_MIPSEL -D__MIPSEL -D__MIPSEL__ -march=mips32r2 -Wa,-mips32r2 -Wa,--trap -Iinclude/asm-mips/mach-tango3 -DEM86XX_CHIP=EM86XX_CHIPID_TANGO3 -DEM86XX_REVISION=3 -DCPU_REMAP_SPACE=0x4000000  -Iinclude/asm-mips/mach-generic    -E -c -o arch/mips/kernel/head.o.s arch/mips/kernel/head.S

luther@gliethttp:~$ vim arch/mips/kernel/head.o.s
.globl stext; stext: # used for profiling
.globl _stext; _stext:
# 173 "arch/mips/kernel/head.S"
 .section ".init.text","ax"

.globl kernel_entry; .align 2; .type kernel_entry,@function; .ent kernel_entry,0; kernel_entry: .frame $29, 16, $29 # kernel entry point

 kernel_entry_setup # cpu specific setup

 setup_c0_status_pri

 ARC64_TWIDDLE_PC
# 201 "arch/mips/kernel/head.S"
 la $8, __bss_start # clear .bss
 sw $0, ($8)
 la $9, __bss_stop - 4
1:
 addiu $8, 4
 sw $0, ($8)
 bne $8, $9, 1b

 sw $4, fw_arg0 # firmware arguments
 sw $5, fw_arg1
 sw $6, fw_arg2
 sw $7, fw_arg3

 mtc0 $0, $4 # clear context register
 la $28, init_thread_union
 li $29, 8192 - 32
 addu $29, $28
 set_saved_sp $29, $8, $9
 subu $29, 4 * 4 # init stack pointer

 j start_kernel  基本上仅仅将bss段清0之后,就跳转到start_kernel执行去了
 .end kernel_entry; .size kernel_entry,.-kernel_entry
# 257 "arch/mips/kernel/head.S"
 .previous


阅读(4150) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~