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
11 #ifndef _PC_BIOS_S390_CCW_BOOTMAP_H
12 #define _PC_BIOS_S390_CCW_BOOTMAP_H
17 typedef uint64_t block_number_t
;
18 #define NULL_BLOCK_NR 0xffffffffffffffffULL
20 #define FREE_SPACE_FILLER '\xAA'
22 typedef struct ScsiBlockPtr
{
27 } __attribute__ ((packed
)) ScsiBlockPtr
;
29 typedef struct FbaBlockPtr
{
33 } __attribute__ ((packed
)) FbaBlockPtr
;
35 typedef struct EckdBlockPtr
{
36 uint16_t cylinder
; /* cylinder/head/sector is an address of the block */
40 uint8_t count
; /* (size_in_blocks-1);
41 * it's 0 for TablePtr, ScriptPtr, and SectionPtr */
42 } __attribute__ ((packed
)) EckdBlockPtr
;
44 typedef struct ExtEckdBlockPtr
{
47 } __attribute__ ((packed
)) ExtEckdBlockPtr
;
49 typedef union BootMapPointer
{
53 ExtEckdBlockPtr xeckd
;
54 } __attribute__ ((packed
)) BootMapPointer
;
56 typedef struct ComponentEntry
{
59 uint8_t component_type
;
60 uint64_t load_address
;
61 } __attribute((packed
)) ComponentEntry
;
63 typedef struct ComponentHeader
{
64 uint8_t magic
[4]; /* == "zIPL" */
65 uint8_t type
; /* == ZIPL_COMP_HEADER_* */
67 } __attribute((packed
)) ComponentHeader
;
69 typedef struct ScsiMbr
{
73 ScsiBlockPtr blockptr
;
74 } __attribute__ ((packed
)) ScsiMbr
;
76 #define ZIPL_MAGIC "zIPL"
77 #define IPL1_MAGIC "\xc9\xd7\xd3\xf1" /* == "IPL1" in EBCDIC */
78 #define IPL2_MAGIC "\xc9\xd7\xd3\xf2" /* == "IPL2" in EBCDIC */
79 #define VOL1_MAGIC "\xe5\xd6\xd3\xf1" /* == "VOL1" in EBCDIC */
80 #define LNX1_MAGIC "\xd3\xd5\xe7\xf1" /* == "LNX1" in EBCDIC */
81 #define CMS1_MAGIC "\xc3\xd4\xe2\xf1" /* == "CMS1" in EBCDIC */
83 #define LDL1_VERSION '\x40' /* == ' ' in EBCDIC */
84 #define LDL2_VERSION '\xf2' /* == '2' in EBCDIC */
86 #define ZIPL_COMP_HEADER_IPL 0x00
87 #define ZIPL_COMP_HEADER_DUMP 0x01
89 #define ZIPL_COMP_ENTRY_LOAD 0x02
90 #define ZIPL_COMP_ENTRY_EXEC 0x01
92 typedef struct XEckdMbr
{
93 uint8_t magic
[4]; /* == "xIPL" */
96 uint8_t dev_type
; /* == DEV_TYPE_* */
97 #define DEV_TYPE_ECKD 0x00
98 #define DEV_TYPE_FBA 0x01
100 BootMapPointer blockptr
;
102 } __attribute__ ((packed
)) XEckdMbr
; /* see also BootInfo */
104 typedef struct BootMapScriptEntry
{
105 BootMapPointer blkptr
;
107 uint8_t type
; /* == BOOT_SCRIPT_* */
108 #define BOOT_SCRIPT_EXEC 0x01
109 #define BOOT_SCRIPT_LOAD 0x02
111 uint64_t load_address
;
114 } __attribute__ ((packed
)) BootMapScriptEntry
;
116 typedef struct BootMapScriptHeader
{
119 #define BOOT_SCRIPT_HDR_IPL 0x00
120 uint8_t reserved
[27];
121 } __attribute__ ((packed
)) BootMapScriptHeader
;
123 typedef struct BootMapScript
{
124 BootMapScriptHeader header
;
125 BootMapScriptEntry entry
[0];
126 } __attribute__ ((packed
)) BootMapScript
;
129 * These aren't real VTOCs, but referred to this way in some docs.
130 * They are "volume labels" actually.
132 * Some structures looks similar to described above, but left
133 * separate as there is no indication that they are the same.
134 * So, the value definitions are left separate too.
136 typedef struct LDL_VTOC
{ /* @ rec.3 cyl.0 trk.0 for ECKD */
137 char magic
[4]; /* "LNX1", EBCDIC */
138 char volser
[6]; /* volser, EBCDIC */
139 uint8_t reserved
[69]; /* reserved, 0x40 */
140 uint8_t LDL_version
; /* 0x40 or 0xF2 */
141 uint64_t formatted_blocks
; /* if LDL_version >= 0xF2 */
142 } __attribute__ ((packed
)) LDL_VTOC
;
144 typedef struct format_date
{
151 } __attribute__ ((packed
)) format_date_t
;
153 typedef struct CMS_VTOC
{ /* @ rec.3 cyl.0 trk.0 for ECKD */
154 /* @ blk.1 (zero based) for FBA */
155 char magic
[4]; /* 'CMS1', EBCDIC */
156 char volser
[6]; /* volser, EBCDIC */
157 uint16_t version
; /* = 0 */
158 uint32_t block_size
; /* = 512, 1024, 2048, or 4096 */
159 uint32_t disk_origin
; /* = 4 or 5 */
160 uint32_t blocks
; /* Number of usable cyls/blocks */
161 uint32_t formatted
; /* Max number of fmtd cyls/blks */
162 uint32_t CMS_blocks
; /* disk size in CMS blocks */
163 uint32_t CMS_used
; /* Number of CMS blocks in use */
164 uint32_t FST_size
; /* = 64, bytes */
165 uint32_t FST_per_CMS_blk
; /* */
166 format_date_t format_date
; /* YYMMDDhhmmss as 6 bytes */
167 uint8_t reserved1
[2]; /* = 0 */
168 uint32_t offset
; /* disk offset when reserved */
169 uint32_t next_hole
; /* block nr */
170 uint32_t HBLK_hole_offset
; /* >> HBLK data of next hole */
171 uint32_t alloc_map_usr_off
; /* >> user part of Alloc map */
172 uint8_t reserved2
[4]; /* = 0 */
173 char shared_seg_name
[8]; /* */
174 } __attribute__ ((packed
)) CMS_VTOC
;
176 /* from zipl/include/boot.h */
177 typedef struct BootInfoBpIpl
{
179 ExtEckdBlockPtr eckd
;
183 } __attribute__ ((packed
)) BootInfoBpIpl
;
185 typedef struct EckdDumpParam
{
192 } __attribute((packed
, may_alias
)) EckdDumpParam
;
194 typedef struct FbaDumpParam
{
197 } __attribute((packed
)) FbaDumpParam
;
199 typedef struct BootInfoBpDump
{
205 } __attribute__ ((packed
)) BootInfoBpDump
;
207 typedef struct BootInfo
{ /* @ 0x70, record #0 */
208 unsigned char magic
[4]; /* = 'zIPL', ASCII */
209 uint8_t version
; /* = 1 */
210 #define BOOT_INFO_VERSION 1
211 uint8_t bp_type
; /* = 0 */
212 #define BOOT_INFO_BP_TYPE_IPL 0x00
213 #define BOOT_INFO_BP_TYPE_DUMP 0x01
214 uint8_t dev_type
; /* = 0 */
215 #define BOOT_INFO_DEV_TYPE_ECKD 0x00
216 #define BOOT_INFO_DEV_TYPE_FBA 0x01
217 uint8_t flags
; /* = 1 */
219 #define BOOT_INFO_FLAGS_ARCH 0x01
221 #define BOOT_INFO_FLAGS_ARCH 0x00
227 } __attribute__ ((packed
)) BootInfo
; /* see also XEckdMbr */
229 typedef struct Ipl1
{
230 unsigned char key
[4]; /* == "IPL1" */
231 unsigned char data
[24];
232 } __attribute__((packed
)) Ipl1
;
234 typedef struct Ipl2
{
235 unsigned char key
[4]; /* == "IPL2" */
237 unsigned char data
[144];
239 unsigned char reserved1
[92-4];
241 unsigned char reserved2
[144-(92-4)-sizeof(XEckdMbr
)];
244 } __attribute__((packed
)) Ipl2
;
246 typedef struct IplVolumeLabel
{
247 unsigned char key
[4]; /* == "VOL1" */
249 unsigned char data
[80];
251 unsigned char key
[4]; /* == "VOL1" */
252 unsigned char volser
[6];
253 unsigned char reserved
[6];
256 } __attribute__((packed
)) IplVolumeLabel
;
265 /* utility code below */
267 static inline void IPL_assert(bool term
, const char *message
)
272 virtio_panic(" !\n"); /* no return */
276 static const unsigned char ebc2asc
[256] =
277 /* 0123456789abcdef0123456789abcdef */
278 "................................" /* 1F */
279 "................................" /* 3F */
280 " ...........<(+|&.........!$*);." /* 5F first.chr.here.is.real.space */
281 "-/.........,%_>?.........`:#@'=\""/* 7F */
282 ".abcdefghi.......jklmnopqr......" /* 9F */
283 "..stuvwxyz......................" /* BF */
284 ".ABCDEFGHI.......JKLMNOPQR......" /* DF */
285 "..STUVWXYZ......0123456789......";/* FF */
287 static inline void ebcdic_to_ascii(const char *src
,
292 for (i
= 0; i
< size
; i
++) {
298 static inline void print_volser(const void *volser
)
302 ebcdic_to_ascii((char *)volser
, ascii
, 6);
304 sclp_print("VOLSER=[");
309 static inline bool unused_space(const void *p
, size_t size
)
312 const unsigned char *m
= p
;
314 for (i
= 0; i
< size
; i
++) {
315 if (m
[i
] != FREE_SPACE_FILLER
) {
322 static inline bool is_null_block_number(block_number_t x
)
324 return x
== NULL_BLOCK_NR
;
327 static inline void read_block(block_number_t blockno
,
331 IPL_assert(virtio_read(blockno
, buffer
) == 0, errmsg
);
334 static inline bool block_size_ok(uint32_t block_size
)
336 return block_size
== virtio_get_block_size();
339 static inline bool magic_match(const void *data
, const void *magic
)
341 return *((uint32_t *)data
) == *((uint32_t *)magic
);
344 #endif /* _PC_BIOS_S390_CCW_BOOTMAP_H */