~boringcactus/crowbar-qbe

6d107542db5553ea66b180952e4509e4faa1fa42 — Melody Horn 3 years ago 5107b84
fix?? some pieces of win ABI
1 files changed, 17 insertions(+), 9 deletions(-)

M amd64/win.c
M amd64/win.c => amd64/win.c +17 -9
@@ 296,7 296,7 @@ selcall(Fn *fn, Ins *i0, Ins *i1, RAlloc **rap)
	AClass *ac, *a, aret;
	int ca, ni, ns, al, varc, envc;
	uint stk, off;
	Ref r, r1, r2, reg[2], env;
	Ref r, r1, reg[2], env;
	RAlloc *ra;

	env = R;


@@ 313,8 313,10 @@ selcall(Fn *fn, Ins *i0, Ins *i1, RAlloc **rap)
		if (a->inmem || a->asPointer) {
			if (a->align > 4)
				err("win abi requires alignments of 16 or less");
			if (a->asPointer && a->inmem)
				stk += 8;
			stk += a->size;
			if (a->align == 4)
			if (a->align == 4 || a->asPointer)
				stk += stk & 15;
		}
	stk += stk & 15;


@@ 367,12 369,10 @@ selcall(Fn *fn, Ins *i0, Ins *i1, RAlloc **rap)
	varc = i1->op == Ovacall;
	if (varc && envc)
		err("win abi does not support variadic env calls");
	ca |= (varc | envc) << 12;
	ca |= envc << 12;
	emit(Ocall, i1->cls, R, i1->arg[0], CALL(ca));
	if (envc)
		emit(Ocopy, Kl, TMP(RAX), env, R);
	if (varc)
		emit(Ocopy, Kw, TMP(RAX), getcon((ca >> 8) & 15, fn), R);

	ni = ns = 0;
	if (ra && aret.inmem)


@@ 381,7 381,9 @@ selcall(Fn *fn, Ins *i0, Ins *i1, RAlloc **rap)
		if (a->inmem)
			continue;
		r1 = rarg(a->cls[0], &ni, &ns);
		if (i->op == Oargc)
		if (a->asPointer)
			emit(Ocopy, a->cls[0], r1, i->arg[1], R);
		else if (i->op == Oargc)
			emit(Oload, a->cls[0], r1, i->arg[1], R);
		else
			emit(Ocopy, i->cls, r1, i->arg[0], R);


@@ 394,16 396,22 @@ selcall(Fn *fn, Ins *i0, Ins *i1, RAlloc **rap)
	for (i=i0, a=ac, off=32; i<i1; i++, a++) {
		if (!a->inmem)
			continue;
		if (i->op == Oargc) {
		if (i->op == Oargc && !a->asPointer) {
			if (a->align == 4)
				off += off & 15;
			blit(r, off, i->arg[1], a->size, fn);
		} else {
			r1 = newtmp("abi", Kl, fn);
			emit(Ostorel, 0, R, i->arg[0], r1);
			if (a->asPointer)
				emit(Ostorel, 0, R, i->arg[1], r1);
			else
				emit(Ostorel, 0, R, i->arg[0], r1);
			emit(Oadd, Kl, r1, r, getcon(off, fn));
		}
		off += a->size;
		if (a->asPointer)
			off += 8;
		else
			off += a->size;
	}
	emit(Osalloc, Kl, r, getcon(stk, fn), R);
}