]>
Commit | Line | Data |
---|---|---|
e674a49a CB |
1 | /* |
2 | * bootloader support | |
3 | * | |
4 | * Copyright IBM, Corp. 2012 | |
5 | * | |
6 | * Authors: | |
7 | * Christian Borntraeger <[email protected]> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or (at your | |
10 | * option) any later version. See the COPYING file in the top-level directory. | |
11 | * | |
12 | */ | |
13 | ||
14 | #include "sysemu/sysemu.h" | |
15 | #include "cpu.h" | |
16 | #include "elf.h" | |
17 | #include "hw/loader.h" | |
18 | #include "hw/sysbus.h" | |
19 | ||
20 | #define KERN_IMAGE_START 0x010000UL | |
21 | #define KERN_PARM_AREA 0x010480UL | |
22 | #define INITRD_START 0x800000UL | |
23 | #define INITRD_PARM_START 0x010408UL | |
24 | #define INITRD_PARM_SIZE 0x010410UL | |
25 | #define PARMFILE_START 0x001000UL | |
e674a49a CB |
26 | #define ZIPL_IMAGE_START 0x009000UL |
27 | #define IPL_PSW_MASK (PSW_MASK_32 | PSW_MASK_64) | |
28 | ||
29 | #define TYPE_S390_IPL "s390-ipl" | |
30 | #define S390_IPL(obj) \ | |
31 | OBJECT_CHECK(S390IPLState, (obj), TYPE_S390_IPL) | |
32 | #if 0 | |
33 | #define S390_IPL_CLASS(klass) \ | |
34 | OBJECT_CLASS_CHECK(S390IPLState, (klass), TYPE_S390_IPL) | |
35 | #define S390_IPL_GET_CLASS(obj) \ | |
36 | OBJECT_GET_CLASS(S390IPLState, (obj), TYPE_S390_IPL) | |
37 | #endif | |
38 | ||
39 | typedef struct S390IPLClass { | |
40 | /*< private >*/ | |
41 | SysBusDeviceClass parent_class; | |
42 | /*< public >*/ | |
43 | ||
44 | void (*parent_reset) (SysBusDevice *dev); | |
45 | } S390IPLClass; | |
46 | ||
47 | typedef struct S390IPLState { | |
48 | /*< private >*/ | |
49 | SysBusDevice parent_obj; | |
74ad2d22 | 50 | uint64_t start_addr; |
e674a49a | 51 | |
74ad2d22 | 52 | /*< public >*/ |
e674a49a CB |
53 | char *kernel; |
54 | char *initrd; | |
55 | char *cmdline; | |
d0249ce5 | 56 | char *firmware; |
e674a49a CB |
57 | } S390IPLState; |
58 | ||
59 | ||
e674a49a CB |
60 | static int s390_ipl_init(SysBusDevice *dev) |
61 | { | |
62 | S390IPLState *ipl = S390_IPL(dev); | |
63 | ram_addr_t kernel_size = 0; | |
64 | ||
65 | if (!ipl->kernel) { | |
66 | ram_addr_t bios_size = 0; | |
67 | char *bios_filename; | |
68 | ||
69 | /* Load zipl bootloader */ | |
70 | if (bios_name == NULL) { | |
d0249ce5 | 71 | bios_name = ipl->firmware; |
e674a49a CB |
72 | } |
73 | ||
74 | bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
1f7de853 DD |
75 | if (bios_filename == NULL) { |
76 | hw_error("could not find stage1 bootloader\n"); | |
77 | } | |
78 | ||
33259956 AG |
79 | bios_size = load_elf(bios_filename, NULL, NULL, &ipl->start_addr, NULL, |
80 | NULL, 1, ELF_MACHINE, 0); | |
81 | if (bios_size == -1UL) { | |
82 | bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, | |
83 | 4096); | |
84 | ipl->start_addr = ZIPL_IMAGE_START; | |
85 | if (bios_size > 4096) { | |
86 | hw_error("stage1 bootloader is > 4k\n"); | |
87 | } | |
88 | } | |
e674a49a CB |
89 | g_free(bios_filename); |
90 | ||
91 | if ((long)bios_size < 0) { | |
92 | hw_error("could not load bootloader '%s'\n", bios_name); | |
93 | } | |
e674a49a CB |
94 | return 0; |
95 | } else { | |
96 | kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, NULL, | |
97 | NULL, 1, ELF_MACHINE, 0); | |
98 | if (kernel_size == -1UL) { | |
99 | kernel_size = load_image_targphys(ipl->kernel, 0, ram_size); | |
100 | } | |
101 | if (kernel_size == -1UL) { | |
102 | fprintf(stderr, "could not load kernel '%s'\n", ipl->kernel); | |
103 | return -1; | |
104 | } | |
105 | /* we have to overwrite values in the kernel image, which are "rom" */ | |
106 | strcpy(rom_ptr(KERN_PARM_AREA), ipl->cmdline); | |
74ad2d22 AG |
107 | |
108 | /* | |
109 | * we can not rely on the ELF entry point, since up to 3.2 this | |
110 | * value was 0x800 (the SALIPL loader) and it wont work. For | |
111 | * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine. | |
112 | */ | |
113 | ipl->start_addr = KERN_IMAGE_START; | |
e674a49a CB |
114 | } |
115 | if (ipl->initrd) { | |
116 | ram_addr_t initrd_offset, initrd_size; | |
117 | ||
118 | initrd_offset = INITRD_START; | |
119 | while (kernel_size + 0x100000 > initrd_offset) { | |
120 | initrd_offset += 0x100000; | |
121 | } | |
122 | initrd_size = load_image_targphys(ipl->initrd, initrd_offset, | |
123 | ram_size - initrd_offset); | |
124 | if (initrd_size == -1UL) { | |
125 | fprintf(stderr, "qemu: could not load initrd '%s'\n", ipl->initrd); | |
126 | exit(1); | |
127 | } | |
128 | ||
129 | /* we have to overwrite values in the kernel image, which are "rom" */ | |
130 | stq_p(rom_ptr(INITRD_PARM_START), initrd_offset); | |
131 | stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size); | |
132 | } | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | static Property s390_ipl_properties[] = { | |
138 | DEFINE_PROP_STRING("kernel", S390IPLState, kernel), | |
139 | DEFINE_PROP_STRING("initrd", S390IPLState, initrd), | |
140 | DEFINE_PROP_STRING("cmdline", S390IPLState, cmdline), | |
d0249ce5 | 141 | DEFINE_PROP_STRING("firmware", S390IPLState, firmware), |
e674a49a CB |
142 | DEFINE_PROP_END_OF_LIST(), |
143 | }; | |
144 | ||
145 | static void s390_ipl_reset(DeviceState *dev) | |
146 | { | |
147 | S390IPLState *ipl = S390_IPL(dev); | |
2c4c71ee DD |
148 | S390CPU *cpu = S390_CPU(qemu_get_cpu(0)); |
149 | CPUS390XState *env = &cpu->env; | |
e674a49a | 150 | |
2c4c71ee DD |
151 | env->psw.addr = ipl->start_addr; |
152 | env->psw.mask = IPL_PSW_MASK; | |
153 | s390_add_running_cpu(cpu); | |
e674a49a CB |
154 | } |
155 | ||
156 | static void s390_ipl_class_init(ObjectClass *klass, void *data) | |
157 | { | |
158 | DeviceClass *dc = DEVICE_CLASS(klass); | |
159 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); | |
160 | ||
161 | k->init = s390_ipl_init; | |
162 | dc->props = s390_ipl_properties; | |
163 | dc->reset = s390_ipl_reset; | |
164 | dc->no_user = 1; | |
165 | } | |
166 | ||
49973ebc | 167 | static const TypeInfo s390_ipl_info = { |
e674a49a CB |
168 | .class_init = s390_ipl_class_init, |
169 | .parent = TYPE_SYS_BUS_DEVICE, | |
170 | .name = "s390-ipl", | |
171 | .instance_size = sizeof(S390IPLState), | |
172 | }; | |
173 | ||
174 | static void s390_ipl_register_types(void) | |
175 | { | |
176 | type_register_static(&s390_ipl_info); | |
177 | } | |
178 | ||
179 | type_init(s390_ipl_register_types) |