Initial revision

This commit is contained in:
ceriel 1988-09-15 09:49:22 +00:00
parent 091f3dbebf
commit a5f48d6493
14 changed files with 1737 additions and 0 deletions

13
mach/vax4/ce/.distr Normal file
View file

@ -0,0 +1,13 @@
EM_table
Make.back
Makefile
as.c
as.h
as_table
do_close.c
do_open.c
end_back.c
mach.c
mach.h
output.c
relocation.c

729
mach/vax4/ce/EM_table Normal file
View file

@ -0,0 +1,729 @@
/******************************************************************************/
/* */
/* Group 1 : Load instructions */
/* */
/******************************************************************************/
C_loc ==> "pushl ~$1".
C_ldc ==> "movq ~$1, -(sp)".
C_lol
$1 < 0 ==> "pushl $1(fp)".
default ==> "pushl $1+4(ap)".
C_loe.. ==> "pushl $1 + $2".
C_lil
$1 < 0 ==> "movl $1(fp), r0";
"pushl (r0)".
default ==> "movl $1+4(ap), r0";
"pushl (r0)".
C_lof ==> "movl (sp)+, r0";
"pushl $1(r0)".
C_lal
$1 < 0 ==> "pushal $1(fp)".
default ==> "pushal $1+4(ap)".
C_lae.. ==> "pushal $1 + $2".
C_lxl
$1 == 0 ==> "pushl fp".
$1 == 1 ==> "pushl 4(ap)".
default ==> "movl ~$1, r0";
"jsb .lxl";
"pushl r0".
C_lxa
$1 == 0 ==> "addl3 ~4, ap, -(sp)".
$1 == 1 ==> "movl 4(ap), r0";
"jsb .lpb";
"pushl r0".
default ==> "movl ~$1, r0";
"jsb .lxa";
"pushl r0".
C_loi
$1 == 1 ==> "movl (sp)+, r0";
"clrl -(sp)";
"movb (r0), (sp)".
$1 == 2 ==> "movl (sp)+, r0";
"clrl -(sp)";
"movw (r0), (sp)".
$1 == 4 ==> "movl (sp)+, r0";
"pushl (r0)".
$1 == 8 ==> "movl (sp)+, r0";
"movq (r0), -(sp)".
$1 % 4 == 0 ==> "movl (sp)+, r0";
"movl ~$1/4, r1";
"addl2 ~$1, r0";
"2:";
"movl -(r0), -(sp)";
"sobgtr r1, 2b".
default ==> arg_error( "loi", $1).
C_los ==> "movl ~$1, r0";
"jsb .los".
C_los_narg ==> "movl (sp)+, r0";
"jsb .los".
C_ldl
$1 < 0 ==> "movq $1(fp), -(sp)".
default ==> "movq $1+4(ap), -(sp)".
C_lde.. ==> "movq $1 + $2, -(sp)".
C_ldf ==> "movl (sp)+, r0";
"movq $1(r0), -(sp)".
C_lpi ==> "pushal $1".
/******************************************************************************/
/* */
/* Group 2 : Store instructions */
/* */
/******************************************************************************/
C_stl
$1 < 0 ==> "movl (sp)+, $1(fp)".
default ==> "movl (sp)+, $1+4(ap)".
C_ste.. ==> "movl (sp)+, $1 + $2".
C_sil
$1 < 0 ==> "movl $1(fp) , r0";
"movl (sp)+, (r0)".
default ==> "movl $1+4(ap), r0";
"movl (sp)+, (r0)".
C_stf ==> "movl (sp)+, r0";
"movl (sp)+, $1(r0)".
C_sti
$1 == 1 ==> "movl (sp)+, r0";
"movl (sp)+, r1";
"movb r1, (r0)".
$1 == 2 ==> "movl (sp)+, r0";
"movl (sp)+, r1";
"movw r1, (r0)".
$1 == 4 ==> "movl (sp)+, r0";
"movl (sp)+, (r0)".
$1 == 8 ==> "movl (sp)+, r0";
"movq (sp)+, (r0)".
$1 % 4 == 0 ==> "movl (sp)+, r0";
"movl ~$1/4, r1";
"2:";
"movl (sp)+, (r0)+";
"sobgtr r1, 2b".
default ==> arg_error( "sti", (arith) $1).
C_sts ==> "movl ~$1, r0";
"jsb .sts".
C_sts_narg ==> "movl (sp)+, r0";
"jsb .sts".
C_sdl
$1 < 0 ==> "movq (sp)+, $1(fp)".
default ==> "movq (sp)+, $1+4(ap)".
C_sde.. ==> "movq (sp)+, $1 + $2".
C_sdf ==> "movl (sp)+, r0";
"movq (sp)+, $1(r0)".
/******************************************************************************/
/* */
/* Group 3 : Integer arithmetic */
/* */
/******************************************************************************/
C_adi
$1 == 4 ==> "addl2 (sp)+, (sp)".
default ==> arg_error( "adi", $1).
C_sbi
$1 == 4 ==> "subl2 (sp)+, (sp)".
default ==> arg_error( "sbi", $1).
C_mli
$1 == 4 ==> "mull2 (sp)+, (sp)".
default ==> arg_error( "mli", $1).
C_dvi
$1 == 4 ==> "divl2 (sp)+, (sp)".
default ==> arg_error( "dvi", $1).
C_rmi
$1 == 4 ==> "divl3 (sp), 4(sp), r0";
"mull2 (sp)+, r0";
"subl2 r0, (sp)".
default ==> arg_error( "rmi", $1).
C_ngi
$1 == 4 ==> "mnegl (sp), (sp)".
default ==> arg_error( "ngi", $1).
C_sli
$1 == 4 ==> "clrl r0";
"cvtlb (sp)+, r0";
"ashl r0, (sp), (sp)".
default ==> arg_error( "sli", $1).
C_sri
$1 == 4 ==> "mnegl (sp)+, r0";
"clrl r1";
"cvtlb r0, r1";
"ashl r1, (sp), (sp)".
default ==> arg_error( "sri", $1).
/******************************************************************************/
/* */
/* Group 4 : Unsigned arithmetic */
/* */
/******************************************************************************/
C_adu ==> C_adi( w).
C_sbu ==> C_sbi( w).
C_mlu ==> C_mli( w).
C_dvu
$1 == 4 ==> "jsb .dvu4";
"pushl r0".
default ==> arg_error( "dvu", $1).
C_rmu
$1 == 4 ==> "jsb .rmu4";
"pushl r0".
default ==> arg_error( "rmu", $1).
C_slu ==> C_sli( w).
C_sru ==> "movl ~$1, r0";
"jsb .sru".
/******************************************************************************/
/* */
/* Group 5 : Floating point arithmetic */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* Group 6 : Pointer arithmetic */
/* */
/******************************************************************************/
C_adp ==> "addl2 ~$1, (sp)".
C_ads
$1 == 4 ==> "addl2 (sp)+, (sp)".
default ==> arg_error( "ads", $1).
C_sbs
$1 == 4 ==> "subl2 (sp)+, (sp)".
default ==> arg_error( "sbs", $1).
/******************************************************************************/
/* */
/* Group 7 : Increment/decrement/zero */
/* */
/******************************************************************************/
C_inc ==> "incl (sp)".
C_inl
$1 < 0 ==> "incl $1(fp)".
default ==> "incl $1+4(ap)".
C_ine.. ==> "incl $1 + $2".
C_dec ==> "decl (sp)".
C_del
$1 < 0 ==> "decl $1(fp)".
default ==> "decl $1+4(ap)".
C_dee.. ==> "decl $1 + $2".
C_zrl
$1 < 0 ==> "clrl $1(fp)".
default ==> "clrl $1+4(ap)".
C_zre.. ==> "clrl $1 + $2".
C_zrf
$1 == 4 ==> "clrl -(sp)".
$1 == 8 ==> "clrq -(sp)".
default ==> arg_error( "zrf", $1).
C_zer
$1 == 4 ==> "clrl -(sp)".
$1 == 8 ==> "clrq -(sp)".
default ==> "movl ~$1/4, r0";
"1:";
"clrl -(sp)";
"sobgtr r0, 1b".
/******************************************************************************/
/* */
/* Group 8 : Convert */
/* */
/******************************************************************************/
C_cii ==> "jsb .cii".
C_cui ==> "jsb .cui".
C_cfi ==> "jsb .cfi".
C_cif ==> "jsb cif".
C_cuf ==> "jsb .cuf".
C_cff ==> "jsb .cff".
C_ciu ==> "jsb .cuu".
C_cuu ==> "jsb .cuu ".
C_cfu ==> "jsb .cfu".
/******************************************************************************/
/* */
/* Group 9 : Logical */
/* */
/******************************************************************************/
C_and
$1 == 4 ==> "mcoml (sp), (sp)";
"bicl2 (sp)+, (sp)".
default ==> "movl ~$1/4, r0";
"addl3 ~$1, sp, r1";
"1:";
"mcoml (sp), (sp)";
"bicl2 (sp)+, (r1)+";
"sobgtr r0, 1b".
C_ior
$1 == 4 ==> "bisl2 (sp)+, (sp)".
default ==> "movl ~$1/4, r0";
"addl3 ~$1, sp, r1";
"1:";
"bisl2 (sp)+, (r1)+";
"sobgtr r0, 1b".
C_xor
$1 == 4 ==> "xorl2 (sp)+, (sp)".
default ==> "movl ~$1/4, r0";
"addl3 ~$1, sp, r1";
"1:";
"xorl2 (sp)+, (r1)+";
"sobgtr r0, 1b".
C_com
$1 == 4 ==> "mcoml (sp), (sp)".
default ==> "movl ~$1, r0";
"jsb .com".
C_rol
$1 == 4 ==> "clrl r0";
"cvtlb (sp)+, r0";
"rotl r0, (sp), (sp)".
default ==> arg_error( "rol", $1).
C_ror
$1 == 4 ==> "mnegl (sp)+, r0";
"clrl r1";
"cvtlb r0, r1";
"rotl r1, (sp), (sp)".
default ==> arg_error( "rol", $1).
/******************************************************************************/
/* */
/* Group 10 : Sets */
/* */
/******************************************************************************/
C_inn
$1 == 4 ==> "mnegl (sp)+, r0";
"clrl r1";
"cvtlb r0, r1";
"ashl r1, (sp), (sp)";
"bicl2 ~~1, (sp)".
default ==> "movl ~$1, r0";
"jsb .inn";
"pushl r1".
C_inn_narg ==> "movl (sp)+, r0";
"jsb .inn";
"pushl r1".
C_set
$1 == 4 ==> "clrl r0";
"cvtlb (sp)+, r0";
"ashl r0, ~1, -(sp)".
default ==> "movl ~$1, r0";
"jsb .setx".
C_set_narg ==> "movl (sp)+, r0";
"jsb .setx".
/******************************************************************************/
/* */
/* Group 11 : Array */
/* */
/******************************************************************************/
C_lar
$1 == 4 ==> "jsb .lar4".
default ==> "movl ~$1, r0";
"jsb .lar".
C_lar_narg ==> "movl (sp)+, r0";
"jsb .lar".
C_sar
$1 == 4 ==> "jsb .sar4".
default ==> "movl ~$1, r0";
"jsb .sar".
C_sar_narg ==> "movl (sp)+, r0";
"jsb .sar".
C_aar
$1 == 4 ==> "jsb .aar4";
"pushl r0".
default ==> "movl ~$1, r0";
"jsb .aar";
"pushl r0".
C_aar_narg ==> "movl (sp)+, r0";
"jsb .aar";
"pushl r0".
/******************************************************************************/
/* */
/* Group 12 : Compare */
/* */
/******************************************************************************/
C_cmi
$1 == 4 ==> /* bug : "subl2 (sp)+, (sp)". */
"clrl r0";
"cmpl (sp)+, (sp)+";
"beql 2f";
"bgtr 1f";
"incl r0";
"br 2f";
"1 : decl r0";
"2 : pushl r0".
default ==> arg_error( "cmi", $1).
C_cmu
$1 == 4 ==> /* bug : "subl2 (sp)+, (sp)". */
"clrl r0";
"cmpl (sp)+, (sp)+";
"beql 2f";
"bgtru 1f";
"incl r0";
"br 2f";
"1 : decl r0";
"2 : pushl r0".
default ==> "movl ~$1, r0";
"jsb .cmu";
"pushl r0".
C_cmu_narg ==> "movl (sp)+, r0";
"jsb .cmu";
"pushl r0".
C_cms ==> "movl ~$1, r0";
"jsb .cms";
"pushl r0".
C_cms_narg ==> "movl (sp)+, r0";
"jsb .cms";
"pushl r0".
C_cmp ==> /* bug : "subl2 (sp)+, (sp)". */
"clrl r0";
"cmpl (sp)+, (sp)+";
"beql 2f";
"bgtru 1f";
"incl r0";
"br 2f";
"1 : decl r0";
"2 : pushl r0".
C_tlt ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"blss 1f";
"clrl (sp)";
"1:".
C_tle ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"bleq 1f";
"clrl (sp)";
"1:".
C_teq ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"beql 1f";
"clrl (sp)";
"1:".
C_tne ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"bneq 1f";
"clrl (sp)";
"1:".
C_tge ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"bgeq 1f";
"clrl (sp)";
"1:".
C_tgt ==> "movl (sp)+, r0";
"movl ~1, -(sp)";
"tstl r0";
"bgtr 1f";
"clrl (sp)";
"1:".
/******************************************************************************/
/* */
/* Group 13 : Branch */
/* */
/******************************************************************************/
C_bra ==> "jmp $1".
C_blt ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jlss $1".
C_ble ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jleq $1".
C_beq ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jeql $1".
C_bne ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jneq $1".
C_bge ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jgeq $1".
C_bgt ==> "movl (sp)+, r0";
"cmpl (sp)+, r0";
"jgtr $1".
C_zlt ==> "tstl (sp)+";
"jlss $1".
C_zle ==> "tstl (sp)+";
"jleq $1".
C_zeq ==> "tstl (sp)+";
"jeql $1".
C_zne ==> "tstl (sp)+";
"jneq $1".
C_zge ==> "tstl (sp)+";
"jgeq $1".
C_zgt ==> "tstl (sp)+";
"jgtr $1".
/******************************************************************************/
/* */
/* Group 14 : Procedure call instructions */
/* */
/******************************************************************************/
C_cai ==> "movl (sp)+, r0";
"calls ~0, (r0)".
C_cal ==> "calls ~0, $1".
C_lfr
$1 == 4 ==> "pushl r0".
$1 == 8 ==> "movq r0, -(sp)".
default ==> arg_error( "lfr", $1).
C_ret
$1 == 0 ==> "ret".
$1 == 4 ==> "movl (sp)+, r0";
"ret".
$1 == 8 ==> "movq (sp)+, r0";
"ret".
default ==> arg_error( "ret", $1).
/******************************************************************************/
/* */
/* Group 15 : Miscellaneous instructions */
/* */
/******************************************************************************/
C_asp ==> "addl2 ~$1, sp".
C_ass
$1 == 4 ==> "addl2 (sp)+, sp".
default ==> "movl ~$1, r2";
"jsb .ass".
C_ass_narg ==> "movl (sp)+, r2";
"jsb .ass".
C_blm
$1 == 4 ==> "movl (sp)+, r0";
"movl (sp)+, r1";
"movl (r1), (r0)".
$1 == 8 ==> "movl (sp)+, r0";
"movl (sp)+, r1";
"movq (r1), (r0)".
default ==> "movl (sp)+, r0";
"movl (sp)+, r1";
"movl ~$1/4, r2";
"1:";
"movl (r1)+, (r0)+";
"sobgtr r2, 1b".
C_bls
$1 == 4 ==> "movl ~4, r0";
"jsb .bls".
default ==> arg_error( "bls", $1).
C_csa
$1 == 4 ==> "jmp .csa4".
default ==> "movl ~$1, r0";
"jmp .csa".
C_csb
$1 == 4 ==> "jmp .csb4".
default ==> "movl ~$1, r0";
"jmp .csb".
C_dch ==> "movl (sp)+, r0";
"pushl (r0)".
C_dup
$1 == 4 ==> "pushl (sp)".
$1 == 8 ==> "movq (sp), -(sp)".
default ==> "movl ~$1/4, r0";
"addl3 ~$1, sp, r1";
"1:";
"movl -(r1), -(sp)";
"sobgtr r0, 1b".
C_dus
$1 == 4 ==> "movl (sp)+, r0";
"addl3 r0, sp, r1";
"ashl ~-2, r0, r0";
"1:";
"movl -(r1), -(sp)";
"sobgtr r0, 1b".
default ==> arg_error( "dus", $1).
C_exg ==> "movl ~$1, r0";
"jsb .exg".
C_fil.. ==> "moval $1 + $2, hol0 + 4".
C_gto.. ==> "pushal $1+$2";
"jmp .gto".
C_lim ==> "movl .trpim, -(sp)".
C_lin ==> "movl ~$1, hol0".
C_lni ==> "incl hol0".
C_lor
$1 == 0 ==> "pushl fp".
$1 == 1 ==> "pushl sp".
$1 == 2 ==> "pushl .reghp".
default ==> arg_error( "lor", $1).
C_lpb ==> "movl (sp)+, r0";
"jsb .lpb";
"pushl r0".
C_mon ==> "jsb .mon".
C_nop ==> .
C_rck
$1 == 4 ==> "jsb .rck4".
default ==> "movl ~$1, r0";
"jsb .rck".
C_rck_narg ==> "movl (sp)+, r0";
"jsb .rck".
C_rtt ==> "ret".
C_sig ==> "jsb .sig".
C_sim ==> "jsb .sim".
C_str
$1 == 0 ==> "movl (sp)+, fp".
$1 == 1 ==> "movl (sp)+, sp".
$1 == 2 ==> "jsb .strhp".
default ==> arg_error( "str", $1).
C_trp ==> "jsb .trp".
/*****************************************************************************/
..icon $2 == 1 ==> gen1( (char) atoi( $1)).
$2 == 2 ==> gen2( (short) atoi( $1)).
$2 == 4 ==> gen4( (long) atol( $1)).
default ==> arg_error( "icon", $2).
..ucon $2 == 1 ==> gen1( (char) atoi( $1)).
$2 == 2 ==> gen2( (short) atoi( $1)).
$2 == 4 ==> gen4( (long) atol( $1)).
default ==> arg_error( "icon", $2).
/*****************************************************************************/
prolog ==> text2( 0x0).
jump ==> "jmp $1".
locals
$1 == 0 ==> .
$1 == 4 ==> "clrq -(sp)".
$1 == 8 ==> "clrq -(sp)".
default ==> "subl2 ~$1, sp".

