flat assembler
Message board for the users of flat assembler.

Index > Main > ccall with 64bit?

Author
Thread Post new topic Reply to topic
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel
Using fasm with libc seems like a fantastic idea, and it certainly makes like a little bit easier.

However, ccall reverse pushd's the arguments onto the stack, and I'm unsure how this should be modified for 64 bit. I have tried using pushing qwords instead of dwords but then arg is the wrong size.

Thanks

Mat

_________________
Cogito Cogito Ergo Essum
Post 06 Dec 2011, 08:19
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
I haven't done any 64bit stuff before but have you tried looking at the stack in OllyDbg.

I just found something interesting though:

Quote:

Argument passing
I’m going to simplify the discussion here on purpose and focus on integer/pointer arguments [3]. According to the ABI, the first 6 integer or pointer arguments to a function are passed in registers. The first is placed in rdi, the second in rsi, the third in rdx, and then rcx, r8 and r9. Only the 7th argument and onwards are passed on the stack.


source:

http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/
Post 06 Dec 2011, 09:07
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Here's another important read too. I recommend you start with it.
http://msdn.microsoft.com/en-us/magazine/cc301708.aspx

I didn't know the IA-64 has 128 general purpose registers, lol
Post 06 Dec 2011, 09:15
View user's profile Send private message Reply with quote
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel
Ok, so I think the conclusion is that ccall is possibly not as much a good way to do it...

I have been looking at the disassembly from simple C code to try and figure it out, and I reached a similar conclusion to you first post: that registers are used, along a similar sort of theory to fastcall.

Thanks for the links. Will probably mean I rewrite all my procedures to use different registers so that they don't have to change them...
Post 06 Dec 2011, 09:28
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger Reply with quote
randall



Joined: 03 Dec 2011
Posts: 155
Location: Poland
randall
I highly recommend this paper http://agner.org/optimize/calling_conventions.pdf
There is everything you need to know about calling convention on any compiler and any OS.
Post 06 Dec 2011, 09:54
View user's profile Send private message Visit poster's website Reply with quote
MattDiesel



Joined: 31 Oct 2010
Posts: 34
Location: England
MattDiesel
Thanks randall. Makes for some nice bed time reading Razz

From first readings, I am particularly interested in the idea of shadow space on windows, and the red zone in linux.

I think the main problem is that I was hoping by linking to libc I'd be able to write good cross-platform asm. There seems to be many differences between windows and linux for 64 bit calls.

Of course it is perfectly possible for me to come up with my own calling convention Razz
Post 06 Dec 2011, 10:16
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Post 16 Dec 2011, 20:59
View user's profile Send private message Visit poster's website Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider
Post 17 Dec 2011, 04:26
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.