From owner-freebsd-ia64 Wed Jun 19 12:40:16 2002 Delivered-To: freebsd-ia64@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id CBB5937B407 for ; Wed, 19 Jun 2002 12:40:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g5JJe2G76445; Wed, 19 Jun 2002 12:40:02 -0700 (PDT) (envelope-from gnats) Date: Wed, 19 Jun 2002 12:40:02 -0700 (PDT) Message-Id: <200206191940.g5JJe2G76445@freefall.freebsd.org> To: freebsd-ia64@FreeBSD.org Cc: From: Espen Skoglund Subject: Re: ia64/39415: Bootloader assuming 8KB buffer when only 4KB is allocated Reply-To: Espen Skoglund Sender: owner-freebsd-ia64@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR ia64/39415; it has been noted by GNATS. From: Espen Skoglund To: Marcel Moolenaar Cc: Espen Skoglund , FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: ia64/39415: Bootloader assuming 8KB buffer when only 4KB is allocated Date: Wed, 19 Jun 2002 21:29:23 +0200 [Marcel Moolenaar] > It looks to me that rounding to a multiple of the EFI page size is > more natural for an EFI application. I would probably fix bootinfo.c > instead of elf_freebsd.c. A second reason for fixing bootinfo.c is > that elf_freebsd.c works with arbitrary large bootinfo blocks, while > bootinfo.c only works if the bootinfo block is smaller than 8KB. > A second order fix would be to allocate enough; not just for the > bootinfo blocks, but also for the memory map... > Thoughts? You're right. It makes more sense to fix it properly. Here's a better fix. It gets the size of the memmap and uses it for determining the allocation size. The size of the allocated memory behind the bootinfo is then passed on to bootinfo.c (the size of memmap itself is not passed since it may increase due to an AllocatePages() call). eSk ================================================================ --- elf_freebsd.c.orig Wed Jun 19 21:14:43 2002 +++ elf_freebsd.c Wed Jun 19 21:16:04 2002 @@ -143,15 +143,22 @@ struct ia64_pte pte; struct bootinfo *bi; u_int64_t psr; - UINTN mapkey; + UINTN mapkey, size, dummy1; + UINT32 dummy2; EFI_STATUS status; if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL) return(EFTYPE); /* XXX actually EFUCKUP */ hdr = (Elf_Ehdr *)&(md->md_data); + /* Get size of EFI memory map */ + size = 0; + BS->GetMemoryMap(&size, (EFI_MEMORY_DESCRIPTOR *)&dummy1, + &mapkey, &dummy1, &dummy2); + + size = EFI_SIZE_TO_PAGES(sizeof(struct bootinfo) + size); status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, - EFI_SIZE_TO_PAGES(sizeof(struct bootinfo)), (void*)&bi); + size, (void*)&bi); if (EFI_ERROR(status)) { printf("unable to create bootinfo block (status=0x%lx)\n", (long)status); @@ -159,7 +166,8 @@ } bzero(bi, sizeof(struct bootinfo)); - bi_load(bi, fp, &mapkey); + bi_load(bi, fp, &mapkey, + (size << EFI_PAGE_SHIFT) - sizeof(struct bootinfo)); printf("Entering %s at 0x%lx...\n", fp->f_name, hdr->e_entry); --- bootinfo.c.orig Wed Jun 19 21:14:50 2002 +++ bootinfo.c Wed Jun 19 21:15:46 2002 @@ -242,7 +242,8 @@ * - Module metadata are formatted and placed in kernel space. */ int -bi_load(struct bootinfo *bi, struct preloaded_file *fp, UINTN *mapkey) +bi_load(struct bootinfo *bi, struct preloaded_file *fp, UINTN *mapkey, + UINTN alloced_size) { char *rootdevname; struct efi_devdesc *rootdev; @@ -331,7 +332,7 @@ /* read memory map and stash it after bootinfo */ bi->bi_memmap = (u_int64_t)(bi + 1); - bi->bi_memmap_size = 8192 - sizeof(struct bootinfo); + bi->bi_memmap_size = alloced_size; status = BS->GetMemoryMap(&bi->bi_memmap_size, (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap, &key, To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ia64" in the body of the message