annotate simtool/readef.c @ 189:123dc7370581

top Makefile: install scripts
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 06 Mar 2021 21:11:21 +0000
parents e70964adcbba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
1 /*
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
2 * This module implements the readef command for dumping the complete
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
3 * content of SIM files.
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
4 */
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
5
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
15
5390dce9faa4 simtool/readcmd.c: missed #include <ctype.h>
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
7 #include <ctype.h>
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "simresp.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "curfile.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
173
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
13 static void
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
14 hexdump_with_offset(outf, extoff)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
15 FILE *outf;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
16 unsigned extoff;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
17 {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
18 unsigned off, cc, n, c;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
19
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
20 for (off = 0; off < sim_resp_data_len; off += cc) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
21 fprintf(outf, "%04X:", extoff + off);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
22 cc = 16;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
23 if (sim_resp_data_len - off < cc)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
24 cc = sim_resp_data_len - off;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
25 for (n = 0; n < 16; n++) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
26 if (n == 0 || n == 8)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
27 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
28 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
29 if (n < cc)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
30 fprintf(outf, "%02X", sim_resp_data[off + n]);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
31 else {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
32 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
33 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
34 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
35 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
36 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
37 putc(' ', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
38 for (n = 0; n < cc; n++) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
39 c = sim_resp_data[off + n];
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
40 if (c < 0x20 || c > 0x7E)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
41 c = '.';
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
42 putc(c, outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
43 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
44 putc('\n', outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
45 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
46 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
47
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
48 static
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
49 readef_transparent(outf)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
50 FILE *outf;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
51 {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
52 unsigned off, cc;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
53 int rc;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
54
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
55 for (off = 0; off < curfile_total_size; off += cc) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
56 cc = curfile_total_size - off;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
57 if (cc > 256)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
58 cc = 256;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
59 rc = readbin_op(off, cc);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
60 if (rc < 0)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
61 return(rc);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
62 hexdump_with_offset(outf, off);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
63 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
64 return(0);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
65 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
66
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
67 static
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
68 readef_records(outf)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
69 FILE *outf;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
70 {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
71 unsigned recno;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
72 int rc;
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
73
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
74 for (recno = 1; recno <= curfile_record_count; recno++) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
75 fprintf(outf, "Record #%u:\n", recno);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
76 rc = readrec_op(recno, 0x04, curfile_record_len);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
77 if (rc < 0)
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
78 return(rc);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
79 display_sim_resp_in_hex(outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
80 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
81 return(0);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
82 }
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
83
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
84 cmd_readef(argc, argv, outf)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 char **argv;
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
86 FILE *outf;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 int file_id, rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 unsigned readlen;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 file_id = strtoul(argv[1], 0, 16);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 file_id = find_symbolic_file_name(argv[1]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (file_id < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 "error: file ID argument is not a hex value or a recognized symbolic name\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 rc = select_op(file_id);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 rc = parse_ef_select_response();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return(rc);
172
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
107 show_access_conditions(outf, "UPDATE", sim_resp_data[8] & 0xF);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
108 show_access_conditions(outf, "READ & SEEK", sim_resp_data[8] >> 4);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
109 show_access_conditions(outf, "INCREASE", sim_resp_data[9] >> 4);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
110 show_access_conditions(outf, "INVALIDATE", sim_resp_data[10] & 0xF);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
111 show_access_conditions(outf, "REHABILITATE", sim_resp_data[10] >> 4);
173
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
112 fprintf(outf, "File status: %02X\n", sim_resp_data[11]);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
113 switch (curfile_structure) {
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
114 case 0x00:
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
115 fprintf(outf, "Transparent EF of %u byte(s)\n",
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
116 curfile_total_size);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
117 return readef_transparent(outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
118 case 0x01:
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
119 fprintf(outf, "%u records of %u bytes (linear fixed)\n",
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
120 curfile_record_count, curfile_record_len);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
121 return readef_records(outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
122 case 0x03:
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
123 fprintf(outf, "%u records of %u bytes (cyclic)\n",
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
124 curfile_record_count, curfile_record_len);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
125 return readef_records(outf);
e70964adcbba fc-simtool readef extended to fully dump all files
Mychaela Falconia <falcon@freecalypso.org>
parents: 172
diff changeset
126 }
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }