qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Cornelia Huck <cohuck@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, rth@twiddle.net, agraf@suse.de,
	thuth@redhat.com, borntraeger@de.ibm.com, david@redhat.com,
	Cornelia Huck <cohuck@redhat.com>
Subject: [Qemu-devel] [PULL 05/44] tests/boot-sector: Do not overwrite the x86 buffer on other architectures
Date: Wed, 30 Aug 2017 18:52:13 +0200	[thread overview]
Message-ID: <20170830165252.13421-6-cohuck@redhat.com> (raw)
In-Reply-To: <20170830165252.13421-1-cohuck@redhat.com>

From: Thomas Huth <thuth@redhat.com>

Re-using the boot_sector code buffer from x86 for other architectures
is not very nice, especially if we add more architectures later. It's
also ugly that the test uses a huge pre-initialized array at all - the
size of the executable is very huge due to this array. So let's use a
separate buffer for each architecture instead, allocated from the heap,
so that we really just use the memory that we need.

Suggested-by: Michael Tsirkin <mst@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <1502431076-22849-2-git-send-email-thuth@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---
 tests/boot-sector.c | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/tests/boot-sector.c b/tests/boot-sector.c
index e3880f4455..87295624d2 100644
--- a/tests/boot-sector.c
+++ b/tests/boot-sector.c
@@ -21,13 +21,12 @@
 #define SIGNATURE 0xdead
 #define SIGNATURE_OFFSET 0x10
 #define BOOT_SECTOR_ADDRESS 0x7c00
+#define SIGNATURE_ADDR (BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET)
 
-/* Boot sector code: write SIGNATURE into memory,
+/* x86 boot sector code: write SIGNATURE into memory,
  * then halt.
- * Q35 machine requires a minimum 0x7e000 bytes disk.
- * (bug or feature?)
  */
