diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@no-log.org> | 2018-01-10 14:35:55 +0100 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2018-01-18 13:47:20 +0000 |
commit | 780e931eed8937bd8e304449913f487fa1d056c5 (patch) | |
tree | 24446641394bdabfee26130913eed808fe658ffa /util/bincfg | |
parent | 86391f16054ff1aa8af75b552204d24f3c00d50e (diff) |
util/blobtool: rename to bincfg
The name blobtool is confusing as 'blob' is also used to
describe nonfree software in binary form.
Since this utility deals with binary configurations it
makes more sense to call it bincfg.
Change-Id: I3339274f1c42df4bb4a6b30b9538d91c3c03d7d0
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
Reviewed-on: https://review.coreboot.org/23239
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/bincfg')
-rw-r--r-- | util/bincfg/Makefile | 29 | ||||
-rw-r--r-- | util/bincfg/Makefile.inc | 41 | ||||
-rw-r--r-- | util/bincfg/bincfg.l | 133 | ||||
-rw-r--r-- | util/bincfg/bincfg.lex.c_shipped | 1857 | ||||
-rw-r--r-- | util/bincfg/bincfg.tab.c_shipped | 1988 | ||||
-rw-r--r-- | util/bincfg/bincfg.tab.h_shipped | 81 | ||||
-rw-r--r-- | util/bincfg/bincfg.y | 551 | ||||
-rw-r--r-- | util/bincfg/ddr3_unregistered_spd_128.spec | 226 | ||||
-rw-r--r-- | util/bincfg/ddr3_unregistered_spd_256.spec | 241 | ||||
-rw-r--r-- | util/bincfg/gbe-ich9m.set | 88 | ||||
-rw-r--r-- | util/bincfg/gbe-ich9m.spec | 142 | ||||
-rw-r--r-- | util/bincfg/ifd-x200.set | 167 | ||||
-rw-r--r-- | util/bincfg/ifd-x200.spec | 187 | ||||
-rw-r--r-- | util/bincfg/it8718f-ec.spec | 368 |
14 files changed, 6099 insertions, 0 deletions
diff --git a/util/bincfg/Makefile b/util/bincfg/Makefile new file mode 100644 index 0000000000..1b3e93643e --- /dev/null +++ b/util/bincfg/Makefile @@ -0,0 +1,29 @@ +CC = gcc +YACC = bison +LEX = flex +TARGET=bincfg + +$(TARGET): $(TARGET).lex.o $(TARGET).tab.o + $(CC) $^ -Wall -Wno-unused-function -g -lfl -o $@ + +$(TARGET).lex.c: $(TARGET).l $(TARGET).tab.h + $(LEX) -o $(patsubst $(TARGET).l,$(TARGET).lex.c,$<) $< + +$(TARGET).tab.c $(TARGET).tab.h: $(TARGET).y + $(YACC) -d $< + +# Use this target to generate GbE for X200 +gen-gbe-ich9m: + ./bincfg gbe-ich9m.spec gbe-ich9m.set gbe1.bin + # duplicate binary as per spec + cat gbe1.bin gbe1.bin > flashregion_3_gbe.bin + rm -f gbe1.bin + +# Use this target to generate IFD for X200 +gen-ifd-x200: + ./bincfg ifd-x200.spec ifd-x200.set flashregion_0_fd.bin + +.PHONY: clean gen-gbe-ich9m gen-ifd-x200 + +clean: + rm -f *.lex.c *.tab.c *.tab.h *.o bincfg flashregion_0_fd.bin flashregion_3_gbe.bin diff --git a/util/bincfg/Makefile.inc b/util/bincfg/Makefile.inc new file mode 100644 index 0000000000..81c6af63b2 --- /dev/null +++ b/util/bincfg/Makefile.inc @@ -0,0 +1,41 @@ +bincfg_obj := bincfg.lex.o bincfg.tab.o + +BINCFG_FLAGS += -I$(top)/util/bincfg -I$(objutil)/bincfg + +$(objutil)/bincfg: + mkdir -p $@ + +$(objutil)/bincfg/.generated: $(objutil)/bincfg + touch $@ + +$(objutil)/bincfg/%.o: util/bincfg/%.c | $(objutil)/bincfg/.generated + printf " HOSTCC $(subst $(obj)/,,$(@))\n" + $(HOSTCC) $(BINCFG_FLAGS) $(HOSTCFLAGS) -c -o $@ $< + +$(objutil)/bincfg/%.o: $(objutil)/bincfg/%.c + printf " HOSTCC $(subst $(obj)/,,$(@))\n" + $(HOSTCC) $(BINCFG_FLAGS) $(HOSTCFLAGS) -c -o $@ $< + +ifeq ($(CONFIG_UTIL_GENPARSER),y) +$(top)/util/bincfg/bincfg.lex.c_shipped: $(top)/util/bincfg/bincfg.l + printf " FLEX $(subst $(top)/,,$(@))\n" + flex -L -o $@ $< + +# the .c rule also creates .h +$(top)/util/bincfg/bincfg.tab.h_shipped: $(top)/util/bincfg/bincfg.tab.c_shipped +$(top)/util/bincfg/bincfg.tab.c_shipped: $(top)/util/bincfg/bincfg.y + printf " BISON $(subst $(top)/,,$(@))\n" + bison -l --defines=$(top)/util/bincfg/bincfg.tab.h_shipped -o $@ $< +endif + +$(objutil)/bincfg/bincfg.lex.o: $(objutil)/bincfg/bincfg.tab.h + +$(objutil)/bincfg/%: $(top)/util/bincfg/%_shipped + mkdir -p $(dir $@) + cp $< $@ + +$(objutil)/bincfg/bincfg: $(addprefix $(objutil)/bincfg/,$(bincfg_obj)) + printf " HOSTCC $(subst $(obj)/,,$(@)) (link)\n" + $(HOSTCC) $(BINCFG_FLAGS) -o $@ $(addprefix $(objutil)/bincfg/,$(bincfg_obj)) + +$(addprefix $(objutil)/bincfg/,$(bincfg_obj)) : $(objutil)/bincfg/bincfg.tab.h $(objutil)/bincfg/bincfg.tab.c $(objutil)/bincfg/bincfg.lex.c diff --git a/util/bincfg/bincfg.l b/util/bincfg/bincfg.l new file mode 100644 index 0000000000..f9e880f333 --- /dev/null +++ b/util/bincfg/bincfg.l @@ -0,0 +1,133 @@ +/* + * bincfg - Compiler/Decompiler for data blobs with specs + * Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +%{ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "bincfg.tab.h" + +extern struct blob binary; + +unsigned int parsehex (char *s) +{ + unsigned int i, nib, val = 0; + unsigned int nibs = strlen(s) - 2; + + for (i = 2; i < nibs + 2; i++) { + if (s[i] >= '0' && s[i] <= '9') { + nib = s[i] - '0'; + } else if (s[i] >= 'a' && s[i] <= 'f') { + nib = s[i] - 'a' + 10; + } else if (s[i] >= 'A' && s[i] <= 'F') { + nib = s[i] - 'A' + 10; + } else { + return 0; + } + val |= nib << (((nibs - 1) - (i - 2)) * 4); + } + return val; +} + +char* stripquotes (char *string) +{ + char *stripped; + unsigned int len = strlen(string); + if (len >= 2 && string[0] == '"' && string[len - 1] == '"') { + stripped = (char *) malloc (len - 1); + if (stripped == NULL) { + printf("Out of memory\n"); + exit(1); + } + snprintf (stripped, len - 1, "%s", string + 1); + return stripped; + } + return NULL; +} + +%} + +%option noyywrap +%option nounput + +DIGIT [0-9] +INT [-]?{DIGIT}|[-]?[1-9]{DIGIT}+ +FRAC [.]{DIGIT}+ +EXP [eE][+-]?{DIGIT}+ +NUMBER {INT}|{INT}{FRAC}|{INT}{EXP}|{INT}{FRAC}{EXP} +HEX [0][x][0-9a-fA-F]+ +STRING ["][^"]*["] +COMMENT [#][^\n]*$ + +%% + +{STRING} { + yylval.str = stripquotes(yytext); + return name; +}; + +{NUMBER} { + yylval.u32 = atoi(yytext); + return val; +}; + +{HEX} { + yylval.u32 = parsehex(yytext); + return val; +}; + +\{ { + return '{'; +}; + +\} { + return '}'; +}; + +\[ { + return '['; +}; + +\] { + return ']'; +}; + +, { + return ','; +}; + +: { + return ':'; +}; + += { + return '='; +}; + +[ \t\n]+ /* ignore whitespace */; + +{COMMENT} /* ignore comments */ + +\% { + return '%'; +}; + +<<EOF>> { return eof; }; + +%% + +void set_input_string(char* in) { + yy_scan_string(in); +} diff --git a/util/bincfg/bincfg.lex.c_shipped b/util/bincfg/bincfg.lex.c_shipped new file mode 100644 index 0000000000..44a76a1a25 --- /dev/null +++ b/util/bincfg/bincfg.lex.c_shipped @@ -0,0 +1,1857 @@ + +#line 3 "/coreboot/util/bincfg/bincfg.lex.c_shipped" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 39 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <stdlib.h> + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include <inttypes.h> +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + yy_size_t yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define yywrap() 1 +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 14 +#define YY_END_OF_BUFFER 15 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[38] = + { 0, + 0, 0, 15, 14, 11, 14, 14, 13, 8, 14, + 2, 2, 9, 10, 6, 7, 4, 5, 11, 0, + 1, 0, 12, 2, 2, 0, 0, 0, 2, 2, + 0, 2, 3, 0, 0, 2, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 5, 1, 6, 1, 1, 1, + 1, 1, 7, 8, 9, 10, 1, 11, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 13, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 16, 15, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 17, 1, 18, 1, 1, 1, 15, 15, 15, 15, + + 16, 15, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 19, + 1, 1, 20, 1, 21, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[22] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, + 1 + } ; + +static yyconst flex_int16_t yy_base[41] = + { 0, + 0, 0, 56, 69, 20, 49, 43, 69, 69, 13, + 16, 26, 69, 69, 69, 69, 69, 69, 25, 40, + 69, 31, 69, 23, 0, 18, 36, 0, 0, 38, + 29, 40, 0, 48, 50, 52, 69, 64, 66, 29 + } ; + +static yyconst flex_int16_t yy_def[41] = + { 0, + 37, 1, 37, 37, 37, 38, 39, 37, 37, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, + 37, 39, 37, 37, 12, 37, 37, 40, 12, 37, + 37, 37, 40, 37, 37, 37, 0, 37, 37, 37 + } ; + +static yyconst flex_int16_t yy_nxt[91] = + { 0, + 4, 5, 5, 6, 7, 8, 4, 9, 10, 4, + 11, 12, 13, 14, 4, 4, 15, 16, 4, 17, + 18, 19, 19, 24, 25, 26, 19, 19, 30, 30, + 33, 27, 26, 23, 28, 26, 29, 29, 27, 32, + 32, 27, 31, 21, 31, 23, 32, 32, 30, 30, + 32, 32, 21, 34, 35, 37, 35, 37, 36, 36, + 36, 36, 36, 36, 20, 20, 22, 22, 3, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 37 + } ; + +static yyconst flex_int16_t yy_chk[91] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 5, 5, 10, 10, 11, 19, 19, 26, 26, + 40, 11, 24, 22, 11, 12, 12, 12, 24, 31, + 31, 12, 27, 20, 27, 7, 27, 27, 30, 30, + 32, 32, 6, 30, 34, 3, 34, 0, 34, 34, + 35, 35, 36, 36, 38, 38, 39, 39, 37, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 37 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +/* + * bincfg - Compiler/Decompiler for data blobs with specs + * Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "bincfg.tab.h" + +extern struct blob binary; + +unsigned int parsehex (char *s) +{ + unsigned int i, nib, val = 0; + unsigned int nibs = strlen(s) - 2; + + for (i = 2; i < nibs + 2; i++) { + if (s[i] >= '0' && s[i] <= '9') { + nib = s[i] - '0'; + } else if (s[i] >= 'a' && s[i] <= 'f') { + nib = s[i] - 'a' + 10; + } else if (s[i] >= 'A' && s[i] <= 'F') { + nib = s[i] - 'A' + 10; + } else { + return 0; + } + val |= nib << (((nibs - 1) - (i - 2)) * 4); + } + return val; +} + +char* stripquotes (char *string) +{ + char *stripped; + unsigned int len = strlen(string); + if (len >= 2 && string[0] == '"' && string[len - 1] == '"') { + stripped = (char *) malloc (len - 1); + if (stripped == NULL) { + printf("Out of memory\n"); + exit(1); + } + snprintf (stripped, len - 1, "%s", string + 1); + return stripped; + } + return NULL; +} + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include <unistd.h> +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +yy_size_t yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 38 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 69 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +/* rule 1 can match eol */ +YY_RULE_SETUP +{ + yylval.str = stripquotes(yytext); + return name; +}; + YY_BREAK +case 2: +YY_RULE_SETUP +{ + yylval.u32 = atoi(yytext); + return val; +}; + YY_BREAK +case 3: +YY_RULE_SETUP +{ + yylval.u32 = parsehex(yytext); + return val; +}; + YY_BREAK +case 4: +YY_RULE_SETUP +{ + return '{'; +}; + YY_BREAK +case 5: +YY_RULE_SETUP +{ + return '}'; +}; + YY_BREAK +case 6: +YY_RULE_SETUP +{ + return '['; +}; + YY_BREAK +case 7: +YY_RULE_SETUP +{ + return ']'; +}; + YY_BREAK +case 8: +YY_RULE_SETUP +{ + return ','; +}; + YY_BREAK +case 9: +YY_RULE_SETUP +{ + return ':'; +}; + YY_BREAK +case 10: +YY_RULE_SETUP +{ + return '='; +}; + YY_BREAK +case 11: +/* rule 11 can match eol */ +YY_RULE_SETUP +/* ignore whitespace */; + YY_BREAK +case 12: +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ +(yy_c_buf_p) = yy_cp -= 1; +YY_DO_BEFORE_ACTION; /* set up yytext again */ +YY_RULE_SETUP +/* ignore comments */ + YY_BREAK +case 13: +YY_RULE_SETUP +{ + return '%'; +}; + YY_BREAK +case YY_STATE_EOF(INITIAL): +{ return eof; }; + YY_BREAK +case 14: +YY_RULE_SETUP +ECHO; + YY_BREAK + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + yy_size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + yy_size_t new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 38 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 38 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 37); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + yy_size_t num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +yy_size_t yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +void set_input_string(char* in) { + yy_scan_string(in); +} + diff --git a/util/bincfg/bincfg.tab.c_shipped b/util/bincfg/bincfg.tab.c_shipped new file mode 100644 index 0000000000..a76f40ecbd --- /dev/null +++ b/util/bincfg/bincfg.tab.c_shipped @@ -0,0 +1,1988 @@ +/* A Bison parser, made by GNU Bison 3.0.2. */ + +/* Bison implementation for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "3.0.2" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + + + +/* Copy the first part of user declarations. */ + + +#include <stdio.h> +#include <inttypes.h> +#include <stdlib.h> +#include <string.h> +//#define YYDEBUG 1 +int yylex (void); +void yyerror (char const *); + +struct field { + char *name; + unsigned int width; + unsigned int value; + struct field *next; +}; + +extern struct field *sym_table; +struct field *putsym (char const *, unsigned int); +struct field *getsym (char const *); + +struct field *sym_table; +struct field *sym_table_tail; + +FILE* fp; + +/* Bit array intermediary representation */ +struct blob { + unsigned int bloblen; + unsigned char *blb; + unsigned short checksum; + unsigned char *actualblob; + unsigned int lenactualblob; +}; + +#define VALID_BIT 0x80 +#define MAX_WIDTH 32 +#define CHECKSUM_SIZE 16 + +struct blob *binary; + +static void check_pointer (void *ptr) +{ + if (ptr == NULL) { + printf("Error: Out of memory\n"); + exit(1); + } +} + +static unsigned char* value_to_bits (unsigned int v, unsigned int w) +{ + unsigned int i; + unsigned char* bitarr; + + if (w > MAX_WIDTH) w = MAX_WIDTH; + bitarr = (unsigned char *) malloc (w * sizeof (unsigned char)); + check_pointer(bitarr); + memset (bitarr, 0, w); + + for (i = 0; i < w; i++) { + bitarr[i] = VALID_BIT | ((v & (1 << i)) >> i); + } + return bitarr; +} + +/* Store each bit of a bitfield in a new byte sequentially 0x80 or 0x81 */ +static void append_field_to_blob (unsigned char b[], unsigned int w) +{ + unsigned int i, j; + binary->blb = (unsigned char *) realloc (binary->blb, binary->bloblen + w); + check_pointer(binary->blb); + for (j = 0, i = binary->bloblen; i < binary->bloblen + w; i++, j++) { + binary->blb[i] = VALID_BIT | (b[j] & 1); + //fprintf (stderr, "blob[%d] = %d\n", i, binary->blb[i] & 1); + } + binary->bloblen += w; +} + +static void set_bitfield(char *name, unsigned int value) +{ + unsigned long long i; + struct field *bf = getsym (name); + if (bf) { + bf->value = value & 0xffffffff; + i = (1 << bf->width) - 1; + if (bf->width > 8 * sizeof (unsigned int)) { + fprintf(stderr, "Overflow in bitfield, truncating bits to fit\n"); + bf->value = value & i; + } + //fprintf(stderr, "Setting `%s` = %d\n", bf->name, bf->value); + } else { + fprintf(stderr, "Can't find bitfield `%s` in spec\n", name); + } +} + +static void set_bitfield_array(char *name, unsigned int n, unsigned int value) +{ + unsigned int i; + unsigned long len = strlen (name); + char *namen = (char *) malloc ((len + 9) * sizeof (char)); + check_pointer(namen); + for (i = 0; i < n; i++) { + snprintf (namen, len + 8, "%s%x", name, i); + set_bitfield (namen, value); + } + free(namen); +} + +static void create_new_bitfield(char *name, unsigned int width) +{ + struct field *bf; + + if (!(bf = putsym (name, width))) return; + //fprintf(stderr, "Added bitfield `%s` : %d\n", bf->name, width); +} + +static void create_new_bitfields(char *name, unsigned int n, unsigned int width) +{ + unsigned int i; + unsigned long len = strlen (name); + char *namen = (char *) malloc ((len + 9) * sizeof (char)); + check_pointer(namen); + for (i = 0; i < n; i++) { + snprintf (namen, len + 8, "%s%x", name, i); + create_new_bitfield (namen, width); + } + free(namen); +} + +struct field *putsym (char const *sym_name, unsigned int w) +{ + if (getsym(sym_name)) { + fprintf(stderr, "Cannot add duplicate named bitfield `%s`\n", sym_name); + return 0; + } + struct field *ptr = (struct field *) malloc (sizeof (struct field)); + check_pointer(ptr); + ptr->name = (char *) malloc (strlen (sym_name) + 1); + check_pointer(ptr->name); + strcpy (ptr->name, sym_name); + ptr->width = w; + ptr->value = 0; + ptr->next = (struct field *)0; + if (sym_table_tail) { + sym_table_tail->next = ptr; + } else { + sym_table = ptr; + } + sym_table_tail = ptr; + return ptr; +} + +struct field *getsym (char const *sym_name) +{ + struct field *ptr; + for (ptr = sym_table; ptr != (struct field *) 0; + ptr = (struct field *)ptr->next) { + if (strcmp (ptr->name, sym_name) == 0) + return ptr; + } + return 0; +} + +static void dump_all_values (void) +{ + struct field *ptr; + for (ptr = sym_table; ptr != (struct field *) 0; + ptr = (struct field *)ptr->next) { + fprintf(stderr, "%s = %d (%d bits)\n", + ptr->name, + ptr->value, + ptr->width); + } +} + +static void empty_field_table(void) +{ + struct field *ptr; + struct field *ptrnext; + + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptrnext) { + if (ptr) { + ptrnext = ptr->next; + free(ptr); + } else { + ptrnext = (struct field *) 0; + } + } + sym_table = 0; + sym_table_tail = 0; +} + +static void create_binary_blob (void) +{ + if (binary && binary->blb) { + free(binary->blb); + free(binary); + } + binary = (struct blob *) malloc (sizeof (struct blob)); + check_pointer(binary); + binary->blb = (unsigned char *) malloc (sizeof (unsigned char)); + check_pointer(binary->blb); + binary->bloblen = 0; + binary->blb[0] = VALID_BIT; +} + +static void interpret_next_blob_value (struct field *f) +{ + unsigned int i; + unsigned int v = 0; + + if (binary->bloblen >= binary->lenactualblob * 8) { + f->value = 0; + return; + } + + for (i = 0; i < f->width; i++) { + v |= (binary->blb[binary->bloblen++] & 1) << i; + } + + f->value = v; +} + +/* {}%BIN -> {} */ +static void generate_setter_bitfields(unsigned char *bin) +{ + unsigned int i; + struct field *ptr; + + /* Convert bytes to bit array */ + for (i = 0; i < binary->lenactualblob; i++) { + append_field_to_blob (value_to_bits(bin[i], 8), 8); + } + + /* Reset blob position to zero */ + binary->bloblen = 0; + + fprintf (fp, "# AUTOGENERATED SETTER BY BINCFG\n{\n"); + + /* Traverse spec and output bitfield setters based on blob values */ + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + + interpret_next_blob_value(ptr); + fprintf (fp, "\t\"%s\" = 0x%x,\n", ptr->name, ptr->value); + } + fseek(fp, -2, SEEK_CUR); + fprintf (fp, "\n}\n"); +} + +static void generate_binary_with_gbe_checksum(void) +{ + int i; + unsigned short checksum; + + /* traverse spec, push to blob and add up for checksum */ + struct field *ptr; + unsigned int uptochksum = 0; + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + if (strcmp (ptr->name, "checksum_gbe") == 0) { + /* Stop traversing because we hit checksum */ + ptr = ptr->next; + break; + } + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), + ptr->width); + uptochksum += ptr->width; + } + + /* deserialize bits of blob up to checksum */ + for (i = 0; i < uptochksum; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + + /* incremental 16 bit checksum */ + if ((i % 16) < 8) { + binary->checksum += byte; + } else { + binary->checksum += byte << 8; + } + } + + checksum = (0xbaba - binary->checksum) & 0xffff; + + /* Now write checksum */ + set_bitfield ("checksum_gbe", checksum); + + fprintf(fp, "%c", checksum & 0xff); + fprintf(fp, "%c", (checksum & 0xff00) >> 8); + + append_field_to_blob (value_to_bits(checksum, 16), 16); + + for (; ptr != (struct field *) 0; ptr = ptr->next) { + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), ptr->width); + } + + /* deserialize rest of blob past checksum */ + for (i = uptochksum + CHECKSUM_SIZE; i < binary->bloblen; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + } +} + +/* {}{} -> BIN */ +static void generate_binary(void) +{ + unsigned int i; + struct field *ptr; + + if (binary->bloblen % 8) { + fprintf (stderr, "ERROR: Spec must be multiple of 8 bits wide\n"); + exit (1); + } + + if (getsym ("checksum_gbe")) { + generate_binary_with_gbe_checksum(); + return; + } + + /* traverse spec, push to blob */ + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), + ptr->width); + } + + /* deserialize bits of blob */ + for (i = 0; i < binary->bloblen; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + } +} + + + + +# ifndef YY_NULLPTR +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* In a future release of Bison, this section will be replaced + by #include "bincfg.tab.h_shipped". */ +#ifndef YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED +# define YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + name = 258, + val = 259, + vals = 260, + hexbyte = 261, + binblob = 262, + eof = 263 + }; +#endif + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE YYSTYPE; +union YYSTYPE +{ + + + char *str; + unsigned int u32; + unsigned int *u32array; + unsigned char u8; + unsigned char *u8array; + + +}; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED */ + +/* Copy the second part of user declarations. */ + + + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T +# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +#ifndef YY_ATTRIBUTE +# if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +# else +# define YY_ATTRIBUTE(Spec) /* empty */ +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#endif + +#if !defined _Noreturn \ + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +# if defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include <alloca.h> /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include <malloc.h> /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's 'empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (0) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 32 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 17 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 9 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 17 +/* YYNSTATES -- Number of states. */ +#define YYNSTATES 39 + +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 263 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, without out-of-bounds checking. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 9, 2, 2, + 2, 2, 2, 2, 12, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 13, 2, + 2, 14, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 15, 2, 16, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 10, 2, 11, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8 +}; + +#if YYDEBUG + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = +{ + 0, 399, 399, 401, 402, 407, 411, 412, 417, 418, + 422, 423, 427, 428, 433, 434, 438, 439 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || 0 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "name", "val", "vals", "hexbyte", + "binblob", "eof", "'%'", "'{'", "'}'", "','", "':'", "'='", "'['", "']'", + "$accept", "input", "blob", "spec", "specmembers", "specpair", "setter", + "valuemembers", "setpair", YY_NULLPTR +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[NUM] -- (External) token number corresponding to the + (internal) symbol number NUM (which must be that of a token). */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 37, + 123, 125, 44, 58, 61, 91, 93 +}; +# endif + +#define YYPACT_NINF -11 + +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-11))) + +#define YYTABLE_NINF -1 + +#define yytable_value_is_error(Yytable_value) \ + 0 + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int8 yypact[] = +{ + -11, 0, -11, -2, -3, -10, -11, -9, -4, 3, + 1, -11, 7, 12, 13, -11, 15, -11, -1, -11, + 8, 9, -11, -11, 4, -11, 18, 19, -11, 21, + 14, -11, 10, -11, 24, 11, -11, 25, -11 +}; + + /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 2, 0, 1, 0, 0, 0, 6, 0, 8, 0, + 0, 4, 0, 0, 0, 7, 0, 5, 0, 12, + 0, 14, 3, 10, 0, 9, 0, 0, 13, 0, + 0, 16, 0, 15, 0, 0, 11, 0, 17 +}; + + /* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -11, -11, -11, -11, 16, -11, -11, 2, -11 +}; + + /* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 1, 11, 4, 7, 8, 12, 20, 21 +}; + + /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_uint8 yytable[] = +{ + 2, 5, 15, 13, 18, 14, 9, 10, 16, 6, + 3, 17, 19, 26, 27, 22, 23, 24, 5, 28, + 30, 29, 31, 32, 18, 37, 35, 34, 36, 38, + 0, 33, 25 +}; + +static const yytype_int8 yycheck[] = +{ + 0, 3, 11, 13, 3, 15, 9, 10, 12, 11, + 10, 8, 11, 14, 15, 8, 4, 4, 3, 11, + 16, 12, 4, 4, 3, 14, 16, 13, 4, 4, + -1, 29, 16 +}; + + /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 18, 0, 10, 20, 3, 11, 21, 22, 9, + 10, 19, 23, 13, 15, 11, 12, 8, 3, 11, + 24, 25, 8, 4, 4, 21, 14, 15, 11, 12, + 16, 4, 4, 24, 13, 16, 4, 14, 4 +}; + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 17, 18, 18, 18, 19, 20, 20, 21, 21, + 22, 22, 23, 23, 24, 24, 25, 25 +}; + + /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 0, 4, 3, 2, 2, 3, 1, 3, + 3, 6, 2, 3, 1, 3, 3, 6 +}; + + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (0) + +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 + + + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif + + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + + +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ + +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +{ + FILE *yyo = yyoutput; + YYUSE (yyo); + if (!yyvaluep) + return; +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + YYUSE (yytype); +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +{ + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +static void +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) +{ + unsigned long int yylno = yyrline[yyrule]; + int yynrhs = yyr2[yyrule]; + int yyi; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyssp, yyvsp, Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +yystrlen (const char *yystr) +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +yystpcpy (char *yydest, const char *yysrc) +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULLPTR; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + { + YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +{ + YYUSE (yyvaluep); + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_END +} + + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; +/* Number of syntax errors so far. */ +int yynerrs; + + +/*----------. +| yyparse. | +`----------*/ + +int +yyparse (void) +{ + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = yylex (); + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + '$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 3: + + { empty_field_table(); YYACCEPT;} + + break; + + case 4: + + { fprintf (stderr, "Parsed all bytes\n"); + empty_field_table(); YYACCEPT;} + + break; + + case 5: + + { generate_setter_bitfields(binary->actualblob); } + + break; + + case 6: + + { fprintf (stderr, "No spec\n"); } + + break; + + case 7: + + { fprintf (stderr, "Parsed all spec\n"); + create_binary_blob(); } + + break; + + case 10: + + { create_new_bitfield((yyvsp[-2].str), (yyvsp[0].u32)); } + + break; + + case 11: + + { create_new_bitfields((yyvsp[-5].str), (yyvsp[-3].u32), (yyvsp[0].u32)); } + + break; + + case 12: + + { fprintf (stderr, "No values\n"); } + + break; + + case 13: + + { fprintf (stderr, "Parsed all values\n"); + generate_binary(); } + + break; + + case 16: + + { set_bitfield((yyvsp[-2].str), (yyvsp[0].u32)); } + + break; + + case 17: + + { set_bitfield_array((yyvsp[-5].str), (yyvsp[-3].u32), (yyvsp[0].u32)); } + + break; + + + + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + /* Now 'shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*--------------------------------------. +| yyerrlab -- here on detecting error. | +`--------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + + yydestruct ("Error: popping", + yystos[yystate], yyvsp); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined yyoverflow || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval); + } + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + return yyresult; +} + + + +/* Called by yyparse on error. */ +void yyerror (char const *s) +{ + fprintf (stderr, "yyerror: %s\n", s); +} + +/* Declarations */ +void set_input_string(char* in); + +/* This function parses a string */ +static int parse_string(unsigned char* in) { + set_input_string ((char *)in); + return yyparse (); +} + +static unsigned int loadfile (char *file, char *filetype, + unsigned char **parsestring, unsigned int lenstr) +{ + unsigned int lenfile; + + if ((fp = fopen(file, "r")) == NULL) { + printf("Error: Could not open %s file: %s\n",filetype,file); + exit(1); + } + fseek(fp, 0, SEEK_END); + lenfile = ftell(fp); + fseek(fp, 0, SEEK_SET); + + if (lenstr == 0) + *parsestring = (unsigned char *) malloc (lenfile + 2); + else + *parsestring = (unsigned char *) realloc (*parsestring, + lenfile + lenstr); + + check_pointer(*parsestring); + fread(*parsestring + lenstr, 1, lenfile, fp); + fclose(fp); + return lenfile; +} + +int main (int argc, char *argv[]) +{ + unsigned int lenspec; + unsigned char *parsestring; + unsigned char c; + unsigned int pos = 0; + int ret = 0; + +#if YYDEBUG == 1 + yydebug = 1; +#endif + create_binary_blob(); + binary->lenactualblob = 0; + + if (argc == 4 && strcmp(argv[1], "-d") != 0) { + /* Compile mode */ + + /* Load Spec */ + lenspec = loadfile(argv[1], "spec", &parsestring, 0); + loadfile(argv[2], "setter", &parsestring, lenspec); + + /* Open output and parse string - output to fp */ + if ((fp = fopen(argv[3], "wb")) == NULL) { + printf("Error: Could not open output file: %s\n",argv[3]); + exit(1); + } + ret = parse_string(parsestring); + free(parsestring); + } else if (argc == 5 && strcmp (argv[1], "-d") == 0) { + /* Decompile mode */ + + /* Load Spec */ + lenspec = loadfile(argv[2], "spec", &parsestring, 0); + + parsestring[lenspec] = '%'; + parsestring[lenspec + 1] = '\0'; + + /* Load Actual Binary */ + if ((fp = fopen(argv[3], "rb")) == NULL) { + printf("Error: Could not open binary file: %s\n",argv[3]); + exit(1); + } + fseek(fp, 0, SEEK_END); + binary->lenactualblob = ftell(fp); + fseek(fp, 0, SEEK_SET); + binary->actualblob = (unsigned char *) malloc (binary->lenactualblob); + check_pointer(binary->actualblob); + fread(binary->actualblob, 1, binary->lenactualblob, fp); + fclose(fp); + + /* Open output and parse - output to fp */ + if ((fp = fopen(argv[4], "w")) == NULL) { + printf("Error: Could not open output file: %s\n",argv[4]); + exit(1); + } + ret = parse_string(parsestring); + free(parsestring); + free(binary->actualblob); + fclose(fp); + } else { + printf("Usage: Compile mode\n\n"); + printf(" bincfg spec setter binaryoutput\n"); + printf(" (file) (file) (file)\n"); + printf(" OR : Decompile mode\n\n"); + printf(" bincfg -d spec binary setteroutput\n"); + } + return ret; +} diff --git a/util/bincfg/bincfg.tab.h_shipped b/util/bincfg/bincfg.tab.h_shipped new file mode 100644 index 0000000000..f1c223f1fe --- /dev/null +++ b/util/bincfg/bincfg.tab.h_shipped @@ -0,0 +1,81 @@ +/* A Bison parser, made by GNU Bison 3.0.2. */ + +/* Bison interface for Yacc-like parsers in C + + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + +#ifndef YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED +# define YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int yydebug; +#endif + +/* Token type. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + enum yytokentype + { + name = 258, + val = 259, + vals = 260, + hexbyte = 261, + binblob = 262, + eof = 263 + }; +#endif + +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE YYSTYPE; +union YYSTYPE +{ + + + char *str; + unsigned int u32; + unsigned int *u32array; + unsigned char u8; + unsigned char *u8array; + + +}; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 +#endif + + +extern YYSTYPE yylval; + +int yyparse (void); + +#endif /* !YY_YY_COREBOOT_UTIL_BINCFG_BINCFG_TAB_H_SHIPPED_INCLUDED */ diff --git a/util/bincfg/bincfg.y b/util/bincfg/bincfg.y new file mode 100644 index 0000000000..7a098cd258 --- /dev/null +++ b/util/bincfg/bincfg.y @@ -0,0 +1,551 @@ +/* + * bincfg - Compiler/Decompiler for data blobs with specs + * Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +%{ +#include <stdio.h> +#include <inttypes.h> +#include <stdlib.h> +#include <string.h> +//#define YYDEBUG 1 +int yylex (void); +void yyerror (char const *); + +struct field { + char *name; + unsigned int width; + unsigned int value; + struct field *next; +}; + +extern struct field *sym_table; +struct field *putsym (char const *, unsigned int); +struct field *getsym (char const *); + +struct field *sym_table; +struct field *sym_table_tail; + +FILE* fp; + +/* Bit array intermediary representation */ +struct blob { + unsigned int bloblen; + unsigned char *blb; + unsigned short checksum; + unsigned char *actualblob; + unsigned int lenactualblob; +}; + +#define VALID_BIT 0x80 +#define MAX_WIDTH 32 +#define CHECKSUM_SIZE 16 + +struct blob *binary; + +static void check_pointer (void *ptr) +{ + if (ptr == NULL) { + printf("Error: Out of memory\n"); + exit(1); + } +} + +static unsigned char* value_to_bits (unsigned int v, unsigned int w) +{ + unsigned int i; + unsigned char* bitarr; + + if (w > MAX_WIDTH) w = MAX_WIDTH; + bitarr = (unsigned char *) malloc (w * sizeof (unsigned char)); + check_pointer(bitarr); + memset (bitarr, 0, w); + + for (i = 0; i < w; i++) { + bitarr[i] = VALID_BIT | ((v & (1 << i)) >> i); + } + return bitarr; +} + +/* Store each bit of a bitfield in a new byte sequentially 0x80 or 0x81 */ +static void append_field_to_blob (unsigned char b[], unsigned int w) +{ + unsigned int i, j; + binary->blb = (unsigned char *) realloc (binary->blb, binary->bloblen + w); + check_pointer(binary->blb); + for (j = 0, i = binary->bloblen; i < binary->bloblen + w; i++, j++) { + binary->blb[i] = VALID_BIT | (b[j] & 1); + //fprintf (stderr, "blob[%d] = %d\n", i, binary->blb[i] & 1); + } + binary->bloblen += w; +} + +static void set_bitfield(char *name, unsigned int value) +{ + unsigned long long i; + struct field *bf = getsym (name); + if (bf) { + bf->value = value & 0xffffffff; + i = (1 << bf->width) - 1; + if (bf->width > 8 * sizeof (unsigned int)) { + fprintf(stderr, "Overflow in bitfield, truncating bits to fit\n"); + bf->value = value & i; + } + //fprintf(stderr, "Setting `%s` = %d\n", bf->name, bf->value); + } else { + fprintf(stderr, "Can't find bitfield `%s` in spec\n", name); + } +} + +static void set_bitfield_array(char *name, unsigned int n, unsigned int value) +{ + unsigned int i; + unsigned long len = strlen (name); + char *namen = (char *) malloc ((len + 9) * sizeof (char)); + check_pointer(namen); + for (i = 0; i < n; i++) { + snprintf (namen, len + 8, "%s%x", name, i); + set_bitfield (namen, value); + } + free(namen); +} + +static void create_new_bitfield(char *name, unsigned int width) +{ + struct field *bf; + + if (!(bf = putsym (name, width))) return; + //fprintf(stderr, "Added bitfield `%s` : %d\n", bf->name, width); +} + +static void create_new_bitfields(char *name, unsigned int n, unsigned int width) +{ + unsigned int i; + unsigned long len = strlen (name); + char *namen = (char *) malloc ((len + 9) * sizeof (char)); + check_pointer(namen); + for (i = 0; i < n; i++) { + snprintf (namen, len + 8, "%s%x", name, i); + create_new_bitfield (namen, width); + } + free(namen); +} + +struct field *putsym (char const *sym_name, unsigned int w) +{ + if (getsym(sym_name)) { + fprintf(stderr, "Cannot add duplicate named bitfield `%s`\n", sym_name); + return 0; + } + struct field *ptr = (struct field *) malloc (sizeof (struct field)); + check_pointer(ptr); + ptr->name = (char *) malloc (strlen (sym_name) + 1); + check_pointer(ptr->name); + strcpy (ptr->name, sym_name); + ptr->width = w; + ptr->value = 0; + ptr->next = (struct field *)0; + if (sym_table_tail) { + sym_table_tail->next = ptr; + } else { + sym_table = ptr; + } + sym_table_tail = ptr; + return ptr; +} + +struct field *getsym (char const *sym_name) +{ + struct field *ptr; + for (ptr = sym_table; ptr != (struct field *) 0; + ptr = (struct field *)ptr->next) { + if (strcmp (ptr->name, sym_name) == 0) + return ptr; + } + return 0; +} + +static void dump_all_values (void) +{ + struct field *ptr; + for (ptr = sym_table; ptr != (struct field *) 0; + ptr = (struct field *)ptr->next) { + fprintf(stderr, "%s = %d (%d bits)\n", + ptr->name, + ptr->value, + ptr->width); + } +} + +static void empty_field_table(void) +{ + struct field *ptr; + struct field *ptrnext; + + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptrnext) { + if (ptr) { + ptrnext = ptr->next; + free(ptr); + } else { + ptrnext = (struct field *) 0; + } + } + sym_table = 0; + sym_table_tail = 0; +} + +static void create_binary_blob (void) +{ + if (binary && binary->blb) { + free(binary->blb); + free(binary); + } + binary = (struct blob *) malloc (sizeof (struct blob)); + check_pointer(binary); + binary->blb = (unsigned char *) malloc (sizeof (unsigned char)); + check_pointer(binary->blb); + binary->bloblen = 0; + binary->blb[0] = VALID_BIT; +} + +static void interpret_next_blob_value (struct field *f) +{ + unsigned int i; + unsigned int v = 0; + + if (binary->bloblen >= binary->lenactualblob * 8) { + f->value = 0; + return; + } + + for (i = 0; i < f->width; i++) { + v |= (binary->blb[binary->bloblen++] & 1) << i; + } + + f->value = v; +} + +/* {}%BIN -> {} */ +static void generate_setter_bitfields(unsigned char *bin) +{ + unsigned int i; + struct field *ptr; + + /* Convert bytes to bit array */ + for (i = 0; i < binary->lenactualblob; i++) { + append_field_to_blob (value_to_bits(bin[i], 8), 8); + } + + /* Reset blob position to zero */ + binary->bloblen = 0; + + fprintf (fp, "# AUTOGENERATED SETTER BY BINCFG\n{\n"); + + /* Traverse spec and output bitfield setters based on blob values */ + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + + interpret_next_blob_value(ptr); + fprintf (fp, "\t\"%s\" = 0x%x,\n", ptr->name, ptr->value); + } + fseek(fp, -2, SEEK_CUR); + fprintf (fp, "\n}\n"); +} + +static void generate_binary_with_gbe_checksum(void) +{ + int i; + unsigned short checksum; + + /* traverse spec, push to blob and add up for checksum */ + struct field *ptr; + unsigned int uptochksum = 0; + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + if (strcmp (ptr->name, "checksum_gbe") == 0) { + /* Stop traversing because we hit checksum */ + ptr = ptr->next; + break; + } + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), + ptr->width); + uptochksum += ptr->width; + } + + /* deserialize bits of blob up to checksum */ + for (i = 0; i < uptochksum; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + + /* incremental 16 bit checksum */ + if ((i % 16) < 8) { + binary->checksum += byte; + } else { + binary->checksum += byte << 8; + } + } + + checksum = (0xbaba - binary->checksum) & 0xffff; + + /* Now write checksum */ + set_bitfield ("checksum_gbe", checksum); + + fprintf(fp, "%c", checksum & 0xff); + fprintf(fp, "%c", (checksum & 0xff00) >> 8); + + append_field_to_blob (value_to_bits(checksum, 16), 16); + + for (; ptr != (struct field *) 0; ptr = ptr->next) { + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), ptr->width); + } + + /* deserialize rest of blob past checksum */ + for (i = uptochksum + CHECKSUM_SIZE; i < binary->bloblen; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + } +} + +/* {}{} -> BIN */ +static void generate_binary(void) +{ + unsigned int i; + struct field *ptr; + + if (binary->bloblen % 8) { + fprintf (stderr, "ERROR: Spec must be multiple of 8 bits wide\n"); + exit (1); + } + + if (getsym ("checksum_gbe")) { + generate_binary_with_gbe_checksum(); + return; + } + + /* traverse spec, push to blob */ + for (ptr = sym_table; ptr != (struct field *) 0; ptr = ptr->next) { + append_field_to_blob ( + value_to_bits(ptr->value, ptr->width), + ptr->width); + } + + /* deserialize bits of blob */ + for (i = 0; i < binary->bloblen; i += 8) { + unsigned char byte = (((binary->blb[i+0] & 1) << 0) + | ((binary->blb[i+1] & 1) << 1) + | ((binary->blb[i+2] & 1) << 2) + | ((binary->blb[i+3] & 1) << 3) + | ((binary->blb[i+4] & 1) << 4) + | ((binary->blb[i+5] & 1) << 5) + | ((binary->blb[i+6] & 1) << 6) + | ((binary->blb[i+7] & 1) << 7) + ); + fprintf(fp, "%c", byte); + } +} + +%} + +%union +{ + char *str; + unsigned int u32; + unsigned int *u32array; + unsigned char u8; + unsigned char *u8array; +} + +%token <str> name +%token <u32> val +%token <u32array> vals +%token <u8> hexbyte +%token <u8array> binblob +%token <u8> eof + +%left '%' +%left '{' '}' +%left ',' +%left ':' +%left '=' + +%% + +input: + /* empty */ +| input spec setter eof { empty_field_table(); YYACCEPT;} +| input spec blob { fprintf (stderr, "Parsed all bytes\n"); + empty_field_table(); YYACCEPT;} +; + +blob: + '%' eof { generate_setter_bitfields(binary->actualblob); } +; + +spec: + '{' '}' { fprintf (stderr, "No spec\n"); } +| '{' specmembers '}' { fprintf (stderr, "Parsed all spec\n"); + create_binary_blob(); } +; + +specmembers: + specpair +| specpair ',' specmembers +; + +specpair: + name ':' val { create_new_bitfield($1, $3); } +| name '[' val ']' ':' val { create_new_bitfields($1, $3, $6); } +; + +setter: + '{' '}' { fprintf (stderr, "No values\n"); } +| '{' valuemembers '}' { fprintf (stderr, "Parsed all values\n"); + generate_binary(); } +; + +valuemembers: + setpair +| setpair ',' valuemembers +; + +setpair: + name '=' val { set_bitfield($1, $3); } +| name '[' val ']' '=' val { set_bitfield_array($1, $3, $6); } +; + +%% + +/* Called by yyparse on error. */ +void yyerror (char const *s) +{ + fprintf (stderr, "yyerror: %s\n", s); +} + +/* Declarations */ +void set_input_string(char* in); + +/* This function parses a string */ +static int parse_string(unsigned char* in) { + set_input_string ((char *)in); + return yyparse (); +} + +static unsigned int loadfile (char *file, char *filetype, + unsigned char **parsestring, unsigned int lenstr) +{ + unsigned int lenfile; + + if ((fp = fopen(file, "r")) == NULL) { + printf("Error: Could not open %s file: %s\n",filetype,file); + exit(1); + } + fseek(fp, 0, SEEK_END); + lenfile = ftell(fp); + fseek(fp, 0, SEEK_SET); + + if (lenstr == 0) + *parsestring = (unsigned char *) malloc (lenfile + 2); + else + *parsestring = (unsigned char *) realloc (*parsestring, + lenfile + lenstr); + + check_pointer(*parsestring); + fread(*parsestring + lenstr, 1, lenfile, fp); + fclose(fp); + return lenfile; +} + +int main (int argc, char *argv[]) +{ + unsigned int lenspec; + unsigned char *parsestring; + unsigned char c; + unsigned int pos = 0; + int ret = 0; + +#if YYDEBUG == 1 + yydebug = 1; +#endif + create_binary_blob(); + binary->lenactualblob = 0; + + if (argc == 4 && strcmp(argv[1], "-d") != 0) { + /* Compile mode */ + + /* Load Spec */ + lenspec = loadfile(argv[1], "spec", &parsestring, 0); + loadfile(argv[2], "setter", &parsestring, lenspec); + + /* Open output and parse string - output to fp */ + if ((fp = fopen(argv[3], "wb")) == NULL) { + printf("Error: Could not open output file: %s\n",argv[3]); + exit(1); + } + ret = parse_string(parsestring); + free(parsestring); + } else if (argc == 5 && strcmp (argv[1], "-d") == 0) { + /* Decompile mode */ + + /* Load Spec */ + lenspec = loadfile(argv[2], "spec", &parsestring, 0); + + parsestring[lenspec] = '%'; + parsestring[lenspec + 1] = '\0'; + + /* Load Actual Binary */ + if ((fp = fopen(argv[3], "rb")) == NULL) { + printf("Error: Could not open binary file: %s\n",argv[3]); + exit(1); + } + fseek(fp, 0, SEEK_END); + binary->lenactualblob = ftell(fp); + fseek(fp, 0, SEEK_SET); + binary->actualblob = (unsigned char *) malloc (binary->lenactualblob); + check_pointer(binary->actualblob); + fread(binary->actualblob, 1, binary->lenactualblob, fp); + fclose(fp); + + /* Open output and parse - output to fp */ + if ((fp = fopen(argv[4], "w")) == NULL) { + printf("Error: Could not open output file: %s\n",argv[4]); + exit(1); + } + ret = parse_string(parsestring); + free(parsestring); + free(binary->actualblob); + fclose(fp); + } else { + printf("Usage: Compile mode\n\n"); + printf(" bincfg spec setter binaryoutput\n"); + printf(" (file) (file) (file)\n"); + printf(" OR : Decompile mode\n\n"); + printf(" bincfg -d spec binary setteroutput\n"); + } + return ret; +} diff --git a/util/bincfg/ddr3_unregistered_spd_128.spec b/util/bincfg/ddr3_unregistered_spd_128.spec new file mode 100644 index 0000000000..3bf027af80 --- /dev/null +++ b/util/bincfg/ddr3_unregistered_spd_128.spec @@ -0,0 +1,226 @@ +# Applies to unbuffered DIMM types +# UDIMM, SO-DIMM, Micro-DIMM, Micro-UDIMM, +# 72b-SO-UDIMM, 16b-SO-UDIMM, 32b-SO-UDIMM + + +# 4_01_02_11R24.pdf +# +# JEDEC Standard No. 21-C +# Page 4.1.2.11 - 1 +# Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM Modules +# DDR3 SPD +# Document Release 6 +# UDIMM Revision 1.3 +# RDIMM Revision 1.3 +# CDIMM Revision 1.3 +# LRDIMM Revision 1.2 + +{ + # Byte 0: Number of Bytes Used / Number of Bytes in SPD Device / + # CRC Coverage + "SPD_Bytes_Used" : 4, + "SPD_Bytes_Total" : 3, + "CRC_Coverage" : 1, + + # Byte 1: SPD Revision + "SPD_Revision" : 8, + + # Byte 2: Key Byte / DRAM Device Type + "DRAM_Device_Type" : 8, + + # Byte 3: Key Byte / Module Type + "Module_Type" : 4, + "Byte_3_reserved" : 4, + + # Byte 4: SDRAM Density and Banks + "SDRAM_Capacity" : 4, + "Bank_Address_Bits" : 3, + "Byte_4_reserved" : 1, + + # Byte 5: SDRAM Addressing + "Column_Address_Bits" : 3, + "Row_Address_Bits" : 3, + "Byte_5_reserved" : 2, + + # Byte 6: Module Nominal Voltage, VDD + "NOT_1.5_V_Operable" : 1, + "1.35_V_Operable" : 1, + "1.25_V_Operable" : 1, + "Byte_6_reserved" : 5, + + # Byte 7: Module Organization + "SDRAM_Device_Width" : 3, + "Number_of_Ranks" : 3, + "Byte_7_reserved" : 2, + + # Byte 8: Module Memory Bus Width + "Primary_Bus_Width" : 3, + "Bus_Width_Extension" : 3, + "Byte_8_reserved" : 2, + + # Byte 9: Fine Timebase (FTB) Dividend / Divisor + "Fine_Timebase_Divisor" : 4, + "Fine_Timebase_Dividend" : 4, + + # Bytes 10 / 11: Medium Timebase (MTB) Dividend / Divisor + "Medium_Timebase_Dividend" : 8, + "Medium_Timebase_Divisor" : 8, + + # Byte 12: SDRAM Minimum Cycle Time (t CK min) + "Minimum_SDRAM_Cycle_Time" : 8, + + # Byte 13: Reserved + "Byte_13_Reserved" : 8, + + # Bytes 14 / 15: CAS Latencies Supported + "CL_4_Supported" : 1, + "CL_5_Supported" : 1, + "CL_6_Supported" : 1, + "CL_7_Supported" : 1, + "CL_8_Supported" : 1, + "CL_9_Supported" : 1, + "CL_10_Supported" : 1, + "CL_11_Supported" : 1, + + "CL_12_Supported" : 1, + "CL_13_Supported" : 1, + "CL_14_Supported" : 1, + "CL_15_Supported" : 1, + "CL_16_Supported" : 1, + "CL_17_Supported" : 1, + "CL_18_Supported" : 1, + "Byte_15_Reserved" : 1, + + # Byte 16: Minimum CAS Latency Time (tAAmin) + "tAAmin" : 8, + + # Byte 17: Minimum Write Recovery Time (tWRmin) + "tWRmin" : 8, + + # Byte 18: Minimum RAS to CAS Delay Time (tRCDmin) + "tRCDmin" : 8, + + # Byte 19: Minimum Row Active to Row Active Delay Time (tRRDmin) + "tRRDmin" : 8, + + # Byte 20: Minimum Row Precharge Delay Time (tRPmin) + "tRPmin" : 8, + + # Bytes 21 - 23: Minimum Active to Precharge Delay Time (tRASmin) + # / Minimum Active to Active/Refresh Delay Time + # (tRCmin) + "tRASmin_Most_Significant Nibble" : 4, + "tRCmin_Most_Significant Nibble" : 4, + "tRASmin_LSB" : 8, + "tRCmin_LSB" : 8, + + # Bytes 24 - 25: Minimum Refresh Recovery Delay Time (tRFCmin) + "tRFCmin LSB" : 8, + "tRFCmin MSB" : 8, + + # Byte 26: Minimum Internal Write to Read Command Delay Time + "tWTRmin" : 8, + + # Byte 27: Minimum Internal Read to Precharge Command Delay Time + # (tRTPmin) + "tRTPmin" : 8, + + # Byte 28 - 29: Minimum Four Activate Window Delay Time + # (tFAWmin) + "tFAWmin Most Significant Nibble" : 4, + "Byte_28_Reserved" : 4, + "tFAWmin Most Significant Byte" : 8, + + # Byte 30: SDRAM Optional Features + "RQZ_Div_6_Supported" : 1, + "RQZ_Div_7_Supported" : 1, + "Byte_30_Reserved" : 5, + "DLL_Off_Mode_Supported" : 1, + + # Byte 31: SDRAM Thermal and Refresh + # Options + "Extended_Temp_range_supported" : 1, + "Extended_Temp_Refresh_1x_Refresh" : 1, + "Auto_Self_Refresh_Supported" : 1, + "On-Die_Thermal_Sensor" : 1, + "Byte_31_Reserved" : 3, + "Partial_Array_Self_Refresh_Supported" : 1, + + # Byte 32: Module Thermal Sensor + "Thermal_Sensor_Accuracy" : 7, + "Thermal_Sensor_incorporated" : 1, + + # Byte 33: SDRAM Device Type + "Signal_Loading" : 2, + "Byte_33_Reserved" : 2, + "Die_Count" : 3, + "SDRAM_Device_Type" : 1, + + # Byte 34: Fine Offset for SDRAM Minimum + # Cycle Time (tCKmin) + "tCKmin_Fine_Offset" : 8, + + #Byte 35: Fine Offset for Minimum CAS Latency Time (tAAmin) + "tAAmin_Fine_Offset" : 8, + + # Byte 36: Fine Offset for Minimum RAS to CAS Delay Time + # (tRCDmin) + "tRCDmin_Fine_Offset" : 8, + + #Byte 37: Fine Offset for Minimum Row Precharge Delay Time + # (tRPmin) + "tRPmin_Fine_Offset" : 8, + + # Byte 38: Fine Offset for Minimum Active to Active/Refresh + # Delay Time (tRCmin) + "tRCmin_Fine_Offset" : 8, + + # Bytes 39 / 40: Reserved + "Byte_39_Reserved" : 8, + "Byte_40_Reserved" : 8, + + # Byte 41: SDRAM Maximum Active Count (MAC) Value + "Maximum_Activate_Count" : 4, + "Maximum_Activate_Window" : 2, + "Byte_41_Reserved" : 2, + + # Bytes 42 - 59: Reserved + "Reserved_bytes_42_to_59_" [18] : 8, + +# Module-Specific Section: Bytes 60 - 116 for Unbuffered DIMMS + + # Byte 60 (Unbuffered): Raw Card Extension, Module Nominal Height + "Module_Nominal_Height" : 5, + "Raw_Card_Estension" : 3, + + # Byte 61 (Unbuffered): Module Maximum Thickness + "Module_Thickness_Front" : 4, + "Module_Thickness_Back" : 4, + + # Byte 62 (Unbuffered): Reference Raw Card Used + "Reference_Raw_Card" : 5, + "Reference_Raw_Card_Revision" : 2, + "Reference_Raw_Card_Extension" : 1, + + # Byte 63: Address Mapping from Edge Connector to DRAM + "Rank_1_Mapping_Mirrored" : 1, + "Byte_63_Reserved" : 7, + + # Bytes 64 -116 (Unbuffered): Reserved + "Module_Specific_Byte_Reserved_"[53] : 8, + + # Bytes 117 - 118: Module ID: Module Manufacturers JEDEC ID Code + "Module_Manufacturer_JEDEC_ID_Code" : 16, + + # Byte 119: Module ID: Module Manufacturing Location + "Module_Manufacturing_Location" : 8, + + # Bytes 120 - 121: Module ID: Module Manufacturing Date + "Module_Manufacturing_Date" : 16, + + # Bytes 122 - 125: Module ID: Module Serial Number + "Module_Serial_Number" : 32, + + # Bytes 126 - 127: Cyclical Redundancy Code + "Module_CRC" : 16 +} diff --git a/util/bincfg/ddr3_unregistered_spd_256.spec b/util/bincfg/ddr3_unregistered_spd_256.spec new file mode 100644 index 0000000000..d9cf51e857 --- /dev/null +++ b/util/bincfg/ddr3_unregistered_spd_256.spec @@ -0,0 +1,241 @@ +# Applies to unbuffered DIMM types +# UDIMM, SO-DIMM, Micro-DIMM, Micro-UDIMM, +# 72b-SO-UDIMM, 16b-SO-UDIMM, 32b-SO-UDIMM + + +# 4_01_02_11R24.pdf +# +# JEDEC Standard No. 21-C +# Page 4.1.2.11 - 1 +# Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM Modules +# DDR3 SPD +# Document Release 6 +# UDIMM Revision 1.3 +# RDIMM Revision 1.3 +# CDIMM Revision 1.3 +# LRDIMM Revision 1.2 + +{ + # Byte 0: Number of Bytes Used / Number of Bytes in SPD Device / + # CRC Coverage + "SPD_Bytes_Used" : 4, + "SPD_Bytes_Total" : 3, + "CRC_Coverage" : 1, + + # Byte 1: SPD Revision + "SPD_Revision" : 8, + + # Byte 2: Key Byte / DRAM Device Type + "DRAM_Device_Type" : 8, + + # Byte 3: Key Byte / Module Type + "Module_Type" : 4, + "Byte_3_reserved" : 4, + + # Byte 4: SDRAM Density and Banks + "SDRAM_Capacity" : 4, + "Bank_Address_Bits" : 3, + "Byte_4_reserved" : 1, + + # Byte 5: SDRAM Addressing + "Column_Address_Bits" : 3, + "Row_Address_Bits" : 3, + "Byte_5_reserved" : 2, + + # Byte 6: Module Nominal Voltage, VDD + "NOT_1.5_V_Operable" : 1, + "1.35_V_Operable" : 1, + "1.25_V_Operable" : 1, + "Byte_6_reserved" : 5, + + # Byte 7: Module Organization + "SDRAM_Device_Width" : 3, + "Number_of_Ranks" : 3, + "Byte_7_reserved" : 2, + + # Byte 8: Module Memory Bus Width + "Primary_Bus_Width" : 3, + "Bus_Width_Extension" : 3, + "Byte_8_reserved" : 2, + + # Byte 9: Fine Timebase (FTB) Dividend / Divisor + "Fine_Timebase_Divisor" : 4, + "Fine_Timebase_Dividend" : 4, + + # Bytes 10 / 11: Medium Timebase (MTB) Dividend / Divisor + "Medium_Timebase_Dividend" : 8, + "Medium_Timebase_Divisor" : 8, + + # Byte 12: SDRAM Minimum Cycle Time (t CK min) + "Minimum_SDRAM_Cycle_Time" : 8, + + # Byte 13: Reserved + "Byte_13_Reserved" : 8, + + # Bytes 14 / 15: CAS Latencies Supported + "CL_4_Supported" : 1, + "CL_5_Supported" : 1, + "CL_6_Supported" : 1, + "CL_7_Supported" : 1, + "CL_8_Supported" : 1, + "CL_9_Supported" : 1, + "CL_10_Supported" : 1, + "CL_11_Supported" : 1, + + "CL_12_Supported" : 1, + "CL_13_Supported" : 1, + "CL_14_Supported" : 1, + "CL_15_Supported" : 1, + "CL_16_Supported" : 1, + "CL_17_Supported" : 1, + "CL_18_Supported" : 1, + "Byte_15_Reserved" : 1, + + # Byte 16: Minimum CAS Latency Time (tAAmin) + "tAAmin" : 8, + + # Byte 17: Minimum Write Recovery Time (tWRmin) + "tWRmin" : 8, + + # Byte 18: Minimum RAS to CAS Delay Time (tRCDmin) + "tRCDmin" : 8, + + # Byte 19: Minimum Row Active to Row Active Delay Time (tRRDmin) + "tRRDmin" : 8, + + # Byte 20: Minimum Row Precharge Delay Time (tRPmin) + "tRPmin" : 8, + + # Bytes 21 - 23: Minimum Active to Precharge Delay Time (tRASmin) + # / Minimum Active to Active/Refresh Delay Time + # (tRCmin) + "tRASmin_Most_Significant Nibble" : 4, + "tRCmin_Most_Significant Nibble" : 4, + "tRASmin_LSB" : 8, + "tRCmin_LSB" : 8, + + # Bytes 24 - 25: Minimum Refresh Recovery Delay Time (tRFCmin) + "tRFCmin LSB" : 8, + "tRFCmin MSB" : 8, + + # Byte 26: Minimum Internal Write to Read Command Delay Time + "tWTRmin" : 8, + + # Byte 27: Minimum Internal Read to Precharge Command Delay Time + # (tRTPmin) + "tRTPmin" : 8, + + # Byte 28 - 29: Minimum Four Activate Window Delay Time + # (tFAWmin) + "tFAWmin Most Significant Nibble" : 4, + "Byte_28_Reserved" : 4, + "tFAWmin Most Significant Byte" : 8, + + # Byte 30: SDRAM Optional Features + "RQZ_Div_6_Supported" : 1, + "RQZ_Div_7_Supported" : 1, + "Byte_30_Reserved" : 5, + "DLL_Off_Mode_Supported" : 1, + + # Byte 31: SDRAM Thermal and Refresh + # Options + "Extended_Temp_range_supported" : 1, + "Extended_Temp_Refresh_1x_Refresh" : 1, + "Auto_Self_Refresh_Supported" : 1, + "On-Die_Thermal_Sensor" : 1, + "Byte_31_Reserved" : 3, + "Partial_Array_Self_Refresh_Supported" : 1, + + # Byte 32: Module Thermal Sensor + "Thermal_Sensor_Accuracy" : 7, + "Thermal_Sensor_incorporated" : 1, + + # Byte 33: SDRAM Device Type + "Signal_Loading" : 2, + "Byte_33_Reserved" : 2, + "Die_Count" : 3, + "SDRAM_Device_Type" : 1, + + # Byte 34: Fine Offset for SDRAM Minimum + # Cycle Time (tCKmin) + "tCKmin_Fine_Offset" : 8, + + #Byte 35: Fine Offset for Minimum CAS Latency Time (tAAmin) + "tAAmin_Fine_Offset" : 8, + + # Byte 36: Fine Offset for Minimum RAS to CAS Delay Time + # (tRCDmin) + "tRCDmin_Fine_Offset" : 8, + + #Byte 37: Fine Offset for Minimum Row Precharge Delay Time + # (tRPmin) + "tRPmin_Fine_Offset" : 8, + + # Byte 38: Fine Offset for Minimum Active to Active/Refresh + # Delay Time (tRCmin) + "tRCmin_Fine_Offset" : 8, + + # Bytes 39 / 40: Reserved + "Byte_39_Reserved" : 8, + "Byte_40_Reserved" : 8, + + # Byte 41: SDRAM Maximum Active Count (MAC) Value + "Maximum_Activate_Count" : 4, + "Maximum_Activate_Window" : 2, + "Byte_41_Reserved" : 2, + + # Bytes 42 - 59: Reserved + "Reserved_bytes_42_to_59_" [18] : 8, + +# Module-Specific Section: Bytes 60 - 116 for Unbuffered DIMMS + + # Byte 60 (Unbuffered): Raw Card Extension, Module Nominal Height + "Module_Nominal_Height" : 5, + "Raw_Card_Estension" : 3, + + # Byte 61 (Unbuffered): Module Maximum Thickness + "Module_Thickness_Front" : 4, + "Module_Thickness_Back" : 4, + + # Byte 62 (Unbuffered): Reference Raw Card Used + "Reference_Raw_Card" : 5, + "Reference_Raw_Card_Revision" : 2, + "Reference_Raw_Card_Extension" : 1, + + # Byte 63: Address Mapping from Edge Connector to DRAM + "Rank_1_Mapping_Mirrored" : 1, + "Byte_63_Reserved" : 7, + + # Bytes 64 -116 (Unbuffered): Reserved + "Module_Specific_Byte_Reserved_"[53] : 8, + + # Bytes 117 - 118: Module ID: Module Manufacturers JEDEC ID Code + "Module_Manufacturer_JEDEC_ID_Code" : 16, + + # Byte 119: Module ID: Module Manufacturing Location + "Module_Manufacturing_Location" : 8, + + # Bytes 120 - 121: Module ID: Module Manufacturing Date + "Module_Manufacturing_Date" : 16, + + # Bytes 122 - 125: Module ID: Module Serial Number + "Module_Serial_Number" : 32, + + # Bytes 126 - 127: Cyclical Redundancy Code + "Module_CRC" : 16, + + # Bytes 128 - 145: Module Part Number + "Module_Part_Number"[18] : 8, + + # Bytes 146 - 147: Module Revision Code + "Module_Revision_Code" : 16, + + # Bytes 148 - 149: DRAM Manufacturers JEDEC ID Code + "DRAM_Manufacturer_JEDEC_ID_Code" : 16, + + # Bytes 150 - 175: Manufacturers Specific Data + "Manufacturer_Specific_Data_byte_" [26] : 8, + + # Bytes 176 - 255: Open for customer use + "Customer_use_byte_" [80] : 8 +} diff --git a/util/bincfg/gbe-ich9m.set b/util/bincfg/gbe-ich9m.set new file mode 100644 index 0000000000..01f85aba86 --- /dev/null +++ b/util/bincfg/gbe-ich9m.set @@ -0,0 +1,88 @@ +# +# Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# GbE values for ICH9M +{ + # Hardcoded chipset values + "reserved04" = 0xffff, + "version05" = 0x1083, + "reserved06" = 0xffff, + "reserved07" = 0xffff, + "pbalow" = 0xffff, + "pbahigh" = 0xffff, + "pci_loadvid" = 1, + "pci_loadssid" = 1, + "pci_pmen" = 1, + "pci_auxpwr" = 1, + "pci_reserved4" = 1, + "sh_phy_enpwrdown" = 1, + "sh_reserved1" = 0x5, + "sh_reserved3" = 1, + "sh_sign" = 0x2, + "cw1_extcfgptr" = 0x020, + "cw1_oemload" = 1, + "cw1_reserved1" = 1, + "cw2_extphylen" = 0x05, + "l1_reserved2" = 1, + "l1_reserved4" = 1, + "l1_lplu_non_d0a" = 1, + "l1_gbedis_non_d0a" = 1, + "reserved19" = 0x2b40, + "reserved1a" = 0x0043, + "reserved1c" = 0x10f5, + "reserved1d" = 0xbaad, + "_82567lm" = 0x10f5, + "_82567lf" = 0x10bf, + "reserved20" = 0xbaad, + "_82567v" = 0x10cb, + "reserved22_0" = 0xbaad, + "reserved22_1" = 0xbaad, + + # Hardcoded PXE setup (disabled) + "pxe30_defbootsel" = 0x3, + "pxe30_ctrlsprompt" = 0x3, + "pxe30_pxeabsent" = 1, + "pxe31_disablemenu" = 1, + "pxe31_disabletitle" = 1, + "pxe31_signature" = 1, + "pxe32_buildnum" = 0x18, + "pxe32_minorversion" = 0x3, + "pxe32_majorversion" = 0x1, + "pxe33_basecodeabsent" = 1, + "pxe33_undipresent" = 1, + "pxe33_reserved1" = 1, + "pxe33_signature" = 1, + "pxe_padding"[11] = 0xffff, + + # GbE power settings + "lanpwr_d3pwr" = 1, + "lanpwr_d0pwr" = 13, + + # GbE LED modes + "l1_led1mode" = 0xb, + "l1_led1blinks" = 1, + "l02_led0mode" = 0x2, + "l02_led2mode" = 0x1, + + # Padding 0xf80 bytes + "padding"[0xf80] = 0xff, + + # TODO: make command line switch for these + + # Configurable PCI IDs + "ssdid" = 0x20ee, + "ssvid" = 0x17aa, + "did" = 0x10f5, + "vid" = 0x8086 +} diff --git a/util/bincfg/gbe-ich9m.spec b/util/bincfg/gbe-ich9m.spec new file mode 100644 index 0000000000..45eed0e043 --- /dev/null +++ b/util/bincfg/gbe-ich9m.spec @@ -0,0 +1,142 @@ +# +# Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org> +# Leah Rowe <info@minifree.org> +# Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# +# Datasheets: +# +# http://www.intel.co.uk/content/dam/doc/application-note/i-o-controller-hub-9m-82567lf-lm-v-nvm-map-appl-note.pdf +# https://communities.intel.com/community/wired/blog/2010/10/14/how-to-basic-eeprom-checksums + +# The datasheet says that this spec covers the following pci ids: +# 8086:10F5 - Intel 82567LM gigabit ethernet controller +# 8086:10BF - Intel 82567LF gigabit ethernet controller +# 8086:10CB - Intel 82567V gigabit ethernet controller + +# GbE SPEC for ICH9M (82567LM/LF/V) +{ + "macaddress"[6] : 8, + "ba_reserved1_0" : 8, + "ba_reserved1_1" : 3, + "ba_ibootagent" : 1, + "ba_reserved2" : 4, + "reserved04" : 16, + "version05" : 16, + "reserved06" : 16, + "reserved07" : 16, + "pbalow" : 16, + "pbahigh" : 16, + "pci_loadvid" : 1, + "pci_loadssid" : 1, + "pci_reserved1" : 1, + "pci_reserved2" : 3, + "pci_pmen" : 1, + "pci_auxpwr" : 1, + "pci_reserved3" : 4, + "pci_reserved4" : 4, + "ssdid" : 16, + "ssvid" : 16, + "did" : 16, + "vid" : 16, + "devrevid" : 16, + "lanpwr_d3pwr" : 5, + "lanpwr_reserved" : 3, + "lanpwr_d0pwr" : 8, + "reserved11" : 16, + "reserved12" : 16, + "sh_reserved1" : 3, + "sh_force_halfduplex" : 1, + "sh_force_lowspeed" : 1, + "sh_reserved2_0" : 3, + "sh_reserved2_1" : 1, + "sh_phy_enpwrdown" : 1, + "sh_reserved3" : 1, + "sh_reserved4" : 3, + "sh_sign" : 2, + "cw1_extcfgptr" : 12, + "cw1_oemload" : 1, + "cw1_reserved1" : 1, + "cw1_reserved2" : 1, + "cw1_reserved3" : 1, + "cw2_reserved" : 8, + "cw2_extphylen" : 8, + "extcfg16" : 16, + "l1_led1mode" : 4, + "l1_reserved1" : 1, + "l1_led1fastblink" : 1, + "l1_led1invert" : 1, + "l1_led1blinks" : 1, + "l1_reserved2" : 1, + "l1_lplu_all" : 1, + "l1_lplu_non_d0a" : 1, + "l1_gbedis_non_d0a" : 1, + "l1_reserved3" : 2, + "l1_gbedis" : 1, + "l1_reserved4" : 1, + "l02_led0mode" : 4, + "l02_reserved1" : 1, + "l02_led0fastblink" : 1, + "l02_led0invert" : 1, + "l02_led0blinks" : 1, + "l02_led2mode" : 4, + "l02_reserved2" : 1, + "l02_led2fastblink" : 1, + "l02_led2invert" : 1, + "l02_led2blinks" : 1, + "reserved19" : 16, + "reserved1a" : 16, + "reserved1b" : 16, + "reserved1c" : 16, + "reserved1d" : 16, + "_82567lm" : 16, + "_82567lf" : 16, + "reserved20" : 16, + "_82567v" : 16, + "reserved22_"[14] : 16, + "pxe30_protocolsel" : 2, + "pxe30_reserved1" : 1, + "pxe30_defbootsel" : 2, + "pxe30_reserved2" : 1, + "pxe30_ctrlsprompt" : 2, + "pxe30_dispsetup" : 1, + "pxe30_reserved3" : 1, + "pxe30_forcespeed" : 2, + "pxe30_forcefullduplex" : 1, + "pxe30_reserved4" : 1, + "pxe30_efipresent" : 1, + "pxe30_pxeabsent" : 1, + "pxe31_disablemenu" : 1, + "pxe31_disabletitle" : 1, + "pxe31_disableprotsel" : 1, + "pxe31_disablebootorder": 1, + "pxe31_disablelegacywak": 1, + "pxe31_disableflash_pro": 1, + "pxe31_reserved1" : 2, + "pxe31_ibootagentmode" : 3, + "pxe31_reserved2" : 3, + "pxe31_signature" : 2, + "pxe32_buildnum" : 8, + "pxe32_minorversion" : 4, + "pxe32_majorversion" : 4, + "pxe33_basecodeabsent" : 1, + "pxe33_undipresent" : 1, + "pxe33_reserved1" : 1, + "pxe33_efiundipresent" : 1, + "pxe33_reserved2_0" : 4, + "pxe33_reserved2_1" : 6, + "pxe33_signature" : 2, + "pxe_padding"[11] : 16, + "checksum_gbe" : 16, + "padding"[0xf80] : 8 +} diff --git a/util/bincfg/ifd-x200.set b/util/bincfg/ifd-x200.set new file mode 100644 index 0000000000..255eb88b70 --- /dev/null +++ b/util/bincfg/ifd-x200.set @@ -0,0 +1,167 @@ +# +# Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# +# X200 Liberated Flash Descriptor +# Layout: +# 0x0000 - 0x1000 : IFD +# 0x1000 - 0x3000 : GbE x2 +# 0x3000 - ROMSIZE : BIOS +{ + "fd_signature" = 0xff0a55a, + + "flmap0_fcba" = 0x1, + "flmap0_nc" = 0x0, + "flmap0_reserved0" = 0x0, + "flmap0_frba" = 0x4, + "flmap0_nr" = 0x3, + "flmap0_reserved1" = 0x0, + "flmap1_fmba" = 0x6, + "flmap1_nm" = 0x2, + "flmap1_reserved" = 0x0, + "flmap1_fisba" = 0x10, + "flmap1_isl" = 0x2, + "flmap2_fmsba" = 0x20, + "flmap2_msl" = 0x1, + "flmap2_reserved" = 0x0, + + "flcomp_density1" = 0x4, + "flcomp_density2" = 0x2, + "flcomp_reserved0" = 0x0, + "flcomp_reserved1" = 0x0, + "flcomp_reserved2" = 0x0, + "flcomp_readclockfreq" = 0x0, + "flcomp_fastreadsupp" = 0x1, + "flcomp_fastreadfreq" = 0x1, + "flcomp_w_eraseclkfreq" = 0x0, + "flcomp_r_statclkfreq" = 0x0, + "flcomp_reserved3" = 0x0, + "flill" = 0x0, + "flbp" = 0x0, + "comp_padding"[0x24] = 0xff, + + "flreg0_base" = 0x0, + "flreg0_reserved0" = 0x0, + "flreg0_limit" = 0x0, + "flreg0_reserved1" = 0x0, + "flreg1_base" = 0x3, + "flreg1_reserved0" = 0x0, + "flreg1_limit" = 0x7ff, + "flreg1_reserved1" = 0x0, + "flreg2_base" = 0x1fff, + "flreg2_reserved0" = 0x0, + "flreg2_limit" = 0x0, + "flreg2_reserved1" = 0x0, + "flreg3_base" = 0x1, + "flreg3_reserved0" = 0x0, + "flreg3_limit" = 0x2, + "flreg3_reserved1" = 0x0, + "flreg4_base" = 0x1fff, + "flreg4_reserved0" = 0x0, + "flreg4_limit" = 0x0, + "flreg4_reserved1" = 0x0, + "flreg_padding"[12] = 0xff, + + "flmstr1_requesterid" = 0x0, + "flmstr1_r_fd" = 0x1, + "flmstr1_r_bios" = 0x1, + "flmstr1_r_me" = 0x1, + "flmstr1_r_gbe" = 0x1, + "flmstr1_r_pd" = 0x1, + "flmstr1_r_reserved" = 0x0, + "flmstr1_w_fd" = 0x1, + "flmstr1_w_bios" = 0x1, + "flmstr1_w_me" = 0x1, + "flmstr1_w_gbe" = 0x1, + "flmstr1_w_pd" = 0x1, + "flmstr1_w_reserved" = 0x0, + "flmstr2_requesterid" = 0x0, + "flmstr2_r_fd" = 0x0, + "flmstr2_r_bios" = 0x0, + "flmstr2_r_me" = 0x0, + "flmstr2_r_gbe" = 0x0, + "flmstr2_r_pd" = 0x0, + "flmstr2_r_reserved" = 0x0, + "flmstr2_w_fd" = 0x0, + "flmstr2_w_bios" = 0x0, + "flmstr2_w_me" = 0x0, + "flmstr2_w_gbe" = 0x0, + "flmstr2_w_pd" = 0x0, + "flmstr2_w_reserved" = 0x0, + "flmstr3_requesterid" = 0x218, + "flmstr3_r_fd" = 0x0, + "flmstr3_r_bios" = 0x0, + "flmstr3_r_me" = 0x0, + "flmstr3_r_gbe" = 0x1, + "flmstr3_r_pd" = 0x0, + "flmstr3_r_reserved" = 0x0, + "flmstr3_w_fd" = 0x0, + "flmstr3_w_bios" = 0x0, + "flmstr3_w_me" = 0x0, + "flmstr3_w_gbe" = 0x1, + "flmstr3_w_pd" = 0x0, + "flmstr3_w_reserved" = 0x0, + "flmstr_padding"[0x94] = 0xff, + + "ich0_medisable" = 0x1, + "ich0_reserved0" = 0x4, + "ich0_tcomode" = 0x1, + "ich0_mesmbusaddr" = 0x64, + "ich0_bmcmode" = 0x0, + "ich0_trippointsel" = 0x0, + "ich0_reserved1" = 0x0, + "ich0_integratedgbe" = 0x1, + "ich0_lanphy" = 0x1, + "ich0_reserved2" = 0x0, + "ich0_dmireqiddisable" = 0x0, + "ich0_me2smbusaddr" = 0x0, + "ich1_dynclk_nmlink" = 0x1, + "ich1_dynclk_smlink" = 0x1, + "ich1_dynclk_mesmbus" = 0x1, + "ich1_dynclk_sst" = 0x1, + "ich1_reserved0" = 0x0, + "ich1_nmlink_npostreqs" = 0x1, + "ich1_reserved1" = 0x0, + "ich1_reserved2" = 0x0, + "ichstrap_padding"[0xf8] = 0xff, + "mch0_medisable" = 0x1, + "mch0_mebootfromflash" = 0x0, + "mch0_tpmdisable" = 0x1, + "mch0_reserved0" = 0x7, + "mch0_spifingerprinton" = 0x1, + "mch0_mealtdisable" = 0x0, + "mch0_reserved1" = 0xff, + "mch0_reserved2" = 0xffff, + "mchstrap_padding"[0xcdc] = 0xff, + + "mevscc_jid0" = 0x1720c2, + "mevscc_vscc0" = 0x20052005, + "mevscc_jid1" = 0x1730ef, + "mevscc_vscc1" = 0x20052005, + "mevscc_jid2" = 0x481f, + "mevscc_vscc2" = 0x20152015, + "mevscc_padding"[4] = 0xff, + "mevscc_tablebase" = 0xee, + "mevscc_tablelength" = 0x6, + "mevscc_reserved" = 0x0, + + "oem_magic0" = 0x4c, + "oem_magic1" = 0x49, + "oem_magic2" = 0x42, + "oem_magic3" = 0x45, + "oem_magic4" = 0x52, + "oem_magic5" = 0x41, + "oem_magic6" = 0x54, + "oem_magic7" = 0x45, + "oem_padding"[0xf8] = 0xff +} diff --git a/util/bincfg/ifd-x200.spec b/util/bincfg/ifd-x200.spec new file mode 100644 index 0000000000..0cdbb9d2dd --- /dev/null +++ b/util/bincfg/ifd-x200.spec @@ -0,0 +1,187 @@ +# +# Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org> +# Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org> +# Copyright (C) 2017 Damien Zammit <damien@zamaudio.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# +# Info on flash descriptor (page 845 onwards): +# +# http://www.intel.co.uk/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdf + +# Flash Descriptor SPEC for GM45/ICH9M +{ + # Signature for descriptor mode + "fd_signature" : 32, + + # Flash map registers + "flmap0_fcba" : 8, + "flmap0_nc" : 2, + "flmap0_reserved0" : 6, + "flmap0_frba" : 8, + "flmap0_nr" : 3, + "flmap0_reserved1" : 5, + "flmap1_fmba" : 8, + "flmap1_nm" : 3, + "flmap1_reserved" : 5, + "flmap1_fisba" : 8, + "flmap1_isl" : 8, + "flmap2_fmsba" : 8, + "flmap2_msl" : 8, + "flmap2_reserved" : 16, + + # Component section + "flcomp_density1" : 3, + "flcomp_density2" : 3, + "flcomp_reserved0" : 2, + "flcomp_reserved1" : 8, + "flcomp_reserved2" : 1, + "flcomp_readclockfreq" : 3, + "flcomp_fastreadsupp" : 1, + "flcomp_fastreadfreq" : 3, + "flcomp_w_eraseclkfreq" : 3, + "flcomp_r_statclkfreq" : 3, + "flcomp_reserved3" : 2, + "flill" : 32, + "flbp" : 32, + "comp_padding"[36] : 8, + + # Region section + "flreg0_base" : 13, + "flreg0_reserved0" : 3, + "flreg0_limit" : 13, + "flreg0_reserved1" : 3, + "flreg1_base" : 13, + "flreg1_reserved0" : 3, + "flreg1_limit" : 13, + "flreg1_reserved1" : 3, + "flreg2_base" : 13, + "flreg2_reserved0" : 3, + "flreg2_limit" : 13, + "flreg2_reserved1" : 3, + "flreg3_base" : 13, + "flreg3_reserved0" : 3, + "flreg3_limit" : 13, + "flreg3_reserved1" : 3, + "flreg4_base" : 13, + "flreg4_reserved0" : 3, + "flreg4_limit" : 13, + "flreg4_reserved1" : 3, + "flreg_padding"[12] : 8, + + # Master access section + + # 1: Host CPU/BIOS + "flmstr1_requesterid" : 16, + "flmstr1_r_fd" : 1, + "flmstr1_r_bios" : 1, + "flmstr1_r_me" : 1, + "flmstr1_r_gbe" : 1, + "flmstr1_r_pd" : 1, + "flmstr1_r_reserved" : 3, + "flmstr1_w_fd" : 1, + "flmstr1_w_bios" : 1, + "flmstr1_w_me" : 1, + "flmstr1_w_gbe" : 1, + "flmstr1_w_pd" : 1, + "flmstr1_w_reserved" : 3, + + # 2: ME + "flmstr2_requesterid" : 16, + "flmstr2_r_fd" : 1, + "flmstr2_r_bios" : 1, + "flmstr2_r_me" : 1, + "flmstr2_r_gbe" : 1, + "flmstr2_r_pd" : 1, + "flmstr2_r_reserved" : 3, + "flmstr2_w_fd" : 1, + "flmstr2_w_bios" : 1, + "flmstr2_w_me" : 1, + "flmstr2_w_gbe" : 1, + "flmstr2_w_pd" : 1, + "flmstr2_w_reserved" : 3, + + # 3: GbE + "flmstr3_requesterid" : 16, + "flmstr3_r_fd" : 1, + "flmstr3_r_bios" : 1, + "flmstr3_r_me" : 1, + "flmstr3_r_gbe" : 1, + "flmstr3_r_pd" : 1, + "flmstr3_r_reserved" : 3, + "flmstr3_w_fd" : 1, + "flmstr3_w_bios" : 1, + "flmstr3_w_me" : 1, + "flmstr3_w_gbe" : 1, + "flmstr3_w_pd" : 1, + "flmstr3_w_reserved" : 3, + + "flmstr_padding"[148] : 8, + + # ICHSTRAP0 + "ich0_medisable" : 1, + "ich0_reserved0" : 6, + "ich0_tcomode" : 1, + "ich0_mesmbusaddr" : 7, + "ich0_bmcmode" : 1, + "ich0_trippointsel" : 1, + "ich0_reserved1" : 2, + "ich0_integratedgbe" : 1, + "ich0_lanphy" : 1, + "ich0_reserved2" : 3, + "ich0_dmireqiddisable" : 1, + "ich0_me2smbusaddr" : 7, + + # ICHSTRAP1 + "ich1_dynclk_nmlink" : 1, + "ich1_dynclk_smlink" : 1, + "ich1_dynclk_mesmbus" : 1, + "ich1_dynclk_sst" : 1, + "ich1_reserved0" : 4, + "ich1_nmlink_npostreqs" : 1, + "ich1_reserved1" : 7, + "ich1_reserved2" : 16, + + "ichstrap_padding"[248] : 8, + + # MCHSTRAP0 + "mch0_medisable" : 1, + "mch0_mebootfromflash" : 1, + "mch0_tpmdisable" : 1, + "mch0_reserved0" : 3, + "mch0_spifingerprinton" : 1, + # Alternate disable - allows ME to perform chipset + # init functions but disables FW apps such as AMT + "mch0_mealtdisable" : 1, + "mch0_reserved1" : 8, + "mch0_reserved2" : 16, + + "mchstrap_padding"[3292]: 8, + + # ME VSCC Table + "mevscc_jid0" : 32, + "mevscc_vscc0" : 32, + "mevscc_jid1" : 32, + "mevscc_vscc1" : 32, + "mevscc_jid2" : 32, + "mevscc_vscc2" : 32, + "mevscc_padding"[4] : 8, + + # Descriptor Map 2 Record + "mevscc_tablebase" : 8, + "mevscc_tablelength" : 8, + "mevscc_reserved" : 16, + + # OEM section + "oem_magic"[8] : 8, + "oem_padding"[248] : 8 +} diff --git a/util/bincfg/it8718f-ec.spec b/util/bincfg/it8718f-ec.spec new file mode 100644 index 0000000000..7fa325f203 --- /dev/null +++ b/util/bincfg/it8718f-ec.spec @@ -0,0 +1,368 @@ +# ITE IT8718F SuperIO EC registers +{ + # 00 Configuration register + "conf00_start" : 1, + "conf00_smien" : 1, + "conf00_irqen" : 1, + "conf00_irqclr" : 1, + "conf00_ro_one" : 1, + "conf00_copen" : 1, + "conf00_vbat" : 1, + "conf00_initreset" : 1, + + # 01 Interrupt Status register 1 + "irq1_maxfantac1" : 1, + "irq1_maxfantac2" : 1, + "irq1_maxfantac3" : 1, + "irq1_maxfantac4" : 1, + "irq1_copen" : 1, + "irq1_reserved0" : 1, + "irq1_maxfantac5" : 1, + "irq1_reserved1" : 1, + + # 02 Interrupt Status register 2 + "irq2_limit_vin"[8] : 1, + + # 03 Interrupt Status register 3 + "irq3_limit_temp1" : 1, + "irq3_limit_temp2" : 1, + "irq3_limit_temp3" : 1, + "irq3_reserved" : 5, + + # 04 SMI Mask register 1 + "smi1_dis_fantac1" : 1, + "smi1_dis_fantac2" : 1, + "smi1_dis_fantac3" : 1, + "smi1_dis_fantac4" : 1, + "smi1_dis_copen" : 1, + "smi1_reserved0" : 1, + "smi1_dis_fantac5" : 1, + "smi1_reserved1" : 1, + + # 05 SMI Mask register 2 + "smi2_dis_vin"[8] : 1, + + # 06 SMI Mask register 3 + "smi3_dis_temp1" : 1, + "smi3_dis_temp2" : 1, + "smi3_dis_temp3" : 1, + "smi3_reserved" : 5, + + # 07 Interrupt Mask register 1 + "irqmask1_fantac1" : 1, + "irqmask1_fantac2" : 1, + "irqmask1_fantac3" : 1, + "irqmask1_fantac4" : 1, + "irqmask1_copen" : 1, + "irqmask1_reserved0" : 1, + "irqmask1_fantac5" : 1, + "irqmask1_reserved1" : 1, + + # 08 Interrupt Mask register 2 + "irqmask2_vin"[8] : 1, + + # 09 Interrupt Mask register 3 + "irqmask3_temp1" : 1, + "irqmask3_temp2" : 1, + "irqmask3_temp3" : 1, + "irqmask3_reserved" : 4, + "irqmask3_extsensor" : 1, + + # 0a Interface Selection register + "iface_reserved" : 4, + "iface_extsensor_select": 3, + "iface_pseudo_eoc" : 1, + + # 0b Fan PWM smoothing step selection reg + "fanpwm_reserved" : 6, + "fanpwm_smoothing_step" : 2, + + # 0c Fan Tachometer 16 bit enable register + "fantach16_en_tac1" : 1, + "fantach16_en_tac2" : 1, + "fantach16_en_tac3" : 1, + "fantach16_tmpin1_enh" : 1, + "fantach16_en_tac4" : 1, + "fantach16_en_tac5" : 1, + "fantach16_tmpin2_enh" : 1, + "fantach16_tmpin3_enh" : 1, + + # 0d-0f Fan Tachmometer read registers + "fantach_lo_counts1" : 8, + "fantach_lo_counts2" : 8, + "fantach_lo_counts3" : 8, + + # 10-12 Fan Tachometer limit registers + "fantach_lo_limit1" : 8, + "fantach_lo_limit2" : 8, + "fantach_lo_limit3" : 8, + + # 13 Fan controller main control register + "fanctlmain_mode1" : 1, + "fanctlmain_mode2" : 1, + "fanctlmain_mode3" : 1, + "fanctlmain_reserved0" : 1, + "fanctlmain_en_tac1" : 1, + "fanctlmain_en_tac2" : 1, + "fanctlmain_en_tac3" : 1, + "fanctlmain_reserved1" : 1, + + # 14 FAN_CTL control register + "fanctl_enable1" : 1, + "fanctl_enable2" : 1, + "fanctl_enable3" : 1, + "fanctl_minduty_sel" : 1, + # 000: 48Mhz (PWM Frequency 375Khz) + # 001: 24Mhz (PWM Frequency 187.5Khz) + # 010: 12Mhz (PWM Frequency 93.75Khz) + # 011: 8Mhz (PWM Frequency 62.5Khz) + # 100: 6Mhz (PWM Frequency 46.875Khz) + # 101: 3Mhz (PWM Frequency 23.43Khz) + # 110: 1.5Mhz (PWM Frequency 11.7Khz) + # 111: 0.75Mhz (PWM Frequency 5.86Khz) + "fanctl_pwm_base_clock" : 3, + "fanctl_allpolarity" : 1, + + # 15 FAN_CTL1 PWM control register + "fanctl1_tmpin_sel" : 2, + "fanctl1_steps" : 5, + "fanctl1_pwm_mode" : 1, + + # 16 FAN_CTL2 PWM control register + "fanctl2_tmpin_sel" : 2, + "fanctl2_steps" : 5, + "fanctl2_pwm_mode" : 1, + + # 17 FAN_CTL3 PWM control register + "fanctl3_tmpin_sel" : 2, + "fanctl3_steps" : 5, + "fanctl3_pwm_mode" : 1, + + # 18-1a Fan Tachometer extended read registers + "fantach_hi_counts1" : 8, + "fantach_hi_counts2" : 8, + "fantach_hi_counts3" : 8, + + # 1b-1d Fan Tachometer extended limit registers + "fantach_hi_limit1" : 8, + "fantach_hi_limit2" : 8, + "fantach_hi_limit3" : 8, + + "reserved1e" : 8, + "reserved1f" : 8, + + + # 20-27 Reading registers + "vin"[8] : 8, + + "vbat" : 8, + "tmpin1" : 8, + "tmpin2" : 8, + "tmpin3" : 8, + "reserved2c" : 8, + "reserved2d" : 8, + "reserved2e" : 8, + "reserved2f" : 8, + "limit_hi_vin0" : 8, + "limit_lo_vin0" : 8, + "limit_hi_vin1" : 8, + "limit_lo_vin1" : 8, + "limit_hi_vin2" : 8, + "limit_lo_vin2" : 8, + "limit_hi_vin3" : 8, + "limit_lo_vin3" : 8, + "limit_hi_vin4" : 8, + "limit_lo_vin4" : 8, + "limit_hi_vin5" : 8, + "limit_lo_vin5" : 8, + "limit_hi_vin6" : 8, + "limit_lo_vin6" : 8, + "limit_hi_vin7" : 8, + "limit_lo_vin7" : 8, + "limit_hi_tmpin1" : 8, + "limit_lo_tmpin1" : 8, + "limit_hi_tmpin2" : 8, + "limit_lo_tmpin2" : 8, + "limit_hi_tmpin3" : 8, + "limit_lo_tmpin3" : 8, + + "reserved46" : 8, + "reserved47" : 8, + "reserved48" : 8, + "reserved49" : 8, + "reserved4a" : 8, + "reserved4b" : 8, + "reserved4c" : 8, + "reserved4d" : 8, + "reserved4e" : 8, + "reserved4f" : 8, + + # 50 ADC Voltage channel enable register + "adc_scan_enable_vin"[8]: 1, + + # 51 ADC Temperature channel enable register + "therm_diode_tmpin1" : 1, + "therm_diode_tmpin2" : 1, + "therm_diode_tmpin3" : 1, + # Mututally exclusive settings + "therm_resistor_tmpin1" : 1, + "therm_resistor_tmpin2" : 1, + "therm_resistor_tmpin3" : 1, + "therm_reserved" : 2, + + "therm_limit_tmpin1" : 8, + "therm_limit_tmpin2" : 8, + "therm_limit_tmpin3" : 8, + + # 55 Temperature extra channel enable reg + "therm_resistor_vin4" : 1, + "therm_resistor_vin5" : 1, + "therm_resistor_vin6" : 1, + "adc_fanctl2_pwm_duty" : 1, + # 000: 48Mhz (PWM Frequency 375Khz) + # 001: 24Mhz (PWM Frequency 187.5Khz) + # 010: 12Mhz (PWM Frequency 93.75Khz) + # 011: 8Mhz (PWM Frequency 62.5Khz) + # 100: 6Mhz (PWM Frequency 46.875Khz) + # 101: 3Mhz (PWM Frequency 23.43Khz) + # 110: 1.5Mhz (PWM Frequency 11.7Khz) + # 111: 0.75Mhz (PWM Frequency 5.86Khz) + "adc_fanctl2_pwm_bclk" : 3, + "adc_tmpin3_ext_select" : 1, + + "thermal_zero_diode1" : 8, + "thermal_zero_diode2" : 8, + "ite_vendor_id" : 8, + "thermal_zero_diode3" : 8, + "reserved5a" : 8, + "ite_code_id" : 8, + + "beep_fantac" : 1, + "beep_vin" : 1, + "beep_tmpin" : 1, + "beep_reserved" : 1, + # ADC clock select + # 000: 500Khz (Default) + # 001: 250Khz + # 010: 125K + # 011: 62.5Khz + # 100: 31.25Khz + # 101: 24Mhz + # 110: 1Mhz + # 111: 2Mhz + "adc_clock_select" : 3, + "thermal_zero_adj_en" : 1, + + "beep_fan_freq_div" : 4, + "beep_fan_tone_div" : 4, + "beep_volt_freq_div" : 4, + "beep_volt_tone_div" : 4, + "beep_temp_freq_div" : 4, + "beep_temp_tone_div" : 4, + + # 60 SmartGuardian registers + "sguard1_temp_lim_off" : 8, + "sguard1_temp_lim_fan" : 8, + "reserved62" : 8, + "sguard1_pwm_start" : 7, + "sguard1_pwm_slope6" : 1, + "sguard1_pwm_slope05" : 6, + "sguard1_pwm_reserved" : 1, + "sguard1_fan_smooth_en" : 1, + "sguard1_temp_interval" : 5, + "sguard1_temp_reserved" : 2, + "sguard1_temp_pwm_lin" : 1, + "reserved66" : 8, + "reserved67" : 8, + "sguard2_temp_lim_off" : 8, + "sguard2_temp_lim_fan" : 8, + "reserved6a" : 8, + "sguard2_pwm_start" : 7, + "sguard2_pwm_slope6" : 1, + "sguard2_pwm_slope05" : 6, + "sguard2_pwm_reserved" : 1, + "sguard2_fan_smooth_en" : 1, + "sguard2_temp_interval" : 5, + "sguard2_temp_reserved" : 2, + "sguard2_temp_pwm_lin" : 1, + "reserved6e" : 8, + "reserved6f" : 8, + "sguard3_temp_lim_off" : 8, + "sguard3_temp_lim_fan" : 8, + "reserved72" : 8, + "sguard3_pwm_start" : 7, + "sguard3_pwm_slope6" : 1, + "sguard3_pwm_slope05" : 6, + "sguard3_pwm_reserved" : 1, + "sguard3_fan_smooth_en" : 1, + "sguard3_temp_interval" : 5, + "sguard3_temp_reserved" : 2, + "sguard3_temp_pwm_lin" : 1, + "reserved76" : 8, + "reserved77" : 8, + "reserved78" : 8, + "reserved79" : 8, + "reserved7a" : 8, + "reserved7b" : 8, + "reserved7c" : 8, + "reserved7d" : 8, + "reserved7e" : 8, + "reserved7f" : 8, + + # 80 Fan Tachometer 4-5 read registers + "fantach_lo_counts4" : 8, + "fantach_hi_counts4" : 8, + "fantach_lo_counts5" : 8, + "fantach_hi_counts5" : 8, + "fantach_lo_limit4" : 8, + "fantach_hi_limit4" : 8, + "fantach_lo_limit5" : 8, + "fantach_hi_limit5" : 8, + + # 88 External temperature sensor host status + "ext_host_busy" : 1, + "ext_host_fnsh" : 1, + "ext_host_r_fcs_error" : 1, + "ext_host_w_fcs_error" : 1, + "ext_host_peci_highz" : 1, + "ext_host_sst_slave" : 1, + "ext_host_sst_bus" : 1, + "ext_host_data_fifo_clr": 1, + + "ext_host_target_addr" : 8, + "ext_host_write_length" : 8, + "ext_host_read_length" : 8, + "ext_host_cmd" : 8, + "ext_host_writedata" : 8, + + "ext_hostctl_start" : 1, + "ext_hostctl_sst_amdsi" : 1, + "ext_hostctl_sst_ctl" : 1, + "ext_hostctl_resetfifo" : 1, + "ext_hostctl_fcs_abort" : 1, + "ext_hostctl_start_en" : 1, + # Auto-Start Control + # The host will start the transaction + # at a regular rate automatically. + # 00: 32 Hz + # 01: 16 Hz + # 10: 8 Hz + # 11: 4 Hz + "ext_hostctl_start_ctl" : 2, + + "ext_host_readdata" : 8, + + "fan1_temp_limit_start" : 8, + "fan1_slope_pwm" : 7, + "fan1_temp_input_sel0" : 1, + "fan1_ctlmode_temp_ivl" : 5, + "fan1_ctlmode_target" : 2, + "fan1_temp_input_sel1" : 1, + "reserved93" : 8, + "fan2_temp_limit_start" : 8, + "fan2_slope_pwm" : 7, + "fan2_temp_input_sel0" : 1, + "fan2_ctlmode_temp_ivl" : 5, + "fan2_ctlmode_target" : 2, + "fan2_temp_input_sel1" : 1 +} |