xref: /netbsd-src/sys/arch/x68k/stand/libdos/makestrerror.awk (revision ed461fc193a34ff07bc68b0c28567cb8cfe199e5)
1f67f0709Sitohy#! /usr/bin/awk -f
2f67f0709Sitohy#
3f67f0709Sitohy#	create  dos_strerror()  from dos_errno.h
4f67f0709Sitohy#
5*ed461fc1Sitohy#	written by ITOH Yasufumi
6f67f0709Sitohy#	public domain
7f67f0709Sitohy#
8*ed461fc1Sitohy#	$NetBSD: makestrerror.awk,v 1.3 2011/02/21 02:31:59 itohy Exp $
9f67f0709Sitohy
10f67f0709Sitohy/^\/\* dos_errlist begin \*\/$/,/^\/\* dos_errlist end \*\/$/ {
11f67f0709Sitohy	if ($0 ~ /^\/\* dos_errlist begin \*\/$/) {
12f67f0709Sitohy		# assembly code
13f67f0709Sitohy		print "| This file is automatically generated.  DO NOT EDIT."
1459c36c2cSitohy		print "#include \"dos_asm.h\""
15f67f0709Sitohy		print "#include \"dos_errno.h\""
16f67f0709Sitohy		print "	.text"
17f67f0709Sitohy		print "	.even"
1859c36c2cSitohy		print "GLOBAL(dos_nerr)"
19f67f0709Sitohy		print "	.long	DOS_ELAST+1"
20f67f0709Sitohy		print ""
2159c36c2cSitohy		print "ENTRY_NOPROFILE(dos_strerror)"
2259c36c2cSitohy		print "	movel	%sp@(4),%d0"
2359c36c2cSitohy		print "	moveq	#80,%d1"
2459c36c2cSitohy		print "	cmpl	%d0,%d1"
25f67f0709Sitohy		print "	bnes	Lnot80"
2659c36c2cSitohy		print "	moveq	#DOS_EEXIST,%d0"
2759c36c2cSitohy		print "Lnot80:	moveq	#DOS_ELAST+1,%d1"
2859c36c2cSitohy		print "	cmpl	%d1,%d0"
29f67f0709Sitohy		print "	bcss	Lnotuk"
3059c36c2cSitohy		print "	movel	%d1,%d0"
3159c36c2cSitohy		print "Lnotuk:	lslw	#1,%d0"
3259c36c2cSitohy		print "Lh1:\tmovew\t%pc@(Lerrtbl-Lh1-2:B,%d0:W),%d0\t| 303B 000A"
3359c36c2cSitohy		print "Lh2:\tlea\t%pc@(Lerrtbl-Lh2-2:B,%d0:W),%a0\t| 41FB 0006"
3459c36c2cSitohy		print "	movel	%a0,%d0"
35f67f0709Sitohy		print "	rts"
36f67f0709Sitohy		print ""
37f67f0709Sitohy		print "Lerrtbl:"
38f67f0709Sitohy		nmsg = 0
39f67f0709Sitohy	} else if ($0 ~ /^\/\* dos_errlist end \*\/$/) {
40f67f0709Sitohy		print "\t.word\tLukmsg-Lerrtbl		| default message"
41f67f0709Sitohy		print ""
42f67f0709Sitohy		# error strings
43f67f0709Sitohy		for (i = 0; i < nmsg; i++)
44f67f0709Sitohy			print "Lmsg" i ":\t.asciz\t\"" msg[i] "\""
45f67f0709Sitohy
46f67f0709Sitohy		print "Lukmsg:\t.asciz\t\"Unknown error\""
47f67f0709Sitohy		exit
48f67f0709Sitohy	} else {
49f67f0709Sitohy		if ($3 != nmsg || $4 != "/*") {
50f67f0709Sitohy			printf FILENAME ":" NR ": format error"
51f67f0709Sitohy			exit(1);
52f67f0709Sitohy		}
53f67f0709Sitohy		# offset table
54f67f0709Sitohy		print "\t.word\tLmsg" nmsg "-Lerrtbl"
55f67f0709Sitohy		$1 = ""
56f67f0709Sitohy		$2 = ""
57f67f0709Sitohy		$3 = ""
58f67f0709Sitohy		$4 = ""
59f67f0709Sitohy		msg[nmsg] = substr($0, 5, length - 7)
60f67f0709Sitohy		nmsg++
61f67f0709Sitohy	}
62f67f0709Sitohy}
63