📄 jbimain.c
字号:
{
/* stack 0 = source right index */
/* stack 1 = source left index */
/* stack 2 = destination right index */
/* stack 3 = destination left index */
destleft = stack[--stack_ptr];
if (copy_count > copy_index)
{
src_reverse = 1;
reverse = 1;
src_count = 1 + copy_count - copy_index;
/* copy_index = source start index */
}
else
{
src_count = 1 + copy_index - copy_count;
copy_index = copy_count; /* source start index */
}
if (copy_index2 > destleft)
{
dest_reverse = 1;
reverse = !reverse;
dest_count = 1 + copy_index2 - destleft;
copy_index2 = destleft; /* destination start index */
}
else
{
dest_count = 1 + destleft - copy_index2;
/* copy_index2 = destination start index */
}
copy_count = (src_count < dest_count) ? src_count : dest_count;
if ((src_reverse || dest_reverse) &&
(src_count != dest_count))
{
/* If either the source or destination is reversed, */
/* we can't tolerate a length mismatch, because we */
/* "left justify" the arrays when copying. This */
/* won't work correctly with reversed arrays. */
status = JBIC_BOUNDS_ERROR;
}
}
count = (unsigned int) copy_count;
index = (unsigned int) copy_index;
index2 = (unsigned int) copy_index2;
/*
* If destination is a read-only array, allocate a buffer
* and convert it to a writable array
*/
variable_id = (unsigned int) args[1];
if ((version > 0) && ((attributes[variable_id] & 0x9c) == 0x0c))
{
/*
* Allocate a writable buffer for this array
*/
long_temp = (variable_size[variable_id] + 7L) >> 3L;
charptr_temp2 = (unsigned char *) variables[variable_id];
charptr_temp = jbi_malloc((unsigned int) long_temp);
variables[variable_id] = (long) charptr_temp;
if (variables[variable_id] == NULL)
{
status = JBIC_OUT_OF_MEMORY;
break;
}
else
{
/* zero the buffer */
for (long_index = 0L;
long_index < long_temp;
++long_index)
{
charptr_temp[long_index] = 0;
}
/* copy previous contents into buffer */
for (long_index = 0L;
long_index < variable_size[variable_id];
++long_index)
{
#if PORT==DOS
if ((attributes[variable_id] & 0x02) &&
(long_index & 0xFFFF == 0))
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (long_index >> 16), version);
charptr_temp = jbi_aca_out_buffer;
long_index2 = long_index & 0xFFFF;
}
#else
long_index2 = long_index;
#endif
if (charptr_temp2[long_index2 >> 3] &
(1 << (long_index2 & 7)))
{
charptr_temp[long_index >> 3] |=
(1 << (long_index & 7));
}
}
/* set bit 7 - buffer was dynamically allocated */
attributes[variable_id] |= 0x80;
/* clear bit 2 - variable is writable */
attributes[variable_id] &= ~0x04;
attributes[variable_id] |= 0x01;
}
}
#if PORT==DOS
/* for 16-bit version, allow writing in allocated buffers */
if ((version > 0) &&
((attributes[variable_id] & 0x9c) == 0x8c))
{
attributes[variable_id] &= ~0x04;
attributes[variable_id] |= 0x01;
}
#endif
charptr_temp = (unsigned char *) variables[args[1]];
charptr_temp2 = (unsigned char *) variables[args[0]];
#if PORT==DOS
variable_id = (unsigned int) args[0];
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (copy_index >> 16), version);
charptr_temp2 = jbi_aca_out_buffer;
}
#endif
/* check that destination is a writable Boolean array */
if ((attributes[args[1]] & 0x1c) != 0x08)
{
status = JBIC_BOUNDS_ERROR;
break;
}
if (count < 1)
{
status = JBIC_BOUNDS_ERROR;
}
else
{
if (reverse)
{
index2 += (count - 1);
}
for (i = 0; i < count; ++i)
{
if (charptr_temp2[index >> 3] & (1 << (index & 7)))
{
charptr_temp[index2 >> 3] |= (1 << (index2 & 7));
}
else
{
charptr_temp[index2 >> 3] &=
~(unsigned int) (1 << (index2 & 7));
}
++index;
if (reverse) --index2; else ++index2;
}
}
}
break;
case 0x81: /* REVA */
/*
* ARRAY COPY reversing bit order
* ...argument 0 is dest ID
* ...argument 1 is source ID
* ...stack 0 is dest index
* ...stack 1 is source index
* ...stack 2 is count
*/
bad_opcode = 1;
break;
case 0x82: /* DSC */
case 0x83: /* ISC */
/*
* DRSCAN with capture
* IRSCAN with capture
* ...argument 0 is scan data variable ID
* ...argument 1 is capture variable ID
* ...stack 0 is capture index
* ...stack 1 is scan data index
* ...stack 2 is count
*/
IF_CHECK_STACK(3)
{
long scan_right, scan_left, capture_count, scan_count;
long capture_index = stack[--stack_ptr];
long scan_index = stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = capture right index */
/* stack 1 = capture left index */
/* stack 2 = scan right index */
/* stack 3 = scan left index */
/* stack 4 = count */
scan_right = stack[--stack_ptr];
scan_left = stack[--stack_ptr];
capture_count = 1 + scan_index - capture_index;
scan_count = 1 + scan_left - scan_right;
scan_index = scan_right;
}
long_count = stack[--stack_ptr];
/*
* If capture array is read-only, allocate a buffer
* and convert it to a writable array
*/
variable_id = (unsigned int) args[1];
if ((version > 0) && ((attributes[variable_id] & 0x9c) == 0x0c))
{
/*
* Allocate a writable buffer for this array
*/
long_temp = (variable_size[variable_id] + 7L) >> 3L;
charptr_temp2 = (unsigned char *) variables[variable_id];
charptr_temp = jbi_malloc((unsigned int) long_temp);
variables[variable_id] = (long) charptr_temp;
if (variables[variable_id] == NULL)
{
status = JBIC_OUT_OF_MEMORY;
break;
}
else
{
/* zero the buffer */
for (long_index = 0L;
long_index < long_temp;
++long_index)
{
charptr_temp[long_index] = 0;
}
/* copy previous contents into buffer */
for (long_index = 0L;
long_index < variable_size[variable_id];
++long_index)
{
#if PORT==DOS
if ((attributes[variable_id] & 0x02) &&
(long_index & 0xFFFF == 0))
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (long_index >> 16), version);
charptr_temp = jbi_aca_out_buffer;
long_index2 = long_index & 0xFFFF;
}
#else
long_index2 = long_index;
#endif
if (charptr_temp2[long_index2 >> 3] &
(1 << (long_index2 & 7)))
{
charptr_temp[long_index >> 3] |=
(1 << (long_index & 7));
}
}
/* set bit 7 - buffer was dynamically allocated */
attributes[variable_id] |= 0x80;
/* clear bit 2 - variable is writable */
attributes[variable_id] &= ~0x04;
attributes[variable_id] |= 0x01;
}
}
#if PORT==DOS
/* for 16-bit version, allow writing in allocated buffers */
if ((version > 0) &&
((attributes[variable_id] & 0x9c) == 0x8c))
{
attributes[variable_id] &= ~0x04;
attributes[variable_id] |= 0x01;
}
#endif
charptr_temp = (unsigned char *) variables[args[0]];
charptr_temp2 = (unsigned char *) variables[args[1]];
#if PORT==DOS
variable_id = (unsigned int) args[0];
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (scan_index >> 16), version);
scan_index &= 0x0000ffff;
charptr_temp = jbi_aca_out_buffer;
}
#endif
if ((version > 0) &&
((long_count > capture_count) || (long_count > scan_count)))
{
status = JBIC_BOUNDS_ERROR;
}
/* check that capture array is a writable Boolean array */
if ((attributes[args[1]] & 0x1c) != 0x08)
{
status = JBIC_BOUNDS_ERROR;
}
if (status == JBIC_SUCCESS)
{
if (opcode == 0x82) /* DSC */
{
status = jbi_swap_dr((unsigned int) long_count,
charptr_temp, (unsigned long) scan_index,
charptr_temp2, (unsigned int) capture_index);
}
else /* ISC */
{
status = jbi_swap_ir((unsigned int) long_count,
charptr_temp, (unsigned int) scan_index,
charptr_temp2, (unsigned int) capture_index);
}
}
}
break;
case 0x84: /* WAIT */
/*
* WAIT
* ...argument 0 is wait state
* ...argument 1 is end state
* ...stack 0 is cycles
* ...stack 1 is microseconds
*/
IF_CHECK_STACK(2)
{
long_temp = stack[--stack_ptr];
if (long_temp != 0L)
{
status = jbi_do_wait_cycles(long_temp, (unsigned int) args[0]);
}
long_temp = stack[--stack_ptr];
if ((status == JBIC_SUCCESS) && (long_temp != 0L))
{
status = jbi_do_wait_microseconds(long_temp, (unsigned int) args[0]);
}
if ((status == JBIC_SUCCESS) && (args[1] != args[0]))
{
status = jbi_goto_jtag_state((unsigned int) args[1]);
}
if (version > 0)
{
--stack_ptr; /* throw away MAX cycles */
--stack_ptr; /* throw away MAX microseconds */
}
}
break;
case 0x85: /* VS */
/*
* VECTOR
* ...argument 0 is dir data variable ID
* ...argument 1 is scan data variable ID
* ...stack 0 is dir array index
* ...stack 1 is scan array index
* ...stack 2 is count
*/
bad_opcode = 1;
break;
case 0xC0: /* CMPA */
/*
* Array compare
* ...argument 0 is source 1 ID
* ...argument 1 is source 2 ID
* ...argument 2 is mask ID
* ...stack 0 is source 1 index
* ...stack 1 is source 2 index
* ...stack 2 is mask index
* ...stack 3 is count
*/
IF_CHECK_STACK(4)
{
long a, b;
unsigned char *source1 = (unsigned char *) variables[args[0]];
unsigned char *source2 = (unsigned char *) variables[args[1]];
unsigned char *mask = (unsigned char *) variables[args[2]];
unsigned long index1 = stack[--stack_ptr];
unsigned long index2 = stack[--stack_ptr];
unsigned long mask_index = stack[--stack_ptr];
long_count = stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = source 1 right index */
/* stack 1 = source 1 left index */
/* stack 2 = source 2 right index */
/* stack 3 = source 2 left index */
/* stack 4 = mask right index */
/* stack 5 = mask left index */
long mask_right = stack[--stack_ptr];
long mask_left = stack[--stack_ptr];
a = 1 + index2 - index1; /* source 1 count */
b = 1 + long_count - mask_index; /* source 2 count */
a = (a < b) ? a : b;
b = 1 + mask_left - mask_right; /* mask count */
a = (a < b) ? a : b;
index2 = mask_index; /* source 2 start index */
mask_index = mask_right; /* mask start index */
long_count = a;
}
long_temp = 1L;
if (long_count < 1)
{
status = JBIC_BOUNDS_ERROR;
}
else
{
#if PORT==DOS
variable_id = (unsigned int) args[0];
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
jbi_uncompress_page(variable_id,
(int) (index1 >> 16), version);
index1 &= 0x0000ffff;
source1 = jbi_aca_out_buffer;
}
variable_id = (unsigned int) args[1];
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
jbi_uncompress_page(variable_id,
(int) (index2 >> 16), version);
index2 &= 0x0000ffff;
source2 = jbi_aca_out_buffer;
}
#endif
count = (unsigned int) long_count;
for (i = 0; i < count; ++i)
{
if (mask[mask_index >> 3] & (1 << (mask_index & 7)))
{
a = source1[index1 >> 3] & (1 << (index1 & 7))
? 1 : 0;
b = source2[index2 >> 3] & (1 << (index2 & 7))
? 1 : 0;
if (a != b) long_temp = 0L; /* failure */
}
++index1;
++index2;
++mask_index;
}
}
stack[stack_ptr++] = long_temp;
}
break;
case 0xC1: /* VSC */
/*
* VECTOR with capture
* ...argument 0 is dir data variable ID
* ...argument 1 is scan data variable ID
* ...argument 2 is capture variable ID
* ...stack 0 is capture index
* ...stack 1 is scan data index
* ...stack 2 is dir data index
* ...stack 3 is count
*/
bad_opcode = 1;
break;
default:
/*
* Unrecognized opcode -- ERROR!
*/
bad_opcode = 1;
break;
}
if (bad_opcode)
{
status = JBIC_ILLEGAL_OPCODE;
}
if ((stack_ptr < 0) || (stack_ptr >= JBI_STACK_SIZE))
{
status = JBIC_STACK_OVERFLOW;
}
if (status != JBIC_SUCCESS)
{
done = 1;
*error_address = (long) (opcode_address - code_section);
}
}
jbi_free_jtag_padding_buffers(reset_jtag);
/*
* Free all dynamically allocated arrays
*/
if ((attributes != NULL) && (variables != NULL))
{
for (i = 0; i < (unsigned int) symbol_count; ++i)
{
if ((attributes[i] & 0x80) && (variables[i] != NULL))
{
jbi_free((void *) variables[i]);
}
}
}
if (variables != NULL) jbi_free(variables);
if (variable_size != NULL) jbi_free(variable_size);
if (attributes != NULL) jbi_free(attributes);
if (proc_attributes != NULL) jbi_free(proc_attributes);
return (status);
}
/****************************************************************************/
/* */
JBI_RETURN_TYPE jbi_get_note
(
PROGRAM_PTR program,
long program_size,
long *offset,
char *key,
char *value,
int length
)
/* */
/* Description: Gets key and value of NOTE fields in the JBC file. */
/* Can be called in two modes: if offset pointer is NULL, */
/* then the function sea
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -