?? parse.c
字號:
/*
parse.c
RETURN: conditions vars: cmdline_loop, cmdline_ask, cmdline_pause_on_error
see "set_passthru_defaults()" for configuration on exit
*/
#include <stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <dos.h>
/* non-standard includes... */
#include <lib.h>
#include <clib1.h>
#include <amcclib.h>
#include <main.h>
#include <nvram.h>
#define ENVSTR "Requires env vars:\n" \
" VERSION5920 - version 0, 1...\n" \
" DQMODE - 16 or 32 (addon bus size)\n" \
" MDMODE - IN or OUT\n" \
" PTMODE - ACTIVE or PASSIVE\n" \
" CLOCK - SYNC or ASYNC\n" \
" CLOCK_RATE_P - PCI clock speed in mhz\n" \
" CLOCK_RATE_A - Addon clock speed in mhz\n"
#define CHECKPCI if ( status != PCI_SUCCESSFUL ) \
return pci_bios_fail( status );
#define UUT_CHIP_ARG 1 /* argument is UUT nvram image file */
#define CONTROL_CHIP_ARG 3 /* argument is control chip nvram image */
#define NUM_REQD_ARGS 4 /* number of required arguments incl executable */
// from env vars...
extern int sync_clock, clock_rate_pci, clock_rate_addon;
extern version_uut;
extern struct _chip chip_uut, chip_control;
extern UINT8 boot_nvram[];
extern CHAR errstring[], text[];
extern int cmdline_ask, cmdline_pause_on_error;
extern int cmdline_loop, cmdline_sram_wait, cmdline_fifo_wait;
extern int cmdline_exit_on_error, cmdline_quiet, use_hp;
extern int skiptest[], cmdline_type;
extern int cmdline_only, exit_program, cmdline_sram_wait, cmdline_fifo_wait;
extern UINT32 cmdline_count;
extern VUINT32 control;
/* ************************************ */
/* local stuff... */
/* ************************************ */
#define ERREXIT(str) return errexit(str)
static int wfifo, prefetch, priority;
static int cmdline_device, cmdline_vendor, cmdline_subsys_vendor_id, cmdline_subsys_id;
static int errexit( CHAR *string );
static int useage( CHAR *exefile );
static CHAR *strip( CHAR *string, CHAR *stripped );
static void enverr( void );
static void checkenv( void );
static int cmdline_pin_defaults( void );
static int dqmode_32, mdmode_in, ptmode_active;
static int c_break( void );
static void set_passthru_defaults( void );
typedef int (*OPTPTR)(CHAR *str); // ptr to function that returns TRUE if
// OK, FALSE if parameter error
// options...
static int ask( CHAR *str );
static int did( CHAR *str );
static int exiterr( CHAR *str );
static int wfifof( CHAR *str );
static int vendorid( CHAR *str );
static int loop( CHAR *str );
static int onetest( CHAR *str );
static int pause( CHAR *str );
static int quiet( CHAR *str );
static int prefetchf( CHAR *str );
static int skip( CHAR *str );
static int type( CHAR *str );
static int priorityf( CHAR *str );
static int svid( CHAR *str );
static int sid( CHAR *str );
static int sramwait( CHAR *str );
static int fifowait( CHAR *str );
static int usehpf( CHAR *str );
static int help( CHAR *str );
// define structure of options - may be more than one character
struct _option {
CHAR *optstr;
OPTPTR optionp;
CHAR *description;
};
// string "BREAK" breaks the listing...
static struct _option options[] = {
{ "DID", did, "<UUT Device ID>" },
{ "VID", vendorid, "<UUT Vendor ID>" },
{ "SVID", svid, "<Subsystem Vendor ID>" },
{ "SIS", sid, "<UUT Subsystem ID>" },
{ "O", onetest, "<test number> - Run this test only" },
{ "PRE", prefetchf, "<prefetch value>" },
{ "S", skip, "<test> - Skip test(s)" },
{ "T", type, "<type> - nibble of types (set bit means SRAM vs FIFO)" },
{ "SW", sramwait, "<waits> - number of SRAM wait states" },
{ "FW", fifowait, "<waits> - number of FIFO wait states" },
{ "PRI", priorityf, "Priority bit" },
{ "BREAK", NULL, "BREAK" }, // leave description
{ "A", ask, "Do not ask if want to run the test" },
{ "E", exiterr, "Do not exit on error" },
{ "F", wfifof, "Write FIFO enable" },
{ "L", loop, "Loop" },
{ "P", pause, "Pause on error" },
{ "Q", quiet, "Quiet mode" },
{ "HP", usehpf, "Do not use HP2925 in tests" },
{ "H", help, "(or ?) - Help" },
{ "?", help, "" },
// end of array...
{ NULL, NULL, NULL }
};
int parse( int argc, char *argv[] )
/*
Parse command line...
* Get control chip DID, VID, and SID from indicated file.
* Get UUT DID, VID, and SVID, and SID from indicated file.
* The control chip and UUT devices must have different SID (SVID is AMCC 10E8).
* Call PCI BIOS to find devices, and save base addresses.
* Load boot_nvram from actual nvram and check against file from
command line (which indicates actual booted values).
* Compare actual nvram against that required for testing.
* If requires reboot, let user know, then do it.
* Set up region sizes based on boot_nvram.
* Set up pin options based on environment variables.
* set up skiptest[] array
Return: TRUE if OK, else FALSE and message printed
No return if must reboot.
*/
{
UINT32 data32;
int i, clp, status, region;
int found, chars, result, write_reboot = 0;
exit_program = FALSE;
ctrlbrk( c_break );
setcbrk( 1 );
// argc includes the name of the executable
if ( (argc < NUM_REQD_ARGS) )
exit( useage(argv[0]) );
// set up command line defaults...
use_hp = TRUE;
wfifo = FALSE; prefetch = 0; priority = FALSE;
cmdline_only = 0; // do not run just one test
cmdline_quiet = FALSE;
cmdline_loop = 1;
cmdline_ask = TRUE;
cmdline_pause_on_error = TRUE;
cmdline_exit_on_error = TRUE;
for ( i = 0; i < MAX_NUM_TESTS; i++ )
skiptest[i] = FALSE;
cmdline_sram_wait = 2;
cmdline_fifo_wait = 0;
cmdline_vendor = FALSE;
cmdline_device = FALSE;
cmdline_subsys_vendor_id = FALSE;
cmdline_subsys_id = FALSE;
// configuration defaults...
cmdline_type = 0xF; // all SRAM
chip_control.bus = 0;
chip_uut.bus = 0;
// parse the optional parameters...
for (clp=4; clp<argc; clp++)
{
/* handle parms & switches using / or - */
if ( (argv[clp][0] == '/') || (argv[clp][0] == '-') )
{
found = FALSE;
for ( i = 0; options[i].optstr != NULL; i++ )
{
chars = strlen( options[i].optstr );
if ( strncmpi( options[i].optstr, &argv[clp][1], chars ) == 0 )
{
found = TRUE;
if ( options[i].optionp == help )
exit( useage(argv[0]) );
result = options[i].optionp( &argv[clp][chars + 1] );
if ( !result )
exit(1);
}
}
if ( !found )
{
fprintf( stderr, "Unknown option \"%s\".\n", &argv[clp][0] );
exit( useage(argv[0]) );
}
} // each arg
else
{
fprintf( stderr, "Unrecognized option delimiter \"%c\".\n", argv[clp][0] );
exit( useage(argv[0]) );
}
}
// get device and vendor IDs from input files (use to find devices)...
status = buffer_load( argv[CONTROL_CHIP_ARG], &boot_nvram, NVRAM_SIZE_BYTES );
if ( status ) ERREXIT("");
chip_control.vendor_id = *(UINT16 *)( &boot_nvram[PCI_CS_VENDOR_ID + 0x40] );
chip_control.device_id = *(UINT16 *)( &boot_nvram[PCI_CS_DEVICE_ID + 0x40] );
chip_control.subsys_vendor_id = *(UINT16 *)( &boot_nvram[0x6C] );
chip_control.subsys_id = *(UINT16 *)( &boot_nvram[0x6E] );
status = buffer_load( argv[UUT_CHIP_ARG], &boot_nvram, NVRAM_SIZE_BYTES );
if ( status ) ERREXIT("");
if ( !cmdline_vendor )
chip_uut.vendor_id = *(UINT16 *)( &boot_nvram[PCI_CS_VENDOR_ID + 0x40] );
if ( !cmdline_device )
chip_uut.device_id = *(UINT16 *)( &boot_nvram[PCI_CS_DEVICE_ID + 0x40] );
if ( !cmdline_subsys_vendor_id )
chip_uut.subsys_vendor_id = *(UINT16 *)( &boot_nvram[0x6C] );
if ( !cmdline_subsys_id )
chip_uut.subsys_id = *(UINT16 *)( &boot_nvram[0x6E] );
// set up structure _chip, base addresses for control chip...
if ( !findchip( &chip_control, errstring ) )
{
printf("Did not find control chip.\n");
printf( errstring );
return FALSE;
}
chip_control.type = AMCC_5920;
// set up structure _chip, base addresses for UUT chip...
if ( !findchip( &chip_uut, errstring ) )
{
printf( "Did not find UUT chip.\n");
printf( errstring );
return FALSE;
}
chip_uut.type = AMCC_5920;
// check/load nvram - first file goes into boot_nvram (UUT)...
switch ( nvstart( argv[1], argv[2], write_reboot ) )
{
case 0: break; // all compared OK
case 1:
// file nvboot miscompared against desired UUT file, all else OK
// fall thru for reboot...
case 2: // nvram data not same as nvboot file
printf( errstring );
if ( write_reboot )
{
printf( "Press key to reboot (may have to do yourself)..." );
waitkey();
dosboot();
}
exit(1); // in case dosboot does not boot
default:
case 3: // fatal error
ERREXIT("");
}
// set up region sizes based on boot_nvram...
// doesn't matter if not enabled
for ( region = 0; region <= MAX_PT_REGION; region++ )
{
chip_uut.reg[region].size = 0L;
data32 = *(UINT32 *)( &boot_nvram[ 0x50 + (region*4)] );
data32 |= 0xC0000000L; // top two bits are width
if ( region == 0 ) data32 |= 0xFFFFFF00L; // top 3 bytes are 10E8FF
data32 &= 0xFFFFFFF0L;
if ( !data32 ) continue; // disabled
data32 = ~data32;
data32++;
chip_uut.reg[region].size = data32;
}
// set up pin defaults from environment...
checkenv();
// must have <= 2 widths if active, only 1 if passive
if ( region_widths() > 2 )
{
fprintf( stderr, "Configuration has more than two passthru widths.\n" );
fprintf( stderr, show_passthru_configuration() );
exit(1);
}
if ( !active_mode() && (region_widths() > 1) )
{
fprintf( stderr, "Passive configuration has more than one passthru width.\n" );
fprintf( stderr, show_passthru_configuration() );
exit(1);
}
control = 0L; // control register shadow to match reset
write_control_reg( 0L );
bset_control_reg( CTRL_MDMODE ); // set as always inputs
bset_control_reg( CTRL_LDENB ); // not loading
bset_control_reg( CTRL_ADDINT ); // ADDINT# inactive
// shouldn't need to reset the UUT for just mode pins (per John)
// if ( !reset_uut(1) ) ERREXIT(""); // reset, reconfigure
// set up hardware from env vars...
if ( !cmdline_pin_defaults() )
ERREXIT("");
// force PTCR and control reg to be consistent from here on...
for ( region = MIN_PT_REGION; region <= MAX_PT_REGION; region++ )
{
region_make_sram( region );
region_make_little_endian( region );
}
set_passthru_defaults();
fix_bugs(); // fixed based on chip version and parameters
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -