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