Open jkenda opened 1 month ago
Extending QBE to support the Windows ABI involves a deep understanding of the conventions used by the Windows operating system for application binaries. Here’s how you can start gathering the necessary information:
Microsoft Official Documentation: The primary source for authoritative information on the Windows ABI is Microsoft's official documentation. Microsoft provides detailed specifications about the calling conventions, register usage, stack organization, and exception handling mechanisms used in Windows applications. You can find this information on the Microsoft Docs website.
Windows Internals Books: The "Windows Internals" book series by Mark Russinovich, David Solomon, and Alex Ionescu offers comprehensive insights into the architecture and core internals of Windows, including aspects of the ABI. These books are valuable for understanding how Windows manages applications at a low level.
Community and Technical Articles: Various technical articles and blog posts discuss aspects of the Windows ABI, particularly those related to development in assembly language or system programming on Windows. Websites like CodeProject or personal blogs of system programmers often contain relevant discussions and examples.
Open Source Projects: Looking at open source projects that target Windows can also provide practical insights into how the Windows ABI is implemented in real-world scenarios. Projects such as Wine (which implements a compatibility layer for running Windows applications on Unix-like operating systems) or ReactOS (an open-source OS aiming to be binary-compatible with Windows) can be useful.
Technical Forums and Discussions: Forums such as Stack Overflow, MSDN forums, or even specialized mailing lists and IRC channels can be great places to ask specific questions about the Windows ABI and receive answers from experienced developers and system architects.
By combining information from these sources, you can gain a solid understanding of the Windows ABI and assess what modifications would be necessary to extend QBE to support it. This approach will involve both theoretical research and practical experimentation, especially when it comes to implementing and testing ABI compliance in your extended version of QBE.
To get started with understanding the Windows ABI, particularly for x86-64 architecture (which is the most commonly used today), here's a brief summary of the main conventions regarding registers for argument passing, return values, and some other ABI-specific details:
RCX
, RDX
, R8
, and R9
. Additional arguments are passed on the stack.XMM0
to XMM3
. Further floating-point arguments are passed on the stack.RAX
register for values that fit within the size of the register.XMM0
register.RAX
register.RAX
, RCX
, RDX
, R8
, R9
, R10
, R11
, and XMM0
-XMM5
are considered volatile and must be saved by the caller if they wish to preserve their values.RBX
, RBP
, RDI
, RSI
, R12
, R13
, R14
, R15
, and XMM6
-XMM15
must be saved and restored by the function if they are used.RSP
should be 16-byte aligned minus 8 bytes. This alignment ensures compatibility with the Microsoft calling convention and is necessary for performance reasons, especially for SIMD instructions.This overview covers the basic aspects of the Windows ABI for x86-64 architecture, which should help you get started on modifying QBE or any other project to support Windows. For a more comprehensive guide, you might want to consult Microsoft's official documentation, which provides detailed and authoritative information. You can find a thorough explanation of the calling convention here on Microsoft's official documentation. This resource is essential for anyone looking to implement or modify compiler backends to be compatible with Windows.
Extend QBE to target the Windows ABI in addition to System V.