annotate simtool/readef.c @ 171:4d747b86da00

simtool code: readef command implementation split off
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 03:03:49 +0000
parents simtool/readcmd.c@f1836c8d36cb
children e7e0d8c06654
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
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
13 cmd_readef(argc, argv, outf)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
15 FILE *outf;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int file_id, rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned readlen;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 file_id = strtoul(argv[1], 0, 16);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 file_id = find_symbolic_file_name(argv[1]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (file_id < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 "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
28 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = select_op(file_id);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rc = parse_ef_select_response();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (curfile_structure != 0x00) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 "error: readef command is only for transparent EFs\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
41 if (outf == stdout) {
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
42 printf("Transparent EF of %u byte(s)\n", curfile_total_size);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
43 printf("File status: %02X\n", sim_resp_data[11]);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
44 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
45 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
46 show_access_conditions("INCREASE", sim_resp_data[9] >> 4);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
47 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
48 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4);
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
49 }
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!curfile_total_size)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 readlen = curfile_total_size;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (readlen > 256)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 readlen = 256;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 rc = readbin_op(0, readlen);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(rc);
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
58 display_sim_resp_in_hex(outf);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }