All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13
@ 2016-07-14 13:52 Paolo Bonzini
  2016-07-14 13:52 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini
  2016-07-14 16:32 ` [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Peter Maydell
  0 siblings, 2 replies; 10+ messages in thread
From: Paolo Bonzini @ 2016-07-14 13:52 UTC (permalink / raw)
  To: qemu-devel

The following changes since commit a91a4e7d8cfe6ece610aacf7c52738188f5b5cb5:

  Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2016-07-11 15:08:47 +0100)

are available in the git repository at:

  git://github.com/bonzini/qemu.git tags/for-upstream-fwcfg

for you to fetch changes up to b2a575a1c652904600869e774e45bf4c9ed72c55:

  Add optionrom compatible with fw_cfg DMA version (2016-07-14 15:50:52 +0200)

----------------------------------------------------------------
* Updated fw_cfg option ROM to include DMA support

----------------------------------------------------------------
Marc Marí (1):
      Add optionrom compatible with fw_cfg DMA version

 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |  10 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/i386/pc.h              |   4 +
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/linuxboot_dma.bin         | Bin 0 -> 1024 bytes
 pc-bios/optionrom/Makefile        |  42 ++++--
 pc-bios/optionrom/code16gcc.h     |   3 +
 pc-bios/optionrom/linuxboot_dma.c | 294 ++++++++++++++++++++++++++++++++++++++
 10 files changed, 349 insertions(+), 13 deletions(-)
 create mode 100644 pc-bios/linuxboot_dma.bin
 create mode 100644 pc-bios/optionrom/code16gcc.h
 create mode 100644 pc-bios/optionrom/linuxboot_dma.c
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-14 13:52 [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Paolo Bonzini
@ 2016-07-14 13:52 ` Paolo Bonzini
  2016-07-15 13:26   ` Stefan Hajnoczi
  2016-08-06 23:53   ` Brad Smith
  2016-07-14 16:32 ` [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Peter Maydell
  1 sibling, 2 replies; 10+ messages in thread
From: Paolo Bonzini @ 2016-07-14 13:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc Marí, Richard W . M . Jones

From: Marc Marí <markmb@redhat.com>

This optionrom is based on linuxboot.S.

Signed-off-by: Marc Marí <markmb@redhat.com>
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <1464027093-24073-2-git-send-email-rjones@redhat.com>
[Add -fno-toplevel-reorder, support clang without -m16. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |  10 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/i386/pc.h              |   4 +
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/linuxboot_dma.bin         | Bin 0 -> 1024 bytes
 pc-bios/optionrom/Makefile        |  42 ++++--
 pc-bios/optionrom/code16gcc.h     |   3 +
 pc-bios/optionrom/linuxboot_dma.c | 294 ++++++++++++++++++++++++++++++++++++++
 10 files changed, 349 insertions(+), 13 deletions(-)
 create mode 100644 pc-bios/linuxboot_dma.bin
 create mode 100644 pc-bios/optionrom/code16gcc.h
 create mode 100644 pc-bios/optionrom/linuxboot_dma.c

diff --git a/.gitignore b/.gitignore
index 9b6a968..88ec249 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,6 +95,10 @@
 /pc-bios/optionrom/linuxboot.bin
 /pc-bios/optionrom/linuxboot.raw
 /pc-bios/optionrom/linuxboot.img
+/pc-bios/optionrom/linuxboot_dma.asm
+/pc-bios/optionrom/linuxboot_dma.bin
+/pc-bios/optionrom/linuxboot_dma.raw
+/pc-bios/optionrom/linuxboot_dma.img
 /pc-bios/optionrom/multiboot.asm
 /pc-bios/optionrom/multiboot.bin
 /pc-bios/optionrom/multiboot.raw
diff --git a/Makefile b/Makefile
index c054bc6..ba92f9e 100644
--- a/Makefile
+++ b/Makefile
@@ -419,7 +419,7 @@ efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
 efi-e1000e.rom efi-vmxnet3.rom \
 qemu-icon.bmp qemu_logo_no_text.svg \
 bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
-multiboot.bin linuxboot.bin kvmvapic.bin \
+multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \
 s390-ccw.img \
 spapr-rtas.bin slof.bin \
 palcode-clipper \
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f56e225..1b8baa8 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -998,8 +998,13 @@ static void load_linux(PCMachineState *pcms,
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
 
-    option_rom[nb_option_roms].name = "linuxboot.bin";
-    option_rom[nb_option_roms].bootindex = 0;
+    if (fw_cfg_dma_enabled(fw_cfg)) {
+        option_rom[nb_option_roms].name = "linuxboot_dma.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    } else {
+        option_rom[nb_option_roms].name = "linuxboot.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    }
     nb_option_roms++;
 }
 
@@ -1291,6 +1296,7 @@ void xen_load_linux(PCMachineState *pcms)
     load_linux(pcms, fw_cfg);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
+               !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
                !strcmp(option_rom[i].name, "multiboot.bin"));
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 74a0079..2873030 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -552,7 +552,7 @@ static bool is_version_1(void *opaque, int version_id)
     return version_id == 1;
 }
 
-static bool fw_cfg_dma_enabled(void *opaque)
+bool fw_cfg_dma_enabled(void *opaque)
 {
     FWCfgState *s = opaque;
 
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 2123532..e38c95a 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -366,6 +366,10 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 #define PC_COMPAT_2_6 \
     HW_COMPAT_2_6 \
     {\
+        .driver   = "fw_cfg_io",\
+        .property = "dma_enabled",\
+        .value    = "off",\
+    },{\
         .driver   = TYPE_X86_CPU,\
         .property = "cpuid-0xb",\
         .value    = "off",\
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index d008112..5c27a1f 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -182,5 +182,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
                                  hwaddr dma_addr, AddressSpace *dma_as);
 
 FWCfgState *fw_cfg_find(void);
+bool fw_cfg_dma_enabled(void *opaque);
 
 #endif
diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin
new file mode 100644
index 0000000000000000000000000000000000000000..e1f623a1245efff0d46ea5b685e0f18e4ef98d74
GIT binary patch
literal 1024
zcmd6mziX307{@Q^tG-DiZ>p(g$dKVIh%T9=qM-1)wGcJY!KxJW`(h~-Bt;!#jBtbm
z9lAI>If`HmD0vg9wINblk!l@67gN$=2eDW*ug_gPT>JyP;dt+J&wZbtZ~C#n!Tz~o
zj3=j(KEJ*^#!l)_mQr7*PmQM8$hE2ITk*;3<5#ZUh})ymX8Y&b7go%$;tR&$u7;7u
zd7Q&ph$V;`5*|d8xQX0)4B`i}tBiRJVivhZ(1A#CL)y8mD6B{C<hEr(%)@Frcy05r
zbS@uxj5+8hYkD)uLkKKDY|{mCMhBuck3cNL?L^_WO=M-NK^%}T5vY^F7&jdhZEm6x
z-9gZr!&e7e1U%2{W_I8Idzk))+^ZNa;1Vw5BI@G1%1`F?+>jnC`{bTm=MXKl`$#}Z
zhxPS-dEM@GB`+A9wh<mCzY4$Cm;yCQRg`y9;fI_8JMQ=296;qT9Z@FDBSRFnUnv_}
zIjAHaC<#g?qItjKw|mkl9&ykoYg?9LBvVjT-1I!E2<_I4i{Y9zQ@!hEfc#=+9ElZ_
zeQokAK0<tI4nn*Qe6aGvK3LB-iBK5#7$vW|oUM^NAGIx*Uy;oe3$W~22Zv-t%7f~N
zK`HnA%QUD46js5euqu00xbwgM6wcIX>{9%R=26W}#UCn8I#H!Vog7g7j<yeJ`@M=!
zXdcr%qWGDfj?F_Vsu(JRiXZLqh-}yxO&O(ia7lIvxlXvWT&k8@rFMx%?{lsiPfjpd
jw8R@E7UiHPHX1ZFTun{A_*7Ps{(-r*mtE5S57vp_DS}uK

literal 0
HcmV?d00001

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index 2cdda87..d88ce11 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -9,22 +9,46 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 
 .PHONY : all clean build-all
 
-CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
-CFLAGS += -I$(SRC_PATH)
-CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
-CFLAGS += $(CFLAGS_NOPIE)
-QEMU_CFLAGS = $(CFLAGS)
-
-build-all: multiboot.bin linuxboot.bin kvmvapic.bin
+# Drop -fstack-protector and the like
+QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE) -ffreestanding
+QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -m16)
+ifeq ($(filter -m16, $(QEMU_CFLAGS)),)
+# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
+# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
+# respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
+# but it places all asm blocks at the beginning and we're relying on it for
+# the option ROM header.  So just force clang not to use the integrated
+# assembler, which doesn't support .code16gcc.
+QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-toplevel-reorder)
+QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -no-integrated-as)
+QEMU_CFLAGS += -m32 -include $(SRC_PATH)/pc-bios/optionrom/code16gcc.h
+endif
+
+# Drop gcov and glib flags
+CFLAGS := $(filter -O% -g%, $(CFLAGS))
+QEMU_INCLUDES += -I$(SRC_PATH)
+
+Wa = -Wa,
+ASFLAGS += -32
+QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), $(Wa)-32)
+
+build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 
 # suppress auto-removal of intermediate files
 .SECONDARY:
 
+
 %.o: %.S
-	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+
+ifdef CONFIG_WIN32
+LD_EMULATION = i386pe
+else
+LD_EMULATION = elf_i386
+endif
 
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
diff --git a/pc-bios/optionrom/code16gcc.h b/pc-bios/optionrom/code16gcc.h
new file mode 100644
index 0000000..9c8d25d
--- /dev/null
+++ b/pc-bios/optionrom/code16gcc.h
@@ -0,0 +1,3 @@
+asm(
+".code16gcc\n"
+);
diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboot_dma.c
new file mode 100644
index 0000000..8509b28
--- /dev/null
+++ b/pc-bios/optionrom/linuxboot_dma.c
@@ -0,0 +1,294 @@
+/*
+ * Linux Boot Option ROM for fw_cfg DMA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2015-2016 Red Hat Inc.
+ *   Authors:
+ *     Marc Marí <marc.mari.barcelo@gmail.com>
+ *     Richard W.M. Jones <rjones@redhat.com>
+ */
+
+asm(
+".text\n"
+".global _start\n"
+"_start:\n"
+"   .short 0xaa55\n"
+"   .byte 0\n" /* size in 512 units, filled in by signrom.py */
+"   .byte 0xcb\n" /* far return without prefix */
+"   .org 0x18\n"
+"   .short 0\n"
+"   .short _pnph\n"
+"_pnph:\n"
+"   .ascii \"$PnP\"\n"
+"   .byte 0x01\n"
+"   .byte (_pnph_len / 16)\n"
+"   .short 0x0000\n"
+"   .byte 0x00\n"
+"   .byte 0x00\n"
+"   .long 0x00000000\n"
+"   .short _manufacturer\n"
+"   .short _product\n"
+"   .long 0x00000000\n"
+"   .short 0x0000\n"
+"   .short 0x0000\n"
+"   .short _bev\n"
+"   .short 0x0000\n"
+"   .short 0x0000\n"
+"   .equ _pnph_len, . - _pnph\n"
+"_manufacturer:\n"
+"   .asciz \"QEMU\"\n"
+"_product:\n"
+"   .asciz \"Linux loader DMA\"\n"
+"   .align 4, 0\n"
+"_bev:\n"
+"   cli\n"
+"   cld\n"
+"   jmp load_kernel\n"
+);
+
+#include "../../include/hw/nvram/fw_cfg_keys.h"
+
+/* QEMU_CFG_DMA_CONTROL bits */
+#define BIOS_CFG_DMA_CTL_ERROR   0x01
+#define BIOS_CFG_DMA_CTL_READ    0x02
+#define BIOS_CFG_DMA_CTL_SKIP    0x04
+#define BIOS_CFG_DMA_CTL_SELECT  0x08
+
+#define BIOS_CFG_DMA_ADDR_HIGH 0x514
+#define BIOS_CFG_DMA_ADDR_LOW  0x518
+
+#define uint64_t unsigned long long
+#define uint32_t unsigned int
+#define uint16_t unsigned short
+
+#define barrier() asm("" : : : "memory")
+
+typedef struct FWCfgDmaAccess {
+    uint32_t control;
+    uint32_t length;
+    uint64_t address;
+} __attribute__((packed)) FWCfgDmaAccess;
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+    asm("outl %0, %w1" : : "a"(value), "Nd"(port));
+}
+
+static inline void set_es(void *addr)
+{
+    uint32_t seg = (uint32_t)addr >> 4;
+    asm("movl %0, %%es" : : "r"(seg));
+}
+
+#ifdef __clang__
+#define ADDR32
+#else
+#define ADDR32 "addr32 "
+#endif
+
+static inline uint16_t readw_es(uint16_t offset)
+{
+    uint16_t val;
+    asm(ADDR32 "movw %%es:(%1), %0" : "=r"(val) : "r"((uint32_t)offset));
+    barrier();
+    return val;
+}
+
+static inline uint32_t readl_es(uint16_t offset)
+{
+    uint32_t val;
+    asm(ADDR32 "movl %%es:(%1), %0" : "=r"(val) : "r"((uint32_t)offset));
+    barrier();
+    return val;
+}
+
+static inline void writel_es(uint16_t offset, uint32_t val)
+{
+    barrier();
+    asm(ADDR32 "movl %0, %%es:(%1)" : : "r"(val), "r"((uint32_t)offset));
+}
+
+static inline uint32_t bswap32(uint32_t x)
+{
+    return
+        ((x & 0x000000ffU) << 24) |
+        ((x & 0x0000ff00U) <<  8) |
+        ((x & 0x00ff0000U) >>  8) |
+        ((x & 0xff000000U) >> 24);
+}
+
+static inline uint64_t bswap64(uint64_t x)
+{
+    return
+        ((x & 0x00000000000000ffULL) << 56) |
+        ((x & 0x000000000000ff00ULL) << 40) |
+        ((x & 0x0000000000ff0000ULL) << 24) |
+        ((x & 0x00000000ff000000ULL) <<  8) |
+        ((x & 0x000000ff00000000ULL) >>  8) |
+        ((x & 0x0000ff0000000000ULL) >> 24) |
+        ((x & 0x00ff000000000000ULL) >> 40) |
+        ((x & 0xff00000000000000ULL) >> 56);
+}
+
+static inline uint64_t cpu_to_be64(uint64_t x)
+{
+    return bswap64(x);
+}
+
+static inline uint32_t cpu_to_be32(uint32_t x)
+{
+    return bswap32(x);
+}
+
+static inline uint32_t be32_to_cpu(uint32_t x)
+{
+    return bswap32(x);
+}
+
+static void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
+{
+    FWCfgDmaAccess access;
+    uint32_t control = (entry << 16) | BIOS_CFG_DMA_CTL_SELECT
+                        | BIOS_CFG_DMA_CTL_READ;
+
+    access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
+    access.length = cpu_to_be32(len);
+    access.control = cpu_to_be32(control);
+
+    barrier();
+
+    outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
+
+    while (be32_to_cpu(access.control) & ~BIOS_CFG_DMA_CTL_ERROR) {
+        barrier();
+    }
+}
+
+/* Return top of memory using BIOS function E801. */
+static uint32_t get_e801_addr(void)
+{
+    uint16_t ax, bx, cx, dx;
+    uint32_t ret;
+
+    asm("int $0x15\n"
+        : "=a"(ax), "=b"(bx), "=c"(cx), "=d"(dx)
+        : "a"(0xe801), "b"(0), "c"(0), "d"(0));
+
+    /* Not SeaBIOS, but in theory a BIOS could return CX=DX=0 in which
+     * case we need to use the result from AX & BX instead.
+     */
+    if (cx == 0 && dx == 0) {
+        cx = ax;
+        dx = bx;
+    }
+
+    if (dx) {
+        /* DX = extended memory above 16M, in 64K units.
+         * Convert it to bytes and return.
+         */
+        ret = ((uint32_t)dx + 256 /* 16M in 64K units */) << 16;
+    } else {
+        /* This is a fallback path for machines with <= 16MB of RAM,
+         * which probably would never be the case, but deal with it
+         * anyway.
+         *
+         * CX = extended memory between 1M and 16M, in kilobytes
+         * Convert it to bytes and return.
+         */
+        ret = ((uint32_t)cx + 1024 /* 1M in K */) << 10;
+    }
+
+    return ret;
+}
+
+/* Force the asm name without leading underscore, even on Win32. */
+extern void load_kernel(void) asm("load_kernel");
+
+void load_kernel(void)
+{
+    void *setup_addr;
+    void *initrd_addr;
+    void *kernel_addr;
+    void *cmdline_addr;
+    uint32_t setup_size;
+    uint32_t initrd_size;
+    uint32_t kernel_size;
+    uint32_t cmdline_size;
+    uint32_t initrd_end_page, max_allowed_page;
+    uint32_t segment_addr, stack_addr;
+
+    bios_cfg_read_entry(&setup_addr, FW_CFG_SETUP_ADDR, 4);
+    bios_cfg_read_entry(&setup_size, FW_CFG_SETUP_SIZE, 4);
+    bios_cfg_read_entry(setup_addr, FW_CFG_SETUP_DATA, setup_size);
+
+    set_es(setup_addr);
+
+    /* For protocol < 0x203 we don't have initrd_max ... */
+    if (readw_es(0x206) < 0x203) {
+        /* ... so we assume initrd_max = 0x37ffffff. */
+        writel_es(0x22c, 0x37ffffff);
+    }
+
+    bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
+    bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4);
+
+    initrd_end_page = ((uint32_t)(initrd_addr + initrd_size) & -4096);
+    max_allowed_page = (readl_es(0x22c) & -4096);
+
+    if (initrd_end_page != 0 && max_allowed_page != 0 &&
+        initrd_end_page != max_allowed_page) {
+        /* Initrd at the end of memory. Compute better initrd address
+         * based on e801 data
+         */
+        initrd_addr = (void *)((get_e801_addr() - initrd_size) & -4096);
+        writel_es(0x218, (uint32_t)initrd_addr);
+
+    }
+
+    bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
+
+    bios_cfg_read_entry(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
+    bios_cfg_read_entry(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
+    bios_cfg_read_entry(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
+
+    bios_cfg_read_entry(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4);
+    bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4);
+    bios_cfg_read_entry(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size);
+
+    /* Boot linux */
+    segment_addr = ((uint32_t)setup_addr >> 4);
+    stack_addr = (uint32_t)(cmdline_addr - setup_addr - 16);
+
+    /* As we are changing critical registers, we cannot leave freedom to the
+     * compiler.
+     */
+    asm("movw %%ax, %%ds\n"
+        "movw %%ax, %%es\n"
+        "movw %%ax, %%fs\n"
+        "movw %%ax, %%gs\n"
+        "movw %%ax, %%ss\n"
+        "movl %%ebx, %%esp\n"
+        "addw $0x20, %%ax\n"
+        "pushw %%ax\n" /* CS */
+        "pushw $0\n" /* IP */
+        /* Clear registers and jump to Linux */
+        "xor %%ebx, %%ebx\n"
+        "xor %%ecx, %%ecx\n"
+        "xor %%edx, %%edx\n"
+        "xor %%edi, %%edi\n"
+        "xor %%ebp, %%ebp\n"
+        "lretw\n"
+        : : "a"(segment_addr), "b"(stack_addr));
+}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13
  2016-07-14 13:52 [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Paolo Bonzini
  2016-07-14 13:52 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini
@ 2016-07-14 16:32 ` Peter Maydell
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Maydell @ 2016-07-14 16:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: QEMU Developers

On 14 July 2016 at 14:52, Paolo Bonzini <pbonzini@redhat.com> wrote:
> The following changes since commit a91a4e7d8cfe6ece610aacf7c52738188f5b5cb5:
>
>   Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2016-07-11 15:08:47 +0100)
>
> are available in the git repository at:
>
>   git://github.com/bonzini/qemu.git tags/for-upstream-fwcfg
>
> for you to fetch changes up to b2a575a1c652904600869e774e45bf4c9ed72c55:
>
>   Add optionrom compatible with fw_cfg DMA version (2016-07-14 15:50:52 +0200)
>
> ----------------------------------------------------------------
> * Updated fw_cfg option ROM to include DMA support
>
> ----------------------------------------------------------------
> Marc Marí (1):
>       Add optionrom compatible with fw_cfg DMA version
>

Applied, thanks.

-- PMM

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-14 13:52 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini
@ 2016-07-15 13:26   ` Stefan Hajnoczi
  2016-07-15 15:02     ` Paolo Bonzini
  2016-07-18  9:03     ` Paolo Bonzini
  2016-08-06 23:53   ` Brad Smith
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2016-07-15 13:26 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Marc Marí, Richard W . M . Jones

On Thu, Jul 14, 2016 at 2:52 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> From: Marc Marí <markmb@redhat.com>
>
> This optionrom is based on linuxboot.S.
>
> Signed-off-by: Marc Marí <markmb@redhat.com>
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> Message-Id: <1464027093-24073-2-git-send-email-rjones@redhat.com>
> [Add -fno-toplevel-reorder, support clang without -m16. - Paolo]
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  .gitignore                        |   4 +
>  Makefile                          |   2 +-
>  hw/i386/pc.c                      |  10 +-
>  hw/nvram/fw_cfg.c                 |   2 +-
>  include/hw/i386/pc.h              |   4 +
>  include/hw/nvram/fw_cfg.h         |   1 +
>  pc-bios/linuxboot_dma.bin         | Bin 0 -> 1024 bytes
>  pc-bios/optionrom/Makefile        |  42 ++++--
>  pc-bios/optionrom/code16gcc.h     |   3 +
>  pc-bios/optionrom/linuxboot_dma.c | 294 ++++++++++++++++++++++++++++++++++++++
>  10 files changed, 349 insertions(+), 13 deletions(-)
>  create mode 100644 pc-bios/linuxboot_dma.bin
>  create mode 100644 pc-bios/optionrom/code16gcc.h
>  create mode 100644 pc-bios/optionrom/linuxboot_dma.c

  CC    optionrom/linuxboot_dma.o
clang-3.8: error: unsupported argument '-32' to option 'Wa,'

$ rpm -qi clang
Name        : clang
Version     : 3.8.0
Release     : 2.fc24
Architecture: x86_64

Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-15 13:26   ` Stefan Hajnoczi
@ 2016-07-15 15:02     ` Paolo Bonzini
  2016-07-18  9:03     ` Paolo Bonzini
  1 sibling, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2016-07-15 15:02 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Marc Marí, qemu-devel, Richard W . M . Jones



On 15/07/2016 15:26, Stefan Hajnoczi wrote:
> On Thu, Jul 14, 2016 at 2:52 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> From: Marc Marí <markmb@redhat.com>
>>
>> This optionrom is based on linuxboot.S.
>>
>> Signed-off-by: Marc Marí <markmb@redhat.com>
>> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
>> Message-Id: <1464027093-24073-2-git-send-email-rjones@redhat.com>
>> [Add -fno-toplevel-reorder, support clang without -m16. - Paolo]
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  .gitignore                        |   4 +
>>  Makefile                          |   2 +-
>>  hw/i386/pc.c                      |  10 +-
>>  hw/nvram/fw_cfg.c                 |   2 +-
>>  include/hw/i386/pc.h              |   4 +
>>  include/hw/nvram/fw_cfg.h         |   1 +
>>  pc-bios/linuxboot_dma.bin         | Bin 0 -> 1024 bytes
>>  pc-bios/optionrom/Makefile        |  42 ++++--
>>  pc-bios/optionrom/code16gcc.h     |   3 +
>>  pc-bios/optionrom/linuxboot_dma.c | 294 ++++++++++++++++++++++++++++++++++++++
>>  10 files changed, 349 insertions(+), 13 deletions(-)
>>  create mode 100644 pc-bios/linuxboot_dma.bin
>>  create mode 100644 pc-bios/optionrom/code16gcc.h
>>  create mode 100644 pc-bios/optionrom/linuxboot_dma.c
> 
>   CC    optionrom/linuxboot_dma.o
> clang-3.8: error: unsupported argument '-32' to option 'Wa,'
> 
> $ rpm -qi clang
> Name        : clang
> Version     : 3.8.0
> Release     : 2.fc24
> Architecture: x86_64

This is strange, the Makefile does check whether the compiler supports
the argument:

+QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), $(Wa)-32)

Can you send the V=1 output?

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-15 13:26   ` Stefan Hajnoczi
  2016-07-15 15:02     ` Paolo Bonzini
@ 2016-07-18  9:03     ` Paolo Bonzini
  1 sibling, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2016-07-18  9:03 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Marc Marí, qemu-devel, Richard W . M . Jones



On 15/07/2016 15:26, Stefan Hajnoczi wrote:
>>  pc-bios/linuxboot_dma.bin         | Bin 0 -> 1024 bytes
>>  pc-bios/optionrom/Makefile        |  42 ++++--
>>  pc-bios/optionrom/code16gcc.h     |   3 +
>>  pc-bios/optionrom/linuxboot_dma.c | 294 ++++++++++++++++++++++++++++++++++++++
>>  10 files changed, 349 insertions(+), 13 deletions(-)
>>  create mode 100644 pc-bios/linuxboot_dma.bin
>>  create mode 100644 pc-bios/optionrom/code16gcc.h
>>  create mode 100644 pc-bios/optionrom/linuxboot_dma.c
> 
>   CC    optionrom/linuxboot_dma.o
> clang-3.8: error: unsupported argument '-32' to option 'Wa,'

Please try this patch:

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index d88ce11..72abb3c 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -30,7 +30,7 @@ QEMU_INCLUDES += -I$(SRC_PATH)
 
 Wa = -Wa,
 ASFLAGS += -32
-QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), $(Wa)-32)
+QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), $(Wa)-32)
 
 build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 
diff --git a/roms/ipxe b/roms/ipxe
index 0418631..4e03af8 160000
--- a/roms/ipxe
+++ b/roms/ipxe
@@ -1 +1 @@
-Subproject commit 04186319181298083ef28695a8309028b26fe83c
+Subproject commit 4e03af8ec2d497e725566a91fd5c19dd604c18a6
diff --git a/rules.mak b/rules.mak
index ed8e482..99cd0b3 100644
--- a/rules.mak
+++ b/rules.mak
@@ -113,6 +113,8 @@ quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
 
 cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \
               >/dev/null 2>&1 && echo OK), $2, $3)
+cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
+                >/dev/null 2>&1 && echo OK), $2, $3)
 
 VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-14 13:52 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini
  2016-07-15 13:26   ` Stefan Hajnoczi
