程序寄存器的初始状态和堆栈Linux上的ARM [英] Initial state of program registers and stack on Linux ARM

查看:186
本文介绍了程序寄存器的初始状态和堆栈Linux上的ARM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在与ARM汇编玩Linux作为一个学习的过程。我使用的是'裸'组装,即,没有libcrt或libgcc中。任何人都可以点我有关的信息什么状态堆栈指针和其他寄存器将在程序的第一个指令之前开始时叫什么名字?显然,PC / R15点_start,其余的似乎被初始化为0,但有两个例外; SP / R13分,远远超出我的程序的地址,r1指向一个稍高的地址。

I'm currently playing with ARM assembly on Linux as a learning exercise. I'm using 'bare' assembly, i.e. no libcrt or libgcc. Can anybody point me to information about what state the stack-pointer and other registers will at the start of the program before the first instruction is called? Obviously pc/r15 points at _start, and the rest appear to be initialised to 0, with two exceptions; sp/r13 points to an address far outside my program, and r1 points to a slightly higher address.

因此​​,要扎实一些问题:

So to some solid questions:


  • 什么是R1的价值?

  • 是一个合法的堆栈由内核分配的SP值?

  • 如果没有,什么是分配堆栈的preferred方法;使用BRK或分配一个静态.bss段?

任何指针将AP preciated。

Any pointers would be appreciated.

推荐答案

下面是我用它来获得一个Linux / ARM程序开始与我的编译器:

Here's what I use to get a Linux/ARM program started with my compiler:

/** The initial entry point.
 */
asm(
"       .text\n"
"       .globl  _start\n"
"       .align  2\n"
"_start:\n"
"       sub     lr, lr, lr\n"           // Clear the link register.
"       ldr     r0, [sp]\n"             // Get argc...
"       add     r1, sp, #4\n"           // ... and argv ...
"       add     r2, r1, r0, LSL #2\n"   // ... and compute environ.
"       bl      _estart\n"              // Let's go!
"       b       .\n"                    // Never gets here.
"       .size   _start, .-_start\n"
);

正如你所看到的,我刚拿到ARGC,ARGV和ENVIRON从堆栈的东西在[SP]。

As you can see, I just get the argc, argv, and environ stuff from the stack at [sp].

一个小澄清:堆栈指针指向进程的内存中的有效区域。 R0,R1,R2和R3是前三个参数的函数被调用。我填充他们的argc,argv的,和ENVIRON,分别为。

A little clarification: The stack pointer points to a valid area in the process' memory. r0, r1, r2, and r3 are the first three parameters to the function being called. I populate them with argc, argv, and environ, respectively.

这篇关于程序寄存器的初始状态和堆栈Linux上的ARM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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