Import Tristan Gingold's ia64 port

(based on patch sent to grub-devel by Tristan in 2008-01-28)
This commit is contained in:
Robert Millan 2010-01-18 14:17:47 +00:00
parent 11cc30ac40
commit 2c40cc7868
32 changed files with 3791 additions and 38 deletions

View file

@ -579,6 +579,29 @@ grub_dl_load_core (void *addr, grub_size_t size)
return mod;
}
void
grub_init_module (const char *name,
void (*init)(grub_dl_t), void (*fini)(void))
{
grub_dl_t mod;
mod = (grub_dl_t) grub_malloc (sizeof (*mod));
if (! mod)
return;
mod->name = name;
mod->ref_count = 1;
mod->dep = 0;
mod->segment = 0;
mod->init = init;
mod->fini = fini;
grub_dl_call_init (mod);
/* Can't fail. */
grub_dl_add (mod);
}
/* Load a module from the file FILENAME. */
grub_dl_t
grub_dl_load_file (const char *filename)

View file

@ -22,16 +22,14 @@
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
//#define DEBUG_MM
#define NEXT_MEMORY_DESCRIPTOR(desc, size) \
((grub_efi_memory_descriptor_t *) ((char *) (desc) + (size)))
#define BYTES_TO_PAGES(bytes) ((bytes) >> 12)
#define BYTES_TO_PAGES(bytes) ((bytes + 0xfff) >> 12)
#define PAGES_TO_BYTES(pages) ((pages) << 12)
/* The size of a memory map obtained from the firmware. This must be
a multiplier of 4KB. */
#define MEMORY_MAP_SIZE 0x1000
/* Maintain the list of allocated pages. */
struct allocated_page
{
@ -49,11 +47,10 @@ static struct allocated_page *allocated_pages = 0;
#define MIN_HEAP_SIZE 0x100000
#define MAX_HEAP_SIZE (16 * 0x100000)
/* Allocate pages. Return the pointer to the first of allocated pages. */
void *
grub_efi_allocate_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
grub_efi_allocate_boot_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_allocate_type_t type;
grub_efi_status_t status;
@ -87,14 +84,34 @@ grub_efi_allocate_pages (grub_efi_physical_address_t address,
{
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
address = 0xffffffff;
status = b->allocate_pages (type, GRUB_EFI_LOADER_DATA, pages, &address);
grub_efi_free_pages (0, pages);
grub_efi_free_boot_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
return 0;
}
if (allocated_pages)
return (void *)address;
}
/* Free pages starting from ADDRESS. */
void
grub_efi_free_boot_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
b->free_pages (address, pages);
}
/* Allocate pages. Return the pointer to the first of allocated pages. */
void *
grub_efi_allocate_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
address = grub_efi_allocate_boot_pages (address, pages);
if (address != 0 && allocated_pages)
{
unsigned i;
@ -118,8 +135,6 @@ void
grub_efi_free_pages (grub_efi_physical_address_t address,
grub_efi_uintn_t pages)
{
grub_efi_boot_services_t *b;
if (allocated_pages
&& ((grub_efi_physical_address_t) ((grub_addr_t) allocated_pages)
!= address))
@ -133,9 +148,8 @@ grub_efi_free_pages (grub_efi_physical_address_t address,
break;
}
}
b = grub_efi_system_table->boot_services;
b->free_pages (address, pages);
grub_efi_free_boot_pages (address, pages);
}
/* Get the memory map as defined in the EFI spec. Return 1 if successful,
@ -278,7 +292,11 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
grub_efi_uint64_t required_pages)
{
grub_efi_memory_descriptor_t *desc;
#ifdef DEBUG_MM
grub_printf ("mm: required_pages=%lu\n", required_pages);
#endif
for (desc = memory_map;
desc < memory_map_end;
desc = NEXT_MEMORY_DESCRIPTOR (desc, desc_size))
@ -303,6 +321,10 @@ add_memory_regions (grub_efi_memory_descriptor_t *memory_map,
grub_mm_init_region (addr, PAGES_TO_BYTES (pages));
#ifdef DEBUG_MM
grub_printf ("mm: add %lu pages from %p\n", pages, addr);
#endif
required_pages -= pages;
if (required_pages == 0)
break;
@ -344,6 +366,8 @@ grub_efi_mm_init (void)
grub_efi_uintn_t desc_size;
grub_efi_uint64_t total_pages;
grub_efi_uint64_t required_pages;
grub_efi_uintn_t memory_map_size;
int res;
/* First of all, allocate pages to maintain allocations. */
allocated_pages
@ -352,26 +376,35 @@ grub_efi_mm_init (void)
grub_fatal ("cannot allocate memory");
grub_memset (allocated_pages, 0, ALLOCATED_PAGES_SIZE);
/* Prepare a memory region to store two memory maps. */
memory_map = grub_efi_allocate_pages (0,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
memory_map_size = 0;
res = grub_efi_get_memory_map (&memory_map_size, NULL, 0, &desc_size, 0);
if (res != 0)
grub_fatal ("cannot get memory map size");
/* Add space for a few more entries as allocating pages can increase
memory map size. */
memory_map_size += 4 * desc_size;
memory_map = grub_efi_allocate_pages
(0, 2 * BYTES_TO_PAGES (memory_map_size));
if (! memory_map)
grub_fatal ("cannot allocate memory");
filtered_memory_map = NEXT_MEMORY_DESCRIPTOR (memory_map, MEMORY_MAP_SIZE);
filtered_memory_map = NEXT_MEMORY_DESCRIPTOR (memory_map, memory_map_size);
/* Obtain descriptors for available memory. */
map_size = MEMORY_MAP_SIZE;
map_size = memory_map_size;
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0)
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) <= 0)
grub_fatal ("cannot get memory map");
memory_map_end = NEXT_MEMORY_DESCRIPTOR (memory_map, map_size);
filtered_memory_map_end = filter_memory_map (memory_map, filtered_memory_map,
desc_size, memory_map_end);
/* By default, request a quarter of the available memory. */
total_pages = get_total_pages (filtered_memory_map, desc_size,
filtered_memory_map_end);
@ -391,7 +424,7 @@ grub_efi_mm_init (void)
#if 0
/* For debug. */
map_size = MEMORY_MAP_SIZE;
map_size = memory_map_size;
if (grub_efi_get_memory_map (&map_size, memory_map, 0, &desc_size, 0) < 0)
grub_fatal ("cannot get memory map");
@ -404,7 +437,7 @@ grub_efi_mm_init (void)
/* Release the memory maps. */
grub_efi_free_pages ((grub_addr_t) memory_map,
2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE));
2 * BYTES_TO_PAGES (memory_map_size));
}
void
@ -420,10 +453,13 @@ grub_efi_mm_fini (void)
p = allocated_pages + i;
if (p->addr != 0)
grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages);
{
grub_efi_free_pages ((grub_addr_t) p->addr, p->num_pages);
}
}
grub_efi_free_pages ((grub_addr_t) allocated_pages,
BYTES_TO_PAGES (ALLOCATED_PAGES_SIZE));
allocated_pages = 0;
}
}

