Author Topic: 64 bit Coding HardCore Source Material  (Read 3032 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
64 bit Coding HardCore Source Material
« on: January 17, 2011, 08:48:18 PM »



x64
http://msdn.microsoft.com/en-us/magazine/cc300794.aspx
44bits 16 terabytes
4k page
handles and pointers are 8 byte

Overview of x64 Calling Conventions
http://msdn.microsoft.com/en-us/library/ms235286(VS.80).aspx
in visual c++
Registers
http://msdn.microsoft.com/en-us/library/9z1stfyw(v=VS.80).aspx
x64software conventions
http://msdn.microsoft.com/en-us/library/7kcdt6fy(v=VS.80).aspx
Parameter Passing
http://msdn.microsoft.com/en-us/library/zthk2dkh(VS.80).aspx
Stack Allocation
http://msdn.microsoft.com/en-US/library/ew5tede7(v=VS.80).aspx
Prolog Epilog
http://msdn.microsoft.com/en-us/library/tawsa7cb(v=VS.80).aspx


The x64 OS Architecture
http://www.codeproject.com/KB/system/64BitOSAndPortingIssues.aspx

Byte Bites
http://winprogger.com/?p=1436
Calling conventions
for different C++ compilers and operating systems
http://www.agner.org/optimize/calling_conventions.pdf

Code: [Select]
REGISTER USAGE
--------------

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       Volatile First FP argument
XMM1       Volatile Second FP argument
XMM2       Volatile Third FP argument
XMM3       Volatile Fourth FP argument
XMM4:XMM5  Volatile Must be preserved as needed by caller
XMM6:XMM15 Nonvolatile Must be preserved as needed by callee.



PROLOG EXAMPLES

mov    [RSP + 8], RCX
push   R15
push   R14
push   R13
sub      RSP, fixed-allocation-size
lea      R13, 128[RSP]
...


mov       [RSP + 8], RCX
push   R15
push   R14
push   R13
mov      RAX,  fixed-allocation-size
call   __chkstk
sub      RSP, RAX
lea      R13, 128[RSP]
...



EPILOG EXAMPLES

add      RSP, fixed-allocation-size
pop      R13
pop      R14
pop      R15
ret


lea      RSP, -128[R13]
; epilogue proper starts here
add      RSP, fixed-allocation-size
pop      R13
pop      R14
pop      R15
ret


lea      RSP, fixed-allocation-size – 128[R13]
pop      R13
pop      R14
pop      R15
ret



INTRINSICS
http://msdn.microsoft.com/en-us/library/26td21ds(v=VS.80).aspx




Datatype alignment.
'------------------
http://www.softwareverify.com/software-verify-blog/?p=376
http://msdn.microsoft.com/en-us/library/aa290049(VS.71).aspx

http://sciencezero.4hv.org/index.php?title=How_to_write_x64_assembly_functions_in_Visual_C%2B%2B

MSDN Articles
http://msdn.microsoft.com/en-us/visualc/aa336463.aspx

structure alignment
http://msdn.microsoft.com/en-us/library/71kf49f1.aspx
Parameter passing
http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx