From 593bbd21955c092921e03dbe52d261939267da4c Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Thu, 2 Nov 2006 17:28:38 +0000 Subject: [PATCH] Revert the last change. Masking only 2 MSBs of the virtual address to get the physical address doesn't work for all values of KVA_PAGES, while masking 8 MSBs works for all values of KVA_PAGES that are multiple of 4 for non-PAE and 8 for PAE. (This leaves us limited with 12MB for non-PAE kernels and 14MB for PAE kernels.) To get things right, we'd need to subtract the KERNBASE from the virtual address (but KERNBASE is not easy to figure out from here), or have physical addresses set properly in the ELF headers. Discussed with: jhb --- sys/boot/common/load_elf.c | 2 +- sys/boot/i386/boot2/boot2.c | 6 +++--- sys/boot/i386/gptboot/gptboot.c | 6 +++--- sys/boot/i386/libi386/elf32_freebsd.c | 2 +- sys/boot/pc98/boot2/boot.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sys/boot/common/load_elf.c b/sys/boot/common/load_elf.c index be8f8815b24..cd983a982db 100644 --- a/sys/boot/common/load_elf.c +++ b/sys/boot/common/load_elf.c @@ -263,7 +263,7 @@ __elfN(loadimage)(struct preloaded_file *fp, elf_file_t ef, u_int64_t off) #if __ELF_WORD_SIZE == 64 off = - (off & 0xffffffffff000000ull);/* x86_64 relocates after locore */ #else - off = - (off & 0xc0000000u); /* i386 relocates after locore */ + off = - (off & 0xff000000u); /* i386 relocates after locore */ #endif #else off = 0; /* other archs use direct mapped kernels */ diff --git a/sys/boot/i386/boot2/boot2.c b/sys/boot/i386/boot2/boot2.c index b07c9eda5ba..df3fe81d17c 100644 --- a/sys/boot/i386/boot2/boot2.c +++ b/sys/boot/i386/boot2/boot2.c @@ -334,7 +334,7 @@ load(void) return; } if (fmt == 0) { - addr = hdr.ex.a_entry & 0x3fffffff; + addr = hdr.ex.a_entry & 0xffffff; p = PTOV(addr); fs_off = PAGE_SIZE; if (xfsread(ino, p, hdr.ex.a_text)) @@ -368,7 +368,7 @@ load(void) j++; } for (i = 0; i < 2; i++) { - p = PTOV(ep[i].p_paddr & 0x3fffffff); + p = PTOV(ep[i].p_paddr & 0xffffff); fs_off = ep[i].p_offset; if (xfsread(ino, p, ep[i].p_filesz)) return; @@ -389,7 +389,7 @@ load(void) p += es[i].sh_size; } } - addr = hdr.eh.e_entry & 0x3fffffff; + addr = hdr.eh.e_entry & 0xffffff; } bootinfo.bi_esymtab = VTOP(p); bootinfo.bi_kernelname = VTOP(kname); diff --git a/sys/boot/i386/gptboot/gptboot.c b/sys/boot/i386/gptboot/gptboot.c index b07c9eda5ba..df3fe81d17c 100644 --- a/sys/boot/i386/gptboot/gptboot.c +++ b/sys/boot/i386/gptboot/gptboot.c @@ -334,7 +334,7 @@ load(void) return; } if (fmt == 0) { - addr = hdr.ex.a_entry & 0x3fffffff; + addr = hdr.ex.a_entry & 0xffffff; p = PTOV(addr); fs_off = PAGE_SIZE; if (xfsread(ino, p, hdr.ex.a_text)) @@ -368,7 +368,7 @@ load(void) j++; } for (i = 0; i < 2; i++) { - p = PTOV(ep[i].p_paddr & 0x3fffffff); + p = PTOV(ep[i].p_paddr & 0xffffff); fs_off = ep[i].p_offset; if (xfsread(ino, p, ep[i].p_filesz)) return; @@ -389,7 +389,7 @@ load(void) p += es[i].sh_size; } } - addr = hdr.eh.e_entry & 0x3fffffff; + addr = hdr.eh.e_entry & 0xffffff; } bootinfo.bi_esymtab = VTOP(p); bootinfo.bi_kernelname = VTOP(kname); diff --git a/sys/boot/i386/libi386/elf32_freebsd.c b/sys/boot/i386/libi386/elf32_freebsd.c index c1363bc3871..5f66622add9 100644 --- a/sys/boot/i386/libi386/elf32_freebsd.c +++ b/sys/boot/i386/libi386/elf32_freebsd.c @@ -65,7 +65,7 @@ elf32_exec(struct preloaded_file *fp) err = bi_load32(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend); if (err != 0) return(err); - entry = ehdr->e_entry & 0x3fffffff; + entry = ehdr->e_entry & 0xffffff; #ifdef DEBUG printf("Start @ 0x%lx ...\n", entry); diff --git a/sys/boot/pc98/boot2/boot.c b/sys/boot/pc98/boot2/boot.c index 96dfb721d1a..feccc7ec035 100644 --- a/sys/boot/pc98/boot2/boot.c +++ b/sys/boot/pc98/boot2/boot.c @@ -199,9 +199,9 @@ loadprog(void) /* * We assume that the entry address is the same as the lowest text * address and that the kernel startup code handles relocation by - * this address rounded down to a multiple of 1G. + * this address rounded down to a multiple of 16M. */ - startaddr = head.a_entry & 0x3FFFFFFF; + startaddr = head.a_entry & 0x00FFFFFF; addr = startaddr; printf("Booting %d:%s(%d,%c)%s @ 0x%x\n" , dosdev & 0x0f