搬迁组装 [英] Relocation in assembly

查看:204
本文介绍了搬迁组装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开机code的汇编语言编写的裸机ARM和我试图理解它是如何工作的。二进制是用一些外部闪光灯,并在启动时被复制自身的某些组件在RAM中。我仍然没有得到确切的搬迁概念在这种情况下,即使我读这维基百科进入。该RAM被映射到一个低地址窗口,并在高地址窗口闪光灯。为什么我们测试链接寄存器的值这里有人能解释一下吗?

  / *测试,如果我们从一个地址上运行,我们不会在*链接/
       BL check_position
 check_position:
        MOV R0,LR
        LDR R1,= check_position
        CMP R0,R1 / *;在调试期间不搬迁* /
        BEQ relocated_entry


解决方案

我的猜测是应用程序从RAM中运行,调试应用程序时,笔者也许是使用某种引导程序和或JTAG来直接加载测试程序进RAM,因此没有理由复制和运行(这可能导致崩溃)。

你会做这样的事的另一个原因是为了避免无限循环。例如,如果你想从闪存启动(必须通常)但是从RAM中执行,这样做最简单的方法是只复制整个闪存或闪存全一些大块的RAM和刚刚转移到RAM的开始。哪个当你这样做意味着你再次点击复制应用到ram和分支循环,以避免第二次(这可能会崩溃你),你有某种我正在运行从闪存或不测试这个循环。

I have a boot-up code for a bare-metal ARM written in assembly and I'm trying to understand how it works. The binary is written in some external Flash, and is copying parts of itself in RAM at boot-up. I still didn't exactly get the concept of relocation in this context, even though I read this wikipedia entry. The RAM is mapped to a low address window, and the flash in a high address window. Can someone explain to me why we test the value of the link register here?

/* Test if we are running from an address, we are not linked at */
       bl check_position
 check_position:
        mov     r0, lr                  
        ldr     r1, =check_position
        cmp     r0, r1                  /* ; don't relocate during debug */
        beq     relocated_entry 

解决方案

My guess is the application runs from ram, and when debugging the application this author is perhaps using some sort of bootloader and or jtag to load the test app directly into ram, thus no reason to copy and run (which could cause a crash).

Another reason you would do something like this is to avoid an infinite loop. If for example you want to boot from flash (have to usually) but execute from ram, the simplest way to do that is to just copy the whole flash or whole some chunk of flash to ram and just branch to the start of ram. Which when you do that means you hit the "copy the app to ram and branch" loop again, to avoid it the second time (which might crash you), you have some sort of am I running this loop from flash or not test.

这篇关于搬迁组装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