aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-18 00:37:03 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-01-18 00:37:03 +0100
commit7199cf6515f9545f345b37a402293fc13bbb5a47 (patch)
treec50561c34822d5dd0a593503400db008db187b51 /src
parentd66fdbe1963ad9561a336ec95e476e41381a2d91 (diff)
downloadnotes-7199cf6515f9545f345b37a402293fc13bbb5a47.tar.gz
notes-7199cf6515f9545f345b37a402293fc13bbb5a47.zip
x86_64: add initial windows abi notes
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86_64.md62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/arch/x86_64.md b/src/arch/x86_64.md
index 7e9008d..d752b09 100644
--- a/src/arch/x86_64.md
+++ b/src/arch/x86_64.md
@@ -180,7 +180,7 @@ rep stosb
rax 64 bit
rax+rdx 128 bit
```
-- Floating point return values:
+- Floating point return values
```markdown
reg size
-------------------
@@ -235,6 +235,64 @@ must must save these registers in case they are used.
```
> Equivalent to `leave` instruction.
+## [Windows x64 ABI][winabi]
+### Passing arguments to functions ([ref][winabi-args])
+> A single argument is never spread across multiple registers.
+- Integer/Pointer arguments
+ ```markdown
+ reg arg
+ -----------
+ rcx 1
+ rdx 2
+ r8 3
+ r9 4
+ ```
+- Floating point arguments
+ ```markdown
+ reg arg
+ -----------
+ xmm0 1
+ .. ..
+ xmm3 4
+ ```
+- Additional arguments are passed on the stack. Arguments are pushed
+ right-to-left (RTL), meaning next arguments are closer to current `rsp`.
+ [See example](https://godbolt.org/z/oT5Tjdf7Y).
+
+### Return values from functions
+- Integer/Pointer return values
+ ```markdown
+ reg size
+ -----------------
+ rax 64 bit
+ ```
+- Floating point return values
+ ```markdown
+ reg size
+ -------------------
+ xmm0 64 bit
+ ```
+
+### Caller saved registers
+Caller must save these registers if they should be preserved across function
+calls.
+- `rax`
+- `rcx`
+- `rdx`
+- `r8` - `r11`
+- `xmm0` - `xmm5`
+
+### Callee saved registers
+Caller can expect these registers to be preserved across function calls. Callee
+must must save these registers in case they are used.
+- `rbx`
+- `rbp`
+- `rdi`
+- `rsi`
+- `rsp`
+- `r12` - `r15`
+- `xmm6` - `xmm15`
+
## ASM skeleton
Small assembler skeleton, ready to use with following properties:
- use raw Linux syscalls (`man 2 syscall` for ABI)
@@ -289,6 +347,8 @@ Hi ASM-World!
[sysvabi]: https://www.uclibc.org/docs/psABI-x86_64.pdf
+[winabi]: https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions
+[winabi-args]: https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention
[amd64_vol1]: https://www.amd.com/system/files/TechDocs/24592.pdf
[amd64_vol2]: https://www.amd.com/system/files/TechDocs/24593.pdf
[amd64_vol3]: https://www.amd.com/system/files/TechDocs/24594.pdf