]> Git Repo - qemu.git/blob - pc-bios/s390-ccw/jump2ipl.c
pc-bios: s390x: Save PSW rework
[qemu.git] / pc-bios / s390-ccw / jump2ipl.c
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 "libc.h"
10 #include "s390-ccw.h"
11 #include "s390-arch.h"
12
13 #define KERN_IMAGE_START 0x010000UL
14 #define RESET_PSW_MASK (PSW_MASK_SHORTPSW | PSW_MASK_64)
15
16 static uint64_t *reset_psw = 0, save_psw, ipl_continue;
17
18 static void jump_to_IPL_addr(void)
19 {
20     __attribute__((noreturn)) void (*ipl)(void) = (void *)ipl_continue;
21
22     /* Restore reset PSW */
23     *reset_psw = save_psw;
24
25     ipl();
26     /* should not return */
27 }
28
29 void jump_to_IPL_code(uint64_t address)
30 {
31     /* store the subsystem information _after_ the bootmap was loaded */
32     write_subsystem_identification();
33     write_iplb_location();
34
35     /* prevent unknown IPL types in the guest */
36     if (iplb.pbt == S390_IPL_TYPE_QEMU_SCSI) {
37         iplb.pbt = S390_IPL_TYPE_CCW;
38         set_iplb(&iplb);
39     }
40
41     /*
42      * The IPL PSW is at address 0. We also must not overwrite the
43      * content of non-BIOS memory after we loaded the guest, so we
44      * save the original content and restore it in jump_to_IPL_2.
45      */
46     save_psw = *reset_psw;
47     *reset_psw = (uint64_t) &jump_to_IPL_addr;
48     *reset_psw |= RESET_PSW_MASK;
49     ipl_continue = address;
50     debug_print_int("set IPL addr to", ipl_continue);
51
52     /* Ensure the guest output starts fresh */
53     sclp_print("\n");
54
55     /*
56      * HACK ALERT.
57      * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2
58      * can then use r15 as its stack pointer.
59      */
60     asm volatile("lghi 1,1\n\t"
61                  "diag 1,1,0x308\n\t"
62                  : : : "1", "memory");
63     panic("\n! IPL returns !\n");
64 }
65
66 void jump_to_low_kernel(void)
67 {
68     /*
69      * If it looks like a Linux binary, i.e. there is the "S390EP" magic from
70      * arch/s390/kernel/head.S here, then let's jump to the well-known Linux
71      * kernel start address (when jumping to the PSW-at-zero address instead,
72      * the kernel startup code fails when we booted from a network device).
73      */
74     if (!memcmp((char *)0x10008, "S390EP", 6)) {
75         jump_to_IPL_code(KERN_IMAGE_START);
76     }
77
78     /* Trying to get PSW at zero address */
79     if (*((uint64_t *)0) & RESET_PSW_MASK) {
80         jump_to_IPL_code((*((uint64_t *)0)) & PSW_MASK_SHORT_ADDR);
81     }
82
83     /* No other option left, so use the Linux kernel start address */
84     jump_to_IPL_code(KERN_IMAGE_START);
85 }
This page took 0.027894 seconds and 4 git commands to generate.