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 /* 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 puts("IPL code jump failed"); 72 return -1; 73 } 74 75 void jump_to_low_kernel(void) 76 { 77 /* 78 * If it looks like a Linux binary, i.e. there is the "S390EP" magic from 79 * arch/s390/kernel/head.S here, then let's jump to the well-known Linux 80 * kernel start address (when jumping to the PSW-at-zero address instead, 81 * the kernel startup code fails when we booted from a network device). 82 */ 83 if (!memcmp((char *)S390EP, "S390EP", 6)) { 84 jump_to_IPL_code(KERN_IMAGE_START); 85 } 86 87 /* Trying to get PSW at zero address (pointed to by reset_psw) */ 88 if (*reset_psw & RESET_PSW_MASK) { 89 /* 90 * Surely nobody will try running directly from lowcore, so 91 * let's use 0 as an indication that we want to load the reset 92 * psw at 0x0 and not jump to the entry. 93 */ 94 jump_to_IPL_code(0); 95 } 96 97 /* No other option left, so use the Linux kernel start address */ 98 jump_to_IPL_code(KERN_IMAGE_START); 99 } 100