mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
Don't assume that pointer and cell size are identical, part 1
On ppc64, cell size is 32 bits but pointers are 64-bit. Thus, direct casts result in warnings, treated as errors. Use [u]intptr_t cast or cell2pointer and pointer2cell macros as necessary. v2: * Drop changes related to physical addresses since physical addresses may be wider than pointers (e.g., 36 bits on sparc32, as pointed out by Blue). * Drop changes to cell2pointer() and pointer2cell() for now. Signed-off-by: Andreas Färber <andreas.faerber@web.de> git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@922 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
committed by
Andreas Färber
parent
28516584d1
commit
380cd335cc
@@ -28,7 +28,7 @@
|
||||
void
|
||||
push_str( const char *str )
|
||||
{
|
||||
PUSH( (ucell)str );
|
||||
PUSH( pointer2cell(str) );
|
||||
PUSH( str ? strlen(str) : 0 );
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ _parword( const char *method, xt_t *cache_xt )
|
||||
void
|
||||
bind_func( const char *name, void (*func)(void) )
|
||||
{
|
||||
PUSH( (ucell)func );
|
||||
PUSH( pointer2cell(func) );
|
||||
push_str( name );
|
||||
fword("is-cfunc");
|
||||
}
|
||||
@@ -111,7 +111,7 @@ bind_xtfunc( const char *name, xt_t xt, ucell arg, void (*func)(void) )
|
||||
{
|
||||
PUSH_xt( xt );
|
||||
PUSH( arg );
|
||||
PUSH( (cell)func );
|
||||
PUSH( pointer2cell(func) );
|
||||
push_str( name );
|
||||
fword("is-xt-cfunc");
|
||||
}
|
||||
@@ -119,7 +119,7 @@ bind_xtfunc( const char *name, xt_t xt, ucell arg, void (*func)(void) )
|
||||
xt_t
|
||||
bind_noname_func( void (*func)(void) )
|
||||
{
|
||||
PUSH( (ucell)func );
|
||||
PUSH( pointer2cell(func) );
|
||||
fword("is-noname-cfunc");
|
||||
return POP_xt();
|
||||
}
|
||||
@@ -249,7 +249,7 @@ char *
|
||||
pop_fstr_copy( void )
|
||||
{
|
||||
int len = POP();
|
||||
char *str, *p = (char*)POP();
|
||||
char *str, *p = (char*)cell2pointer(POP());
|
||||
if( !len )
|
||||
return NULL;
|
||||
str = malloc( len + 1 );
|
||||
@@ -279,7 +279,7 @@ set_property( phandle_t ph, const char *name, const char *buf, int len )
|
||||
printk("set_property: NULL phandle\n");
|
||||
return;
|
||||
}
|
||||
PUSH((ucell)buf);
|
||||
PUSH(pointer2cell(buf));
|
||||
PUSH(len);
|
||||
push_str( name );
|
||||
PUSH_ph(ph);
|
||||
@@ -309,7 +309,7 @@ get_property( phandle_t ph, const char *name, int *retlen )
|
||||
len = POP();
|
||||
if( retlen )
|
||||
*retlen = len;
|
||||
return (char*)POP();
|
||||
return (char*)cell2pointer(POP());
|
||||
}
|
||||
|
||||
u32
|
||||
@@ -426,7 +426,7 @@ static void
|
||||
call1_func( void )
|
||||
{
|
||||
void (*func)(cell v);
|
||||
func = (void*)POP();
|
||||
func = (void*)cell2pointer(POP());
|
||||
|
||||
(*func)( POP() );
|
||||
}
|
||||
@@ -455,7 +455,7 @@ add_methods( int flags, int size, const method_t *methods, int nmet )
|
||||
char *buf = NULL;
|
||||
if( xt ) {
|
||||
enterforth( xt );
|
||||
buf = (char*)POP();
|
||||
buf = (char*)cell2pointer(POP());
|
||||
}
|
||||
(*(initfunc)methods[i].func)( buf );
|
||||
continue;
|
||||
@@ -463,7 +463,7 @@ add_methods( int flags, int size, const method_t *methods, int nmet )
|
||||
if( !size )
|
||||
bind_func( methods[i].name, methods[i].func );
|
||||
else
|
||||
bind_xtfunc( methods[i].name, xt, (ucell)methods[i].func,
|
||||
bind_xtfunc( methods[i].name, xt, pointer2cell(methods[i].func),
|
||||
&call1_func );
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ bootinfo_init_program(void)
|
||||
filename = get_filename(bootpath, &directory);
|
||||
|
||||
feval("load-base");
|
||||
base = (char*)POP();
|
||||
base = (char*)cell2pointer(POP());
|
||||
|
||||
feval("load-size");
|
||||
size = POP();
|
||||
|
||||
@@ -478,12 +478,12 @@ elf_init_program(void)
|
||||
Elf_phdr *phdr;
|
||||
size_t size, total_size = 0;
|
||||
char *addr;
|
||||
cell tmp;
|
||||
uintptr_t tmp;
|
||||
|
||||
/* TODO: manage ELF notes section */
|
||||
feval("0 state-valid !");
|
||||
feval("load-base");
|
||||
base = (char*)POP();
|
||||
base = (char*)cell2pointer(POP());
|
||||
|
||||
ehdr = (Elf_ehdr *)base;
|
||||
|
||||
|
||||
@@ -41,42 +41,42 @@ void init_program(void)
|
||||
addr = POP();
|
||||
|
||||
#ifdef CONFIG_LOADER_AOUT
|
||||
if (is_aout((struct exec *)addr)) {
|
||||
if (is_aout((struct exec *)cell2pointer(addr))) {
|
||||
aout_init_program();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOADER_BOOTINFO
|
||||
if (is_bootinfo((char *)addr)) {
|
||||
if (is_bootinfo((char *)cell2pointer(addr))) {
|
||||
bootinfo_init_program();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOADER_ELF
|
||||
if (is_elf((Elf_ehdr *)addr)) {
|
||||
if (is_elf((Elf_ehdr *)cell2pointer(addr))) {
|
||||
elf_init_program();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOADER_FCODE
|
||||
if (is_fcode((unsigned char *)addr)) {
|
||||
if (is_fcode((unsigned char *)cell2pointer(addr))) {
|
||||
fcode_init_program();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOADER_FORTH
|
||||
if (is_forth((char *)addr)) {
|
||||
if (is_forth((char *)cell2pointer(addr))) {
|
||||
forth_init_program();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LOADER_XCOFF
|
||||
if (is_xcoff((COFF_filehdr_t *)addr)) {
|
||||
if (is_xcoff((COFF_filehdr_t *)cell2pointer(addr))) {
|
||||
xcoff_init_program();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void* ofmem_malloc( size_t size )
|
||||
|
||||
top = ofmem_arch_get_heap_top();
|
||||
|
||||
if( (ucell)ofmem->next_malloc + size > top ) {
|
||||
if( pointer2cell(ofmem->next_malloc) + size > top ) {
|
||||
printk("out of malloc memory (%x)!\n", size );
|
||||
return NULL;
|
||||
}
|
||||
@@ -183,10 +183,9 @@ ofmem_set_property( phandle_t ph, const char *name, const char *buf, int len )
|
||||
printk("ofmem_set_property: NULL phandle\n");
|
||||
return;
|
||||
}
|
||||
PUSH((ucell)buf);
|
||||
PUSH(pointer2cell(buf));
|
||||
PUSH(len);
|
||||
PUSH((ucell)name);
|
||||
PUSH(strlen(name));
|
||||
push_str(name);
|
||||
PUSH_ph(ph);
|
||||
fword("encode-property");
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ xcoff_init_program(void)
|
||||
feval("0 state-valid !");
|
||||
|
||||
feval("load-base");
|
||||
base = (char*)POP();
|
||||
base = (char*)cell2pointer(POP());
|
||||
|
||||
fhdr = (COFF_filehdr_t*)base;
|
||||
|
||||
@@ -111,22 +111,22 @@ xcoff_init_program(void)
|
||||
|
||||
if (strcmp(shdr->s_name, ".text") == 0) {
|
||||
|
||||
memcpy((char*)shdr->s_vaddr, base + shdr->s_scnptr,
|
||||
memcpy((char*)(uintptr_t)shdr->s_vaddr, base + shdr->s_scnptr,
|
||||
shdr->s_size);
|
||||
total_size += shdr->s_size;
|
||||
#ifdef CONFIG_PPC
|
||||
flush_icache_range((char*)shdr->s_vaddr,
|
||||
(char*)(shdr->s_vaddr + shdr->s_size));
|
||||
flush_icache_range((char*)(uintptr_t)shdr->s_vaddr,
|
||||
(char*)(uintptr_t)(shdr->s_vaddr + shdr->s_size));
|
||||
#endif
|
||||
} else if (strcmp(shdr->s_name, ".data") == 0) {
|
||||
|
||||
memcpy((char*)shdr->s_vaddr, base + shdr->s_scnptr,
|
||||
memcpy((char*)(uintptr_t)shdr->s_vaddr, base + shdr->s_scnptr,
|
||||
shdr->s_size);
|
||||
total_size += shdr->s_size;
|
||||
|
||||
} else if (strcmp(shdr->s_name, ".bss") == 0) {
|
||||
|
||||
memset((void *)shdr->s_vaddr, 0, shdr->s_size);
|
||||
memset((void *)(uintptr_t)shdr->s_vaddr, 0, shdr->s_size);
|
||||
total_size += shdr->s_size;
|
||||
} else {
|
||||
DPRINTF(" Skip '%s' section\n", shdr->s_name);
|
||||
@@ -137,7 +137,7 @@ xcoff_init_program(void)
|
||||
DPRINTF("XCOFF entry point: %x\n", *(uint32_t*)ahdr->entry);
|
||||
|
||||
// Initialise saved-program-state
|
||||
PUSH(*(uint32_t*)ahdr->entry);
|
||||
PUSH(*(uint32_t*)(uintptr_t)ahdr->entry);
|
||||
feval("saved-program-state >sps.entry !");
|
||||
PUSH(total_size);
|
||||
feval("saved-program-state >sps.file-size !");
|
||||
|
||||
Reference in New Issue
Block a user