release 3.10

https://sourceforge.net/projects/elilo/files/elilo/elilo-3.10/

(sans a few CVS directories)
This commit is contained in:
Stephane Eranian 2009-04-03 09:38:32 -04:00 committed by Vincent Batts
parent 34d8003a54
commit 4e87874a03
35 changed files with 412 additions and 235 deletions

View file

@ -47,7 +47,7 @@ bzImage_probe(CHAR16 *kname)
DBG_PRT((L"probe_bzImage_boot()\n"));
if (!kname) {
ERR_PRT((L"kname == %xh", kname));
ERR_PRT((L"kname == " PTR_FMT, kname));
free_kmem();
return -1;
}
@ -110,7 +110,7 @@ bzImage_probe(CHAR16 *kname)
param_size = (bootsect[0x1F1] + 1) * 512;
param_start = alloc(param_size, EfiLoaderData);
DBG_PRT((L"param_size=%d param_start=%x", param_size, param_start));
DBG_PRT((L"param_size=%d param_start=" PTR_FMT, param_size, param_start));
if (!param_start) {
ERR_PRT((L"Could not allocate %d bytes of setup data.",
@ -141,7 +141,7 @@ bzImage_probe(CHAR16 *kname)
{
UINT8 *c = ((UINT8 *)param_start)+514;
DBG_PRT((L"param_start(c=%x): %c-%c-%c-%c",
DBG_PRT((L"param_start(c=" PTR_FMT "): %c-%c-%c-%c",
c, (CHAR16)c[0],(CHAR16) c[1], (CHAR16)c[2], (CHAR16)c[3]));
}
if (CompareMem(((UINT8 *)param_start) + 514, "HdrS", 4)) {
@ -158,13 +158,38 @@ bzImage_probe(CHAR16 *kname)
* Allocate memory for kernel.
*/
if (alloc_kmem(kernel_start, EFI_SIZE_TO_PAGES(kernel_size))) {
ERR_PRT((L"Could not allocate kernel memory."));
return -1;
} else {
VERB_PRT(3, Print(L"kernel_start: 0x%x kernel_size: %d\n",
kernel_start, kernel_size));
}
/*
* Get correct address for kernel from header, if applicable & available.
*/
if ((param_start->s.hdr_major == 2) &&
(param_start->s.hdr_minor >= 6) &&
(param_start->s.kernel_start >= DEFAULT_KERNEL_START)) {
kernel_start = (void *)param_start->s.kernel_start;
VERB_PRT(3, Print(L"kernel header suggests kernel start at address "PTR_FMT"\n",
kernel_start));
}
kernel_load_address = kernel_start;
if (alloc_kmem(kernel_start, EFI_SIZE_TO_PAGES(kernel_size)) != 0) {
/*
* Couldn't get desired address--just load it anywhere and move it later.
* (Easier than relocating kernel, and also works with non-relocatable kernels.)
*/
if (alloc_kmem_anywhere(&kernel_load_address, EFI_SIZE_TO_PAGES(kernel_size)) != 0) {
ERR_PRT((L"Could not allocate memory for kernel."));
free(param_start);
param_start = NULL;
param_size = 0;
fops_close(fd);
return -1;
}
}
VERB_PRT(3, Print(L"kernel_start: "PTR_FMT" kernel_size: %d loading at: "PTR_FMT"\n",
kernel_start, kernel_size, kernel_load_address));
/*
* Now read the rest of the kernel image into memory.
*/
@ -172,7 +197,7 @@ bzImage_probe(CHAR16 *kname)
DBG_PRT((L"reading kernel image...\n"));
size = kernel_size;
efi_status = fops_read(fd, kernel_start, &size);
efi_status = fops_read(fd, kernel_load_address, &size);
if (EFI_ERROR(efi_status) || size < 0x10000) {
ERR_PRT((L"Error reading kernel image %s.", kname));
free(param_start);
@ -200,7 +225,7 @@ bzImage_load(CHAR16 *kname, kdesc_t *kd)
DBG_PRT((L"load_bzImage_boot()\n"));
if (!kname || !kd) {
ERR_PRT((L"kname=0x%x kd=0x%x", kname, kd));
ERR_PRT((L"kname=" PTR_FMT " kd=" PTR_FMT, kname, kd));
free(param_start);
param_start = NULL;
param_size = 0;
@ -210,7 +235,7 @@ bzImage_load(CHAR16 *kname, kdesc_t *kd)
kd->kstart = kd->kentry = kernel_start;
kd->kend = ((UINT8 *)kd->kstart) + kernel_size;
DBG_PRT((L"kstart=0x%x kentry=0x%x kend=0x%x\n", kd->kstart, kd->kentry, kd->kend));
DBG_PRT((L"kstart=" PTR_FMT " kentry=" PTR_FMT " kend=" PTR_FMT "\n", kd->kstart, kd->kentry, kd->kend));
return 0;
}

View file

@ -153,7 +153,7 @@ gzip_free(void *where)
int
fill_inbuf(void)
{
INTN expected, nread;
UINTN expected, nread;
EFI_STATUS status;
expected = nread = INBUFSIZE;
@ -277,7 +277,7 @@ analyze_chunks(void)
* the relevant header information.
*/
int
first_block (const char *buf, long blocksize)
first_block (const unsigned char *buf, long blocksize)
{
Elf32_Ehdr *elf;
Elf32_Phdr *phdrs;
@ -297,13 +297,13 @@ first_block (const char *buf, long blocksize)
phnum = elf->e_phnum;
VERB_PRT(3, {
Print(L"Entry point 0x%lx\n", elf->e_entry);
Print(L"Entry point "PTR_FMT"\n", elf->e_entry);
Print(L"%d program headers\n", phnum);
Print(L"%d segment headers\n", elf->e_shnum);
});
if (offs + phnum * sizeof(*phdrs) > (unsigned) blocksize) {
ERR_PRT((L"%s : ELF program headers not in first block (%ld)\n", LD_NAME, offs));
ERR_PRT((L"%s : ELF program headers not in first block (%d)\n", LD_NAME, offs));
return -1;
}
@ -345,15 +345,15 @@ first_block (const char *buf, long blocksize)
if (phdrs[i].p_type != PT_LOAD) {
CHUNK_NO_LOAD(i); /* mark no load chunk */
DBG_PRT((L"%s : skipping segment %ld\n", LD_NAME, i));
DBG_PRT((L"%s : skipping segment %d\n", LD_NAME, i));
continue;
}
CHUNK_CAN_LOAD(i); /* mark no load chunk */
VERB_PRT(3,
Print(L"\n%s : segment %ld vaddr [0x%lx-0x%lx] offset %ld filesz %ld "
"memsz=%ld bss_sz=%ld\n",
Print(L"\n%s : segment %d vaddr ["PTR_FMT"-"PTR_FMT"] offset %d filesz %d "
"memsz=%d bss_sz=%d\n",
LD_NAME, 1+i, chunks[i].addr, chunks[i].addr+phdrs[i].p_filesz,
chunks[i].offset, chunks[i].size, memsz, chunks[i].bss_sz));
@ -364,12 +364,12 @@ first_block (const char *buf, long blocksize)
}
if (low_addr & (EFI_PAGE_SIZE - 1)) {
ERR_PRT((L"%s : low_addr not page aligned 0x%lx\n", LD_NAME, low_addr));
ERR_PRT((L"%s : low_addr not page aligned "PTR_FMT"\n", LD_NAME, low_addr));
goto error;
}
analyze_chunks();
DBG_PRT((L"%s : %d program headers entry=0x%lx\nlowest_addr=0x%lx highest_addr=0x%lx\n",
DBG_PRT((L"%s : %d program headers entry=" PTR_FMT "\nlowest_addr="PTR_FMT" highest_addr="PTR_FMT"\n",
LD_NAME,
phnum, kernel_entry, low_addr, max_addr));
@ -384,9 +384,9 @@ first_block (const char *buf, long blocksize)
/* allocate memory for the kernel */
if (alloc_kmem((void *)low_addr, pages) == -1) {
ERR_PRT((L"%s : AllocatePages(%d, 0x%lx) for kernel failed\n",
ERR_PRT((L"%s : AllocatePages(%d, "PTR_FMT") for kernel failed\n",
LD_NAME, pages, low_addr));
ERR_PRT((L"%s : Could not load kernel at 0x%lx\n", LD_NAME, low_addr));
ERR_PRT((L"%s : Could not load kernel at "PTR_FMT"\n", LD_NAME, low_addr));
ERR_PRT((L"%s : Bailing\n", LD_NAME));
goto error;
}
@ -430,12 +430,12 @@ flush_window(void)
static const CHAR8 helicopter[4] = { '|' , '/' , '-' , '\\' };
static UINTN heli_count;
struct segment *cp;
char *src, *dst;
unsigned char *src, *dst;
long cnt;
if (!outcnt) return;
DBG_PRT((L"%s : flush_window outnct=%d file_offset=%ld\n", LD_NAME, outcnt, file_offset));
DBG_PRT((L"%s : flush_window outnct=%d file_offset=%d\n", LD_NAME, outcnt, file_offset));
Print(L"%c\b",helicopter[heli_count++%4]);
@ -468,7 +468,7 @@ tail:
file_offset += skip;
outcnt -= skip;
}
dst = (char *)cp->addr + (file_offset - cp->offset);
dst = (unsigned char *)cp->addr + (file_offset - cp->offset);
cnt = cp->offset + cp->size - file_offset;
if (cnt > outcnt)
cnt = outcnt;
@ -482,7 +482,7 @@ tail:
/* See if we are at the end of this chunk */
if (file_offset == cp->offset + cp->size) {
if (cp->bss_sz) {
dst = (char *)cp->addr + cp->size;
dst = (unsigned char *)cp->addr + cp->size;
Memset(dst, 0, cp->bss_sz);
}
nextchunk();

View file

@ -111,7 +111,7 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
}
VERB_PRT(3, {
Print(L"ELF Header information: \n");
Print(L"\tEntry point 0x%x\n", (ehdr.e_entry & PADDR_MASK));
Print(L"\tEntry point "PTR_FMT"\n", (ehdr.e_entry & PADDR_MASK));
Print(L"\t%d program headers\n", ehdr.e_phnum);
Print(L"\t%d segment headers\n", ehdr.e_shnum);
});
@ -145,8 +145,8 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
paddr = (phdrs[i].p_paddr & PADDR_MASK);
memsz = phdrs[i].p_memsz;
DBG_PRT((L"Phdr %d paddr [0x%x-0x%x] offset 0x%x"
" filesz 0x%x memsz=0x%x bss_sz=0x%x p_type=0x%x\n",
DBG_PRT((L"Phdr %d paddr ["PTR_FMT"-"PTR_FMT"] offset "PTR_FMT""
" filesz "PTR_FMT" memsz="PTR_FMT" bss_sz="PTR_FMT" p_type="PTR_FMT"\n",
1+i, paddr, paddr+phdrs[i].p_filesz, phdrs[i].p_offset,
phdrs[i].p_filesz, memsz,
(memsz - phdrs[i].p_filesz), phdrs[i].p_type));
@ -160,7 +160,7 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
}
if ((UINTN)low_addr & (EFI_PAGE_SIZE - 1)) {
ERR_PRT((L"%s : kernel low address 0x%x not page aligned\n",
ERR_PRT((L"%s : kernel low address "PTR_FMT" not page aligned\n",
LD_NAME, low_addr));
goto out;
}
@ -176,16 +176,16 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
kd->kentry = (VOID *)(ehdr.e_entry & PADDR_MASK);
VERB_PRT(3, {
Print(L"Lowest PhysAddr: 0x%x\nTotalMemSize:%d bytes (%d pages)\n",
Print(L"Lowest PhysAddr: "PTR_FMT"\nTotalMemSize:%d bytes (%d pages)\n",
low_addr, total_size, pages);
Print(L"Kernel entry @ 0x%x\n", kd->kentry);
Print(L"Kernel entry @ "PTR_FMT"\n", kd->kentry);
});
/* now allocate memory for the kernel at the exact requested spot */
if (alloc_kmem(low_addr, pages) == -1) {
ERR_PRT((L"%s : AllocatePages(%d, 0x%lx) for kernel failed\n",
ERR_PRT((L"%s : AllocatePages(%d, "PTR_FMT") for kernel failed\n",
LD_NAME, pages, low_addr));
ERR_PRT((L"%s : Could not alloc %d pages for the kernel at 0x%lx "
ERR_PRT((L"%s : Could not alloc %d pages for the kernel at "PTR_FMT""
" and relocation is not not been implemented!\n",
LD_NAME, pages, low_addr));
goto load_abort;
@ -206,7 +206,7 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
if (phdrs[i].p_type != PT_LOAD)
continue;
VERB_PRT(3, Print(L"poffs: 0x%x (phdrs[%d].p_offset)\n",
VERB_PRT(3, Print(L"poffs: "PTR_FMT" (phdrs[%d].p_offset)\n",
phdrs[i].p_offset, i));
filesz = phdrs[i].p_filesz;
@ -221,9 +221,9 @@ load_elf(fops_fd_t fd, kdesc_t *kd)
VERB_PRT(4, {
Print(L"\nHeader #%d\n", i);
Print(L"Offset in file 0x%x\n", phdrs[i].p_offset);
Print(L"Physical addr 0x%x\n", low_addr);
Print(L"BSS size 0x%x bytes\n", bss_sz);
Print(L"Offset in file "PTR_FMT"\n", phdrs[i].p_offset);
Print(L"Physical addr "PTR_FMT"\n", low_addr);
Print(L"BSS size %d bytes\n", bss_sz);
});
/*

View file

@ -35,6 +35,9 @@
#define ELILO_ARCH "IA-32" /* ASCII string */
#define PADDR_MASK 0xfffffff
#define INITRD_START (15*1024*1024)
#define DEFAULT_KERNEL_START 0x100000
/* for now use library versions */
#define Memset(a,v,n) SetMem((a),(n),(v))
#define Memcpy(a,b,n) CopyMem((a),(b),(n))
@ -299,11 +302,17 @@ typedef union ia32_boot_params {
UINT8 *t = (UINT8 *)(to); \
UINT8 *f = (UINT8 *)(from); \
UINTN n = cnt; \
if (t && f && n) { \
while (n--) { \
*t++ = *f++; \
} \
} \
if (t && f && n && (t<f)) { \
while (n--) { \
*t++ = *f++; \
} \
} else if (t && f && n && (t>f)) { \
t += n; \
f += n; \
while (n--) { \
*t-- = *f--; \
} \
} \
}
#define MEMSET(ptr, size, val) { \
@ -338,6 +347,7 @@ extern UINTN kernel_size;
extern VOID *initrd_start;
extern UINTN initrd_size;
extern VOID *kernel_load_address;
extern dt_addr_t gdt_addr;
extern dt_addr_t idt_addr;
@ -357,19 +367,31 @@ extern INTN ia32_use_legacy_free_boot();
static inline void
start_kernel(VOID *kentry, boot_params_t *bp)
{
UINT32 temp;
/*
* Disable interrupts.
*/
asm volatile ( "cli" : : );
/*
* Relocate initrd, if present.
*/
/*
* Relocate kernel (if needed), and initrd (if present).
* Copy kernel first, in case kernel was loaded overlapping where we're
* planning to copy the initrd. This assumes that the initrd didn't
* get loaded overlapping where we're planning to copy the kernel, but
* that's pretty unlikely since we couldn't alloc that space for the
* kernel (or the kernel would already be there).
*/
if (kernel_start != kernel_load_address) {
MEMCPY(kernel_start, kernel_load_address, kernel_size);
}
if (bp->s.initrd_start) {
temp = bp->s.initrd_start;
MEMCPY(INITRD_START, temp , bp->s.initrd_size);
bp->s.initrd_start = INITRD_START;
}
if (bp->s.initrd_start) {
MEMCPY(15 * 1024 * 1024, bp->s.initrd_start, bp->s.initrd_size);
bp->s.initrd_start = 15 * 1024 * 1024;
}
/*
* Copy boot sector, setup data and command line
* to final resting place. We need to copy

View file

@ -97,7 +97,10 @@ UINTN high_base_mem = 0x90000;
UINTN high_ext_mem = 32 * 1024 * 1024;
/* This starting address will hold true for all of the loader types for now */
VOID *kernel_start = (VOID *)0x100000; /* 1M */
VOID *kernel_start = (VOID *)DEFAULT_KERNEL_START;
/* The kernel may load elsewhere if EFI firmware reserves kernel_start */
VOID *kernel_load_address = (VOID *)DEFAULT_KERNEL_START;
VOID *initrd_start = NULL;
UINTN initrd_size = 0;
@ -131,16 +134,16 @@ sysdeps_initrd_get_addr(kdesc_t *kd, memdesc_t *imem)
DBG_PRT((L"initrd_get_addr()\n"));
if (!kd || !imem) {
ERR_PRT((L"kd=0x%x imem=0x%x", kd, imem));
ERR_PRT((L"kd=" PTR_FMT " imem=" PTR_FMT, kd, imem));
return -1;
}
VERB_PRT(3, Print(L"kstart=0x%x kentry=0x%x kend=0x%x\n",
VERB_PRT(3, Print(L"kstart=" PTR_FMT " kentry=" PTR_FMT " kend=" PTR_FMT "\n",
kd->kstart, kd->kentry, kd->kend));
imem->start_addr = kd->kend;
VERB_PRT(3, Print(L"initrd start_addr=0x%x pgcnt=%d\n",
VERB_PRT(3, Print(L"initrd start_addr=" PTR_FMT " pgcnt=%d\n",
imem->start_addr, imem->pgcnt));
return 0;
@ -156,6 +159,24 @@ sysdeps_free_boot_params(boot_params_t *bp)
free_memmap(&md);
}
static VOID find_bits(unsigned long mask, UINT8 *first, UINT8* len) {
unsigned char bit_pos = 0, bit_len = 0;
*first =0;
*len = 0;
if (mask == 0)
return;
while (!(mask & 0x1)) {
mask = mask >> 1;
bit_pos++;
}
while (mask & 0x1) {
mask = mask >> 1;
bit_len++;
}
*first = bit_pos;
*len = bit_len;
}
/*
* Get video information.
*/
@ -163,10 +184,11 @@ static INTN get_video_info(boot_params_t * bp) {
EFI_GUID GopProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop_interface;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Gop_info;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Gop_mode;
EFI_HANDLE *Gop_handle;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Gop_mode = NULL;
EFI_HANDLE *Gop_handle = NULL;
EFI_STATUS efi_status;
UINTN size, size1;
UINTN size = 0;
UINTN size1;
UINT8 i;
efi_status = uefi_call_wrapper(
@ -204,7 +226,7 @@ static INTN get_video_info(boot_params_t * bp) {
3,
*Gop_handle,
&GopProtocol,
&Gop_interface);
(VOID **) &Gop_interface);
if (EFI_ERROR(efi_status)) {
continue;
@ -428,7 +450,7 @@ sysdeps_create_boot_params(
DBG_PRT((L"fill_boot_params()\n"));
if (!bp || !cmdline || !initrd || !cookie) {
ERR_PRT((L"bp=0x%x cmdline=0x%x initrd=0x%x cookie=0x%x",
ERR_PRT((L"bp=" PTR_FMT " cmdline=" PTR_FMT " initrd=" PTR_FMT " cookie=" PTR_FMT,
bp, cmdline, initrd, cookie));
if (param_start != NULL) {
@ -515,7 +537,7 @@ sysdeps_create_boot_params(
* Initial RAMdisk and root device stuff.
*/
DBG_PRT((L"initrd->start_addr=0x%x initrd->pgcnt=%d\n",
DBG_PRT((L"initrd->start_addr=" PTR_FMT " initrd->pgcnt=%d\n",
initrd->start_addr, initrd->pgcnt));
/* These RAMdisk flags are not needed, just zero them. */
@ -597,7 +619,7 @@ sysdeps_create_boot_params(
#define WAIT_FOR_KEY() \
{ \
EFI_INPUT_KEY key; \
while (ST->ConIn->ReadKeyStroke(ST->ConIn, &key) != EFI_SUCCESS) { \
while (uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &key) != EFI_SUCCESS) { \
; \
} \
}
@ -697,7 +719,9 @@ sysdeps_create_boot_params(
if (!get_video_info(bp)) goto do_memmap;
efi_status = ST->ConOut->QueryMode(
efi_status = uefi_call_wrapper(
ST->ConOut->QueryMode,
4,
ST->ConOut,
ST->ConOut->Mode->Mode,
&cols,