26 #include <asm/unaligned.h>
27 #include <linux/ctype.h>
28 #include <linux/string.h>
30 #include <linux/slab.h>
31 #include <linux/module.h>
44 #define dprintk(args...) \
46 printk(KERN_DEBUG args); \
134 static int altera_check_stack(
int stack_ptr,
int count,
int *
status)
136 if (stack_ptr < count) {
144 static void altera_export_int(
char *
key,
s32 value)
146 dprintk(
"Export: key = \"%s\", value = %d\n", key, value);
149 #define HEX_LINE_CHARS 72
150 #define HEX_LINE_BITS (HEX_LINE_CHARS * 4)
159 dprintk(
"Export: key = \"%s\", %d bits, value = HEX\n",
163 for (line = 0; line < lines; ++line) {
164 if (line < (lines - 1)) {
171 size = (linebits + 3) / 4;
179 for (k = 0; k < linebits; ++
k) {
181 if (data[i >> 3] & (1 << (i & 7)))
182 value |= (1 << (i & 3));
184 sprintf(&
string[j],
"%1x", value);
190 sprintf(&
string[j],
"%1x", value);
196 size = (count + 3) / 4;
201 for (i = 0; i <
count; ++
i) {
202 if (data[i >> 3] & (1 << (i & 7)))
203 value |= (1 << (i & 3));
205 sprintf(&
string[j],
"%1x", value);
211 sprintf(&
string[j],
"%1x", value);
213 dprintk(
"Export: key = \"%s\", %d bits, value = HEX %s\n",
230 u32 action_table = 0
L;
237 u32 action_count = 0
L;
243 u8 *proc_attributes =
NULL;
272 int current_proc = 0;
280 if (program_size > 52L) {
282 version = (first_word & 1
L);
283 *format_version = version + 1;
298 if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L)) {
307 vars = kzalloc(sym_count *
sizeof(
long),
GFP_KERNEL);
315 if (var_size ==
NULL)
326 if ((status == 0) && (version > 0)) {
327 proc_attributes = kzalloc(proc_count,
GFP_KERNEL);
329 if (proc_attributes ==
NULL)
338 for (i = 0; i < sym_count; ++
i) {
339 offset = (sym_table + ((11 +
delta) * i));
365 if ((attrs[i] & 0x0c) == 0x04)
368 else if ((attrs[i] & 0x1e) == 0x0e) {
385 version) != uncomp_size)
389 var_size[
i] = uncomp_size * 8
L;
392 }
else if ((attrs[i] & 0x1e) == 0x0c) {
394 vars[
i] = value + data_sect + (
long)p;
395 }
else if ((attrs[i] & 0x1c) == 0x1c) {
397 vars[
i] = value + data_sect;
398 }
else if ((attrs[i] & 0x0c) == 0x08) {
404 if (var_size[i] > 0) {
409 size = (var_size[
i] *
sizeof(
s32));
412 size = ((var_size[
i] + 7
L) / 8L);
420 for (j = 0; j <
size; ++
j)
421 ((
u8 *)(vars[
i]))[
j] = 0;
450 int action_found = 0;
451 for (i = 0; (i < action_count) && !action_found; ++
i) {
455 name = &p[str_table + name_id];
474 while ((i != 0) || first_time) {
499 ((proc_attributes[i] == 1) ||
500 ((proc_attributes[i] & 0xc0) == 0x40))) {
505 if ((i != 0) || ((i == 0) && (current_proc == 0) &&
506 ((proc_attributes[0] != 1) &&
507 ((proc_attributes[0] & 0xc0) != 0x40)))) {
512 if ((pc < code_sect) || (pc >= debug_sect))
524 opcode = (p[
pc] & 0xff);
529 printk(
"opcode: %02x\n", opcode);
531 arg_count = (opcode >> 6) & 3;
532 for (i = 0; i < arg_count; ++
i) {
541 if (altera_check_stack(stack_ptr, 1, &status)) {
542 stack[stack_ptr] = stack[stack_ptr - 1];
547 if (altera_check_stack(stack_ptr, 2, &status)) {
548 long_tmp = stack[stack_ptr - 2];
549 stack[stack_ptr - 2] = stack[stack_ptr - 1];
550 stack[stack_ptr - 1] = long_tmp;
554 if (altera_check_stack(stack_ptr, 2, &status)) {
556 stack[stack_ptr - 1] += stack[stack_ptr];
560 if (altera_check_stack(stack_ptr, 2, &status)) {
562 stack[stack_ptr - 1] -= stack[stack_ptr];
566 if (altera_check_stack(stack_ptr, 2, &status)) {
568 stack[stack_ptr - 1] *= stack[stack_ptr];
572 if (altera_check_stack(stack_ptr, 2, &status)) {
574 stack[stack_ptr - 1] /= stack[stack_ptr];
578 if (altera_check_stack(stack_ptr, 2, &status)) {
580 stack[stack_ptr - 1] %= stack[stack_ptr];
584 if (altera_check_stack(stack_ptr, 2, &status)) {
586 stack[stack_ptr - 1] <<= stack[stack_ptr];
590 if (altera_check_stack(stack_ptr, 2, &status)) {
592 stack[stack_ptr - 1] >>= stack[stack_ptr];
596 if (altera_check_stack(stack_ptr, 1, &status))
597 stack[stack_ptr - 1] ^= (-1
L);
601 if (altera_check_stack(stack_ptr, 2, &status)) {
603 stack[stack_ptr - 1] &= stack[stack_ptr];
607 if (altera_check_stack(stack_ptr, 2, &status)) {
609 stack[stack_ptr - 1] |= stack[stack_ptr];
613 if (altera_check_stack(stack_ptr, 2, &status)) {
615 stack[stack_ptr - 1] ^= stack[stack_ptr];
619 if (!altera_check_stack(stack_ptr, 1, &status))
621 stack[stack_ptr - 1] = stack[stack_ptr - 1] ? 0
L : 1
L;
624 if (!altera_check_stack(stack_ptr, 2, &status))
627 stack[stack_ptr - 1] =
628 (stack[stack_ptr - 1] > stack[stack_ptr]) ?
633 if (!altera_check_stack(stack_ptr, 2, &status))
636 stack[stack_ptr - 1] =
637 (stack[stack_ptr - 1] < stack[stack_ptr]) ?
642 if ((version > 0) && (stack_ptr == 0)) {
651 (13 * current_proc) + 4]);
653 ((proc_attributes[i] == 1) ||
654 ((proc_attributes[i] & 0xc0) == 0x40)))
667 if ((pc < code_sect) ||
673 if (altera_check_stack(stack_ptr, 1, &status)) {
674 pc = stack[--stack_ptr] + code_sect;
675 if ((pc <= code_sect) ||
690 if (altera_check_stack(stack_ptr, 4, &status)) {
691 s32 a = stack[--stack_ptr];
692 s32 b = stack[--stack_ptr];
693 long_tmp = stack[--stack_ptr];
694 count = stack[stack_ptr - 1];
696 if ((count < 1) || (count > 32))
699 long_tmp &= ((-1
L) >> (32 - count));
701 stack[stack_ptr - 1] =
702 ((a & long_tmp) == (b & long_tmp))
712 if (!altera_check_stack(stack_ptr, 1, &status))
715 "%ld", stack[--stack_ptr]);
730 if (!altera_check_stack(stack_ptr, 2, &status))
732 long_tmp = stack[--stack_ptr];
733 count = stack[--stack_ptr];
743 if (!altera_check_stack(stack_ptr, 2, &status))
745 long_tmp = stack[--stack_ptr];
746 count = stack[stack_ptr - 1];
758 if (!altera_check_stack(stack_ptr, 2, &status))
760 long_tmp = stack[--stack_ptr];
761 count = stack[--stack_ptr];
771 if (!altera_check_stack(stack_ptr, 2, &status))
773 long_tmp = stack[--stack_ptr];
774 count = stack[stack_ptr - 1];
781 if (!altera_check_stack(stack_ptr, 1, &status))
783 count = stack[--stack_ptr];
792 if (!altera_check_stack(stack_ptr, 2, &status))
794 count = stack[--stack_ptr];
795 long_tmp = stack[--stack_ptr];
805 if (altera_check_stack(stack_ptr, 1, &status)) {
806 count = stack[--stack_ptr];
817 if (!altera_check_stack(stack_ptr, 2, &status))
819 count = stack[--stack_ptr];
820 long_tmp = stack[--stack_ptr];
826 if (altera_check_stack(stack_ptr, 1, &status)) {
827 count = stack[--stack_ptr];
838 if (altera_check_stack(stack_ptr, 2, &status)) {
839 count = stack[--stack_ptr];
840 long_tmp = stack[--stack_ptr];
851 if (altera_check_stack(stack_ptr, 1, &status)) {
852 count = stack[--stack_ptr];
863 if (!altera_check_stack(stack_ptr, 2, &status))
865 count = stack[--stack_ptr];
866 long_tmp = stack[--stack_ptr];
872 if (altera_check_stack(stack_ptr, 1, &status)) {
875 ch = (
char) stack[--stack_ptr];
876 if ((ch < 1) || (ch > 127)) {
884 msg_buff[
count] = ch;
885 msg_buff[count + 1] =
'\0';
889 if (altera_check_stack(stack_ptr, 1, &status))
890 *exit_code = stack[--stack_ptr];
895 if (!altera_check_stack(stack_ptr, 2, &status))
898 stack[stack_ptr - 1] =
899 (stack[stack_ptr - 1] == stack[stack_ptr]) ?
903 if (altera_check_stack(stack_ptr, 1, &status))
908 if (!altera_check_stack(stack_ptr, 1, &status))
910 if (stack[stack_ptr - 1] < 0)
911 stack[stack_ptr - 1] = 0 - stack[stack_ptr - 1];
929 if (altera_check_stack(stack_ptr, 2, &status)) {
930 long_tmp = stack[stack_ptr - 2];
931 stack[stack_ptr - 2] = stack[stack_ptr - 1];
932 stack[stack_ptr - 1] = long_tmp;
937 if (altera_check_stack(stack_ptr, index, &status)) {
938 long_tmp = stack[stack_ptr -
index];
939 stack[stack_ptr -
index] = stack[stack_ptr - 1];
940 stack[stack_ptr - 1] = long_tmp;
944 if (altera_check_stack(stack_ptr, 2, &status)) {
945 long_tmp = stack[stack_ptr - 2];
946 stack[stack_ptr - 2] = stack[stack_ptr - 1];
947 stack[stack_ptr - 1] = long_tmp;
952 if (altera_check_stack(stack_ptr, index, &status)) {
953 long_tmp = stack[stack_ptr -
index];
954 stack[stack_ptr -
index] = stack[stack_ptr - 1];
955 stack[stack_ptr - 1] = long_tmp;
960 if (altera_check_stack(stack_ptr, index, &status)) {
961 stack[stack_ptr] = stack[stack_ptr -
index];
967 if (altera_check_stack(stack_ptr, index, &status)) {
968 long_tmp = stack[stack_ptr -
index];
969 stack[stack_ptr -
index] = stack[stack_ptr - 1];
970 stack[stack_ptr - 1] = long_tmp;
974 if (altera_check_stack(stack_ptr, 2, &status)) {
975 long_tmp = stack[stack_ptr - 2];
976 stack[stack_ptr - 2] = stack[stack_ptr - 1];
977 stack[stack_ptr - 1] = long_tmp;
982 if (altera_check_stack(stack_ptr, index, &status)) {
983 stack[stack_ptr] = stack[stack_ptr -
index];
989 if (altera_check_stack(stack_ptr, index, &status)) {
990 stack[stack_ptr] = stack[stack_ptr -
index];
995 stack[stack_ptr++] = 0;
998 stack[stack_ptr++] = (
s32) args[0];
1001 stack[stack_ptr++] = vars[args[0]];
1004 pc = args[0] + code_sect;
1005 if ((pc < code_sect) || (pc >= debug_sect))
1009 stack[stack_ptr++] =
pc;
1010 pc = args[0] + code_sect;
1011 if ((pc < code_sect) || (pc >= debug_sect))
1022 if (altera_check_stack(stack_ptr, 3, &status)) {
1023 s32 step = stack[stack_ptr - 1];
1024 s32 end = stack[stack_ptr - 2];
1025 s32 top = stack[stack_ptr - 3];
1026 s32 iterator = vars[args[0]];
1030 if (iterator <= end)
1032 }
else if (iterator >= end)
1038 vars[args[0]] = iterator +
step;
1039 pc = top + code_sect;
1040 if ((pc < code_sect) ||
1051 count =
strlen(msg_buff);
1053 &p[str_table + args[0]],
1091 index = (args[0]) + 1;
1092 if (altera_check_stack(stack_ptr, index, &status)) {
1093 long_tmp = stack[stack_ptr -
index];
1094 stack[stack_ptr -
index] = stack[stack_ptr - 1];
1095 stack[stack_ptr - 1] = long_tmp;
1103 index = (args[0]) + 1;
1104 if (altera_check_stack(stack_ptr, index, &status)) {
1105 stack[stack_ptr] = stack[stack_ptr -
index];
1115 if (altera_check_stack(stack_ptr, 1, &status))
1116 vars[args[0]] = stack[--stack_ptr];
1126 if (!altera_check_stack(stack_ptr, 2, &status))
1128 variable_id = args[0];
1134 if ((version > 0) &&
1135 ((attrs[variable_id] & 0x9c) == 0x1c)) {
1137 count = var_size[variable_id];
1138 long_tmp = vars[variable_id];
1139 longptr_tmp = kzalloc(count *
sizeof(
long),
1141 vars[variable_id] = (
long)longptr_tmp;
1143 if (vars[variable_id] == 0) {
1149 for (i = 0; i <
count; ++
i) {
1152 long_tmp +=
sizeof(
long);
1159 attrs[variable_id] |= 0x80;
1162 attrs[variable_id] &= ~0x04;
1163 attrs[variable_id] |= 0x01;
1168 if ((attrs[variable_id] & 0x1c) != 0x18)
1171 longptr_tmp = (
long *)vars[variable_id];
1174 index = stack[--stack_ptr];
1177 longptr_tmp[
index] = stack[--stack_ptr];
1189 if (!altera_check_stack(stack_ptr, 3, &status))
1191 variable_id = args[0];
1197 if ((version > 0) &&
1198 ((attrs[variable_id] & 0x9c) == 0x0c)) {
1201 (var_size[variable_id] + 7
L) >> 3L;
1202 charptr_tmp2 = (
u8 *)vars[variable_id];
1205 vars[variable_id] = (
long)charptr_tmp;
1207 if (vars[variable_id] == 0) {
1214 long_idx < long_tmp;
1216 charptr_tmp[long_idx] = 0;
1221 long_idx < var_size[variable_id];
1223 long_idx2 = long_idx;
1225 if (charptr_tmp2[long_idx2 >> 3] &
1226 (1 << (long_idx2 & 7))) {
1227 charptr_tmp[long_idx >> 3] |=
1228 (1 << (long_idx & 7));
1236 attrs[variable_id] |= 0x80;
1239 attrs[variable_id] &= ~0x04;
1240 attrs[variable_id] |= 0x01;
1248 if ((attrs[variable_id] & 0x1c) != 0x08) {
1253 charptr_tmp = (
u8 *)vars[variable_id];
1256 long_count = stack[--stack_ptr];
1259 long_idx = stack[--stack_ptr];
1269 if (long_idx > long_count) {
1271 long_tmp = long_count;
1272 long_count = 1 + long_idx -
1274 long_idx = long_tmp;
1280 long_count = 1 + long_count -
1286 long_tmp = stack[--stack_ptr];
1288 if (long_count < 1) {
1293 for (i = 0; i < long_count; ++
i) {
1294 if (long_tmp & (1L << (
s32)
i))
1295 charptr_tmp[long_idx >> 3
L] |=
1296 (1
L << (long_idx & 7
L));
1298 charptr_tmp[long_idx >> 3
L] &=
1299 ~(1
L << (long_idx & 7
L));
1311 if (altera_check_stack(stack_ptr, 1, &status)) {
1312 if (stack[--stack_ptr] == 0) {
1313 pc = args[0] + code_sect;
1314 if ((pc < code_sect) ||
1329 if (!altera_check_stack(stack_ptr, 2, &status))
1331 long_idx = stack[--stack_ptr];
1332 long_count = stack[--stack_ptr];
1340 long_tmp = long_count;
1341 long_count = stack[--stack_ptr];
1343 if (long_idx > long_tmp) {
1345 long_idx = long_tmp;
1349 charptr_tmp = (
u8 *)vars[args[0]];
1356 charptr_tmp2 = charptr_tmp;
1357 charptr_tmp = kzalloc((long_count >> 3) + 1,
1359 if (charptr_tmp ==
NULL) {
1364 long_tmp = long_idx + long_count - 1;
1366 while (long_idx2 < long_count) {
1367 if (charptr_tmp2[long_tmp >> 3] &
1368 (1 << (long_tmp & 7)))
1369 charptr_tmp[long_idx2 >> 3] |=
1370 (1 << (long_idx2 & 7));
1372 charptr_tmp[long_idx2 >> 3] &=
1373 ~(1 << (long_idx2 & 7));
1382 charptr_tmp, long_idx);
1385 charptr_tmp, long_idx);
1398 if (!altera_check_stack(stack_ptr, 2, &status))
1400 index = stack[--stack_ptr];
1401 count = stack[--stack_ptr];
1408 count = 1 + count -
index;
1410 charptr_tmp = (
u8 *)vars[args[0]];
1421 if (!altera_check_stack(stack_ptr, 2, &status))
1423 index = stack[--stack_ptr];
1424 count = stack[--stack_ptr];
1431 count = 1 + count -
index;
1433 charptr_tmp = (
u8 *)vars[args[0]];
1444 if (!altera_check_stack(stack_ptr, 2, &status))
1446 index = stack[--stack_ptr];
1447 count = stack[--stack_ptr];
1454 count = 1 + count -
index;
1456 charptr_tmp = (
u8 *)vars[args[0]];
1468 if (!altera_check_stack(stack_ptr, 2, &status))
1470 index = stack[--stack_ptr];
1471 count = stack[--stack_ptr];
1478 count = 1 + count -
index;
1480 charptr_tmp = (
u8 *)vars[args[0]];
1491 if (altera_check_stack(stack_ptr, 1, &status)) {
1492 name = &p[str_table + args[0]];
1493 long_tmp = stack[--stack_ptr];
1494 altera_export_int(name, long_tmp);
1503 if (!altera_check_stack(stack_ptr, 1, &status))
1505 variable_id = args[0];
1506 index = stack[stack_ptr - 1];
1509 if ((attrs[variable_id] & 0x1f) == 0x19) {
1511 longptr_tmp = (
long *)vars[variable_id];
1512 stack[stack_ptr - 1] = longptr_tmp[
index];
1513 }
else if ((attrs[variable_id] & 0x1f) == 0x1c) {
1515 long_tmp = vars[variable_id] +
1516 (index *
sizeof(
long));
1517 stack[stack_ptr - 1] =
1530 if (!altera_check_stack(stack_ptr, 2, &status))
1532 variable_id = args[0];
1535 if ((attrs[variable_id] & 0x18) != 0x08) {
1540 charptr_tmp = (
u8 *)vars[variable_id];
1543 count = stack[--stack_ptr];
1546 index = stack[stack_ptr - 1];
1553 count = 1 + count -
index;
1555 if ((count < 1) || (count > 32)) {
1562 for (i = 0; i <
count; ++
i)
1563 if (charptr_tmp[(i + index) >> 3] &
1564 (1 << ((i +
index) & 7)))
1565 long_tmp |= (1
L <<
i);
1567 stack[stack_ptr - 1] = long_tmp;
1576 if (!altera_check_stack(stack_ptr, 1, &status))
1578 variable_id = args[0];
1579 long_tmp = stack[--stack_ptr];
1581 if (long_tmp > var_size[variable_id]) {
1582 var_size[variable_id] = long_tmp;
1584 if (attrs[variable_id] & 0x10)
1586 long_tmp *=
sizeof(
long);
1589 long_tmp = (long_tmp + 7) >> 3;
1595 if (attrs[variable_id] & 0x80) {
1596 kfree((
void *)vars[variable_id]);
1597 vars[variable_id] = 0;
1604 vars[variable_id] = (
long)
1607 if (vars[variable_id] == 0) {
1617 attrs[variable_id] |= 0x80;
1620 count = ((var_size[variable_id] + 7
L) /
1622 charptr_tmp = (
u8 *)(vars[variable_id]);
1624 charptr_tmp[index] = 0;
1637 if (!altera_check_stack(stack_ptr, 3, &status))
1644 name = &p[str_table + args[0]];
1645 variable_id = stack[--stack_ptr];
1646 long_idx = stack[--stack_ptr];
1647 long_idx2 = stack[--stack_ptr];
1649 if (long_idx > long_idx2) {
1655 long_count = 1 + long_idx2 - long_idx;
1657 charptr_tmp = (
u8 *)vars[variable_id];
1658 charptr_tmp2 =
NULL;
1660 if ((long_idx & 7L) != 0) {
1663 kzalloc(((long_count + 7L) / 8L),
1665 if (charptr_tmp2 ==
NULL) {
1670 for (i = 0; i < long_count; ++
i) {
1671 if (charptr_tmp[k >> 3] &
1673 charptr_tmp2[i >> 3] |=
1676 charptr_tmp2[i >> 3] &=
1681 charptr_tmp = charptr_tmp2;
1683 }
else if (long_idx != 0)
1684 charptr_tmp = &charptr_tmp[long_idx >> 3];
1686 altera_export_bool_array(name, charptr_tmp,
1690 if ((long_idx & 7L) != 0)
1691 kfree(charptr_tmp2);
1709 int src_reverse = 0;
1710 int dest_reverse = 0;
1712 if (!altera_check_stack(stack_ptr, 3, &status))
1715 copy_count = stack[--stack_ptr];
1716 copy_index = stack[--stack_ptr];
1717 copy_index2 = stack[--stack_ptr];
1727 destleft = stack[--stack_ptr];
1729 if (copy_count > copy_index) {
1732 src_count = 1 + copy_count - copy_index;
1735 src_count = 1 + copy_index - copy_count;
1737 copy_index = copy_count;
1740 if (copy_index2 > destleft) {
1743 dest_count = 1 + copy_index2 - destleft;
1745 copy_index2 = destleft;
1747 dest_count = 1 + destleft - copy_index2;
1749 copy_count = (src_count < dest_count) ?
1750 src_count : dest_count;
1752 if ((src_reverse || dest_reverse) &&
1753 (src_count != dest_count))
1768 index2 = copy_index2;
1774 variable_id = args[1];
1775 if ((version > 0) &&
1776 ((attrs[variable_id] & 0x9c) == 0x0c)) {
1779 (var_size[variable_id] + 7L) >> 3L;
1780 charptr_tmp2 = (
u8 *)vars[variable_id];
1783 vars[variable_id] = (
long)charptr_tmp;
1785 if (vars[variable_id] == 0) {
1791 for (long_idx = 0L; long_idx < long_tmp;
1793 charptr_tmp[long_idx] = 0;
1797 long_idx < var_size[variable_id];
1799 long_idx2 = long_idx;
1801 if (charptr_tmp2[long_idx2 >> 3] &
1802 (1 << (long_idx2 & 7)))
1803 charptr_tmp[long_idx >> 3] |=
1804 (1 << (long_idx & 7));
1810 attrs[variable_id] |= 0x80;
1813 attrs[variable_id] &= ~0x04;
1814 attrs[variable_id] |= 0x01;
1817 charptr_tmp = (
u8 *)vars[args[1]];
1818 charptr_tmp2 = (
u8 *)vars[args[0]];
1821 if ((attrs[args[1]] & 0x1c) != 0x08) {
1832 index2 += (count - 1);
1834 for (i = 0; i <
count; ++
i) {
1835 if (charptr_tmp2[index >> 3] &
1837 charptr_tmp[index2 >> 3] |=
1838 (1 << (index2 & 7));
1840 charptr_tmp[index2 >> 3] &=
1841 ~(1 << (index2 & 7));
1863 s32 scan_right, scan_left;
1864 s32 capture_count = 0;
1869 if (!altera_check_stack(stack_ptr, 3, &status))
1872 capture_index = stack[--stack_ptr];
1873 scan_index = stack[--stack_ptr];
1883 scan_right = stack[--stack_ptr];
1884 scan_left = stack[--stack_ptr];
1885 capture_count = 1 + scan_index - capture_index;
1886 scan_count = 1 + scan_left - scan_right;
1887 scan_index = scan_right;
1890 long_count = stack[--stack_ptr];
1895 variable_id = args[1];
1896 if ((version > 0) &&
1897 ((attrs[variable_id] & 0x9c) == 0x0c)) {
1900 (var_size[variable_id] + 7L) >> 3L;
1901 charptr_tmp2 = (
u8 *)vars[variable_id];
1904 vars[variable_id] = (
long)charptr_tmp;
1906 if (vars[variable_id] == 0) {
1912 for (long_idx = 0L; long_idx < long_tmp;
1914 charptr_tmp[long_idx] = 0;
1918 long_idx < var_size[variable_id];
1920 long_idx2 = long_idx;
1922 if (charptr_tmp2[long_idx2 >> 3] &
1923 (1 << (long_idx2 & 7)))
1924 charptr_tmp[long_idx >> 3] |=
1925 (1 << (long_idx & 7));
1933 attrs[variable_id] |= 0x80;
1936 attrs[variable_id] &= ~0x04;
1937 attrs[variable_id] |= 0x01;
1941 charptr_tmp = (
u8 *)vars[args[0]];
1942 charptr_tmp2 = (
u8 *)vars[args[1]];
1944 if ((version > 0) &&
1945 ((long_count > capture_count) ||
1946 (long_count > scan_count))) {
1955 if ((attrs[args[1]] & 0x1c) != 0x08) {
1988 if (!altera_check_stack(stack_ptr, 2, &status))
1990 long_tmp = stack[--stack_ptr];
1996 long_tmp = stack[--stack_ptr];
1998 if ((status == 0) && (long_tmp != 0L))
2003 if ((status == 0) && (args[1] != args[0]))
2024 u8 *source1 = (
u8 *)vars[args[0]];
2025 u8 *source2 = (
u8 *)vars[args[1]];
2031 if (!altera_check_stack(stack_ptr, 4, &status))
2034 index1 = stack[--stack_ptr];
2035 index2 = stack[--stack_ptr];
2036 mask_index = stack[--stack_ptr];
2037 long_count = stack[--stack_ptr];
2048 s32 mask_right = stack[--stack_ptr];
2049 s32 mask_left = stack[--stack_ptr];
2051 a = 1 + index2 - index1;
2053 b = 1 + long_count - mask_index;
2054 a = (a <
b) ? a : b;
2056 b = 1 + mask_left - mask_right;
2057 a = (a <
b) ? a : b;
2059 index2 = mask_index;
2061 mask_index = mask_right;
2072 for (i = 0; i <
count; ++
i) {
2073 if (mask[mask_index >> 3] &
2074 (1 << (mask_index & 7))) {
2075 a = source1[index1 >> 3] &
2078 b = source2[index2 >> 3] &
2091 stack[stack_ptr++] = long_tmp;
2109 *error_address = (
s32)(opcode_address - code_sect);
2116 if ((attrs !=
NULL) && (vars !=
NULL))
2117 for (i = 0; i < sym_count; ++
i)
2118 if (attrs[i] & 0x80)
2119 kfree((
void *)vars[i]);
2124 kfree(proc_attributes);
2129 static int altera_get_note(
u8 *p,
s32 program_size,
2142 u32 note_strings = 0L;
2143 u32 note_table = 0L;
2144 u32 note_count = 0L;
2145 u32 first_word = 0L;
2153 if (program_size > 52L) {
2155 version = (first_word & 1L);
2156 delta = version * 8;
2163 if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L))
2166 if (note_count <= 0L)
2169 if (offset ==
NULL) {
2174 for (i = 0; (i < note_count) &&
2175 (status != 0); ++
i) {
2176 key_ptr = &p[note_strings +
2178 &p[note_table + (8 * i)])];
2183 value_ptr = &p[note_strings +
2185 &p[note_table + (8 * i) + 4])];
2188 strlcpy(value, value_ptr, length);
2200 if ((i >= 0) && (i < note_count)) {
2204 strlcpy(key, &p[note_strings +
2206 &p[note_table + (8 * i)])],
2210 strlcpy(value, &p[note_strings +
2212 &p[note_table + (8 * i) + 4])],
2222 static int altera_check_crc(
u8 *p,
s32 program_size)
2225 u16 local_expected = 0,
2231 u32 crc_section = 0L;
2232 u32 first_word = 0L;
2236 if (program_size > 52L) {
2238 version = (first_word & 1L);
2239 delta = version * 8;
2244 if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L))
2247 if (crc_section >= program_size)
2251 local_expected = (
u16)get_unaligned_be16(&p[crc_section]);
2253 for (i = 0; i < crc_section; ++
i) {
2255 for (bit = 0; bit < 8; bit++) {
2256 feedback = (databyte ^ shift_reg) & 0x01;
2259 shift_reg ^= 0x8408;
2265 local_actual = (
u16)~shift_reg;
2267 if (local_expected != local_actual)
2272 if (
debug || status) {
2280 "actual %04x\n", __func__, local_expected,
2285 "actual CRC = %04x\n", __func__,
2290 "recognized.\n", __func__);
2294 "code %d\n", __func__, status);
2302 static int altera_get_file_info(
u8 *p,
2304 int *format_version,
2306 int *procedure_count)
2312 if (program_size <= 52L)
2317 if ((first_word == 0x4A414D00L) || (first_word == 0x4A414D01L)) {
2320 version = (first_word & 1L);
2321 *format_version = version + 1;
2332 static int altera_get_act_info(
u8 *p,
2342 u32 first_word = 0L;
2343 u32 action_table = 0L;
2344 u32 proc_table = 0L;
2346 u32 note_strings = 0L;
2347 u32 action_count = 0L;
2348 u32 proc_count = 0L;
2349 u32 act_name_id = 0L;
2350 u32 act_desc_id = 0L;
2351 u32 act_proc_id = 0L;
2352 u32 act_proc_name = 0L;
2353 u8 act_proc_attribute = 0;
2355 if (program_size <= 52L)
2360 if (first_word != 0x4A414D01L)
2370 if (index >= action_count)
2377 *name = &p[str_table + act_name_id];
2379 if (act_desc_id < (note_strings - str_table))
2380 *description = &p[str_table + act_desc_id];
2384 &p[proc_table + (13 * act_proc_id)]);
2385 act_proc_attribute =
2386 (p[proc_table + (13 * act_proc_id) + 8] & 0x03);
2392 if (procptr ==
NULL)
2395 procptr->
name = &p[str_table + act_proc_name];
2396 procptr->
attrs = act_proc_attribute;
2400 if (*proc_list ==
NULL)
2401 *proc_list = procptr;
2403 tmpptr = *proc_list;
2405 tmpptr = tmpptr->
next;
2406 tmpptr->
next = procptr;
2411 &p[proc_table + (13 * act_proc_id) + 4]);
2412 }
while ((act_proc_id != 0) && (act_proc_id < proc_count));
2424 char *action_name =
NULL;
2425 char *description =
NULL;
2426 int exec_result = 0;
2428 int format_version = 0;
2429 int action_count = 0;
2430 int procedure_count = 0;
2433 s32 error_address = 0L;
2453 if (!astate->
config->jtag_io) {
2461 altera_get_file_info((
u8 *)fw->
data, fw->
size, &format_version,
2462 &action_count, &procedure_count);
2464 __func__, (format_version == 2) ?
"Jam STAPL" :
2465 "pre-standardized Jam 1.1");
2466 while (altera_get_note((
u8 *)fw->
data, fw->
size,
2467 &offset, key, value, 256) == 0)
2469 __func__, key, value);
2472 if (
debug && (format_version == 2) && (action_count > 0)) {
2474 for (index = 0; index < action_count; ++
index) {
2475 altera_get_act_info((
u8 *)fw->
data, fw->
size,
2476 index, &action_name,
2480 if (description ==
NULL)
2490 procptr = proc_list;
2491 while (procptr !=
NULL) {
2492 if (procptr->
attrs != 0)
2496 (procptr->
attrs == 1) ?
2497 "optional" :
"recommended");
2499 proc_list = procptr->
next;
2501 procptr = proc_list;
2508 exec_result = altera_execute(astate, (
u8 *)fw->
data, fw->
size,
2509 &error_address, &exit_code, &format_version);
2514 if ((format_version == 2) && (exec_result == -
EINVAL)) {
2517 "Jam STAPL file.\nprogram terminated.\n",
2521 " is not supported "
2522 "for this Jam STAPL file.\n"
2523 "Program terminated.\n", __func__,
2526 }
else if (exec_result)