The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: TouEnMasm on September 11, 2015, 11:14:13 PM

Title: creating a prologue/epilogue for jwasm 64
Post by: TouEnMasm on September 11, 2015, 11:14:13 PM
Hello,
I try to create it and i have already the start point (arguments parameters).
I do it following this:
https://msdn.microsoft.com/en-us/library/ew5tede7.aspx
The problem is that jwasm don't follow the same rules.
The frame pointeur doesn't point at the same frame pointer than c++.
:dazzled:


.NOLIST
      .686P   
.XMM
.MMX

   .x64                ; -pe requires to set cpu, model & language
   .model flat, fastcall

option casemap : none
option win64 : 3;,7,11
option frame : auto
option stackbase : rsp


VISU MACRO chaine,valeur
%ECHO chaine valeur
ENDM

Prologue64 MACRO procname, flags, parambytes, localbytes, reglist, userparms
local Pointprologue
;start of prologue rsp point the return adress (mov r10,rsp:jmp rsp)
;in increasing order for  rsp adress,we find
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Stack parameter Area if Number of arguments > 4 ;number of bytes
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; R9  save place if needed
; R8  save place if needed ;size 20h
; rdx save place if needed
; rcx save place if needed
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;********** return adress ;rsp point here at the start of the prologue,rsp = rsp -8 after push ****** 
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;
ECHO aPROLOGUE
;save rcx,rdx,r8,r9 and made them accessible by there name
mov [rsp+8],rcx
mov [rsp+16],rdx
mov [rsp+24],r8
mov [rsp+32],r9
mov rax,0
distanceRsp=20h ; shadow space ??? 4*8 jwasm need

VISU distance,%distanceRsp
sub rsp,distanceRsp

EXITM <Pointprologue>
ENDM


Title: Re: creating a prologue/epilogue for jwasm 64
Post by: habran on September 12, 2015, 05:54:52 AM
use: option win64 : 11
Title: Re: creating a prologue/epilogue for jwasm 64
Post by: TouEnMasm on September 13, 2015, 12:15:14 AM
No change using this option

I use a test proc with and whithout prologue,and get Strange result:

OPTION PROLOGUE:NONE ;
OPTION EPILOGUE:Epilogue64 ;Epilogue64 ;rbpFrameEpilogue ;StdEpilogue
.LISTALL
aTestProc PROC uses rax hwnd:HWND,uMsg:UINT,wParam: WPARAM,lParam:LPARAM,pilearg:QWORD
LOCAL retour:QWORD ,child:HWND,Hfen:HWND,rien :QWORD
invoke DebugBreak
;push rax     ;rsp +8
;pop rax      ;rsp -8
sub r10,rsp
mov rax,hwnd  ;rsp+48h     ;+28h ori-- --------             rsp + 48h
mov rax,wParam ;rsp +58h   ;+38h ori-- --------                58h
mov rax,pilearg    ;-------------------                   68h
mov retour,90h    ;---------  ---------                  20h
mov rax,rien    ;-------------------                   38h

ret
aTestProc endp
.NOLIST
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef



Prologue64 MACRO procname, flags, parambytes, localbytes, reglist, userparms:VARARG

EXITM <>
ENDM

OPTION PROLOGUE:Prologue64 ;
OPTION EPILOGUE:Epilogue64 ;Epilogue64 ;rbpFrameEpilogue ;StdEpilogue
.LISTALL
aTestProc PROC uses rax hwnd:HWND,uMsg:UINT,wParam: WPARAM,lParam:LPARAM,pilearg:QWORD
LOCAL retour:QWORD ,child:HWND,Hfen:HWND,rien :QWORD
invoke DebugBreak
;push rax     ;rsp +8
;pop rax      ;rsp -8
sub r10,rsp
mov rax,hwnd  ;rsp+48h     ;+28h ori-- --------                           rsp + 48h
mov rax,wParam ;rsp +58h   ;+38h ori-- --------                         58h *********
mov rax,pilearg    ;-------------------                   68h
mov retour,90h    ;---------  ---------                  40h
mov rax,rien    ;-------------------                   58h ******** error ******

ret
aTestProc endp
.NOLIST
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef



seems to be modifies by the EXITM return value EXITM <20h>
Perhaps a little explain
Title: Re: creating a prologue/epilogue for jwasm 64
Post by: TouEnMasm on September 14, 2015, 05:34:16 AM

No answer ?
Also I made it myself .
The EXITM must return <32h> to made rsp point on the first local [rsp +0]
This don't reserve stack space for the next call or invoke,It's for that there is a crash.
Soluce is to add a big first local to allocate space for the next call.

LOCAL NEXTCALL[50h]:QWORD


And----- exit bug