FreeCalypso > hg > freecalypso-reveng
annotate frbl/test/frbl2.c @ 323:cefa700d1b8f
frbl: beginning of frbl2test
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 05 Mar 2020 22:05:01 +0000 |
parents | |
children | 43c92df87ac6 |
rev | line source |
---|---|
323
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdint.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdio.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdlib.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <string.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <strings.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <unistd.h> |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "srecreader.h" |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern char *target_ttydev; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern int target_fd; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern struct srecreader srimage; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #define MAX_IMAGE_LEN 32768 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static u_char codeimage[MAX_IMAGE_LEN]; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static unsigned codeimage_len; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static uint32_t loadaddr; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 read_srec_image() |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 u_char *writep; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 uint32_t endaddr; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int i; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (open_srec_file(&srimage) < 0) |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 for (;;) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (read_s_record(&srimage) < 0) |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 switch (srimage.record_type) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case '0': |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (srimage.lineno == 1) |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 continue; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 "%s: S0 record found in line %d (expected in line 1 only)\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case '3': |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 case '7': |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (s3s7_get_addr_data(&srimage) < 0) |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 break; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 default: |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 "%s line %d: S%c record type not supported\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 srimage.filename, srimage.lineno, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 srimage.record_type); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (srimage.record_type == '7') |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 break; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 /* must be S3 */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (srimage.datalen < 1) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 "%s line %d: S3 record has zero data length\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (srimage.datalen & 1) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 "%s line %d: S3 record has odd data length\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (srimage.addr & 1) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 "%s line %d: S3 record has odd address\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /* handle first record */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (!codeimage_len) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 endaddr = loadaddr = srimage.addr; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 writep = codeimage; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (srimage.addr != endaddr) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, "%s line %d: address discontinuity\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (codeimage_len + srimage.datalen > MAX_IMAGE_LEN) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 "%s line %d: max image length exceeded\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 /* reverse byte order */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 for (i = 0; i < srimage.datalen; i += 2) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *writep++ = srimage.record[i+6]; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 *writep++ = srimage.record[i+5]; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 endaddr += srimage.datalen; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 codeimage_len += srimage.datalen; |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 /* got S7 */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fclose(srimage.openfile); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (!codeimage_len) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 "%s line %d: S7 without any preceding S3 data records\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (srimage.addr != loadaddr) { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 fprintf(stderr, |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 "%s line %d: S7 address differs from image load address\n", |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 srimage.filename, srimage.lineno); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 exit(1); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 /* all good */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 return(0); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 frbl_test_main() |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 { |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 read_srec_image(); |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 /* remainder to be implemented */ |
cefa700d1b8f
frbl: beginning of frbl2test
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |