From patchwork Thu Jun 26 14:30:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 364562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 03D23140080 for ; Fri, 27 Jun 2014 00:33:27 +1000 (EST) Received: from localhost ([::1]:44987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Ajt-0002ko-4q for incoming@patchwork.ozlabs.org; Thu, 26 Jun 2014 10:33:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0AhC-0006b3-JA 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-0001lJ-V6 for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:38 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:60372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Ah0-0001kw-4F for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:26 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Jun 2014 15:30:25 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 26 Jun 2014 15:30:23 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id B6A2B1B0805F for ; Thu, 26 Jun 2014 15:30:55 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5QEUNY533226846 for ; Thu, 26 Jun 2014 14:30:23 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5QEULYo021794 for ; Thu, 26 Jun 2014 08:30:22 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5QEUKLQ021626; Thu, 26 Jun 2014 08:30:20 -0600 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 1122) id B4FFF1224439; Thu, 26 Jun 2014 16:30:20 +0200 (CEST) From: Jens Freimann To: Christian Borntraeger , Alexander Graf , Cornelia Huck Date: Thu, 26 Jun 2014 16:30:04 +0200 Message-Id: <1403793009-54176-6-git-send-email-jfrei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.5.5 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> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14062614-8372-0000-0000-000000560D57 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.108 Cc: "Eugene \(jno\) Dvurechenski" , Jens Freimann , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 05/10] pc-bios/s390-ccw: Unify error handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Eugene (jno) Dvurechenski" Convert to IPL_assert and friends Signed-off-by: Eugene (jno) Dvurechenski Signed-off-by: Jens Freimann --- pc-bios/s390-ccw/bootmap.c | 82 ++++++++++++--------------------------------- pc-bios/s390-ccw/main.c | 13 ++++--- pc-bios/s390-ccw/s390-ccw.h | 2 +- 3 files changed, 31 insertions(+), 66 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index d2893e2..9e342c9 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -85,7 +85,7 @@ static int zipl_magic(uint8_t *ptr) return 1; } -static int zipl_load_segment(ComponentEntry *entry) +static void zipl_load_segment(ComponentEntry *entry) { const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr)); ScsiBlockPtr *bprs = (void *)sec; @@ -102,10 +102,8 @@ static int zipl_load_segment(ComponentEntry *entry) do { memset(bprs, FREE_SPACE_FILLER, bprs_size); - if (virtio_read(blockno, (uint8_t *)bprs)) { - debug_print_int("failed reading bprs at", blockno); - goto fail; - } + debug_print_int("reading bprs at", blockno); + read_block(blockno, bprs, "zipl_load_segment: cannot read block"); for (i = 0;; i++) { u64 *cur_desc = (void *)&bprs[i]; @@ -133,21 +131,13 @@ static int zipl_load_segment(ComponentEntry *entry) } address = virtio_load_direct(cur_desc[0], cur_desc[1], 0, (void *)address); - if (address == -1) { - goto fail; - } + IPL_assert(address != -1, "zipl_load_segment: wrong IPL address"); } } while (blockno); - - return 0; - -fail: - sclp_print("failed loading segment\n"); - return -1; } /* Run a zipl program */ -static int zipl_run(ScsiBlockPtr *pte) +static void zipl_run(ScsiBlockPtr *pte) { ComponentHeader *header; ComponentEntry *entry; @@ -156,75 +146,53 @@ static int zipl_run(ScsiBlockPtr *pte) virtio_read(pte->blockno, tmp_sec); header = (ComponentHeader *)tmp_sec; - if (!zipl_magic(tmp_sec)) { - goto fail; - } + IPL_assert(zipl_magic(tmp_sec), "zipl_run: zipl_magic"); - if (header->type != ZIPL_COMP_HEADER_IPL) { - goto fail; - } + IPL_assert(header->type == ZIPL_COMP_HEADER_IPL, + "zipl_run: wrong header type"); dputs("start loading images\n"); /* Load image(s) into RAM */ entry = (ComponentEntry *)(&header[1]); while (entry->component_type == ZIPL_COMP_ENTRY_LOAD) { - if (zipl_load_segment(entry) < 0) { - goto fail; - } + zipl_load_segment(entry); entry++; - if ((uint8_t *)(&entry[1]) > (tmp_sec + SECTOR_SIZE)) { - goto fail; - } + IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + SECTOR_SIZE), + "zipl_run: wrong entry size"); } - if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) { - goto fail; - } + IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC, + "zipl_run: no EXEC entry"); /* should not return */ jump_to_IPL_code(entry->load_address); - - return 0; - -fail: - sclp_print("failed running zipl\n"); - return -1; } -int zipl_load(void) +void zipl_load(void) { ScsiMbr *mbr = (void *)sec; uint8_t *ns, *ns_end; int program_table_entries = 0; const int pte_len = sizeof(ScsiBlockPtr); ScsiBlockPtr *prog_table_entry; - const char *error = ""; /* Grab the MBR */ - virtio_read(0, (void *)mbr); + read_block(0, mbr, "zipl_load: cannot read block 0"); dputs("checking magic\n"); - if (!zipl_magic(mbr->magic)) { - error = "zipl_magic 1"; - goto fail; - } + IPL_assert(zipl_magic(mbr->magic), "zipl_load: zipl_magic 1"); debug_print_int("program table", mbr->blockptr.blockno); /* Parse the program table */ - if (virtio_read(mbr->blockptr.blockno, sec)) { - error = "virtio_read"; - goto fail; - } + read_block(mbr->blockptr.blockno, sec, + "zipl_load: cannot read program table"); - if (!zipl_magic(sec)) { - error = "zipl_magic 2"; - goto fail; - } + IPL_assert(zipl_magic(sec), "zipl_load: zipl_magic 2"); ns_end = sec + virtio_get_block_size(); for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) { @@ -238,19 +206,11 @@ int zipl_load(void) debug_print_int("program table entries", program_table_entries); - if (!program_table_entries) { - goto fail; - } + IPL_assert(program_table_entries, "zipl_load: no program table"); /* Run the default entry */ prog_table_entry = (ScsiBlockPtr *)(sec + pte_len); - return zipl_run(prog_table_entry); - -fail: - sclp_print("failed loading zipl: "); - sclp_print(error); - sclp_print("\n"); - return -1; + zipl_run(prog_table_entry); /* no return */ } diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c index 5c33766..dbfb40e 100644 --- a/pc-bios/s390-ccw/main.c +++ b/pc-bios/s390-ccw/main.c @@ -9,6 +9,7 @@ */ #include "s390-ccw.h" +#include "virtio.h" char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); uint64_t boot_value; @@ -64,6 +65,10 @@ static void virtio_setup(uint64_t dev_info) } virtio_setup_block(blk_schid); + + if (!virtio_ipl_disk_is_valid()) { + virtio_panic("No valid hard disk detected.\n"); + } } int main(void) @@ -72,8 +77,8 @@ int main(void) debug_print_int("boot reg[7] ", boot_value); virtio_setup(boot_value); - if (zipl_load() < 0) - sclp_print("Failed to load OS from hard disk\n"); - disabled_wait(); - while (1) { } + zipl_load(); /* no return */ + + virtio_panic("Failed to load OS from hard disk\n"); + return 0; /* make compiler happy */ } diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h index a2bd042..d1c3c42 100644 --- a/pc-bios/s390-ccw/s390-ccw.h +++ b/pc-bios/s390-ccw/s390-ccw.h @@ -64,7 +64,7 @@ int virtio_read(ulong sector, void *load_addr); int enable_mss_facility(void); /* bootmap.c */ -int zipl_load(void); +void zipl_load(void); static inline void *memset(void *s, int c, size_t n) {