3 # create DOS call interface from dos.h
5 # written by Yasha (ITOH Yasufumi)
8 # $NetBSD: makedoscalls.awk,v 1.2 1999/11/11 08:14:43 itohy Exp $
11 errno_nomem =
8 # errno for "Cannot allocate memory"
12 argsiz
["l"] =
4; argsiz
["w"] =
2
13 argsiz
["lb31"] =
4; argsiz
["wb8"] =
2; argsiz
["wb15"] =
2
14 print "#include \"dos_asm.h\""
17 $
1 ==
"/*" && $
2 ~
/^ff
[0-9a
-f
][0-9a
-f
]$
/ {
22 ncarg=
0 # number of 32bit C function argument
33 for (i =
3; i
<=
NF && $i
!= "*/" && $i
!= ";"; i
++) {
41 for (i
++; i
<=
NF && $i
!= "*/"; i
++) {
44 else if ($i ==
"estrct") {
47 } else if ($i ==
"ep") {
50 } else if ($i ==
"ealloc") {
53 } else if ($i ==
"sv")
55 else if ($i ==
"noret")
57 else if ($i ==
"alias") {
60 } else if ($i ==
"super")
62 else if ($i ==
"super_jsr")
65 print FILENAME ":" NR ": unknown opt", $i
71 print FILENAME ":" NR ": malformed input line:" $
0
76 for (i
++; i
<=
NF; i
++) {
78 if ($i ~
/^\
**DOS_
[A
-Z0
-9_
]*$
/) {
80 while (funcnam ~
/^\
*/) {
81 funcnam =
substr(funcnam
, 2, length(funcnam
) -1)
88 print FILENAME ":" NR ": can't find function name"
92 # output assembly code
93 print "ENTRY_NOPROFILE(" funcnam
")"
95 print "GLOBAL(" alias
")"
97 if (svreg
) print "\tmoveml\t%d2-%d7/%a2-%a6,%sp@-"
103 for (i = narg
- 1; i
>=
0; i
--) {
108 # optimize with movem
109 if (arg
[i
-1] ==
"l" && arg
[i
-2] ==
"l") {
110 if (arg
[i
-3] ==
"l") {
111 print "\tmoveml\t%sp@(" argoff
- 12 "),%d0-%d1/%a0-%a1"
112 print "\tmoveml\t%d0-%d1/%a0-%a1,%sp@-"
115 } else if (arg
[i
-3] ==
"w") {
116 print "\tmoveml\t%sp@(" argoff
- 12 "),%d0-%d1/%a0-%a1"
117 print "\tmoveml\t%d1/%a0-%a1,%sp@-"
118 print "\tmovew\t%d0,%sp@-"
122 print "\tmoveml\t%sp@(" argoff
- 8 "),%d0-%d1/%a0"
123 print "\tmoveml\t%d0-%d1/%a0,%sp@-"
128 print "\tmovel\t%sp@(" argoff
"),%sp@-"
131 print "\tmovew\t%sp@(" argoff
+ 2 "),%sp@-"
132 else if (a ==
"lb31") {
133 print "\tmovel\t%sp@(" argoff
"),%d0"
134 print "\tbset\t#31,%d0"
135 print "\tmovel\t%d0,%sp@-"
136 } else if (a ==
"wb8") {
137 print "\tmovew\t%sp@(" argoff
+ 2 "),%d0"
138 print "\torw\t#0x100,%d0"
139 print "\tmovew\t%d0,%sp@-"
140 } else if (a ==
"wb15") {
141 print "\tmovew\t%sp@(" argoff
+ 2 "),%d0"
142 print "\torw\t#0x8000,%d0"
143 print "\tmovew\t%d0,%sp@-"
145 print "??? unknown type"
151 } else if (a ~
/^
[0-9][0-9]*\.w$
/) {
154 val =
substr(a
, 1, length(a
) - 2)
156 print "\tclrw\t%sp@-"
158 print "\tmovew\t#" val
",%sp@-"
159 } else if (a ~
/^
[0-9][0-9]*\.l$
/) {
162 val =
substr(a
, 1, length(a
) - 2)
164 print "\tclrl\t%sp@-"
165 else if (val
<=
32767)
166 print "\tpea\t" val
":w"
168 print "\tmovel\t#" val
",%sp@-"
169 } else if (a ==
"drvctrl" && narg ==
1) {
170 # only for DOS_DRVCTRL
172 print "\tmoveb\t%sp@(7),%d0"
173 print "\tlslw\t#8,%d0"
174 print "\tmoveb\t%sp@(11),%d0"
175 print "\tmovew\t%d0,%sp@-"
176 } else if (a ==
"super" && narg ==
1) {
178 print "\tmoveal\t%sp@+,%a1"
180 print FILENAME ":" NR ": unknown arg type:", a
187 print "\tmoveal\t%sp@(" argoff
+ 8 "),%a0 | inregs"
188 print "\tmoveml\t%a0@,%d0-%d7/%a0-%a6"
191 if (dosno ~
/^ff
[8a
].
/) {
193 v2dosno =
"ff5" substr(dosno
, 4, 1)
195 v2dosno =
"ff7" substr(dosno
, 4, 1)
196 print "\tcmpiw #0x200+14,_C_LABEL(_vernum)+2 | 2.14"
197 # print "\tbcss\tLv2doscall"
199 print "\t.word\t0x" dosno
201 # print "\tbras\tLedoscall"
203 # print "Lv2doscall:"
205 print "\t.word\t0x" v2dosno
210 print "\t.word\t0x" dosno
213 # no postprocess needed for dead calls
218 print "\tmovel\t%a6,%sp@"
219 print "\tmoveal\t%sp@(" argoff
+ 12 "),%a6 | outregs"
220 print "\tmovel\t%sp@+,%a6@(" 4 * 14 ")"
221 print "\tmoveml\t%d0-%d7/%a0-%a5,%a6@"
222 } else if (argbyte
> 0) {
225 print "\taddql\t#" argbyte
",%sp"
227 print "\tlea\t%sp@(" argbyte
"),%sp"
230 if (svreg
) print "\tmoveml\t%sp@+,%d2-%d7/%a2-%a6"
231 if (ptrval
) print "#ifdef __SVR4_ABI__\n\tmoveal\t%d0,%a0\n#endif"
234 print "\tcmpil\t#0xffffff00,%d0"
235 print "\tbcc\tCERROR"
239 # print "\tbpls\tLnoerr"
242 print "\tmovel\t%d0,_C_LABEL(dos_errno)"
246 } else if (e_alloc
) {
247 # print "\tbpls\tLnoerr"
249 print "\tmovel\t#" errno_nomem
",_C_LABEL(dos_errno)"
253 print "\tbmi\tPRCERROR"
255 print "\tbmi\tCERROR"