You will find tut02,tut03,tut04,tut05,tut31 in 64 bits in the zip
The tut03 show the minimal rules to follow with 64 bits.
The tut31 is a listview control and the more complete on the subject
Take care that use of rdi register,even preserved in stack is not allowed.
See wndproc and use rdi instead r9 after preserved it and see what happen
Le tut21 is a pipe (run \masm32\bin\ml.exe)
VERBOTEN with JWASM,extract from Jwasm doc on "OPTION WIN64":
-------------------------------------------------------------------------------------------------------------------------
Warning: You should have understood exactly what this option does BEFORE you're using it. Using PUSH/POP instruction pairs to "save" values across an INVOKE is VERBOTEN if this option is on.
-------------------------------------------------------------------------------------------------------------------------
a complete comparison on the subject between ml64 and jwasm is here
http://masm32.com/board/index.php?topic=4536.msg48597#msg48597
Here a real trap,use of push:
Quote
start:
;fastcall need stack space before call
;one qword for return adress of call
;
add rsp,-(8 + 10 * 8) ; - (align + shadow space)
mov Saverdi,rdi ;save rdi en data
push rdi
mov rdi,200
invoke InitInstance,1
pop rdi
.if rdi != Saverdi ;wrong if an API function had been call by the proc
mov rdi,Saverdi
invoke MessageBox,NULL,addr errorrdi,addr Titre,MB_OK
.endif
invoke ExitProcess,0
InitInstance PROC FRAME init:DWORD
Local retour:QWORD
mov retour,1
.if init == 1
invoke GetModuleHandle,NULL
mov hInstance,rax
;--------------------------------------------------------------
invoke GetModuleFileName,hInstance,addr RelativePath,sizeof RelativePath
.endif
FindeInitInstance:
mov rax,retour
ret
InitInstance endp
hello, Yves!
Why 2-nd, 3-rd and 4-th lesson have a size of 14 Kbytes, and size of 5-th lesson is 5 Kbytes and size of 31-st lesson is 8.5 Kbytes? What is the reason reducing the size of the program, because they become more difficult? Clicking on the title in the 31 lesson is not sorted, and the second-clicking on the header of the first leads to a crash in program
Difference of size = debug or not debug
On which system have you a crash ? After compile ? or using the executable ?
it is ;
Quote
UpdatelParam proc FRAME
LOCAL lvi:LVITEM,CPT:QWORD
invoke RtlZeroMemory,addr lvi,sizeof lvi
invoke DebugBreak
invoke SendMessage,hList, LVM_GETITEMCOUNT,0,0
dec rax
mov CPT,rax
.if rax > 0
mov lvi.imask,LVIF_PARAM
LoopSetItem:
xor rax,rax
mov eax,lvi.iItem
mov lvi.lParam,rax ;defaut param
invoke SendMessage,hList, LVM_SETITEM,0,addr lvi
inc lvi.iItem
dec CPT
jnz LoopSetItem
.endif
ret
UpdatelParam endp
Who don't want to work.I have put it in comment on WM_NOTIFY message and all is OK
Hi, Yves!
see my version of the program
- Win x64 Tutorial #31a: ListView Control (http://masm32.com/board/index.php?topic=4190.msg46624#msg46624)
- Win x64 Tutorial #31b: ListView Control (http://masm32.com/board/index.php?topic=4190.msg46837#msg46837)
QuoteOn which system have you a crash ? After compile ? or using the executable ?
Win 7 pro x64, I used your executable file
Found the problem and corrected it in the first post (tut31).
Use of rdi ,even preserved,is not allowed in the wndproc (it is allowed in 32 bits).
I have replaced it by r9 (more simple) and all is ok.
QuoteUse of rdi ,even preserved,is not allowed in the wndproc
Yves,
use rdi, rsi, rbp, rbx and so on, check the functionality of applications, if this is not a blue screen of death, then proceed according to the rules,
Quoteif you want it, you can it
There is Nothing on the rules who say it is not allowed to use rdi rsi rbx as in 32 bits.
If you have a link who say that,put it here
I must refer to itself?(http://www.cyberforum.ru/images/smilies/ap.gif)
Too bad.I prefer rules writed in plain text .
- Everything You Need To Know To Start Programming 64-Bit Windows Systems (Matt Pietrek) (http://m.blog.csdn.net/blog/cosmoslife/17050801)
- X64 Unwind Information (Kevin Frei) (http://blogs.msdn.com/509372.aspx.)
- x64 Software Conventions (http://msdn.microsoft.com/en-us/library/7kcdt6fy.aspx)
Register | Status | Use |
RAX | Volatile | Return value register |
RCX | Volatile | First integer argument |
RDX | Volatile | Second integer argument |
R8 | Volatile | Third integer argument |
R9 | Volatile | Fourth integer argument |
R10:R11 | Volatile | Must be preserved as needed by caller; used in syscall/sysret instructions |
R12:R15 | Nonvolatile | Must be preserved by callee |
RDI | Nonvolatile | Must be preserved by callee |
RSI | Nonvolatile | Must be preserved by callee |
RBX | Nonvolatile | Must be preserved by callee |
RBP | Nonvolatile | May be used as a frame pointer; must be preserved by callee |
RSP | Nonvolatile | Stack pointer |
XMM0, YMM0 | Volatile | First FP argument; first vector-type argument when __vectorcall is used |
XMM1, YMM1 | Volatile | Second FP argument; second vector-type argument when __vectorcall is used |
XMM2, YMM2 | Volatile | Third FP argument; third vector-type argument when __vectorcall is used |
XMM3, YMM3 | Volatile | Fourth FP argument; fourth vector-type argument when __vectorcall is used |
XMM4, YMM4 | Volatile | Must be preserved as needed by caller; fifth vector-type argument when __vectorcall is used |
XMM5, YMM5 | Volatile | Must be preserved as needed by caller; sixth vector-type argument when __vectorcall is used |
XMM6:XMM15, YMM6:YMM15 | Nonvolatile (XMM), Volatile (upper half of YMM) | Must be preserved as needed by callee. YMM registers must be preserved as needed by caller. |
I know all of this page
Quote
RDI Nonvolatile Must be preserved by callee
incorrect assertion because miss:
you couldn't call another function even if rdi is preserved.
It is what happen in the tut31.(couldn't use rdi instead of r9 even if rdi is preserved).
You can also search agner site with it's pdf,nothing on the subject.
search more.
it can be also that the sendmessage 64 bit don't preserve and initialise correctly rdi (????).
added a a pipe,tut21.It run \masm32\bin\ml.exe
@TuteEnMasm,
You can use rdi like any other nonvolatile register, e.g. rsi. Unfortunately I can't (easily) make your examples since I don't have VC, sdk64, etc. So I can't check what's going on. However my guess is: in tute31 (before the fix) you're pushing / popping rdi to save it across invocation of SendMessage. However UpdatelParam, with FRAME, screws up the stack - you can't use push/pop to preserve across such invokes in JWasm (unfortunately as I said I can't check this). So if you push/pop rdi at each individual invocation of SendMessage (4 separate times) it would work, if this guess is correct.
Regardless, there's nothing special about rdi as you say, it can be used in WndProc same as rsi.
Of course your fix works so you can leave it at that, but should correct misunderstanding about rdi.
Wish I could check your code but 2 much trouble to get it to compile since my environment is so different
You are right,here is a sample:
After debugging,the push is destroy when a function is called Inside the proc
Did you find this NORMAL??????????
Quote
start:
;fastcall need stack space before call
;one qword for return adress of call
;
add rsp,-(8 + 10 * 8) ; - (align + shadow space)
mov Saverdi,rdi ;save rdi en data
push rdi
mov rdi,200
invoke InitInstance,1
pop rdi
.if rdi != Saverdi ;wrong if an API function had been call by the proc
mov rdi,Saverdi
invoke MessageBox,NULL,addr errorrdi,addr Titre,MB_OK
.endif
invoke ExitProcess,0
InitInstance PROC FRAME init:DWORD
Local retour:QWORD
mov retour,1
.if init == 1
invoke GetModuleHandle,NULL
mov hInstance,rax
;--------------------------------------------------------------
invoke GetModuleFileName,hInstance,addr RelativePath,sizeof RelativePath
.endif
FindeInitInstance:
mov rax,retour
ret
InitInstance endp
Hi, Yves!
store the value of registers in local variables how in my samples
Quote from: ToutEnMasmDid you find this NORMAL??????????
- These days, who's to say what's normal? See the JWasm forum for explanation. JWasm reserves (maximum) stack space once, at beginning of a proc, for all proc's called within; it's more efficient, but u have to be aware of it. You can enable / disable this feature by appropriate options. Interesting to note others have been bitten by this, u can see examples in the Laboratory; threads never did figure out what the problem was. In one, they decided there was "something wrong" with rbx, same as u decided "something wrong" with rdi
Anyway thanks for the tute examples. Mikl__ used no invokes, push his own args; you're using invoke's and all the latest JWasm features; so together you demonstrate full range of approaches (my 3rd approach, using nvk macro, could be considered in the middle)
The explain seem to be here :(VERBOTEN by JWASM)
http://masm32.com/board/index.php?topic=4536.msg48597#msg48597