@ 2016-08-06 23:53   ` Brad Smith
  2016-08-08  8:50     ` Paolo Bonzini
  1 sibling, 1 reply; 10+ messages in thread
From: Brad Smith @ 2016-08-06 23:53 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Marc Marí, Richard W . M . Jones

On 07/14/16 09:52, Paolo Bonzini wrote:
> diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
> index 2cdda87..d88ce11 100644
> --- a/pc-bios/optionrom/Makefile
> +++ b/pc-bios/optionrom/Makefile
> @@ -9,22 +9,46 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
>
>  .PHONY : all clean build-all
>
> -CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
> -CFLAGS += -I$(SRC_PATH)
> -CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
> -CFLAGS += $(CFLAGS_NOPIE)
> -QEMU_CFLAGS = $(CFLAGS)
> -
> -build-all: multiboot.bin linuxboot.bin kvmvapic.bin
> +# Drop -fstack-protector and the like
> +QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE) -ffreestanding
> +QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -m16)

This change in CFLAGS handling broke the build on OpenBSD. Filtering 
-fstack-protector is not enough and is why the Makefile had an explicit 
-fno-stack-protector provided.

Adding this back in fixes the issue..

QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)



ld -nopie -m elf_i386 -Ttext 0 -e _start -s -o linuxboot_dma.img 
linuxboot_dma.o
linuxboot_dma.o: In function `bios_cfg_read_entry':
linuxboot_dma.c:(.text+0x90): undefined reference to `__guard_local'
linuxboot_dma.c:(.text+0x12d): undefined reference to `__guard_local'
linuxboot_dma.c:(.text+0x149): undefined reference to 
`__stack_smash_handler'
linuxboot_dma.o: In function `load_kernel':
linuxboot_dma.c:(.text+0x168): undefined reference to `__guard_local'
linuxboot_dma.c:(.text+0x381): undefined reference to `__guard_local'
linuxboot_dma.c:(.text+0x3b6): undefined reference to 
`__stack_smash_handler'
gmake[1]: *** [Makefile:52: linuxboot_dma.img] Error 1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-08-06 23:53   ` Brad Smith
@ 2016-08-08  8:50     ` Paolo Bonzini
  2016-08-10 23:28       ` Brad Smith
  0 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2016-08-08  8:50 UTC (permalink / raw)
  To: Brad Smith, qemu-devel; +Cc: Marc Marí, Richard W . M . Jones



On 07/08/2016 01:53, Brad Smith wrote:
> On 07/14/16 09:52, Paolo Bonzini wrote:
>> diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
>> index 2cdda87..d88ce11 100644
>> --- a/pc-bios/optionrom/Makefile
>> +++ b/pc-bios/optionrom/Makefile
>> @@ -9,22 +9,46 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
>>
>>  .PHONY : all clean build-all
>>
>> -CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
>> -fno-builtin
>> -CFLAGS += -I$(SRC_PATH)
>> -CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
>> -CFLAGS += $(CFLAGS_NOPIE)
>> -QEMU_CFLAGS = $(CFLAGS)
>> -
>> -build-all: multiboot.bin linuxboot.bin kvmvapic.bin
>> +# Drop -fstack-protector and the like
>> +QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE)
>> -ffreestanding
>> +QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -m16)
> 
> This change in CFLAGS handling broke the build on OpenBSD. Filtering
> -fstack-protector is not enough and is why the Makefile had an explicit
> -fno-stack-protector provided.
> 
> Adding this back in fixes the issue..
> 
> QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)

Ok, will add back.

Paolo

> 
> 
> ld -nopie -m elf_i386 -Ttext 0 -e _start -s -o linuxboot_dma.img
> linuxboot_dma.o
> linuxboot_dma.o: In function `bios_cfg_read_entry':
> linuxboot_dma.c:(.text+0x90): undefined reference to `__guard_local'
> linuxboot_dma.c:(.text+0x12d): undefined reference to `__guard_local'
> linuxboot_dma.c:(.text+0x149): undefined reference to
> `__stack_smash_handler'
> linuxboot_dma.o: In function `load_kernel':
> linuxboot_dma.c:(.text+0x168): undefined reference to `__guard_local'
> linuxboot_dma.c:(.text+0x381): undefined reference to `__guard_local'
> linuxboot_dma.c:(.text+0x3b6): undefined reference to
> `__stack_smash_handler'
> gmake[1]: *** [Makefile:52: linuxboot_dma.img] Error 1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-08-08  8:50     ` Paolo Bonzini
@ 2016-08-10 23:28       ` Brad Smith
  0 siblings, 0 replies; 10+ messages in thread
From: Brad Smith @ 2016-08-10 23:28 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Marc Marí, Richard W . M . Jones

On 08/08/16 04:50, Paolo Bonzini wrote:
>
>
> On 07/08/2016 01:53, Brad Smith wrote:
>> On 07/14/16 09:52, Paolo Bonzini wrote:
>>> diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
>>> index 2cdda87..d88ce11 100644
>>> --- a/pc-bios/optionrom/Makefile
>>> +++ b/pc-bios/optionrom/Makefile
>>> @@ -9,22 +9,46 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
>>>
>>>  .PHONY : all clean build-all
>>>
>>> -CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
>>> -fno-builtin
>>> -CFLAGS += -I$(SRC_PATH)
>>> -CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
>>> -CFLAGS += $(CFLAGS_NOPIE)
>>> -QEMU_CFLAGS = $(CFLAGS)
>>> -
>>> -build-all: multiboot.bin linuxboot.bin kvmvapic.bin
>>> +# Drop -fstack-protector and the like
>>> +QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS)) $(CFLAGS_NOPIE)
>>> -ffreestanding
>>> +QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -m16)
>>
>> This change in CFLAGS handling broke the build on OpenBSD. Filtering
>> -fstack-protector is not enough and is why the Makefile had an explicit
>> -fno-stack-protector provided.
>>
>> Adding this back in fixes the issue..
>>
>> QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)
>
> Ok, will add back.

Great, thank you.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version
  2016-07-13 12:55 [Qemu-devel] [PULL " Paolo Bonzini
@ 2016-07-13 12:55 ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2016-07-13 12:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Marc Marí, Richard W.M. Jones

From: Marc Marí <markmb@redhat.com>

This optionrom is based on linuxboot.S.

Signed-off-by: Marc Marí <markmb@redhat.com>
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <1464027093-24073-2-git-send-email-rjones@redhat.com>
[Add -fno-toplevel-reorder, support clang without -m16. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 .gitignore                        |   4 +
 Makefile                          |   2 +-
 hw/i386/pc.c                      |  10 +-
 hw/nvram/fw_cfg.c                 |   2 +-
 include/hw/nvram/fw_cfg.h         |   1 +
 pc-bios/linuxboot_dma.bin         | Bin 0 -> 2560 bytes
 pc-bios/optionrom/Makefile        |  30 +++-
 pc-bios/optionrom/code16gcc.h     |   3 +
 pc-bios/optionrom/linuxboot_dma.c | 291 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 335 insertions(+), 8 deletions(-)
 create mode 100644 pc-bios/linuxboot_dma.bin
 create mode 100644 pc-bios/optionrom/code16gcc.h
 create mode 100644 pc-bios/optionrom/linuxboot_dma.c

diff --git a/.gitignore b/.gitignore
index 9b6a968..88ec249 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,6 +95,10 @@
 /pc-bios/optionrom/linuxboot.bin
 /pc-bios/optionrom/linuxboot.raw
 /pc-bios/optionrom/linuxboot.img
+/pc-bios/optionrom/linuxboot_dma.asm
+/pc-bios/optionrom/linuxboot_dma.bin
+/pc-bios/optionrom/linuxboot_dma.raw
+/pc-bios/optionrom/linuxboot_dma.img
 /pc-bios/optionrom/multiboot.asm
 /pc-bios/optionrom/multiboot.bin
 /pc-bios/optionrom/multiboot.raw
diff --git a/Makefile b/Makefile
index c054bc6..ba92f9e 100644
--- a/Makefile
+++ b/Makefile
@@ -419,7 +419,7 @@ efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \
 efi-e1000e.rom efi-vmxnet3.rom \
 qemu-icon.bmp qemu_logo_no_text.svg \
 bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
-multiboot.bin linuxboot.bin kvmvapic.bin \
+multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \
 s390-ccw.img \
 spapr-rtas.bin slof.bin \
 palcode-clipper \
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f56e225..1b8baa8 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -998,8 +998,13 @@ static void load_linux(PCMachineState *pcms,
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
 
-    option_rom[nb_option_roms].name = "linuxboot.bin";
-    option_rom[nb_option_roms].bootindex = 0;
+    if (fw_cfg_dma_enabled(fw_cfg)) {
+        option_rom[nb_option_roms].name = "linuxboot_dma.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    } else {
+        option_rom[nb_option_roms].name = "linuxboot.bin";
+        option_rom[nb_option_roms].bootindex = 0;
+    }
     nb_option_roms++;
 }
 
@@ -1291,6 +1296,7 @@ void xen_load_linux(PCMachineState *pcms)
     load_linux(pcms, fw_cfg);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
+               !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
                !strcmp(option_rom[i].name, "multiboot.bin"));
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 74a0079..2873030 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -552,7 +552,7 @@ static bool is_version_1(void *opaque, int version_id)
     return version_id == 1;
 }
 
-static bool fw_cfg_dma_enabled(void *opaque)
+bool fw_cfg_dma_enabled(void *opaque)
 {
     FWCfgState *s = opaque;
 
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index d008112..5c27a1f 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -182,5 +182,6 @@ FWCfgState *fw_cfg_init_mem_wide(hwaddr ctl_addr,
                                  hwaddr dma_addr, AddressSpace *dma_as);
 
 FWCfgState *fw_cfg_find(void);
+bool fw_cfg_dma_enabled(void *opaque);
 
 #endif
diff --git a/pc-bios/linuxboot_dma.bin b/pc-bios/linuxboot_dma.bin
new file mode 100644
index 0000000000000000000000000000000000000000..a318d63aa53944d2048a46060d6000b88e238cda
GIT binary patch
literal 2560
zcmeHI&x>1C6uvXQv@bQx#G1AdM#$o}bYPGMf(DE-LIlwaMEXVx#u_1>M<rB|40bUK
zA>-mYn7=@9qZ@JGs+(k5oJvun-Bc7Dx{%i&;(!}Ft$qE@xpVU}b;N(bS-iRT-0ytn
zobR4<v-nx+lG^oeM(O(L`oyF=tf*()QU$Vl@!5q%RXcTh=}e*h*6Xb|-YHZU7_)Wf
z+DeMLH@%Qnt2z@JPs_>=Y5HtV(;w8m;L&*?vSQECAOhAfRy=xrAhLqUi6w72rq6o%
zNVuv(K=(5l{sEc$HzWbdv^Gq31ht9zjx=Y}%NzlC(&i>nJsND}$*gT}4y#xxn0!hn
zCfJbum}wB@DLq6+i}W(RM8{EO8w4x*Jt!mDG-bQuwk@G&W1w4zM(1z>(yItPAamIs
zlZ|e^mTil=8;Z<2nN2cV<4!)A?<ftFDQPl4QThigYuZ-a1Pc<DEN~gP93hgum7cAE
z&d~HHYk967+Y+m@tUWS+Qu;iw4V@)3r1W3nXD>*YRV)^E8fTu7JzE1k!^}R5h;2<S
zrlE6WzNhp$oR@V$sILf-y_P1|D*L0`#D{SY)-op+wg-BSravEo`Z`mC2;a7b2Dd0Z
zfO}0J6Y5B)O5&JMmu26wDhr|_7Pbev!qm{?Iu`*Vd>gtnQo5t($Fi=9V?zC$?3vn0
zUlR-416^a!;*Z=z*e~mOeA~K8=C%{NK9+VMo=x#=jXXK4hOXn=(E*uXot7uWb5qJ`
zi029MY@o;6^a`D%*XY$9v%|x}c~mtnZ8VQ;K~uoOgKPryLiFh0ar}>YVgN<`J91<v
z+!Ho1$kC_cNA?aXJj~$cVa}j2Fr^pwNpO3)W%`omVMp-i<Jh*EP3Ne@fN~O}?G6iK
z28);%of(yVXzSx-pBD3aReSl=b`*-{Z^!Wsgj`K<Mc~kgcj^89(r+ld1l@SHvvh7E
z!nl6LNzxbcm4v@Nz=iDzF)m(+?wblBTqf);>nXKV;Qtx5gq!2KfvN%^Yk*k~Iqy8;
zbV;cReiJtElHu6DamXG_QA&AoU?sD6=Oe!??$>4rT~MA67%JjI56TJ}IBDL#%X01n
z9daOU1QzNA0ih3IfG+GCaIc7T0v4FIu!Q{JmXLdT4}M7~n#K01$;o$78GAz2C$RGL
zoSZf-ct^VXTqd|?2{AzH-JkA*4g^I7^pSv&u5FGyO$;%Co7;U;8H+i%g_})|${|7f
zis~%LqO3Z0pyBdlRhK)DQ}lq7B2Tm9tTq&<iOM8GUaI;45g=NiksPFBz(~6NiFDU6
z9QW6?*VV<H&ew2Z7m)8jc#8$}v49W|1_ZQI;tRL;P!jOWE?f^gE=-Sb9p43%b0BU<
z&gwB25C#Nf-%*7Jl7M?H49zk6#kY?DUVZzMI!Ci>{AzV0+v&%Ik3j*y-<Nw=di~x;
pFX|1+{L<|g>TfD4{!GPh_zf+_RQ&xCntz^~A7TIh`!5A9-UFq<KP~_O

literal 0
HcmV?d00001

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index 2cdda87..4e3b908 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -10,21 +10,43 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
 .PHONY : all clean build-all
 
 CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
-CFLAGS += -I$(SRC_PATH)
 CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
 CFLAGS += $(CFLAGS_NOPIE)
+CFLAGS += $(call cc-option, $(CFLAGS), -m16)
+ifeq ($(filter -m16, $(CFLAGS)),)
+# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
+# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with
+# respect to the rest of the code.  clang does not have -fno-toplevel-reorder,
+# but it places all asm blocks at the beginning and we're relying on it for
+# the option ROM header.  So just force clang not to use the integrated
+# assembler, which doesn't support .code16gcc.
+CFLAGS += $(call cc-option, $(CFLAGS), -fno-toplevel-reorder)
+CFLAGS += $(call cc-option, $(CFLAGS), -no-integrated-as)
+CFLAGS += -m32 -include $(SRC_PATH)/pc-bios/optionrom/code16gcc.h
+endif
+
+QEMU_INCLUDES += -I$(SRC_PATH)
 QEMU_CFLAGS = $(CFLAGS)
 
-build-all: multiboot.bin linuxboot.bin kvmvapic.bin
+ASFLAGS += -32
+
+build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
 
 # suppress auto-removal of intermediate files
 .SECONDARY:
 
+
 %.o: %.S
-	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) $(CFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+	$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< | $(AS) $(ASFLAGS) -o $@,"  AS    $(TARGET_DIR)$@")
+
+ifdef CONFIG_WIN32
+LD_EMULATION = i386pe
+else
+LD_EMULATION = elf_i386
+endif
 
 %.img: %.o