103
mach/vax4/ce/Make.back Normal file
View file

@ -0,0 +1,103 @@
EMHOME=../../../..
CEG=$(EMHOME)/lib/ceg
SOURCE=$(CEG)/ce_back/obj_back
CFLAGS=-O
CC=cc
IDIRS=-I.\
-I..\
-I$(EMHOME)/h\
-I$(EMHOME)/modules/h
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) $(CFLAGS) -c $(IDIRS) $(SOURCE)/data.c
memory.o :data.h back.h header.h $(SOURCE)/memory.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/memory.c
con2.o : data.h back.h header.h $(SOURCE)/con2.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/con2.c
con4.o : data.h back.h header.h $(SOURCE)/con4.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/con4.c
relocation.o : data.h back.h ../mach.h ../relocation.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. ../relocation.c
do_open.o : data.h back.h ../mach.h ../do_open.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. ../do_open.c
do_close.o : data.h back.h ../mach.h ../do_close.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. ../do_close.c
gen1.o : data.h back.h header.h $(SOURCE)/gen1.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/gen1.c
gen2.o : data.h back.h header.h $(SOURCE)/gen2.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/gen2.c
gen4.o : data.h back.h header.h $(SOURCE)/gen4.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/gen4.c
init_back.o : data.h back.h ../mach.h $(SOURCE)/init_back.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/init_back.c
end_back.o : data.h back.h ../mach.h ../end_back.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. ../end_back.c
mysprint.o : data.h back.h data.h $(SOURCE)/mysprint.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/mysprint.c
output.o : data.h back.h ../mach.h ../output.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. ../output.c
reloc1.o : data.h back.h header.h $(SOURCE)/reloc1.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/reloc1.c
reloc2.o : data.h back.h header.h $(SOURCE)/reloc2.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/reloc2.c
reloc4.o : data.h back.h header.h $(SOURCE)/reloc4.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/reloc4.c
rom2.o : data.h back.h header.h $(SOURCE)/rom2.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/rom2.c
rom4.o : data.h back.h header.h $(SOURCE)/rom4.c
$(CC) $(CFLAGS) -c $(IDIRS) $(SOURCE)/rom4.c
set_global.o : data.h back.h ../mach.h $(SOURCE)/set_global.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/set_global.c
set_local.o : data.h back.h ../mach.h $(SOURCE)/set_local.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/set_local.c
switchseg.o : data.h back.h ../mach.h $(SOURCE)/switchseg.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/switchseg.c
symboldef.o : data.h back.h ../mach.h $(SOURCE)/symboldef.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/symboldef.c
text2.o : data.h back.h ../mach.h $(SOURCE)/text2.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/text2.c
text4.o : data.h back.h ../mach.h $(SOURCE)/text4.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/text4.c
symtable.o : data.h back.h ../mach.h $(SOURCE)/symtable.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/symtable.c
extnd.o : data.h back.h ../mach.h $(SOURCE)/extnd.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/extnd.c
misc.o : data.h back.h ../mach.h $(SOURCE)/misc.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/misc.c
label.o : data.h back.h ../mach.h $(SOURCE)/label.c
$(CC) $(CFLAGS) -c $(IDIRS) -I.. $(SOURCE)/label.c

