qbe/test/conaddr.ssa
Scott Graham d166a61141 Implementation of Windows amd64_win target
This is an implementation of the Windows ABI. It supports most features
(struct passing/returning, varargs, env). TLS is not yet supported.

This patch does not actually port QBE to Windows, it only allows QBE to
generate correct asm to target Windows. As a result, testing is
accomplished on a Linux host, by using a cross-compiling toolchain, and
running the resulting binaries by using wine. See:

	TARGET=amd64_win tools/test.sh all

A few cross-platform tests were changed from 'long' to 'long long' in
driver code because long in C does not match the size of a QBE 'l' on
Windows.
2026-02-12 09:17:17 +01:00

77 lines
1.2 KiB
Plaintext

# skip amd64_win (no signals on win32)
# test amd64 addressing modes
export
function w $f0(l %o) {
@start
%addr =l add $a, %o
%char =w loadub %addr
ret %char
}
export
function w $f1(l %o) {
@start
%o1 =l mul %o, 1
%addr =l add 10, %o1
%char =w loadub %addr
ret %char
}
export
function w $f2(l %o1, l %o2) {
@start
%o22 =l mul %o2, 2
%o =l add %o1, %o22
%addr =l add $a, %o
%char =w loadub %addr
ret %char
}
export
function l $f3(l %o) {
@start
%addr =l add %o, $a
ret %addr
}
export
function $f4() {
@start
storel $p, $p
ret
}
export
function $writeto0() {
@start
storel 0, 0
ret
}
# >>> driver
# #include <stdlib.h>
# #include <signal.h>
# char a[] = "qbe rocks";
# void *p;
# int ok;
# extern unsigned f0(long), f1(long), f2(long, long);
# extern char *f3(long);
# extern void f4(), writeto0();
# void h(int sig, siginfo_t *si, void *unused) {
# ok += si->si_addr == 0;
# exit(!(ok == 6));
# }
# int main() {
# struct sigaction sa = {.sa_flags=SA_SIGINFO, .sa_sigaction=h};
# sigemptyset(&sa.sa_mask); sigaction(SIGSEGV, &sa, 0);
# ok += f0(2) == 'e';
# ok += f1((long)a-5) == 'o';
# ok += f2(4, 2) == 's';
# ok += *f3(0) == 'q';
# f4();
# ok += p == &p;
# writeto0(); /* will segfault */
# }
# <<<