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: "Eugene (jno) Dvurechenski" <jno@linux.vnet.ibm.com>,
	Jens Freimann <jfrei@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 04/10] pc-bios/s390-ccw: add some utility code
Date: Thu, 26 Jun 2014 16:30:03 +0200	[thread overview]
Message-ID: <1403793009-54176-5-git-send-email-jfrei@linux.vnet.ibm.com> (raw)
In-Reply-To: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com>

From: "Eugene (jno) Dvurechenski" <jno@linux.vnet.ibm.com>

IPL_assert(term,message) is introduced to handle error conditions.
ebcdic_to_ascii() to convert chars (mostly to print VOLSERs).
read_block() provision for unified block-number handling.

Signed-off-by: Eugene (jno) Dvurechenski <jno@linux.vnet.ibm.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 pc-bios/s390-ccw/bootmap.c | 15 +--------
 pc-bios/s390-ccw/bootmap.h | 83 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 14 deletions(-)

diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index 79db3c3..d2893e2 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -85,25 +85,12 @@ static int zipl_magic(uint8_t *ptr)
     return 1;
 }
 
-static inline bool unused_space(const void *p, unsigned int size)
-{
-    int i;
-    const unsigned char *m = p;
-
-    for (i = 0; i < size; i++) {
-        if (m[i] != FREE_SPACE_FILLER) {
-            return false;
-        }
-    }
-    return true;
-}
-
 static int zipl_load_segment(ComponentEntry *entry)
 {
     const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
-    uint64_t blockno;
+    block_number_t blockno;
     long address;
     int i;
 
diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h
index 59267b0..1846632 100644
--- a/pc-bios/s390-ccw/bootmap.h
+++ b/pc-bios/s390-ccw/bootmap.h
@@ -12,6 +12,10 @@
 #define _PC_BIOS_S390_CCW_BOOTMAP_H
 
 #include "s390-ccw.h"
+#include "virtio.h"
+
+typedef uint64_t block_number_t;
+#define NULL_BLOCK_NR 0xffffffffffffffff
 
 #define FREE_SPACE_FILLER '\xAA'
 
@@ -251,4 +255,83 @@ typedef struct IplVolumeLabel {
     };
 } __attribute__((packed)) IplVolumeLabel;
 
+/* utility code below */
+
+static inline void IPL_assert(bool term, const char *message)
+{
+    if (!term) {
+        sclp_print("\n! ");
+        sclp_print(message);
+        virtio_panic(" !\n"); /* no return */
+    }
+}
+
+static const unsigned char ebc2asc[256] =
+      /* 0123456789abcdef0123456789abcdef */
+        "................................" /* 1F */
+        "................................" /* 3F */
+        " ...........<(+|&.........!$*);." /* 5F first.chr.here.is.real.space */
+        "-/.........,%_>?.........`:#@'=\""/* 7F */
+        ".abcdefghi.......jklmnopqr......" /* 9F */
+        "..stuvwxyz......................" /* BF */
+        ".ABCDEFGHI.......JKLMNOPQR......" /* DF */
+        "..STUVWXYZ......0123456789......";/* FF */
+
+static inline void ebcdic_to_ascii(const char *src,
+                                   char *dst,
+                                   unsigned int size)
+{
+    unsigned int i;
+    for (i = 0; i < size; i++) {
+        unsigned c = src[i];
+        dst[i] = ebc2asc[c];
+    }
+}
+
+static inline void print_volser(const void *volser)
+{
+    char ascii[8];
+
+    ebcdic_to_ascii((char *)volser, ascii, 6);
+    ascii[6] = '\0';
+    sclp_print("VOLSER=[");
+    sclp_print(ascii);
+    sclp_print("]\n");
+}
+
+static inline bool unused_space(const void *p, size_t size)
+{
+    size_t i;
+    const unsigned char *m = p;
+
+    for (i = 0; i < size; i++) {
+        if (m[i] != FREE_SPACE_FILLER) {
+            return false;
+        }
+    }
+    return true;
+}
+
+static inline bool is_null_block_number(block_number_t x)
+{
+    return x == NULL_BLOCK_NR;
+}
+
+static inline void read_block(block_number_t blockno,
+                              void *buffer,
+                              const char *errmsg)
+{
+    IPL_assert(virtio_read(blockno, buffer) == 0, errmsg);
+}
+
+static inline bool block_size_ok(uint32_t block_size)
+{
+    return block_size == virtio_get_block_size();
+}
+
+static inline bool magic_match(const void *data, const void *magic)
+{
+    return *((uint32_t *)data) == *((uint32_t *)magic);
+}
+
 #endif /* _PC_BIOS_S390_CCW_BOOTMAP_H */
-- 
1.8.5.5

  parent reply	other threads:[~2014-06-26 14:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 14:29 [Qemu-devel] [PATCH 00/10] pc-bios/s390-ccw: Add DASD IPL support Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 01/10] pc-bios/s390-ccw: make checkpatch happy Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 02/10] pc-bios/s390-ccw: cleanup and enhance bootmap defintions Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 03/10] pc-bios/s390-ccw: handle different sector sizes Jens Freimann
2014-06-26 14:35   ` Alexander Graf
2014-06-26 15:08     ` Eugene "jno" Dvurechenski
2014-06-26 15:10       ` Alexander Graf
2014-06-26 14:30 ` Jens Freimann [this message]
2014-06-26 14:30 ` [Qemu-devel] [PATCH 05/10] pc-bios/s390-ccw: Unify error handling Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 06/10] pc-bios/s390-ccw: Add fill_hex_val func to provide better msgs Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 07/10] pc-bios/s390-ccw: factor out ipl code Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 08/10] pc-bios/s390-ccw: IPL from CDL-formatted ECKD DASD Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 09/10] pc-bios/s390-ccw: IPL from LDL/CMS-formatted " Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 10/10] pc-bios/s390-ccw: update binary Jens Freimann
2014-06-26 14:42 ` [Qemu-devel] [PATCH 00/10] pc-bios/s390-ccw: Add DASD IPL support Alexander Graf
2014-06-27  7:53   ` Christian Borntraeger
2014-06-27  9:05     ` Alexander Graf
2014-06-27  9:27       ` Christian Borntraeger
2014-06-27  9:47         ` 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=1403793009-54176-5-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=jno@linux.vnet.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).