Add new ports: i386-xen and x86_64-xen. This allows running GRUB in

XEN PV environment and load kernels.
This commit is contained in:
Vladimir Serbinenko 2013-11-09 21:29:11 +01:00
parent 1a46a3a4b3
commit 9612ebc00e
59 changed files with 4167 additions and 259 deletions

View file

@ -48,6 +48,7 @@ enum grub_disk_dev_id
GRUB_DISK_DEVICE_PROCFS_ID,
GRUB_DISK_DEVICE_CBFSDISK_ID,
GRUB_DISK_DEVICE_UBOOTDISK_ID,
GRUB_DISK_DEVICE_XEN,
};
struct grub_disk;

View file

@ -2454,7 +2454,9 @@ typedef Elf32_Addr Elf32_Conflict;
#if GRUB_TARGET_WORDSIZE == 32
typedef Elf32_Addr Elf_Addr;
typedef Elf32_Nhdr Elf_Nhdr;
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
typedef Elf32_Half Elf_Half;
typedef Elf32_Off Elf_Off;
typedef Elf32_Rel Elf_Rel;
@ -2477,7 +2479,9 @@ typedef Elf32_Xword Elf_Xword;
#elif GRUB_TARGET_WORDSIZE == 64
typedef Elf64_Addr Elf_Addr;
typedef Elf64_Nhdr Elf_Nhdr;
typedef Elf64_Ehdr Elf_Ehdr;
typedef Elf64_Phdr Elf_Phdr;
typedef Elf64_Half Elf_Half;
typedef Elf64_Off Elf_Off;
typedef Elf64_Rel Elf_Rel;

View file

@ -158,4 +158,10 @@ grub_file_seekable (const grub_file_t file)
return !file->not_easily_seekable;
}
grub_file_t
grub_file_offset_open (grub_file_t parent, grub_off_t start,
grub_off_t size);
void
grub_file_offset_close (grub_file_t file);
#endif /* ! GRUB_FILE_HEADER */

View file

@ -0,0 +1,85 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_XEN_CPU_HYPERCALL_HEADER
#define GRUB_XEN_CPU_HYPERCALL_HEADER 1
#include <grub/types.h>
int
EXPORT_FUNC (grub_xen_hypercall) (grub_uint32_t callno, grub_uint32_t a0,
grub_uint32_t a1, grub_uint32_t a2,
grub_uint32_t a3, grub_uint32_t a4,
grub_uint32_t a5)
__attribute__ ((regparm (3), stdcall));
static inline int
grub_xen_sched_op (int cmd, void *arg)
{
return grub_xen_hypercall (__HYPERVISOR_sched_op, cmd, (grub_uint32_t) arg,
0, 0, 0, 0);
}
static inline int
grub_xen_mmu_update (const struct mmu_update *reqs,
unsigned count, unsigned *done_out, unsigned foreigndom)
{
return grub_xen_hypercall (__HYPERVISOR_mmu_update, (grub_uint32_t) reqs,
(grub_uint32_t) count, (grub_uint32_t) done_out,
(grub_uint32_t) foreigndom, 0, 0);
}
static inline int
grub_xen_mmuext_op (mmuext_op_t * ops,
unsigned int count,
unsigned int *pdone, unsigned int foreigndom)
{
return grub_xen_hypercall (__HYPERVISOR_mmuext_op, (grub_uint32_t) ops,
count, (grub_uint32_t) pdone, foreigndom, 0, 0);
}
static inline int
grub_xen_event_channel_op (int op, void *arg)
{
return grub_xen_hypercall (__HYPERVISOR_event_channel_op, op,
(grub_uint32_t) arg, 0, 0, 0, 0);
}
static inline int
grub_xen_update_va_mapping (void *addr, uint64_t pte, uint32_t flags)
{
return grub_xen_hypercall (__HYPERVISOR_update_va_mapping,
(grub_uint32_t) addr, pte, pte >> 32, flags, 0,
0);
}
static inline int
grub_xen_grant_table_op (int a, void *b, int c)
{
return grub_xen_hypercall (__HYPERVISOR_grant_table_op, a,
(grub_uint32_t) b, c, 0, 0, 0);
}
static inline int
grub_xen_vm_assist (int cmd, int type)
{
return grub_xen_hypercall (__HYPERVISOR_vm_assist, cmd, type, 0, 0, 0, 0);
}
#endif

