Use 64-bit math when finding a block of ram to hold the kernel. This fixes

a problem on 32-bit systems which have ram occupying the end of the physical
address space -- for example, a block of ram at 0x80000000 with a size of
0x80000000 was overflowing 32 bit math and ending up with a calculated size
of zero.

This is a fix for one of the two problems mentioned in the PR.  Something
similar will need to be done on the kernel side before the PR is closed.

PR:		201614
This commit is contained in:
Ian Lepore 2016-01-02 18:16:24 +00:00
parent b0bf7fcd29
commit 577353fcbf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=293053

View file

@ -69,11 +69,11 @@ uint64_t
uboot_loadaddr(u_int type, void *data, uint64_t addr)
{
struct sys_info *si;
uintptr_t sblock, eblock, subldr, eubldr;
uintptr_t biggest_block, this_block;
size_t biggest_size, this_size;
uint64_t sblock, eblock, subldr, eubldr;
uint64_t biggest_block, this_block;
uint64_t biggest_size, this_size;
int i;
char * envstr;
char *envstr;
if (addr == 0) {
/*
@ -100,14 +100,15 @@ uboot_loadaddr(u_int type, void *data, uint64_t addr)
biggest_block = 0;
biggest_size = 0;
subldr = rounddown2((uintptr_t)_start, KERN_ALIGN);
eubldr = roundup2(uboot_heap_end, KERN_ALIGN);
subldr = rounddown2((uint64_t)_start, KERN_ALIGN);
eubldr = roundup2((uint64_t)uboot_heap_end, KERN_ALIGN);
for (i = 0; i < si->mr_no; i++) {
if (si->mr[i].flags != MR_ATTR_DRAM)
continue;
sblock = roundup2(si->mr[i].start, KERN_ALIGN);
eblock = rounddown2(si->mr[i].start + si->mr[i].size,
sblock = roundup2((uint64_t)si->mr[i].start,
KERN_ALIGN);
eblock = rounddown2((uint64_t)si->mr[i].start +
si->mr[i].size, KERN_ALIGN);
if (biggest_size == 0)
sblock += KERN_MINADDR;
if (subldr >= sblock && subldr < eblock) {
@ -134,9 +135,10 @@ uboot_loadaddr(u_int type, void *data, uint64_t addr)
if (biggest_size == 0)
panic("Not enough DRAM to load kernel\n");
#if 0
printf("Loading kernel into region 0x%08x-0x%08x (%u MiB)\n",
biggest_block, biggest_block + biggest_size - 1,
biggest_size / 1024 / 1024);
printf("Loading kernel into region 0x%08jx-0x%08jx (%ju MiB)\n",
(uintmax_t)biggest_block,
(uintmax_t)biggest_block + biggest_size - 1,
(uintmax_t)biggest_size / 1024 / 1024);
#endif
return (biggest_block);
}