Home | History | Annotate | Line # | Download | only in hpc
      1  1.1  uch #  $NetBSD: platid.awk,v 1.1 2001/01/28 02:52:18 uch Exp $
      2  1.1  uch #
      3  1.1  uch #  Copyright (c) 1999
      4  1.1  uch #          Shin Takemura and PocketBSD Project. All rights reserved.
      5  1.1  uch # 
      6  1.1  uch #  Redistribution and use in source and binary forms, with or without
      7  1.1  uch #  modification, are permitted provided that the following conditions
      8  1.1  uch #  are met:
      9  1.1  uch #  1. Redistributions of source code must retain the above copyright
     10  1.1  uch #     notice, this list of conditions and the following disclaimer.
     11  1.1  uch #  2. Redistributions in binary form must reproduce the above copyright
     12  1.1  uch #     notice, this list of conditions and the following disclaimer in the
     13  1.1  uch #     documentation and/or other materials provided with the distribution.
     14  1.1  uch #  3. All advertising materials mentioning features or use of this software
     15  1.1  uch #     must display the following acknowledgement:
     16  1.1  uch # 	This product includes software developed by the PocketBSD project
     17  1.1  uch # 	and its contributors.
     18  1.1  uch #  4. Neither the name of the project nor the names of its contributors
     19  1.1  uch #     may be used to endorse or promote products derived from this software
     20  1.1  uch #     without specific prior written permission.
     21  1.1  uch # 
     22  1.1  uch #  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  uch #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  uch #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  uch #  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  uch #  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  uch #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  uch #  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  uch #  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  uch #  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  uch #  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  uch #  SUCH DAMAGE.
     33  1.1  uch # 
     34  1.1  uch 
     35  1.1  uch #
     36  1.1  uch #  sub routines
     37  1.1  uch #
     38  1.1  uch 
     39  1.1  uch function gen_header(file) {
     40  1.1  uch   printf("/*\n") >> file
     41  1.1  uch   printf(" *  Do not edit.\n") > file
     42  1.1  uch   printf(" *  This file is automatically generated by platid.awk.\n") > file
     43  1.1  uch   printf(" */\n") > file
     44  1.1  uch }
     45  1.1  uch 
     46  1.1  uch function error() {
     47  1.1  uch     printf("ERROR!\n") > stderr
     48  1.1  uch     exit
     49  1.1  uch }
     50  1.1  uch 
     51  1.1  uch function mode_check() {
     52  1.1  uch     if (mode != MACH && mode != CPU) {
     53  1.1  uch         printf("ERROR: invalid mode( = %d)\n", mode) > stderr
     54  1.1  uch         exit
     55  1.1  uch     }
     56  1.1  uch }
     57  1.1  uch 
     58  1.1  uch function defname() {
     59  1.1  uch     mode_check()
     60  1.1  uch 
     61  1.1  uch     #
     62  1.1  uch     #  master header
     63  1.1  uch     #
     64  1.1  uch     enumerator[mode] += 1
     65  1.1  uch     printf("#define PLATID_%s_%s%s_NUM\t%d\n",
     66  1.1  uch            mode_name[mode], nm, saved_name, enumerator[mode]) > out_h
     67  1.1  uch     printf("#define PLATID_%s_%s%s\t\\\n",
     68  1.1  uch            mode_name[mode], nm, saved_name) > out_h
     69  1.1  uch     printf("  ((PLATID_%s_%s%s_NUM << %s)",
     70  1.1  uch            mode_name[mode], nm, saved_name, shifts[mode, nest]) > out_h
     71  1.1  uch     if (nest) {
     72  1.1  uch       printf("| \\\n    PLATID_%s", mode_name[mode]) > out_h
     73  1.1  uch       for (i = 0; i < nest; i++) {
     74  1.1  uch         printf("_%s", names[i]) > out_h
     75  1.1  uch       }
     76  1.1  uch     }
     77  1.1  uch     printf(")\n") > out_h
     78  1.1  uch 
     79  1.1  uch     #
     80  1.1  uch     #  mask header
     81  1.1  uch     #
     82  1.1  uch     printf("extern platid_t platid_mask_%s_%s%s;\n",
     83  1.1  uch 	   mode_name[mode], nm, saved_name) > out_mask_h
     84  1.1  uch     printf("#ifdef PLATID_DEFINE_MASK_NICKNAME\n") > out_mask_h
     85  1.1  uch     if (mode == CPU) {
     86  1.1  uch         printf("#  define GENERIC_%s%s ((int)&platid_mask_%s_%s%s)\n",
     87  1.1  uch 	       nm, saved_name,
     88  1.1  uch 	       mode_name[mode], nm, saved_name) > out_mask_h
     89  1.1  uch     } else {
     90  1.1  uch         printf("#  define %s%s ((int)&platid_mask_%s_%s%s)\n",
     91  1.1  uch 	       nm, saved_name,
     92  1.1  uch 	       mode_name[mode], nm, saved_name) > out_mask_h
     93  1.1  uch     }
     94  1.1  uch     printf("#endif\n") > out_mask_h
     95  1.1  uch 
     96  1.1  uch     #
     97  1.1  uch     #  mask holder
     98  1.1  uch     #
     99  1.1  uch     printf("platid_t platid_mask_%s_%s%s = {{\n",
    100  1.1  uch 	   mode_name[mode], nm, saved_name) > out_mask_c
    101  1.1  uch     if (mode == CPU) {
    102  1.1  uch         printf("\tPLATID_%s_%s%s,\n",
    103  1.1  uch 	       mode_name[mode], nm, saved_name) > out_mask_c
    104  1.1  uch 	printf("\tPLATID_WILD\n") > out_mask_c
    105  1.1  uch     }
    106  1.1  uch     if (mode == MACH) {
    107  1.1  uch         if (saved_cpu != "") {
    108  1.1  uch 	    printf("\tPLATID_CPU_%s,\n", saved_cpu) > out_mask_c
    109  1.1  uch         } else {
    110  1.1  uch 	    printf("\tPLATID_WILD,\n") > out_mask_c
    111  1.1  uch 	}
    112  1.1  uch 	printf("\tPLATID_%s_%s%s\n",
    113  1.1  uch 	       mode_name[mode], nm, saved_name) > out_mask_c
    114  1.1  uch 
    115  1.1  uch     }
    116  1.1  uch     printf("}};\n") > out_mask_c
    117  1.1  uch 
    118  1.1  uch }
    119  1.1  uch 
    120  1.1  uch function flushname() {
    121  1.1  uch     if ( saved_name != "" ) {
    122  1.1  uch         defname()
    123  1.1  uch     }
    124  1.1  uch }
    125  1.1  uch 
    126  1.1  uch BEGIN {
    127  1.1  uch   CPU = 1
    128  1.1  uch   MACH = 2
    129  1.1  uch 
    130  1.1  uch   nest = 0
    131  1.1  uch   nm = ""
    132  1.1  uch   saved_name = ""
    133  1.1  uch   mode = NA
    134  1.1  uch   change_cpu = 0
    135  1.1  uch   saved_cpu = ""
    136  1.1  uch 
    137  1.1  uch   mode_name[CPU] = "CPU"
    138  1.1  uch   mode_name[MACH] = "MACH"
    139  1.1  uch 
    140  1.1  uch   shifts[CPU, 0] = "PLATID_CPU_ARCH_SHIFT"
    141  1.1  uch   shifts[CPU, 1] = "PLATID_CPU_SERIES_SHIFT"
    142  1.1  uch   shifts[CPU, 2] = "PLATID_CPU_MODEL_SHIFT"
    143  1.1  uch   shifts[CPU, 3] = "PLATID_CPU_SUBMODEL_SHIFT"
    144  1.1  uch 
    145  1.1  uch   shifts[MACH, 0] = "PLATID_VENDOR_SHIFT"
    146  1.1  uch   shifts[MACH, 1] = "PLATID_SERIES_SHIFT"
    147  1.1  uch   shifts[MACH, 2] = "PLATID_MODEL_SHIFT"
    148  1.1  uch   shifts[MACH, 3] = "PLATID_SUBMODEL_SHIFT"
    149  1.1  uch 
    150  1.1  uch   enumerator[CPU] = 0
    151  1.1  uch   enumerator[MACH] = 0
    152  1.1  uch 
    153  1.1  uch   if (stderr == "") {
    154  1.1  uch     stderr = "/dev/stderr"
    155  1.1  uch   }
    156  1.1  uch   if (out_h == "") {
    157  1.1  uch     out_h = "platid_generated.h"
    158  1.1  uch   }
    159  1.1  uch   if (out_mask_h == "") {
    160  1.1  uch     out_mask_h = "platid_mask.h"
    161  1.1  uch   }
    162  1.1  uch   if (out_mask_c == "") {
    163  1.1  uch     out_mask_c = "platid_mask.c"
    164  1.1  uch   }
    165  1.1  uch 
    166  1.1  uch   printf("files: %s %s %s\n", out_h, out_mask_h, out_mask_c) > stderr
    167  1.1  uch 
    168  1.1  uch   gen_header(out_h)
    169  1.1  uch   gen_header(out_mask_h)
    170  1.1  uch   gen_header(out_mask_c)
    171  1.1  uch   printf("#include <machine/platid.h>\n") > out_mask_c
    172  1.1  uch }
    173  1.1  uch 
    174  1.1  uch /^[ \t]*$/ {
    175  1.1  uch   next
    176  1.1  uch }
    177  1.1  uch /\/\*/ {
    178  1.1  uch   commentout = 1
    179  1.1  uch   next
    180  1.1  uch }
    181  1.1  uch /\*\// {
    182  1.1  uch   commentout = 0
    183  1.1  uch   next
    184  1.1  uch }
    185  1.1  uch /:/{
    186  1.1  uch   if (commentout) {
    187  1.1  uch     next
    188  1.1  uch   }
    189  1.1  uch   if (nest != 0) {
    190  1.1  uch     error()
    191  1.1  uch   }
    192  1.1  uch   if (saved_name == "CPU") {
    193  1.1  uch     mode = CPU
    194  1.1  uch   } else
    195  1.1  uch   if (saved_name == "MACHINE") {
    196  1.1  uch     mode = MACH
    197  1.1  uch   } else {
    198  1.1  uch     error()
    199  1.1  uch   }
    200  1.1  uch   saved_name = ""
    201  1.1  uch   next
    202  1.1  uch }
    203  1.1  uch /=/{
    204  1.1  uch   if (commentout) {
    205  1.1  uch     next
    206  1.1  uch   }
    207  1.1  uch   if (saved_name == "CPU") {
    208  1.1  uch     change_cpu = 1
    209  1.1  uch   } else {
    210  1.1  uch     error()
    211  1.1  uch   }
    212  1.1  uch   saved_name = ""
    213  1.1  uch   next
    214  1.1  uch }
    215  1.1  uch /\?/{
    216  1.1  uch   if (commentout) {
    217  1.1  uch     next
    218  1.1  uch   }
    219  1.1  uch   if (change_cpu) {
    220  1.1  uch     saved_cpu = ""
    221  1.1  uch     change_cpu = 0
    222  1.1  uch   } else {
    223  1.1  uch     error()
    224  1.1  uch   }
    225  1.1  uch   next
    226  1.1  uch }
    227  1.1  uch /{/{
    228  1.1  uch   if (commentout) {
    229  1.1  uch     next
    230  1.1  uch   }
    231  1.1  uch   flushname()
    232  1.1  uch 
    233  1.1  uch   nms[nest] = nm
    234  1.1  uch   enums[nest] = enumerator[mode]
    235  1.1  uch   names[nest] = saved_name
    236  1.1  uch   cpus[nest] = saved_cpu
    237  1.1  uch 
    238  1.1  uch   if (nest == 2) {
    239  1.1  uch   } else
    240  1.1  uch   if (nest == 0) {
    241  1.1  uch     nm = sprintf("%s_", saved_name)
    242  1.1  uch   } else {
    243  1.1  uch     nm = sprintf("%s%s_", nm, saved_name)
    244  1.1  uch   }
    245  1.1  uch   nest++
    246  1.1  uch 
    247  1.1  uch   mode_check()
    248  1.1  uch   enumerator[mode] = 0
    249  1.1  uch   saved_name = ""
    250  1.1  uch 
    251  1.1  uch   next
    252  1.1  uch }
    253  1.1  uch /}/{
    254  1.1  uch   if (commentout) {
    255  1.1  uch     next
    256  1.1  uch   }
    257  1.1  uch   flushname()
    258  1.1  uch   saved_name = ""
    259  1.1  uch   --nest
    260  1.1  uch   nm = nms[nest]
    261  1.1  uch   enumerator[mode] = enums[nest]
    262  1.1  uch   saved_cpu = cpus[nest]
    263  1.1  uch   next
    264  1.1  uch }
    265  1.1  uch /[a-zA-Z0-9]*/{
    266  1.1  uch   if (commentout) {
    267  1.1  uch     next
    268  1.1  uch   }
    269  1.1  uch   if (change_cpu) {
    270  1.1  uch     saved_cpu = $1
    271  1.1  uch     change_cpu = 0
    272  1.1  uch     next
    273  1.1  uch   }
    274  1.1  uch 
    275  1.1  uch   flushname()
    276  1.1  uch   saved_name = toupper($1)
    277  1.1  uch   next
    278  1.1  uch }
    279  1.1  uch {
    280  1.1  uch    printf("SYNTAX ERROR: %s\n", $0) > stderr
    281  1.1  uch }
    282