master
c 112 lines 3.21 KB
Raw
1 /*
2 * QEMU s390-ccw firmware - jump to IPL code
3 *
4 * This work is licensed under the terms of the GNU GPL, version 2 or (at
5 * your option) any later version. See the COPYING file in the top-level
6 * directory.
7 */
8
9 #include <string.h>
10 #include <stdio.h>
11 #include "s390-ccw.h"
12 #include "s390-arch.h"
13
14 #define KERN_IMAGE_START 0x010000UL
15 #define RESET_PSW_MASK (PSW_MASK_SHORTPSW | PSW_MASK_64)
16 #define RESET_PSW ((uint64_t)&jump_to_IPL_addr | RESET_PSW_MASK)
17
18 static uint64_t *reset_psw = 0, save_psw, ipl_continue;
19
20 void write_reset_psw(uint64_t psw)
21 {
22 *reset_psw = psw;
23 }
24
25 static void jump_to_IPL_addr(void)
26 {
27 __attribute__((noreturn)) void (*ipl)(void) = (void *)ipl_continue;
28
29 /* Restore reset PSW */
30 write_reset_psw(save_psw);
31
32 ipl();
33 /* should not return */
34 }
35
36 int jump_to_IPL_code(uint64_t address)
37 {
38 /* store the subsystem information _after_ the bootmap was loaded */
39 write_subsystem_identification();
40 write_iplb_location();
41
42 /*
43 * The IPLB for QEMU SCSI type devices must be rebuilt during re-ipl. The
44 * iplb.devno is set to the boot position of the target SCSI device.
45 */
46 if (iplb->pbt == S390_IPL_TYPE_QEMU_SCSI) {
47 iplb->devno = qipl.index;
48 }
49
50 if (have_iplb && !set_iplb(iplb)) {
51 panic("Failed to set IPLB");
52 }
53
54 /*
55 * The IPL PSW is at address 0. We also must not overwrite the
56 * content of non-BIOS memory after we loaded the guest, so we
57 * save the original content and restore it in jump_to_IPL_2.
58 */
59 if (address) {
60 save_psw = *reset_psw;
61 write_reset_psw(RESET_PSW);
62 ipl_continue = address;
63 }
64 debug_print_int("set IPL addr to", address ?: *reset_psw & PSW_MASK_SHORT_ADDR);
65
66 /* Ensure the guest output starts fresh */
67 printf("\n");
68
69 /*
70 * HACK ALERT.
71 * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2
72 * can then use r15 as its stack pointer.
73 */
74 asm volatile("lghi %%r1,1\n\t"
75 "diag %%r1,%%r1,0x308\n\t"
76 : : : "1", "memory");
77 puts("IPL code jump failed");
78
79 /*
80 * A failed jump only occurs in extreme conditions, so abort the IPL entirely.
81 * This also prevents attempts to boot from the chain area if it has been
82 * overwritten with component data.
83 */
84 qipl.chain_len = 0;
85 return -1;
86 }
87
88 void jump_to_low_kernel(void)
89 {
90 /*
91 * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
92 * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
93 * kernel start address (when jumping to the PSW-at-zero address instead,
94 * the kernel startup code fails when we booted from a network device).
95 */
96 if (!memcmp((char *)S390EP, "S390EP", 6)) {
97 jump_to_IPL_code(KERN_IMAGE_START);
98 }
99
100 /* Trying to get PSW at zero address (pointed to by reset_psw) */
101 if (*reset_psw & RESET_PSW_MASK) {
102 /*
103 * Surely nobody will try running directly from lowcore, so
104 * let's use 0 as an indication that we want to load the reset
105 * psw at 0x0 and not jump to the entry.
106 */
107 jump_to_IPL_code(0);
108 }
109
110 /* No other option left, so use the Linux kernel start address */
111 jump_to_IPL_code(KERN_IMAGE_START);
112 }