/* $NetBSD: platid_gen.c,v 1.11 2014/03/26 17:54:46 christos Exp $ */ /*- * Copyright (c) 1999 * Shin Takemura and PocketBSD Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the PocketBSD project * and its contributors. * 4. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include __KERNEL_RCSID(0, "$NetBSD: platid_gen.c,v 1.11 2014/03/26 17:54:46 christos Exp $"); #include #include #include #include #include "platid_gen.h" /* * constants */ #define SEARCH_IGNORECASE (1<<0) #define NMODES 2 #define MAXNEST 4 #define MAXLEN 1024 enum { FORM_GENHDR, FORM_MASK_H, FORM_MASK_C, FORM_NAME_C, FORM_PARSE_ONLY }; /* * data type definitions */ struct genctx_t { int num; const char *alt; const char *node_name[2]; char sym[MAXLEN]; char name[MAXLEN]; } genctx[NMODES][MAXNEST]; /* * function prototypes */ void gen_list(node_t *); void gen_output(void); void gen_header(void); void gen_mask_h(void); void gen_mask_c(void); void gen_name_c(void); void gen_comment(FILE *); void enter(void); void leave(void); /* * global data */ node_t* def_tree; int nest; int mode; FILE *fp_out; int form; int count; #define MODE_INVALID -1 #define MODE_CPU 0 #define MODE_MACHINE 1 char* mode_names[] = { "CPU", "MACHINE", NULL }; #define PREFIX "PLATID" char* prefix_names[] = { "CPU", "MACH", }; char* shift_names[NMODES][MAXNEST] = { { "PLATID_CPU_ARCH_SHIFT", "PLATID_CPU_SERIES_SHIFT", "PLATID_CPU_MODEL_SHIFT", "PLATID_CPU_SUBMODEL_SHIFT", }, { "PLATID_VENDOR_SHIFT", "PLATID_SERIES_SHIFT", "PLATID_MODEL_SHIFT", "PLATID_SUBMODEL_SHIFT", }, }; /* * program entry */ int main(int argc, char *argv[]) { int i; form = FORM_GENHDR; fp_out = stdout; count = 0; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-header") == 0) { form = FORM_GENHDR; } else if (strcmp(argv[i], "-mask_h") == 0) { form = FORM_MASK_H; } else if (strcmp(argv[i], "-mask_c") == 0) { form = FORM_MASK_C; } else if (strcmp(argv[i], "-name_c") == 0) { form = FORM_NAME_C; } else if (strcmp(argv[i], "-parse_only") == 0) { form = FORM_PARSE_ONLY; } else { usage: fprintf(stderr, "usage platid_gen