ack/mach/vax4/cg/mach.c

288 lines
5.4 KiB
C
Raw Normal View History

1990-12-19 11:54:55 +00:00
#include <stb.h>
#ifndef lint
1994-06-24 14:02:31 +00:00
static char rcsid[] = "$Id$";
#endif /* lint */
1984-10-09 10:36:29 +00:00
/*
1987-03-10 01:26:51 +00:00
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
1984-10-09 10:36:29 +00:00
*
*/
/*
* Machine dependent back end routines for the VAX using 4-byte words
1984-10-09 10:36:29 +00:00
*/
/*
* Byte order: | 3 | 2 | 1 | 0 |
*/
2019-05-10 17:11:03 +00:00
void con_part(register int sz, word w)
{
/*
* Align new bytes on boundary of its on size.
*/
1984-10-09 10:36:29 +00:00
while (part_size % sz) part_size++;
if (part_size == TEM_WSIZE)
1984-10-09 10:36:29 +00:00
part_flush();
if (sz == 1 || sz == 2) {
/* Smaller than a machineword. */
w &= (sz == 1 ? 0xFF : 0xFFFF);
w <<= 8 * part_size;
part_word |= w;
} else {
assert(sz == 4);
part_word = w;
}
part_size += sz;
}
1984-10-09 10:36:29 +00:00
2019-05-10 17:11:03 +00:00
void con_mult(word sz)
{
1984-10-09 10:36:29 +00:00
if (sz != 4)
fatal("bad icon/ucon size");
1990-01-12 17:05:42 +00:00
fprintf(codefile,".data4\t%s\n",str);
1984-10-09 10:36:29 +00:00
}
1992-03-27 17:36:49 +00:00
#ifdef MACH_OPTIONS
static int gdb_flag = 0;
2019-05-10 17:11:03 +00:00
void mach_option(char *s)
1992-03-27 17:36:49 +00:00
{
if (! strcmp(s, "-gdb")) {
gdb_flag = 1;
}
else {
error("Unknown flag %s", s);
}
}
#endif /* MACH_OPTIONS */
2019-05-10 17:11:03 +00:00
void mes(word type)
{
1990-12-19 11:54:55 +00:00
int argt, a1, a2 ;
2019-05-10 17:11:03 +00:00
switch ( (int)type ) {
1990-12-19 11:54:55 +00:00
case ms_ext :
for (;;) {
switch ( argt=getarg(
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
case sp_cend :
return ;
default:
strarg(argt) ;
fprintf(codefile,".define %s\n",argstr) ;
break ;
}
}
case ms_stb:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
fputs(".symb \"\", ", codefile);
else {
fprintf(codefile, ".symb \"%s\", ", str);
argt = getarg(cst_ptyp);
}
a1 = argval;
argt = getarg(cst_ptyp);
a2 = argval;
argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
1992-03-27 17:36:49 +00:00
#ifdef MACH_OPTIONS
if (gdb_flag) {
if (a1 == N_PSYM) {
/* Change offset from AB into offset from
the frame pointer (ab).
*/
argval += 4;
}
1990-12-19 11:54:55 +00:00
}
#endif
fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
argt = getarg(end_ptyp);
break;
case ms_std:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
str[0] = '\0';
else {
argt = getarg(cst_ptyp);
}
swtxt();
1992-03-27 17:36:49 +00:00
if (argval == N_SLINE
#ifdef MACH_OPTIONS
&& ! gdb_flag
#endif
) {
1990-12-19 11:54:55 +00:00
fputs("calls $0,___u_LiB\n", codefile);
cleanregs(); /* debugger might change variables */
}
fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
argt = getarg(cst_ptyp);
fprintf(codefile, "%d\n", (int) argval);
argt = getarg(end_ptyp);
break;
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
1984-10-09 10:36:29 +00:00
}
1990-01-12 17:05:42 +00:00
#define PDPFLOAT
#define CODE_GENERATOR
#include <con_float>
1984-10-09 10:36:29 +00:00
#ifndef REGVARS
2019-05-10 17:11:03 +00:00
void prolog(full nlocals)
{
1990-01-12 17:05:42 +00:00
fprintf(codefile,".data2 00\n");
1984-10-09 10:36:29 +00:00
if (nlocals == 0)
return;
if (nlocals == 4)
fprintf(codefile,"\tclrl\t-(sp)\n");
else if (nlocals == 8)
fprintf(codefile,"\tclrq\t-(sp)\n");
else
fprintf(codefile,"\tsubl2\t$%ld,sp\n",nlocals);
}
#endif /* not REGVARS */
1984-10-09 10:36:29 +00:00
char *segname[] = {
1990-01-12 17:05:42 +00:00
".sect .text", /* SEGTXT */
".sect .data", /* SEGCON */
".sect .rom", /* SEGROM */
".sect .bss" /* SEGBSS */
1984-10-09 10:36:29 +00:00
};
#ifdef REGVARS
static full nlocals; /* Number of local variables. */
1984-10-09 10:36:29 +00:00
#define NR_REG 8 /* Number of registers. */
#define FIRST_REG 4
#define LAST_REG (FIRST_REG + NR_REG - 1)
/*
* Save number of locals.
*/
2019-05-10 17:11:03 +00:00
void prolog(full n)
{
1984-10-09 10:36:29 +00:00
nlocals = n;
}
/*
* Structure to store information about the registers to be stored.
*/
static struct s_reg {
char *sr_str; /* Name of register used. */
long sr_off; /* Offset from LB. */
int sr_size; /* Size in bytes. */
1984-10-09 10:36:29 +00:00
} a_reg[NR_REG + 1], *p_reg;
/*
* Initialize saving of registers.
*/
2019-05-10 17:11:03 +00:00
void i_regsave(void)
{
1984-10-09 10:36:29 +00:00
p_reg = a_reg;
}
/*
* Called for each register to be saved.
* Save the parameters in the struct.
*/
2019-05-10 17:11:03 +00:00
void regsave(char *str, long off, int size)
{
1984-10-09 10:36:29 +00:00
p_reg->sr_str = str;
p_reg->sr_off = off;
(p_reg++)->sr_size = size;
fprintf(codefile,
1990-01-12 17:05:42 +00:00
"\t! Local %ld, size %d, to register %s\n",
1984-10-09 10:36:29 +00:00
off, size, str
);
1984-10-09 10:36:29 +00:00
}
/*
* Generate code to save the registers.
*/
2019-05-10 17:11:03 +00:00
void f_regsave(void)
{
register struct s_reg *p;
1984-10-09 10:36:29 +00:00
register int mask;
register int i;
register int count;
mask = 0;
count = p_reg - a_reg;
/*
* For each register to be saved, set a bit in the
* mask corresponding to its number.
*/
1984-10-09 10:36:29 +00:00
for (p = a_reg; p < p_reg; p++) {
i = atoi(p->sr_str + 1);
if (p->sr_size <= 4)
mask |= (1 << i);
else {
mask |= (3 << i);
count++;
}
}
/*
* Now generate code to save registers.
*/
1990-01-12 17:05:42 +00:00
fprintf(codefile, ".data2 0%o\n", mask);
/*
* Emit code to initialize parameters in registers.
*/
for (p = a_reg; p < p_reg; p++)
if (p->sr_off >= 0)
fprintf(codefile,
1985-01-21 12:14:59 +00:00
"mov%c\t%ld(ap), %s\n",
p->sr_size == 4 ? 'l' : 'q',
p->sr_off,
p->sr_str
);
/*
* Generate room for locals.
1984-10-09 10:36:29 +00:00
*/
if (nlocals == 0)
return;
if (nlocals == 4)
fprintf(codefile,"clrl\t-(sp)\n");
else if (nlocals == 8)
fprintf(codefile,"clrq\t-(sp)\n");
else
fprintf(codefile,"subl2\t$%ld,sp\n",nlocals);
}
1984-10-09 10:36:29 +00:00
regreturn() { }
1984-10-09 10:36:29 +00:00
2019-05-10 17:11:03 +00:00
int regscore(long off, int size, int typ, int score, int totyp)
{
register int i = score;
1984-10-09 10:36:29 +00:00
/*
* If the offset doesn't fit in a byte, word-offset is used,
1984-10-09 10:36:29 +00:00
* which is one byte more expensive.
*/
if (off > 127 || off < -128) i *= 2;
/*
* Compute cost of initialization for parameters.
1984-10-09 10:36:29 +00:00
*/
if (off > 127) i -= 5;
else if (off >= 0) i -= 4;
/*
* Storing a pointer in a register sometimes saves an instruction.
1984-10-09 10:36:29 +00:00
*/
if (typ == reg_pointer) i += score;
else if (typ == reg_loop) i += 5;
/*
* Now adjust for the saving of the register.
* But this costs no space at all.
*/
return i - 1;
}
1984-10-09 10:36:29 +00:00
#endif /* REGVARS */