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 typedef struct ResetInfo { 17 uint64_t ipl_psw; 18 uint32_t ipl_continue; 19 } ResetInfo; 20 21 static ResetInfo save; 22 23 static void jump_to_IPL_2(void) 24 { 25 ResetInfo *current = 0; 26 27 void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue; 28 *current = save; 29 ipl(); /* should not return */ 30 } 31 32 void jump_to_IPL_code(uint64_t address) 33 { 34 /* store the subsystem information _after_ the bootmap was loaded */ 35 write_subsystem_identification(); 36 write_iplb_location(); 37 38 /* prevent unknown IPL types in the guest */ 39 if (iplb.pbt == S390_IPL_TYPE_QEMU_SCSI) { 40 iplb.pbt = S390_IPL_TYPE_CCW; 41 set_iplb(&iplb); 42 } 43 44 /* 45 * The IPL PSW is at address 0. We also must not overwrite the 46 * content of non-BIOS memory after we loaded the guest, so we 47 * save the original content and restore it in jump_to_IPL_2. 48 */ 49 ResetInfo *current = 0; 50 51 save = *current; 52 53 current->ipl_psw = (uint64_t) &jump_to_IPL_2; 54 current->ipl_psw |= RESET_PSW_MASK; 55 current->ipl_continue = address & PSW_MASK_SHORT_ADDR; 56 57 debug_print_int("set IPL addr to", current->ipl_continue); 58 59 /* Ensure the guest output starts fresh */ 60 sclp_print("\n"); 61 62 /* 63 * HACK ALERT. 64 * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2 65 * can then use r15 as its stack pointer. 66 */ 67 asm volatile("lghi 1,1\n\t" 68 "diag 1,1,0x308\n\t" 69 : : : "1", "memory"); 70 panic("\n! IPL returns !\n"); 71 } 72 73 void jump_to_low_kernel(void) 74 { 75 /* 76 * If it looks like a Linux binary, i.e. there is the "S390EP" magic from 77 * arch/s390/kernel/head.S here, then let's jump to the well-known Linux 78 * kernel start address (when jumping to the PSW-at-zero address instead, 79 * the kernel startup code fails when we booted from a network device). 80 */ 81 if (!memcmp((char *)0x10008, "S390EP", 6)) { 82 jump_to_IPL_code(KERN_IMAGE_START); 83 } 84 85 /* Trying to get PSW at zero address */ 86 if (*((uint64_t *)0) & RESET_PSW_MASK) { 87 jump_to_IPL_code((*((uint64_t *)0)) & PSW_MASK_SHORT_ADDR); 88 } 89 90 /* No other option left, so use the Linux kernel start address */ 91 jump_to_IPL_code(KERN_IMAGE_START); 92 } 93