2013-11-09 20:29:11 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
#include <grub/i386/memory.h>
|
|
|
|
#include <grub/i386/types.h>
|
2013-11-09 20:29:11 +00:00
|
|
|
#include <grub/symbol.h>
|
|
|
|
#include <grub/xen.h>
|
|
|
|
|
|
|
|
.p2align 4 /* force 16-byte alignment */
|
|
|
|
|
|
|
|
VARIABLE(grub_relocator_xen_remap_start)
|
|
|
|
LOCAL(base):
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Remap the remapper to it's new address. */
|
|
|
|
/* mov imm32, %ebx - %ebx: new virtual address of remapper */
|
2013-11-09 20:29:11 +00:00
|
|
|
.byte 0xbb
|
|
|
|
VARIABLE(grub_relocator_xen_remapper_virt)
|
|
|
|
.long 0
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
/* mov imm32, %ecx - %ecx: low part of page table entry */
|
2013-11-09 20:29:11 +00:00
|
|
|
.byte 0xb9
|
|
|
|
VARIABLE(grub_relocator_xen_remapper_map)
|
|
|
|
.long 0
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
/* mov imm32, %edx - %edx: high part of page table entry */
|
2013-11-09 20:29:11 +00:00
|
|
|
.byte 0xba
|
|
|
|
VARIABLE(grub_relocator_xen_remapper_map_high)
|
|
|
|
.long 0
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
movl %ebx, %ebp /* %ebx is clobbered by hypercall */
|
2013-12-17 12:40:52 +00:00
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
movl $UVMF_INVLPG, %esi /* esi: flags (inv. single entry) */
|
2013-11-09 20:29:11 +00:00
|
|
|
movl $__HYPERVISOR_update_va_mapping, %eax
|
|
|
|
int $0x82
|
|
|
|
|
2013-12-17 12:40:52 +00:00
|
|
|
movl %ebp, %ebx
|
2013-11-09 20:29:11 +00:00
|
|
|
addl $(LOCAL(cont) - LOCAL(base)), %ebx
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
jmp *%ebx /* Continue with new virtual address */
|
2013-11-09 20:29:11 +00:00
|
|
|
|
|
|
|
LOCAL(cont):
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Modify mappings of new page tables to be read-only. */
|
|
|
|
/* mov imm32, %eax */
|
|
|
|
.byte 0xb8
|
|
|
|
VARIABLE(grub_relocator_xen_paging_areas_addr)
|
|
|
|
.long 0
|
|
|
|
movl %eax, %ebx
|
2013-12-17 12:40:52 +00:00
|
|
|
1:
|
2016-03-03 09:38:15 +00:00
|
|
|
movl 0(%ebx), %ebp /* Get start pfn of the current area */
|
|
|
|
movl GRUB_TARGET_SIZEOF_LONG(%ebx), %ecx /* Get # of pg tables */
|
|
|
|
testl %ecx, %ecx /* 0 -> last area reached */
|
|
|
|
jz 3f
|
|
|
|
addl $(2 * GRUB_TARGET_SIZEOF_LONG), %ebx
|
|
|
|
movl %ebx, %esp /* Save current area pointer */
|
|
|
|
|
|
|
|
2:
|
|
|
|
movl %ecx, %edi
|
2013-12-17 12:40:52 +00:00
|
|
|
/* mov imm32, %eax */
|
|
|
|
.byte 0xb8
|
|
|
|
VARIABLE(grub_relocator_xen_mfn_list)
|
2013-11-09 20:29:11 +00:00
|
|
|
.long 0
|
2016-03-03 09:38:15 +00:00
|
|
|
movl 0(%eax, %ebp, 4), %ecx /* mfn */
|
|
|
|
movl %ebp, %ebx
|
|
|
|
shll $PAGE_SHIFT, %ebx /* virtual address (1:1 mapping) */
|
2013-11-09 20:29:11 +00:00
|
|
|
movl %ecx, %edx
|
2016-03-03 09:38:15 +00:00
|
|
|
shll $PAGE_SHIFT, %ecx /* prepare pte low part */
|
|
|
|
shrl $(32 - PAGE_SHIFT), %edx /* pte high part */
|
|
|
|
orl $(GRUB_PAGE_PRESENT | GRUB_PAGE_USER), %ecx /* pte low */
|
|
|
|
movl $UVMF_INVLPG, %esi
|
2013-11-09 20:29:11 +00:00
|
|
|
movl $__HYPERVISOR_update_va_mapping, %eax
|
2016-03-03 09:38:15 +00:00
|
|
|
int $0x82 /* parameters: eax, ebx, ecx, edx, esi */
|
2013-11-09 20:29:11 +00:00
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
incl %ebp /* next pfn */
|
|
|
|
movl %edi, %ecx
|
|
|
|
|
|
|
|
loop 2b
|
2013-11-09 20:29:11 +00:00
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
mov %esp, %ebx /* restore area poniter */
|
|
|
|
jmp 1b
|
2013-11-09 20:29:11 +00:00
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
3:
|
|
|
|
/* Switch page tables: pin new L3 pt, load cr3, unpin old L3. */
|
2013-11-09 20:29:11 +00:00
|
|
|
/* mov imm32, %ebx */
|
|
|
|
.byte 0xbb
|
|
|
|
VARIABLE(grub_relocator_xen_mmu_op_addr)
|
|
|
|
.long 0
|
2016-03-03 09:38:15 +00:00
|
|
|
movl $3, %ecx /* 3 mmu ops */
|
|
|
|
movl $0, %edx /* pdone (not used) */
|
|
|
|
movl $DOMID_SELF, %esi
|
2013-11-09 20:29:11 +00:00
|
|
|
movl $__HYPERVISOR_mmuext_op, %eax
|
|
|
|
int $0x82
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Continue in virtual kernel mapping. */
|
2013-11-09 20:29:11 +00:00
|
|
|
/* mov imm32, %eax */
|
|
|
|
.byte 0xb8
|
|
|
|
VARIABLE(grub_relocator_xen_remap_continue)
|
|
|
|
.long 0
|
|
|
|
|
|
|
|
jmp *%eax
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
VARIABLE(grub_relocator_xen_paging_areas)
|
|
|
|
.long 0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
|
2013-11-09 20:29:11 +00:00
|
|
|
VARIABLE(grub_relocator_xen_mmu_op)
|
|
|
|
.space 256
|
|
|
|
|
|
|
|
VARIABLE(grub_relocator_xen_remap_end)
|
|
|
|
|
|
|
|
|
|
|
|
VARIABLE(grub_relocator_xen_start)
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Unmap old remapper area. */
|
2013-11-09 20:29:11 +00:00
|
|
|
/* mov imm32, %eax */
|
|
|
|
.byte 0xb8
|
|
|
|
VARIABLE(grub_relocator_xen_remapper_virt2)
|
|
|
|
.long 0
|
|
|
|
|
2017-03-05 09:04:07 +00:00
|
|
|
movl %eax, %ebx
|
2013-11-09 20:29:11 +00:00
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
xorl %ecx, %ecx /* Invalid pte */
|
2013-11-09 20:29:11 +00:00
|
|
|
xorl %edx, %edx
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
movl $UVMF_INVLPG, %esi
|
2013-11-09 20:29:11 +00:00
|
|
|
movl $__HYPERVISOR_update_va_mapping, %eax
|
|
|
|
int $0x82
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Prepare registers for starting kernel. */
|
2013-11-09 20:29:11 +00:00
|
|
|
/* 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
|
|
|
|
|
2016-03-03 09:38:15 +00:00
|
|
|
/* Now start the new kernel. */
|
2013-11-09 20:29:11 +00:00
|
|
|
jmp *%eax
|
|
|
|
|
|
|
|
VARIABLE(grub_relocator_xen_end)
|