qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jens Freimann <jfrei@linux.vnet.ibm.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	Alexander Graf <agraf@suse.de>,
	Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: Jens Freimann <jfrei@linux.vnet.ibm.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/4] pc-bios/s390-ccw: do a subsystem reset before running the guest
Date: Wed, 18 Jun 2014 14:16:45 +0200	[thread overview]
Message-ID: <1403093807-32836-3-git-send-email-jfrei@linux.vnet.ibm.com> (raw)
In-Reply-To: <1403093807-32836-1-git-send-email-jfrei@linux.vnet.ibm.com>

From: Christian Borntraeger <borntraeger@de.ibm.com>

The loader BIOS has already activated several devices. Let's do a
subsystem reset before jumping into the guest. As there is no direct
way of doing so, we use diagnose 308 to bring the system in a
defined state. This is similar to what kdump on s390 uses. We have
to define a small trampoline function that restores the low bytes
to whatever the bootmap has written there.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 pc-bios/s390-ccw/bootmap.c | 55 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 8 deletions(-)

diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index 53a460d..c07553b 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -58,6 +58,52 @@ struct mbr {
 /* Scratch space */
 static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
 
+typedef struct ResetInfo {
+    uint32_t ipl_mask;
+    uint32_t ipl_addr;
+    uint32_t ipl_continue;
+} ResetInfo;
+
+ResetInfo save;
+
+static void jump_to_IPL_2(void)
+{
+    ResetInfo *current = 0;
+
+    void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue;
+    debug_print_addr("set IPL addr to", ipl);
+
+    /* Ensure the guest output starts fresh */
+    sclp_print("\n");
+
+    *current = save;
+    ipl(); /* should not return */
+}
+
+static void jump_to_IPL_code(uint64_t address)
+{
+    /*
+     * The IPL PSW is at address 0. We also must not overwrite the
+     * content of non-BIOS memory after we loaded the guest, so we
+     * save the original content and restore it in jump_to_IPL_2.
+     */
+    ResetInfo *current = 0;
+
+    save = *current;
+    current->ipl_addr = (uint32_t) (uint64_t) &jump_to_IPL_2;
+    current->ipl_continue = address & 0x7fffffff;
+
+    /*
+     * HACK ALERT.
+     * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2
+     * can then use r15 as its stack pointer.
+     */
+    asm volatile("lghi 1,1\n\t"
+                 "diag 1,1,0x308\n\t"
+                 : : : "1", "memory");
+    virtio_panic("\n! IPL returns !\n");
+}
+
 /* Check for ZIPL magic. Returns 0 if not matched. */
 static int zipl_magic(uint8_t *ptr)
 {
@@ -123,7 +169,6 @@ static int zipl_run(struct scsi_blockptr *pte)
 {
     struct component_header *header;
     struct component_entry *entry;
-    void (*ipl)(void);
     uint8_t tmp_sec[SECTOR_SIZE];
 
     virtio_read(pte->blockno, tmp_sec);
@@ -157,14 +202,8 @@ static int zipl_run(struct scsi_blockptr *pte)
         goto fail;
     }
 
-    /* Ensure the guest output starts fresh */
-    sclp_print("\n");
-
-    /* And run the OS! */
-    ipl = (void*)(entry->load_address & 0x7fffffff);
-    debug_print_addr("set IPL addr to", ipl);
     /* should not return */
-    ipl();
+    jump_to_IPL_code(entry->load_address);
 
     return 0;
 
-- 
1.8.5.5

  parent reply	other threads:[~2014-06-18 12:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-18 12:16 [Qemu-devel] [PATCH 0/4] s390-ccw.img: s390-ccw.img fixes Jens Freimann
2014-06-18 12:16 ` [Qemu-devel] [PATCH 1/4] pc-bios/s390-ccw: virtio_load_direct() can't load max number of sectors Jens Freimann
2014-06-18 12:16 ` Jens Freimann [this message]
2014-06-18 12:16 ` [Qemu-devel] [PATCH 3/4] pc-bios/s390-ccw: fix for fragmented SCSI bootmap Jens Freimann
2014-06-18 12:53   ` Eugene "jno" Dvurechenski
2014-06-23 10:47     ` Cornelia Huck
2014-06-18 12:16 ` [Qemu-devel] [PATCH 4/4] pc-bios/s390-ccw: update s390-ccw.img binary Jens Freimann
2014-06-18 13:06 ` [Qemu-devel] [PATCH 0/4] s390-ccw.img: s390-ccw.img fixes Alexander Graf
2014-06-23 10:48 ` Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403093807-32836-3-git-send-email-jfrei@linux.vnet.ibm.com \
    --to=jfrei@linux.vnet.ibm.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).