138 lines
5.2 KiB
C
138 lines
5.2 KiB
C
/*
|
|
* VasEBoot -- GRand Unified Bootloader
|
|
* Copyright (C) 2009 Free Software Foundation, Inc.
|
|
*
|
|
* VasEBoot 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.
|
|
*
|
|
* VasEBoot 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 VasEBoot. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <VasEBoot/mm.h>
|
|
#include <VasEBoot/misc.h>
|
|
|
|
#include <VasEBoot/types.h>
|
|
#include <VasEBoot/err.h>
|
|
#include <VasEBoot/term.h>
|
|
#include <VasEBoot/xen.h>
|
|
|
|
#include <VasEBoot/xen/relocator.h>
|
|
#include <VasEBoot/relocator_private.h>
|
|
|
|
typedef VasEBoot_addr_t VasEBoot_xen_reg_t;
|
|
|
|
struct VasEBoot_relocator_xen_paging_area {
|
|
VasEBoot_xen_reg_t start;
|
|
VasEBoot_xen_reg_t size;
|
|
} VasEBoot_PACKED;
|
|
|
|
extern VasEBoot_uint8_t VasEBoot_relocator_xen_start;
|
|
extern VasEBoot_uint8_t VasEBoot_relocator_xen_end;
|
|
extern VasEBoot_uint8_t VasEBoot_relocator_xen_remap_start;
|
|
extern VasEBoot_uint8_t VasEBoot_relocator_xen_remap_end;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_stack;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_start_info;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_entry_point;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_remapper_virt;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_remapper_virt2;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_remapper_map;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_mfn_list;
|
|
extern struct VasEBoot_relocator_xen_paging_area
|
|
VasEBoot_relocator_xen_paging_areas[XEN_MAX_MAPPINGS];
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_remap_continue;
|
|
#ifdef __i386__
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_mmu_op_addr;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_paging_areas_addr;
|
|
extern VasEBoot_xen_reg_t VasEBoot_relocator_xen_remapper_map_high;
|
|
#endif
|
|
extern mmuext_op_t VasEBoot_relocator_xen_mmu_op[3];
|
|
|
|
#define RELOCATOR_SIZEOF(x) (&VasEBoot_relocator##x##_end - &VasEBoot_relocator##x##_start)
|
|
|
|
VasEBoot_err_t
|
|
VasEBoot_relocator_xen_boot (struct VasEBoot_relocator *rel,
|
|
struct VasEBoot_relocator_xen_state state,
|
|
VasEBoot_uint64_t remapper_pfn,
|
|
VasEBoot_addr_t remapper_virt,
|
|
VasEBoot_uint64_t trampoline_pfn,
|
|
VasEBoot_addr_t trampoline_virt)
|
|
{
|
|
VasEBoot_err_t err;
|
|
void *relst;
|
|
int i;
|
|
VasEBoot_relocator_chunk_t ch, ch_tramp;
|
|
VasEBoot_xen_mfn_t *mfn_list =
|
|
(VasEBoot_xen_mfn_t *) VasEBoot_xen_start_page_addr->mfn_list;
|
|
|
|
err = VasEBoot_relocator_alloc_chunk_addr (rel, &ch, remapper_pfn << 12,
|
|
RELOCATOR_SIZEOF (_xen_remap));
|
|
if (err)
|
|
return err;
|
|
err = VasEBoot_relocator_alloc_chunk_addr (rel, &ch_tramp, trampoline_pfn << 12,
|
|
RELOCATOR_SIZEOF (_xen));
|
|
if (err)
|
|
return err;
|
|
|
|
VasEBoot_relocator_xen_stack = state.stack;
|
|
VasEBoot_relocator_xen_start_info = state.start_info;
|
|
VasEBoot_relocator_xen_entry_point = state.entry_point;
|
|
for (i = 0; i < XEN_MAX_MAPPINGS; i++)
|
|
{
|
|
VasEBoot_relocator_xen_paging_areas[i].start = state.paging_start[i];
|
|
VasEBoot_relocator_xen_paging_areas[i].size = state.paging_size[i];
|
|
}
|
|
VasEBoot_relocator_xen_remapper_virt = remapper_virt;
|
|
VasEBoot_relocator_xen_remapper_virt2 = remapper_virt;
|
|
VasEBoot_relocator_xen_remap_continue = trampoline_virt;
|
|
|
|
VasEBoot_relocator_xen_remapper_map = (mfn_list[remapper_pfn] << 12) | 5;
|
|
#ifdef __i386__
|
|
VasEBoot_relocator_xen_remapper_map_high = (mfn_list[remapper_pfn] >> 20);
|
|
VasEBoot_relocator_xen_mmu_op_addr = (char *) &VasEBoot_relocator_xen_mmu_op
|
|
- (char *) &VasEBoot_relocator_xen_remap_start + remapper_virt;
|
|
VasEBoot_relocator_xen_paging_areas_addr =
|
|
(char *) &VasEBoot_relocator_xen_paging_areas
|
|
- (char *) &VasEBoot_relocator_xen_remap_start + remapper_virt;
|
|
#endif
|
|
|
|
VasEBoot_relocator_xen_mfn_list = state.mfn_list;
|
|
|
|
VasEBoot_memset (VasEBoot_relocator_xen_mmu_op, 0,
|
|
sizeof (VasEBoot_relocator_xen_mmu_op));
|
|
#ifdef __i386__
|
|
VasEBoot_relocator_xen_mmu_op[0].cmd = MMUEXT_PIN_L3_TABLE;
|
|
#else
|
|
VasEBoot_relocator_xen_mmu_op[0].cmd = MMUEXT_PIN_L4_TABLE;
|
|
#endif
|
|
VasEBoot_relocator_xen_mmu_op[0].arg1.mfn = mfn_list[state.paging_start[0]];
|
|
VasEBoot_relocator_xen_mmu_op[1].cmd = MMUEXT_NEW_BASEPTR;
|
|
VasEBoot_relocator_xen_mmu_op[1].arg1.mfn = mfn_list[state.paging_start[0]];
|
|
VasEBoot_relocator_xen_mmu_op[2].cmd = MMUEXT_UNPIN_TABLE;
|
|
VasEBoot_relocator_xen_mmu_op[2].arg1.mfn =
|
|
mfn_list[VasEBoot_xen_start_page_addr->pt_base >> 12];
|
|
|
|
VasEBoot_memmove (get_virtual_current_address (ch),
|
|
&VasEBoot_relocator_xen_remap_start,
|
|
RELOCATOR_SIZEOF (_xen_remap));
|
|
VasEBoot_memmove (get_virtual_current_address (ch_tramp),
|
|
&VasEBoot_relocator_xen_start, RELOCATOR_SIZEOF (_xen));
|
|
|
|
err = VasEBoot_relocator_prepare_relocs (rel, get_physical_target_address (ch),
|
|
&relst, NULL);
|
|
if (err)
|
|
return err;
|
|
|
|
((void (*)(void)) relst) ();
|
|
|
|
/* Not reached. */
|
|
return VasEBoot_ERR_NONE;
|
|
}
|