flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > [Arm] Has the Linux interface spec changed?

Author
Thread Post new topic Reply to topic
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 12:29
Hi all, it's my first post here and I hope it's in the right place.
As regards writing ELF code for the ARM, I was under the impression that to
use Linux System calls, one populates the first 6 parameters (if all applicable)
in regs R1 to R6 then the call number in R7 then followed by a SWI 0.
However I see with FasmArm this is different (printing hello world example)

Code:
 ; All the format stuff etc I've left out for this example.

mov r0,0  ; I thought the handle for STDOUT was 1 not 0
add r1,pc,hello-$-8  ; OK understand
mov r2,hello-len ; OK understand
swi 0x900004 ; why not swi 0, is it because the call table lives at 0x900000?
    

Can anyone elaborate as I'm now confused.
Thanks.
Post 02 Jun 2012, 12:29
View user's profile Send private message 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 02 Jun 2012, 12:33
The example you show was tested using an older version of Linux used on the Gumstix SOM by one of the users here. It is entirely possible that the call structure has changed in later versions of Linux.

If you have an example that is updated to run on the current Linux version then please feel free to post it here.
Post 02 Jun 2012, 12:33
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 12:36
Hi revolution
The example I used is straight from the examples of FasmARM ver 1.26
Post 02 Jun 2012, 12:36
View user's profile Send private message 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 02 Jun 2012, 12:38
I don't have an updated example for current Linux versions. If you know that the interface has been changed then you are welcome to submit an update.
Post 02 Jun 2012, 12:38
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 12:40
I don't know if it has been changed, I'm just trying to confirm if it will
work as I don't have an ARM based machine running Linux at my disposal.
Post 02 Jun 2012, 12:40
View user's profile Send private message 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 02 Jun 2012, 12:41
AnewUser wrote:
... I don't have an ARM based machine running Linux at my disposal.
Me either.

AFAIK it was working previously. But I can't verify if it still works, or if it did work.
Post 02 Jun 2012, 12:41
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 12:44
No problem, thanks.
You mentioned that the example was from Gumstix SOM, any idea
what kernel version it was using?

From what I can gather, the system calls are pretty standard across kernel
version.
I'm just intrigued by the 0 instead of a 1 for STDOUT.
As regards the swi 0x900004, it can very well be as with ARM, it boots to
0x0 then the bootloader starts to populate any kernel parameters from 0x100
and the actual kernel starting at 0x8000, so it could well be that the
system call vector table starts at 0x900000 and since sys_write is the fouth call
it stands to reason it would be at 0x900004.


Last edited by AnewUser on 02 Jun 2012, 12:51; edited 1 time in total
Post 02 Jun 2012, 12:44
View user's profile Send private message 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 02 Jun 2012, 12:48
Post 02 Jun 2012, 12:48
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 02 Jun 2012, 12:54
AnewUser wrote:
... so it could well be that the
system call vector table starts at 0x900000 and since sys_write is the fouth call
it stands to reason it would be at 0x900004.
SWI does not work that way. The number is arbitrary and is for software use only. It doesn't affect any hardware call destination.
Post 02 Jun 2012, 12:54
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 13:01
Interesting, are you then saying that swi 800004 would achieve the same result?
Or have I missed something?
Post 02 Jun 2012, 13:01
View user's profile Send private message 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 02 Jun 2012, 13:03
AnewUser wrote:
Interesting, are you then saying that swi 800004 would achieve the same result?
Or have I missed something?
You have to match the numbers with what the kernel is expecting. The hardware call destination won't change, but it is possible that the Linux kernel has changed over time to use a different numbering scheme.
Post 02 Jun 2012, 13:03
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 13:15
OK, I think the confusion may be coming from us using different terminology.
The addresses and offsets I refered to are software addresses as we are
"talking" to the OS kernel and not a peripheral.
Not trying to be argumentative, just trying to clear my beginners confusion.
Post 02 Jun 2012, 13:15
View user's profile Send private message 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 02 Jun 2012, 13:50
It is up to the kernel if it wants to jump directly to the SWI parameter passed by the user. Although, to me that would seem like an extremely bad idea. More likely it will have some sort of lookup table to decide what to do. Anyhow, I suppose the Linux source code will give the ultimate answer to your question.
Post 02 Jun 2012, 13:50
View user's profile Send private message Visit poster's website Reply with quote
AnewUser



Joined: 02 Jun 2012
Posts: 7
AnewUser 02 Jun 2012, 14:08
I agree.
I'm going to load QEMU on my PC and get a Linux ARM distro running on it
then compile one of the armelf examples that came with FasmARM and see
what the result is.
Thanks for your input.
Post 02 Jun 2012, 14:08
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 44
cwpjr 03 Jul 2012, 06:14
Post your travels if you would!
Post 03 Jul 2012, 06:14
View user's profile Send private message 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.