cleaned-up bsdl subsystem, avoid double reading during detect, commenting

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1345 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Arnim Läuger 16 years ago
parent d7199e8bb5
commit a4550b1b68

@ -1,3 +1,13 @@
2008-08-27 Arnim Laeuger <arniml@users.sourceforge.net>
* include/Makefile.am, include/bsdl.h, include/bsdl_mode.h,
src/cmd/include.c, src/cmd/bsdl.c, src/bsdl/vhdl_parser.h,
src/bsdl/bsdl_msg.h, src/bsdl/bsdl.c, src/bsdl/bsdl_bison.y,
src/bsdl/vhdl_flex.l, src/bsdl/bsdl_parser.h, src/bsdl/bsdl_sem.c,
src/bsdl/bsdl_flex.l, src/bsdl/bsdl_types.h, src/bsdl/vhdl_bison.y,
src/tap/detect.c: cleaned-up bsdl subsystem, avoid double reading
during detect, commenting
2008-08-24 Arnim Laeuger <arniml@users.sourceforge.net>
* src/bsdl/bsdl_sem.c (bsdl_process_cell_info): fix error with

@ -26,6 +26,7 @@ include $(top_srcdir)/Makefile.rules
noinst_HEADERS = \
bsbit.h \
bsdl.h \
bsdl_mode.h \
bitmask.h \
bus.h \
bus_driver.h \

@ -25,6 +25,8 @@
#ifndef BSDL_H
#define BSDL_H
#include <bsdl_mode.h>
typedef struct {
char **path_list;
int debug;

@ -0,0 +1,66 @@
/*
* $Id$
*
* Copyright (C) 2008, Arnim Laeuger
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Written by Arnim Laeuger <arniml@users.sourceforge.net>, 2008.
*
*/
#ifndef BSDL_MODE_H
#define BSDL_MODE_H
#define BSDL_MODE_MSG_NOTE (1 << 0)
#define BSDL_MODE_MSG_WARN (1 << 1)
#define BSDL_MODE_MSG_ERR (1 << 2)
#define BSDL_MODE_MSG_FATAL (1 << 3)
#define BSDL_MODE_MSG_ALL (BSDL_MODE_MSG_FATAL | \
BSDL_MODE_MSG_ERR | \
BSDL_MODE_MSG_WARN | \
BSDL_MODE_MSG_NOTE)
#define BSDL_MODE_MSG_ALWAYS BSDL_MODE_MSG_FATAL
#define BSDL_MODE_SYN_CHECK (1 << 4)
#define BSDL_MODE_INSTR_PRINT (1 << 5)
#define BSDL_MODE_INSTR_EXEC (1 << 6)
#define BSDL_MODE_IDCODE_CHECK (1 << 7)
#define BSDL_MODE_ACTION_ALL (BSDL_MODE_SYN_CHECK | \
BSDL_MODE_INSTR_PRINT | \
BSDL_MODE_INSTR_EXEC | \
BSDL_MODE_IDCODE_CHECK)
#define BSDL_MODE_INCLUDE1 (BSDL_MODE_MSG_ALWAYS)
#define BSDL_MODE_INCLUDE2 (BSDL_MODE_SYN_CHECK | \
BSDL_MODE_INSTR_EXEC | \
BSDL_MODE_MSG_WARN | \
BSDL_MODE_MSG_ERR | \
BSDL_MODE_MSG_FATAL)
#define BSDL_MODE_DETECT (BSDL_MODE_SYN_CHECK | \
BSDL_MODE_INSTR_EXEC | \
BSDL_MODE_IDCODE_CHECK | \
BSDL_MODE_MSG_ALWAYS)
#define BSDL_MODE_TEST (BSDL_MODE_SYN_CHECK | \
BSDL_MODE_MSG_ALL)
#define BSDL_MODE_DUMP (BSDL_MODE_SYN_CHECK | \
BSDL_MODE_INSTR_PRINT | \
BSDL_MODE_MSG_WARN | \
BSDL_MODE_MSG_ERR | \
BSDL_MODE_MSG_FATAL)
#endif /* BSDL_MODE_H */