-static uint8_t boot_sector[0x7e000] = {
+static uint8_t x86_boot_sector[512] = {
     /* The first sector will be placed at RAM address 00007C00, and
      * the BIOS transfers control to 00007C00
      */
@@ -50,8 +49,8 @@ static uint8_t boot_sector[0x7e000] = {
     [0x07] = HIGH(SIGNATURE),
     /* 7c08:  mov %ax,0x7c10 */
     [0x08] = 0xa3,
-    [0x09] = LOW(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
-    [0x0a] = HIGH(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET),
+    [0x09] = LOW(SIGNATURE_ADDR),
+    [0x0a] = HIGH(SIGNATURE_ADDR),
 
     /* 7c0b cli */
     [0x0b] = 0xfa,
@@ -72,7 +71,9 @@ static uint8_t boot_sector[0x7e000] = {
 int boot_sector_init(char *fname)
 {
     int fd, ret;
-    size_t len = sizeof boot_sector;
+    size_t len;
+    char *boot_code;
+    const char *arch = qtest_get_arch();
 
     fd = mkstemp(fname);
     if (fd < 0) {
@@ -80,16 +81,26 @@ int boot_sector_init(char *fname)
         return 1;
     }
 
-    /* For Open Firmware based system, we can use a Forth script instead */
-    if (strcmp(qtest_get_arch(), "ppc64") == 0) {
-        len = sprintf((char *)boot_sector, "\\ Bootscript\n%x %x c! %x %x c!\n",
-                LOW(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET,
-                HIGH(SIGNATURE), BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
+    if (g_str_equal(arch, "i386") || g_str_equal(arch, "x86_64")) {
+        /* Q35 requires a minimum 0x7e000 bytes disk (bug or feature?) */
+        len = MAX(0x7e000, sizeof(x86_boot_sector));
+        boot_code = g_malloc0(len);
+        memcpy(boot_code, x86_boot_sector, sizeof(x86_boot_sector));
+    } else if (g_str_equal(arch, "ppc64")) {
+        /* For Open Firmware based system, use a Forth script */
+        boot_code = g_strdup_printf("\\ Bootscript\n%x %x c! %x %x c!\n",
+                                    LOW(SIGNATURE), SIGNATURE_ADDR,
+                                    HIGH(SIGNATURE), SIGNATURE_ADDR + 1);
+        len = strlen(boot_code);
+    } else {
+        g_assert_not_reached();
     }
 
-    ret = write(fd, boot_sector, len);
+    ret = write(fd, boot_code, len);
     close(fd);
 
+    g_free(boot_code);
+
     if (ret != len) {
         fprintf(stderr, "Could not write \"%s\"", fname);
         return 1;
@@ -115,8 +126,8 @@ void boot_sector_test(void)
      * instruction.
      */
     for (i = 0; i < TEST_CYCLES; ++i) {
-        signature_low = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET);
-        signature_high = readb(BOOT_SECTOR_ADDRESS + SIGNATURE_OFFSET + 1);
+        signature_low = readb(SIGNATURE_ADDR);
+        signature_high = readb(SIGNATURE_ADDR + 1);
         signature = (signature_high << 8) | signature_low;
         if (signature == SIGNATURE) {
             break;
-- 
2.13.5

  parent reply	other threads:[~2017-08-30 16:53 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 16:52 [Qemu-devel] [PULL 00/44] first batch of s390x patches for 2.11 Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 01/44] s390x/css: use macro for event-information pending error recover code Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 02/44] s390x/css: generate solicited crw for rchp completion signaling Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 03/44] s390x: introduce 2.11 compat machine Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 04/44] s390x/ipl: The s390-ipl device is not hot-pluggable Cornelia Huck
2017-08-30 16:52 ` Cornelia Huck [this message]
2017-08-30 16:52 ` [Qemu-devel] [PULL 06/44] tests/pxe: Check virtio-net-ccw on s390x Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 07/44] tests: Run filter-redirector and -mirror test only on POSIX systems Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 08/44] tests: Add network filter tests to the check-qtest-s390x list Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 09/44] s390x/tcg: specification exception for unknown diag Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 10/44] watchdog/wdt_diag288: Mark diag288 watchdog as non-hotpluggable Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 11/44] s390x: wire up diag288 in tcg Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 12/44] configure: enable --s390-pgste linker option Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 13/44] 9pfs: fix dependencies Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 14/44] kvm: remove hard dependency on pci Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 15/44] s390x/pci: add stubs Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 16/44] s390x: chsc nt2 events are pci-only Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 17/44] s390x/pci: do not advertise pci on non-pci builds Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 18/44] s390x/ccw: create s390 phb conditionally Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 19/44] s390x/sclp: properly guard pci-specific functions Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 20/44] s390x/pci: fence off instructions for non-pci Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 21/44] s390x: refine pci dependencies Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 22/44] s390x/s390-skeys: Mark the storage key devices with user_creatable = false Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 23/44] s390x/kvm: drop KVMState parameter from s390_get_memslot_count() Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 24/44] s390x/kvm: drop KVMState parameter from kvm_s390_set_mem_limit() Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 25/44] target/s390x: simplify ri_allowed() Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 26/44] target/s390x: simplify gs_allowed() Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 27/44] target/s390x: no need to pass kvm_state to savevm_gtod handlers Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 28/44] s390x/cpumodel: factor out determination of default model name Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 29/44] s390x: drop inclusion of sysemu/kvm.h from some files Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 30/44] target/s390x: move gtod_*() declarations to s390-virtio.h Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 31/44] target/s390x: move cc_name() to helper.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 32/44] target/s390x: move cpu_mmu_idx_to_asc() to excp_helper.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 33/44] target/s390x: move psw_key_valid() to mem_helper.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 34/44] target/s390x: move s390_do_cpu_reset() to diag.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 35/44] target/s390x: move get_per_in_range() to misc_helper.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 36/44] target/s390x: introduce internal.h Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 37/44] target/s390x: move a couple of functions to cpu.c Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 38/44] s390x: avoid calling kvm_ functions outside of target/s390x/ Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 39/44] s390x/kvm: move KVM declarations and stubs to separate files Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 40/44] target/s390x: cleanup cpu.h Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 41/44] s390x/s390-stattrib: Mark the storage attribute as not user_creatable Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 42/44] s390-ccw: Fix alignment for CCW1 Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 43/44] pc-bios/s390-ccw.img: update image Cornelia Huck
2017-08-30 16:52 ` [Qemu-devel] [PULL 44/44] s390x/pci: fixup trap_msix() Cornelia Huck
2017-08-31 12:50 ` [Qemu-devel] [PULL 00/44] first batch of s390x patches for 2.11 Peter Maydell

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=20170830165252.13421-6-cohuck@redhat.com \
    --to=cohuck@redhat.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=david@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    /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).