VC 2005 64-bit Assembly
Park_7677
Missouri Member
In my adventures to compile PHP for Win64 I have come across some inline assembly code. Well VC 2005 does not support inline assembly with 64-bit compiling so it must be rewritten. I have no idea where to even begin with this part :confused2
It looks like this is it:
I've been looking online and it suggests moving the assembly code to a separate *.asm file and compile it along with the project. They might as well be speaking a foreign language :o
It's inside the IIS API module (php5isapi.dll). A person has emailed me about a POST issue with the PHP x64 and IIS which I think is caused by the CGI version (PHP-CGI.exe). If I can get the module to compile I think it would work out for him.
It looks like this is it:
_asm mov lpPage, esp;
I've been looking online and it suggests moving the assembly code to a separate *.asm file and compile it along with the project. They might as well be speaking a foreign language :o
It's inside the IIS API module (php5isapi.dll). A person has emailed me about a POST issue with the PHP x64 and IIS which I think is caused by the CGI version (PHP-CGI.exe). If I can get the module to compile I think it would work out for him.
0
Comments
I'll try your suggestion later because I've got class in a few.
Thanks lightnin!
http://msdn.microsoft.com/msdntv/transcripts/20040708VisualCTMTranscript.aspx
there's a little blurb about adding assembly files to a project for use. i'd highly suggest looking into the documentation for the ide to see exactly how to structure the project and add asm files to it, if it's anything like other MS IDEs it'll generate code for you, if you like that sort of thing. i have the feeling the project will only build properly in the vc++ environment if you play by it's rules.
on the other hand, have you tried cross-compiling on a different platform? maybe gcc on linux? you still can't use inline assembly, but the compiler itself might be a little more flexible (but i could be wrong, never used vc++ for comparison).
in any event, here's a decent doc on win64 assembly language:
http://www.codegurus.be/codegurus/Programming/assembler&win64_en.htm
and here's how to build assembly/c++ projects in visual c++ ide:
http://www.daniweb.com/techtalkforums/thread8072.html
one thing i learned about building projects for amd64 is that the code needs to build with relatively fewer errors than an x86 project. basically make the code compile as cleanly as possible and you'll see fewer glitches later on down the road, if at all possible.
--edit
that last link will likely be the most helpful for you
Since it's one line I know it can't be too hard but I'm just not seeing it. Is what I have below close to what it should be?
I assume I would create a function like below in the ASM file
I don't know how to pass the lpPage variable to the assembly code (note the ??? in mov). And I assume "esp" is something in assembly because it's not defined in the C code at all.
Thanks for tying to help me. I really appreciate it. I'm just going to have to keep looking and trying.
btw where did you get this code you are trying to compile?
File: php5isapi.c
Line: 883
What I am doing is trying to compile PHP for Windows x64 (here). No one has a distribution for it so that's what I'm trying to put together. Of the many projects inside PHP, this one I'm working on is ISAPI (the API module for Internet Information Services [IIS], Microsoft's Web server).
Again, thank you!
i can't find where the var esp is declared in this code, so i'm assuming that it's also a LPBYTE data type. you can give this a try.....
Release_TS\php5isapi.dll : fatal error LNK1120: 1 unresolved externals
Yes, but with an unfortunate side effect:
That's why an IIS 64-bit and PHP 64-bit combination would be highly preferable to most people. It's unfortunate that by trying to get the most out of a 64-bit server (IIS HTTP in this case) they will hurt themselves in the long run if they want to use PHP (previously only 32-bit).
lmao thank you, thank you....
ok i feel retarded now, after you jogged my memory now i remember that esp is a register... duuhhh.... great job on finding that rsp reference btw. i wouldnt have thought they'd change that, but i guess it makes sense 'r' standing for register perhaps?
anyways, could you post the asm file as well as the c code that you have now? i'd like to see what you've got so far. i'm guessing moveit is what you named the asm process?
I didn't know one line of code was going to be this troublesome. :sad2: At least I know that the CGI/FastCGI interface works with IIS so Win64 with IIS users are not left totally out in the cold on this one.
C source attached.
Don't feel obligated lightnin. You've helped me out a lot and I'm further than I would have been. IIS people still can use my PHPx64 so this isn't vital. Thank you
http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx
http://www.microsoft.com/whdc/devtools/debugging/install64bit.mspx
time to debug that sucker and see where your code is hanging up. now that you can get it to compile and begin some execution you should be able to see where it's hanging up at. there may be a problem somewhere else. but at least now you can see what to fix.
I was changing the Assembly code around trying to get it to work... and it did I copied the DLL and am trying to rebuild it to see if I get the same result.
Either way I'll have an ISAPI DLL for my next release. Now I just need to fix all the bugs in PHP
Thanks lightnin
EDIT:// I've tried rebuilding it several times and none of them work. I didn't change that much Assembly code between builds so I can't figure out why it built correctly once. I still have the working DLL so maybe I can pick it apart.
I rewrote the ASM file several times and I think my last time makes the most since. The original C code is just trying to get the location of the stack (esp/rsp) and store it in lpPage. So lpPage doesn't really need to be passed to the Assembly code, lpPage should instead equal what the Assembly code returns. I found out that eax/rax is the register used to return the value to C so I need to copy esp/rsp to eax/rax for returning to C.
movit_.asm
php5isapi.c
Does it work? I don't know really, but logically it makes since. I've been having trouble getting that DLL into the debugger you linked since it's not itself executable. I've tried to attach the debugger to IIS (the webserver which loads the DLL) but I still don't see my DLL listed.
Now on to the weird part. PHP is built with a makefile. This makefile builds everything: the core php dll, php executables, apache filters, mysql extensions, etc. It is also supposed to make the module I'm working on now (isapi). It does but the resulting DLL does not work. However, if you open the Visual C project for isapi in the IDE and build it from there after I ran the makefile to build everything else it builds correctly. I found this out by luck, but it works. Very odd.
Thanks lightnin! Looks like I got it working :thumbup
but i'm glad to hear you got it compiled, good job on the assembly.