merge mainline into backtrace
This commit is contained in:
commit
9ad7edd055
951 changed files with 130580 additions and 42624 deletions
193
grub-core/lib/i386/backtrace.c
Normal file
193
grub-core/lib/i386/backtrace.c
Normal file
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* 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/misc.h>
|
||||
#include <grub/command.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/backtrace.h>
|
||||
|
||||
#define MAX_STACK_FRAME 102400
|
||||
|
||||
struct idt_descriptor
|
||||
{
|
||||
grub_uint16_t limit;
|
||||
void *base;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define GRUB_IDT_ENTRY_TYPE_PRESENT 0x80
|
||||
#define GRUB_IDT_ENTRY_TYPE_NOT_PRESENT 0x00
|
||||
#define GRUB_IDT_ENTRY_TYPE_RING0 0x00
|
||||
#define GRUB_IDT_ENTRY_TYPE_TRAP32 0x0f
|
||||
|
||||
struct idt_entry
|
||||
{
|
||||
grub_uint16_t addr_low;
|
||||
grub_uint16_t segment;
|
||||
grub_uint8_t unused;
|
||||
grub_uint8_t type;
|
||||
grub_uint16_t addr_high;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
void grub_interrupt_handler_real (void *ret, void *ebp);
|
||||
|
||||
static void
|
||||
print_address (void *addr)
|
||||
{
|
||||
const char *name;
|
||||
int section;
|
||||
grub_off_t off;
|
||||
auto int hook (grub_dl_t mod);
|
||||
int hook (grub_dl_t mod)
|
||||
{
|
||||
grub_dl_segment_t segment;
|
||||
for (segment = mod->segment; segment; segment = segment->next)
|
||||
if (segment->addr <= addr && (grub_uint8_t *) segment->addr
|
||||
+ segment->size > (grub_uint8_t *) addr)
|
||||
{
|
||||
name = mod->name;
|
||||
section = segment->section;
|
||||
off = (grub_uint8_t *) addr - (grub_uint8_t *) segment->addr;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
name = NULL;
|
||||
grub_dl_iterate (hook);
|
||||
if (name)
|
||||
grub_printf ("%s.%x+%lx", name, section, (unsigned long) off);
|
||||
else
|
||||
grub_printf ("%p", addr);
|
||||
}
|
||||
|
||||
void
|
||||
grub_backtrace_pointer (void *ebp)
|
||||
{
|
||||
void *ptr, *nptr;
|
||||
unsigned i;
|
||||
|
||||
ptr = ebp;
|
||||
while (1)
|
||||
{
|
||||
grub_printf ("%p: ", ptr);
|
||||
print_address (((void **) ptr)[1]);
|
||||
grub_printf (" (");
|
||||
for (i = 0; i < 2; i++)
|
||||
grub_printf ("%p,", ((void **)ptr) [i + 2]);
|
||||
grub_printf ("%p)\n", ((void **)ptr) [i + 2]);
|
||||
nptr = *(void **)ptr;
|
||||
if (nptr < ptr || (void **) nptr - (void **) ptr > MAX_STACK_FRAME
|
||||
|| nptr == ptr)
|
||||
{
|
||||
grub_printf ("Invalid stack frame at %p (%p)\n", ptr, nptr);
|
||||
break;
|
||||
}
|
||||
ptr = nptr;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_interrupt_handler_real (void *ret, void *ebp)
|
||||
{
|
||||
grub_printf ("Unhandled exception at ");
|
||||
print_address (ret);
|
||||
grub_printf ("\n");
|
||||
grub_backtrace_pointer (ebp);
|
||||
grub_abort ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_backtrace (void)
|
||||
{
|
||||
#ifdef __x86_64__
|
||||
asm volatile ("movq %rbp, %rdi\n"
|
||||
"call grub_backtrace_pointer");
|
||||
#else
|
||||
asm volatile ("movl %ebp, %eax\n"
|
||||
"call grub_backtrace_pointer");
|
||||
#endif
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)),
|
||||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_backtrace ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define NUM_INTERRUPTS 0x20
|
||||
|
||||
void grub_int_handler (void);
|
||||
|
||||
struct idt_descriptor idt_desc;
|
||||
|
||||
static grub_err_t
|
||||
setup_interrupts (void)
|
||||
{
|
||||
struct idt_entry *idt_table;
|
||||
unsigned long i;
|
||||
grub_uint16_t seg;
|
||||
idt_table = grub_memalign (0x10, NUM_INTERRUPTS * sizeof (struct idt_entry));
|
||||
if (!idt_table)
|
||||
return grub_errno;
|
||||
idt_desc.base = idt_table;
|
||||
idt_desc.limit = NUM_INTERRUPTS;
|
||||
|
||||
asm volatile ("xorl %%eax, %%eax\n"
|
||||
"mov %%cs, %%ax\n" :"=a" (seg));
|
||||
|
||||
for (i = 0; i < NUM_INTERRUPTS; i++)
|
||||
{
|
||||
idt_table[i].addr_low = ((grub_addr_t) grub_int_handler) & 0xffff;
|
||||
idt_table[i].addr_high = ((grub_addr_t) grub_int_handler) >> 16;
|
||||
idt_table[i].unused = 0;
|
||||
idt_table[i].segment = seg;
|
||||
idt_table[i].type = GRUB_IDT_ENTRY_TYPE_PRESENT
|
||||
| GRUB_IDT_ENTRY_TYPE_RING0 | GRUB_IDT_ENTRY_TYPE_TRAP32;
|
||||
}
|
||||
|
||||
asm volatile ("lidt %0" : : "m" (idt_desc));
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_command_t cmd;
|
||||
|
||||
GRUB_MOD_INIT(backtrace)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = setup_interrupts();
|
||||
if (err)
|
||||
{
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
cmd = grub_register_command ("backtrace", grub_cmd_backtrace,
|
||||
0, "Print backtrace.");
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(backtrace)
|
||||
{
|
||||
grub_unregister_command (cmd);
|
||||
}
|
12
grub-core/lib/i386/backtrace_int.S
Normal file
12
grub-core/lib/i386/backtrace_int.S
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <grub/symbol.h>
|
||||
|
||||
.text
|
||||
.p2align 4
|
||||
|
||||
FUNCTION(grub_int_handler)
|
||||
/* FIXME: push this only when CPU pushes no error on stack. */
|
||||
push $0
|
||||
pusha
|
||||
movl 36(%esp), %eax
|
||||
movl %ebp, %edx
|
||||
call EXT_C(grub_interrupt_handler_real)
|
60
grub-core/lib/i386/halt.c
Normal file
60
grub-core/lib/i386/halt.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 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/cpu/io.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/acpi.h>
|
||||
|
||||
const char bochs_shutdown[] = "Shutdown";
|
||||
|
||||
/*
|
||||
* This call is special... it never returns... in fact it should simply
|
||||
* hang at this point!
|
||||
*/
|
||||
static inline void __attribute__ ((noreturn))
|
||||
stop (void)
|
||||
{
|
||||
asm volatile ("cli");
|
||||
while (1)
|
||||
{
|
||||
asm volatile ("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_halt (void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT)
|
||||
grub_acpi_halt ();
|
||||
#endif
|
||||
|
||||
/* Disable interrupts. */
|
||||
__asm__ __volatile__ ("cli");
|
||||
|
||||
/* Bochs, QEMU, etc. */
|
||||
for (i = 0; i < sizeof (bochs_shutdown) - 1; i++)
|
||||
grub_outb (bochs_shutdown[i], 0x8900);
|
||||
|
||||
grub_printf ("GRUB doesn't know how to halt this machine yet!\n");
|
||||
|
||||
/* In order to return we'd have to check what the previous status of IF
|
||||
flag was. But user most likely doesn't want to return anyway ... */
|
||||
stop ();
|
||||
}
|
46
grub-core/lib/i386/pc/biosnum.c
Normal file
46
grub-core/lib/i386/pc/biosnum.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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/env.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
|
||||
static int
|
||||
grub_get_root_biosnumber_default (void)
|
||||
{
|
||||
char *biosnum;
|
||||
int ret = -1;
|
||||
grub_device_t dev;
|
||||
|
||||
biosnum = grub_env_get ("biosnum");
|
||||
|
||||
if (biosnum)
|
||||
return grub_strtoul (biosnum, 0, 0);
|
||||
|
||||
dev = grub_device_open (0);
|
||||
if (dev && dev->disk && dev->disk->dev
|
||||
&& dev->disk->dev->id == GRUB_DISK_DEVICE_BIOSDISK_ID)
|
||||
ret = (int) dev->disk->id;
|
||||
|
||||
if (dev)
|
||||
grub_device_close (dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int (*grub_get_root_biosnumber) (void) = grub_get_root_biosnumber_default;
|
270
grub-core/lib/i386/relocator.c
Normal file
270
grub-core/lib/i386/relocator.c
Normal file
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* 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/i386/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;
|
||||
|
||||
extern grub_uint8_t grub_relocator16_start;
|
||||
extern grub_uint8_t grub_relocator16_end;
|
||||
extern grub_uint16_t grub_relocator16_cs;
|
||||
extern grub_uint16_t grub_relocator16_ip;
|
||||
extern grub_uint16_t grub_relocator16_ds;
|
||||
extern grub_uint16_t grub_relocator16_es;
|
||||
extern grub_uint16_t grub_relocator16_fs;
|
||||
extern grub_uint16_t grub_relocator16_gs;
|
||||
extern grub_uint16_t grub_relocator16_ss;
|
||||
extern grub_uint16_t grub_relocator16_sp;
|
||||
extern grub_uint32_t grub_relocator16_edx;
|
||||
|
||||
extern grub_uint8_t grub_relocator32_start;
|
||||
extern grub_uint8_t grub_relocator32_end;
|
||||
extern grub_uint32_t grub_relocator32_eax;
|
||||
extern grub_uint32_t grub_relocator32_ebx;
|
||||
extern grub_uint32_t grub_relocator32_ecx;
|
||||
extern grub_uint32_t grub_relocator32_edx;
|
||||
extern grub_uint32_t grub_relocator32_eip;
|
||||
extern grub_uint32_t grub_relocator32_esp;
|
||||
extern grub_uint32_t grub_relocator32_ebp;
|
||||
extern grub_uint32_t grub_relocator32_esi;
|
||||
extern grub_uint32_t grub_relocator32_edi;
|
||||
|
||||
extern grub_uint8_t grub_relocator64_start;
|
||||
extern grub_uint8_t grub_relocator64_end;
|
||||
extern grub_uint64_t grub_relocator64_rax;
|
||||
extern grub_uint64_t grub_relocator64_rbx;
|
||||
extern grub_uint64_t grub_relocator64_rcx;
|
||||
extern grub_uint64_t grub_relocator64_rdx;
|
||||
extern grub_uint64_t grub_relocator64_rip;
|
||||
extern grub_uint64_t grub_relocator64_rip_addr;
|
||||
extern grub_uint64_t grub_relocator64_rsp;
|
||||
extern grub_uint64_t grub_relocator64_rsi;
|
||||
extern grub_addr_t grub_relocator64_cr3;
|
||||
|
||||
#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)
|
||||
{
|
||||
grub_err_t err;
|
||||
void *relst;
|
||||
grub_relocator_chunk_t ch;
|
||||
|
||||
err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
|
||||
(0xffffffff - RELOCATOR_SIZEOF (32))
|
||||
+ 1, RELOCATOR_SIZEOF (32), 16,
|
||||
GRUB_RELOCATOR_PREFERENCE_NONE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_relocator32_eax = state.eax;
|
||||
grub_relocator32_ebx = state.ebx;
|
||||
grub_relocator32_ecx = state.ecx;
|
||||
grub_relocator32_edx = state.edx;
|
||||
grub_relocator32_eip = state.eip;
|
||||
grub_relocator32_esp = state.esp;
|
||||
grub_relocator32_ebp = state.ebp;
|
||||
grub_relocator32_esi = state.esi;
|
||||
grub_relocator32_edi = state.edi;
|
||||
|
||||
grub_memmove (get_virtual_current_address (ch), &grub_relocator32_start,
|
||||
RELOCATOR_SIZEOF (32));
|
||||
|
||||
err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
|
||||
&relst, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
asm volatile ("cli");
|
||||
((void (*) (void)) relst) ();
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_relocator16_boot (struct grub_relocator *rel,
|
||||
struct grub_relocator16_state state)
|
||||
{
|
||||
grub_err_t err;
|
||||
void *relst;
|
||||
grub_relocator_chunk_t ch;
|
||||
|
||||
err = grub_relocator_alloc_chunk_align (rel, &ch, 0,
|
||||
0xa0000 - RELOCATOR_SIZEOF (16),
|
||||
RELOCATOR_SIZEOF (16), 16,
|
||||
GRUB_RELOCATOR_PREFERENCE_NONE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_relocator16_cs = state.cs;
|
||||
grub_relocator16_ip = state.ip;
|
||||
|
||||
grub_relocator16_ds = state.ds;
|
||||
grub_relocator16_es = state.es;
|
||||
grub_relocator16_fs = state.fs;
|
||||
grub_relocator16_gs = state.gs;
|
||||
|
||||
grub_relocator16_ss = state.ss;
|
||||
grub_relocator16_sp = state.sp;
|
||||
|
||||
grub_relocator16_edx = state.edx;
|
||||
|
||||
grub_memmove (get_virtual_current_address (ch), &grub_relocator16_start,
|
||||
RELOCATOR_SIZEOF (16));
|
||||
|
||||
err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
|
||||
&relst, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
asm volatile ("cli");
|
||||
((void (*) (void)) relst) ();
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_relocator64_boot (struct grub_relocator *rel,
|
||||
struct grub_relocator64_state state,
|
||||
grub_addr_t min_addr, grub_addr_t max_addr)
|
||||
{
|
||||
grub_err_t err;
|
||||
void *relst;
|
||||
grub_relocator_chunk_t ch;
|
||||
|
||||
err = grub_relocator_alloc_chunk_align (rel, &ch, min_addr,
|
||||
max_addr - RELOCATOR_SIZEOF (64),
|
||||
RELOCATOR_SIZEOF (64), 16,
|
||||
GRUB_RELOCATOR_PREFERENCE_NONE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
grub_relocator64_rax = state.rax;
|
||||
grub_relocator64_rbx = state.rbx;
|
||||
grub_relocator64_rcx = state.rcx;
|
||||
grub_relocator64_rdx = state.rdx;
|
||||
grub_relocator64_rip = state.rip;
|
||||
grub_relocator64_rsp = state.rsp;
|
||||
grub_relocator64_rsi = state.rsi;
|
||||
grub_relocator64_cr3 = state.cr3;
|
||||
|
||||
grub_memmove (get_virtual_current_address (ch), &grub_relocator64_start,
|
||||
RELOCATOR_SIZEOF (64));
|
||||
|
||||
err = grub_relocator_prepare_relocs (rel, get_physical_target_address (ch),
|
||||
&relst, NULL);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
asm volatile ("cli");
|
||||
((void (*) (void)) relst) ();
|
||||
|
||||
/* Not reached. */
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
193
grub-core/lib/i386/relocator16.S
Normal file
193
grub-core/lib/i386/relocator16.S
Normal file
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2010 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/>.
|
||||
*/
|
||||
|
||||
/* The code segment of the protected mode. */
|
||||
#define CODE_SEGMENT 0x08
|
||||
|
||||
/* The data segment of the protected mode. */
|
||||
#define DATA_SEGMENT 0x10
|
||||
|
||||
#define PSEUDO_REAL_CSEG 0x18
|
||||
|
||||
#define PSEUDO_REAL_DSEG 0x20
|
||||
|
||||
#include "relocator_common.S"
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_relocator16_start)
|
||||
PREAMBLE
|
||||
|
||||
movl %esi, %eax
|
||||
movw %ax, (LOCAL (cs_base_bytes12) - LOCAL (base)) (RSI, 1)
|
||||
shrl $16, %eax
|
||||
movb %al, (LOCAL (cs_base_byte3) - LOCAL (base)) (RSI, 1)
|
||||
|
||||
RELOAD_GDT
|
||||
.code32
|
||||
/* Update other registers. */
|
||||
movl $DATA_SEGMENT, %eax
|
||||
movl %eax, %ds
|
||||
movl %eax, %es
|
||||
movl %eax, %fs
|
||||
movl %eax, %gs
|
||||
movl %eax, %ss
|
||||
|
||||
DISABLE_PAGING
|
||||
|
||||
#ifdef __x86_64__
|
||||
/* Disable amd64. */
|
||||
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
|
||||
rdmsr
|
||||
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
|
||||
wrmsr
|
||||
#endif
|
||||
|
||||
/* Turn off PAE. */
|
||||
movl %cr4, %eax
|
||||
andl $(~GRUB_MEMORY_CPU_CR4_PAE_ON), %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
/* Update other registers. */
|
||||
movl $PSEUDO_REAL_DSEG, %eax
|
||||
movl %eax, %ds
|
||||
movl %eax, %es
|
||||
movl %eax, %fs
|
||||
movl %eax, %gs
|
||||
movl %eax, %ss
|
||||
|
||||
movl %esi, %eax
|
||||
shrl $4, %eax
|
||||
movw %ax, (LOCAL (segment) - LOCAL (base)) (%esi, 1)
|
||||
|
||||
/* jump to a 16 bit segment */
|
||||
ljmp $PSEUDO_REAL_CSEG, $(LOCAL (cont2) - LOCAL(base))
|
||||
LOCAL(cont2):
|
||||
.code16
|
||||
|
||||
/* clear the PE bit of CR0 */
|
||||
movl %cr0, %eax
|
||||
andl $(~GRUB_MEMORY_CPU_CR0_PE_ON), %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* flush prefetch queue, reload %cs */
|
||||
/* ljmp */
|
||||
.byte 0xea
|
||||
.word LOCAL(cont3)-LOCAL(base)
|
||||
LOCAL(segment):
|
||||
.word 0
|
||||
|
||||
LOCAL(cont3):
|
||||
/* we are in real mode now
|
||||
* set up the real mode segment registers : DS, SS, ES
|
||||
*/
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_ds)
|
||||
.word 0
|
||||
movw %ax, %ds
|
||||
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_es)
|
||||
.word 0
|
||||
movw %ax, %es
|
||||
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_fs)
|
||||
.word 0
|
||||
movw %ax, %fs
|
||||
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_gs)
|
||||
.word 0
|
||||
movw %ax, %gs
|
||||
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_ss)
|
||||
.word 0
|
||||
movw %ax, %ss
|
||||
|
||||
/* movw imm16, %ax. */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator16_sp)
|
||||
.word 0
|
||||
movw %ax, %ss
|
||||
|
||||
/* movw imm32, %edx. */
|
||||
.byte 0x66, 0xba
|
||||
VARIABLE(grub_relocator16_edx)
|
||||
.long 0
|
||||
|
||||
/* Cleared direction flag is of no problem with any current
|
||||
payload and makes this implementation easier. */
|
||||
cld
|
||||
|
||||
/* ljmp */
|
||||
.byte 0xea
|
||||
VARIABLE(grub_relocator16_ip)
|
||||
.word 0
|
||||
VARIABLE(grub_relocator16_cs)
|
||||
.word 0
|
||||
|
||||
.code32
|
||||
|
||||
/* GDT. Copied from loader/i386/linux.c. */
|
||||
.p2align 4
|
||||
LOCAL(gdt):
|
||||
.word 0, 0
|
||||
.byte 0, 0, 0, 0
|
||||
|
||||
/* -- code segment --
|
||||
* base = 0x00000000, limit = 0xFFFFF (4 KiB Granularity), present
|
||||
* type = 32bit code execute/read, DPL = 0
|
||||
*/
|
||||
.word 0xFFFF, 0
|
||||
.byte 0, 0x9A, 0xCF, 0
|
||||
|
||||
/* -- data segment --
|
||||
* base = 0x00000000, limit 0xFFFFF (4 KiB Granularity), present
|
||||
* type = 32 bit data read/write, DPL = 0
|
||||
*/
|
||||
.word 0xFFFF, 0
|
||||
.byte 0, 0x92, 0xCF, 0
|
||||
|
||||
/* -- 16 bit real mode CS --
|
||||
* base = 0x00000000, limit 0x0FFFF (1 B Granularity), present
|
||||
* type = 16 bit code execute/read only/conforming, DPL = 0
|
||||
*/
|
||||
.word 0xFFFF
|
||||
LOCAL(cs_base_bytes12):
|
||||
.word 0
|
||||
LOCAL(cs_base_byte3):
|
||||
.byte 0
|
||||
|
||||
.byte 0x9E, 0, 0
|
||||
|
||||
/* -- 16 bit real mode DS --
|
||||
* base = 0x00000000, limit 0x0FFFF (1 B Granularity), present
|
||||
* type = 16 bit data read/write, DPL = 0
|
||||
*/
|
||||
.word 0xFFFF, 0
|
||||
.byte 0, 0x92, 0, 0
|
||||
LOCAL(gdt_end):
|
||||
|
||||
VARIABLE(grub_relocator16_end)
|
134
grub-core/lib/i386/relocator32.S
Normal file
134
grub-core/lib/i386/relocator32.S
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2010 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/>.
|
||||
*/
|
||||
|
||||
/* The code segment of the protected mode. */
|
||||
#define CODE_SEGMENT 0x10
|
||||
|
||||
/* The data segment of the protected mode. */
|
||||
#define DATA_SEGMENT 0x18
|
||||
|
||||
#include "relocator_common.S"
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_relocator32_start)
|
||||
PREAMBLE
|
||||
|
||||
RELOAD_GDT
|
||||
.code32
|
||||
/* Update other registers. */
|
||||
movl $DATA_SEGMENT, %eax
|
||||
movl %eax, %ds
|
||||
movl %eax, %es
|
||||
movl %eax, %fs
|
||||
movl %eax, %gs
|
||||
movl %eax, %ss
|
||||
|
||||
DISABLE_PAGING
|
||||
|
||||
#ifdef __x86_64__
|
||||
/* Disable amd64. */
|
||||
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
|
||||
rdmsr
|
||||
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
|
||||
wrmsr
|
||||
#endif
|
||||
|
||||
/* Turn off PAE. */
|
||||
movl %cr4, %eax
|
||||
andl $(~GRUB_MEMORY_CPU_CR4_PAE_ON), %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
jmp LOCAL(cont2)
|
||||
LOCAL(cont2):
|
||||
.code32
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_esp)
|
||||
.long 0
|
||||
|
||||
movl %eax, %esp
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_ebp)
|
||||
.long 0
|
||||
|
||||
movl %eax, %ebp
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_esi)
|
||||
.long 0
|
||||
|
||||
movl %eax, %esi
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_edi)
|
||||
.long 0
|
||||
|
||||
movl %eax, %edi
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_eax)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %ebx */
|
||||
.byte 0xbb
|
||||
VARIABLE(grub_relocator32_ebx)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator32_ecx)
|
||||
.long 0
|
||||
|
||||
/* mov imm32, %edx */
|
||||
.byte 0xba
|
||||
VARIABLE(grub_relocator32_edx)
|
||||
.long 0
|
||||
|
||||
/* Cleared direction flag is of no problem with any current
|
||||
payload and makes this implementation easier. */
|
||||
cld
|
||||
|
||||
.byte 0xea
|
||||
VARIABLE(grub_relocator32_eip)
|
||||
.long 0
|
||||
.word CODE_SEGMENT
|
||||
|
||||
/* GDT. Copied from loader/i386/linux.c. */
|
||||
.p2align 4
|
||||
LOCAL(gdt):
|
||||
/* NULL. */
|
||||
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
|
||||
/* Reserved. */
|
||||
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
|
||||
/* Code segment. */
|
||||
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x9A, 0xCF, 0x00
|
||||
|
||||
/* Data segment. */
|
||||
.byte 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x92, 0xCF, 0x00
|
||||
LOCAL(gdt_end):
|
||||
|
||||
VARIABLE(grub_relocator32_end)
|
160
grub-core/lib/i386/relocator64.S
Normal file
160
grub-core/lib/i386/relocator64.S
Normal file
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2010 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/>.
|
||||
*/
|
||||
|
||||
#define CODE32_SEGMENT 0x18
|
||||
#define CODE_SEGMENT 0x08
|
||||
|
||||
/* The data segment of the protected mode. */
|
||||
#define DATA_SEGMENT 0x10
|
||||
|
||||
#include "relocator_common.S"
|
||||
|
||||
.p2align 4 /* force 16-byte alignment */
|
||||
|
||||
VARIABLE(grub_relocator64_start)
|
||||
PREAMBLE
|
||||
#ifndef __x86_64__
|
||||
DISABLE_PAGING
|
||||
|
||||
/* Turn on PAE. */
|
||||
movl %cr4, %eax
|
||||
orl $(GRUB_MEMORY_CPU_CR4_PAE_ON | GRUB_MEMORY_CPU_CR4_PSE_ON), %eax
|
||||
movl %eax, %cr4
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator64_cr3)
|
||||
.long 0
|
||||
movl %eax, %cr3
|
||||
|
||||
/* Turn on amd64. */
|
||||
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
|
||||
rdmsr
|
||||
orl $GRUB_MEMORY_CPU_AMD64_MSR_ON, %eax
|
||||
wrmsr
|
||||
|
||||
/* Enable paging. */
|
||||
movl %cr0, %eax
|
||||
orl $GRUB_MEMORY_CPU_CR0_PAGING_ON, %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
RELOAD_GDT
|
||||
#else
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator64_cr3)
|
||||
.quad 0
|
||||
movq %rax, %cr3
|
||||
#endif
|
||||
|
||||
.code64
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator64_rsp)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsp
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator64_rsi)
|
||||
.quad 0
|
||||
|
||||
movq %rax, %rsi
|
||||
|
||||
/* mov imm64, %rax */
|
||||
.byte 0x48
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator64_rax)
|
||||
.quad 0
|
||||
|
||||
/* mov imm64, %rbx */
|
||||
.byte 0x48
|
||||
.byte 0xbb
|
||||
VARIABLE(grub_relocator64_rbx)
|
||||
.quad 0
|
||||
|
||||
/* mov imm64, %rcx */
|
||||
.byte 0x48
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator64_rcx)
|
||||
.quad 0
|
||||
|
||||
/* mov imm64, %rdx */
|
||||
.byte 0x48
|
||||
.byte 0xba
|
||||
VARIABLE(grub_relocator64_rdx)
|
||||
.quad 0
|
||||
|
||||
/* Cleared direction flag is of no problem with any current
|
||||
payload and makes this implementation easier. */
|
||||
cld
|
||||
|
||||
jmp *LOCAL(jump_addr) (%rip)
|
||||
|
||||
LOCAL(jump_addr):
|
||||
VARIABLE(grub_relocator64_rip)
|
||||
.quad 0
|
||||
|
||||
#ifndef __x86_64__
|
||||
.p2align 4
|
||||
LOCAL(gdt):
|
||||
/* NULL. */
|
||||
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
|
||||
/* 64-bit segment. */
|
||||
.word 0xffff /* Limit xffff. */
|
||||
.word 0x0000 /* Base xxxx0000. */
|
||||
.byte 0x00 /* Base xx00xxxx. */
|
||||
.byte (0x8 /* Type 8. */ | (1 << 4) /* Code. */ \
|
||||
| (0 << 5) /* Ring 0. */ | (1 << 7) /* Present. */)
|
||||
.byte (0xf /* Limit fxxxx. */ | (0 << 4) /* AVL flag. */ \
|
||||
| (1 << 5) /* 64-bit. */ | (0 << 6) \
|
||||
| (1 << 7) /* 4K granular. */)
|
||||
.byte 0x00 /* Base 00xxxxxx. */
|
||||
|
||||
/* Data segment*/
|
||||
.word 0xffff /* Limit xffff. */
|
||||
.word 0x0000 /* Base xxxx0000. */
|
||||
.byte 0x00 /* Base xx00xxxx. */
|
||||
.byte (0x0 /* Type 0. */ | (0 << 4) /* Data. */ \
|
||||
| (0 << 5) /* Ring 0. */ | (1 << 7) /* Present. */)
|
||||
.byte (0xf /* Limit fxxxx. */ | (0 << 4) /* AVL flag. */ \
|
||||
| (0 << 5) /* Data. */ | (0 << 6) \
|
||||
| (1 << 7) /* 4K granular. */)
|
||||
.byte 0x00 /* Base 00xxxxxx. */
|
||||
|
||||
/* Compatibility segment. */
|
||||
.word 0xffff /* Limit xffff. */
|
||||
.word 0x0000 /* Base xxxx0000. */
|
||||
.byte 0x00 /* Base xx00xxxx. */
|
||||
.byte (0x8 /* Type 8. */ | (1 << 4) /* Code. */ \
|
||||
| (0 << 5) /* Ring 0. */ | (1 << 7) /* Present. */)
|
||||
.byte (0xf /* Limit fxxxx. */ | (0 << 4) /* AVL flag. */ \
|
||||
| (0 << 5) /* 32-bit. */ | (1 << 6) /* 32-bit. */ \
|
||||
| (1 << 7) /* 4K granular. */)
|
||||
.byte 0x00 /* Base 00xxxxxx. */
|
||||
|
||||
LOCAL(gdt_end):
|
||||
#endif
|
||||
|
||||
VARIABLE(grub_relocator64_end)
|
80
grub-core/lib/i386/relocator_asm.S
Normal file
80
grub-core/lib/i386/relocator_asm.S
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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/symbol.h>
|
||||
#include <grub/i386/memory.h>
|
||||
|
||||
.p2align 2
|
||||
|
||||
VARIABLE(grub_relocator_backward_start)
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_backward_dest)
|
||||
.long 0
|
||||
movl %eax, %edi
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_backward_src)
|
||||
.long 0
|
||||
movl %eax, %esi
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator_backward_chunk_size)
|
||||
.long 0
|
||||
|
||||
add %ecx, %esi
|
||||
add %ecx, %edi
|
||||
|
||||
|
||||
/* Backward movsb is implicitly off-by-one. compensate that. */
|
||||
sub $1, %esi
|
||||
sub $1, %edi
|
||||
|
||||
/* Backward copy. */
|
||||
std
|
||||
|
||||
rep
|
||||
movsb
|
||||
VARIABLE(grub_relocator_backward_end)
|
||||
|
||||
|
||||
VARIABLE(grub_relocator_forward_start)
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_forward_dest)
|
||||
.long 0
|
||||
movl %eax, %edi
|
||||
|
||||
/* mov imm32, %rax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator_forward_src)
|
||||
.long 0
|
||||
movl %eax, %esi
|
||||
|
||||
/* mov imm32, %ecx */
|
||||
.byte 0xb9
|
||||
VARIABLE(grub_relocator_forward_chunk_size)
|
||||
.long 0
|
||||
|
||||
/* Forward copy. */
|
||||
cld
|
||||
rep
|
||||
movsb
|
||||
VARIABLE(grub_relocator_forward_end)
|
2
grub-core/lib/i386/relocator_backward.S
Normal file
2
grub-core/lib/i386/relocator_backward.S
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define BACKWARD
|
||||
#include "relocator_asm.S"
|
82
grub-core/lib/i386/relocator_common.S
Normal file
82
grub-core/lib/i386/relocator_common.S
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2009,2010 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/i386/memory.h>
|
||||
|
||||
#ifdef __x86_64__
|
||||
#define RAX %rax
|
||||
#define RSI %rsi
|
||||
#else
|
||||
#define RAX %eax
|
||||
#define RSI %esi
|
||||
#endif
|
||||
|
||||
.macro DISABLE_PAGING
|
||||
#ifdef GRUB_MACHINE_IEEE1275
|
||||
#endif
|
||||
|
||||
movl %cr0, %eax
|
||||
andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
|
||||
movl %eax, %cr0
|
||||
.endm
|
||||
|
||||
.macro PREAMBLE
|
||||
LOCAL(base):
|
||||
/* %rax contains now our new 'base'. */
|
||||
mov RAX, RSI
|
||||
|
||||
add $(LOCAL(cont0) - LOCAL(base)), RAX
|
||||
jmp *RAX
|
||||
LOCAL(cont0):
|
||||
.endm
|
||||
|
||||
.macro RELOAD_GDT
|
||||
lea (LOCAL(cont1) - LOCAL(base)) (RSI, 1), RAX
|
||||
movl %eax, (LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
|
||||
|
||||
lea (LOCAL(gdt) - LOCAL(base)) (RSI, 1), RAX
|
||||
mov RAX, (LOCAL(gdt_addr) - LOCAL(base)) (RSI, 1)
|
||||
|
||||
/* Switch to compatibility mode. */
|
||||
lgdt (LOCAL(gdtdesc) - LOCAL(base)) (RSI, 1)
|
||||
|
||||
/* Update %cs. */
|
||||
ljmp *(LOCAL(jump_vector) - LOCAL(base)) (RSI, 1)
|
||||
|
||||
.p2align 4
|
||||
LOCAL(gdtdesc):
|
||||
.word LOCAL(gdt_end) - LOCAL(gdt)
|
||||
LOCAL(gdt_addr):
|
||||
#ifdef __x86_64__
|
||||
/* Filled by the code. */
|
||||
.quad 0
|
||||
#else
|
||||
/* Filled by the code. */
|
||||
.long 0
|
||||
#endif
|
||||
|
||||
.p2align 4
|
||||
LOCAL(jump_vector):
|
||||
/* Jump location. Is filled by the code */
|
||||
.long 0
|
||||
.long CODE_SEGMENT
|
||||
|
||||
LOCAL(cont1):
|
||||
.endm
|
56
grub-core/lib/i386/setjmp.S
Normal file
56
grub-core/lib/i386/setjmp.S
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003,2007 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>
|
||||
|
||||
.file "setjmp.S"
|
||||
|
||||
.text
|
||||
|
||||
/*
|
||||
* int grub_setjmp (grub_jmp_buf env)
|
||||
*/
|
||||
FUNCTION(grub_setjmp)
|
||||
movl %ebx, 0(%eax) /* EBX */
|
||||
movl %esi, 4(%eax) /* ESI */
|
||||
movl %edi, 8(%eax) /* EDI */
|
||||
movl %ebp, 12(%eax) /* EBP */
|
||||
popl %ecx
|
||||
movl %esp, 16(%eax) /* ESP */
|
||||
movl %ecx, 20(%eax) /* EIP */
|
||||
xorl %eax, %eax
|
||||
jmp *%ecx
|
||||
|
||||
|
||||
/*
|
||||
* int grub_longjmp (grub_jmp_buf env, int val)
|
||||
*/
|
||||
FUNCTION(grub_longjmp)
|
||||
movl 0(%eax), %ebx
|
||||
movl 4(%eax), %esi
|
||||
movl 8(%eax), %edi
|
||||
movl 12(%eax), %ebp
|
||||
movl 16(%eax), %esp
|
||||
movl 20(%eax), %ecx
|
||||
|
||||
movl %edx, %eax
|
||||
testl %eax, %eax
|
||||
jnz 1f
|
||||
incl %eax
|
||||
1: jmp *%ecx
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue