flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [ARM] Regarding register preservation

Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 23 Feb 2016, 09:42
Hi,

I have a question regarding register preservation in ARM.

It says here ...

r0-r3 are the argument and scratch registers; r0-r1 are also the result registers
r4-r8 are callee-save registers
r9 might be a callee-save register or not (on some variants of AAPCS it is a special register)
r10-r11 are callee-save registers
r12-r15 are special register


My question is: what registers modified by Linux system calls ?

Is it safe to write (a generic approach for a hypothetical syscall with no return value) ...
Code:
stmfd   sp!, {r0-r3,r7,lr} 

ldmfd   sp!, {r0-r3,r7,pc}
    
Post 23 Feb 2016, 09:42
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 23 Feb 2016, 10:04
R9 is the ThumbEE register and I would consider it a callee-save register if you are not using ThumbEE

R12 is the intra-procedure call register and should be considered a scratch register for all other purposes.

R14 should also be considered a scratch register.

So, without actually checking Linux (hehe, so my advice is totally without any verification) you can probably expect {R0-R3,R12,R14} to be modified, and all others (except R15 of course) to be preserved.
Post 23 Feb 2016, 10:04
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 27 Feb 2016, 07:40
Thanks revolution. I'll keep an eye on those registers. I report back anything unusual.

To summarize:
r0 to r3, r12 and r14 will not be preserved.

It's probably best to save also the local registers r4 to r11, afterall is just an STM instruction.
Post 27 Feb 2016, 07:40
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 27 Feb 2016, 07:52
Picnic wrote:
It's probably best to save also the local registers r4 to r11, afterall is just an STM instruction.
Up to you. It will hurt performance if that is an issue for your code. I expect it is probably unnecessary though.
Post 27 Feb 2016, 07:52
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 15 Mar 2016, 15:41
I have a couple of questions more, sorry if they sound a bit foolish, i'm noob to Android stuff.

Using clone(), does every thread has its own registers copy, like in Windows? What is reasonable size for each child stack?

mmap allocates ram in 4KB pages, no less, what other options do i have? (memory must be shared between threads).
Post 15 Mar 2016, 15:41
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 15 Mar 2016, 16:23
I am assuming you are asking Linux questions?

If you are asking about the ARM architecture then 4kB pages is implementation dependant. The standard MMU implementation has a number of other page size options but whether or not Linux supports the other sizes up to the OS.

For threading there would be a requirement that each thread gets its own register copy. There is no way to share program registers and still have a sane multitasking system. Theoretically the OS can do whatever it pleases but having some registers shared is not something I'd ever expect to see in something like Linux.

The stack size for each thread is most likely taken from the ELF header, so you could set that to whatever you need.
Post 15 Mar 2016, 16:23
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1392
Location: Piraeus, Greece
Picnic 22 Mar 2016, 15:17
Thank you, helpful reply.
Post 22 Mar 2016, 15:17
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.