16
mach/vax4/ce/Makefile Normal file
View file

@ -0,0 +1,16 @@
EMHOME=../../..
BACK=$(EMHOME)/lib/ceg/ce_back
install : back.a
install_ceg
clean:
rm -rf back.a back
back.a :
-mkdir back
cp $(BACK)/obj_back/*h back
cp Make.back back/Makefile
( cd back; make)
ar r back.a back/*o;
-ranlib back.a

245
mach/vax4/ce/as.c Normal file
View file

@ -0,0 +1,245 @@
#include <ctype.h>
#include "as.h"
#define DOLLAR '$'
#define LEFT '('
#define RIGHT ')'
/*****************************************************************************/
/* Een constraint-function */
const( arg)
struct t_operand *arg;
{
return( arg->type == CONST);
}
/*****************************************************************************/
/* decode_operand() recognizes the follwing assembly-argumnets:
$const : CONST
register : REGISTER
-(register) : AUTO_DEC
(register)+ : AUTO_INC
(register) : REG_DEF
index(register) : IND_REG
label+offset : LABEL
label[b|f] : L_ILB
*/
/* An assembly instruction has at most 5 arguments.
* This is for the time being.
*/
char lab_buf[4][256],
ind_buf[4][256],
*match(), *lab(), *ind(), *end_arg();
static int n_index = -1;
process_label( l)
char *l;
{
}
process_mnemonic( m)
char *m;
{
}
process_operand( arg, op)
char *arg;
struct t_operand *op;
{
char *einde;
if ( n_index == 3)
n_index = 0;
else
n_index++;
if ( arg[0] == '~' ) {
op->type = CONST;
op->const = arg+1;
}
else if ( is_reg( arg, &(op->num)) ) {
op->type = REGISTER;
}
else if ((arg[0]=='-') && (arg[1] == LEFT) &&
is_reg( arg+2,&(op->num))) {
op->type = AUTO_DEC;
}
else if( ( arg[0] == LEFT) && is_reg( arg+1, &(op->num))) {
arg = match( arg, RIGHT);
if ( *(arg+1) == '+')
op->type = AUTO_INC;
else
op->type = REG_DEF;
}
else {
einde = end_arg( arg);
if ( (*einde == 'b' || *einde == 'f') && isdigit( *(einde-1))) {
*einde = '\0';
op->type = L_ILB;
op->offset = "0";
op->lab = arg;
}
else if ( *einde == RIGHT) {
op->type = IND_REG;
arg = ind( ind_buf[ n_index], arg);
if ( is_reg( arg+1, &(op->num)))
op->index = ind_buf[ n_index];
else
fprint( STDERR, "unknown argtype %s\n", arg);
}
else {
op->type = LABEL;
arg = lab( lab_buf[ n_index], arg);
op->lab = lab_buf[ n_index];
if ( *arg == '\0')
op->offset = "0";
else
op->offset = arg+1;
}
}
}
char *ind( buf, str)
char *buf, *str;
/* Reads the index in front of '(register)'.
*/
{
while ( *str != LEFT)
*buf++ = *str++;
*buf = '\0';
return( str);
}
char *lab( buf, str)
char *buf, *str;
/* Reads 'label' in front of '+offset'.
*/
{
while ( ( *str != '+') && ( *str != '\0'))
*buf++ = *str++;
*buf = '\0';
while ( isspace( *(buf-1)) ) {
*(buf-1) = '\0';
buf--;
}
return( str);
}
int is_reg( str, num)
char *str;
int *num;
/* Is "str" a 'registers' ?
*/
{
if ( ( *str == 'a') && ( *(str+1) == 'p')) {
*num = 12;
return( TRUE);
}
else if ( ( *str == 'f') && ( *(str+1) == 'p')) {
*num = 13;
return( TRUE);
}
else if ( ( *str == 's') && ( *(str+1) == 'p')) {
*num = 14;
return( TRUE);
}
if ( *str == 'r') {
if ( isdigit( *(str+1)) && isdigit( *(str+2))) {
*num = ( *(str+1) - '0') * 10 + *(str+2) - '0';
return( TRUE);
}
else if ( isdigit( *(str+1))) {
*num = *(str+1) - '0';
return( TRUE);
}
else
return( FALSE);
}
return( FALSE);
}
char *end_arg( str)
char *str;
/* Shift to the last character of "str".
*/
{
while ( *str != '\0')
str++;
return( str-1);
}
char *match( str, sym)
char *str, sym;
{
while ( *str != sym)
str++;
return( str);
}
/******************************************************************************/
char my_buf[256];
gen_operand( op)
struct t_operand *op;
/* Generate object-code for a argument.
*/
{
switch( op->type) {
case CONST : @text1( 0x8f);
@text4( %$(op->const));
break;
case REGISTER: @text1( %d(0x50 | op->num));
break;
case REG_DEF : @text1( %d(0x60 | op->num));
break;
case AUTO_DEC : @text1( %d(0x70 | op->num));
break;
case AUTO_INC : @text1( %d(0x80 | op->num));
break;
case IND_REG : @text1( %d(0xe0 | op->num));
@text4( %$(op->index));
break;
case LABEL : @text1( 0xef);
if ( strindex( op->lab, DOLLAR)) {
@reloc4( %$(op->lab), %$(op->offset), PC_REL);
}
else if ( strindex( op->lab, LEFT)) {
@reloc4( %$(op->lab), %$(op->offset), PC_REL);
}
else {
sprint( my_buf, "\"%s\"", op->lab);
@reloc4( %$(my_buf), %$(op->offset) , PC_REL);
}
break;
case L_ILB : @text1( %dist( op->lab));
break;
default : fprint( STDERR, "error");
}
}

25
mach/vax4/ce/as.h Normal file
View file

@ -0,0 +1,25 @@
/* When generating assembly : */
#define ARITH_FMT "%ld"
#define INT_FMT "%d"
/* When generating object code : */
#define CONST 0
#define REGISTER 1
#define AUTO_DEC 2
#define AUTO_INC 3
#define REG_DEF 4
#define IND_REG 5
#define LABEL 6
#define L_ILB 7
#define TRUE 1
#define FALSE 0
#define PC_REL 1
struct t_operand {
int type, num;
char *lab, *index, *const, *offset;
};

232
mach/vax4/ce/as_table Normal file
View file

@ -0,0 +1,232 @@
addl2 src, dst ==>
@text1( 0xc0);
gen_operand( src);
gen_operand( dst).
addl3 src1, src2, dst ==>
@text1( 0xc1);
gen_operand( src1);
gen_operand( src2);
gen_operand( dst).
ashl src1, src2, dst ==>
@text1( 0x78);
gen_operand( src1);
gen_operand( src2);
gen_operand( dst).
beql l_ilb ==>
@text1( 0x13);
gen_operand( l_ilb).
jeql ilb ==>
@text1( 0x12);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
bgeq l_ilb ==>
@text1( 0x18);
gen_operand( l_ilb).
jgeq ilb ==>
@text1( 0x19);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
bgtr l_ilb ==>
@text1( 0x14);
gen_operand( l_ilb).
bgtru l_ilb ==>
@text1( 0x1a);
gen_operand( l_ilb).
jgtr ilb ==>
@text1( 0x15);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
bicl2 src, dst ==>
@text1( 0xca);
gen_operand( src);
gen_operand( dst).
bisl2 src, dst ==>
@text1( 0xc8);
gen_operand( src);
gen_operand( dst).
bleq l_ilb ==>
@text1( 0x15);
gen_operand( l_ilb).
jleq ilb ==>
@text1( 0x14);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
blss l_ilb ==>
@text1( 0x19);
gen_operand( l_ilb).
blssu l_ilb ==>
@text1( 0x1f);
gen_operand( l_ilb).
jlss ilb ==>
@text1( 0x18);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
bneq l_ilb ==>
@text1( 0x12);
gen_operand( l_ilb).
jneq ilb ==>
@text1( 0x13);
@text1( 0x06);
@text1( 0x17);
gen_operand( ilb).
br l_ilb ==>
@text1( 0x11);
gen_operand( l_ilb).
calls n : const , pro ==>
@text1( 0xfb);
@text1( %$(n->const));
gen_operand( pro).
clrl src ==>
@text1( 0xd4);
gen_operand( src).
clrq src ==>
@text1( 0x7c);
gen_operand( src).
cmpl src, dest ==>
@text1( 0xd1);
gen_operand( src);
gen_operand( dest).
cvtlb src, dst ==>
@text1( 0xf6);
gen_operand( src);
gen_operand( dst).
decl src ==>
@text1( 0xd7);
gen_operand( src).
divl2 src, dst ==>
@text1( 0xc6);
gen_operand( src);
gen_operand( dst).
divl3 src1, src2, dst ==>
@text1( 0xc7);
gen_operand( src1);
gen_operand( src2);
gen_operand( dst).
incl src ==>
@text1( 0xd6);
gen_operand( src).
jmp ilb4 ==>
@text1( 0x17);
gen_operand( ilb4).
jsb lab ==>
@text1( 0x16);
gen_operand( lab).
mcoml src, dst ==>
@text1( 0xd2);
gen_operand( src);
gen_operand( dst).
mnegl src, dst ==>
@text1( 0xce);
gen_operand( src);
gen_operand( dst).
moval src, dst ==>
@text1( 0xde);
gen_operand( src);
gen_operand( dst).
movb src, dst ==>
@text1( 0x90);
gen_operand( src);
gen_operand( dst).
movw src, dst ==>
@text1( 0xb0);
gen_operand( src);
gen_operand( dst).
movl src, dst ==>
@text1( 0xd0);
gen_operand( src);
gen_operand( dst).
movq src : const, dst ==>
@text1( 0x7d);
gen_operand( src);
@text4( 0);
gen_operand( dst).
... src , dst ==>
@text1( 0x7d);
gen_operand( src);
gen_operand( dst).
mull2 src, dst ==>
@text1( 0xc4);
gen_operand( src);
gen_operand( dst).
pushl src ==>
@text1( 0xdd);
gen_operand( src).
pushal src ==>
@text1( 0xdf);
gen_operand( src).
ret ==>
@text1( 0x04).
rotl src1, src2, dst ==>
@text1( 0x9c);
gen_operand( src1);
gen_operand( src2);
gen_operand( dst).
sobgtr tel, ilb ==>
@text1( 0xf5);
gen_operand( tel);
gen_operand( ilb).
subl2 src, dst ==>
@text1( 0xc2);
gen_operand( src);
gen_operand( dst).
tstl src ==>
@text1( 0xd5);
gen_operand( src).
xorl2 src, dst ==>
@text1( 0xcc);
gen_operand( src);
gen_operand( dst).

