Initial revision
This commit is contained in:
93
util/ceg/ce_back/as_back/Makefile
Normal file
93
util/ceg/ce_back/as_back/Makefile
Normal file
@@ -0,0 +1,93 @@
|
||||
EM=/proj/em/Work
|
||||
CEG=/usr/star/kaashoek/em/ceg.1
|
||||
SOURCE=$(CEG)/ce_back/as_back
|
||||
|
||||
IDIRS=-I.\
|
||||
-I..\
|
||||
-I$(EM)/h\
|
||||
-I$(EM)/modules/h
|
||||
|
||||
LIBS=$(EM)/modules/lib/object.a\
|
||||
$(EM)/modules/lib/libstring.a\
|
||||
$(EM)/modules/lib/libprint.a\
|
||||
$(EM)/modules/lib/libsystem.a
|
||||
|
||||
all : bottom.o con1.o con2.o con4.o end_back.o gen1.o gen2.o\
|
||||
gen4.o init_back.o reloc1.o reloc2.o reloc4.o bss.o\
|
||||
rom1.o rom2.o rom4.o set_global.o set_local.o switchseg.o symboldef.o \
|
||||
do_open.o do_close.o text1.o text2.o text4.o
|
||||
|
||||
bottom.o : ../mach.h back.h header.h $(SOURCE)/bottom.c
|
||||
cc -c $(IDIRS) $(SOURCE)/bottom.c
|
||||
|
||||
bss.o : ../mach.h back.h header.h $(SOURCE)/bss.c
|
||||
cc -c $(IDIRS) $(SOURCE)/bss.c
|
||||
|
||||
text1.o : ../mach.h back.h header.h $(SOURCE)/text1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/text1.c
|
||||
|
||||
text2.o : ../mach.h back.h header.h $(SOURCE)/text2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/text2.c
|
||||
|
||||
text4.o : ../mach.h back.h header.h $(SOURCE)/text4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/text4.c
|
||||
|
||||
con1.o : ../mach.h back.h header.h $(SOURCE)/con1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/con1.c
|
||||
|
||||
con2.o : ../mach.h back.h header.h $(SOURCE)/con2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/con2.c
|
||||
|
||||
con4.o : ../mach.h back.h header.h $(SOURCE)/con4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/con4.c
|
||||
|
||||
do_open.o : back.h header.h ../mach.h $(SOURCE)/do_open.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/do_open.c
|
||||
|
||||
do_close.o : back.h header.h ../mach.h $(SOURCE)/do_close.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/do_close.c
|
||||
|
||||
gen1.o : back.h header.h ../mach.h $(SOURCE)/gen1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen1.c
|
||||
|
||||
gen2.o : back.h header.h ../mach.h $(SOURCE)/gen2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen2.c
|
||||
|
||||
gen4.o : back.h header.h ../mach.h $(SOURCE)/gen4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen4.c
|
||||
|
||||
init_back.o : header.h back.h ../mach.h $(SOURCE)/init_back.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/init_back.c
|
||||
|
||||
end_back.o : header.h back.h ../mach.h $(SOURCE)/end_back.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/end_back.c
|
||||
|
||||
reloc1.o : back.h header.h ../mach.h $(SOURCE)/reloc1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc1.c
|
||||
|
||||
reloc2.o : back.h header.h ../mach.h $(SOURCE)/reloc2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc2.c
|
||||
|
||||
reloc4.o : back.h header.h ../mach.h $(SOURCE)/reloc4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc4.c
|
||||
|
||||
rom1.o : back.h header.h ../mach.h $(SOURCE)/rom1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/rom1.c
|
||||
|
||||
rom2.o : back.h header.h ../mach.h $(SOURCE)/rom2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/rom2.c
|
||||
|
||||
rom4.o : back.h header.h ../mach.h $(SOURCE)/rom4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/rom4.c
|
||||
|
||||
set_global.o : header.h back.h ../mach.h $(SOURCE)/set_global.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/set_global.c
|
||||
|
||||
set_local.o : header.h back.h ../mach.h $(SOURCE)/set_local.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/set_local.c
|
||||
|
||||
switchseg.o : header.h back.h ../mach.h $(SOURCE)/switchseg.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/switchseg.c
|
||||
|
||||
symboldef.o : header.h back.h ../mach.h $(SOURCE)/symboldef.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/symboldef.c
|
||||
18
util/ceg/ce_back/as_back/back.h
Normal file
18
util/ceg/ce_back/as_back/back.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <em.h>
|
||||
#include <system.h>
|
||||
|
||||
extern File *codefile;
|
||||
|
||||
extern char *extnd_name(), *extnd_dnam(), *extnd_dlb(), *extnd_ilb(),
|
||||
*extnd_hol(), *extnd_ext(), *extnd_pro(), *extnd_start();
|
||||
|
||||
extern int holno, procno;
|
||||
|
||||
#define swtxt() switchseg( SEGTXT)
|
||||
|
||||
#define SEGTXT 0
|
||||
#define SEGROM 1
|
||||
#define SEGCON 2
|
||||
#define SEGBSS 3
|
||||
|
||||
#define ABSOLUTE 1
|
||||
96
util/ceg/ce_back/as_back/bottom.c
Normal file
96
util/ceg/ce_back/as_back/bottom.c
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "mach.h"
|
||||
#include "const.h"
|
||||
#include "back.h"
|
||||
|
||||
|
||||
int procno = 0, holno = 0, cur_seg = -1, saved = FALSE;
|
||||
char name[256], labeltje[256];
|
||||
|
||||
File *codefile;
|
||||
|
||||
|
||||
align_word()
|
||||
|
||||
/* The EM-definition demands that segments are aligned at a word boundary
|
||||
*/
|
||||
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : return;
|
||||
default : fprint( codefile, ALIGN_FMT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
save_label( l)
|
||||
char *l;
|
||||
{
|
||||
sprint( labeltje, "%s", l);
|
||||
saved = TRUE;
|
||||
}
|
||||
|
||||
|
||||
dump_label()
|
||||
{
|
||||
if ( saved) {
|
||||
align_word();
|
||||
symbol_definition( labeltje);
|
||||
}
|
||||
saved = FALSE;
|
||||
}
|
||||
|
||||
|
||||
char *extnd_pro( procno)
|
||||
int procno;
|
||||
{
|
||||
sprint( name, "pro%d", procno);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_start( procno)
|
||||
int procno;
|
||||
{
|
||||
sprint( name, "start%d", procno);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_name( s)
|
||||
char *s;
|
||||
{
|
||||
sprint( name, NAME_FMT, s);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_dnam( s)
|
||||
char *s;
|
||||
{
|
||||
sprint( name, DNAM_FMT, s);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_dlb( g)
|
||||
arith g;
|
||||
{
|
||||
sprint( name, DLB_FMT, (arith)g);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_ilb( l)
|
||||
arith l;
|
||||
{
|
||||
sprint( name, ILB_FMT, procno, (arith) l);
|
||||
return( name);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_hol( hol)
|
||||
int hol;
|
||||
{
|
||||
sprint( name, HOL_FMT, hol);
|
||||
return( name);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/bss.c
Normal file
7
util/ceg/ce_back/as_back/bss.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
bss( n)
|
||||
arith n;
|
||||
{
|
||||
fprint( codefile, BSS_FMT, (arith) n);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/con1.c
Normal file
7
util/ceg/ce_back/as_back/con1.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
con1( w)
|
||||
arith w;
|
||||
{
|
||||
gen1( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/con2.c
Normal file
7
util/ceg/ce_back/as_back/con2.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
con2( w)
|
||||
arith w;
|
||||
{
|
||||
gen2( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/con4.c
Normal file
7
util/ceg/ce_back/as_back/con4.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
con4( w)
|
||||
arith w;
|
||||
{
|
||||
gen4( w);
|
||||
}
|
||||
2
util/ceg/ce_back/as_back/const.h
Normal file
2
util/ceg/ce_back/as_back/const.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
6
util/ceg/ce_back/as_back/do_close.c
Normal file
6
util/ceg/ce_back/as_back/do_close.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "header.h"
|
||||
|
||||
do_close()
|
||||
{
|
||||
sys_close( codefile);
|
||||
}
|
||||
10
util/ceg/ce_back/as_back/do_open.c
Normal file
10
util/ceg/ce_back/as_back/do_open.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "header.h"
|
||||
|
||||
do_open( filename)
|
||||
char *filename;
|
||||
{
|
||||
if ( filename == (char *) '\0')
|
||||
return( FALSE);
|
||||
else
|
||||
return( sys_open( filename, OP_WRITE, &codefile));
|
||||
}
|
||||
5
util/ceg/ce_back/as_back/end_back.c
Normal file
5
util/ceg/ce_back/as_back/end_back.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "header.h"
|
||||
|
||||
end_back()
|
||||
{
|
||||
}
|
||||
17
util/ceg/ce_back/as_back/gen1.c
Normal file
17
util/ceg/ce_back/as_back/gen1.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "header.h"
|
||||
|
||||
gen1( w)
|
||||
arith w;
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : fprint( codefile, BYTE_FMT, (arith) w);
|
||||
break;
|
||||
case SEGCON : fprint( codefile, BYTE_FMT, (arith) w);
|
||||
break;
|
||||
case SEGROM : fprint( codefile, BYTE_FMT, (arith) w);
|
||||
break;
|
||||
case SEGBSS : bss( 1);
|
||||
break;
|
||||
default : fprint( STDERR, "gen1 unkown seg %d\n", cur_seg);
|
||||
}
|
||||
}
|
||||
17
util/ceg/ce_back/as_back/gen2.c
Normal file
17
util/ceg/ce_back/as_back/gen2.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "header.h"
|
||||
|
||||
gen2( w)
|
||||
arith w;
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : fprint( codefile, WORD_FMT, (arith) w);
|
||||
break;
|
||||
case SEGCON : fprint( codefile, WORD_FMT, (arith) w);
|
||||
break;
|
||||
case SEGROM : fprint( codefile, WORD_FMT, (arith) w);
|
||||
break;
|
||||
case SEGBSS : bss( 2);
|
||||
break;
|
||||
default : fprint( STDERR, "gen2 unkown seg %d\n", cur_seg);
|
||||
}
|
||||
}
|
||||
17
util/ceg/ce_back/as_back/gen4.c
Normal file
17
util/ceg/ce_back/as_back/gen4.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "header.h"
|
||||
|
||||
gen4( w)
|
||||
arith w;
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : fprint( codefile, LONG_FMT, (arith) w);
|
||||
break;
|
||||
case SEGCON : fprint( codefile, LONG_FMT, (arith) w);
|
||||
break;
|
||||
case SEGROM : fprint( codefile, LONG_FMT, (arith) w);
|
||||
break;
|
||||
case SEGBSS : bss( 4);
|
||||
break;
|
||||
default : fprint( STDERR, "gen4 unkown seg %d\n", cur_seg);
|
||||
}
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/header.h
Normal file
7
util/ceg/ce_back/as_back/header.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "mach.h"
|
||||
#include "const.h"
|
||||
#include "back.h"
|
||||
|
||||
extern int cur_seg;
|
||||
|
||||
extern holno, procno;
|
||||
5
util/ceg/ce_back/as_back/init_back.c
Normal file
5
util/ceg/ce_back/as_back/init_back.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "header.h"
|
||||
|
||||
init_back()
|
||||
{
|
||||
}
|
||||
9
util/ceg/ce_back/as_back/reloc1.c
Normal file
9
util/ceg/ce_back/as_back/reloc1.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "header.h"
|
||||
|
||||
reloc1( s, o, r)
|
||||
char *s;
|
||||
arith o;
|
||||
int r;
|
||||
{
|
||||
fprint( codefile, RELOC1_FMT, s, (arith) o);
|
||||
}
|
||||
9
util/ceg/ce_back/as_back/reloc2.c
Normal file
9
util/ceg/ce_back/as_back/reloc2.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "header.h"
|
||||
|
||||
reloc2( s, o, r)
|
||||
char *s;
|
||||
arith o;
|
||||
int r;
|
||||
{
|
||||
fprint( codefile, RELOC2_FMT, s, (arith) o);
|
||||
}
|
||||
9
util/ceg/ce_back/as_back/reloc4.c
Normal file
9
util/ceg/ce_back/as_back/reloc4.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "header.h"
|
||||
|
||||
reloc4( s, o, r)
|
||||
char *s;
|
||||
arith o;
|
||||
int r;
|
||||
{
|
||||
fprint( codefile, RELOC4_FMT, s, (arith) o);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/rom1.c
Normal file
7
util/ceg/ce_back/as_back/rom1.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
rom1( w)
|
||||
arith w;
|
||||
{
|
||||
gen1( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/rom2.c
Normal file
7
util/ceg/ce_back/as_back/rom2.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
rom2( w)
|
||||
arith w;
|
||||
{
|
||||
gen2( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/rom4.c
Normal file
7
util/ceg/ce_back/as_back/rom4.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
rom4( w)
|
||||
arith w;
|
||||
{
|
||||
gen4( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/set_global.c
Normal file
7
util/ceg/ce_back/as_back/set_global.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
set_global_visible( s)
|
||||
char *s;
|
||||
{
|
||||
fprint( codefile, GLOBAL_FMT, s);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/set_local.c
Normal file
7
util/ceg/ce_back/as_back/set_local.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
set_local_visible( s)
|
||||
char *s;
|
||||
{
|
||||
fprint( codefile, LOCAL_FMT, s);
|
||||
}
|
||||
25
util/ceg/ce_back/as_back/switchseg.c
Normal file
25
util/ceg/ce_back/as_back/switchseg.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "header.h"
|
||||
|
||||
switchseg( seg)
|
||||
int seg;
|
||||
{
|
||||
if ( seg == cur_seg)
|
||||
return;
|
||||
|
||||
cur_seg = seg;
|
||||
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : fprint( codefile, SEGTXT_FMT);
|
||||
break;
|
||||
case SEGCON : fprint( codefile, SEGDAT_FMT);
|
||||
break;
|
||||
case SEGROM : fprint( codefile, SEGDAT_FMT);
|
||||
break;
|
||||
case SEGBSS : fprint( codefile, SEGBSS_FMT);
|
||||
break;
|
||||
}
|
||||
|
||||
if ( seg != SEGTXT)
|
||||
align_word();
|
||||
}
|
||||
|
||||
7
util/ceg/ce_back/as_back/symboldef.c
Normal file
7
util/ceg/ce_back/as_back/symboldef.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
symbol_definition( s)
|
||||
char *s;
|
||||
{
|
||||
fprint( codefile, SYMBOL_DEF_FMT, s);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/text1.c
Normal file
7
util/ceg/ce_back/as_back/text1.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
text1( w)
|
||||
arith w;
|
||||
{
|
||||
gen1( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/text2.c
Normal file
7
util/ceg/ce_back/as_back/text2.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
text2( w)
|
||||
arith w;
|
||||
{
|
||||
gen2( w);
|
||||
}
|
||||
7
util/ceg/ce_back/as_back/text4.c
Normal file
7
util/ceg/ce_back/as_back/text4.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
text4( w)
|
||||
arith w;
|
||||
{
|
||||
gen4( w);
|
||||
}
|
||||
107
util/ceg/ce_back/obj_back/Makefile
Normal file
107
util/ceg/ce_back/obj_back/Makefile
Normal file
@@ -0,0 +1,107 @@
|
||||
EM=/proj/em/Work
|
||||
CEG=/usr/star/kaashoek/em/ceg.1
|
||||
SOURCE=$(CEG)/ce_back/obj_back
|
||||
|
||||
IDIRS=-I.\
|
||||
-I..\
|
||||
-I$(EM)/h\
|
||||
-I$(EM)/modules/h
|
||||
|
||||
LIBS=$(EM)/modules/lib/object.a\
|
||||
$(EM)/modules/lib/libstring.a\
|
||||
$(EM)/modules/lib/libprint.a\
|
||||
$(EM)/modules/lib/liballoc.a\
|
||||
$(EM)/modules/lib/libsystem.a
|
||||
|
||||
all : data.o con2.o con4.o relocation.o end_back.o gen1.o gen2.o\
|
||||
gen4.o init_back.o mysprint.o output.o reloc1.o reloc2.o reloc4.o\
|
||||
rom2.o rom4.o set_global.o set_local.o switchseg.o symboldef.o text2.o\
|
||||
text4.o do_open.o do_close.o memory.o label.o misc.o extnd.o symtable.o
|
||||
|
||||
data.o : data.h back.h header.h $(SOURCE)/data.c
|
||||
cc -c $(IDIRS) $(SOURCE)/data.c
|
||||
|
||||
memory.o :data.h back.h header.h $(SOURCE)/memory.c
|
||||
cc -c $(IDIRS) $(SOURCE)/memory.c
|
||||
|
||||
con2.o : data.h back.h header.h $(SOURCE)/con2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/con2.c
|
||||
|
||||
con4.o : data.h back.h header.h $(SOURCE)/con4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/con4.c
|
||||
|
||||
relocation.o : data.h back.h ../mach.h $(SOURCE)/relocation.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/relocation.c
|
||||
|
||||
do_open.o : data.h back.h ../mach.h $(SOURCE)/do_open.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/do_open.c
|
||||
|
||||
do_close.o : data.h back.h ../mach.h $(SOURCE)/do_close.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/do_close.c
|
||||
|
||||
gen1.o : data.h back.h header.h $(SOURCE)/gen1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen1.c
|
||||
|
||||
gen2.o : data.h back.h header.h $(SOURCE)/gen2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen2.c
|
||||
|
||||
gen4.o : data.h back.h header.h $(SOURCE)/gen4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/gen4.c
|
||||
|
||||
init_back.o : data.h back.h ../mach.h $(SOURCE)/init_back.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/init_back.c
|
||||
|
||||
end_back.o : data.h back.h ../mach.h $(SOURCE)/end_back.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/end_back.c
|
||||
|
||||
mysprint.o : data.h back.h data.h $(SOURCE)/mysprint.c
|
||||
cc -c $(IDIRS) $(SOURCE)/mysprint.c
|
||||
|
||||
output.o : data.h back.h ../mach.h $(SOURCE)/output.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/output.c
|
||||
|
||||
reloc1.o : data.h back.h header.h $(SOURCE)/reloc1.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc1.c
|
||||
|
||||
reloc2.o : data.h back.h header.h $(SOURCE)/reloc2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc2.c
|
||||
|
||||
reloc4.o : data.h back.h header.h $(SOURCE)/reloc4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/reloc4.c
|
||||
|
||||
rom2.o : data.h back.h header.h $(SOURCE)/rom2.c
|
||||
cc -c $(IDIRS) $(SOURCE)/rom2.c
|
||||
|
||||
rom4.o : data.h back.h header.h $(SOURCE)/rom4.c
|
||||
cc -c $(IDIRS) $(SOURCE)/rom4.c
|
||||
|
||||
set_global.o : data.h back.h ../mach.h $(SOURCE)/set_global.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/set_global.c
|
||||
|
||||
set_local.o : data.h back.h ../mach.h $(SOURCE)/set_local.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/set_local.c
|
||||
|
||||
switchseg.o : data.h back.h ../mach.h $(SOURCE)/switchseg.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/switchseg.c
|
||||
|
||||
symboldef.o : data.h back.h ../mach.h $(SOURCE)/symboldef.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/symboldef.c
|
||||
|
||||
text2.o : data.h back.h ../mach.h $(SOURCE)/text2.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/text2.c
|
||||
|
||||
text4.o : data.h back.h ../mach.h $(SOURCE)/text4.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/text4.c
|
||||
|
||||
symtable.o : data.h back.h ../mach.h $(SOURCE)/symtable.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/symtable.c
|
||||
|
||||
extnd.o : data.h back.h ../mach.h $(SOURCE)/extnd.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/extnd.c
|
||||
|
||||
misc.o : data.h back.h ../mach.h $(SOURCE)/misc.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/misc.c
|
||||
|
||||
label.o : data.h back.h ../mach.h $(SOURCE)/label.c
|
||||
cc -c $(IDIRS) -I.. $(SOURCE)/label.c
|
||||
|
||||
27
util/ceg/ce_back/obj_back/back.h
Normal file
27
util/ceg/ce_back/obj_back/back.h
Normal file
@@ -0,0 +1,27 @@
|
||||
extern char *extnd_name(), *extnd_dnam(), *extnd_dlb(), *extnd_ilb(),
|
||||
*extnd_hol(), *extnd_ext(), *extnd_pro(), *extnd_start();
|
||||
extern holno, procno;
|
||||
|
||||
#include "data.h"
|
||||
|
||||
#define text1(b) {if (text-text_area>=size_text) mem_text() ; *text++=b;}
|
||||
#define con1(b) {if (data-data_area>=size_data) mem_data(); *data++ = b;}
|
||||
#define rom1(b) {if (data-data_area>=size_data) mem_data(); *data++=b;}
|
||||
#define bss( n) ( nbss += n)
|
||||
|
||||
#define SEGTXT 0
|
||||
#define SEGROM 1
|
||||
#define SEGCON 2
|
||||
#define SEGBSS 3
|
||||
|
||||
#define swtxt() switchseg( SEGTXT)
|
||||
|
||||
#define MAXTEXT 20
|
||||
#define MAXDATA 20
|
||||
#define MAXRELO 3
|
||||
#define MAXNAME 5
|
||||
#define MAXSTRING 20
|
||||
#define MAXHASH 256
|
||||
|
||||
#define PC_REL 1
|
||||
#define ABSOLUTE !PC_REL
|
||||
15
util/ceg/ce_back/obj_back/con2.c
Normal file
15
util/ceg/ce_back/obj_back/con2.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
con2( w)
|
||||
TWO_BYTES w;
|
||||
{
|
||||
#ifdef BYTES_REVERSED
|
||||
con1( (char) ( ( unsigned short)w>>8));
|
||||
con1( (char) w);
|
||||
#else
|
||||
con1( (char) w);
|
||||
con1( (char) ( ( unsigned short)w>>8));
|
||||
#endif
|
||||
}
|
||||
|
||||
15
util/ceg/ce_back/obj_back/con4.c
Normal file
15
util/ceg/ce_back/obj_back/con4.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "mach.h"
|
||||
|
||||
con4( l)
|
||||
FOUR_BYTES l;
|
||||
{
|
||||
#ifdef WORDS_REVERSED
|
||||
con2( (short) ((unsigned long)l>>16));
|
||||
con2( (short) l);
|
||||
#else
|
||||
con2( (short) l);
|
||||
con2( (short) ((unsigned long)l>>16));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
97
util/ceg/ce_back/obj_back/data.c
Normal file
97
util/ceg/ce_back/obj_back/data.c
Normal file
@@ -0,0 +1,97 @@
|
||||
#include <system.h>
|
||||
#include <out.h>
|
||||
#include "mach.h"
|
||||
|
||||
|
||||
char *text_area,
|
||||
*data_area,
|
||||
*string_area,
|
||||
*text, *data, *string;
|
||||
struct outrelo *reloc_info, *relo;
|
||||
struct outname *symbol_table;
|
||||
|
||||
|
||||
int cur_seg = -1 , nname = 0;
|
||||
long nbss = 0, size_text, size_data, size_reloc, size_symbol,
|
||||
size_string;
|
||||
|
||||
|
||||
put1(sect,addr,b)
|
||||
char *sect;
|
||||
long addr;
|
||||
char b;
|
||||
{
|
||||
sect[addr] = b;
|
||||
}
|
||||
|
||||
|
||||
put2(sect,addr,w)
|
||||
char *sect;
|
||||
long addr;
|
||||
int w;
|
||||
{
|
||||
#ifdef BYTES_REVERSED
|
||||
put1(sect,addr,(char) (w>>8));
|
||||
put1(sect,addr+1,(char) w);
|
||||
#else
|
||||
put1(sect,addr,(char) w);
|
||||
put1(sect,addr+1,(char) (w>>8));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
put4(sect,addr,l)
|
||||
char *sect;
|
||||
long addr;
|
||||
long l;
|
||||
{
|
||||
#ifdef WORDS_REVERSED
|
||||
put2(sect,addr,(short) (l>>16));
|
||||
put2(sect,addr+2,(short) l);
|
||||
#else
|
||||
put2(sect,addr,(short) l);
|
||||
put2(sect,addr+2,(short) (l>>16));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
char get1( sect, addr)
|
||||
char *sect;
|
||||
long addr;
|
||||
{
|
||||
return( sect[addr]);
|
||||
}
|
||||
|
||||
|
||||
short get2(sect,addr)
|
||||
char *sect;
|
||||
long addr;
|
||||
{
|
||||
short h,l;
|
||||
|
||||
#ifdef BYTES_REVERSED
|
||||
h = sect[addr];
|
||||
l = sect[addr+1];
|
||||
#else
|
||||
l = sect[addr];
|
||||
h = sect[addr+1];
|
||||
#endif
|
||||
return( ( h << 8) | ( l & 255));
|
||||
}
|
||||
|
||||
|
||||
long get4(sect,addr)
|
||||
char *sect;
|
||||
long addr;
|
||||
{
|
||||
long l,h;
|
||||
|
||||
#ifdef WORDS_REVERSED
|
||||
h = get2(sect,addr);
|
||||
l = get2(sect,addr+2);
|
||||
#else
|
||||
l = get2(sect,addr);
|
||||
h = get2(sect,addr+2);
|
||||
#endif
|
||||
return( ( h << 16) | ( l & 65535L));
|
||||
}
|
||||
13
util/ceg/ce_back/obj_back/data.h
Normal file
13
util/ceg/ce_back/obj_back/data.h
Normal file
@@ -0,0 +1,13 @@
|
||||
extern long cur_value();
|
||||
|
||||
extern int cur_seg;
|
||||
|
||||
extern char *text, *data, *string;
|
||||
extern int nname;
|
||||
extern long nbss, size_text, size_data, size_reloc, size_symbol,
|
||||
size_string;
|
||||
|
||||
extern char *text_area, *data_area, *string_area;
|
||||
extern struct outrelo *reloc_info, *relo;
|
||||
extern struct outname *symbol_table;
|
||||
|
||||
10
util/ceg/ce_back/obj_back/do_close.c
Normal file
10
util/ceg/ce_back/obj_back/do_close.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <out.h>
|
||||
#include <arch.h>
|
||||
#include <ranlib.h>
|
||||
|
||||
do_close()
|
||||
{
|
||||
output();
|
||||
|
||||
wr_close();
|
||||
}
|
||||
14
util/ceg/ce_back/obj_back/do_open.c
Normal file
14
util/ceg/ce_back/obj_back/do_open.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <out.h>
|
||||
#include <arch.h>
|
||||
#include <ranlib.h>
|
||||
#include "data.h"
|
||||
#include "header.h"
|
||||
|
||||
do_open( filename)
|
||||
char *filename;
|
||||
{
|
||||
if ( filename == (char *) '\0')
|
||||
return( 0);
|
||||
else
|
||||
return( wr_open( filename));
|
||||
}
|
||||
41
util/ceg/ce_back/obj_back/end_back.c
Normal file
41
util/ceg/ce_back/obj_back/end_back.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <out.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
#include "header.h"
|
||||
|
||||
|
||||
end_back()
|
||||
{
|
||||
sync();
|
||||
define_segments();
|
||||
do_local_relocation();
|
||||
}
|
||||
|
||||
|
||||
sync()
|
||||
{
|
||||
while ( ( text - text_area) % EM_WSIZE != 0 )
|
||||
text1( '\0');
|
||||
while ( ( data - data_area) % EM_WSIZE != 0 )
|
||||
con1( '\0');
|
||||
}
|
||||
|
||||
|
||||
static char *seg_name[] = {
|
||||
".text",
|
||||
".rom",
|
||||
".con",
|
||||
".bss"
|
||||
};
|
||||
|
||||
|
||||
define_segments()
|
||||
{
|
||||
int i, s;
|
||||
|
||||
for ( s = SEGTXT; s <= SEGBSS; s++) {
|
||||
i = find_sym( seg_name[s], SYMBOL_DEFINITION);
|
||||
symbol_table[i].on_type = ( S_MIN + s) | S_SCT;
|
||||
}
|
||||
}
|
||||
|
||||
77
util/ceg/ce_back/obj_back/extnd.c
Normal file
77
util/ceg/ce_back/obj_back/extnd.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <system.h>
|
||||
#include <em.h>
|
||||
#include <out.h>
|
||||
#include "header.h"
|
||||
#include "mach.h"
|
||||
|
||||
/* The extnd_*() make a name unique. The resulting string is directly stored
|
||||
in the symbol_table (by mysprint()). Later additional fields in the
|
||||
symbol_table are filled. For these actions the values of the index in
|
||||
the symbol_table and the length of the string are stored.
|
||||
*/
|
||||
|
||||
extern int string_lengte, index_symbol_table;
|
||||
int procno = 0, holno = 0;
|
||||
|
||||
|
||||
char *extnd_pro( procno)
|
||||
int procno;
|
||||
{
|
||||
string_lengte = mysprint( "pro%d", procno);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_start( procno)
|
||||
int procno;
|
||||
{
|
||||
string_lengte = mysprint( "start%d", procno);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_name( s)
|
||||
char *s;
|
||||
{
|
||||
string_lengte = mysprint( NAME_FMT, s);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( string_area + symbol_table[ index_symbol_table].on_foff);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_dnam( s)
|
||||
char *s;
|
||||
{
|
||||
string_lengte = mysprint( DNAM_FMT, s);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_dlb( g)
|
||||
arith g;
|
||||
{
|
||||
string_lengte = mysprint( DLB_FMT, (arith)g);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_ilb( l)
|
||||
arith l;
|
||||
{
|
||||
string_lengte = mysprint( ILB_FMT, procno, (arith) l);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
|
||||
|
||||
char *extnd_hol( hol)
|
||||
int hol;
|
||||
{
|
||||
string_lengte = mysprint( HOL_FMT, hol);
|
||||
index_symbol_table = find_sym( string, STORE_STRING);
|
||||
return( symbol_table[ index_symbol_table].on_foff + string_area);
|
||||
}
|
||||
21
util/ceg/ce_back/obj_back/gen1.c
Normal file
21
util/ceg/ce_back/obj_back/gen1.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <system.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
gen1( c)
|
||||
ONE_BYTE c;
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : text1( c);
|
||||
return;
|
||||
case SEGCON : con1( c);
|
||||
return;
|
||||
case SEGROM : rom1( c);
|
||||
return;
|
||||
case SEGBSS : bss( 1);
|
||||
return;
|
||||
default : fprint( STDERR, "gen1() : bad seg number\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
15
util/ceg/ce_back/obj_back/gen2.c
Normal file
15
util/ceg/ce_back/obj_back/gen2.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
gen2( w)
|
||||
TWO_BYTES w;
|
||||
{
|
||||
#ifdef BYTES_REVERSED
|
||||
gen1( (char) ( ( unsigned short)w>>8));
|
||||
gen1( (char) w);
|
||||
#else
|
||||
gen1( (char) w);
|
||||
gen1( (char) ( ( unsigned short)w>>8));
|
||||
#endif
|
||||
}
|
||||
|
||||
14
util/ceg/ce_back/obj_back/gen4.c
Normal file
14
util/ceg/ce_back/obj_back/gen4.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "mach.h"
|
||||
|
||||
gen4( l)
|
||||
FOUR_BYTES l;
|
||||
{
|
||||
#ifdef WORDS_REVERSED
|
||||
gen2( (short) ((unsigned long)l>>16));
|
||||
gen2( (short) l);
|
||||
#else
|
||||
gen2( (short) l);
|
||||
gen2( (short) ((unsigned long)l>>16));
|
||||
#endif
|
||||
}
|
||||
|
||||
6
util/ceg/ce_back/obj_back/hash.h
Normal file
6
util/ceg/ce_back/obj_back/hash.h
Normal file
@@ -0,0 +1,6 @@
|
||||
struct Hashitem {
|
||||
int hs_next;
|
||||
int hs_nami;
|
||||
};
|
||||
|
||||
extern struct Hashitem *Hashitems;
|
||||
5
util/ceg/ce_back/obj_back/header.h
Normal file
5
util/ceg/ce_back/obj_back/header.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#define SYMBOL_DEFINITION 1
|
||||
#define REFERENCE 2
|
||||
#define STORE_STRING 3
|
||||
|
||||
#define conv_seg( s) ( ( s == SEGROM) ? SEGCON : s)
|
||||
27
util/ceg/ce_back/obj_back/init_back.c
Normal file
27
util/ceg/ce_back/obj_back/init_back.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <out.h>
|
||||
#include "back.h"
|
||||
#include "hash.h"
|
||||
|
||||
char *calloc();
|
||||
|
||||
init_back()
|
||||
{
|
||||
text_area = calloc( MAXTEXT, sizeof( char));
|
||||
data_area = calloc( MAXDATA, sizeof( char));
|
||||
reloc_info = (struct outrelo *)calloc( MAXRELO, SZ_RELO);
|
||||
symbol_table = (struct outname *)calloc( MAXNAME, SZ_NAME);
|
||||
Hashitems = (struct Hashitem *)calloc( MAXNAME + 1,
|
||||
sizeof( struct Hashitem));
|
||||
string_area = calloc( MAXSTRING, sizeof( char));
|
||||
|
||||
text = text_area;
|
||||
data = data_area;
|
||||
string = string_area;
|
||||
relo = reloc_info;
|
||||
|
||||
size_text = MAXTEXT;
|
||||
size_data = MAXDATA;
|
||||
size_reloc = MAXRELO;
|
||||
size_symbol = MAXNAME;
|
||||
size_string = MAXSTRING;
|
||||
}
|
||||
24
util/ceg/ce_back/obj_back/label.c
Normal file
24
util/ceg/ce_back/obj_back/label.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <out.h>
|
||||
#include "header.h"
|
||||
#include "back.h"
|
||||
|
||||
int Label, label_waiting;
|
||||
|
||||
save_label( lab)
|
||||
char *lab;
|
||||
{
|
||||
Label = find_sym( lab, SYMBOL_DEFINITION);
|
||||
label_waiting = 1;
|
||||
}
|
||||
|
||||
|
||||
dump_label()
|
||||
{
|
||||
if ( label_waiting) {
|
||||
align_word();
|
||||
symbol_table[ Label].on_valu = cur_value();
|
||||
symbol_table[ Label].on_type |= ( S_MIN + conv_seg( cur_seg));
|
||||
label_waiting = 0;
|
||||
}
|
||||
}
|
||||
|
||||
64
util/ceg/ce_back/obj_back/memory.c
Normal file
64
util/ceg/ce_back/obj_back/memory.c
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <out.h>
|
||||
#include <system.h>
|
||||
#include "data.h"
|
||||
#include "hash.h"
|
||||
|
||||
char *realloc();
|
||||
|
||||
mem_text()
|
||||
{
|
||||
/* print( "text_area too small %d %d \n", text_area, text); */
|
||||
|
||||
text_area = realloc( text_area, sizeof( char) * 2 * size_text);
|
||||
text = text_area + size_text;
|
||||
size_text = 2 * size_text;
|
||||
}
|
||||
|
||||
|
||||
mem_data()
|
||||
{
|
||||
/* print( "data_area too small\n"); */
|
||||
|
||||
data_area = realloc( data_area, sizeof( char) * 2 * size_data);
|
||||
data = data_area + size_data;
|
||||
size_data = 2 * size_data;
|
||||
}
|
||||
|
||||
|
||||
mem_symbol_hash()
|
||||
{
|
||||
/* print( "symbol_table out of memory\n"); */
|
||||
|
||||
size_symbol = 2 * size_symbol;
|
||||
symbol_table = (struct outname *) realloc( (char *) symbol_table,
|
||||
sizeof( struct outname) * size_symbol);
|
||||
|
||||
/* print( "hash out of memory\n"); */
|
||||
|
||||
Hashitems = (struct Hashitem *) realloc( (char *) Hashitems,
|
||||
sizeof( struct Hashitem)*(size_symbol+1));
|
||||
}
|
||||
|
||||
|
||||
mem_relo()
|
||||
{
|
||||
/* print( "reloc_table out of memory\n"); */
|
||||
|
||||
reloc_info = (struct outrelo *) realloc( (char *) reloc_info,
|
||||
sizeof( struct outrelo) * 2 * size_reloc);
|
||||
relo = reloc_info + size_reloc;
|
||||
size_reloc = 2 * size_reloc;
|
||||
}
|
||||
|
||||
|
||||
mem_string()
|
||||
{
|
||||
int i;
|
||||
|
||||
/* print( "string_area out of memory %d %d \n", string_area, string);*/
|
||||
|
||||
i = string - string_area;
|
||||
size_string = 2 * size_string;
|
||||
string_area = realloc( string_area, sizeof( char) * size_string);
|
||||
string = string_area + i;
|
||||
}
|
||||
39
util/ceg/ce_back/obj_back/misc.c
Normal file
39
util/ceg/ce_back/obj_back/misc.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <system.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
/* The following functions are called from reloc1(), reloc2(), reloc4(),
|
||||
dump_label().
|
||||
*/
|
||||
|
||||
align_word()
|
||||
{
|
||||
switch ( cur_seg) {
|
||||
case SEGTXT : return;
|
||||
case SEGCON : while ( (data - data_area) % EM_WSIZE != 0)
|
||||
con1( '\0');
|
||||
return;
|
||||
case SEGROM : while ( (data - data_area) % EM_WSIZE != 0)
|
||||
rom1( '\0');
|
||||
return;
|
||||
case SEGBSS : while ( nbss % EM_WSIZE != 0)
|
||||
nbss++;
|
||||
return;
|
||||
default : fprint( STDERR, "align_word() : unknown seg\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long cur_value()
|
||||
{
|
||||
switch( cur_seg) {
|
||||
case SEGTXT: return text - text_area;
|
||||
case SEGCON: return data - data_area;
|
||||
case SEGROM: return data - data_area;
|
||||
case SEGBSS: return nbss;
|
||||
default : fprint( STDERR, "cur_value() : unknown seg\n");
|
||||
return -1L;
|
||||
}
|
||||
}
|
||||
|
||||
122
util/ceg/ce_back/obj_back/mysprint.c
Normal file
122
util/ceg/ce_back/obj_back/mysprint.c
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <system.h>
|
||||
#include "data.h"
|
||||
|
||||
int mysprint( fmt, args)
|
||||
char *fmt;
|
||||
int args;
|
||||
{
|
||||
return( _myformat( fmt, &args));
|
||||
}
|
||||
|
||||
char *long2str();
|
||||
|
||||
static int integral(c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b':
|
||||
return -2;
|
||||
case 'd':
|
||||
return 10;
|
||||
case 'o':
|
||||
return -8;
|
||||
case 'u':
|
||||
return -10;
|
||||
case 'x':
|
||||
return -16;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _myformat( fmt, argp)
|
||||
char *fmt;
|
||||
char *argp;
|
||||
{
|
||||
register char *pf = fmt, *pa = argp;
|
||||
register char *pb = string;
|
||||
int n = 0;
|
||||
|
||||
while (*pf) {
|
||||
if (*pf == '%') {
|
||||
register width, base, pad, npad, s_l;
|
||||
char *arg;
|
||||
char cbuf[2];
|
||||
char *badformat = "<bad format>";
|
||||
|
||||
/* get padder */
|
||||
if (*++pf == '0') {
|
||||
pad = '0';
|
||||
++pf;
|
||||
}
|
||||
else
|
||||
pad = ' ';
|
||||
|
||||
/* get width */
|
||||
width = 0;
|
||||
while (*pf >= '0' && *pf <= '9')
|
||||
width = 10 * width + *pf++ - '0';
|
||||
|
||||
/* get text and move pa */
|
||||
if (*pf == 's') {
|
||||
arg = *(char **)pa;
|
||||
pa += sizeof(char *);
|
||||
}
|
||||
else
|
||||
if (*pf == 'c') {
|
||||
cbuf[0] = * (int *) pa;
|
||||
cbuf[1] = '\0';
|
||||
pa += sizeof(int);
|
||||
arg = &cbuf[0];
|
||||
}
|
||||
else
|
||||
if (*pf == 'l') {
|
||||
/* alignment ??? */
|
||||
if (base = integral(*++pf)) {
|
||||
arg = long2str(*(long *)pa, base);
|
||||
pa += sizeof(long);
|
||||
}
|
||||
else {
|
||||
pf--;
|
||||
arg = badformat;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (base = integral(*pf)) {
|
||||
arg = long2str((long)*(int *)pa, base);
|
||||
pa += sizeof(int);
|
||||
}
|
||||
else
|
||||
if (*pf == '%')
|
||||
arg = "%";
|
||||
else
|
||||
arg = badformat;
|
||||
|
||||
s_l = strlen( arg);
|
||||
npad = width - s_l;
|
||||
if ( npad > 0)
|
||||
s_l += npad;
|
||||
|
||||
if ( n + s_l + string - string_area >= size_string) {
|
||||
mem_string();
|
||||
pb = string + n;
|
||||
}
|
||||
|
||||
while (npad-- > 0)
|
||||
*pb++ = pad;
|
||||
|
||||
while (*pb++ = *arg++);
|
||||
n += s_l;
|
||||
|
||||
pb--;
|
||||
pf++;
|
||||
}
|
||||
else {
|
||||
if ( n + ( string - string_area) >= size_string) {
|
||||
mem_string();
|
||||
pb = string + n;
|
||||
}
|
||||
n++;
|
||||
*pb++ = *pf++;
|
||||
}
|
||||
}
|
||||
return n ;
|
||||
}
|
||||
89
util/ceg/ce_back/obj_back/output.c
Normal file
89
util/ceg/ce_back/obj_back/output.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <system.h>
|
||||
#include <out.h>
|
||||
#include "data.h"
|
||||
|
||||
output()
|
||||
/* Notice : entries in the symbol_table are converted.
|
||||
*/
|
||||
|
||||
{
|
||||
struct outhead header;
|
||||
struct outsect sect;
|
||||
long ntext = text - text_area,
|
||||
ndata = data - data_area,
|
||||
nchar = string - string_area;
|
||||
int nrelo = relo - reloc_info;
|
||||
|
||||
header.oh_magic = O_MAGIC;
|
||||
header.oh_flags = HF_LINK;
|
||||
header.oh_nsect = 4;
|
||||
header.oh_nrelo = nrelo;
|
||||
header.oh_nname = nname;
|
||||
header.oh_nemit = ntext + ndata;
|
||||
header.oh_nchar = nchar;
|
||||
|
||||
wr_ohead( &header);
|
||||
|
||||
sect.os_base = 20;
|
||||
sect.os_size = ntext;
|
||||
sect.os_foff = OFF_EMIT( header);
|
||||
sect.os_flen = ntext;
|
||||
sect.os_lign = 1;
|
||||
|
||||
wr_sect( §, 1);
|
||||
|
||||
sect.os_base = 20 + ntext;
|
||||
sect.os_size = 0;
|
||||
sect.os_foff = OFF_EMIT( header) + ntext;
|
||||
sect.os_flen = 0;
|
||||
sect.os_lign = 1;
|
||||
|
||||
wr_sect( §, 1);
|
||||
|
||||
sect.os_base = 20 + ntext;
|
||||
sect.os_size = ndata;
|
||||
sect.os_foff = OFF_EMIT( header) + ntext;
|
||||
sect.os_flen = ndata;
|
||||
sect.os_lign = 1;
|
||||
|
||||
wr_sect( §, 1);
|
||||
|
||||
sect.os_base = 20 + ntext + ndata;
|
||||
sect.os_size = nbss;
|
||||
sect.os_foff = OFF_EMIT( header) + ntext + ndata;
|
||||
sect.os_flen = 0;
|
||||
sect.os_lign = 1;
|
||||
|
||||
wr_sect( §, 1);
|
||||
|
||||
wr_outsect( 0);
|
||||
wr_emit( text_area, ntext);
|
||||
wr_outsect( 2);
|
||||
wr_emit( data_area, ndata);
|
||||
|
||||
wr_relo( reloc_info, nrelo);
|
||||
|
||||
convert_outname( &header);
|
||||
wr_name( symbol_table, nname);
|
||||
|
||||
wr_string( string_area, nchar);
|
||||
}
|
||||
|
||||
wr_fatal()
|
||||
{
|
||||
fprint( STDERR, "write failed\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
convert_outname( header)
|
||||
struct outhead *header;
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( i=0; i < nname; i++) {
|
||||
symbol_table[ i].on_foff += OFF_CHAR( *header);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
util/ceg/ce_back/obj_back/reloc1.c
Normal file
29
util/ceg/ce_back/obj_back/reloc1.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <out.h>
|
||||
#include <em.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
#include "header.h"
|
||||
|
||||
reloc1( sym, off, pcrel)
|
||||
char *sym;
|
||||
arith off;
|
||||
int pcrel;
|
||||
{
|
||||
if ( relo - reloc_info >= size_reloc)
|
||||
mem_relo();
|
||||
|
||||
relo->or_type = RELO1;
|
||||
#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
|
||||
relo->or_type |= RELBR;
|
||||
#endif
|
||||
#ifdef WORDS_REVERSED
|
||||
relo->or_type |= RELWR;
|
||||
#endif
|
||||
relo->or_type |= ( pcrel) ? RELPC : S_UND;
|
||||
relo->or_sect = S_MIN + conv_seg( cur_seg);
|
||||
relo->or_nami = find_sym(sym, REFERENCE);
|
||||
relo->or_addr = cur_value();
|
||||
gen1( (pcrel) ? off - ( cur_value() + 1) : off);
|
||||
|
||||
relo++;
|
||||
}
|
||||
29
util/ceg/ce_back/obj_back/reloc2.c
Normal file
29
util/ceg/ce_back/obj_back/reloc2.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <out.h>
|
||||
#include <em.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
#include "header.h"
|
||||
|
||||
reloc2( sym, off, pcrel)
|
||||
char *sym;
|
||||
arith off;
|
||||
int pcrel;
|
||||
{
|
||||
if ( relo - reloc_info >= size_reloc)
|
||||
mem_relo();
|
||||
|
||||
relo->or_type = RELO2;
|
||||
#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
|
||||
relo->or_type |= RELBR;
|
||||
#endif
|
||||
#ifdef WORDS_REVERSED
|
||||
relo->or_type |= RELWR;
|
||||
#endif
|
||||
relo->or_type |= ( pcrel) ? RELPC : S_UND;
|
||||
relo->or_sect = S_MIN + conv_seg( cur_seg);
|
||||
relo->or_nami = find_sym(sym, REFERENCE);
|
||||
relo->or_addr = cur_value();
|
||||
gen2( (pcrel) ? off - ( cur_value() + 2) : off);
|
||||
|
||||
relo++;
|
||||
}
|
||||
35
util/ceg/ce_back/obj_back/reloc4.c
Normal file
35
util/ceg/ce_back/obj_back/reloc4.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <em.h>
|
||||
#include <out.h>
|
||||
#include <system.h>
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
#include "header.h"
|
||||
|
||||
reloc4( sym, off, pcrel)
|
||||
char *sym;
|
||||
arith off;
|
||||
int pcrel;
|
||||
{
|
||||
if ( relo - reloc_info >= size_reloc)
|
||||
mem_relo();
|
||||
|
||||
relo->or_type = RELO4;
|
||||
#ifdef BYTES_REVERSED /* Nog optimaliseren?? */
|
||||
relo->or_type |= RELBR;
|
||||
#endif
|
||||
#ifdef WORDS_REVERSED
|
||||
relo->or_type |= RELWR;
|
||||
#endif
|
||||
relo->or_type |= ( pcrel) ? RELPC : S_UND;
|
||||
relo->or_sect = S_MIN + conv_seg( cur_seg);
|
||||
relo->or_nami = find_sym(sym, REFERENCE);
|
||||
relo->or_addr = cur_value();
|
||||
gen4( (pcrel) ? off - ( cur_value() + 4) : off);
|
||||
|
||||
/* print( "r %s r %ld s %d in %d adrr %ld off %ld\n",
|
||||
sym, pcrel, cur_seg, relo->or_nami, relo->or_addr,
|
||||
(pcrel) ? off-cur_value() : off);
|
||||
*/
|
||||
|
||||
relo++;
|
||||
}
|
||||
91
util/ceg/ce_back/obj_back/relocation.c
Normal file
91
util/ceg/ce_back/obj_back/relocation.c
Normal file
@@ -0,0 +1,91 @@
|
||||
#include <system.h>
|
||||
#include <out.h>
|
||||
#include "back.h"
|
||||
|
||||
#define seg_index( s) ( nname - SEGBSS - 1 + s)
|
||||
|
||||
long get4();
|
||||
long base_adres();
|
||||
extern short get2();
|
||||
extern char get1();
|
||||
|
||||
|
||||
do_local_relocation()
|
||||
{
|
||||
register struct outrelo *ptr;
|
||||
register int s;
|
||||
|
||||
for ( ptr = reloc_info; ptr < relo; ptr++) {
|
||||
s = ptr->or_nami;
|
||||
if ( symbol_table[ s].on_valu != -1)
|
||||
do_relo(&symbol_table[ s], ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do_relo(np,rp)
|
||||
struct outname *np;
|
||||
struct outrelo *rp;
|
||||
{
|
||||
long oldval,newval;
|
||||
char *sect;
|
||||
|
||||
switch( rp->or_sect - S_MIN) {
|
||||
case SEGTXT:
|
||||
sect = text_area;
|
||||
break;
|
||||
case SEGCON:
|
||||
sect = data_area;
|
||||
break;
|
||||
default:
|
||||
fprint( STDERR,
|
||||
"do_local_relo(): bad section %d\n",
|
||||
rp->or_sect - S_MIN);
|
||||
break;
|
||||
}
|
||||
|
||||
/* nu reloceren tov het segment waar het symbool in voorkomt! */
|
||||
if ( rp->or_type & RELO4) {
|
||||
oldval = get4( sect, rp->or_addr);
|
||||
newval = oldval + np->on_valu;
|
||||
put4( sect, rp->or_addr, newval);
|
||||
|
||||
rp->or_nami = seg_index(
|
||||
( symbol_table[ rp->or_nami].on_type & S_TYP) - S_MIN);
|
||||
}
|
||||
else if ( rp->or_type & RELO2) {
|
||||
oldval = (long) get2( sect, rp->or_addr);
|
||||
newval = oldval + np->on_valu;
|
||||
put2( sect, rp->or_addr, (int) newval);
|
||||
|
||||
rp->or_nami = seg_index(
|
||||
( symbol_table[ rp->or_nami].on_type & S_TYP) - S_MIN);
|
||||
}
|
||||
else if ( rp->or_type & RELO1) {
|
||||
oldval = (long) get1( sect, rp->or_addr);
|
||||
newval = oldval + np->on_valu;
|
||||
put1( sect, rp->or_addr, (char) newval);
|
||||
|
||||
rp->or_nami = seg_index(
|
||||
( symbol_table[ rp->or_nami].on_type & S_TYP) - S_MIN);
|
||||
}
|
||||
else
|
||||
print( STDERR, "do_relo() : bad relocation size\n");
|
||||
/* print(
|
||||
"reloc %s adrr=%ld sect=%ld oldval=%ld newval=%ld def = %ld\n",
|
||||
np->on_foff+string_area, rp->or_addr, rp->or_sect-S_MIN, oldval, newval, np->on_valu);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
long base_adres( seg)
|
||||
int seg;
|
||||
{
|
||||
switch ( seg) {
|
||||
case SEGTXT : return( 0);
|
||||
case SEGCON : return( text-text_area);
|
||||
case SEGBSS : return( text-text_area + data-data_area);
|
||||
default : fprint( STDERR, "base_adres() wrong seg %d\n", seg);
|
||||
}
|
||||
}
|
||||
16
util/ceg/ce_back/obj_back/rom2.c
Normal file
16
util/ceg/ce_back/obj_back/rom2.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
rom2( w)
|
||||
TWO_BYTES w;
|
||||
{
|
||||
#ifdef BYTES_REVERSED
|
||||
rom1( (char) ( ( unsigned short)w>>8));
|
||||
rom1( (char) w);
|
||||
#else
|
||||
rom1( (char) w);
|
||||
rom1( (char) ( ( unsigned short)w>>8));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
15
util/ceg/ce_back/obj_back/rom4.c
Normal file
15
util/ceg/ce_back/obj_back/rom4.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "mach.h"
|
||||
|
||||
rom4( l)
|
||||
FOUR_BYTES l;
|
||||
{
|
||||
#ifdef WORDS_REVERSED
|
||||
rom2( (short) ((unsigned long)l>>16));
|
||||
rom2( (short) l);
|
||||
#else
|
||||
rom2( (short) l);
|
||||
rom2( (short) ((unsigned long)l>>16));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
14
util/ceg/ce_back/obj_back/set_global.c
Normal file
14
util/ceg/ce_back/obj_back/set_global.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <out.h>
|
||||
#include "data.h"
|
||||
#include "header.h"
|
||||
|
||||
set_global_visible(sym)
|
||||
char *sym;
|
||||
{
|
||||
int i;
|
||||
|
||||
i = find_sym(sym, REFERENCE);
|
||||
symbol_table[i].on_type |= S_EXT;
|
||||
}
|
||||
|
||||
|
||||
14
util/ceg/ce_back/obj_back/set_local.c
Normal file
14
util/ceg/ce_back/obj_back/set_local.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <out.h>
|
||||
#include "data.h"
|
||||
#include "header.h"
|
||||
|
||||
set_local_visible(sym)
|
||||
char *sym;
|
||||
{
|
||||
int i;
|
||||
|
||||
i = find_sym(sym, REFERENCE);
|
||||
symbol_table[i].on_type &= (~S_EXT);
|
||||
}
|
||||
|
||||
|
||||
14
util/ceg/ce_back/obj_back/switchseg.c
Normal file
14
util/ceg/ce_back/obj_back/switchseg.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "data.h"
|
||||
|
||||
switchseg( seg)
|
||||
int seg;
|
||||
|
||||
/* De EM definitie eist dat pseudoinstructies gealigned worden op
|
||||
* woordgrens.
|
||||
*/
|
||||
{
|
||||
if ( seg == cur_seg)
|
||||
return;
|
||||
cur_seg = seg;
|
||||
align_word();
|
||||
}
|
||||
18
util/ceg/ce_back/obj_back/symboldef.c
Normal file
18
util/ceg/ce_back/obj_back/symboldef.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <out.h>
|
||||
#include <system.h>
|
||||
#include "data.h"
|
||||
#include "back.h"
|
||||
#include "header.h"
|
||||
|
||||
symbol_definition(sym)
|
||||
char *sym;
|
||||
{
|
||||
int i;
|
||||
|
||||
i = find_sym( sym, SYMBOL_DEFINITION);
|
||||
(symbol_table + i)->on_valu = cur_value();
|
||||
(symbol_table + i)->on_type |= (S_MIN + conv_seg( cur_seg));
|
||||
/* print( "s %s in %d seg %d addr %ld\n", sym , i, conv_seg( cur_seg),
|
||||
cur_value()); */
|
||||
}
|
||||
|
||||
99
util/ceg/ce_back/obj_back/symtable.c
Normal file
99
util/ceg/ce_back/obj_back/symtable.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <out.h>
|
||||
#include <system.h>
|
||||
#include "hash.h"
|
||||
#include "header.h"
|
||||
#include "back.h"
|
||||
|
||||
|
||||
int string_lengte = 0,
|
||||
index_symbol_table = -1;
|
||||
|
||||
struct Hashitem *Hashitems ;
|
||||
int Hashtab[ MAXHASH];
|
||||
|
||||
|
||||
int find_sym( sym, isdef)
|
||||
char *sym;
|
||||
int isdef;
|
||||
{
|
||||
register char *p;
|
||||
register struct outname *s;
|
||||
register struct Hashitem *ip;
|
||||
register int h;
|
||||
|
||||
if ( index_symbol_table != -1 ) {
|
||||
s = symbol_table + index_symbol_table;
|
||||
if ( sym == s->on_foff + string_area) {
|
||||
if ( (s->on_valu == -2) && ( isdef == REFERENCE)) {
|
||||
s->on_type = S_EXT;
|
||||
s->on_valu = -1;
|
||||
}
|
||||
return( index_symbol_table);
|
||||
}
|
||||
}
|
||||
|
||||
h = Hash(sym);
|
||||
for ( ip = Hashtab[h] + Hashitems ; ip != Hashitems;
|
||||
ip = (ip->hs_next) + Hashitems) {
|
||||
s = symbol_table + ip->hs_nami;
|
||||
if (strcmp(sym, (s->on_foff) + string_area) == 0) {
|
||||
if ( (s->on_valu == -2) && (isdef == REFERENCE)) {
|
||||
s->on_type = S_EXT;
|
||||
s->on_valu = -1;
|
||||
}
|
||||
return ip->hs_nami;
|
||||
}
|
||||
}
|
||||
|
||||
if ( nname >= size_symbol)
|
||||
mem_symbol_hash();
|
||||
|
||||
s = symbol_table + nname;
|
||||
ip = Hashitems + nname + 1; /* skip the first entry */
|
||||
|
||||
if (isdef == REFERENCE) {
|
||||
s->on_type = S_EXT;
|
||||
s->on_valu = -1;
|
||||
}
|
||||
if (isdef == STORE_STRING) {
|
||||
s->on_type = S_UND;
|
||||
s->on_valu = -2;
|
||||
}
|
||||
|
||||
ip->hs_nami = nname;
|
||||
ip->hs_next = Hashtab[h];
|
||||
Hashtab[h] = ip - Hashitems;
|
||||
|
||||
if ( sym == string)
|
||||
string += string_lengte;
|
||||
else { /* zie C_fil, C_lin, C_lni */
|
||||
string_lengte = 0;
|
||||
for( p=sym; *p != '\0' ; p++) {
|
||||
if ( (string - string_area) >= size_string)
|
||||
mem_string();
|
||||
*string++ = *p;
|
||||
string_lengte++;
|
||||
}
|
||||
}
|
||||
if ( (string - string_area) >= size_string)
|
||||
mem_string();
|
||||
*string++ = '\0';
|
||||
s->on_foff = string - (string_lengte + 1) - string_area;
|
||||
|
||||
return nname++;
|
||||
}
|
||||
|
||||
|
||||
int Hash(sym)
|
||||
char *sym;
|
||||
{
|
||||
register unsigned h;
|
||||
register c;
|
||||
|
||||
h = 0;
|
||||
while (c = *sym++) {
|
||||
h <<= 2;
|
||||
h += c;
|
||||
}
|
||||
return (h % MAXHASH);
|
||||
}
|
||||
15
util/ceg/ce_back/obj_back/text2.c
Normal file
15
util/ceg/ce_back/obj_back/text2.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "mach.h"
|
||||
#include "back.h"
|
||||
|
||||
text2( w)
|
||||
TWO_BYTES w;
|
||||
{
|
||||
#ifdef BYTES_REVERSED
|
||||
text1( (char) ( ( unsigned short)w>>8));
|
||||
text1( (char) w);
|
||||
#else
|
||||
text1( (char) w);
|
||||
text1( (char) ( ( unsigned short)w>>8));
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user