cp: sched.h accumulated tons of structs that belong into vcpu.h
[hvf.git] / build / ccw_gen.c
blob8452c0986cf8373f6960e5432e50d626ee4605db
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 static char *deck_head =
6 "#\n"
7 "# NOTE: This file was automatically generated by " __FILE__ "\n"
8 "#\n"
9 "# During the system IPL, 24 bytes are read from the device.\n"
10 "#\n"
11 "# NOTE: zArch IPLs in ESA/390 mode.\n"
12 "#\n";
14 static char *card_head =
15 "\n"
16 "#######################################################################\n"
17 "# CARD %-3d #\n"
18 "#######################################################################\n";
20 static char *psw_head =
21 "#\n"
22 "# Bytes 0-7 contain PSW to be loaded after IO operation completes\n"
23 "#\n";
25 static char *psw =
26 " .byte 0x%c%c\n"
27 " # bits value name desc\n"
28 " # 0 0 <zero>\n"
29 " # 1 0 PER Mask (R) disabled\n"
30 " # 2-4 0 <zero>\n"
31 " # 5 0 DAT Mode (T) disabled\n"
32 " # 6 0 I/O Mask (IO) disabled\n"
33 " # 7 0 External Mask (EX) disabled\n"
34 "\n"
35 " .byte 0x%c%c\n"
36 " # bits value name desc\n"
37 " # 8-11 0 Key\n"
38 " # 12 1 <one>\n"
39 " # 13 0 Machine-Check Mask (M) disabled\n"
40 " # 14 0 Wait State (W) executing\n"
41 " # 15 0 Problem State (P) supervisor state\n"
42 "\n"
43 " .byte 0x%c%c\n"
44 " # bits value name desc\n"
45 " # 16-17 0 Address-Space Control (AS) disabled\n"
46 " # 18-19 0 Condition Code (CC)\n"
47 " # 20-23 0 Program Mask exceptions disabled\n"
48 "\n"
49 " .byte 0x%c%c\n"
50 " # bits value name desc\n"
51 " # 24-30 0 <zero>\n"
52 " # 31 0 Extended Addressing (EA) ! 64 mode\n"
53 "\n"
54 " .byte 0x%c%c # bits 32-39\n"
55 " .byte 0x%c%c # bits 40-47\n"
56 " .byte 0x%c%c # bits 48-55\n"
57 " .byte 0x%c%c # bits 56-63\n"
58 " # bits value name desc\n"
59 " # 32 1 Basic Addressing (BA) BA = 31, !BA = 24\n"
60 " # 33-63 addr Instruction Address Address to exec\n";
62 static char *psw_tail =
63 "\n"
64 "#\n"
65 "# The remaining 16 bytes should contain CCW to read data from device\n"
66 "#\n"
67 "\n"
68 "# CCW format-0:\n"
69 "# bits name\n"
70 "# 0-7 Cmd Code\n"
71 "# 8-31 Data Address\n"
72 "# 32 Chain-Data (CD)\n"
73 "# 33 Chain-Command (CC)\n"
74 "# 34 Sup.-Len.-Inditcation (SLI)\n"
75 "# 35 Skip (SKP)\n"
76 "# 36 Prog.-Contr.-Inter. (PCI)\n"
77 "# 37 Indir.-Data-Addr. (IDA)\n"
78 "# 38 Suspend (S)\n"
79 "# 39 Modified I.D.A. (MIDA)\n"
80 "# 40-47 <ignored>\n"
81 "# 48-63 number of bytes to read\n"
82 "\n"
83 "# CP-CCW 1\n"
84 " # READ 80 bytes of CCWs to 0x%06X\n"
85 " .byte 0x02, 0x%02X, 0x%02X, 0x%02X\n"
86 " .byte 0x%02X, 0x00, 0x00, 0x50\n"
87 "\n"
88 "# CP-CCW 2\n"
89 " # TIC to 0x%06X\n"
90 " .byte 0x08, 0x%02X, 0x%02X, 0x%02X\n"
91 " .byte 0x00, 0x00, 0x00, 0x00\n";
93 static char *pad =
94 "\n"
95 "#\n"
96 "# Pad to 80 bytes\n"
97 "#\n"
98 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
99 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
100 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
101 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
102 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
103 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n"
104 " .byte 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40\n";
106 static char *cp_ccw =
107 "\n"
108 "# CP-CCW %d\n"
109 " .byte 0x02, 0x%02X, 0x%02X, 0x%02X\n"
110 " .byte 0x40, 0x00, 0x00, 0x50\n";
112 #define CHAIN 0x40
114 static char *data_ccw =
115 "\n"
116 "# LOADER-CCW %d\n"
117 " .byte 0x02, 0x%02X, 0x%02X, 0x%02X\n"
118 " .byte 0x%02X, 0x00, 0x00, 0x50\n";
120 static char *nop_ccw =
121 "\n"
122 "# NOP-CCW %d\n"
123 " .byte 0x03, 0x00, 0x00, 0x08\n"
124 " .byte 0x60, 0x00, 0x00, 0x01\n";
126 #define ADDR(x) (((x)[0]<<16) | \
127 ((x)[1]<<8) | \
128 ((x)[2]))
130 #define ADDRS(x) (x)[0], (x)[1], (x)[2]
132 static void die(char *pgm, char *s)
134 fprintf(stderr, "Error: %s\n", s);
135 fprintf(stderr, "Usage: %s <psw word 1> <psw word 2> <file size> "
136 "<address> <channel pgm addr>\n", pgm);
137 exit(1);
140 static unsigned int unhex(char *pgm, char c)
142 if ((c >= '0') && (c <= '9'))
143 return c - '0';
144 if ((c >= 'A') && (c <= 'F'))
145 return c - 'A' + 10;
146 if ((c >= 'a') && (c <= 'f'))
147 return c - 'a' + 10;
148 die(pgm, "Argument not hexadecimal");
149 return 0;
152 static void __add(unsigned int *addr, int a)
154 int i;
156 addr[2] += a;
157 for(i=2; i>=0; i--) {
158 if (addr[i] > 255) {
159 addr[i-1] += addr[i] / 256;
160 addr[i] %= 256;
165 int main(int argc, char **argv)
167 int i = 1, j;
168 unsigned int card;
169 unsigned int ccw_addr[3];
170 unsigned int addr[3];
171 unsigned int size;
172 unsigned int data_cards;
174 if (argc != 6)
175 die(argv[0], "Invalid number of args");
177 if ((strlen(argv[1]) != 8) ||
178 (strlen(argv[2]) != 8))
179 die(argv[0], "Invalid PSW argument length");
181 size = atol(argv[3]);
182 if (!size)
183 die(argv[0], "Invalid file size");
185 if ((strlen(argv[4]) != 6) ||
186 (strlen(argv[5]) != 6))
187 die(argv[0], "Invalid addr argument length");
189 addr[0] = (unhex(argv[0], argv[4][0]) << 4) |
190 unhex(argv[0], argv[4][1]);
191 addr[1] = (unhex(argv[0], argv[4][2]) << 4) |
192 unhex(argv[0], argv[4][3]);
193 addr[2] = (unhex(argv[0], argv[4][4]) << 4) |
194 unhex(argv[0], argv[4][5]);
196 ccw_addr[0] = (unhex(argv[0], argv[5][0]) << 4) |
197 unhex(argv[0], argv[5][1]);
198 ccw_addr[1] = (unhex(argv[0], argv[5][2]) << 4) |
199 unhex(argv[0], argv[5][3]);
200 ccw_addr[2] = (unhex(argv[0], argv[5][4]) << 4) |
201 unhex(argv[0], argv[5][5]);
203 /* round up */
204 if (size % 80)
205 size = size - (size % 80) + 80;
207 data_cards = size / 80;
209 printf(deck_head);
211 printf(card_head, i);
212 printf(psw_head);
213 printf(psw,
214 argv[1][0], argv[1][1], argv[1][2], argv[1][3],
215 argv[1][4], argv[1][5], argv[1][6], argv[1][7],
216 argv[2][0], argv[2][1], argv[2][2], argv[2][3],
217 argv[2][4], argv[2][5], argv[2][6], argv[2][7]);
219 if (data_cards == 1)
220 die(argv[0], "Cannot handle the case where size <= 80");
222 card = 2;
223 i = 0;
224 j = 1;
226 printf(psw_tail, ADDR(ccw_addr), ADDRS(ccw_addr), CHAIN,
227 ADDR(ccw_addr), ADDRS(ccw_addr));
228 printf(pad);
229 __add(ccw_addr, 80);
231 for(i=0; i<=((data_cards+9)/10) + (((data_cards+9)/10)+9)/10 - 2; i++) {
232 printf(cp_ccw, i+3, ADDRS(ccw_addr));
233 __add(ccw_addr, 80);
236 while (i % 10) {
237 printf(nop_ccw, i);
238 i++;
241 for(i=1; i<=data_cards; i++) {
242 printf(data_ccw, i, ADDRS(addr),
243 (i == data_cards) ? 0 : CHAIN);
245 __add(addr, 80);
248 return 0;
250 printf(card_head, card++);
251 return 0;