Home | History | Annotate | Line # | Download | only in libiocs
makeiocscalls.awk revision 1.1
      1  1.1  itohy #! /usr/bin/awk -f
      2  1.1  itohy #
      3  1.1  itohy #	create IOCS call interface from iocs.h
      4  1.1  itohy #
      5  1.1  itohy #	written by Yasha (ITOH Yasufumi)
      6  1.1  itohy #	public domain
      7  1.1  itohy #
      8  1.1  itohy #	$NetBSD: makeiocscalls.awk,v 1.1 1998/09/01 19:53:54 itohy Exp $
      9  1.1  itohy 
     10  1.1  itohy BEGIN {
     11  1.1  itohy 	argsiz["l"] = 4; argsiz["w"] = 2
     12  1.1  itohy 	argsiz["lb31"] = 4; argsiz["wb8"] = 2
     13  1.1  itohy 
     14  1.1  itohy 	for (i = 0; i < 16; i++) {
     15  1.1  itohy 		reg = substr("d0d1d2d3d4d5d6d7a0a1a2a3a4a5a6a7", i*2+1, 2)
     16  1.1  itohy 		regno[reg] = i
     17  1.1  itohy 	}
     18  1.1  itohy }
     19  1.1  itohy 
     20  1.1  itohy $1 == "/*" && ($2 ~ /^[0-9a-f][0-9a-f]$/ || $2 == "(none)") {
     21  1.1  itohy 	funcnam=""
     22  1.1  itohy 	iocsno=$2
     23  1.1  itohy 	narg=0
     24  1.1  itohy 	retd2=0
     25  1.1  itohy 	err_d0=0
     26  1.1  itohy 	noret=0
     27  1.1  itohy 	c_md=0
     28  1.1  itohy 	b_super=0
     29  1.1  itohy 	sp_regst=0
     30  1.1  itohy 	b_curmod = 0
     31  1.1  itohy 	b_curpat = 0
     32  1.1  itohy 	b_scroll = 0
     33  1.1  itohy 	iocs_trap15=0
     34  1.1  itohy 	for (i = 3; i <= NF && $i != "*/" && $i != ";"; i++) {
     35  1.1  itohy 		arg[narg] = $i
     36  1.1  itohy 		narg++
     37  1.1  itohy 	}
     38  1.1  itohy 	if ($i == ";") {
     39  1.1  itohy 		# process opts
     40  1.1  itohy 		for (i++; i <= NF && $i != "*/"; i++) {
     41  1.1  itohy 			if ($i == "retd2")
     42  1.1  itohy 				retd2 = 1
     43  1.1  itohy 			else if ($i == "err_d0")
     44  1.1  itohy 				err_d0 = 1
     45  1.1  itohy 			else if ($i == "noret")
     46  1.1  itohy 				noret = 1
     47  1.1  itohy 			else if ($i == "c_md")
     48  1.1  itohy 				c_md = 1
     49  1.1  itohy 			else if ($i == "b_super")
     50  1.1  itohy 				b_super = 1
     51  1.1  itohy 			else if ($i == "sp_regst")
     52  1.1  itohy 				sp_regst = 1
     53  1.1  itohy 			else if ($i == "b_curmod")
     54  1.1  itohy 				b_curmod = 1
     55  1.1  itohy 			else if ($i == "b_curpat")
     56  1.1  itohy 				b_curpat = 1
     57  1.1  itohy 			else if ($i == "b_scroll")
     58  1.1  itohy 				b_scroll = 1
     59  1.1  itohy 			else if ($i == "trap15")
     60  1.1  itohy 				iocs_trap15 = 1
     61  1.1  itohy 			else {
     62  1.1  itohy 				print FILENAME ":" NR ": unknown opt", $i
     63  1.1  itohy 				exit(1)
     64  1.1  itohy 			}
     65  1.1  itohy 		}
     66  1.1  itohy 	}
     67  1.1  itohy 	if ($i != "*/") {
     68  1.1  itohy 		print FILENAME ":" NR ": malformed input line:" $0
     69  1.1  itohy 		exit(1)
     70  1.1  itohy 	}
     71  1.1  itohy 
     72  1.1  itohy 	# find out func name
     73  1.1  itohy 	printf "|"
     74  1.1  itohy 	for (i++; i <= NF; i++) {
     75  1.1  itohy 		printf " %s", $i
     76  1.1  itohy 		if ($i ~ /^\**IOCS_[A-Z0-9_]*$/) {
     77  1.1  itohy 			funcnam = $i
     78  1.1  itohy 			while (funcnam ~ /^\*/)
     79  1.1  itohy 				funcnam = substr(funcnam, 2, length(funcnam) -1)
     80  1.1  itohy 		}
     81  1.1  itohy 	}
     82  1.1  itohy 	print ""
     83  1.1  itohy 	if (!funcnam) {
     84  1.1  itohy 		print FILENAME ":" NR ": can't find function name"
     85  1.1  itohy 		exit(1)
     86  1.1  itohy 	}
     87  1.1  itohy 
     88  1.1  itohy 	# output assembly code
     89  1.1  itohy 	print "\t.text\n\t.even"
     90  1.1  itohy 	print "\t.globl\t_" funcnam
     91  1.1  itohy 	print "_" funcnam ":"
     92  1.1  itohy 
     93  1.1  itohy 	# SAVE REGISTERS
     94  1.1  itohy 	for (i = 0; i < 16; i++) {
     95  1.1  itohy 		savereg[i] = 0
     96  1.1  itohy 	}
     97  1.1  itohy 	for (i = 0; i < narg; i++) {
     98  1.1  itohy 		r = arg[i]
     99  1.1  itohy 		if (r ~ /^o[ad][0-7]$/)
    100  1.1  itohy 			r = substr(r, 2, 2)
    101  1.1  itohy 		else if (r ~ /^d[0-7]=/)
    102  1.1  itohy 			r = substr(r, 1, 2)
    103  1.1  itohy 		if (r != "d0" && !regno[r]) {
    104  1.1  itohy 			print FILENAME ":" NR ": unknown arg type:", arg[i]
    105  1.1  itohy 			exit(1)
    106  1.1  itohy 		}
    107  1.1  itohy 		if (r !~ /^[da][01]$/)		# may not be saved
    108  1.1  itohy 			savereg[regno[r]] = r
    109  1.1  itohy 	}
    110  1.1  itohy 	# count reg to save
    111  1.1  itohy 	nsave = 0
    112  1.1  itohy 	for (i = 0; i < 16; i++) {
    113  1.1  itohy 		if (savereg[i])
    114  1.1  itohy 			nsave++
    115  1.1  itohy 	}
    116  1.1  itohy 
    117  1.1  itohy 	if (iocs_trap15) {
    118  1.1  itohy 		print "\tmoveml\td2-d7/a2-a6,sp@-"
    119  1.1  itohy 		nsave = 11
    120  1.1  itohy 	} else if (nsave == 1 || nsave == 2){
    121  1.1  itohy 		# use movel
    122  1.1  itohy 		for (i = 0; i < 16; i++) {
    123  1.1  itohy 			if (savereg[i])
    124  1.1  itohy 				print "\tmovel\t" savereg[i] ",sp@-"
    125  1.1  itohy 		}
    126  1.1  itohy 	} else if (nsave > 2) {
    127  1.1  itohy 		# use moveml
    128  1.1  itohy 		saveregs = ""
    129  1.1  itohy 		for (i = 0; i < 16; i++) {
    130  1.1  itohy 			if (savereg[i])
    131  1.1  itohy 				saveregs = saveregs "/" savereg[i]
    132  1.1  itohy 		}
    133  1.1  itohy 		saveregs = substr(saveregs, 2, length(saveregs) - 1)
    134  1.1  itohy 		print "\tmoveml\t" saveregs ",sp@-"
    135  1.1  itohy 	}
    136  1.1  itohy 
    137  1.1  itohy 	# LOAD ARGS
    138  1.1  itohy 	# XXX this should be more intelligent
    139  1.1  itohy 	argoff = nsave * 4 + 4
    140  1.1  itohy 	# input arguments for IOCS call
    141  1.1  itohy 	iarg = ""
    142  1.1  itohy 	niarg = 0
    143  1.1  itohy 	iarg_incorder = 1
    144  1.1  itohy 	immarg = ""
    145  1.1  itohy 	nimmarg = 0
    146  1.1  itohy 	for (i = 0; i < narg && arg[i] ~ /^[ad]/; i++) {
    147  1.1  itohy 		a = arg[i]
    148  1.1  itohy 		if (a ~ /^d[1-7]=[0-9][0-9]*$/) {
    149  1.1  itohy 			immarg = immarg " " a
    150  1.1  itohy 			nimmarg++
    151  1.1  itohy 		} else {
    152  1.1  itohy 			if (iarg) {
    153  1.1  itohy 				if (regno[a1] >= regno[a])
    154  1.1  itohy 					iarg_incorder = 0
    155  1.1  itohy 			}
    156  1.1  itohy 			a1 = a
    157  1.1  itohy 			iarg = iarg "/" a
    158  1.1  itohy 			niarg++
    159  1.1  itohy 		}
    160  1.1  itohy 	}
    161  1.1  itohy 	oarg = ""
    162  1.1  itohy 	noarg = 0
    163  1.1  itohy 	for ( ; i < narg; i++) {
    164  1.1  itohy 		if (arg[i] ~ /^[o]d[0-7]/) {
    165  1.1  itohy 			oarg = oarg " " arg[i]
    166  1.1  itohy 			noarg++
    167  1.1  itohy 		} else {
    168  1.1  itohy 			print "unknown arg:", arg[i]
    169  1.1  itohy 			exit(1)
    170  1.1  itohy 		}
    171  1.1  itohy 	}
    172  1.1  itohy 	# remove leading char
    173  1.1  itohy 	iarg = substr(iarg, 2, length(iarg) - 1);
    174  1.1  itohy 	immarg = substr(immarg, 2, length(immarg) - 1);
    175  1.1  itohy 	oarg = substr(oarg, 2, length(oarg) - 1);
    176  1.1  itohy 	# load input args
    177  1.1  itohy 	if (niarg == 0)
    178  1.1  itohy 		;
    179  1.1  itohy 	else if (niarg == 1 && iarg !~ /\=/) {
    180  1.1  itohy 		print "\tmovel\tsp@(" argoff ")," iarg	"\t| 1arg"
    181  1.1  itohy 	} else if (iarg_incorder && iarg !~ /\=/) {
    182  1.1  itohy 		print "\tmoveml\tsp@(" argoff ")," iarg	"\t| inc order"
    183  1.1  itohy 	} else if (iarg == "a1/d1") {
    184  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a1"
    185  1.1  itohy 		print "\tmovel\tsp@(" argoff + 4 "),d1"
    186  1.1  itohy 	} else if (iarg == "d1/a1/d2") {
    187  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),d1-d2/a1"
    188  1.1  itohy 		print "\texg\td2,a1"
    189  1.1  itohy 	} else if (iarg == "a1/a2/d1") {
    190  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),a1/a2"
    191  1.1  itohy 		print "\tmovel\tsp@(" argoff + 8 "),d1"
    192  1.1  itohy 	} else if (iarg == "a1/a2/d1/d2") {
    193  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),d1-d2/a1-a2"
    194  1.1  itohy 		print "\texg\td1,a1"
    195  1.1  itohy 		print "\texg\td2,a2"
    196  1.1  itohy 	} else if (iarg == "a1/d1/d2") {
    197  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),d0-d2"
    198  1.1  itohy 		print "\tmovel\td0,a1"
    199  1.1  itohy 	} else if (iarg == "d1=bb") {
    200  1.1  itohy 		print "\tmoveq\t#0,d1"
    201  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 3 "),d1"
    202  1.1  itohy 		print "\tlslw\t#8,d1"
    203  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 7 "),d1"
    204  1.1  itohy 		niarg = 2
    205  1.1  itohy 	} else if (iarg == "d1=ww") {
    206  1.1  itohy 		print "\tmovew\tsp@(" argoff + 2 "),d1"
    207  1.1  itohy 		print "\tswap\td1"
    208  1.1  itohy 		print "\tmovew\tsp@(" argoff + 6 "),d1"
    209  1.1  itohy 		niarg = 2
    210  1.1  itohy 	} else if (iarg == "d1=hsv") {
    211  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 3 "),d1"
    212  1.1  itohy 		print "\tswap\td1"
    213  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 7 "),d1"
    214  1.1  itohy 		print "\tlslw\t#8,d1"
    215  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 11 "),d1"
    216  1.1  itohy 		print "\tandl\t#0x00ff1f1f,d1"
    217  1.1  itohy 		niarg = 3
    218  1.1  itohy 	} else if (iarg == "a1/d1=bb") {
    219  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a1"
    220  1.1  itohy 		print "\tmoveq\t#0,d1"
    221  1.1  itohy 		print "\tmoveb\tsp@(" argoff + 7 "),d1"
    222  1.1  itohy 		print "\tlslw\t#8,d1"
    223  1.1  itohy 		print "\tmoveb	sp@(" argoff + 11 "),d1"
    224  1.1  itohy 		niarg = 3
    225  1.1  itohy 	} else if (iarg == "d1/d2=ww") {
    226  1.1  itohy 		print "\tmovel\tsp@(" argoff "),d1"
    227  1.1  itohy 		print "\tmovew\tsp@(" argoff + 6 "),d2"
    228  1.1  itohy 		print "\tswap\td2"
    229  1.1  itohy 		print "\tmovew\tsp@(" argoff + 10 "),d2"
    230  1.1  itohy 		niarg = 3
    231  1.1  itohy 	} else if (iarg == "d1=ww/a1") {
    232  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),d0-d1/a1"
    233  1.1  itohy 		print "\tswap\td1"
    234  1.1  itohy 		print "\tmovew\td0,d1"
    235  1.1  itohy 		print "\tswap\td1"
    236  1.1  itohy 		niarg = 3
    237  1.1  itohy 	} else if (iarg == "d1=ww/d2=ww") {
    238  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),d1-d2"
    239  1.1  itohy 		print "\tswap\td1"
    240  1.1  itohy 		print "\tmovew\td2,d1"
    241  1.1  itohy 		print "\tmovew\tsp@(" argoff + 10 "),d2"
    242  1.1  itohy 		print "\tswap\td2"
    243  1.1  itohy 		print "\tmovew\tsp@(" argoff + 14 "),d2"
    244  1.1  itohy 		niarg = 4
    245  1.1  itohy 	} else {
    246  1.1  itohy 		print "unsupported iarg:", iarg
    247  1.1  itohy 		exit(1)
    248  1.1  itohy 	}
    249  1.1  itohy 	argoff += niarg * 4
    250  1.1  itohy 
    251  1.1  itohy 	if (sp_regst) {
    252  1.1  itohy 		print "\tandl\t#0x80000000,d1"
    253  1.1  itohy 		print "\tmoveb\td0,d1"
    254  1.1  itohy 	}
    255  1.1  itohy 
    256  1.1  itohy 	if (b_curmod) {
    257  1.1  itohy 		print "\tmoveq\t#1,d0"
    258  1.1  itohy 		print "\tcmpl\td1,d0"
    259  1.1  itohy #		print "\tbcss\tLerr"
    260  1.1  itohy 		print "\tbcss\t6f"
    261  1.1  itohy 	}
    262  1.1  itohy 
    263  1.1  itohy 	if (b_curpat) {
    264  1.1  itohy 		print "\ttstw\td2"
    265  1.1  itohy #		print "\tbeqs\tLerr"
    266  1.1  itohy 		print "\tbeqs\t6f"
    267  1.1  itohy 	}
    268  1.1  itohy 
    269  1.1  itohy 	if (b_super) {
    270  1.1  itohy 		print "\tmoval\tsp@+,a0"
    271  1.1  itohy 		print "\tmoval\tsp@,a1"
    272  1.1  itohy 	}
    273  1.1  itohy 
    274  1.1  itohy 	# load imm args
    275  1.1  itohy 	if (nimmarg) {
    276  1.1  itohy 		for (i = 0; i < narg && arg[i] ~ /^[ad]/; i++) {
    277  1.1  itohy 			a = arg[i]
    278  1.1  itohy 			if (a ~ /^d[1-7]=[0-9][0-9]*$/) {
    279  1.1  itohy 				r = substr(a, 1, 2)
    280  1.1  itohy 				v = substr(a, 4, length(a)-3)
    281  1.1  itohy 				print "\tmoveq\t#" v "," r
    282  1.1  itohy 			}
    283  1.1  itohy 		}
    284  1.1  itohy 	}
    285  1.1  itohy 
    286  1.1  itohy 	if (c_md) {
    287  1.1  itohy 		# -1: flush(3), -2: set default(2), other: set by the value(4)
    288  1.1  itohy 		print "\tmovel\td2,d0"
    289  1.1  itohy 		print "\taddql\t#1,d0"
    290  1.1  itohy 		print "\tbeqs\tLcachemd"
    291  1.1  itohy 		print "\tmoveq\t#2,d1"
    292  1.1  itohy 		print "\taddql\t#1,d0"
    293  1.1  itohy 		print "\tbnes\tLcachemd"
    294  1.1  itohy 		print "\tmoveq\t#4,d1"
    295  1.1  itohy 		print "Lcachemd:"
    296  1.1  itohy 	}
    297  1.1  itohy 
    298  1.1  itohy 	if (b_scroll) {
    299  1.1  itohy 		# d1 has 16
    300  1.1  itohy 		print "\tcmpl\td1,d2"
    301  1.1  itohy 		print "\tbcss\tLscriocs"
    302  1.1  itohy 		print "\tmovel\td2,d1"
    303  1.1  itohy 		print "Lscriocs:"
    304  1.1  itohy 	}
    305  1.1  itohy 
    306  1.1  itohy 	if (iocs_trap15) {
    307  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a0	| inregs"
    308  1.1  itohy 		print "\tmoveml\ta0@,d0-d7/a1-a6"
    309  1.1  itohy 		argoff += 4
    310  1.1  itohy 	}
    311  1.1  itohy 
    312  1.1  itohy 	if (iocsno != "(none)") {
    313  1.1  itohy 		if (iocsno ~ /^[89abcdef]./)
    314  1.1  itohy 			iocsno = "ffffff" iocsno
    315  1.1  itohy 		print "\tmoveq\t#0x" iocsno ",d0"
    316  1.1  itohy 	}
    317  1.1  itohy 	print "\ttrap\t#15"
    318  1.1  itohy 
    319  1.1  itohy 	if (iocs_trap15) {
    320  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a0	| outregs"
    321  1.1  itohy 		print "\tmoveml\td0-d7/a1-a6,a0@"
    322  1.1  itohy 	}
    323  1.1  itohy 
    324  1.1  itohy 	if (err_d0 && noarg) {
    325  1.1  itohy 		print "\ttstl\td0"
    326  1.1  itohy #		print "\tbnes\tLerr"
    327  1.1  itohy 		print "\tbnes\t6f"
    328  1.1  itohy 	}
    329  1.1  itohy 
    330  1.1  itohy 	# SAVERESULTS
    331  1.1  itohy 	# XXX this should be more intelligent
    332  1.1  itohy 	if (noarg == 0)
    333  1.1  itohy 		;
    334  1.1  itohy 	else if (oarg == "od2") {
    335  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a0"
    336  1.1  itohy 		argoff += 4
    337  1.1  itohy 		print "\tmovel\td2,a0@"
    338  1.1  itohy 	} else if (oarg == "od1 od2 od0") {
    339  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),a0/a1"
    340  1.1  itohy 		argoff += 8
    341  1.1  itohy 		print "\tmovel\td1,a0@"
    342  1.1  itohy 		print "\tmovel\td2,a1@"
    343  1.1  itohy 		print "\tmoveal\tsp@(" argoff "),a0"
    344  1.1  itohy 		argoff += 4
    345  1.1  itohy 		print "\tmovel\td0,a0@"
    346  1.1  itohy 	} else if (oarg == "od2 od3") {
    347  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),a0/a1"
    348  1.1  itohy 		argoff += 8
    349  1.1  itohy 		print "\tmovel\td2,a0@"
    350  1.1  itohy 		print "\tmovel\td3,a1@"
    351  1.1  itohy 	} else if (oarg == "od2 od3 od4 od5") {
    352  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),a0/a1"
    353  1.1  itohy 		argoff += 8
    354  1.1  itohy 		print "\tmovel\td2,a0@"
    355  1.1  itohy 		print "\tmovel\td3,a1@"
    356  1.1  itohy 		print "\tmoveml\tsp@(" argoff "),a0/a1"
    357  1.1  itohy 		argoff += 8
    358  1.1  itohy 		print "\tmovel\td4,a0@"
    359  1.1  itohy 		print "\tmovel\td5,a1@"
    360  1.1  itohy 	} else {
    361  1.1  itohy 		print "unsupported oarg:", oarg
    362  1.1  itohy 		exit(1)
    363  1.1  itohy 	}
    364  1.1  itohy 
    365  1.1  itohy 	if ((err_d0 && noarg) || b_curmod || b_curpat)
    366  1.1  itohy #		print "Lerr:"
    367  1.1  itohy 		print "6:"
    368  1.1  itohy 
    369  1.1  itohy 	# return value
    370  1.1  itohy 	if (retd2)
    371  1.1  itohy 		print "\tmovel\td2,d0"
    372  1.1  itohy 
    373  1.1  itohy 	# RESTORE REGISTERS
    374  1.1  itohy 	if (iocs_trap15) {
    375  1.1  itohy 		print "\tmoveml\tsp@+,d2-d7/a2-a6"
    376  1.1  itohy 	} else if (nsave == 1 || nsave == 2){
    377  1.1  itohy 		# use movel
    378  1.1  itohy 		for (i = 16 - 1; i >= 0; i--) {
    379  1.1  itohy 			if (savereg[i])
    380  1.1  itohy 				print "\tmovel\tsp@+," savereg[i]
    381  1.1  itohy 		}
    382  1.1  itohy 	} else if (nsave > 2) {
    383  1.1  itohy 		# use moveml
    384  1.1  itohy 		print "\tmoveml\tsp@+," saveregs
    385  1.1  itohy 	}
    386  1.1  itohy 
    387  1.1  itohy 
    388  1.1  itohy 	if (b_super)
    389  1.1  itohy 		print "\tjmp\ta0@"
    390  1.1  itohy 	else if (!noret)
    391  1.1  itohy 		print "\trts"
    392  1.1  itohy }
    393