Skip to content

Commit

Permalink
qboot: modified the malloc for fseg and high momory.
Browse files Browse the repository at this point in the history
The fseg and high memory malloc all use the up align
mode in do_alloc(),which will result in qboot hang
issue.The high memory use the down align mode and fseg
memory use the up align mode. With those changes,the
qemu can boot up the image with qboot.

Signed-off-by: Yang Zhong <yang.zhong@intel.com>
Message-Id: <1490869250-4357-1-git-send-email-yang.zhong@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
yangzhon authored and bonzini committed Mar 30, 2017
1 parent fd8d084 commit ea7d0e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
13 changes: 11 additions & 2 deletions include/string.h
Expand Up @@ -23,7 +23,16 @@ static inline void *memcpy(void *dest, const void *src, size_t n)
return __builtin_memcpy(dest, src, n);
}

void *malloc(int n);
void *malloc_fseg(int n);
void *malloc_align(int n, int align);
void *malloc_fseg_align(int n, int align);

static inline void *malloc(int n)
{
return malloc_align(n, 16);
}

static inline void *malloc_fseg(int n)
{
return malloc_fseg_align(n, 16);
}
#endif
12 changes: 7 additions & 5 deletions malloc.c
Expand Up @@ -5,15 +5,17 @@
static uint8_t *fseg_base = &edata;
static uint8_t *malloc_top = &stext;

void *malloc(int n)
void *malloc_align(int n, int align)
{
malloc_top -= (n + 15) & -16;
malloc_top = (uint8_t *) ((uintptr_t)(malloc_top - n) & -align);
return malloc_top;
}

void *malloc_fseg(int n)
void *malloc_fseg_align(int n, int align)
{
void *p = fseg_base;
fseg_base += (n + 15) & -16;
void *p;
fseg_base = (uint8_t *) (((uintptr_t)fseg_base + align - 1) & -align);
p = fseg_base;
fseg_base += n;
return p;
}
10 changes: 4 additions & 6 deletions tables.c
Expand Up @@ -57,15 +57,13 @@ static void do_alloc(char *file, uint32_t align, uint8_t zone)
if (id == -1)
panic();

if (align > 16)
n += align - 16;
if (align < 16)
align = 16;

if (zone == ALLOC_FSEG)
p = malloc_fseg(n);
p = malloc_fseg_align(n, align);
else
p = malloc(n);

p = (char *)((uintptr_t)(p + align - 1) & -align);
p = malloc_align(n, align);

set_file_addr(id, p);
fw_cfg_read_file(id, p, n);
Expand Down

0 comments on commit ea7d0e3

Please sign in to comment.