This patch moves the PVH boot logic handling code out of xen.cc
into a new file pvh-boot.cc. This is necessary to support
building kernels with a specific set of device drivers.

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
---
 Makefile             |  1 +
 arch/x64/pvh-boot.cc | 40 ++++++++++++++++++++++++++++++++++++++++
 arch/x64/xen.cc      | 38 --------------------------------------
 3 files changed, 41 insertions(+), 38 deletions(-)
 create mode 100644 arch/x64/pvh-boot.cc

diff --git a/Makefile b/Makefile
index 2f249ee4..59cc6de4 100644
--- a/Makefile
+++ b/Makefile
@@ -916,6 +916,7 @@ objects += arch/x64/apic-clock.o
 objects += arch/x64/entry-xen.o
 objects += arch/x64/vmlinux.o
 objects += arch/x64/vmlinux-boot64.o
+objects += arch/x64/pvh-boot.o
 objects += $(acpi)
 endif # x64
 
diff --git a/arch/x64/pvh-boot.cc b/arch/x64/pvh-boot.cc
new file mode 100644
index 00000000..406d39f8
--- /dev/null
+++ b/arch/x64/pvh-boot.cc
@@ -0,0 +1,40 @@
+#include "arch-setup.hh"
+#include <xen/interface/arch-x86/hvm/start_info.h>
+
+struct hvm_start_info* hvm_xen_start_info __attribute__((section(".data")));
+
+#define OSV_MULTI_BOOT_INFO_ADDR      0x1000
+#define OSV_E820_TABLE_ADDR           0x2000
+
+extern "C"
+void hvm_xen_extract_boot_params()
+{
+    // Set location of multiboot info struct at arbitrary place in lower memory
+    // to copy to (happens to be the same as in boot16.S)
+    osv_multiboot_info_type* mb_info = 
reinterpret_cast<osv_multiboot_info_type*>(OSV_MULTI_BOOT_INFO_ADDR);
+
+    // Copy command line pointer from boot params
+    mb_info->mb.cmdline = hvm_xen_start_info->cmdline_paddr;
+
+    // Copy e820 information from boot params
+    mb_info->mb.mmap_length = 0;
+    mb_info->mb.mmap_addr = OSV_E820_TABLE_ADDR;
+
+    struct hvm_memmap_table_entry *source_e820_table = reinterpret_cast<struct 
hvm_memmap_table_entry *>(hvm_xen_start_info->memmap_paddr);
+    struct e820ent *dest_e820_table = reinterpret_cast<struct e820ent 
*>(mb_info->mb.mmap_addr);
+
+    for (uint32_t e820_index = 0; e820_index < 
hvm_xen_start_info->memmap_entries; e820_index++) {
+        dest_e820_table[e820_index].ent_size = 20;
+        dest_e820_table[e820_index].type = source_e820_table[e820_index].type;
+        dest_e820_table[e820_index].addr = source_e820_table[e820_index].addr;
+        dest_e820_table[e820_index].size = source_e820_table[e820_index].size;
+        mb_info->mb.mmap_length += sizeof(e820ent);
+    }
+
+    // Save ACPI RDSP address in the field of the osv_multiboot_info_type 
structure
+    // Ideally, we would wanted to save it under the acpi::pvh_rsdp_paddr but 
it is
+    // to early in the boot process as it would have been overwritten later in 
premain().
+    mb_info->pvh_rsdp = hvm_xen_start_info->rsdp_paddr;
+
+    reset_bootchart(mb_info);
+}
diff --git a/arch/x64/xen.cc b/arch/x64/xen.cc
index 4e905653..d642c4fa 100644
--- a/arch/x64/xen.cc
+++ b/arch/x64/xen.cc
@@ -12,20 +12,17 @@
 #include "processor.hh"
 #include "cpuid.hh"
 #include "exceptions.hh"
-#include "arch-setup.hh"
 #include <osv/interrupt.hh>
 #include <osv/sched.hh>
 #include <bsd/porting/pcpu.h>
 #include <machine/xen/xen-os.h>
 #include <xen/evtchn.h>
-#include <xen/interface/arch-x86/hvm/start_info.h>
 
 shared_info_t *HYPERVISOR_shared_info;
 uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
 // make sure xen_start_info is not in .bss, or it will be overwritten
 // by init code, as xen_init() is called before .bss initialization
 struct start_info* xen_start_info __attribute__((section(".data")));
-struct hvm_start_info* hvm_xen_start_info __attribute__((section(".data")));
 
 namespace xen {
 
@@ -225,39 +222,4 @@ void xen_init(struct start_info* si)
     xen_start_info = si;
 }
 
-#define OSV_MULTI_BOOT_INFO_ADDR      0x1000
-#define OSV_E820_TABLE_ADDR           0x2000
-
-extern "C"
-void hvm_xen_extract_boot_params()
-{
-    // Set location of multiboot info struct at arbitrary place in lower memory
-    // to copy to (happens to be the same as in boot16.S)
-    osv_multiboot_info_type* mb_info = 
reinterpret_cast<osv_multiboot_info_type*>(OSV_MULTI_BOOT_INFO_ADDR);
-
-    // Copy command line pointer from boot params
-    mb_info->mb.cmdline = hvm_xen_start_info->cmdline_paddr;
-
-    // Copy e820 information from boot params
-    mb_info->mb.mmap_length = 0;
-    mb_info->mb.mmap_addr = OSV_E820_TABLE_ADDR;
-
-    struct hvm_memmap_table_entry *source_e820_table = reinterpret_cast<struct 
hvm_memmap_table_entry *>(hvm_xen_start_info->memmap_paddr);
-    struct e820ent *dest_e820_table = reinterpret_cast<struct e820ent 
*>(mb_info->mb.mmap_addr);
-
-    for (uint32_t e820_index = 0; e820_index < 
hvm_xen_start_info->memmap_entries; e820_index++) {
-        dest_e820_table[e820_index].ent_size = 20;
-        dest_e820_table[e820_index].type = source_e820_table[e820_index].type;
-        dest_e820_table[e820_index].addr = source_e820_table[e820_index].addr;
-        dest_e820_table[e820_index].size = source_e820_table[e820_index].size;
-        mb_info->mb.mmap_length += sizeof(e820ent);
-    }
-
-    // Save ACPI RDSP address in the field of the osv_multiboot_info_type 
structure
-    // Ideally, we would wanted to save it under the acpi::pvh_rsdp_paddr but 
it is
-    // to early in the boot process as it would have been overwritten later in 
premain().
-    mb_info->pvh_rsdp = hvm_xen_start_info->rsdp_paddr;
-
-    reset_bootchart(mb_info);
-}
 }
-- 
2.31.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20220209021847.514721-1-jwkozaczuk%40gmail.com.

Reply via email to