convert gitignore files to hgignore files
[hvf.git] / installer / loader.h
blobeddca6e9bc8d9f076c8b5cc58f06caaf0fc2bf06
1 #ifndef __LOADER_H
2 #define __LOADER_H
4 #include <errno.h>
6 /*
7 * "Config" values
8 */
9 #define TEMP_BASE ((unsigned char*) 0x200000) /* 2MB */
11 #define CON_DEVNUM 0x0009
13 /* 3390 with 0 key length, and 4096 data length */
14 #define RECORDS_PER_CYL (15*12)
15 #define RECORDS_PER_TRACK 12
17 /* the nucleus fn ft (in EBCDIC) => HVF ELF */
18 #define CP_FN "\xC8\xE5\xC6\x40\x40\x40\x40\x40"
19 #define CP_FT "\xC5\xD3\xC6\x40\x40\x40\x40\x40"
21 static inline int strlen(char *p)
23 int i;
25 for(i=0;*p; p++, i++)
28 return i;
32 * halt the cpu
34 * NOTE: we don't care about not clobbering registers as when this
35 * code executes, the CPU will be stopped.
37 static inline void die(void)
39 asm volatile(
40 "SR %r1, %r1 # not used, but should be zero\n"
41 "SR %r3, %r3 # CPU Address\n"
42 "SIGP %r1, %r3, 0x05 # Signal, order 0x05\n"
46 * Just in case SIGP fails
48 for(;;);
52 * I/O related structs, macros & variables
54 struct ccw {
55 u8 cmd; /* Command code */
56 u8 flags; /* Flags */
57 u16 count; /* Count */
58 u32 addr; /* Data Address */
59 } __attribute__((packed,aligned(8)));
61 #define CCW_FLAG_CD 0x80 /* Chain-Data */
62 #define CCW_FLAG_CC 0x40 /* Chain-Command */
63 #define CCW_FLAG_SLI 0x20 /* Suppress-Length-Indication */
64 #define CCW_FLAG_SKP 0x10 /* Skip */
65 #define CCW_FLAG_PCI 0x08 /* Program-Controlled-Interruption */
66 #define CCW_FLAG_IDA 0x04 /* Indirect-Data-Address */
67 #define CCW_FLAG_S 0x02 /* Suspend */
68 #define CCW_FLAG_MIDA 0x01 /* Modified-Indirect-Data-Address */
70 struct orb {
71 /* word 0 */
72 u32 param; /* Interruption Parameter */
74 /* word 1 */
75 u8 key:4, /* Subchannel Key */
76 s:1, /* Suspend */
77 c:1, /* Streaming-Mode Control */
78 m:1, /* Modification Control */
79 y:1; /* Synchronization Control */
80 u8 f:1, /* Format Control */
81 p:1, /* Prefetch Control */
82 i:1, /* Initial-Status-Interruption Control */
83 a:1, /* Address-Limit-Checking control */
84 u:1, /* Suppress-Suspend-Interruption Control */
85 __zero1:1,
86 h:1, /* Format-2-IDAW Control */
87 t:1; /* 2K-IDAW Control */
88 u8 lpm; /* Logical-Path Mask */
89 u8 l:1, /* Incorrect-Length-Suppression Mode */
90 d:1, /* Modified-CCW-Indirect-Data-Addressing Control */
91 __zero2:5,
92 x:1; /* ORB-Extension Control */
94 /* word 2 */
95 u32 addr; /* Channel-Program Address */
97 /* word 3 */
98 u8 css_prio; /* Channel-Subsystem Priority */
99 u8 __reserved1;
100 u8 cu_prio; /* Control-Unit Priority */
101 u8 __reserved2;
103 /* word 4 - 7 */
104 u32 __reserved3;
105 u32 __reserved4;
106 u32 __reserved5;
107 u32 __reserved6;
108 } __attribute__((packed,aligned(4)));
110 struct scsw {
111 /* word 0 */
112 u16 key:4, /* Subchannel key */
113 s:1, /* Suspend control */
114 l:1, /* ESW format */
115 cc:2, /* Deferred condition code */
116 f:1, /* Format */
117 p:1, /* Prefetch */
118 i:1, /* Initial-status interruption control */
119 a:1, /* Address-limit-checking control */
120 u:1, /* Supress-suspended interruption */
121 z:1, /* Zero condition code */
122 e:1, /* Extended control */
123 n:1; /* Path no operational */
124 u16 __zero:1,
125 fc:3, /* Function control */
126 ac:8, /* Activity control */
127 sc:4; /* Status control */
129 /* word 1 */
130 u32 addr; /* CCW Address */
132 /* word 2 */
133 u8 dev_status; /* Device status */
134 u8 sch_status; /* Subchannel status */
135 u16 count; /* Count */
136 } __attribute__((packed));
138 /* Path Management Control Word */
139 struct pmcw {
140 /* word 0 */
141 u32 interrupt_param; /* Interruption Parameter */
143 /* word 1*/
144 u8 __zero1:2,
145 isc:3, /* I/O-Interruption-Subclass Code */
146 __zero2:3;
147 u8 e:1, /* Enabled */
148 lm:2, /* Limit Mode */
149 mm:2, /* Measurement-Mode Enable */
150 d:1, /* Multipath Mode */
151 t:1, /* Timing Facility */
152 v:1; /* Device Number Valid */
153 u16 dev_num; /* Device Number */
155 /* word 2 */
156 u8 lpm; /* Logical-Path Mask */
157 u8 pnom; /* Path-Not-Operational Mask */
158 u8 lpum; /* Last-Path-Used Mask */
159 u8 pim; /* Path-Installed Mask */
161 /* word 3 */
162 u16 mbi; /* Measurement-Block Index */
163 u8 pom; /* Path-Operational Mask */
164 u8 pam; /* Path-Available Mask */
166 /* word 4 & 5 */
167 u8 chpid[8]; /* Channel-Path Identifiers */
169 /* word 6 */
170 u16 __zero3;
171 u16 __zero4:13,
172 f:1, /* Measurement Block Format Control */
173 x:1, /* Extended Measurement Word Mode Enable */
174 s:1; /* Concurrent Sense */
177 struct schib {
178 struct pmcw pmcw; /* Path Management Control Word */
179 struct scsw scsw; /* Subchannel Status Word */
180 u32 w0, w1;
181 u32 model_dep_area;
182 } __attribute__((packed,aligned(4)));
184 #define ADDR31(x) ((u32) (u64) (x))
186 extern void wto(char *str);
187 extern void wtor(char *str, char *inp, int buflen);
188 extern void __readwrite_blk(void *ptr, u32 lba, int rwccw);
189 #define read_blk(ptr, lba) __readwrite_blk((ptr), (lba), 0x86)
190 #define write_blk(ptr, lba) __readwrite_blk((ptr), (lba), 0x05)
192 extern int __do_io(u32 sch);
193 extern void __wait_for_attn();
194 extern void PGMHANDLER();
195 extern void IOHANDLER();
197 extern void load_nucleus(void);
199 extern struct orb ORB;
201 extern u64 ipl_sch;
202 extern u64 con_sch;
203 extern u64 dasd_sch;
205 static inline int store_sch(u32 sch, struct schib *schib)
207 int cc;
209 asm volatile(
210 "lr %%r1,%2\n"
211 "stsch %1\n"
212 "ipm %0\n"
213 "srl %0,28\n"
214 : /* output */
215 "=d" (cc),
216 "=Q" (*schib)
217 : /* input */
218 "d" (sch)
219 : /* clobbered */
220 "cc", "r1", "memory"
223 if (cc == 3)
224 return -EINVAL;
225 return 0;
228 static inline int modify_sch(u32 sch, struct schib *schib)
230 int cc;
232 asm volatile(
233 "lr %%r1,%1\n"
234 "msch %2\n"
235 "ipm %0\n"
236 "srl %0,28\n"
237 : /* output */
238 "=d" (cc)
239 : /* input */
240 "d" (sch),
241 "m" (*schib)
242 : /* clobbered */
243 "cc", "r1"
246 if (cc == 1 || cc == 2)
247 return -EBUSY;
248 if (cc == 3)
249 return -EINVAL;
250 return 0;
253 extern void unload_archive(void);
256 * EDF related structs & macros
258 #define EDF_LABEL_BLOCK_NO 3
259 #define EDF_SUPPORTED_BLOCK_SIZE 4096
261 struct ADT {
262 u32 IDENT; /* VOL START / LABEL IDENTIFIER */
263 #define __ADTIDENT 0xC3D4E2F1 /* 'CMS1' in EBCDIC */
264 u8 ID[6]; /* VOL START / VOL IDENTIFIER */
265 u8 VER[2]; /* VERSION LEVEL */
266 u32 DBSIZ; /* DISK BLOCK SIZE */
267 u32 DOP; /* DISK ORIGIN POINTER */
268 u32 CYL; /* NUM OF FORMATTED CYL ON DISK */
269 u32 MCYL; /* MAX NUM FORMATTED CYL ON DISK */
270 u32 NUM; /* Number of Blocks on disk */
271 u32 USED; /* Number of Blocks used */
272 u32 FSTSZ; /* SIZE OF FST */
273 u32 NFST; /* NUMBER OF FST'S PER BLOCK */
274 u8 DCRED[6]; /* DISK CREATION DATE (YYMMDDHHMMSS) */
275 u8 FLGL; /* LABEL FLAG BYTE (ADTFLGL) */
276 #define ADTCNTRY 0x01 /* Century for disk creation date (0=19, 1=20),
277 * corresponds to ADTDCRED. */
278 u8 reserved[1];
279 u32 OFFST; /* DISK OFFSET WHEN RESERVED */
280 u32 AMNB; /* ALLOC MAP BLOCK WITH NEXT HOLE */
281 u32 AMND; /* DISP INTO HBLK DATA OF NEXT HOLE */
282 u32 AMUP; /* DISP INTO USER PART OF ALLOC MAP */
283 u32 OFCNT; /* Count of SFS open files for this ADT */
284 u8 SFNAM[8]; /* NAME OF SHARED SEGMENT */
287 struct FST {
288 u8 FNAME[8]; /* filename */
289 u8 FTYPE[8]; /* filetype */
290 u8 DATEW[2]; /* DATE LAST WRITTEN - MMDD */
291 u8 TIMEW[2]; /* TIME LAST WRITTEN - HHMM */
292 u16 WRPNT; /* WRITE POINTER - ITEM NUMBER */
293 u16 RDPNT; /* READ POINTER - ITEM NUMBER */
294 u8 FMODE[2]; /* FILE MODE - LETTER AND NUMBER */
295 u16 RECCT; /* NUMBER OF LOGICAL RECORDS */
296 u16 FCLPT; /* FIRST CHAIN LINK POINTER */
297 u8 RECFM; /* F*1 - RECORD FORMAT - F OR V */
298 #define FSTDFIX 0xC6 /* Fixed record format (EBCDIC 'F') */
299 #define FSTDVAR 0xE5 /* Variable record format (EBCDIC 'V') */
300 u8 FLAGS; /* F*2 - FST FLAG BYTE */
301 #define FSTRWDSK 0x80 /* READ/WRITE DISK */
302 #define FSTRODSK 0x00 /* READ/ONLY DISK */
303 #define FSTDSFS 0x10 /* Shared File FST */
304 #define FSTXRDSK 0x40 /* EXTENSION OF R/O DISK */
305 #define FSTXWDSK 0xC0 /* EXTENSION OF R/W DISK */
306 #define FSTEPL 0x20 /* EXTENDED PLIST */
307 #define FSTDIA 0x40 /* ITEM AVAILABLE */
308 #define FSTDRA 0x01 /* PREVIOUS RECORD NULL */
309 #define FSTCNTRY 0x08 /* Century for date last written (0=19, 1=20),\\
310 corresponds to FSTYEARW, FSTADATI. */
311 #define FSTACTRD 0x04 /* ACTIVE FOR READING */
312 #define FSTACTWR 0x02 /* ACTIVE FOR WRITING */
313 #define FSTACTPT 0x01 /* ACTIVE FROM A POINT */
314 #define FSTFILEA 0x07 /* THE FILE IS ACTIVE */
315 u32 LRECL; /* LOGICAL RECORD LENGTH */
316 u16 BLKCT; /* NUMBER OF 800 BYTE BLOCKS */
317 u16 YEARW; /* YEAR LAST WRITTEN */
318 u32 FOP; /* ALT. FILE ORIGIN POINTER */
319 u32 ADBC; /* ALT. NUMBER OF DATA BLOCKS */
320 u32 AIC; /* ALT. ITEM COUNT */
321 u8 NLVL; /* NUMBER OF POINTER BLOCK LEVELS */
322 u8 PTRSZ; /* LENGTH OF A POINTER ELEMENT */
323 u8 ADATI[6]; /* ALT. DATE/TIME(YY MM DD HH MM SS) */
324 u8 REALM; /* Real filemode */
325 u8 FLAG2; /* F*3 - FST FLAG BYTE 2 FSTFLAG2 */
326 #define FSTPIPEU 0x10 /* Reserved for CMS PIPELINES usage */
327 u8 reserved[2];
330 extern void init_malloc(void *ptr);
331 extern void *malloc(u32 size);
333 extern void mount_fs();
334 extern int find_file(char *fn, char *ft, struct FST *fst);
335 extern int create_file(char *fn, char *ft, int lrecl, struct FST *fst);
336 extern void append_record(struct FST *fst, u8 *buf);
338 extern void writeback_buffers();
340 #endif