View file

@ -0,0 +1,84 @@
/*
* 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/>.
*/
OUTPUT_FORMAT("elf64-ia64-little")
OUTPUT_ARCH(ia64)
ENTRY(_start)
SECTIONS
{
. = 0x240;
.text :
{
*(.text)
*(.text.*)
*(.rodata)
*(.rodata.*)
/* Reserve space for the entry point descriptor. */
. = ALIGN(16);
QUAD(0)
QUAD(0)
}
. = ALIGN(0x20);
.got :
{
*(.got.plt)
*(.got)
. = ALIGN(0x10);
}
.opd :
{
*(.opd)
}
.sdata :
{
*(.srodata)
*(.sdata)
*(.sbss)
*(.scommon)
. = ALIGN(0x10);
}
.data :
{
*(.data*)
*(.dynbss)
*(.bss)
*(COMMON)
. = ALIGN(0x10);
}
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.interp : { *(.interp) }
.plt : { *(.plt) }
.rela :
{
*(.rela.text*)
*(.rela.data*)
*(.rela.sdata)
*(.rela.got)
}
.hash : { *(.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
/DISCARD/ :
{
*(.IA_64.unwind*)
*(.IA64.unwind*)
*(.moddeps)
*(.modname)
}
}

59
kern/ia64/efi/init.c Normal file
View file

@ -0,0 +1,59 @@
/* init.c - initialize an ia64-based EFI system */
/*
* 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/types.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/cache.h>
#include <grub/kernel.h>
#include <grub/efi/efi.h>
void
grub_machine_init (void)
{
grub_efi_init ();
grub_init_modules ();
}
void
grub_machine_fini (void)
{
grub_efi_fini ();
}
void
grub_machine_set_prefix (void)
{
grub_efi_set_prefix ();
}
void
grub_arch_sync_caches (void *address, grub_size_t len)
{
/* Cache line length is at least 32. */
grub_uint64_t a = (grub_uint64_t)address & ~0x1f;
/* Flush data. */
for (len = (len + 31) & ~0x1f; len > 0; len -= 0x20, a += 0x20)
asm volatile ("fc.i %0" : : "r" (a));
/* Sync and serialize. Maybe extra. */
asm volatile (";; sync.i;; srlz.i;;");
}

40
kern/ia64/efi/startup.S Normal file
View file

@ -0,0 +1,40 @@
/*
* 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/>.
*/
.text
.psr abi64
.psr lsb
.lsb
.global _start
.proc _start
_start:
alloc loc0=ar.pfs,2,4,0,0
mov loc1=rp
addl loc2=@gprel(grub_efi_image_handle),gp
addl loc3=@gprel(grub_efi_system_table),gp
;;
st8 [loc2]=in0
st8 [loc3]=in1
br.call.sptk.few rp=grub_main
;;
mov ar.pfs=loc0
mov rp=loc1
;;
br.ret.sptk.few rp
.endp _start

38
kern/ia64/trampoline.S Normal file
View file

@ -0,0 +1,38 @@
/*
* 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/>.
*/
.text
.psr abi64
.psr lsb
.lsb
.proc __ia64_trampoline
.global __ia64_trampoline
__ia64_trampoline:
// Read address of the real descriptor
ld8 r2=[r1],8
;;
// Read chain
ld8 r15=[r1]
// Read pc
ld8 r3=[r2],8
;;
// Read gp
ld8 r1=[r2]
mov b6=r3
br.many b6
.endp __ia64_trampoline