View file

View file

@ -78,7 +78,7 @@ struct grub_module_info64
#if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) \
|| defined (GRUB_MACHINE_MULTIBOOT) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) \
|| defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_ARC) \
|| defined (__sparc__) || defined (GRUB_MACHINE_UBOOT)
|| defined (__sparc__) || defined (GRUB_MACHINE_UBOOT) || defined (GRUB_MACHINE_XEN)
/* FIXME: stack is between 2 heap regions. Move it. */
#define GRUB_KERNEL_PRELOAD_SPACE_REUSABLE 1
#endif
@ -114,7 +114,7 @@ void grub_main (void) __attribute__ ((noreturn));
void grub_machine_init (void);
/* The machine-specific finalization. */
void EXPORT_FUNC(grub_machine_fini) (void);
void EXPORT_FUNC(grub_machine_fini) (int flags);
/* The machine-specific prefix initialization. */
void

View file

@ -99,7 +99,12 @@
#define GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN 0x1
#define GRUB_KERNEL_I386_MULTIBOOT_MOD_ALIGN GRUB_KERNEL_I386_COREBOOT_MOD_ALIGN
#define GRUB_KERNEL_X86_64_XEN_MOD_ALIGN 0x8
#define GRUB_KERNEL_I386_XEN_MOD_ALIGN 0x8
/* Non-zero value is only needed for PowerMacs. */
#define GRUB_KERNEL_X86_64_XEN_MOD_GAP 0x0
#define GRUB_KERNEL_I386_XEN_MOD_GAP 0x0
#define GRUB_KERNEL_I386_IEEE1275_MOD_GAP 0x0
#define GRUB_KERNEL_I386_COREBOOT_MOD_GAP 0x0
#define GRUB_KERNEL_SPARC64_IEEE1275_MOD_GAP 0x0

View file

@ -0,0 +1,34 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_XEN_CPU_HYPERCALL_HEADER
#define GRUB_XEN_CPU_HYPERCALL_HEADER 1
int EXPORT_FUNC (grub_xen_sched_op) (int cmd, void *arg);
int grub_xen_update_va_mapping (void *addr, uint64_t pte, uint64_t flags);
int grub_xen_event_channel_op (int op, void *arg);
int grub_xen_mmuext_op (mmuext_op_t * ops,
unsigned int count,
unsigned int *pdone, unsigned int foreigndom);
int EXPORT_FUNC (grub_xen_mmu_update) (const struct mmu_update * reqs,
unsigned count, unsigned *done_out,
unsigned foreigndom);
int EXPORT_FUNC (grub_xen_grant_table_op) (int, void *, int);
#endif

93
include/grub/xen.h Normal file
View file

@ -0,0 +1,93 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_XEN_HEADER
#define GRUB_XEN_HEADER 1
#define __XEN_INTERFACE_VERSION__ 0x0003020a
#ifdef ASM_FILE
#define __ASSEMBLY__
#include <xen/xen.h>
#else
#include <grub/symbol.h>
#include <grub/types.h>
#include <grub/err.h>
#ifndef GRUB_SYMBOL_GENERATOR
#include <stdint.h>
#include <xen/xen.h>
#include <xen/sched.h>
#include <xen/grant_table.h>
#include <xen/io/console.h>
#include <xen/io/xs_wire.h>
#include <xen/io/xenbus.h>
#include <xen/io/protocols.h>
#endif
#include <grub/cpu/xen/hypercall.h>
extern grub_size_t EXPORT_VAR (grub_xen_n_allocated_shared_pages);
#define GRUB_XEN_LOG_PAGE_SIZE 12
#define GRUB_XEN_PAGE_SIZE (1 << GRUB_XEN_LOG_PAGE_SIZE)
extern volatile struct xencons_interface *grub_xen_xcons;
extern volatile struct shared_info *EXPORT_VAR (grub_xen_shared_info);
extern volatile struct xenstore_domain_interface *grub_xen_xenstore;
extern volatile grant_entry_v2_t *grub_xen_grant_table;
void EXPORT_FUNC (grub_xen_store_send) (const void *buf_, grub_size_t len);
void EXPORT_FUNC (grub_xen_store_recv) (void *buf_, grub_size_t len);
grub_err_t
EXPORT_FUNC (grub_xenstore_dir) (const char *dir,
int (*hook) (const char *dir,
void *hook_data),
void *hook_data);
void *EXPORT_FUNC (grub_xenstore_get_file) (const char *dir,
grub_size_t * len);
grub_err_t EXPORT_FUNC (grub_xenstore_write_file) (const char *dir,
const void *buf,
grub_size_t len);
typedef unsigned int grub_xen_grant_t;
void *EXPORT_FUNC (grub_xen_alloc_shared_page) (domid_t dom,
grub_xen_grant_t * grnum);
void EXPORT_FUNC (grub_xen_free_shared_page) (void *ptr);
#define mb() asm volatile("mfence;sfence;" : : : "memory");
extern struct start_info *EXPORT_VAR (grub_xen_start_page_addr);
void grub_console_init (void);
void grub_xendisk_fini (void);
void grub_xendisk_init (void);
#ifdef __x86_64__
typedef grub_uint64_t grub_xen_mfn_t;
#else
typedef grub_uint32_t grub_xen_mfn_t;
#endif
typedef unsigned int grub_xen_evtchn_t;
#endif
#endif

View file

@ -0,0 +1,44 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_RELOCATOR_XEN_HEADER
#define GRUB_RELOCATOR_XEN_HEADER 1
#include <grub/types.h>
#include <grub/err.h>
#include <grub/relocator.h>
struct grub_relocator_xen_state
{
grub_addr_t start_info;
grub_addr_t paging_start;
grub_addr_t paging_size;
grub_addr_t mfn_list;
grub_addr_t stack;
grub_addr_t entry_point;
};
grub_err_t
grub_relocator_xen_boot (struct grub_relocator *rel,
struct grub_relocator_xen_state state,
grub_uint64_t remapper_pfn,
grub_addr_t remapper_virt,
grub_uint64_t trampoline_pfn,
grub_addr_t trampoline_virt);
#endif

54
include/grub/xen_file.h Normal file
View file

@ -0,0 +1,54 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* GRUB 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 3 of the License, or
* (at your option) any later version.
*
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GRUB_XEN_FILE_HEADER
#define GRUB_XEN_FILE_HEADER 1
#include <grub/types.h>
#include <grub/elf.h>
#include <grub/elfload.h>
grub_elf_t grub_xen_file (grub_file_t file);
struct grub_xen_file_info
{
grub_uint64_t kern_start, kern_end;
grub_uint64_t virt_base;
grub_uint64_t entry_point;
grub_uint64_t hypercall_page;
grub_uint64_t paddr_offset;
int has_hypercall_page;
int has_note;
int has_xen_guest;
int extended_cr3;
enum
{
GRUB_XEN_FILE_I386 = 1,
GRUB_XEN_FILE_I386_PAE = 2,
GRUB_XEN_FILE_I386_PAE_BIMODE = 3,
GRUB_XEN_FILE_X86_64 = 4
} arch;
};
grub_err_t
grub_xen_get_info32 (grub_elf_t elf, struct grub_xen_file_info *xi);
grub_err_t
grub_xen_get_info64 (grub_elf_t elf, struct grub_xen_file_info *xi);
grub_err_t grub_xen_get_info (grub_elf_t elf, struct grub_xen_file_info *xi);
#endif