From: Jan Kiszka <[email protected]>

This simplifies the startup code and avoids having to specify the load
address explicitly, aligning x86 with ARM.

Signed-off-by: Jan Kiszka <[email protected]>
---
 Documentation/debug-output.md    |  8 +++---
 README.md                        | 10 ++++----
 configs/apic-demo.c              |  2 --
 configs/e1000-demo.c             |  2 --
 configs/ioapic-demo.c            |  2 --
 configs/ivshmem-demo.c           |  2 --
 configs/linux-x86-demo.c         |  2 --
 configs/pci-demo.c               |  2 --
 configs/smp-demo.c               |  2 --
 configs/tiny-demo.c              |  2 --
 inmates/lib/x86/header-32.S      | 12 +++------
 inmates/lib/x86/header.S         | 14 +++--------
 inmates/lib/x86/inmate.h         |  5 ++--
 inmates/lib/x86/inmate.lds       | 54 ++++++++++++++--------------------------
 inmates/lib/x86/smp.c            |  4 +--
 inmates/tools/x86/linux-loader.c |  2 +-
 tools/jailhouse-cell-linux       | 12 ++++-----
 17 files changed, 47 insertions(+), 90 deletions(-)

diff --git a/Documentation/debug-output.md b/Documentation/debug-output.md
index f9adca35..a6f18cd0 100644
--- a/Documentation/debug-output.md
+++ b/Documentation/debug-output.md
@@ -143,15 +143,15 @@ On x86, VGA output is not available for inmates.
 Example command line parameters for PIO based debug output on x86, where the
 inmate will initialise UART:
 
-    jailhouse cell load foocell inmate.bin -a 0xf0000 \
-        -s "con-base=0x3f8 con-divider=1" -a 0xf0000
+    jailhouse cell load foocell inmate.bin \
+        -s "con-base=0x3f8 con-divider=1" -a 0x100
 
 Example configuration for MMIO based debug output on ARM using the 8250 driver:
 
-    jailhouse cell load foocell inmate.bin -a 0x0 \
+    jailhouse cell load foocell inmate.bin \
         -s "con-type=8250 con-base=0x70006000 con-divider=0xdd" -a 0x100
 
 Example configuration for MMIO based debug output on ARM64 using the PL011 
driver:
 
-    jailhouse cell load foocell inmate.bin -a 0x0 \
+    jailhouse cell load foocell inmate.bin \
         -s "con-type=PL011 con-base=0xf7113000" -a 0x1000
diff --git a/README.md b/README.md
index c9fc175d..077592e1 100644
--- a/README.md
+++ b/README.md
@@ -289,7 +289,7 @@ like this:
 Next you can create a cell with a demonstration application as follows:
 
     jailhouse cell create /path/to/apic-demo.cell
-    jailhouse cell load apic-demo /path/to/apic-demo.bin -a 0xf0000
+    jailhouse cell load apic-demo /path/to/apic-demo.bin
     jailhouse cell start apic-demo
 
 apic-demo.bin is left by the built process in the inmates/demos/x86 directory.
@@ -324,8 +324,8 @@ To demonstrate the execution of a second, non-Linux cell, 
issue the following
 commands:
 
     jailhouse cell create /path/to/pci-demo.cell
-    jailhouse cell load pci-demo /path/to/pci-demo.bin -a 0xf0000 \
-        -s "con-base=0x2f8" -a 0xf0000
+    jailhouse cell load pci-demo /path/to/pci-demo.bin \
+        -s "con-base=0x2f8" -a 0x100
     jailhouse cell start pci-demo
 
 The pci-demo will use the second serial port provided by QEMU. You will find
@@ -337,8 +337,8 @@ the content of existing cell (provided they accept their 
shutdown first). To
 reload and restart the tiny-demo, issue the following commands:
 
     jailhouse cell start apic-demo
-    jailhouse cell load pci-demo /path/to/pci-demo.bin -a 0xf0000 \
-        -s "con-base=0x2f8" -a 0xf0000
+    jailhouse cell load pci-demo /path/to/pci-demo.bin \
+        -s "con-base=0x2f8" -a 0x100
     jailhouse cell start pci-demo
 
 Finally, Jailhouse is can be stopped completely again:
diff --git a/configs/apic-demo.c b/configs/apic-demo.c
index 9c8fed23..7f2de60a 100644
--- a/configs/apic-demo.c
+++ b/configs/apic-demo.c
@@ -35,8 +35,6 @@ struct {
                .num_irqchips = 0,
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = 0,
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/e1000-demo.c b/configs/e1000-demo.c
index 05696ab2..59a350ff 100644
--- a/configs/e1000-demo.c
+++ b/configs/e1000-demo.c
@@ -38,8 +38,6 @@ struct {
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                .num_pci_caps = ARRAY_SIZE(config.pci_caps),
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/ioapic-demo.c b/configs/ioapic-demo.c
index 2a95a7d8..4f12d12a 100644
--- a/configs/ioapic-demo.c
+++ b/configs/ioapic-demo.c
@@ -36,8 +36,6 @@ struct {
                .num_irqchips = ARRAY_SIZE(config.irqchips),
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = 0,
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/ivshmem-demo.c b/configs/ivshmem-demo.c
index 745c24db..8fa991fe 100644
--- a/configs/ivshmem-demo.c
+++ b/configs/ivshmem-demo.c
@@ -35,8 +35,6 @@ struct {
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                .num_pci_caps = ARRAY_SIZE(config.pci_caps),
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/linux-x86-demo.c b/configs/linux-x86-demo.c
index e094ada5..27c972df 100644
--- a/configs/linux-x86-demo.c
+++ b/configs/linux-x86-demo.c
@@ -47,8 +47,6 @@ struct {
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                .num_pci_caps = ARRAY_SIZE(config.pci_caps),
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/pci-demo.c b/configs/pci-demo.c
index 3bd9eb32..b15d4e0a 100644
--- a/configs/pci-demo.c
+++ b/configs/pci-demo.c
@@ -38,8 +38,6 @@ struct {
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                .num_pci_caps = ARRAY_SIZE(config.pci_caps),
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/smp-demo.c b/configs/smp-demo.c
index f4b8db1f..f05f029f 100644
--- a/configs/smp-demo.c
+++ b/configs/smp-demo.c
@@ -34,8 +34,6 @@ struct {
                .num_irqchips = 0,
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = 0,
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/configs/tiny-demo.c b/configs/tiny-demo.c
index 69ce7393..f31ac96b 100644
--- a/configs/tiny-demo.c
+++ b/configs/tiny-demo.c
@@ -36,8 +36,6 @@ struct {
                .num_irqchips = 0,
                .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                .num_pci_devices = 0,
-
-               .cpu_reset_address = 0xffff0,
        },
 
        .cpus = {
diff --git a/inmates/lib/x86/header-32.S b/inmates/lib/x86/header-32.S
index 4a3bfcc2..119f9555 100644
--- a/inmates/lib/x86/header-32.S
+++ b/inmates/lib/x86/header-32.S
@@ -52,19 +52,13 @@
 
        .globl __reset_entry
 __reset_entry:
-       ljmp $0xf000,$start16
-
-
-       .section ".startup", "ax"
-
-start16:
        lgdtl %cs:gdt_ptr
 
        mov %cr0,%eax
        or $X86_CR0_PE,%al
        mov %eax,%cr0
 
-       ljmpl $INMATE_CS32,$start32 + FSEGMENT_BASE
+       ljmpl $INMATE_CS32,$start32
 
 
        .code32
@@ -95,7 +89,7 @@ start32:
        jnz call_entry
 
        mov $1,%edi
-       lock xadd %edi,cpu_number + FSEGMENT_BASE
+       lock xadd %edi,cpu_number
 
        cmp $SMP_MAX_CPUS,%edi
        jae stop
@@ -155,7 +149,7 @@ loader_gdt:
 
 gdt_ptr:
        .short  gdt_ptr - loader_gdt - 1
-       .long   loader_gdt + FSEGMENT_BASE
+       .long   loader_gdt
 
 
        .section ".rodata"
diff --git a/inmates/lib/x86/header.S b/inmates/lib/x86/header.S
index de3717bb..95c7a5a4 100644
--- a/inmates/lib/x86/header.S
+++ b/inmates/lib/x86/header.S
@@ -55,19 +55,13 @@
 
        .globl __reset_entry
 __reset_entry:
-       ljmp $0xf000,$start16
-
-
-       .section ".startup", "ax"
-
-start16:
        lgdtl %cs:gdt_ptr
 
        mov %cr0,%eax
        or $X86_CR0_PE,%al
        mov %eax,%cr0
 
-       ljmpl $INMATE_CS32,$start32 + FSEGMENT_BASE
+       ljmpl $INMATE_CS32,$start32
 
 
        .code32
@@ -92,7 +86,7 @@ start32:
        mov $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE),%eax
        mov %eax,%cr0
 
-       ljmpl $INMATE_CS64,$start64 + FSEGMENT_BASE
+       ljmpl $INMATE_CS64,$start64
 
        .code64
 start64:
@@ -102,7 +96,7 @@ start64:
        jnz call_entry
 
        mov $1,%edi
-       lock xadd %edi,cpu_number + FSEGMENT_BASE
+       lock xadd %edi,cpu_number
 
        cmp $SMP_MAX_CPUS,%edi
        jae stop
@@ -160,7 +154,7 @@ gdt:
 
 gdt_ptr:
        .short  gdt_ptr - gdt - 1
-       .long   gdt + FSEGMENT_BASE
+       .long   gdt
 
 
        .section ".rodata"
diff --git a/inmates/lib/x86/inmate.h b/inmates/lib/x86/inmate.h
index cef30784..964a5435 100644
--- a/inmates/lib/x86/inmate.h
+++ b/inmates/lib/x86/inmate.h
@@ -39,8 +39,7 @@
 #ifndef _JAILHOUSE_INMATE_H
 #define _JAILHOUSE_INMATE_H
 
-#define HEAP_BASE              0x000000
-#define FSEGMENT_BASE          0x0f0000
+#define HEAP_BASE              ((unsigned long)stack_top)
 #define COMM_REGION_BASE       0x100000
 
 #define INMATE_CS32            0x8
@@ -255,6 +254,8 @@ extern volatile u32 smp_num_cpus;
 extern u8 smp_cpu_ids[SMP_MAX_CPUS];
 void smp_wait_for_all_cpus(void);
 void smp_start_cpu(unsigned int cpu_id, void (*entry)(void));
+
+extern const char stack_top[];
 #endif
 
 #include "../inmate_common.h"
diff --git a/inmates/lib/x86/inmate.lds b/inmates/lib/x86/inmate.lds
index 9ec0ca8b..526cf3b6 100644
--- a/inmates/lib/x86/inmate.lds
+++ b/inmates/lib/x86/inmate.lds
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013-2016
+ * Copyright (c) Siemens AG, 2013-2017
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -36,59 +36,43 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Layout:
- *  0x000000..        : heap (not configured here)
- *          ..0x0e0000: stack
- *  0x0e0000..0x0effff: bss
- *  0x0f0000..0x0fffef: command line, startup code, text, rodata, data
- *  0x0ffff0..0x0fffff: startup code (boot address)
- *  0x100000..0x100fff: communication region (not configured here)
- */
 SECTIONS
 {
        . = 0;
+       .boot           : { *(.boot) }
+
+       . = 0x100;
        .cmdline        : {
-               cmdline = 0xf0000; /* adjust relocation address of variable */
                *(.cmdline)
                BYTE(0); /* empty string in case no buffer is provided */
        }
 
-       /* 16-bit sections */
-       .startup        : { *(.startup) }
-
-       . = 0xfff0;
-       .boot           : {
-               *(.boot)
-               . = ALIGN(16);
-       }
-
-       /* 32/64-bit sections */
-       . = 0xe0000;
-       stack_top = .;
-       bss_start = .;
-       .bss            : {
-               *(.bss)
-               . = ALIGN(8);
-       }
-       bss_dwords = SIZEOF(.bss) / 4;
-       bss_qwords = SIZEOF(.bss) / 8;
-
-       . = 0xf0000 + ADDR(.startup) + SIZEOF(.startup);
-       .text           : AT (ADDR(.text) & 0xffff) {
+       .text           : {
                *(.text)
        }
 
        . = ALIGN(16);
-       .rodata         : AT (ADDR(.rodata) & 0xffff) {
+       .rodata         : {
                *(.rodata)
        }
 
        . = ALIGN(16);
-       .data           : AT (ADDR(.data) & 0xffff) {
+       .data           : {
                *(.data)
        }
 
+       .bss            : {
+               bss_start = .;
+               *(.bss)
+               . = ALIGN(8);
+       }
+       bss_dwords = SIZEOF(.bss) / 4;
+       bss_qwords = SIZEOF(.bss) / 8;
+
+       . = ALIGN(4096);
+       . += 0x1000;
+       stack_top = .;
+
        /DISCARD/ : {
                *(.eh_frame*)
        }
diff --git a/inmates/lib/x86/smp.c b/inmates/lib/x86/smp.c
index 7de00656..9b983611 100644
--- a/inmates/lib/x86/smp.c
+++ b/inmates/lib/x86/smp.c
@@ -57,9 +57,9 @@ void smp_start_cpu(unsigned int cpu_id, void (*entry)(void))
 
        write_msr(X2APIC_ICR, base_val | APIC_DM_INIT);
        delay_us(10000);
-       write_msr(X2APIC_ICR, base_val | APIC_DM_SIPI | 0xf0);
+       write_msr(X2APIC_ICR, base_val | APIC_DM_SIPI);
        delay_us(200);
-       write_msr(X2APIC_ICR, base_val | APIC_DM_SIPI | 0xf0);
+       write_msr(X2APIC_ICR, base_val | APIC_DM_SIPI);
 
        while (ap_entry != NULL)
                cpu_relax();
diff --git a/inmates/tools/x86/linux-loader.c b/inmates/tools/x86/linux-loader.c
index 78bb9c74..a05a6e09 100644
--- a/inmates/tools/x86/linux-loader.c
+++ b/inmates/tools/x86/linux-loader.c
@@ -12,7 +12,7 @@
 
 #include <inmate.h>
 
-#define ZERO_PAGE_ADDR         0xf5000UL
+#define ZERO_PAGE_ADDR         HEAP_BASE
 
 struct boot_params {
        u8      padding1[0x230];
diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
index c49e57b5..63ccffd2 100755
--- a/tools/jailhouse-cell-linux
+++ b/tools/jailhouse-cell-linux
@@ -246,6 +246,8 @@ class X86:
     name = 'x86'
 
     def setup(self, args, config):
+        self._cpu_reset_address = config.cpu_reset_address
+
         self._zero_page = X86ZeroPage(args.kernel, args.initrd, config)
 
         setup_data = x86_gen_setup_data()
@@ -278,13 +280,11 @@ jailhouse cell load %s linux-loader.bin -a 0x%x %s -a 
0x%x ' %
         print('%s -a 0x%x' % (args.write_params.name, arch.params_address()))
         print('jailhouse cell start %s' % config.name)
 
-    @staticmethod
-    def loader_address():
-        return 0xf0000
+    def loader_address(self):
+        return self._cpu_reset_address
 
-    @staticmethod
-    def params_address():
-        return 0xf5000
+    def params_address(self):
+        return self._cpu_reset_address + 0x6000
 
     def kernel_address(self):
         return self._zero_page.kernel_load_addr
-- 
2.12.3

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to