@ -49,19 +49,20 @@
/*****************************************************************************
* bsdl_msg( type, format, ... )
* bsdl_msg( proc_mode, type, format, ... )
*
* Main printing function for the BSDL subsystem.
*
* Parameters
* type : one of the BSDL_MSG_* defines, determines message tag
* format : printf format
* ... : additional parameters to fill the printf format string
* proc_mode : processing mode, consisting of BSDL_MODE_* bits
* type : one of the BSDL_MSG_* defines, determines message tag
* format : printf format
* ... : additional parameters to fill the printf format string
*
* Returns
* void
****************************************************************************/
void bsdl_msg( int type, const char *format, ... )
void bsdl_msg( int proc_mode, int type, const char *format, ... )
{
va_list lst;
@ -69,15 +70,23 @@ void bsdl_msg( int type, const char *format, ... )
switch (type)
{
case BSDL_MSG_NOTE:
if (!(proc_mode & BSDL_MODE_MSG_NOTE))
return;
printf( "-N- " );
break;
case BSDL_MSG_WARN:
if (!(proc_mode & BSDL_MODE_MSG_WARN))
return;
printf( "-W- " );
break;
case BSDL_MSG_ERR:
if (!(proc_mode & BSDL_MODE_MSG_ERR))
return;
printf( "-E- " );
break;
case BSDL_MSG_FATAL:
if (!(proc_mode & BSDL_MODE_MSG_FATAL))
return;
printf( "-F- " );
break;
default:
@ -90,20 +99,15 @@ void bsdl_msg( int type, const char *format, ... )
/*****************************************************************************
* bsdl_read_file( chain, BSDL_File_Name, mode, idcode )
* bsdl_read_file( chain, BSDL_File_Name, proc_mode, idcode )
*
* Read, parse and optionally apply contents of BSDL file.
*
* Parameters
* chain : pointer to active chain structure
* BSDL_File_Name : name of BSDL file to read
* mode : -1 -> read file
* no further action based on components
* 0 -> read file and extract all components
* dump commands to stdout, do not execute commands
* 1 -> read file and extract all components
* execute commands
* idcode : reference idcode string
* chain : pointer to active chain structure
* BSDL_File_Name : name of BSDL file to read
* proc_mode : processing mode, consisting of BSDL_MODE_* bits
* idcode : reference idcode string
*
* Returns
* < 0 : Error occured, parse/syntax problems or out of memory
@ -111,46 +115,39 @@ void bsdl_msg( int type, const char *format, ... )
* > 0 : No errors, idcode checked and matched
*
****************************************************************************/
int bsdl_read_file( chain_t *chain, const char *BSDL_File_Name, int mode,
int bsdl_read_file( chain_t *chain, const char *BSDL_File_Name, int proc_mode,
const char *idcode )
{
bsdl_globs_t *globs = &(chain->bsdl);
FILE *BSDL_File;
vhdl_parser_priv_t *vhdl_parser_priv;
bsdl_parser_priv_t *bsdl_parser_priv;
jtag_ctrl_t jtag_ctrl;
int Compile_Errors = 1;
int idcode_match = 0;
int result;
jtag_ctrl.mode = mode;
jtag_ctrl.debug = globs->debug;
if (globs->debug)
proc_mode |= BSDL_MODE_MSG_ALL;
jtag_ctrl.proc_mode = proc_mode;
/* perform some basic checks */
if (mode >= 0)
if (proc_mode & BSDL_MODE_INSTR_EXEC)
{
if (mode >= 1)
if (chain == NULL)
{
if (chain == NULL)
{
bsdl_msg( BSDL_MSG_ERR, _("No JTAG chain available\n") );
return -1;
}
if (chain->parts == NULL)
{
bsdl_msg( BSDL_MSG_ERR, _("Chain without any parts\n") );
return -1;
}
if (!(chain && chain->parts))
return -1;
jtag_ctrl.chain = chain;
jtag_ctrl.part = chain->parts->parts[chain->active_part];
bsdl_msg( proc_mode, BSDL_MSG_ERR, _("No JTAG chain available\n") );
return -1;
}
else
if (chain->parts == NULL)
{
jtag_ctrl.chain = NULL;
jtag_ctrl.part = NULL;
bsdl_msg( proc_mode, BSDL_MSG_ERR, _("Chain without any parts\n") );
return -1;
}
if (!(chain && chain->parts))
return -1;
jtag_ctrl.chain = chain;
jtag_ctrl.part = chain->parts->parts[chain->active_part];
}
else
{
@ -160,11 +157,11 @@ int bsdl_read_file( chain_t *chain, const char *BSDL_File_Name, int mode,
BSDL_File = fopen( BSDL_File_Name, "r" );
if (globs->debug || (mode == 0))
bsdl_msg( BSDL_MSG_NOTE, _("Reading file '%s'\n"), BSDL_File_Name );
bsdl_msg( proc_mode, BSDL_MSG_NOTE, _("Reading file '%s'\n"), BSDL_File_Name );
if (BSDL_File == NULL) {
bsdl_msg( BSDL_MSG_ERR, _("Unable to open BSDL file '%s'\n"), BSDL_File_Name );
bsdl_msg( proc_mode,
BSDL_MSG_ERR, _("Unable to open BSDL file '%s'\n"), BSDL_File_Name );
return -1;
}
@ -177,68 +174,30 @@ int bsdl_read_file( chain_t *chain, const char *BSDL_File_Name, int mode,
Compile_Errors = vhdl_flex_get_compile_errors( vhdl_parser_priv->scanner );
if (Compile_Errors == 0)
{
if (globs->debug)
bsdl_msg( BSDL_MSG_NOTE, _("BSDL file '%s' passed VHDL stage correctly\n"),
BSDL_File_Name );
if ((bsdl_parser_priv = bsdl_parser_init( &jtag_ctrl )))
{
bsdl_msg( proc_mode,
BSDL_MSG_NOTE, _("BSDL file '%s' passed VHDL stage correctly\n"),
BSDL_File_Name );
Compile_Errors = bsdl_sem_process_elements( bsdl_parser_priv );
result = bsdl_process_elements( &jtag_ctrl, idcode );
if ((Compile_Errors == 0) && globs->debug)
bsdl_msg( BSDL_MSG_NOTE, _("BSDL file '%s' passed BSDL stage correctly\n"),
BSDL_File_Name );
if (result >= 0)
bsdl_msg( proc_mode,
BSDL_MSG_NOTE, _("BSDL file '%s' passed BSDL stage correctly\n"),
BSDL_File_Name );
/* handle IDCODE comparison */
if ((Compile_Errors == 0) && jtag_ctrl.idcode)
{
if (globs->debug)
bsdl_msg( BSDL_MSG_NOTE, _("Got IDCODE: %s\n"), jtag_ctrl.idcode );
/* should we compare the idcodes? */
if (idcode)
{
if (strlen( idcode ) == strlen(jtag_ctrl.idcode))
{
int idx;
/* compare given idcode with idcode from BSDL file
including the end of string character */
idcode_match = 1;
for (idx = 0; idx <= strlen( idcode ); idx++)
if (jtag_ctrl.idcode[idx] != 'X')
if (idcode[idx] != jtag_ctrl.idcode[idx])
idcode_match = 0;
if (globs->debug)
{
if (idcode_match)
bsdl_msg( BSDL_MSG_NOTE, _("IDCODE matched\n") );
else
bsdl_msg( BSDL_MSG_NOTE, _("IDCODE mismatch\n") );
}
}
}
}
bsdl_parser_deinit( bsdl_parser_priv );
}
}
else
{
if (globs->debug || (mode >= 0))
bsdl_msg( BSDL_MSG_ERR, _("BSDL file '%s' contains errors in VHDL stage, stopping\n"),
BSDL_File_Name );
bsdl_msg( proc_mode,
BSDL_MSG_ERR, _("BSDL file '%s' contains errors in VHDL stage, stopping\n"),
BSDL_File_Name );
}
vhdl_parser_deinit( vhdl_parser_priv );
}
return Compile_Errors == 0 ? idcode_match : -1;
return Compile_Errors == 0 ? result : -1;
}
@ -300,12 +259,13 @@ void bsdl_set_path( chain_t *chain, const char *pathlist )
if (globs->debug)
for (num = 0; globs->path_list[num] != NULL; num++)
bsdl_msg( BSDL_MSG_NOTE, "%s\n", globs->path_list[num] );
bsdl_msg( BSDL_MODE_MSG_ALL,
BSDL_MSG_NOTE, "%s\n", globs->path_list[num] );
}
/*****************************************************************************
* bsdl_scan_files( chain, idcode, mode )
* bsdl_scan_files( chain, idcode, proc_mode )
*
* Scans through all files found via the elements in bsdl_path_list
* and does a test read on each of them.
@ -314,14 +274,9 @@ void bsdl_set_path( chain_t *chain, const char *pathlist )
* the current part.
*
* Parameters
* chain : pointer to active chain structure
* idcode : reference idcode string
* mode : -1 -> read file
* no further action based on components
* 0 -> read file and extract all components
* dump commands to stdout, do not execute commands
* 1 -> read file and extract all components
* execute commands
* chain : pointer to active chain structure
* idcode : reference idcode string
* proc_mode : processing mode, consisting of BSDL_MODE_* bits
*
* Returns
* < 0 : Error occured, parse/syntax problems or out of memory
@ -329,7 +284,7 @@ void bsdl_set_path( chain_t *chain, const char *pathlist )
* > 0 : No errors, idcode checked and matched
*
****************************************************************************/
int bsdl_scan_files( chain_t *chain, const char *idcode, int mode )
int bsdl_scan_files( chain_t *chain, const char *idcode, int proc_mode )
{
bsdl_globs_t *globs = &(chain->bsdl);
int idx = 0;
@ -366,20 +321,9 @@ int bsdl_scan_files( chain_t *chain, const char *idcode, int mode )
{
if (buf.st_mode & S_IFREG)
{
if (mode >= 1)
{
/* now we know we can finally read the file */
/* do a test read first */
result = bsdl_read_file( chain, name, -1, idcode );
if (result > 0)
{
/* read in BSDL file if IDCODE matched */
printf( _(" Filename: %s\n"), name );
result = bsdl_read_file( chain, name, 1, idcode );
}
}
else
result = bsdl_read_file( chain, name, mode, idcode );
result = bsdl_read_file( chain, name, proc_mode, idcode );
if (result == 1)
printf( _(" Filename: %s\n"), name );
}
}
@ -390,7 +334,8 @@ int bsdl_scan_files( chain_t *chain, const char *idcode, int mode )
closedir( dir );
}
else
bsdl_msg( BSDL_MSG_WARN, _("Cannot open directory %s\n"), globs->path_list[idx] );
bsdl_msg( proc_mode,
BSDL_MSG_WARN, _("Cannot open directory %s\n"), globs->path_list[idx] );
idx++;
}

@ -871,18 +871,18 @@ Exit_Instruction_List : IDENTIFIER
/*----------------------------------------------------------------------*/
static void Print_Error( bsdl_parser_priv_t *priv_data, const char *Errmess )
{
if (priv_data->jtag_ctrl->debug || (priv_data->jtag_ctrl->mode >= 0))
bsdl_msg( BSDL_MSG_ERR, _("Line %d, %s.\n"),
priv_data->lineno,
Errmess );
bsdl_msg( priv_data->jtag_ctrl->proc_mode,
BSDL_MSG_ERR, _("Line %d, %s.\n"),
priv_data->lineno,
Errmess );
}
/*----------------------------------------------------------------------*/
static void Print_Warning( bsdl_parser_priv_t *priv_data, const char *Warnmess )
{
if (priv_data->jtag_ctrl->debug || (priv_data->jtag_ctrl->mode >= 0))
bsdl_msg( BSDL_MSG_WARN, _("Line %d, %s.\n"),
priv_data->lineno,
Warnmess );
bsdl_msg( priv_data->jtag_ctrl->proc_mode,
BSDL_MSG_WARN, _("Line %d, %s.\n"),
priv_data->lineno,
Warnmess );
}
/*----------------------------------------------------------------------*/
static void Give_Up_And_Quit( bsdl_parser_priv_t *priv_data )
@ -1110,13 +1110,14 @@ bsdl_parser_priv_t *bsdl_parser_init( jtag_ctrl_t *jtag_ctrl )
bsdl_parser_priv_t *new_priv;
if (!(new_priv = (bsdl_parser_priv_t *)malloc( sizeof( bsdl_parser_priv_t ) ))) {
bsdl_msg( BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( jtag_ctrl->proc_mode,
BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
return NULL;
}
new_priv->jtag_ctrl = jtag_ctrl;
if (!(new_priv->scanner = bsdl_flex_init( jtag_ctrl->mode, jtag_ctrl->debug ))) {
if (!(new_priv->scanner = bsdl_flex_init( jtag_ctrl->proc_mode ))) {
free(new_priv);
new_priv = NULL;
}
@ -1177,7 +1178,8 @@ static void add_instruction( bsdl_parser_priv_t *priv, char *instr, char *opcode
priv->jtag_ctrl->instr_list = new_instr;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
@ -1235,7 +1237,8 @@ static void ac_add_instruction( bsdl_parser_priv_t *priv, char *instr )
tmp_ai->instr_list = new_instr;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
@ -1269,7 +1272,8 @@ static void ac_apply_assoc( bsdl_parser_priv_t *priv )
jc->ainfo_list = new_ai;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( jc->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
/* clean up obsolete temporary entries */
tmp_ai->reg = NULL;
@ -1306,7 +1310,8 @@ static void prt_add_name( bsdl_parser_priv_t *priv, char *name )
pd->names_list = new_string;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
@ -1455,7 +1460,8 @@ static void ci_set_cell_spec( bsdl_parser_priv_t *priv,
}
else
{
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
ci->port_name = NULL;
}
@ -1504,7 +1510,8 @@ static void ci_append_cell_info( bsdl_parser_priv_t *priv, int bit_num )
tmp_ci->basic_safe_value = NULL;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( jc->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}

@ -140,7 +140,7 @@ LEGAL NOTICES:
#define YY_EXTRA_TYPE scan_extra_t *
static char *new_string( const char * );
static char *new_string( scan_extra_t *, const char * );
#define BINARY 0
#define DECIMAL 1
@ -385,26 +385,26 @@ ISC_Illegal_Exit ISC_ILLEGAL_EXIT
{White} { /* Do Nothing on White Space */ }
{VHDL_Comment} { /* Do Nothing on Comments */ }
{Bin_X_Pattern} {if (yyextra->Base != BIN_X) REJECT;
yylval->str = new_string( yytext );
yylval->str = new_string( yyextra, yytext );
return( BIN_X_PATTERN );}
{Hex_String} {if (yyextra->Base != HEX) REJECT;
yylval->str = new_string( yytext );
yylval->str = new_string( yyextra, yytext );
return( HEX_STRING );}
{Identifier} {yylval->str = new_string( yytext );
{Identifier} {yylval->str = new_string( yyextra, yytext );
return( IDENTIFIER ); }
{Binary_Pattern} {if (yyextra->Base != BINARY) REJECT;
yylval->str = new_string( yytext );
yylval->str = new_string( yyextra, yytext );
return( BINARY_PATTERN );}
{Decimal_Number} {if (yyextra->Base != DECIMAL) REJECT;
yylval->integer = atoi( (char *)yytext );
return( DECIMAL_NUMBER );}
{Real_Number} {yylval->str = new_string( yytext );
{Real_Number} {yylval->str = new_string( yyextra, yytext );
return( REAL_NUMBER );}
{Illegal} {if (yyextra->debug || (yyextra->mode >= 0))
bsdl_msg( BSDL_MSG_ERR,
_("Illegal character %c (/%03o) at line %d:\n"),
(char)yytext[yyleng-1], (int)yytext[yyleng-1],
yylineno );
{Illegal} {bsdl_msg( yyextra->proc_mode,
BSDL_MSG_ERR,
_("Illegal character %c (/%03o) at line %d:\n"),
(char)yytext[yyleng-1], (int)yytext[yyleng-1],
yylineno );
yyextra->Compile_Errors++;
return( ILLEGAL ); /* Will cause syntax error */}
<<EOF>> {
@ -414,24 +414,17 @@ ISC_Illegal_Exit ISC_ILLEGAL_EXIT
}
%%
/*****************************************************************************
* void *bsdl_flex_init( int mode, int debug )
* void *bsdl_flex_init( int proc_mode )
*
* Initializes the scanner and storage elements extra data structure.
*
* Parameters
* mode : -1 -> read file
* no further action based on components
* 0 -> read file and extract all components
* dump commands to stdout, do not execute commands
* 1 -> read file and extract all components
* execute commands
* debug : 1 -> emit failure messages
* 0 -> no failure messages
* proc_mode : processing mode, consisting of BSDL_MODE_* bits
*
* Returns
* pointer to newly initialized scanner structure
****************************************************************************/
void *bsdl_flex_init( int mode, int debug )
void *bsdl_flex_init( int proc_mode )
{
scan_extra_t *extra;
yyscan_t scanner;
@ -439,18 +432,19 @@ void *bsdl_flex_init( int mode, int debug )
/* get our scanner structure */
if (yylex_init(&scanner) != 0)
{
bsdl_msg( BSDL_MSG_FATAL, _("Scanner could not be initialized\n") );
bsdl_msg( proc_mode,
BSDL_MSG_FATAL, _("Scanner could not be initialized\n") );
return NULL;
}
if (!(extra = (scan_extra_t *)malloc( sizeof( scan_extra_t ) ))) {
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
yylex_destroy( scanner );
return NULL;
}
extra->mode = mode;
extra->debug = debug;
extra->proc_mode = proc_mode;
extra->Compile_Errors = 0;
extra->Base = DECIMAL;
@ -507,17 +501,18 @@ int yywrap( yyscan_t scanner )
/*****************************************************************************
* char *new_string( const char *str )
* char *new_string( scan_extra_t *extra, const char *str )
*
* Allocates memory for a string and copies the contents of *str.
*
* Parameters
* str : pointer to string to be duplicated
* extra : pointer to extra data structure
* str : pointer to string to be duplicated
*
* Returns
* pointer to allocated and initialized string memory
****************************************************************************/
static char *new_string( const char *str )
static char *new_string( scan_extra_t *extra, const char *str )
{
char *n_str;
size_t n_str_size;
@ -529,7 +524,8 @@ static char *new_string( const char *str )
n_str[n_str_size-1] = '\0'; /* set very last element to EOS */
}
else
bsdl_msg(BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__);
bsdl_msg( extra->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
return(n_str);
}

@ -25,12 +25,14 @@
#ifndef BSDL_MSG_H
#define BSDL_MSG_H
#include "bsdl_types.h"
/* message types for bsdl_msg() */
#define BSDL_MSG_NOTE 0
#define BSDL_MSG_WARN 1
#define BSDL_MSG_ERR 2
#define BSDL_MSG_FATAL 3
void bsdl_msg( int, const char *, ... );
void bsdl_msg( int, int, const char *, ... );
#endif /* BSDL_MSG_H */

@ -28,7 +28,7 @@
#include "bsdl_types.h"
/* VHDL lexer declarations */
void *bsdl_flex_init( int, int );
void *bsdl_flex_init( int );
void bsdl_flex_deinit( void * );
void bsdl_flex_set_bin_x( void * );
void bsdl_flex_set_hex( void * );
@ -44,6 +44,6 @@ void bsdl_parser_deinit( bsdl_parser_priv_t * );
int bsdlparse( bsdl_parser_priv_t * );
/* BSDL semantic functions */
int bsdl_sem_process_elements( bsdl_parser_priv_t * );
int bsdl_process_elements( jtag_ctrl_t *, const char * );
#endif /* BSDL_PARSER_H */

@ -69,7 +69,7 @@ static void print_cmd(char **cmd)
/*****************************************************************************
* void bsdl_set_instruction_length( jtag_ctrl_t *jc )
* int bsdl_set_instruction_length( jtag_ctrl_t *jc )
*
* Sets the specified length of the instruction register via shell command
* instruction length <len>
@ -78,31 +78,31 @@ static void print_cmd(char **cmd)
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_set_instruction_length( jtag_ctrl_t *jc )
static int bsdl_set_instruction_length( jtag_ctrl_t *jc )
{
if (jc->mode >= 0)
{
char lenstring[6];
char *cmd[] = {"instruction",
"length",
lenstring,
NULL};
char lenstring[6];
char *cmd[] = {"instruction",
"length",
lenstring,
NULL};
snprintf( lenstring, 6, "%i", jc->instr_len );
lenstring[5] = '\0';
snprintf( lenstring, 6, "%i", jc->instr_len );
lenstring[5] = '\0';
if (jc->mode >= 1)
cmd_run( jc->chain, cmd );
else
print_cmd( cmd );
}
if (jc->proc_mode & BSDL_MODE_INSTR_EXEC)
cmd_run( jc->chain, cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_PRINT)
print_cmd( cmd );
return 1;
}
/*****************************************************************************
* void bsdl_emit_ports( jtag_ctrl_t *jc )
* int bsdl_emit_ports( jtag_ctrl_t *jc )
*
* Adds the specified port name as a signal via shell command
* signal <pin>
@ -116,67 +116,70 @@ static void bsdl_set_instruction_length( jtag_ctrl_t *jc )
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_emit_ports(jtag_ctrl_t *jc)
static int bsdl_emit_ports(jtag_ctrl_t *jc)
{
port_desc_t *pd = jc->port_desc;
struct string_elem *name;
size_t str_len, name_len;
char *port_string;
int idx;
int result = 0;
char *cmd[] = {"signal",
NULL,
NULL};
if (jc->mode >= 0) {
char *cmd[] = {"signal",
NULL,
NULL};
struct string_elem *name;
size_t str_len, name_len;
char *port_string;
int idx;
while (pd)
{
name = pd->names_list;
while (name) {
/* handle indexed port name:
- names of scalar ports are simply copied from the port_desc structure
to the final string that goes into ci
- names of vectored ports are expanded with their decimal index as
collected earlier in rule Scalar_or_Vector
*/
name_len = strlen( name->string );
str_len = name_len + 1 + 10 + 1 + 1;
if ((port_string = (char *)malloc( str_len )) != NULL)
{
cmd[1] = port_string;
while (pd)
{
name = pd->names_list;
while (name) {
/* handle indexed port name:
- names of scalar ports are simply copied from the port_desc structure
to the final string that goes into ci
- names of vectored ports are expanded with their decimal index as
collected earlier in rule Scalar_or_Vector
*/
name_len = strlen( name->string );
str_len = name_len + 1 + 10 + 1 + 1;
if ((port_string = (char *)malloc( str_len )) != NULL)
for (idx = pd->low_idx; idx <= pd->high_idx; idx++)
{
cmd[1] = port_string;
for (idx = pd->low_idx; idx <= pd->high_idx; idx++)
{
if (pd->is_vector)
snprintf( port_string, str_len-1, "%s(%d)", name->string, idx );
else
strncpy( port_string, name->string, str_len-1 );
port_string[str_len-1] = '\0';
if (jc->mode >= 1)
cmd_run( jc->chain, cmd );
else
print_cmd( cmd );
}
free( port_string );
if (pd->is_vector)
snprintf( port_string, str_len-1, "%s(%d)", name->string, idx );
else
strncpy( port_string, name->string, str_len-1 );
port_string[str_len-1] = '\0';
if (jc->proc_mode & BSDL_MODE_INSTR_EXEC)
cmd_run( jc->chain, cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_PRINT)
print_cmd( cmd );
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
name = name->next;
free( port_string );
result = 1;
}
else
bsdl_msg( jc->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
pd = pd->next;
name = name->next;
}
pd = pd->next;
}
return result;
}
/*****************************************************************************
* void create_register( jtag_ctrl_t *jc, char *reg_name, size_t len )
* int create_register( jtag_ctrl_t *jc, char *reg_name, size_t len )
*
* Generic function to create a jtag register via shell command
* register <reg_name> <len>
@ -187,34 +190,35 @@ static void bsdl_emit_ports(jtag_ctrl_t *jc)
* len : number of bits (= length) of new register
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void create_register( jtag_ctrl_t *jc, char *reg_name, size_t len)
static int create_register( jtag_ctrl_t *jc, char *reg_name, size_t len)
{
if (jc->mode >= 0) {
const size_t str_len = 10;
char len_str[str_len+1];
char *cmd[] = {"register",
reg_name,
len_str,
NULL};
const size_t str_len = 10;
char len_str[str_len+1];
char *cmd[] = {"register",
reg_name,
len_str,
NULL};
if (part_find_data_register( jc->part, reg_name ))
return;
if (part_find_data_register( jc->part, reg_name ))
return 1;
/* convert length information to string */
snprintf( len_str, str_len, "%i", len );
/* convert length information to string */
snprintf( len_str, str_len, "%i", len );
if (jc->mode >= 1)
cmd_run( jc->chain, cmd );
else
print_cmd( cmd );
}
if (jc->proc_mode & BSDL_MODE_INSTR_EXEC)
cmd_run( jc->chain, cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_PRINT)
print_cmd( cmd );
return 1;
}
/*****************************************************************************
* void bsdl_process_idcode( jtag_ctrl_t *jc )
* int bsdl_process_idcode( jtag_ctrl_t *jc )
*
* Creates the DIR register based on the extracted idcode.
*
@ -222,19 +226,23 @@ static void create_register( jtag_ctrl_t *jc, char *reg_name, size_t len)
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_process_idcode(jtag_ctrl_t *jc)
static int bsdl_process_idcode(jtag_ctrl_t *jc)
{
if (jc->idcode)
create_register( jc, "DIR", strlen( jc->idcode ) );
else
bsdl_msg( BSDL_MSG_WARN, _("No IDCODE specification found.\n") );
bsdl_msg( jc->proc_mode,
BSDL_MSG_WARN, _("No IDCODE specification found.\n") );
return 1;
}
/*****************************************************************************
* void bsdl_process_usercode( jtag_ctrl_t *jc )
* int bsdl_process_usercode( jtag_ctrl_t *jc )
*
* Creates the USERCODE register, the contents of the usercode string is
* ignored.
@ -243,19 +251,22 @@ static void bsdl_process_idcode(jtag_ctrl_t *jc)
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_process_usercode( jtag_ctrl_t *jc )
static int bsdl_process_usercode( jtag_ctrl_t *jc )
{
if (jc->usercode)
create_register( jc, "USERCODE", strlen( jc->usercode ) );
/* we're not interested in the usercode value at all */
return 1;
}
/*****************************************************************************
* void bsdl_set_bsr_length( jtag_ctrl_t *jc )
* int bsdl_set_bsr_length( jtag_ctrl_t *jc )
*
* Creates the BSR register based on the specified length.
*
@ -263,16 +274,19 @@ static void bsdl_process_usercode( jtag_ctrl_t *jc )
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_set_bsr_length( jtag_ctrl_t *jc )
static int bsdl_set_bsr_length( jtag_ctrl_t *jc )
{
create_register( jc, "BSR", jc->bsr_len );
return 1;
}
/*****************************************************************************
* void bsdl_process_cell_info( jtag_ctrl_t *jc )
* int bsdl_process_cell_info( jtag_ctrl_t *jc )
* Cell Info management function
*
* Creates a BSR cell from the temporary storage variables via shell command
@ -282,96 +296,95 @@ static void bsdl_set_bsr_length( jtag_ctrl_t *jc )
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_process_cell_info( jtag_ctrl_t *jc )
static int bsdl_process_cell_info( jtag_ctrl_t *jc )
{
cell_info_t *ci = jc->cell_info_first;
if (jc->mode >= 0)
const size_t str_len = 10;
char bit_num_str[str_len+1];
char ctrl_bit_num_str[str_len+1];
char disable_safe_value_str[str_len+1];
char *cmd[] = {"bit",
bit_num_str,
NULL,
NULL,
NULL,
NULL,
disable_safe_value_str,
"Z",
NULL};
while (ci)
{
const size_t str_len = 10;
char bit_num_str[str_len+1];
char ctrl_bit_num_str[str_len+1];
char disable_safe_value_str[str_len+1];
char *cmd[] = {"bit",
bit_num_str,
NULL,
NULL,
NULL,
NULL,
disable_safe_value_str,
"Z",
NULL};
while (ci)
/* convert bit number to string */
snprintf( bit_num_str, str_len, "%i", ci->bit_num );
bit_num_str[str_len] = '\0';
/* convert cell function from BSDL token to jtag syntax */
switch (ci->cell_function)
{
/* convert bit number to string */
snprintf( bit_num_str, str_len, "%i", ci->bit_num );
bit_num_str[str_len] = '\0';
/* convert cell function from BSDL token to jtag syntax */
switch (ci->cell_function)
{
case INTERNAL:
/* fall through */
case OUTPUT2:
/* fall through */
case OUTPUT3:
cmd[2] = "O";
break;
case OBSERVE_ONLY:
/* fall through */
case INPUT:
/* fall through */
case CLOCK:
cmd[2] = "I";
break;
case CONTROL:
/* fall through */
case CONTROLR:
cmd[2] = "C";
break;
case BIDIR:
cmd[2] = "B";
break;
default:
/* spoil command */
cmd[2] = "?";
break;
}
/* convert basic safe value */
cmd[3] = strcasecmp( ci->basic_safe_value, "x" ) == 0 ? "?" : ci->basic_safe_value;
/* apply port name */
cmd[4] = ci->port_name;
case INTERNAL:
/* fall through */
case OUTPUT2:
/* fall through */
case OUTPUT3:
cmd[2] = "O";
break;
case OBSERVE_ONLY:
/* fall through */
case INPUT:
/* fall through */
case CLOCK:
cmd[2] = "I";
break;
case CONTROL:
/* fall through */
case CONTROLR:
cmd[2] = "C";
break;
case BIDIR:
cmd[2] = "B";
break;
default:
/* spoil command */
cmd[2] = "?";
break;
}
/* convert basic safe value */
cmd[3] = strcasecmp( ci->basic_safe_value, "x" ) == 0 ? "?" : ci->basic_safe_value;
/* apply port name */
cmd[4] = ci->port_name;
/* add disable spec if present */
if (ci->ctrl_bit_num >= 0)
{
/* convert bit number to string */
snprintf( ctrl_bit_num_str, str_len, "%i", ci->ctrl_bit_num );
ctrl_bit_num_str[str_len] = '\0';
/* convert disable safe value to string */
snprintf( disable_safe_value_str, str_len, "%i", ci->disable_safe_value );
disable_safe_value_str[str_len] = '\0';
cmd[5] = ctrl_bit_num_str;
}
else
/* stop command procssing here */
cmd[5] = NULL;
/* add disable spec if present */
if (ci->ctrl_bit_num >= 0)
{
/* convert bit number to string */
snprintf( ctrl_bit_num_str, str_len, "%i", ci->ctrl_bit_num );
ctrl_bit_num_str[str_len] = '\0';
/* convert disable safe value to string */
snprintf( disable_safe_value_str, str_len, "%i", ci->disable_safe_value );
disable_safe_value_str[str_len] = '\0';
cmd[5] = ctrl_bit_num_str;
}
else
/* stop command procssing here */
cmd[5] = NULL;
if (jc->mode >= 1)
cmd_run( jc->chain, cmd );
else
print_cmd( cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_EXEC)
cmd_run( jc->chain, cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_PRINT)
print_cmd( cmd );
ci = ci->next;
}
ci = ci->next;
}
return 1;
}
/*****************************************************************************
* void bsdl_process_register_access( jtag_ctrl_t *jc )
* int bsdl_process_register_access( jtag_ctrl_t *jc )
* Register Access management function
*
* Runs through the main instruction list and builds the instruction/register
@ -391,10 +404,14 @@ static void bsdl_process_cell_info( jtag_ctrl_t *jc )
* jc : jtag control structure
*
* Returns
* void
* 1 -> all ok
* 0 -> error occured
****************************************************************************/
static void bsdl_process_register_access( jtag_ctrl_t *jc )
static int bsdl_process_register_access( jtag_ctrl_t *jc )
{
ainfo_elem_t *ai;
instr_elem_t *cinst;
/* ensure that all mandatory registers are created prior to
handling the instruction/register associations
+ BOUNDARY/BSR has been generated during the parsing process
@ -403,151 +420,139 @@ static void bsdl_process_register_access( jtag_ctrl_t *jc )
/* we need a BYPASS register */
create_register( jc, "BYPASS", 1 );
if (jc->mode >= 0) {
ainfo_elem_t *ai;
instr_elem_t *cinst;
/* next scan through all register_access definitions and create
the non-standard registers */
ai = jc->ainfo_list;
while (ai)
{
int is_std = 0;
/* next scan through all register_access definitions and create
the non-standard registers */
ai = jc->ainfo_list;
while (ai)
{
int is_std = 0;
if (strcasecmp( ai->reg, "BOUNDARY" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "BYPASS" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "DEVICE_ID" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "USERCODE" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "BOUNDARY" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "BYPASS" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "DEVICE_ID" ) == 0) is_std = 1;
if (strcasecmp( ai->reg, "USERCODE" ) == 0) is_std = 1;
if (!is_std)
create_register( jc, ai->reg, ai->reg_len );
if (!is_std)
create_register( jc, ai->reg, ai->reg_len );
ai = ai->next;
}
ai = ai->next;
}
/* next scan through all instruction/opcode definitions and resolve
the instruction/register associations for these */
cinst = jc->instr_list;
while (cinst)
{
char *reg_name = NULL;
char *instr_name = NULL;
/* next scan through all instruction/opcode definitions and resolve
the instruction/register associations for these */
cinst = jc->instr_list;
while (cinst)
/* now see which of the register_access elements matches this instruction */
ai = jc->ainfo_list;
while (ai && (reg_name == NULL))
{
char *reg_name = NULL;
char *instr_name = NULL;
instr_elem_t *tinst = ai->instr_list;
/* now see which of the register_access elements matches this instruction */
ai = jc->ainfo_list;
while (ai && (reg_name == NULL))
while (tinst && (reg_name == NULL))
{
instr_elem_t *tinst = ai->instr_list;
while (tinst && (reg_name == NULL))
if (strcasecmp( tinst->instr, cinst->instr ) == 0)
{
if (strcasecmp( tinst->instr, cinst->instr ) == 0)
{
/* found the instruction inside the current access info,
now set the register name
map some standard register names to different internal names*/
if (strcasecmp( ai->reg, "BOUNDARY" ) == 0) reg_name = "BSR";
else if (strcasecmp( ai->reg, "DEVICE_ID" ) == 0) reg_name = "DIR";
else reg_name = ai->reg;
}
tinst = tinst->next;
/* found the instruction inside the current access info,
now set the register name
map some standard register names to different internal names*/
if (strcasecmp( ai->reg, "BOUNDARY" ) == 0) reg_name = "BSR";
else if (strcasecmp( ai->reg, "DEVICE_ID" ) == 0) reg_name = "DIR";
else reg_name = ai->reg;
}
ai = ai->next;
tinst = tinst->next;
}
if (reg_name == NULL)
{
/* BSDL file didn't specify an explicit register_access definition
if we're looking at a standard mandatory instruction, we should
build the association ourselves */
if (strcasecmp( cinst->instr, "BYPASS" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "CLAMP" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "EXTEST" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "HIGHZ" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "IDCODE" ) == 0) reg_name = "DIR";
else if (strcasecmp( cinst->instr, "INTEST" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "PRELOAD" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "SAMPLE" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "USERCODE" ) == 0) reg_name = "USERCODE";
}
ai = ai->next;
}
if (strcasecmp( cinst->instr, "SAMPLE" ) == 0)
instr_name = "SAMPLE/PRELOAD";
else
instr_name = cinst->instr;
if (reg_name == NULL)
{
/* BSDL file didn't specify an explicit register_access definition
if we're looking at a standard mandatory instruction, we should
build the association ourselves */
if (strcasecmp( cinst->instr, "BYPASS" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "CLAMP" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "EXTEST" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "HIGHZ" ) == 0) reg_name = "BYPASS";
else if (strcasecmp( cinst->instr, "IDCODE" ) == 0) reg_name = "DIR";
else if (strcasecmp( cinst->instr, "INTEST" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "PRELOAD" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "SAMPLE" ) == 0) reg_name = "BSR";
else if (strcasecmp( cinst->instr, "USERCODE" ) == 0) reg_name = "USERCODE";
}
if (reg_name)
{
char *cmd[] = {"instruction",
instr_name,
cinst->opcode,
reg_name,
NULL};
if (jc->mode >= 1)
cmd_run( jc->chain, cmd );
else
print_cmd( cmd );
}
if (strcasecmp( cinst->instr, "SAMPLE" ) == 0)
instr_name = "SAMPLE/PRELOAD";
else
instr_name = cinst->instr;
if (reg_name)
{
char *cmd[] = {"instruction",
instr_name,
cinst->opcode,
reg_name,
NULL};
cinst = cinst->next;
if (jc->proc_mode & BSDL_MODE_INSTR_EXEC)
cmd_run( jc->chain, cmd );
if (jc->proc_mode & BSDL_MODE_INSTR_PRINT)
print_cmd( cmd );
}
cinst = cinst->next;
}
return 1;
}
/*****************************************************************************
* int parse_vhdl_elem( bsdl_parser_priv_t *priv, vhdl_elem_t *elem )
*
* Runs the specified vhdl element through the BSDl parser.
*
* Parameters
* priv : private data container for parser related tasks
* elem : vhdl element to be parsed
*
* Returns
* BSDL_MODE_SYN_CHECK -> parsing successful
* 0 -> error occured
****************************************************************************/
static int parse_vhdl_elem( bsdl_parser_priv_t *priv, vhdl_elem_t *elem )
{
char *buf;
size_t buf_len;
char *type_string = NULL;
size_t type_string_len = 0;
size_t name_string_len;
size_t elem_string_len;
#if 0
/* decode element type and set initial string for the parser */
switch (elem->type)
{
case VET_CONSTANT:
type_string = "CONSTANT ";
break;
case VET_UNKNOWN:
/* use default initializations */
break;
default:
type_string = "ATTRIBUTE ";
break;
}
type_string_len = type_string ? strlen( type_string ) : 0;
#endif
name_string_len = elem->name ? strlen( elem->name ) : 0;
elem_string_len = elem->payload ? strlen( elem->payload ) : 0;
/* allocate enough memory for total buffer */
buf_len = type_string_len + name_string_len + 1 + elem_string_len + 1;
buf_len = name_string_len + 1 + elem_string_len + 1;
buf = (char *)malloc( buf_len );
if (!buf)
{
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
return -1;
}
buf[0] = '\0';
if (type_string_len > 0)
strncat( buf, type_string, buf_len );
if (name_string_len > 0)
strncat( buf, elem->name, buf_len - type_string_len );
strncat( buf, " ", buf_len - type_string_len - name_string_len );
strncat( buf, elem->name, buf_len );
strncat( buf, " ", buf_len - name_string_len );
if (elem_string_len > 0)
strncat( buf, elem->payload, buf_len - type_string_len - name_string_len - 1 );
strncat( buf, elem->payload, buf_len - name_string_len - 1 );
buf[buf_len - 1] = '\0';
@ -559,51 +564,158 @@ static int parse_vhdl_elem( bsdl_parser_priv_t *priv, vhdl_elem_t *elem )
free( buf );
return bsdl_flex_get_compile_errors( priv->scanner );
return bsdl_flex_get_compile_errors( priv->scanner ) == 0 ? BSDL_MODE_SYN_CHECK : 0;
}
/*****************************************************************************
* int build_commands( bsdl_parser_priv_t *priv )
*
* Calls the various functions that execute or print the information extracted
* from the BSDL/vhdl elements.
*
* Parameters
* priv : private data container for parser related tasks
*
* Returns
* bit field consisting of BSDL_MODE_* actions
* telling if INSTR_EXEC or INSTR_PRINT succeeded
****************************************************************************/
static int build_commands( bsdl_parser_priv_t *priv )
{
jtag_ctrl_t *jc = priv->jtag_ctrl;
int result = 1;
bsdl_emit_ports( jc );
result &= bsdl_emit_ports( jc );
bsdl_set_instruction_length( jc );
result &= bsdl_set_instruction_length( jc );
bsdl_process_idcode( jc );
result &= bsdl_process_idcode( jc );
bsdl_process_usercode( jc );
result &= bsdl_process_usercode( jc );
bsdl_set_bsr_length( jc );
result &= bsdl_set_bsr_length( jc );
bsdl_process_register_access( jc );
result &= bsdl_process_register_access( jc );
bsdl_process_cell_info( jc );
result &= bsdl_process_cell_info( jc );
return 0;
return result ? BSDL_MODE_INSTR_EXEC | BSDL_MODE_INSTR_PRINT : 0;
}
int bsdl_sem_process_elements( bsdl_parser_priv_t *priv )
/*****************************************************************************
* int compare_idcode( jtag_ctrl_t *jc, const char *idcode )
*
* Compares idcode versus jtag_ctrl->idcode.
*
* Parameters
* jc : jtag_ctrl structure
* idcode : idcode string
*
* Returns
* 1 -> idcodes match
* 0 -> idcodes don't match
****************************************************************************/
static int compare_idcode( jtag_ctrl_t *jc, const char *idcode )
{
vhdl_elem_t *el = priv->jtag_ctrl->vhdl_elem_first;
int result = 0;
int idcode_match = 0;
while (el && (result == 0))
/* should we compare the idcodes? */
if (idcode)
{
result = parse_vhdl_elem( priv, el );
el = el->next;
if (strlen( idcode ) == strlen(jc->idcode))
{
int idx;
/* compare given idcode with idcode from BSDL file */
idcode_match = BSDL_MODE_IDCODE_CHECK;
for (idx = 0; idx < strlen( idcode ); idx++)
if (jc->idcode[idx] != 'X')
if (idcode[idx] != jc->idcode[idx])
idcode_match = 0;
if (idcode_match)
bsdl_msg( jc->proc_mode,
BSDL_MSG_NOTE, _("IDCODE matched\n") );
else
bsdl_msg( jc->proc_mode,
BSDL_MSG_NOTE, _("IDCODE mismatch\n") );
}
}
if (result != 0)
return idcode_match;
}
/*****************************************************************************
* int bsdl_process_elements( jtag_ctrl_t *jc, const char *idcode )
*
* If enabled, runs through the list of vhdl elements in jtag ctrl and parser
* them as BSDL statements.
* If enabled, compares idcode versus jc->idcode.
* If enabled, prints or executes the resulting jtag commands.
*
* Parameters
* jc : jtag_ctrl structure
* idcode : idcode string
*
* Returns
* < 0 : Error occured, parse/syntax problems or out of memory
* = 0 : No errors, idcode not checked or mismatching
* > 0 : No errors, idcode checked and matched
*
****************************************************************************/
int bsdl_process_elements( jtag_ctrl_t *jc, const char *idcode )
{
bsdl_parser_priv_t *priv;
vhdl_elem_t *el = jc->vhdl_elem_first;
int result = BSDL_MODE_SYN_CHECK;
if ((priv = bsdl_parser_init( jc )) == NULL)
return -1;
if (jc->proc_mode & BSDL_MODE_SYN_CHECK)
{
bsdl_msg( BSDL_MSG_ERR, _("BSDL stage reported errors, aborting.\n") );
return result;
while (el && (result & BSDL_MODE_SYN_CHECK))
{
result = parse_vhdl_elem( priv, el );
el = el->next;
}
if (!(result & BSDL_MODE_SYN_CHECK))
{
bsdl_msg( jc->proc_mode,
BSDL_MSG_ERR, _("BSDL stage reported errors, aborting.\n") );
bsdl_parser_deinit( priv );
return result;
}
}
result = build_commands( priv );
if (jc->idcode)
bsdl_msg( jc->proc_mode,
BSDL_MSG_NOTE, _("Got IDCODE: %s\n"), jc->idcode );
if (jc->proc_mode & BSDL_MODE_IDCODE_CHECK)
result |= compare_idcode( jc, idcode );
if (jc->proc_mode & (BSDL_MODE_INSTR_EXEC | BSDL_MODE_INSTR_PRINT))
/* IDCODE check positive if requested? */
if ( ((jc->proc_mode & BSDL_MODE_IDCODE_CHECK) &&
(result & BSDL_MODE_IDCODE_CHECK))
|| (!(jc->proc_mode & BSDL_MODE_IDCODE_CHECK)) )
result |= build_commands( priv );
if ((result & jc->proc_mode) == (jc->proc_mode & BSDL_MODE_ACTION_ALL))
if (jc->proc_mode & BSDL_MODE_IDCODE_CHECK)
result = 1;
else
result = 0;
else
result = -1;
bsdl_parser_deinit( priv );
return result;
}

@ -26,13 +26,13 @@
#define BSDL_TYPES_H
#include <jtag.h>
#include <bsdl_mode.h>
/* private data of the flex scanner
handled internally in bsdl_flex.l as yyextra */
struct scan_extra
{
int mode;
int debug;
int proc_mode;
int Compile_Errors;
int Base;
};
@ -135,8 +135,7 @@ typedef enum
with jtag internals */
struct jtag_ctrl
{
int mode;
int debug;
int proc_mode;
chain_t *chain;
part_t *part;
/* collected by VHDL parser */

@ -474,6 +474,11 @@ User_Package : PACKAGE IDENTIFIER
;
VHDL_Elements : VHDL_Element
| VHDL_Elements VHDL_Element
| error
{
Print_Error( priv_data, _("Unknown VHDL statement") );
BUMP_ERROR; YYABORT;
}
;
VHDL_Element : VHDL_Constant
| VHDL_Attribute
@ -639,16 +644,19 @@ static void Store_Text( vhdl_parser_priv_t *priv, char *Source )
/*----------------------------------------------------------------------*/
static void Print_Error( vhdl_parser_priv_t *priv_data, const char *Errmess )
{
jtag_ctrl_t *jc = priv_data->jtag_ctrl;
if (priv_data->Reading_Package)
bsdl_msg( BSDL_MSG_ERR, _("In Package %s, Line %d, %s.\n"),
bsdl_msg( jc->proc_mode,
BSDL_MSG_ERR, _("In Package %s, Line %d, %s.\n"),
priv_data->Package_File_Name,
vhdl_flex_get_lineno( priv_data->scanner ),
Errmess );
else
if (priv_data->jtag_ctrl->debug || (priv_data->jtag_ctrl->mode >= 0))
bsdl_msg( BSDL_MSG_ERR, _("Line %d, %s.\n"),
vhdl_flex_get_lineno( priv_data->scanner ),
Errmess );
bsdl_msg( jc->proc_mode,
BSDL_MSG_ERR, _("Line %d, %s.\n"),
vhdl_flex_get_lineno( priv_data->scanner ),
Errmess );
}
/*----------------------------------------------------------------------*/
static void Give_Up_And_Quit( vhdl_parser_priv_t *priv_data )
@ -809,7 +817,8 @@ vhdl_parser_priv_t *vhdl_parser_init( FILE *f, jtag_ctrl_t *jtag_ctrl )
if (!(new_priv = (vhdl_parser_priv_t *)malloc( sizeof( vhdl_parser_priv_t ) )))
{
bsdl_msg( BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( jtag_ctrl->proc_mode,
BSDL_MSG_ERR, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
return NULL;
}
@ -819,7 +828,7 @@ vhdl_parser_priv_t *vhdl_parser_init( FILE *f, jtag_ctrl_t *jtag_ctrl )
new_priv->buffer = NULL;
new_priv->len_buffer = 0;
if (!(new_priv->scanner = vhdl_flex_init( f, jtag_ctrl->mode, jtag_ctrl->debug )))
if (!(new_priv->scanner = vhdl_flex_init( f, jtag_ctrl->proc_mode )))
{
free( new_priv );
new_priv = NULL;
@ -872,7 +881,7 @@ void vhdl_parser_deinit( vhdl_parser_priv_t *priv_data )
****************************************************************************/
static void vhdl_set_entity( vhdl_parser_priv_t *priv, char *entityname )
{
if (priv->jtag_ctrl->mode >= 1)
if (priv->jtag_ctrl->proc_mode & BSDL_MODE_INSTR_EXEC)
{
strncpy( priv->jtag_ctrl->part->part, entityname, MAXLEN_PART );
priv->jtag_ctrl->part->part[MAXLEN_PART] = '\0';
@ -909,7 +918,8 @@ static void vhdl_port_add_name( vhdl_parser_priv_t *priv, char *name )
pd->names_list = new_string;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
@ -996,7 +1006,8 @@ static void vhdl_port_apply_port( vhdl_parser_priv_t *priv )
tmp_pd->next = NULL;
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
static void add_elem( vhdl_parser_priv_t *priv, vhdl_elem_t *el )
@ -1047,7 +1058,8 @@ static void set_attr_decimal( vhdl_parser_priv_t *priv, char *name, int value )
add_elem( priv, el );
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
static void set_attr_string( vhdl_parser_priv_t *priv, char *name, char *string )
@ -1076,7 +1088,8 @@ static void set_attr_string( vhdl_parser_priv_t *priv, char *name, char *string
add_elem(priv, el);
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( priv->jtag_ctrl->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
}
#if 0

@ -140,7 +140,7 @@ LEGAL NOTICES:
#define YY_EXTRA_TYPE scan_extra_t *
static char *new_string( const char * );
static char *new_string( scan_extra_t *, const char * );
#define BINARY 0
#define DECIMAL 1
@ -315,24 +315,24 @@ Std_1532_2002 STD_1532_2002
{White} { /* Do Nothing on White Space */ }
{VHDL_Comment} { /* Do Nothing on Comments */ }
{Bin_X_Pattern} {if (yyextra->Base != BIN_X) REJECT;
yylval->str = new_string( yytext );
yylval->str = new_string( yyextra, yytext );
return( BIN_X_PATTERN );}
{Identifier} {yylval->str = new_string( yytext );
{Identifier} {yylval->str = new_string( yyextra, yytext );
return( IDENTIFIER ); }
{Quoted_String} {yylval->str = new_string( yytext );
{Quoted_String} {yylval->str = new_string( yyextra, yytext );
return( QUOTED_STRING ); }
{Decimal_Number} {if (yyextra->Base != DECIMAL) REJECT;
yylval->integer = atoi( (char *)yytext );
return( DECIMAL_NUMBER );}
{Real_Number} {yylval->str = new_string( yytext );
{Real_Number} {yylval->str = new_string( yyextra, yytext );
return( REAL_NUMBER );}
{Concatenate} {return( CONCATENATE );}
{Semicolon} {return( SEMICOLON );}
{Illegal} {if (yyextra->debug || (yyextra->mode >= 0))
bsdl_msg( BSDL_MSG_ERR,
_("Illegal character %c (/%03o) at line %d:\n"),
(char)yytext[yyleng-1], (int)yytext[yyleng-1],
yylineno );
{Illegal} {bsdl_msg( yyextra->proc_mode,
BSDL_MSG_ERR,
_("Illegal character %c (/%03o) at line %d:\n"),
(char)yytext[yyleng-1], (int)yytext[yyleng-1],
yylineno );
yyextra->Compile_Errors++;
return( ILLEGAL ); /* Will cause syntax error */}
<<EOF>> {
@ -342,25 +342,18 @@ Std_1532_2002 STD_1532_2002
}
%%
/*****************************************************************************
* void *vhdl_flex_init( FILE *f, int mode, int debug )
* void *vhdl_flex_init( FILE *f, int mode )
*
* Initializes the scanner and storage elements extra data structure.
*
* Parameters
* f : descriptor of file for scanning
* mode : -1 -> read file
* no further action based on components
* 0 -> read file and extract all components
* dump commands to stdout, do not execute commands
* 1 -> read file and extract all components
* execute commands
* debug : 1 -> emit failure messages
* 0 -> no failure messages
* f : descriptor of file for scanning
* proc_mode : processing mode, consisting of BSDL_MODE_* bits
*
* Returns
* pointer to newly initialized scanner structure
****************************************************************************/
void *vhdl_flex_init( FILE *f, int mode, int debug )
void *vhdl_flex_init( FILE *f, int proc_mode )
{
scan_extra_t *extra;
yyscan_t scanner;
@ -368,20 +361,20 @@ void *vhdl_flex_init( FILE *f, int mode, int debug )
/* get our scanner structure */
if (yylex_init( &scanner ) != 0)
{
bsdl_msg( BSDL_MSG_FATAL, _("Scanner could not be initialized\n") );
bsdl_msg( proc_mode, BSDL_MSG_FATAL, _("Scanner could not be initialized\n") );
return NULL;
}
yyset_in( f, scanner );
if (!(extra = (scan_extra_t *)malloc( sizeof( scan_extra_t ) )))
{
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
yylex_destroy( scanner );
return NULL;
}
extra->mode = mode;
extra->debug = debug;
extra->proc_mode = proc_mode;
extra->Compile_Errors = 0;
extra->Base = DECIMAL;
@ -439,17 +432,18 @@ int yywrap( yyscan_t scanner )
/*****************************************************************************
* char *new_string( const char *str )
* char *new_string( scan_extra_t * extra, const char *str )
*
* Allocates memory for a string and copies the contents of *str.
*
* Parameters
* str : pointer to string to be duplicated
* extra : pointer to extra data structure
* str : pointer to string to be duplicated
*
* Returns
* pointer to allocated and initialized string memory
****************************************************************************/
static char *new_string( const char *str )
static char *new_string( scan_extra_t *extra, const char *str )
{
char *n_str;
size_t n_str_size;
@ -461,7 +455,8 @@ static char *new_string( const char *str )
n_str[n_str_size-1] = '\0'; /* set very last element to EOS */
}
else
bsdl_msg( BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
bsdl_msg( extra->proc_mode,
BSDL_MSG_FATAL, _("Out of memory, %s line %i\n"), __FILE__, __LINE__ );
return n_str;
}
@ -494,6 +489,8 @@ void vhdl_flex_switch_file( yyscan_t scanner, char *filename )
s++;
}
extra = yyget_extra( scanner );
/* file in current directory has precedence */
f = fopen( filename, "r" );
if (!f)
@ -516,7 +513,8 @@ void vhdl_flex_switch_file( yyscan_t scanner, char *filename )
f = fopen( db_file, "r" );
if (!f)
bsdl_msg( BSDL_MSG_FATAL, _("Cannot open file %s or %s.\n"), filename, db_file );
bsdl_msg( extra->proc_mode,
BSDL_MSG_FATAL, _("Cannot open file %s or %s.\n"), filename, db_file );
free( db_file );
if (!f)
return;
@ -524,7 +522,6 @@ void vhdl_flex_switch_file( yyscan_t scanner, char *filename )
}
yypush_buffer_state( yy_create_buffer( f, YY_BUF_SIZE, scanner ), scanner );
extra = yyget_extra( scanner );
yyset_lineno( 1, scanner );
}

@ -28,7 +28,7 @@
#include "bsdl_types.h"
/* VHDL lexer declarations */
void *vhdl_flex_init( FILE *, int, int );
void *vhdl_flex_init( FILE *, int );
void vhdl_flex_deinit( void * );
void vhdl_flex_switch_file( void *, char * );
int vhdl_flex_get_compile_errors( void * );

@ -46,9 +46,9 @@ cmd_bsdl_run( chain_t *chain, char *params[] )
debug_save = globs->debug;
globs->debug = 1;
if (num_params == 3) {
result = bsdl_read_file(chain, params[2], -1, NULL) >= 0 ? 1 : -1;
result = bsdl_read_file(chain, params[2], BSDL_MODE_TEST, NULL) >= 0 ? 1 : -1;
} else if (num_params == 2) {
bsdl_scan_files(chain, NULL, -1);
bsdl_scan_files(chain, NULL, BSDL_MODE_TEST);
result = 1;
}
globs->debug = debug_save;
@ -56,9 +56,9 @@ cmd_bsdl_run( chain_t *chain, char *params[] )
if (strcmp(params[1], "dump") == 0) {
if (num_params == 3) {
result = bsdl_read_file(chain, params[2], 0, NULL) >= 0 ? 1 : -1;
result = bsdl_read_file(chain, params[2], BSDL_MODE_DUMP, NULL) >= 0 ? 1 : -1;
} else if (num_params == 2) {
bsdl_scan_files(chain, NULL, 0);
bsdl_scan_files(chain, NULL, BSDL_MODE_DUMP);
result = 1;
}
}

@ -76,13 +76,13 @@ cmd_include_or_script_run( chain_t *chain, int is_include, char *params[] )
#ifdef ENABLE_BSDL
/* perform a test read to check for BSDL syntax */
if (bsdl_read_file( chain, path, -1, NULL ) >= 0)
if (bsdl_read_file( chain, path, BSDL_MODE_INCLUDE1, NULL ) >= 0)
{
/* it seems to be a proper BSDL file, so re-read and execute */
go = bsdl_read_file( chain, path, 1, NULL );
go = bsdl_read_file( chain, path, BSDL_MODE_INCLUDE2, NULL );
free( path );
return go >= 0 ? 1 : 0;
return 1;
}
#endif

@ -278,7 +278,8 @@ detect_parts( chain_t *chain, const char *db_path )
chain->active_part = ps->len - 1;
#ifdef ENABLE_BSDL
if (bsdl_scan_files(chain, register_get_string( did ), 1) <= 0) {
if (bsdl_scan_files( chain, register_get_string( did ),
BSDL_MODE_DETECT ) <= 0) {
#endif
/* find JTAG declarations for a part with id */

Loading…
Cancel
Save