-	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
+	$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_EMULATION) -Ttext 0 -e _start -s -o $@ $<,"  Building $(TARGET_DIR)$@")
 
 %.raw: %.img
 	$(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@,"  Building $(TARGET_DIR)$@")
diff --git a/pc-bios/optionrom/code16gcc.h b/pc-bios/optionrom/code16gcc.h
new file mode 100644
index 0000000..9c8d25d
--- /dev/null
+++ b/pc-bios/optionrom/code16gcc.h
@@ -0,0 +1,3 @@
+asm(
+".code16gcc\n"
+);
diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboot_dma.c
new file mode 100644
index 0000000..86ef1ce
--- /dev/null
+++ b/pc-bios/optionrom/linuxboot_dma.c
@@ -0,0 +1,291 @@
+/*
+ * Linux Boot Option ROM for fw_cfg DMA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2015-2016 Red Hat Inc.
+ *   Authors:
+ *     Marc Marí <marc.mari.barcelo@gmail.com>
+ *     Richard W.M. Jones <rjones@redhat.com>
+ */
+
+asm(
+".text\n"
+".global _start\n"
+"_start:\n"
+"   .short 0xaa55\n"
+"   .byte 0\n" /* size in 512 units, filled in by signrom.py */
+"   .byte 0xcb\n" /* far return without prefix */
+"   .org 0x18\n"
+"   .short 0\n"
+"   .short _pnph\n"
+"_pnph:\n"
+"   .ascii \"$PnP\"\n"
+"   .byte 0x01\n"
+"   .byte (_pnph_len / 16)\n"
+"   .short 0x0000\n"
+"   .byte 0x00\n"
+"   .byte 0x00\n"
+"   .long 0x00000000\n"
+"   .short _manufacturer\n"
+"   .short _product\n"
+"   .long 0x00000000\n"
+"   .short 0x0000\n"
+"   .short 0x0000\n"
+"   .short _bev\n"
+"   .short 0x0000\n"
+"   .short 0x0000\n"
+"   .equ _pnph_len, . - _pnph\n"
+"_manufacturer:\n"
+"   .asciz \"QEMU\"\n"
+"_product:\n"
+"   .asciz \"Linux loader DMA\"\n"
+"   .align 4, 0\n"
+"_bev:\n"
+"   cli\n"
+"   cld\n"
+"   jmp load_kernel\n"
+);
+
+#include "../../include/hw/nvram/fw_cfg_keys.h"
+
+/* QEMU_CFG_DMA_CONTROL bits */
+#define BIOS_CFG_DMA_CTL_ERROR   0x01
+#define BIOS_CFG_DMA_CTL_READ    0x02
+#define BIOS_CFG_DMA_CTL_SKIP    0x04
+#define BIOS_CFG_DMA_CTL_SELECT  0x08
+
+#define BIOS_CFG_DMA_ADDR_HIGH 0x514
+#define BIOS_CFG_DMA_ADDR_LOW  0x518
+
+#define uint64_t unsigned long long
+#define uint32_t unsigned int
+#define uint16_t unsigned short
+
+#define barrier() asm("" : : : "memory")
+
+typedef struct FWCfgDmaAccess {
+    uint32_t control;
+    uint32_t length;
+    uint64_t address;
+} __attribute__((packed)) FWCfgDmaAccess;
+
+static inline void outl(uint32_t value, uint16_t port)
+{
+    asm("outl %0, %w1" : : "a"(value), "Nd"(port));
+}
+
+static inline void set_es(void *addr)
+{
+    uint32_t seg = (uint32_t)addr >> 4;
+    asm("movl %0, %%es" : : "r"(seg));
+}
+
+#ifdef __clang__
+#define ADDR32
+#else
+#define ADDR32 "addr32 "
+#endif
+
+static inline uint16_t readw_es(uint16_t offset)
+{
+    uint16_t val;
+    asm(ADDR32 "movw %%es:(%1), %0" : "=r"(val) : "r"((uint32_t)offset));
+    barrier();
+    return val;
+}
+
+static inline uint32_t readl_es(uint16_t offset)
+{
+    uint32_t val;
+    asm(ADDR32 "movl %%es:(%1), %0" : "=r"(val) : "r"((uint32_t)offset));
+    barrier();
+    return val;
+}
+
+static inline void writel_es(uint16_t offset, uint32_t val)
+{
+    barrier();
+    asm(ADDR32 "movl %0, %%es:(%1)" : : "r"(val), "r"((uint32_t)offset));
+}
+
+static inline uint32_t bswap32(uint32_t x)
+{
+    return
+        ((x & 0x000000ffU) << 24) |
+        ((x & 0x0000ff00U) <<  8) |
+        ((x & 0x00ff0000U) >>  8) |
+        ((x & 0xff000000U) >> 24);
+}
+
+static inline uint64_t bswap64(uint64_t x)
+{
+    return
+        ((x & 0x00000000000000ffULL) << 56) |
+        ((x & 0x000000000000ff00ULL) << 40) |
+        ((x & 0x0000000000ff0000ULL) << 24) |
+        ((x & 0x00000000ff000000ULL) <<  8) |
+        ((x & 0x000000ff00000000ULL) >>  8) |
+        ((x & 0x0000ff0000000000ULL) >> 24) |
+        ((x & 0x00ff000000000000ULL) >> 40) |
+        ((x & 0xff00000000000000ULL) >> 56);
+}
+
+static inline uint64_t cpu_to_be64(uint64_t x)
+{
+    return bswap64(x);
+}
+
+static inline uint32_t cpu_to_be32(uint32_t x)
+{
+    return bswap32(x);
+}
+
+static inline uint32_t be32_to_cpu(uint32_t x)
+{
+    return bswap32(x);
+}
+
+static void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
+{
+    FWCfgDmaAccess access;
+    uint32_t control = (entry << 16) | BIOS_CFG_DMA_CTL_SELECT
+                        | BIOS_CFG_DMA_CTL_READ;
+
+    access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
+    access.length = cpu_to_be32(len);
+    access.control = cpu_to_be32(control);
+
+    barrier();
+
+    outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
+
+    while (be32_to_cpu(access.control) & ~BIOS_CFG_DMA_CTL_ERROR) {
+        barrier();
+    }
+}
+
+/* Return top of memory using BIOS function E801. */
+static uint32_t get_e801_addr(void)
+{
+    uint16_t ax, bx, cx, dx;
+    uint32_t ret;
+
+    asm("int $0x15\n"
+        : "=a"(ax), "=b"(bx), "=c"(cx), "=d"(dx)
+        : "a"(0xe801), "b"(0), "c"(0), "d"(0));
+
+    /* Not SeaBIOS, but in theory a BIOS could return CX=DX=0 in which
+     * case we need to use the result from AX & BX instead.
+     */
+    if (cx == 0 && dx == 0) {
+        cx = ax;
+        dx = bx;
+    }
+
+    if (dx) {
+        /* DX = extended memory above 16M, in 64K units.
+         * Convert it to bytes and return.
+         */
+        ret = ((uint32_t)dx + 256 /* 16M in 64K units */) << 16;
+    } else {
+        /* This is a fallback path for machines with <= 16MB of RAM,
+         * which probably would never be the case, but deal with it
+         * anyway.
+         *
+         * CX = extended memory between 1M and 16M, in kilobytes
+         * Convert it to bytes and return.
+         */
+        ret = ((uint32_t)cx + 1024 /* 1M in K */) << 10;
+    }
+
+    return ret;
+}
+
+void load_kernel(void)
+{
+    void *setup_addr;
+    void *initrd_addr;
+    void *kernel_addr;
+    void *cmdline_addr;
+    uint32_t setup_size;
+    uint32_t initrd_size;
+    uint32_t kernel_size;
+    uint32_t cmdline_size;
+    uint32_t initrd_end_page, max_allowed_page;
+    uint32_t segment_addr, stack_addr;
+
+    bios_cfg_read_entry(&setup_addr, FW_CFG_SETUP_ADDR, 4);
+    bios_cfg_read_entry(&setup_size, FW_CFG_SETUP_SIZE, 4);
+    bios_cfg_read_entry(setup_addr, FW_CFG_SETUP_DATA, setup_size);
+
+    set_es(setup_addr);
+
+    /* For protocol < 0x203 we don't have initrd_max ... */
+    if (readw_es(0x206) < 0x203) {
+        /* ... so we assume initrd_max = 0x37ffffff. */
+        writel_es(0x22c, 0x37ffffff);
+    }
+
+    bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
+    bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4);
+
+    initrd_end_page = ((uint32_t)(initrd_addr + initrd_size) & -4096);
+    max_allowed_page = (readl_es(0x22c) & -4096);
+
+    if (initrd_end_page != 0 && max_allowed_page != 0 &&
+        initrd_end_page != max_allowed_page) {
+        /* Initrd at the end of memory. Compute better initrd address
+         * based on e801 data
+         */
+        initrd_addr = (void *)((get_e801_addr() - initrd_size) & -4096);
+        writel_es(0x218, (uint32_t)initrd_addr);
+
+    }
+
+    bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
+
+    bios_cfg_read_entry(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
+    bios_cfg_read_entry(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
+    bios_cfg_read_entry(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
+
+    bios_cfg_read_entry(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4);
+    bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4);
+    bios_cfg_read_entry(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size);
+
+    /* Boot linux */
+    segment_addr = ((uint32_t)setup_addr >> 4);
+    stack_addr = (uint32_t)(cmdline_addr - setup_addr - 16);
+
+    /* As we are changing critical registers, we cannot leave freedom to the
+     * compiler.
+     */
+    asm("movw %%ax, %%ds\n"
+        "movw %%ax, %%es\n"
+        "movw %%ax, %%fs\n"
+        "movw %%ax, %%gs\n"
+        "movw %%ax, %%ss\n"
+        "movl %%ebx, %%esp\n"
+        "addw $0x20, %%ax\n"
+        "pushw %%ax\n" /* CS */
+        "pushw $0\n" /* IP */
+        /* Clear registers and jump to Linux */
+        "xor %%ebx, %%ebx\n"
+        "xor %%ecx, %%ecx\n"
+        "xor %%edx, %%edx\n"
+        "xor %%edi, %%edi\n"
+        "xor %%ebp, %%ebp\n"
+        "lretw\n"
+        : : "a"(segment_addr), "b"(stack_addr));
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-08-10 23:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14 13:52 [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Paolo Bonzini
2016-07-14 13:52 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini
2016-07-15 13:26   ` Stefan Hajnoczi
2016-07-15 15:02     ` Paolo Bonzini
2016-07-18  9:03     ` Paolo Bonzini
2016-08-06 23:53   ` Brad Smith
2016-08-08  8:50     ` Paolo Bonzini
2016-08-10 23:28       ` Brad Smith
2016-07-14 16:32 ` [Qemu-devel] [PULL v2 0/1] updated fw_cfg option ROM 2016-07-13 Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2016-07-13 12:55 [Qemu-devel] [PULL " Paolo Bonzini
2016-07-13 12:55 ` [Qemu-devel] [PULL 1/1] Add optionrom compatible with fw_cfg DMA version Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.