From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0AhC-0006aq-Eh for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0Ah0-0001l5-66 for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:38 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:46050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Agz-0001k1-Iv for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:26 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Jun 2014 15:30:24 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id E1D201B0804B for ; Thu, 26 Jun 2014 15:30:53 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5QEULvn35782848 for ; Thu, 26 Jun 2014 14:30:21 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5QEUKEm005048 for ; Thu, 26 Jun 2014 08:30:20 -0600 From: Jens Freimann Date: Thu, 26 Jun 2014 16:30:03 +0200 Message-Id: <1403793009-54176-5-git-send-email-jfrei@linux.vnet.ibm.com> In-Reply-To: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com> References: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 04/10] pc-bios/s390-ccw: add some utility code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Christian Borntraeger , Alexander Graf , Cornelia Huck Cc: "Eugene (jno) Dvurechenski" , Jens Freimann , qemu-devel@nongnu.org From: "Eugene (jno) Dvurechenski" 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 Reviewed-by: David Hildenbrand Signed-off-by: Jens Freimann --- 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