Re: define_c_func/proc and 64-bit return types
- Posted by ghaberek (admin) Jul 30, 2012
- 1372 views
If you must know (which you must because it will help LOL), I'm wrapping Allegro 5.
Here's some relevant information:
// allegro5/color.h struct ALLEGRO_COLOR { float r, g, b, a; }; // allegro5/bitmap.h ALLEGRO_COLOR al_map_rgba(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Hmmm....how does this actually work with the compiler? What's the convention?
I made a quick program to call one of the offending functions and here is what I got back from objdump. I have no idea what I'm looking at since I haven't done Assembly coding in well over a decade. I've also been programming all weekend so my eyes are literally tied of reading all this code.
ALLEGRO_COLOR color = al_map_rgba( 255, 0, 255, 0 ); 401b59: 8d 5d d8 lea -0x28(%ebp),%ebx 401b5c: c7 44 24 10 00 00 00 movl $0x0,0x10(%esp) 401b63: 00 401b64: c7 44 24 0c ff 00 00 movl $0xff,0xc(%esp) 401b6b: 00 401b6c: c7 44 24 08 00 00 00 movl $0x0,0x8(%esp) 401b73: 00 401b74: c7 44 24 04 ff 00 00 movl $0xff,0x4(%esp) 401b7b: 00 401b7c: 89 1c 24 mov %ebx,(%esp) 401b7f: e8 94 f7 ff ff call 401318 <_al_map_rgba> 401b84: 50 push %eax 401b85: d9 45 dc flds -0x24(%ebp) 401b88: d9 45 e0 flds -0x20(%ebp) 401b8b: d9 45 e4 flds -0x1c(%ebp)
I agree with Jim. The shim is probably easier to deal with, though still a PITA. It might be easier, actually, to build the shim, then see if you can't rip out the machine code, poke it into memory and call it that way. That would alleviate the requirement of having to ship an extra, platform dependent binary.
Note, however, that Windows has defined its own 64-bit calling convention that is subtly different than what's specified by the AMD64 spec (or whatever it's properly called).
I really like the idea of writing a machine-code shim. It's fast, it's dangerous, it lives on the edge. Let's do it!
-Greg