u-boot-2014.10移植第6天----深入分析代码(一)

硬件平台:tq2440

开发环境:Ubuntu-3.11

u-boot版本:2014.10

本文允许转载,请注明出处:http://blog.csdn.net/fulinus

前面我们看到了一个lds文件,我们这里深入的了解一下:

section.c:

/*
 * Copyright: (C) 2014 EAST fulinux <[email protected]>
 */
#include <stdio.h>
#include <stdlib.h>

int localmemory0 __attribute__((section("LOCALmem"))) = 0;
int localmemory1 __attribute__((section("LOCALmem"))) = 0;
int globalmemory __attribute__((section("GLOBALmem"))) = 0;

int main (int argc, char *argv[])
{
    localmemory0 = 0x456;
    localmemory1 = 0x123;

    globalmemory = localmemory0 + localmemory1;

    return 0;
}

$ gcc -c -o section.o section.c
$ objdump -d section.o 

section.o:     文件格式 elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   89 7d fc                mov    %edi,-0x4(%rbp)
   7:   48 89 75 f0             mov    %rsi,-0x10(%rbp)
   b:   c7 05 00 00 00 00 56    movl   $0x456,0x0(%rip)        # 15 <main+0x15>
  12:   04 00 00
  15:   c7 05 00 00 00 00 23    movl   $0x123,0x0(%rip)        # 1f <main+0x1f>
  1c:   01 00 00
  1f:   8b 15 00 00 00 00       mov    0x0(%rip),%edx        # 25 <main+0x25>
  25:   8b 05 00 00 00 00       mov    0x0(%rip),%eax        # 2b <main+0x2b>
  2b:   01 d0                   add    %edx,%eax
  2d:   89 05 00 00 00 00       mov    %eax,0x0(%rip)        # 33 <main+0x33>
  33:   b8 00 00 00 00          mov    $0x0,%eax
  38:   5d                      pop    %rbp
  39:   c3                      retq 

section.lds:

SECTIONS
{
    .text :
    {
        *(.text)
    }
    LOCALmem 0x1f0000 :
    {
        *(LOCALmem)
    }
    GLOBALmem 0xff0000 :
    {
        *(GLOBALmem)
    }
}

$ ld -o section.elf -T section.lds section.o

$ objdump -S section.elf 
section.elf:     文件格式 elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   89 7d fc                mov    %edi,-0x4(%rbp)
   7:   48 89 75 f0             mov    %rsi,-0x10(%rbp)
   b:   c7 05 eb ff 1e 00 56    movl   $0x456,0x1effeb(%rip)        # 1f0000 <localmemory0>
  12:   04 00 00
  15:   c7 05 e5 ff 1e 00 23    movl   $0x123,0x1effe5(%rip)        # 1f0004 <localmemory1>
  1c:   01 00 00
  1f:   8b 15 db ff 1e 00       mov    0x1effdb(%rip),%edx        # 1f0000 <localmemory0>
  25:   8b 05 d9 ff 1e 00       mov    0x1effd9(%rip),%eax        # 1f0004 <localmemory1>
  2b:   01 d0                   add    %edx,%eax
  2d:   89 05 cd ff fe 00       mov    %eax,0xfeffcd(%rip)        # ff0000 <globalmemory>
  33:   b8 00 00 00 00          mov    $0x0,%eax
  38:   5d                      pop    %rbp
  39:   c3                      retq
[[email protected] jupiter]$ 

时间: 2024-08-19 23:41:40

u-boot-2014.10移植第6天----深入分析代码(一)的相关文章

u-boot-2014.10移植第9天----深入分析代码(四)

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus ENTRY(_main) /* * Set up initial C runtime environment and call board_init_f(0). */ #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK) //在smdk2410开发板的相

u-boot-2014.10移植第8天----深入分析代码(三)

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus 接着第七天的代码分析,下面是cpu_init_crit的代码段,同样位于文件arch/arm/cpu/arm920t/start.S中: /* ************************************************************************* * * CPU_init_cri

u-boot-2014.10移植第11天----深入分析代码(六)

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus "从relocate_code回到_main中,接下来是main最后一段代码"也就是arch/arm/lib/crt0.S文件中: b   relocate_codehere://从这里开始u-boot已经在重定位的地方运行了 /* Set up final (full) environment */ bl  c

u-boot-2014.10移植第12天----深入分析代码(七)

c_runtime_cpu_setup函数在arch/arm/cpu/arm920t/start.S文件中: .globl  c_runtime_cpu_setupc_runtime_cpu_setup:  mov pc, lr //没做什么就返回了 回到arch/arm/lib/crt0.S文件中: bl  c_runtime_cpu_setup /* we still call old routine here */ //bss段清零    ldr r0, =__bss_start    /

u-boot-2014.10移植第7天----深入代码分析(二)

现在从代码的角度来分析启动的流程: 从u-boot.lds文件知: ENTRY(_start) SECTIONS { . = 0x00000000; . = ALIGN(4); .text : { *(.__image_copy_start) *(.vectors) CPUDIR/start.o (.text*) *(.text*) } 文件中__image_copy_start位映像文件复制起始地址,它在文件arch/arm/lib/sections.c中如下定义: char __image_

u-boot-2014.10移植第29天----nand flash的SPL启动(一)

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus 前面在移植nand flash启动时做了很多探索性的工作,但是后来发现在relocate.S文件中调用的函数中有调用大部分的库函数,牵扯到的文件较多,很难将它们一一包含到前面4K空间中去.正在想其他方法时,突然意识到SPL功能.我初步了解了一下SPL的功能,简而言之是一个将u-boot从nand flash拷贝到SDRAM

u-boot-2014.10移植第21天----添加nand flash命令支持(三)

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus 虽说nand flash读写操作是可以了,但是我使用nand markbad命令将一个块标记为坏块时,再用nand scrub命令恢复出厂设置时,却出现了下面的错误: nand0: MTD Erase failure: -5 说明我们的nand flash移植是不完全正确的. 下面查找原因 在文件drivers/mtd/n

u-boot-2014.10移植第14天----在SDRAM中运行

昨天遇到编译错误,我们从错误提示中寻找解决方法: 信息1:CHK     include/config.h /* Automatically generated - do not edit */ #define CONFIG_BOARDDIR board/samsung/tq2440 #include <config_defaults.h> #include <configs/tq2440.h> #include <asm/config.h> #include <

u-boot-2014.10移植第3天----LED裸机程序

硬件平台:tq2440 开发环境:Ubuntu-3.11 u-boot版本:2014.10 本文允许转载,请注明出处:http://blog.csdn.net/fulinus 在移植u-boot之前我们先熟悉一下硬件,以及如何控制硬件: 情况一: 这个情况是你的开发板中有了可以运行的u-boot.因为裸机程序能运行的前提条件是系统初始化了. 下面led.S是一位高人写的代码,完全是用ARM汇编编写的,短小精悍,主要是实现跑马灯的功能: /*****************************