ack/mach/pdp/cg/mach.c

210 lines
4 KiB
C
Raw Permalink Normal View History

1984-05-19 12:48:59 +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-05-19 12:48:59 +00:00
*
* Author: Hans van Staveren
*/
/*
* machine dependent back end routines for the PDP-11
*/
2019-05-10 17:10:47 +00:00
/* #define REGPATCH */ /* save all registers in markblock */
1984-05-19 12:48:59 +00:00
2019-05-10 17:10:47 +00:00
void con_part(register int sz, word w)
{
1984-05-19 12:48:59 +00:00
while (part_size % sz)
part_size++;
1984-10-23 15:02:03 +00:00
if (part_size == TEM_WSIZE)
1984-05-19 12:48:59 +00:00
part_flush();
if (sz == 1) {
w &= 0xFF;
if (part_size)
w <<= 8;
part_word |= w;
} else {
assert(sz == 2);
part_word = w;
}
part_size += sz;
}
2019-05-10 17:10:47 +00:00
void con_mult(word sz) {
long l;
1984-05-19 12:48:59 +00:00
if (sz != 4)
fatal("bad icon/ucon size");
1988-04-25 10:31:33 +00:00
l = atol(str);
#ifdef ACK_ASS
1988-07-07 14:31:29 +00:00
fprintf(codefile,".data2 0%o, 0%o !%s\n",(int)(l>>16),(int)l, str);
#else
1984-05-19 12:48:59 +00:00
fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
#endif
1984-05-19 12:48:59 +00:00
}
1989-10-04 10:28:50 +00:00
#define PDPFLOAT
1989-10-26 11:07:26 +00:00
#define FL_MSL_AT_LOW_ADDRESS 1
#define FL_MSW_AT_LOW_ADDRESS 1
#define FL_MSB_AT_LOW_ADDRESS 0
#define CODE_GENERATOR
1989-10-04 10:28:50 +00:00
#include <con_float>
1984-05-19 12:48:59 +00:00
#ifdef REGVARS
char Rstring[10];
full lbytes;
struct regadm {
char *ra_str;
long ra_off;
} regadm[2];
int n_regvars;
1984-05-19 12:48:59 +00:00
2019-05-10 17:10:47 +00:00
int regscore(long off,int size,int typ,int score,int totyp)
{
1984-05-19 12:48:59 +00:00
if (size != 2)
return(-1);
score -= 1; /* allow for save/restore */
if (off>=0)
score -= 2;
if (typ==reg_pointer)
score *= 17;
else if (typ==reg_loop)
score = 10*score+50; /* Guestimate */
else
score *= 10;
return(score); /* estimated # of words of profit */
}
2019-05-10 17:10:47 +00:00
void i_regsave(void) {
1984-05-19 12:48:59 +00:00
Rstring[0] = 0;
n_regvars=0;
1984-05-19 12:48:59 +00:00
}
2019-05-10 17:10:47 +00:00
void f_regsave(void) {
register int i;
if (n_regvars==0 || lbytes==0) {
#ifdef REGPATCH
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
#endif
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
if (lbytes == 2)
fprintf(codefile,"tst -(sp)\n");
else if (lbytes!=0)
fprintf(codefile,"sub $0%o,sp\n",lbytes);
for (i=0;i<n_regvars;i++)
fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
} else {
if (lbytes>6) {
fprintf(codefile,"mov $0%o,r0\n",lbytes);
fprintf(codefile,"jsr r5,PR%s\n",Rstring);
} else {
fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
}
}
for (i=0;i<n_regvars;i++)
if (regadm[i].ra_off>=0)
fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
regadm[i].ra_str);
}
1984-05-19 12:48:59 +00:00
2019-05-10 17:10:47 +00:00
void regsave(char *regstr,long off,int size)
{
fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
/* commented away
1984-05-19 12:48:59 +00:00
#ifndef REGPATCH
fprintf(codefile,"mov %s,-(sp)\n",regstr);
#endif
strcat(Rstring,regstr);
if (off>=0)
fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
end of commented away */
strcat(Rstring,regstr);
regadm[n_regvars].ra_str = regstr;
regadm[n_regvars].ra_off = off;
n_regvars++;
1984-05-19 12:48:59 +00:00
}
2019-05-10 17:10:47 +00:00
void regreturn(void) {
1984-05-19 12:48:59 +00:00
#ifdef REGPATCH
fprintf(codefile,"jmp eret\n");
#else
fprintf(codefile,"jmp RT%s\n",Rstring);
1984-05-19 12:48:59 +00:00
#endif
}
#endif
2019-05-10 17:10:47 +00:00
void prolog(full nlocals) {
1984-05-19 12:48:59 +00:00
#ifndef REGVARS
1984-05-19 12:48:59 +00:00
#ifdef REGPATCH
fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
#endif
fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
if (nlocals == 0)
return;
if (nlocals == 2)
fprintf(codefile,"tst -(sp)\n");
else
fprintf(codefile,"sub $0%o,sp\n",nlocals);
#else
lbytes = nlocals;
#endif
1984-05-19 12:48:59 +00:00
}
2019-05-10 17:10:47 +00:00
void dlbdlb(string as,string ls)
{
1984-05-19 12:48:59 +00:00
if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
strcat(ls,":");
strcat(ls,as);
} else
fatal("too many consecutive labels");
}
2019-05-10 17:10:47 +00:00
void mes(word type)
{
int argt;
1984-05-19 12:48:59 +00:00
switch ( (int)type ) {
case ms_ext :
for (;;) {
switch ( argt=getarg(
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
case sp_cend :
return ;
default:
strarg(argt) ;
#ifdef ACK_ASS
fprintf(codefile,".define %s\n",argstr) ;
#else
1984-05-19 12:48:59 +00:00
fprintf(codefile,".globl %s\n",argstr) ;
#endif
1984-05-19 12:48:59 +00:00
break ;
}
}
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
1987-02-04 15:09:31 +00:00
#ifdef ACK_ASS
".sect .text", /* SEGTXT */
".sect .data", /* SEGCON */
".sect .rom", /* SEGROM */
".sect .bss" /* SEGBSS */
#else
1984-05-19 12:48:59 +00:00
".text", /* SEGTXT */
".data", /* SEGCON */
".data", /* SEGROM */
".bss" /* SEGBSS */
1987-02-04 15:09:31 +00:00
#endif
1984-05-19 12:48:59 +00:00
};