开发者

How to get saved registers of a process in Linux (ARM Architecture)

开发者 https://www.devze.com 2023-03-21 02:25 出处:网络
I\'m writing a program that parses all tasks running on linux, starting from init_task for each task i read it\'s task_struct structure which allows me to get it\'s PID, State, Oncpu..

I'm writing a program that parses all tasks running on linux, starting from init_task for each task i read it's task_struct structure which allows me to get it's PID, State, Oncpu..

However i also need to find the saved registers of that task, especially registers R0 to R10, IP, SP, FP and PC

Also in task_struct I found a pointer to a structure called cpu_context which holds registers R4 to PC

So the problem is that I don't know how to get registers R0 to R3 I tried to manually parse the stack of the task but i haven't found any relevant values

so here are my questions:

-where in the stack(or in an other location in memory) are saved the registers of a task that is not running?

-Can I trust the values of the registers R4 to PC found in the structure cpu_context?

I'm using a board containing开发者_开发问答 an ARM Cortex A9 MPCore processor(2 cores), linked with the host PC with a JTAG Link

Linux Kernel 2.6.35.7+ is running on the board(of course this kernel was compiled for the ARM architecture)

On the Host PC i'm using OPENOCD and GDB for the debug.

Thanks


It depends on which set of registers you are interested in.

If you are interested in the user mode state, take a look on how ptrace does it. From a quick peek at the source code, task_pt_regs(task) is where you should look. Apparently, they are near the top of the kernel stack for the task (take a look at vector_swi for instance; it has a stmia sp, {r0 - r12} near its beginning, followed by a store of sp and lr).

If you are interested in the kernel mode state, it is saved by __switch_to into task->cpu_context (TI_CPU_SAVE is the offset of cpu_context within the struct thread_info). As another answer already noted, it doesn't save r0-r3 because it doesn't have to; the caller of switch_to assumes they will be clobbered by __switch_to, so their values don't matter.


cpu_context contains the value of registers when __switch_to is called, caller saved registers are not stored.

If you want the value of registers upon entry to an interrupt or system call you need to look elsewhere.

0

精彩评论

暂无评论...
验证码 换一张
取 消