8
mach/vax4/ce/do_close.c Normal file
View file

@ -0,0 +1,8 @@
#include <system.h>
extern File *out_file;
do_close()
{
sys_close( out_file);
}

13
mach/vax4/ce/do_open.c Normal file
View file

@ -0,0 +1,13 @@
#include <system.h>
File *out_file;
do_open( filename)
char *filename;
{
if ( filename == (char *) '\0')
return( 0);
else
return( sys_open( filename, OP_WRITE, &out_file));
}

22
mach/vax4/ce/end_back.c Normal file
View file

@ -0,0 +1,22 @@
#include <out.h>
#include "mach.h"
#include "data.h"
#include "back.h"
#include "header.h"
end_back()
{
sync();
do_local_relocation();
output();
}
sync()
{
while ( ( text - text_area) % EM_WSIZE != 0 )
text1( '\0');
while ( ( data - data_area) % EM_WSIZE != 0 )
con1( '\0');
}

12
mach/vax4/ce/mach.c Normal file
View file

@ -0,0 +1,12 @@
#include <system.h>
#include <em.h>
#include <out.h>
#include "mach.h"
#include "back.h"
arg_error( s, arg)
char *s;
int arg;
{
fprint( STDERR, "arg_error %s %d\n", s, arg);
}

36
mach/vax4/ce/mach.h Normal file
View file

