pc-bios/s390-ccw: cleanup and enhance bootmap defintions
[qemu/kevin.git] / pc-bios / s390-ccw / bootmap.h
blob59267b0db3394b568e05272c56bb33e9df6053da
1 /*
2 * QEMU S390 bootmap interpreter -- declarations
4 * Copyright 2014 IBM Corp.
5 * Author(s): Eugene (jno) Dvurechenski <jno@linux.vnet.ibm.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
9 * directory.
11 #ifndef _PC_BIOS_S390_CCW_BOOTMAP_H
12 #define _PC_BIOS_S390_CCW_BOOTMAP_H
14 #include "s390-ccw.h"
16 #define FREE_SPACE_FILLER '\xAA'
18 typedef struct ScsiBlockPtr {
19 uint64_t blockno;
20 uint16_t size;
21 uint16_t blockct;
22 uint8_t reserved[4];
23 } __attribute__ ((packed)) ScsiBlockPtr;
25 typedef struct FbaBlockPtr {
26 uint32_t blockno;
27 uint16_t size;
28 uint16_t blockct;
29 } __attribute__ ((packed)) FbaBlockPtr;
31 typedef struct EckdBlockPtr {
32 uint16_t cylinder; /* cylinder/head/sector is an address of the block */
33 uint16_t head;
34 uint8_t sector;
35 uint16_t size;
36 uint8_t count; /* (size_in_blocks-1);
37 * it's 0 for TablePtr, ScriptPtr, and SectionPtr */
38 } __attribute__ ((packed)) EckdBlockPtr;
40 typedef struct ExtEckdBlockPtr {
41 EckdBlockPtr bptr;
42 uint8_t reserved[8];
43 } __attribute__ ((packed)) ExtEckdBlockPtr;
45 typedef union BootMapPointer {
46 ScsiBlockPtr scsi;
47 FbaBlockPtr fba;
48 EckdBlockPtr eckd;
49 ExtEckdBlockPtr xeckd;
50 } __attribute__ ((packed)) BootMapPointer;
52 typedef struct ComponentEntry {
53 ScsiBlockPtr data;
54 uint8_t pad[7];
55 uint8_t component_type;
56 uint64_t load_address;
57 } __attribute((packed)) ComponentEntry;
59 typedef struct ComponentHeader {
60 uint8_t magic[4]; /* == "zIPL" */
61 uint8_t type; /* == ZIPL_COMP_HEADER_* */
62 uint8_t reserved[27];
63 } __attribute((packed)) ComponentHeader;
65 typedef struct ScsiMbr {
66 uint8_t magic[4];
67 uint32_t version_id;
68 uint8_t reserved[8];
69 ScsiBlockPtr blockptr;
70 } __attribute__ ((packed)) ScsiMbr;
72 #define ZIPL_MAGIC "zIPL"
73 #define IPL1_MAGIC "\xc9\xd7\xd3\xf1" /* == "IPL1" in EBCDIC */
74 #define IPL2_MAGIC "\xc9\xd7\xd3\xf2" /* == "IPL2" in EBCDIC */
75 #define VOL1_MAGIC "\xe5\xd6\xd3\xf1" /* == "VOL1" in EBCDIC */
76 #define LNX1_MAGIC "\xd3\xd5\xe7\xf1" /* == "LNX1" in EBCDIC */
77 #define CMS1_MAGIC "\xc3\xd4\xe2\xf1" /* == "CMS1" in EBCDIC */
79 #define LDL1_VERSION '\x40' /* == ' ' in EBCDIC */
80 #define LDL2_VERSION '\xf2' /* == '2' in EBCDIC */
82 #define ZIPL_COMP_HEADER_IPL 0x00
83 #define ZIPL_COMP_HEADER_DUMP 0x01
85 #define ZIPL_COMP_ENTRY_LOAD 0x02
86 #define ZIPL_COMP_ENTRY_EXEC 0x01
88 typedef struct XEckdMbr {
89 uint8_t magic[4]; /* == "xIPL" */
90 uint8_t version;
91 uint8_t bp_type;
92 uint8_t dev_type; /* == DEV_TYPE_* */
93 #define DEV_TYPE_ECKD 0x00
94 #define DEV_TYPE_FBA 0x01
95 uint8_t flags;
96 BootMapPointer blockptr;
97 uint8_t reserved[8];
98 } __attribute__ ((packed)) XEckdMbr; /* see also BootInfo */
100 typedef struct BootMapScriptEntry {
101 BootMapPointer blkptr;
102 uint8_t pad[7];
103 uint8_t type; /* == BOOT_SCRIPT_* */
104 #define BOOT_SCRIPT_EXEC 0x01
105 #define BOOT_SCRIPT_LOAD 0x02
106 union {
107 uint64_t load_address;
108 uint64_t load_psw;
109 } address;
110 } __attribute__ ((packed)) BootMapScriptEntry;
112 typedef struct BootMapScriptHeader {
113 uint32_t magic;
114 uint8_t type;
115 #define BOOT_SCRIPT_HDR_IPL 0x00
116 uint8_t reserved[27];
117 } __attribute__ ((packed)) BootMapScriptHeader;
119 typedef struct BootMapScript {
120 BootMapScriptHeader header;
121 BootMapScriptEntry entry[0];
122 } __attribute__ ((packed)) BootMapScript;
125 * These aren't real VTOCs, but referred to this way in some docs.
126 * They are "volume labels" actually.
128 * Some structures looks similar to described above, but left
129 * separate as there is no indication that they are the same.
130 * So, the value definitions are left separate too.
132 typedef struct LDL_VTOC { /* @ rec.3 cyl.0 trk.0 for ECKD */
133 char magic[4]; /* "LNX1", EBCDIC */
134 char volser[6]; /* volser, EBCDIC */
135 uint8_t reserved[69]; /* reserved, 0x40 */
136 uint8_t LDL_version; /* 0x40 or 0xF2 */
137 uint64_t formatted_blocks; /* if LDL_version >= 0xF2 */
138 } __attribute__ ((packed)) LDL_VTOC;
140 typedef struct format_date {
141 uint8_t YY;
142 uint8_t MM;
143 uint8_t DD;
144 uint8_t hh;
145 uint8_t mm;
146 uint8_t ss;
147 } __attribute__ ((packed)) format_date_t;
149 typedef struct CMS_VTOC { /* @ rec.3 cyl.0 trk.0 for ECKD */
150 /* @ blk.1 (zero based) for FBA */
151 char magic[4]; /* 'CMS1', EBCDIC */
152 char volser[6]; /* volser, EBCDIC */
153 uint16_t version; /* = 0 */
154 uint32_t block_size; /* = 512, 1024, 2048, or 4096 */
155 uint32_t disk_origin; /* = 4 or 5 */
156 uint32_t blocks; /* Number of usable cyls/blocks */
157 uint32_t formatted; /* Max number of fmtd cyls/blks */
158 uint32_t CMS_blocks; /* disk size in CMS blocks */
159 uint32_t CMS_used; /* Number of CMS blocks in use */
160 uint32_t FST_size; /* = 64, bytes */
161 uint32_t FST_per_CMS_blk; /* */
162 format_date_t format_date; /* YYMMDDhhmmss as 6 bytes */
163 uint8_t reserved1[2]; /* = 0 */
164 uint32_t offset; /* disk offset when reserved */
165 uint32_t next_hole; /* block nr */
166 uint32_t HBLK_hole_offset; /* >> HBLK data of next hole */
167 uint32_t alloc_map_usr_off; /* >> user part of Alloc map */
168 uint8_t reserved2[4]; /* = 0 */
169 char shared_seg_name[8]; /* */
170 } __attribute__ ((packed)) CMS_VTOC;
172 /* from zipl/include/boot.h */
173 typedef struct BootInfoBpIpl {
174 union {
175 ExtEckdBlockPtr eckd;
176 ScsiBlockPtr linr;
177 } bm_ptr;
178 uint8_t unused[16];
179 } __attribute__ ((packed)) BootInfoBpIpl;
181 typedef struct EckdDumpParam {
182 uint32_t start_blk;
183 uint32_t end_blk;
184 uint16_t blocksize;
185 uint8_t num_heads;
186 uint8_t bpt;
187 char reserved[4];
188 } __attribute((packed, may_alias)) EckdDumpParam;
190 typedef struct FbaDumpParam {
191 uint64_t start_blk;
192 uint64_t blockct;
193 } __attribute((packed)) FbaDumpParam;
195 typedef struct BootInfoBpDump {
196 union {
197 EckdDumpParam eckd;
198 FbaDumpParam fba;
199 } param;
200 uint8_t unused[16];
201 } __attribute__ ((packed)) BootInfoBpDump;
203 typedef struct BootInfo { /* @ 0x70, record #0 */
204 unsigned char magic[4]; /* = 'zIPL', ASCII */
205 uint8_t version; /* = 1 */
206 #define BOOT_INFO_VERSION 1
207 uint8_t bp_type; /* = 0 */
208 #define BOOT_INFO_BP_TYPE_IPL 0x00
209 #define BOOT_INFO_BP_TYPE_DUMP 0x01
210 uint8_t dev_type; /* = 0 */
211 #define BOOT_INFO_DEV_TYPE_ECKD 0x00
212 #define BOOT_INFO_DEV_TYPE_FBA 0x01
213 uint8_t flags; /* = 1 */
214 #ifdef __s390x__
215 #define BOOT_INFO_FLAGS_ARCH 0x01
216 #else
217 #define BOOT_INFO_FLAGS_ARCH 0x00
218 #endif
219 union {
220 BootInfoBpDump dump;
221 BootInfoBpIpl ipl;
222 } bp;
223 } __attribute__ ((packed)) BootInfo; /* see also XEckdMbr */
225 typedef struct Ipl1 {
226 unsigned char key[4]; /* == "IPL1" */
227 unsigned char data[24];
228 } __attribute__((packed)) Ipl1;
230 typedef struct Ipl2 {
231 unsigned char key[4]; /* == "IPL2" */
232 union {
233 unsigned char data[144];
234 struct {
235 unsigned char reserved1[92-4];
236 XEckdMbr mbr;
237 unsigned char reserved2[144-(92-4)-sizeof(XEckdMbr)];
238 } x;
239 } u;
240 } __attribute__((packed)) Ipl2;
242 typedef struct IplVolumeLabel {
243 unsigned char key[4]; /* == "VOL1" */
244 union {
245 unsigned char data[80];
246 struct {
247 unsigned char key[4]; /* == "VOL1" */
248 unsigned char volser[6];
249 unsigned char reserved[6];
250 } f;
252 } __attribute__((packed)) IplVolumeLabel;
254 #endif /* _PC_BIOS_S390_CCW_BOOTMAP_H */