ref: f4ba2dfd7b806f4ddd2dd5dbba478aa33ebe0274
parent: ce5aa6c86476d8aab853cf7f18d75af5d2baf2fe
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Tue Sep 18 14:18:43 EDT 2012
6c: extern register fix (import from patch/6c-extreg) to make it easy to use normal libraries (such as libdraw, libsec, and libmp) with the kernel, which uses extern register, don't stray into the external register set when allocating values to registers.
--- a/amd64/include/u.h
+++ b/amd64/include/u.h
@@ -10,7 +10,7 @@
typedef unsigned long usize;
typedef ushort Rune;
typedef union FPdbleword FPdbleword;
-typedef uvlong jmp_buf[2];
+typedef uintptr jmp_buf[2];
#define JMPBUFSP 0
#define JMPBUFPC 1
#define JMPBUFDPC 0
--- a/sys/src/cmd/6c/reg.c
+++ b/sys/src/cmd/6c/reg.c
@@ -50,6 +50,8 @@
lastr = R;
nvar = 0;
regbits = RtoB(D_SP) | RtoB(D_AX) | RtoB(D_X0);
+ if(REGEXT)
+ regbits |= RtoB(REGEXT) | RtoB(REGEXT-1);
for(z=0; z<BITS; z++) {externs.b[z] = 0;
params.b[z] = 0;
--- a/sys/src/cmd/6c/txt.c
+++ b/sys/src/cmd/6c/txt.c
@@ -1,5 +1,7 @@
#include "gc.h"
+static int resvreg[nelem(reg)];
+
void
ginit(void)
{@@ -94,6 +96,7 @@
if(0)
com64init();
+ memset(reg, 0, sizeof(reg));
for(i=0; i<nelem(reg); i++) {reg[i] = 1;
if(i >= D_AX && i <= D_R15 && i != D_SP)
@@ -101,6 +104,10 @@
if(i >= D_X0 && i <= D_X7)
reg[i] = 0;
}
+ /* keep two external registers */
+ reg[REGEXT] = 1;
+ reg[REGEXT-1] = 1;
+ memmove(resvreg, reg, sizeof(resvreg));
}
void
@@ -111,10 +118,10 @@
reg[D_SP]--;
for(i=D_AX; i<=D_R15; i++)
- if(reg[i])
+ if(reg[i] && !resvreg[i])
diag(Z, "reg %R left allocated", i);
for(i=D_X0; i<=D_X7; i++)
- if(reg[i])
+ if(reg[i] && !resvreg[i])
diag(Z, "reg %R left allocated", i);
while(mnstring)
outstring("", 1L);@@ -179,7 +186,7 @@
n = 0;
for(i=D_AX; i<=D_R15; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
n++;
return n;
}
@@ -337,7 +344,7 @@
goto out;
}
for(i=D_AX; i<=D_R15; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
goto out;
diag(tn, "out of fixed registers");
goto err;
@@ -350,7 +357,7 @@
goto out;
}
for(i=D_X0; i<=D_X7; i++)
- if(reg[i] == 0)
+ if(reg[i] == 0 && !resvreg[i])
goto out;
diag(tn, "out of float registers");
goto out;
--- a/sys/src/cmd/6l/span.c
+++ b/sys/src/cmd/6l/span.c
@@ -668,6 +668,9 @@
rex &= (0x40 | Rxr);
v = a->offset;
+ if ((vlong)v != a->offset)
+ print("asmandsz: Trying to emit %#ullx and 32 bits is not sufficient\n",+ a->offset);
t = a->type;
if(a->index != D_NONE) { if(t >= D_INDIR) {--
⑨