@ -0,0 +1,36 @@
#define ONE_BYTE char
#define TWO_BYTES short
#define FOUR_BYTES long
#define EM_WSIZE 4
#define EM_PSIZE 4
#define EM_BSIZE 0
#define BSS_INIT 0
#define NAME_FMT "_%s"
#define DNAM_FMT "_%s"
#define DLB_FMT "_%ld"
#define ILB_FMT "I%03d%ld"
#define HOL_FMT "hol%d"
#define ALIGN_FMT ""
#define BYTE_FMT ".byte %ld\n"
#define WORD_FMT ".word %ld\n"
#define LONG_FMT ".long %ld\n"
#define BSS_FMT ".space %ld\n"
#define SEGTXT_FMT ".text\n"
#define SEGDAT_FMT ".data\n"
#define SEGBSS_FMT ".data\n"
#define SYMBOL_DEF_FMT "%s :"
#define GLOBAL_FMT ".globl %s\n"
#define LOCAL_FMT ""
#define RELOC1_FMT ".byte %s + %ld\n"
#define RELOC2_FMT ".word %s + %ld\n"
#define RELOC4_FMT ".long %s + %ld\n"

207
mach/vax4/ce/output.c Normal file
View file

@ -0,0 +1,207 @@
#include <system.h>
#include <em.h>
#include <out.h>
#include "mach.h"
#include "back.h"
#include "data.h"
extern File *out_file;
/* This program converts an ACK a.out format to A BSD4.1 a.out.
* It is written for the a.out's generated by a code expander. So be
* carefull it is not very powerfull.
*/
#include <a.out.h>
struct exec u_header;
struct relocation_info u_reloc;
struct nlist u_name;
long ntext, ndata, nrelo, nchar, base_address();
int trsize=0, drsize=0;
output()
{
register int i;
init_unixheader();
putbuf( (char *) &u_header, 32);
putbuf( (char *) text_area, ntext);
putbuf( (char *) data_area, ndata);
for (i = 0; i < nrelo; i++) {
if ( ( reloc_info[i].or_sect-S_MIN) == SEGTXT) {
convert_reloc( &reloc_info[i], &u_reloc);
putbuf((char *) &u_reloc, 8);
}
}
for (i = 0; i < nrelo; i++) {
if (( reloc_info[i].or_sect-S_MIN) != SEGTXT) {
convert_reloc( &reloc_info[i], &u_reloc);
putbuf((char *) &u_reloc, 8);
}
}
for (i = 0; i < nname ; i++) { /* The segment names can be omitted */
convert_name( &symbol_table[i], &u_name);
putbuf((char *) &u_name, 12);
}
/* print( "size string_area %d\n", nchar); */
put_stringtablesize( nchar + 4);
putbuf((char *) string_area, nchar);
}
init_unixheader()
{
register int i;
for ( i = 0; i < (relo - reloc_info); i++)
if ( ( reloc_info[ i].or_sect - S_MIN) == SEGTXT)
trsize++;
else
drsize++;
ntext = text - text_area;
ndata = data - data_area;
nchar = string - string_area;
nrelo = relo - reloc_info;
u_header.a_magic = OMAGIC;
u_header.a_text = ntext;
u_header.a_data = ndata;
u_header.a_bss = nbss;
u_header.a_syms = nname * 12;
u_header.a_entry = 0;
u_header.a_trsize = trsize * 8;
u_header.a_drsize = drsize * 8;
/* print( "header %o %d %d %d %d %d %d %d\n",
u_header.a_magic, u_header.a_text, u_header.a_data,
u_header.a_bss, u_header.a_syms, u_header.a_entry,
u_header.a_trsize, u_header.a_drsize);
*/
}
convert_reloc( a_relo, u_relo)
struct outrelo *a_relo;
struct relocation_info *u_relo;
{
u_relo->r_address = a_relo->or_addr;
u_relo->r_symbolnum = a_relo->or_nami;
u_relo->r_pcrel = (a_relo->or_type & RELPC) >> 3;
u_relo->r_length = convert_length( (a_relo->or_type) & RELSZ);
if ( symbol_table[ a_relo->or_nami].on_valu == -1)
u_relo->r_extern = 1;
else
u_relo->r_extern = 0;
if ( symbol_table[ a_relo->or_nami].on_valu != -1) {
switch ( (symbol_table[ a_relo->or_nami].on_type & S_TYP) - S_MIN) {
case SEGTXT : u_relo->r_symbolnum = N_TEXT;
break;
case SEGCON : u_relo->r_symbolnum = N_DATA;
break;
case SEGBSS : u_relo->r_symbolnum = N_BSS;
break;
default : fprint( STDERR,
"convert_relo(): bad segment %d\n",
(symbol_table[ a_relo->or_nami].on_type & S_TYP) - S_MIN);
}
}
}
int convert_length( length)
int length;
{
if ( length & RELO1)
return( 0);
else if ( length & RELO2)
return( 1);
else if ( length & RELO4)
return( 2);
else
fprint( STDERR, "convert_length(): size is impossible %d\n",
length);
}
#define n_mptr n_un.n_name
#define n_str n_un.n_strx
convert_name( a_name, u_name)
struct outname *a_name;
struct nlist *u_name;
{
/* print( "naam is %s\n", a_name->on_foff + string_area); */
u_name->n_str = a_name->on_foff + 4;
fill_type( &(u_name->n_type), &(a_name->on_type), a_name->on_valu);
u_name->n_other = '\0';
u_name->n_desc = 0;
if ( a_name->on_valu != -1)
u_name->n_value = a_name->on_valu +
base_address( ( a_name->on_type & S_TYP) - S_MIN);
else
u_name->n_value = 0;
}
fill_type( u_type, a_type, valu)
unsigned char *u_type;
ushort *a_type;
long valu;
{
int sect;
*u_type = '\0';
*u_type |= ( *a_type & S_EXT) ? N_EXT : N_UNDF;
if ( valu != -1) {
sect = ( *a_type & S_TYP ) - S_MIN;
switch ( sect) {
case SEGTXT: *u_type |= N_TEXT;
break;
case SEGCON : *u_type |= N_DATA;
break;
case SEGBSS : *u_type |= N_BSS;
break;
default: fprint(STDERR,
"fill_type() : bad section %d\n", sect);
}
}
}
long base_address( seg)
int seg;
{
switch ( seg) {
case SEGTXT : return( 0);
break;
case SEGCON : return( text - text_area);
break;
case SEGBSS : return( text - text_area + data - data_area);
break;
default : fprint( STDERR,
"base_adres() : bad section %d\n", seg);
}
}
put_stringtablesize( n)
int n;
{
putbuf( (char *)&n, 4);
}
putbuf(buf,n)
char *buf;
long n;
{
sys_write( out_file, buf, n);
}

76
mach/vax4/ce/relocation.c Normal file
View file

@ -0,0 +1,76 @@
#include <system.h>
#include <out.h>
#include "data.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;
/* print( "n relocation records %d\n", relo - reloc_info); */
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;
}
oldval = get4( sect, rp->or_addr);
newval = oldval + np->on_valu +
base_address( (np->on_type & S_TYP) -S_MIN);
if ( rp->or_type & RELO4)
put4( sect, rp->or_addr, newval);
else if ( rp->or_type & RELO2)
put2( sect, rp->or_addr, (int) newval);
else if ( rp->or_type & RELO1)
put1( sect, rp->or_addr, (char) newval);
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);
}
}