annotate rvinterf/tmsh/abbtm3.c @ 465:003e48f8ebe1

rvinterf/etmsync/fsnew.c: cast 0 to (char *) for execl sentinel I generally don't use NULL and use plain 0 instead, based on a "NULL considered harmful" discussion on the classiccmp mailing list many aeons ago (I couldn't find it, and I reason that it must have been 2005 or earlier), but a recent complaint by a packager sent me searching, and I found this: https://ewontfix.com/11/ While I don't give a @#$% about "modern" systems and code-nazi tools, I realized that passing a plain 0 as a pointer sentinel in execl is wrong because it will break on systems where pointers are longer than the plain int type. Again, I don't give a @#$% about the abomination of x86_64 and the like, but if anyone ever manages to port my code to something like a PDP-11 (16-bit int, 32-bit long and pointers), then passing a plain 0 as a function argument where a pointer is expected most definitely won't work: if the most natural stack slot and SP alignment unit is 16 bits, fitting an int, with longs and pointers taking up two such slots, then the call stack will be totally wrong with a plain 0 passed for a pointer. Casting the 0 to (char *) ought to be the most kosher solution for the most retro systems possible.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Feb 2019 00:00:19 +0000
parents 74b9aeb25d79
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Old TM3 versions of ABB register read and write commands
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "pktmux.h"
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "limits.h"
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "localtypes.h"
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "tm3.h"
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "exitcodes.h"
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern u_char rvi_msg[];
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int rvi_msg_len;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
151
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
19 void
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
20 handle_oabbr_response()
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
21 {
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
22 char buf[80];
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
23 unsigned val;
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
24
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
25 if (rvi_msg[3]) {
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
26 if (rvi_msg_len == 5) {
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
27 sprintf(buf, "oabbr error %u (0x%02X)",
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
28 rvi_msg[3], rvi_msg[3]);
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
29 async_msg_output(buf);
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
30 } else
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
31 print_etm_pkt_raw("oabbr long error response");
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
32 return;
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
33 }
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
34 if (rvi_msg_len != 7) {
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
35 print_etm_pkt_raw("oabbr response wrong length");
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
36 return;
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
37 }
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
38 val = rvi_msg[4] | (rvi_msg[5] << 8);
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
39 sprintf(buf, "oabbr: %04X", val);
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
40 async_msg_output(buf);
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
41 }
74b9aeb25d79 fc-tmsh: oabbr and oabbw response handling implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 150
diff changeset
42
150
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 cmd_oabbr(argc, argv)
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 char **argv;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 u32 page, reg;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 u_char cmdpkt[5];
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 page = strtoul(argv[1], 0, 0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 reg = strtoul(argv[2], 0, 0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (page > 1 || reg > 31) {
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 printf("error: argument(s) out of range\n");
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(ERROR_USAGE);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 cmdpkt[1] = CODEC_READ;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 cmdpkt[2] = page << 5 | reg;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 cmdpkt[3] = 0;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 send_etm_cmd(cmdpkt, 3);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 cmd_oabbw(argc, argv)
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 char **argv;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 {
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 u32 page, reg, val;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 u_char cmdpkt[7];
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 page = strtoul(argv[1], 0, 0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 reg = strtoul(argv[2], 0, 0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 val = strtoul(argv[3], 0, 16);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (page > 1 || reg > 31 || val > 0x3FF) {
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 printf("error: argument(s) out of range\n");
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return(ERROR_USAGE);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 cmdpkt[1] = CODEC_WRITE;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 cmdpkt[2] = page << 5 | reg;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 cmdpkt[3] = 0;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 cmdpkt[4] = val;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 cmdpkt[5] = val >> 8;
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 send_etm_cmd(cmdpkt, 5);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return(0);
45d8c175f9b5 fc-tmsh: oabbr and oabbw command sending implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }