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

@ -130,8 +130,9 @@ grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
}
void
grub_machine_fini (void)
grub_machine_fini (int flags)
{
grub_vga_text_fini ();
if (flags & GRUB_LOADER_FLAG_NORETURN)
grub_vga_text_fini ();
grub_stop_floppy ();
}

View file

@ -35,7 +35,8 @@ grub_machine_init (void)
}
void
grub_machine_fini (void)
grub_machine_fini (int flags)
{
grub_efi_fini ();
if (flags & GRUB_LOADER_FLAG_NORETURN)
grub_efi_fini ();
}

View file

@ -239,8 +239,9 @@ grub_machine_init (void)
}
void
grub_machine_fini (void)
grub_machine_fini (int flags)
{
grub_console_fini ();
if (flags & GRUB_LOADER_FLAG_NORETURN)
grub_console_fini ();
grub_stop_floppy ();
}

View file

@ -277,8 +277,9 @@ grub_machine_get_bootlocation (char **device __attribute__ ((unused)),
}
void
grub_machine_fini (void)
grub_machine_fini (int flags)
{
grub_vga_text_fini ();
if (flags & GRUB_LOADER_FLAG_NORETURN)
grub_vga_text_fini ();
grub_stop_floppy ();
}

View file

@ -25,7 +25,11 @@
#include <grub/misc.h>
#include <grub/i386/tsc.h>
#include <grub/i386/cpuid.h>
#ifdef GRUB_MACHINE_XEN
#include <grub/xen.h>
#else
#include <grub/i386/pit.h>
#endif
#include <grub/cpu/io.h>
/* This defines the value TSC had at the epoch (that is, when we calibrated it). */
@ -65,6 +69,8 @@ grub_cpu_is_tsc_supported (void)
return (d & (1 << 4)) != 0;
}
#ifndef GRUB_MACHINE_XEN
static void
grub_pit_wait (grub_uint16_t tics)
{
@ -92,6 +98,7 @@ grub_pit_wait (grub_uint16_t tics)
& ~ (GRUB_PIT_SPK_DATA | GRUB_PIT_SPK_TMR2),
GRUB_PIT_SPEAKER_PORT);
}
#endif
static grub_uint64_t
grub_tsc_get_time_ms (void)
@ -103,6 +110,7 @@ grub_tsc_get_time_ms (void)
return ((al * grub_tsc_rate) >> 32) + ah * grub_tsc_rate;
}
#ifndef GRUB_MACHINE_XEN
/* Calibrate the TSC based on the RTC. */
static void
calibrate_tsc (void)
@ -116,10 +124,22 @@ calibrate_tsc (void)
grub_tsc_rate = grub_divmod64 ((55ULL << 32), end_tsc - tsc_boot_time, 0);
}
#endif
void
grub_tsc_init (void)
{
#ifdef GRUB_MACHINE_XEN
grub_uint64_t t;
tsc_boot_time = grub_get_tsc ();
t = grub_xen_shared_info->vcpu_info[0].time.tsc_to_system_mul;
if (grub_xen_shared_info->vcpu_info[0].time.tsc_shift > 0)
t <<= grub_xen_shared_info->vcpu_info[0].time.tsc_shift;
else
t >>= -grub_xen_shared_info->vcpu_info[0].time.tsc_shift;
grub_tsc_rate = grub_divmod64 (t, 1000000, 0);
grub_install_get_time_ms (grub_tsc_get_time_ms);
#else
if (grub_cpu_is_tsc_supported ())
{
calibrate_tsc ();
@ -133,4 +153,5 @@ grub_tsc_init (void)
grub_fatal ("no TSC found");
#endif
}
#endif
}

View file

@ -0,0 +1,43 @@
/* hypercall.S - wrappers for Xen hypercalls */
/*
* 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>
FUNCTION(grub_xen_hypercall)
pushl %ebp
movl %esp, %ebp
pushl %esi
pushl %edi
pushl %ebx
/* call number already in %eax. */
/* %edx -> %ebx*/
/* %ecx -> %ecx*/
movl %edx, %ebx
movl 8(%ebp), %edx
movl 12(%ebp), %esi
movl 16(%ebp), %edi
movl 20(%ebp), %ebp
int $0x82
popl %ebx
popl %edi
popl %esi
popl %ebp
retl $16

View file

@ -0,0 +1,38 @@
/* startup.S - bootstrap GRUB itself */
/*
* 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 <config.h>
#include <grub/symbol.h>
.file "startup.S"
.text
.globl start, _start
.code32
start:
_start:
leal LOCAL(stack_end), %esp
movl %esi, EXT_C(grub_xen_start_page_addr)
call EXT_C(grub_main)
/* Doesn't return. */
.bss
.space (1 << 22)
LOCAL(stack_end):