Home | History | Annotate | Line # | Download | only in radeon
      1 #!/usr/bin/awk -f
      2 #	$NetBSD: mkregtable.awk,v 1.1 2014/07/16 20:59:58 riastradh Exp $
      3 #
      4 # Copyright (c) 2014 The NetBSD Foundation, Inc.
      5 # All rights reserved.
      6 #
      7 # This code is derived from software contributed to The NetBSD Foundation
      8 # by Taylor R. Campbell.
      9 #
     10 # Redistribution and use in source and binary forms, with or without
     11 # modification, are permitted provided that the following conditions
     12 # are met:
     13 # 1. Redistributions of source code must retain the above copyright
     14 #    notice, this list of conditions and the following disclaimer.
     15 # 2. Redistributions in binary form must reproduce the above copyright
     16 #    notice, this list of conditions and the following disclaimer in the
     17 #    documentation and/or other materials provided with the distribution.
     18 #
     19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29 # POSSIBILITY OF SUCH DAMAGE.
     30 
     31 function howmany(x, n) {
     32 	return int((x + (n - 1)) / n)
     33 }
     34 
     35 function hi(x, n) {
     36 	return int(x / 2^n)
     37 }
     38 
     39 function lo(x, n) {
     40 	return (x % 2^n)
     41 }
     42 
     43 function rcsid(s) {
     44 	sub("^\\$", "", s)
     45 	sub("\\$$", "", s)
     46 
     47 	return s;
     48 }
     49 
     50 BEGIN {
     51 	state = "INITIAL"
     52 }
     53 
     54 state == "INITIAL" {
     55 	gpu = $1
     56 	maxreg = lastreg = $2
     57 	state = "REGS"
     58 	noffsets = 0
     59 }
     60 
     61 state == "REGS" &&
     62 $1 ~ /0x[0-9a-fA-F]/ &&
     63 $2 ~ /[_a-zA-Z0-9]*/ {
     64 	if (!seen[$1]) {
     65 		seen[$1] = 1
     66 		offset[noffsets++] = $1
     67 		if ($1 > maxreg)
     68 			maxreg = $1
     69 	}
     70 }
     71 
     72 END {
     73 	# We do this in 16-bit arithmetic to avoid overflow in case
     74 	# this ever runs on a system whose awk uses single-precision
     75 	# floats or 32-bit integers or something horrible like that.
     76 	nentries = howmany(hi(maxreg, 2), 32)
     77 	for (i = 0; i < nentries; i++) {
     78 		# No hex numeric literals in awk!
     79 		table_hi[i] = 2^16 - 1
     80 		table_lo[i] = 2^16 - 1
     81 	}
     82 	for (o = 0; o < noffsets; o++) {
     83 		reg = hi(offset[o], 2)
     84 		wi = hi(reg, 5)
     85 		bi = lo(reg, 5)
     86 		# Clear the bit.  No bitwise operations, but if the
     87 		# offsets don't overlap, the bit is guaranteed to be
     88 		# set so we can just subtract 2^n.
     89 		if (hi(bi, 4) != 0)
     90 			table_hi[wi] -= 2^lo(bi, 4)
     91 		else
     92 			table_lo[wi] -= 2^bi
     93 	}
     94 	printf("/*\n")
     95 	printf(" *\t%c%s%c\n", "$", "NetBSD", "$")
     96 	printf(" *\n")
     97 	printf(" * Stand back!  This file was automagically generated by\n")
     98 	printf(" *\t%s\n", rcsid("$NetBSD: mkregtable.awk,v 1.1 2014/07/16 20:59:58 riastradh Exp $"))
     99 	printf(" */\n")
    100 	printf("\n")
    101 	printf("static const uint32_t %s_reg_safe_bm[%u] = {\n", gpu, nentries)
    102 	for (i = 0; i < nentries; i++) {
    103 		if ((i % 4) == 0)
    104 			printf("\t")
    105 		printf("0x%04X%04X,", table_hi[i], table_lo[i])
    106 		if (((i % 4) == 3) || (i == (nentries - 1)))
    107 			printf("\n")
    108 		else
    109 			printf(" ")
    110 	}
    111 	printf("};\n")
    112 }
    113