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 void 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 /* prevent unknown IPL types in the guest */ 43 if (iplb.pbt == S390_IPL_TYPE_QEMU_SCSI) { 44 iplb.pbt = S390_IPL_TYPE_CCW; 45 set_iplb(&iplb); 46 } 47 48 /* 49 * The IPL PSW is at address 0. We also must not overwrite the 50 * content of non-BIOS memory after we loaded the guest, so we 51 * save the original content and restore it in jump_to_IPL_2. 52 */ 53 if (address) { 54 save_psw = *reset_psw; 55 write_reset_psw(RESET_PSW); 56 ipl_continue = address; 57 } 58 debug_print_int("set IPL addr to", address ?: *reset_psw & PSW_MASK_SHORT_ADDR); 59 60 /* Ensure the guest output starts fresh */ 61 printf("\n"); 62 63 /* 64 * HACK ALERT. 65 * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2 66 * can then use r15 as its stack pointer. 67 */ 68 asm volatile("lghi %%r1,1\n\t" 69 "diag %%r1,%%r1,0x308\n\t" 70 : : : "1", "memory"); 71 panic("\n! IPL returns !\n"); 72 } 73 74 void jump_to_low_kernel(void) 75 { 76 /* 77 * If it looks like a Linux binary, i.e. there is the "S390EP" magic from 78 * arch/s390/kernel/head.S here, then let's jump to the well-known Linux 79 * kernel start address (when jumping to the PSW-at-zero address instead, 80 * the kernel startup code fails when we booted from a network device). 81 */ 82 if (!memcmp((char *)S390EP, "S390EP", 6)) { 83 jump_to_IPL_code(KERN_IMAGE_START); 84 } 85 86 /* Trying to get PSW at zero address (pointed to by reset_psw) */ 87 if (*reset_psw & RESET_PSW_MASK) { 88 /* 89 * Surely nobody will try running directly from lowcore, so 90 * let's use 0 as an indication that we want to load the reset 91 * psw at 0x0 and not jump to the entry. 92 */ 93 jump_to_IPL_code(0); 94 } 95 96 /* No other option left, so use the Linux kernel start address */ 97 jump_to_IPL_code(KERN_IMAGE_START); 98 } 99