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:
parent
1a46a3a4b3
commit
9612ebc00e
59 changed files with 4167 additions and 259 deletions
|
@ -58,4 +58,3 @@ grub_reboot (void)
|
|||
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,19 +28,6 @@
|
|||
#include <grub/i386/relocator_private.h>
|
||||
#include <grub/i386/pc/int.h>
|
||||
|
||||
extern grub_uint8_t grub_relocator_forward_start;
|
||||
extern grub_uint8_t grub_relocator_forward_end;
|
||||
extern grub_uint8_t grub_relocator_backward_start;
|
||||
extern grub_uint8_t grub_relocator_backward_end;
|
||||
|
||||
extern void *grub_relocator_backward_dest;
|
||||
extern void *grub_relocator_backward_src;
|
||||
extern grub_size_t grub_relocator_backward_chunk_size;
|
||||
|
||||
extern void *grub_relocator_forward_dest;
|
||||
extern void *grub_relocator_forward_src;
|
||||
extern grub_size_t grub_relocator_forward_chunk_size;
|
||||
|
||||
extern grub_uint8_t grub_relocator16_start;
|
||||
extern grub_uint8_t grub_relocator16_end;
|
||||
extern grub_uint16_t grub_relocator16_cs;
|
||||
|
@ -85,75 +72,6 @@ extern struct grub_i386_idt grub_relocator16_idt;
|
|||
|
||||
#define RELOCATOR_SIZEOF(x) (&grub_relocator##x##_end - &grub_relocator##x##_start)
|
||||
|
||||
grub_size_t grub_relocator_align = 1;
|
||||
grub_size_t grub_relocator_forward_size;
|
||||
grub_size_t grub_relocator_backward_size;
|
||||
#ifdef __x86_64__
|
||||
grub_size_t grub_relocator_jumper_size = 12;
|
||||
#else
|
||||
grub_size_t grub_relocator_jumper_size = 7;
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_cpu_relocator_init (void)
|
||||
{
|
||||
grub_relocator_forward_size = RELOCATOR_SIZEOF(_forward);
|
||||
grub_relocator_backward_size = RELOCATOR_SIZEOF(_backward);
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
ptr = rels;
|
||||
#ifdef __x86_64__
|
||||
/* movq imm64, %rax (for relocator) */
|
||||
*(grub_uint8_t *) ptr = 0x48;
|
||||
ptr++;
|
||||
*(grub_uint8_t *) ptr = 0xb8;
|
||||
ptr++;
|
||||
*(grub_uint64_t *) ptr = addr;
|
||||
ptr += sizeof (grub_uint64_t);
|
||||
#else
|
||||
/* movl imm32, %eax (for relocator) */
|
||||
*(grub_uint8_t *) ptr = 0xb8;
|
||||
ptr++;
|
||||
*(grub_uint32_t *) ptr = addr;
|
||||
ptr += sizeof (grub_uint32_t);
|
||||
#endif
|
||||
/* jmp $eax/$rax */
|
||||
*(grub_uint8_t *) ptr = 0xff;
|
||||
ptr++;
|
||||
*(grub_uint8_t *) ptr = 0xe0;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_backward (void *ptr, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_relocator_backward_dest = dest;
|
||||
grub_relocator_backward_src = src;
|
||||
grub_relocator_backward_chunk_size = size;
|
||||
|
||||
grub_memmove (ptr,
|
||||
&grub_relocator_backward_start,
|
||||
RELOCATOR_SIZEOF (_backward));
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_forward (void *ptr, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_relocator_forward_dest = dest;
|
||||
grub_relocator_forward_src = src;
|
||||
grub_relocator_forward_chunk_size = size;
|
||||
|
||||
grub_memmove (ptr,
|
||||
&grub_relocator_forward_start,
|
||||
RELOCATOR_SIZEOF (_forward));
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_relocator32_boot (struct grub_relocator *rel,
|
||||
struct grub_relocator32_state state,
|
||||
|
|
109
grub-core/lib/i386/relocator_common_c.c
Normal file
109
grub-core/lib/i386/relocator_common_c.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009-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/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
#include <grub/relocator.h>
|
||||
#include <grub/relocator_private.h>
|
||||
|
||||
extern grub_uint8_t grub_relocator_forward_start;
|
||||
extern grub_uint8_t grub_relocator_forward_end;
|
||||
extern grub_uint8_t grub_relocator_backward_start;
|
||||
extern grub_uint8_t grub_relocator_backward_end;
|
||||
|
||||
extern void *grub_relocator_backward_dest;
|
||||
extern void *grub_relocator_backward_src;
|
||||
extern grub_size_t grub_relocator_backward_chunk_size;
|
||||
|
||||
extern void *grub_relocator_forward_dest;
|
||||
extern void *grub_relocator_forward_src;
|
||||
extern grub_size_t grub_relocator_forward_chunk_size;
|
||||
|
||||
#define RELOCATOR_SIZEOF(x) (&grub_relocator##x##_end - &grub_relocator##x##_start)
|
||||
|
||||
grub_size_t grub_relocator_align = 1;
|
||||
grub_size_t grub_relocator_forward_size;
|
||||
grub_size_t grub_relocator_backward_size;
|
||||
#ifdef __x86_64__
|
||||
grub_size_t grub_relocator_jumper_size = 12;
|
||||
#else
|
||||
grub_size_t grub_relocator_jumper_size = 7;
|
||||
#endif
|
||||
|
||||
void
|
||||
grub_cpu_relocator_init (void)
|
||||
{
|
||||
grub_relocator_forward_size = RELOCATOR_SIZEOF (_forward);
|
||||
grub_relocator_backward_size = RELOCATOR_SIZEOF (_backward);
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_jumper (void *rels, grub_addr_t addr)
|
||||
{
|
||||
grub_uint8_t *ptr;
|
||||
ptr = rels;
|
||||
#ifdef __x86_64__
|
||||
/* movq imm64, %rax (for relocator) */
|
||||
*(grub_uint8_t *) ptr = 0x48;
|
||||
ptr++;
|
||||
*(grub_uint8_t *) ptr = 0xb8;
|
||||
ptr++;
|
||||
*(grub_uint64_t *) ptr = addr;
|
||||
ptr += sizeof (grub_uint64_t);
|
||||
#else
|
||||
/* movl imm32, %eax (for relocator) */
|
||||
*(grub_uint8_t *) ptr = 0xb8;
|
||||
ptr++;
|
||||
*(grub_uint32_t *) ptr = addr;
|
||||
ptr += sizeof (grub_uint32_t);
|
||||
#endif
|
||||
/* jmp $eax/$rax */
|
||||
*(grub_uint8_t *) ptr = 0xff;
|
||||
ptr++;
|
||||
*(grub_uint8_t *) ptr = 0xe0;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_backward (void *ptr, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_relocator_backward_dest = dest;
|
||||
grub_relocator_backward_src = src;
|
||||
grub_relocator_backward_chunk_size = size;
|
||||
|
||||
grub_memmove (ptr,
|
||||
&grub_relocator_backward_start, RELOCATOR_SIZEOF (_backward));
|
||||
}
|
||||
|
||||
void
|
||||
grub_cpu_relocator_forward (void *ptr, void *src, void *dest,
|
||||
grub_size_t size)
|
||||
{
|
||||
grub_relocator_forward_dest = dest;
|
||||
grub_relocator_forward_src = src;
|
||||
grub_relocator_forward_chunk_size = size;
|
||||
|
||||
grub_memmove (ptr,
|
||||
&grub_relocator_forward_start, RELOCATOR_SIZEOF (_forward));
|
||||
}
|
146
grub-core/lib/i386/xen/relocator.S
Normal file
146
grub-core/lib/i386/xen/relocator.S
Normal file
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_relocator_xen_remap_start)
|
||||
LOCAL(base):
|
||||
/* mov imm32, %ebx */
|
||||
.byte 0xbb
|
||||
VARIABLE(grub_relocator_xen_remapper_virt)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator_xen_remapper_map)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %edx */
|
||||
.byte 0xba
|
||||
VARIABLE(grub_relocator_xen_remapper_map_high)
|
||||
.long 0
|
||||
|
||||
movl $2, %esi
|
||||
movl $__HYPERVISOR_update_va_mapping, %eax
|
||||
int $0x82
|
||||
|
||||
addl $(LOCAL(cont) - LOCAL(base)), %ebx
|
||||
|
||||
jmp *%ebx
|
||||
|
||||
LOCAL(cont):
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator_xen_paging_size)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %ebx */
|
||||
.byte 0xbb
|
||||
VARIABLE(grub_relocator_xen_paging_start)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_mfn_list)
|
||||
.long 0
|
||||
|
||||
movl %eax, %edi
|
||||
1:
|
||||
movl %ecx, %ebp
|
||||
movl 0(%edi), %ecx
|
||||
movl %ecx, %edx
|
||||
shll $12, %ecx
|
||||
shrl $20, %edx
|
||||
orl $5, %ecx
|
||||
movl $2, %esi
|
||||
movl $__HYPERVISOR_update_va_mapping, %eax
|
||||
int $0x82
|
||||
|
||||
movl %ebp, %ecx
|
||||
addl $4, %edi
|
||||
addl $4096, %ebx
|
||||
|
||||
loop 1b
|
||||
|
||||
/* mov imm32, %ebx */
|
||||
.byte 0xbb
|
||||
VARIABLE(grub_relocator_xen_mmu_op_addr)
|
||||
.long 0
|
||||
movl $3, %ecx
|
||||
movl $0, %edx
|
||||
movl $0x7FF0, %esi
|
||||
movl $__HYPERVISOR_mmuext_op, %eax
|
||||
int $0x82
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remap_continue)
|
||||
.long 0
|
||||
|
||||
jmp *%eax
|
||||
|
||||
VARIABLE(grub_relocator_xen_mmu_op)
|
||||
.space 256
|
||||
|
||||
VARIABLE(grub_relocator_xen_remap_end)
|
||||
|
||||
|
||||
VARIABLE(grub_relocator_xen_start)
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remapper_virt2)
|
||||
.long 0
|
||||
|
||||
movl %eax, %edi
|
||||
|
||||
xorl %ecx, %ecx
|
||||
xorl %edx, %edx
|
||||
|
||||
movl $2, %esi
|
||||
movl $__HYPERVISOR_update_va_mapping, %eax
|
||||
int $0x82
|
||||
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_stack)
|
||||
.long 0
|
||||
|
||||
movl %eax, %esp
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_start_info)
|
||||
.long 0
|
||||
|
||||
movl %eax, %esi
|
||||
|
||||
cld
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_entry_point)
|
||||
.long 0
|
||||
|
||||
jmp *%eax
|
||||
|
||||
VARIABLE(grub_relocator_xen_end)
|
|
@ -250,6 +250,9 @@ static struct legacy_command legacy_commands[] =
|
|||
{"pause", "echo %s; if ! sleep -i 60; then return; fi\n", NULL, 0, 1,
|
||||
{TYPE_REST_VERBATIM}, 0,
|
||||
"[MESSAGE ...]", "Print MESSAGE, then wait until a key is pressed."},
|
||||
{"print", "echo %s\n", NULL, 0, 1,
|
||||
{TYPE_REST_VERBATIM}, 0,
|
||||
"[MESSAGE ...]", "Print MESSAGE."},
|
||||
/* FIXME: quit unsupported. */
|
||||
/* FIXME: rarp unsupported. */
|
||||
{"read", "read_dword %s\n", NULL, 0, 1, {TYPE_INT}, 0, "ADDR",
|
||||
|
|
|
@ -1432,7 +1432,7 @@ grub_relocator_alloc_chunk_align (struct grub_relocator *rel,
|
|||
#ifdef GRUB_MACHINE_EFI
|
||||
grub_efi_mmap_iterate (grub_relocator_alloc_chunk_align_iter, &ctx,
|
||||
avoid_efi_boot_services);
|
||||
#elif defined (__powerpc__)
|
||||
#elif defined (__powerpc__) || defined (GRUB_MACHINE_XEN)
|
||||
(void) avoid_efi_boot_services;
|
||||
grub_machine_mmap_iterate (grub_relocator_alloc_chunk_align_iter, &ctx);
|
||||
#else
|
||||
|
|
154
grub-core/lib/x86_64/xen/relocator.S
Normal file
154
grub-core/lib/x86_64/xen/relocator.S
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_relocator_xen_remap_start)
|
||||
LOCAL(base):
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remapper_virt)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rdi
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remapper_map)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsi
|
||||
|
||||
movq $2, %rdx
|
||||
movq $__HYPERVISOR_update_va_mapping, %rax
|
||||
syscall
|
||||
|
||||
addq $(LOCAL(cont) - LOCAL(base)), %rdi
|
||||
|
||||
jmp *%rdi
|
||||
|
||||
LOCAL(cont):
|
||||
|
||||
/* mov imm64, %rcx */
|
||||
.byte 0x48
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator_xen_paging_size)
|
||||
.quad 0
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_paging_start)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rdi
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_mfn_list)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsi
|
||||
1:
|
||||
movq %rsi, %rbx
|
||||
movq 0(%rsi), %rsi
|
||||
shlq $12, %rsi
|
||||
orq $5, %rsi
|
||||
movq $2, %rdx
|
||||
movq %rcx, %r9
|
||||
movq $__HYPERVISOR_update_va_mapping, %rax
|
||||
syscall
|
||||
|
||||
movq %r9, %rcx
|
||||
addq $8, %rbx
|
||||
addq $4096, %rdi
|
||||
movq %rbx, %rsi
|
||||
|
||||
loop 1b
|
||||
|
||||
leaq EXT_C(grub_relocator_xen_mmu_op) (%rip), %rdi
|
||||
movq $3, %rsi
|
||||
movq $0, %rdx
|
||||
movq $0x7FF0, %r10
|
||||
movq $__HYPERVISOR_mmuext_op, %rax
|
||||
syscall
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remap_continue)
|
||||
.quad 0
|
||||
|
||||
jmp *%rax
|
||||
|
||||
VARIABLE(grub_relocator_xen_mmu_op)
|
||||
.space 256
|
||||
|
||||
VARIABLE(grub_relocator_xen_remap_end)
|
||||
|
||||
|
||||
VARIABLE(grub_relocator_xen_start)
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_remapper_virt2)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rdi
|
||||
|
||||
xorq %rax, %rax
|
||||
movq %rax, %rsi
|
||||
|
||||
movq $2, %rdx
|
||||
movq $__HYPERVISOR_update_va_mapping, %rax
|
||||
syscall
|
||||
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_stack)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsp
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_start_info)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsi
|
||||
|
||||
cld
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_xen_entry_point)
|
||||
.quad 0
|
||||
|
||||
jmp *%rax
|
||||
|
||||
VARIABLE(grub_relocator_xen_end)
|
40
grub-core/lib/xen/datetime.c
Normal file
40
grub-core/lib/xen/datetime.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/datetime.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
GRUB_MOD_LICENSE ("GPLv3+");
|
||||
|
||||
grub_err_t
|
||||
grub_get_datetime (struct grub_datetime *datetime)
|
||||
{
|
||||
long long nix;
|
||||
nix = (grub_xen_shared_info->wc_sec
|
||||
+ grub_divmod64 (grub_xen_shared_info->vcpu_info[0].time.system_time, 1000000000, 0));
|
||||
grub_unixtime2datetime (nix, datetime);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_set_datetime (struct grub_datetime *datetime __attribute__ ((unused)))
|
||||
{
|
||||
return grub_error (GRUB_ERR_IO, "setting time isn't supported");
|
||||
}
|
32
grub-core/lib/xen/halt.c
Normal file
32
grub-core/lib/xen/halt.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
void
|
||||
grub_halt (void)
|
||||
{
|
||||
struct sched_shutdown arg;
|
||||
|
||||
arg.reason = SHUTDOWN_poweroff;
|
||||
grub_xen_sched_op (SCHEDOP_shutdown, &arg);
|
||||
for (;;);
|
||||
}
|
32
grub-core/lib/xen/reboot.c
Normal file
32
grub-core/lib/xen/reboot.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2011 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
void
|
||||
grub_reboot (void)
|
||||
{
|
||||
struct sched_shutdown arg;
|
||||
|
||||
arg.reason = SHUTDOWN_reboot;
|
||||
grub_xen_sched_op (SCHEDOP_shutdown, &arg);
|
||||
for (;;);
|
||||
}
|
125
grub-core/lib/xen/relocator.c
Normal file
125
grub-core/lib/xen/relocator.c
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009 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/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/xen.h>
|
||||
|
||||
#include <grub/xen/relocator.h>
|
||||
#include <grub/relocator_private.h>
|
||||
|
||||
typedef grub_addr_t grub_xen_reg_t;
|
||||
|
||||
extern grub_uint8_t grub_relocator_xen_start;
|
||||
extern grub_uint8_t grub_relocator_xen_end;
|
||||
extern grub_uint8_t grub_relocator_xen_remap_start;
|
||||
extern grub_uint8_t grub_relocator_xen_remap_end;
|
||||
extern grub_xen_reg_t grub_relocator_xen_stack;
|
||||
extern grub_xen_reg_t grub_relocator_xen_start_info;
|
||||
extern grub_xen_reg_t grub_relocator_xen_entry_point;
|
||||
extern grub_xen_reg_t grub_relocator_xen_paging_start;
|
||||
extern grub_xen_reg_t grub_relocator_xen_paging_size;
|
||||
extern grub_xen_reg_t grub_relocator_xen_remapper_virt;
|
||||
extern grub_xen_reg_t grub_relocator_xen_remapper_virt2;
|
||||
extern grub_xen_reg_t grub_relocator_xen_remapper_map;
|
||||
extern grub_xen_reg_t grub_relocator_xen_mfn_list;
|
||||
extern grub_xen_reg_t grub_relocator_xen_remap_continue;
|
||||
#ifdef __i386__
|
||||
extern grub_xen_reg_t grub_relocator_xen_mmu_op_addr;
|
||||
extern grub_xen_reg_t grub_relocator_xen_remapper_map_high;
|
||||
#endif
|
||||
extern mmuext_op_t grub_relocator_xen_mmu_op[3];
|
||||
|
||||
#define RELOCATOR_SIZEOF(x) (&grub_relocator##x##_end - &grub_relocator##x##_start)
|
||||
|
||||
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)
|
||||
{
|
||||
grub_err_t err;
|
||||
void *relst;
|
||||
grub_relocator_chunk_t ch, ch_tramp;
|
||||
grub_xen_mfn_t *mfn_list =
|
||||
(grub_xen_mfn_t *) grub_xen_start_page_addr->mfn_list;
|
||||
|
||||
err = grub_relocator_alloc_chunk_addr (rel, &ch, remapper_pfn << 12,
|
||||
RELOCATOR_SIZEOF (_xen_remap));
|
||||
if (err)
|
||||
return err;
|
||||
err = grub_relocator_alloc_chunk_addr (rel, &ch_tramp, trampoline_pfn << 12,
|
||||
RELOCATOR_SIZEOF (_xen));
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_relocator_xen_stack = state.stack;
|
||||
grub_relocator_xen_start_info = state.start_info;
|
||||
grub_relocator_xen_entry_point = state.entry_point;
|
||||
grub_relocator_xen_paging_start = state.paging_start << 12;
|
||||
grub_relocator_xen_paging_size = state.paging_size;
|
||||
grub_relocator_xen_remapper_virt = remapper_virt;
|
||||
grub_relocator_xen_remapper_virt2 = remapper_virt;
|
||||
grub_relocator_xen_remap_continue = trampoline_virt;
|
||||
|
||||
grub_relocator_xen_remapper_map = (mfn_list[remapper_pfn] << 12) | 5;
|
||||
#ifdef __i386__
|
||||
grub_relocator_xen_remapper_map_high = (mfn_list[remapper_pfn] >> 20);
|
||||
grub_relocator_xen_mmu_op_addr = (char *) &grub_relocator_xen_mmu_op
|
||||
- (char *) &grub_relocator_xen_remap_start + remapper_virt;
|
||||
#endif
|
||||
|
||||
grub_relocator_xen_mfn_list = state.mfn_list
|
||||
+ state.paging_start * sizeof (grub_addr_t);
|
||||
|
||||
grub_memset (grub_relocator_xen_mmu_op, 0,
|
||||
sizeof (grub_relocator_xen_mmu_op));
|
||||
#ifdef __i386__
|
||||
grub_relocator_xen_mmu_op[0].cmd = MMUEXT_PIN_L3_TABLE;
|
||||
#else
|
||||
grub_relocator_xen_mmu_op[0].cmd = MMUEXT_PIN_L4_TABLE;
|
||||
#endif
|
||||
grub_relocator_xen_mmu_op[0].arg1.mfn = mfn_list[state.paging_start];
|
||||
grub_relocator_xen_mmu_op[1].cmd = MMUEXT_NEW_BASEPTR;
|
||||
grub_relocator_xen_mmu_op[1].arg1.mfn = mfn_list[state.paging_start];
|
||||
grub_relocator_xen_mmu_op[2].cmd = MMUEXT_UNPIN_TABLE;
|
||||
grub_relocator_xen_mmu_op[2].arg1.mfn =
|
||||
mfn_list[grub_xen_start_page_addr->pt_base >> 12];
|
||||
|
||||
grub_memmove (get_virtual_current_address (ch),
|
||||
&grub_relocator_xen_remap_start,
|
||||
RELOCATOR_SIZEOF (_xen_remap));
|
||||
grub_memmove (get_virtual_current_address (ch_tramp),
|
||||
&grub_relocator_xen_start, RELOCATOR_SIZEOF (_xen));
|
||||
|
||||
err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
|
||||
&relst, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
((void (*)(void)) relst) ();
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue