[OpenBIOS] [PATCH 3/3] Don't assume that pointer and cell size are identical
Andreas Färber
andreas.faerber at web.de
Mon Oct 18 01:18:25 CEST 2010
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.
Cc: Blue Swirl <blauwirbel at gmail.com>
Cc: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>
Cc: Alexander Graf <agraf at suse.de>
Signed-off-by: Andreas Färber <andreas.faerber at web.de>
---
Hey,
I've compile-tested ppc, ppc64, sparc32, sparc64; they all appeared to boot
as before now (Haiku, AIX, Debian, Solaris, Milax guests).
@Mark: I've taken the liberty of using push_str() in ofmem_set_property()
to avoid duplicating the conversion.
Cheers,
Andreas
arch/ppc/qemu/kernel.c | 16 ++++++++--------
arch/ppc/qemu/main.c | 2 +-
arch/ppc/qemu/methods.c | 4 ++--
arch/ppc/qemu/ofmem.c | 2 +-
drivers/adb_kbd.c | 6 +++---
drivers/cuda.c | 4 ++--
drivers/escc.c | 20 ++++++++++----------
drivers/ide.c | 2 +-
drivers/macio.c | 8 ++++----
drivers/macio.h | 6 +++---
fs/ext2/ext2_fs.c | 8 ++++----
fs/grubfs/grubfs_fs.c | 8 ++++----
fs/hfs/hfs_fs.c | 10 +++++-----
fs/hfsplus/hfsp_fs.c | 10 +++++-----
fs/iso9660/iso9660_fs.c | 4 ++--
include/arch/ppc/io.h | 18 +++++++++---------
include/drivers/drivers.h | 6 +++---
include/kernel/stack.h | 4 ++--
kernel/internal.c | 18 +++++++++---------
libc/diskio.c | 8 ++++----
libc/extra.c | 2 +-
libopenbios/bindings.c | 20 ++++++++++----------
libopenbios/bootinfo_load.c | 2 +-
libopenbios/elf_load.c | 4 ++--
libopenbios/initprogram.c | 12 ++++++------
libopenbios/ofmem_common.c | 7 +++----
libopenbios/xcoff_load.c | 14 +++++++-------
packages/deblocker.c | 4 ++--
packages/disk-label.c | 4 ++--
packages/mac-parts.c | 4 ++--
packages/nvram.c | 8 ++++----
packages/pc-parts.c | 4 ++--
packages/video.c | 4 ++--
33 files changed, 126 insertions(+), 127 deletions(-)
diff --git a/arch/ppc/qemu/kernel.c b/arch/ppc/qemu/kernel.c
index cafa167..dbfca57 100644
--- a/arch/ppc/qemu/kernel.c
+++ b/arch/ppc/qemu/kernel.c
@@ -40,13 +40,13 @@ forth_segv_handler( char *segv_addr )
{
ucell addr = 0xdeadbeef;
- if( PC >= (ucell) dict && PC <= (ucell) dict + dicthead )
- addr = *(ucell *) PC;
+ if( PC >= pointer2cell(dict) && PC <= pointer2cell(dict) + dicthead )
+ addr = *(ucell *)cell2pointer(PC);
- printk("panic: segmentation violation at %x\n", (int)segv_addr);
- printk("dict=0x%x here=0x%x(dict+0x%x) pc=0x%x(dict+0x%x)\n",
- (int)dict, (int)(dict + dicthead), dicthead,
- PC, PC - (ucell) dict);
+ printk("panic: segmentation violation at 0x%p\n", segv_addr);
+ printk("dict=0x%p here=0x%p(dict+0x%x) pc=0x%x(dict+0x%x)\n",
+ dict, (char*)dict + dicthead, dicthead,
+ PC, PC - pointer2cell(dict));
printk("dstackcnt=%d rstackcnt=%d instruction=%x\n",
dstackcnt, rstackcnt, addr);
@@ -75,8 +75,8 @@ init_memory( void )
* to initialize the memory allocator
*/
- PUSH( (ucell)memory );
- PUSH( (ucell)memory + MEMORY_SIZE );
+ PUSH( pointer2cell(memory) );
+ PUSH( pointer2cell(memory) + MEMORY_SIZE );
}
int
diff --git a/arch/ppc/qemu/main.c b/arch/ppc/qemu/main.c
index 2d4ae5a..f9c1a53 100644
--- a/arch/ppc/qemu/main.c
+++ b/arch/ppc/qemu/main.c
@@ -183,7 +183,7 @@ static void check_preloaded_kernel(void)
kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE);
if (kernel_size) {
kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR);
- kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE);
+ kernel_cmdline = (const char *)(uintptr_t) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE);
initrd_image = fw_cfg_read_i32(FW_CFG_INITRD_ADDR);
initrd_size = fw_cfg_read_i32(FW_CFG_INITRD_SIZE);
printk("[ppc] Kernel already loaded (0x%8.8lx + 0x%8.8lx) "
diff --git a/arch/ppc/qemu/methods.c b/arch/ppc/qemu/methods.c
index 71a364f..bbb101f 100644
--- a/arch/ppc/qemu/methods.c
+++ b/arch/ppc/qemu/methods.c
@@ -71,7 +71,7 @@ static void
tty_read( void )
{
int ch, len = POP();
- char *p = (char*)POP();
+ char *p = (char*)cell2pointer(POP());
int ret=0;
if( len > 0 ) {
@@ -91,7 +91,7 @@ static void
tty_write( void )
{
int i, len = POP();
- char *p = (char*)POP();
+ char *p = (char*)cell2pointer(POP());
for( i=0; i<len; i++ )
putchar( *p++ );
RET( len );
diff --git a/arch/ppc/qemu/ofmem.c b/arch/ppc/qemu/ofmem.c
index 189dae3..a507009 100644
--- a/arch/ppc/qemu/ofmem.c
+++ b/arch/ppc/qemu/ofmem.c
@@ -105,7 +105,7 @@ static inline size_t ALIGN_SIZE(size_t x, size_t a)
ofmem_t* ofmem_arch_get_private(void)
{
- return (ofmem_t*)(get_heap_top() - OFMEM_SIZE);
+ return (ofmem_t*)cell2pointer(get_heap_top() - OFMEM_SIZE);
}
void* ofmem_arch_get_malloc_base(void)
diff --git a/drivers/adb_kbd.c b/drivers/adb_kbd.c
index e65ba71..10a5197 100644
--- a/drivers/adb_kbd.c
+++ b/drivers/adb_kbd.c
@@ -483,7 +483,7 @@ static int adb_kbd_read (void *private)
int key;
int ret;
- kbd = (void *)dev->state;
+ kbd = (void *)(uintptr_t)dev->state;
if (kbd->len > 0) {
ret = kbd->sequence[kbd->len-- - 1];
@@ -531,7 +531,7 @@ void *adb_kbd_new (char *path, void *private)
ADB_kbd_us, ADB_sequences);
kbd->next_key = -1;
kbd->len = 0;
- dev->state = (int32_t)kbd;
+ dev->state = (uint32_t)(uintptr_t)kbd;
my_adb_dev = dev;
}
@@ -556,7 +556,7 @@ static void keyboard_read(void)
char *addr;
int len, key, i;
len=POP();
- addr=(char *)POP();
+ addr=(char *)cell2pointer(POP());
for (i = 0; i < len; i++) {
key = adb_kbd_read(my_adb_dev);
diff --git a/drivers/cuda.c b/drivers/cuda.c
index c254720..4d784de 100644
--- a/drivers/cuda.c
+++ b/drivers/cuda.c
@@ -65,12 +65,12 @@
static uint8_t cuda_readb (cuda_t *dev, int reg)
{
- return *(volatile uint8_t *)(dev->base + reg);
+ return *(volatile uint8_t *)(uintptr_t)(dev->base + reg);
}
static void cuda_writeb (cuda_t *dev, int reg, uint8_t val)
{
- *(volatile uint8_t *)(dev->base + reg) = val;
+ *(volatile uint8_t *)(uintptr_t)(dev->base + reg) = val;
}
static void cuda_wait_irq (cuda_t *dev)
diff --git a/drivers/escc.c b/drivers/escc.c
index dbf8262..c70e7ea 100644
--- a/drivers/escc.c
+++ b/drivers/escc.c
@@ -54,19 +54,19 @@ static volatile unsigned char *serial_dev;
#define Rx_CH_AV 0x1 /* Rx Character Available */
#define Tx_BUF_EMP 0x4 /* Tx Buffer empty */
-int uart_charav(int port)
+int uart_charav(uintptr_t port)
{
return (CTRL(port) & Rx_CH_AV) != 0;
}
-char uart_getchar(int port)
+char uart_getchar(uintptr_t port)
{
while (!uart_charav(port))
;
return DATA(port) & 0177;
}
-static void uart_putchar(int port, unsigned char c)
+static void uart_putchar(uintptr_t port, unsigned char c)
{
if (!serial_dev)
return;
@@ -102,7 +102,7 @@ static void uart_init_line(volatile unsigned char *port, unsigned long baud)
}
-int uart_init(uint64_t port, unsigned long speed)
+int uart_init(uintptr_t port, unsigned long speed)
{
#ifdef CONFIG_DRIVER_ESCC_SUN
serial_dev = map_io(port & ~7ULL, ZS_REGS);
@@ -116,7 +116,7 @@ int uart_init(uint64_t port, unsigned long speed)
void serial_putchar(int c)
{
- uart_putchar((int)serial_dev, (unsigned char) (c & 0xff));
+ uart_putchar((uintptr_t)serial_dev, (unsigned char) (c & 0xff));
}
void serial_cls(void)
@@ -137,10 +137,10 @@ escc_read(unsigned long *address)
int len;
len = POP();
- addr = (char *)POP();
+ addr = (char *)cell2pointer(POP());
if (len < 1)
- printk("escc_read: bad len, addr %x len %x\n", (unsigned int)addr, len);
+ printk("escc_read: bad len, addr %p len %x\n", addr, len);
if (uart_charav(*address)) {
*addr = (char)uart_getchar(*address);
@@ -158,7 +158,7 @@ escc_write(unsigned long *address)
int i, len;
len = POP();
- addr = (unsigned char *)POP();
+ addr = (unsigned char *)cell2pointer(POP());
for (i = 0; i < len; i++) {
uart_putchar(*address, addr[i]);
@@ -369,7 +369,7 @@ ob_zs_init(uint64_t base, uint64_t offset, int intr, int slave, int keyboard)
#else
static void
-escc_add_channel(const char *path, const char *node, uint32_t addr,
+escc_add_channel(const char *path, const char *node, uintptr_t addr,
uint32_t offset)
{
char buf[64], tty[32];
@@ -430,7 +430,7 @@ escc_add_channel(const char *path, const char *node, uint32_t addr,
}
void
-escc_init(const char *path, unsigned long addr)
+escc_init(const char *path, uintptr_t addr)
{
char buf[64];
int props[2];
diff --git a/drivers/ide.c b/drivers/ide.c
index 7006720..0d09bcd 100644
--- a/drivers/ide.c
+++ b/drivers/ide.c
@@ -1190,7 +1190,7 @@ ob_ide_read_blocks(int *idx)
{
cell n = POP(), cnt=n;
ucell blk = POP();
- unsigned char *dest = (unsigned char *)POP();
+ unsigned char *dest = (unsigned char *)cell2pointer(POP());
struct ide_drive *drive = *(struct ide_drive **)idx;
IDE_DPRINTF("ob_ide_read_blocks %lx block=%ld n=%ld\n",
diff --git a/drivers/macio.c b/drivers/macio.c
index d6d1696..55528c1 100644
--- a/drivers/macio.c
+++ b/drivers/macio.c
@@ -43,7 +43,7 @@ arch_nvram_size( void )
return NW_IO_NVRAM_SIZE >> NW_IO_NVRAM_SHIFT;
}
-void macio_nvram_init(const char *path, uint32_t addr)
+void macio_nvram_init(const char *path, uintptr_t addr)
{
phandle_t chosen, aliases;
phandle_t dnode;
@@ -145,7 +145,7 @@ arch_nvram_get( char *buf )
}
static void
-openpic_init(const char *path, uint32_t addr)
+openpic_init(const char *path, uintptr_t addr)
{
phandle_t target_node;
phandle_t dnode;
@@ -238,7 +238,7 @@ NODE_METHODS(ob_macio) = {
};
void
-ob_macio_heathrow_init(const char *path, uint32_t addr)
+ob_macio_heathrow_init(const char *path, uintptr_t addr)
{
phandle_t aliases;
@@ -253,7 +253,7 @@ ob_macio_heathrow_init(const char *path, uint32_t addr)
}
void
-ob_macio_keylargo_init(const char *path, uint32_t addr)
+ob_macio_keylargo_init(const char *path, uintptr_t addr)
{
phandle_t aliases;
diff --git a/drivers/macio.h b/drivers/macio.h
index d580387..9fcd167 100644
--- a/drivers/macio.h
+++ b/drivers/macio.h
@@ -1,5 +1,5 @@
extern phandle_t pic_handle;
-void ob_macio_heathrow_init(const char *path, uint32_t addr);
-void ob_macio_keylargo_init(const char *path, uint32_t addr);
-void macio_nvram_init(const char *path, uint32_t addr);
+void ob_macio_heathrow_init(const char *path, uintptr_t addr);
+void ob_macio_keylargo_init(const char *path, uintptr_t addr);
+void macio_nvram_init(const char *path, uintptr_t addr);
diff --git a/fs/ext2/ext2_fs.c b/fs/ext2/ext2_fs.c
index 970fb4d..66eb0b4 100644
--- a/fs/ext2/ext2_fs.c
+++ b/fs/ext2/ext2_fs.c
@@ -144,7 +144,7 @@ static void
ext2_files_read( ext2_info_t *mi )
{
int count = POP();
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
ext2_COMMON *common = mi->common;
if (common->type != FILE)
@@ -177,7 +177,7 @@ ext2_files_seek( ext2_info_t *mi )
static void
ext2_files_load( ext2_info_t *mi )
{
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
int count;
ext2_COMMON *common = mi->common;
@@ -201,14 +201,14 @@ ext2_files_get_path( ext2_info_t *mi )
if (common->type != FILE)
RET( 0 );
- RET( (ucell) strdup(common->file->path) );
+ RET( pointer2cell(strdup(common->file->path)) );
}
/* ( -- cstr ) */
static void
ext2_files_get_fstype( ext2_info_t *mi )
{
- PUSH( (ucell)strdup("ext2") );
+ PUSH( pointer2cell(strdup("ext2")) );
}
/* static method, ( pathstr len ihandle -- ) */
diff --git a/fs/grubfs/grubfs_fs.c b/fs/grubfs/grubfs_fs.c
index fc61943..acd2a64 100644
--- a/fs/grubfs/grubfs_fs.c
+++ b/fs/grubfs/grubfs_fs.c
@@ -238,7 +238,7 @@ static void
grubfs_files_read( grubfs_info_t *mi )
{
int count = POP();
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
grubfile_t *file = mi->gfs->fd;
int ret;
@@ -295,7 +295,7 @@ grubfs_files_seek( grubfs_info_t *mi )
static void
grubfs_files_load( grubfs_info_t *mi )
{
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
int count, ret;
grubfile_t *file = mi->gfs->fd;
@@ -314,7 +314,7 @@ grubfs_files_get_path( grubfs_info_t *mi )
grubfile_t *file = mi->gfs->fd;
const char *path = file->path;
- RET( (ucell) strdup(path) );
+ RET( pointer2cell(strdup(path)) );
}
/* ( -- cstr ) */
@@ -323,7 +323,7 @@ grubfs_files_get_fstype( grubfs_info_t *mi )
{
grubfs_t *gfs = mi->gfs;
- PUSH( (ucell)strdup(gfs->fsys->name) );
+ PUSH( pointer2cell(strdup(gfs->fsys->name)) );
}
diff --git a/fs/hfs/hfs_fs.c b/fs/hfs/hfs_fs.c
index 293dc18..2d62ec0 100644
--- a/fs/hfs/hfs_fs.c
+++ b/fs/hfs/hfs_fs.c
@@ -359,7 +359,7 @@ static void
hfs_files_read( hfs_info_t *mi )
{
int count = POP();
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
hfscommon *common = mi->common;
if (common->type != FILE)
@@ -402,7 +402,7 @@ hfs_files_seek( hfs_info_t *mi )
static void
hfs_files_load( hfs_info_t *mi )
{
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
int count;
hfscommon *common = mi->common;
@@ -461,14 +461,14 @@ hfs_files_get_path( hfs_info_t *mi )
if( strlen(buf) >= sizeof(buf) )
RET( 0 );
- RET( (ucell) strdup(buf+start) );
+ RET( pointer2cell(strdup(buf+start)) );
}
/* ( -- cstr ) */
static void
hfs_files_get_fstype( hfs_info_t *mi )
{
- PUSH( (ucell)strdup("HFS") );
+ PUSH( pointer2cell(strdup("HFS")) );
}
/* ( -- cstr|0 ) */
@@ -486,7 +486,7 @@ hfs_files_volume_name( hfs_info_t *mi )
volname[0] = '\0';
}
- PUSH ((ucell)volname);
+ PUSH(pointer2cell(volname));
}
/* static method, ( pathstr len ihandle -- ) */
diff --git a/fs/hfsplus/hfsp_fs.c b/fs/hfsplus/hfsp_fs.c
index 9c3deb3..83e4d8d 100644
--- a/fs/hfsplus/hfsp_fs.c
+++ b/fs/hfsplus/hfsp_fs.c
@@ -264,7 +264,7 @@ static void
hfsp_files_read( hfsp_info_t *mi )
{
int count = POP();
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
hfsp_file_t *t = mi->hfspfile;
volume *vol = t->rec.tree->vol;
@@ -350,7 +350,7 @@ hfsp_files_seek( hfsp_info_t *mi )
static void
hfsp_files_load( hfsp_info_t *mi )
{
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
hfsp_file_t *t = mi->hfspfile;
volume *vol = t->rec.tree->vol;
@@ -388,7 +388,7 @@ hfsp_files_load( hfsp_info_t *mi )
static void
hfsp_files_get_fstype( hfsp_info_t *mi )
{
- PUSH( (ucell)strdup("HFS+") );
+ PUSH( pointer2cell(strdup("HFS+")) );
}
/* ( -- cstr ) */
@@ -405,7 +405,7 @@ hfsp_files_get_path( hfsp_info_t *mi )
strncpy( buf, t->path, strlen(t->path) );
buf[strlen(t->path)] = 0;
- PUSH ((ucell)buf);
+ PUSH(pointer2cell(buf));
}
/* ( -- success? ) */
@@ -434,7 +434,7 @@ hfsp_files_volume_name( hfsp_info_t *mi )
volname[0] = '\0';
}
- PUSH ((ucell)volname);
+ PUSH(pointer2cell(volname));
}
/* static method, ( pathstr len ihandle -- ) */
diff --git a/fs/iso9660/iso9660_fs.c b/fs/iso9660/iso9660_fs.c
index 3fb5c16..d6f547b 100644
--- a/fs/iso9660/iso9660_fs.c
+++ b/fs/iso9660/iso9660_fs.c
@@ -90,7 +90,7 @@ static void
iso9660_files_read( iso9660_info_t *mi )
{
int count = POP();
- char *buf = (char *)POP();
+ char *buf = (char *)cell2pointer(POP());
int ret;
if ( mi->common->type != FILE )
@@ -137,7 +137,7 @@ iso9660_files_offset( iso9660_info_t *mi )
static void
iso9660_files_load( iso9660_info_t *mi)
{
- char *buf = (char*)POP();
+ char *buf = (char*)cell2pointer(POP());
int ret, size;
if ( mi->common->type != FILE )
diff --git a/include/arch/ppc/io.h b/include/arch/ppc/io.h
index d7c78a0..e5180f2 100644
--- a/include/arch/ppc/io.h
+++ b/include/arch/ppc/io.h
@@ -22,15 +22,15 @@ extern uint32_t isa_io_base;
* are arrays of bytes, and byte-swapping is not appropriate in
* that case. - paulus
*/
-#define insw(port, buf, ns) _insw((uint16_t *)((port)+isa_io_base), (buf), (ns))
-#define outsw(port, buf, ns) _outsw((uint16_t *)((port)+isa_io_base), (buf), (ns))
-
-#define inb(port) in_8((uint8_t *)((port)+isa_io_base))
-#define outb(val, port) out_8((uint8_t *)((port)+isa_io_base), (val))
-#define inw(port) in_le16((uint16_t *)((port)+isa_io_base))
-#define outw(val, port) out_le16((uint16_t *)((port)+isa_io_base), (val))
-#define inl(port) in_le32((uint32_t *)((port)+isa_io_base))
-#define outl(val, port) out_le32((uint32_t *)((port)+isa_io_base), (val))
+#define insw(port, buf, ns) _insw((uint16_t *)(uintptr_t)((port)+isa_io_base), (buf), (ns))
+#define outsw(port, buf, ns) _outsw((uint16_t *)(uintptr_t)((port)+isa_io_base), (buf), (ns))
+
+#define inb(port) in_8((uint8_t *)(uintptr_t)((port)+isa_io_base))
+#define outb(val, port) out_8((uint8_t *)(uintptr_t)((port)+isa_io_base), (val))
+#define inw(port) in_le16((uint16_t *)(uintptr_t)((port)+isa_io_base))
+#define outw(val, port) out_le16((uint16_t *)(uintptr_t)((port)+isa_io_base), (val))
+#define inl(port) in_le32((uint32_t *)(uintptr_t)((port)+isa_io_base))
+#define outl(val, port) out_le32((uint32_t *)(uintptr_t)((port)+isa_io_base), (val))
/*
* 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
diff --git a/include/drivers/drivers.h b/include/drivers/drivers.h
index 6829572..cf17d8e 100644
--- a/include/drivers/drivers.h
+++ b/include/drivers/drivers.h
@@ -113,9 +113,9 @@ char uart_getchar(int port);
void serial_putchar(int c);
#endif
#ifdef CONFIG_DRIVER_ESCC
-int uart_init(uint64_t port, unsigned long speed);
-int uart_charav(int port);
-char uart_getchar(int port);
+int uart_init(uintptr_t port, unsigned long speed);
+int uart_charav(uintptr_t port);
+char uart_getchar(uintptr_t port);
void serial_putchar(int c);
void serial_cls(void);
#ifdef CONFIG_DRIVER_ESCC_SUN
diff --git a/include/kernel/stack.h b/include/kernel/stack.h
index 809ffe9..44fef0f 100644
--- a/include/kernel/stack.h
+++ b/include/kernel/stack.h
@@ -31,8 +31,8 @@ typedef ucell phandle_t;
#ifdef NATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH
-#define pointer2cell(x) ((ucell)(x))
-#define cell2pointer(x) ((u8 *)(x))
+#define pointer2cell(x) ((ucell)(uintptr_t)(x))
+#define cell2pointer(x) ((u8 *)(uintptr_t)(x))
#endif
#ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH
#define pointer2cell(x) ((ucell)(((unsigned long)(x))-base_address))
diff --git a/kernel/internal.c b/kernel/internal.c
index be1f216..0235737 100644
--- a/kernel/internal.c
+++ b/kernel/internal.c
@@ -208,7 +208,7 @@ static void call(void)
exit(1);
#else
void (*funcptr) (void);
- funcptr=(void *)POP();
+ funcptr=(void *)cell2pointer(POP());
dbg_interp_printk("call: %x", funcptr);
funcptr();
#endif
@@ -329,7 +329,7 @@ static void doplusloop(void)
#ifndef FCOMPILER
static ucell get_myself(void)
{
- static ucell **myself = NULL;
+ static ucell **myself = NULL;
if( !myself )
myself = (ucell**)findword("my-self") + 1;
return (*myself && **myself) ? (ucell)**myself : 0;
@@ -337,35 +337,35 @@ static ucell get_myself(void)
static void doivar(void)
{
- ucell r, *p = (ucell *)(*(ucell *) PC + sizeof(ucell));
+ ucell r, *p = (ucell *)(*(ucell *) cell2pointer(PC) + sizeof(ucell));
ucell ibase = get_myself();
dbg_interp_printk("ivar, offset: %d size: %d (ibase %d)\n", p[0], p[1], ibase );
- r = ibase ? ibase + p[0] : (ucell)&p[2];
+ r = ibase ? ibase + p[0] : pointer2cell(&p[2]);
PUSH( r );
}
static void doival(void)
{
- ucell r, *p = (ucell *)(*(ucell *) PC + sizeof(ucell));
+ ucell r, *p = (ucell *)(*(ucell *) cell2pointer(PC) + sizeof(ucell));
ucell ibase = get_myself();
dbg_interp_printk("ivar, offset: %d size: %d\n", p[0], p[1] );
- r = ibase ? ibase + p[0] : (ucell)&p[2];
- PUSH( *(ucell *)r );
+ r = ibase ? ibase + p[0] : pointer2cell(&p[2]);
+ PUSH( *(ucell *)cell2pointer(r) );
}
static void doidefer(void)
{
- ucell *p = (ucell *)(*(ucell *) PC + sizeof(ucell));
+ ucell *p = (ucell *)(*(ucell *) cell2pointer(PC) + sizeof(ucell));
ucell ibase = get_myself();
dbg_interp_printk("doidefer, offset: %d size: %d\n", p[0], p[1] );
PUSHR(PC);
- PC = ibase ? ibase + p[0] : (ucell)&p[2];
+ PC = ibase ? ibase + p[0] : pointer2cell(&p[2]);
PC -= sizeof(ucell);
}
#else
diff --git a/libc/diskio.c b/libc/diskio.c
index 9f0fd0a..23f38eb 100644
--- a/libc/diskio.c
+++ b/libc/diskio.c
@@ -150,7 +150,7 @@ get_file_path( int fd )
if( lookup_xt(fdp->ih, "get-path", &fdp->get_path_xt) )
return NULL;
call_package( fdp->get_path_xt, fdp->ih );
- return (char*)POP();
+ return (char*)cell2pointer(POP());
}
const char *
@@ -160,7 +160,7 @@ get_volume_name( int fd )
if( lookup_xt(fdp->ih, "volume-name", &fdp->volume_name_xt) )
return NULL;
call_package( fdp->volume_name_xt, fdp->ih );
- return (char*)POP();
+ return (char*)cell2pointer(POP());
}
const char *
@@ -170,7 +170,7 @@ get_fstype( int fd )
if( lookup_xt(fdp->ih, "get-fstype", &fdp->get_fstype_xt) )
return NULL;
call_package( fdp->get_fstype_xt, fdp->ih );
- return (char*)POP();
+ return (char*)cell2pointer(POP());
}
int
@@ -183,7 +183,7 @@ read_io( int fd, void *buf, size_t cnt )
if (fd != -1) {
fdp = file_descriptors[fd];
- PUSH( (ucell)buf );
+ PUSH( pointer2cell(buf) );
PUSH( cnt );
call_package( fdp->read_xt, fdp->ih );
ret = POP();
diff --git a/libc/extra.c b/libc/extra.c
index 5823afb..85731ad 100644
--- a/libc/extra.c
+++ b/libc/extra.c
@@ -39,7 +39,7 @@ int forth_printf( const char *fmt, ... )
i = vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
- PUSH((ucell)buf);
+ PUSH(pointer2cell(buf));
PUSH(i);
fword("type");
diff --git a/libopenbios/bindings.c b/libopenbios/bindings.c
index f6bc8de..5323421 100644
--- a/libopenbios/bindings.c
+++ b/libopenbios/bindings.c
@@ -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 );
}
diff --git a/libopenbios/bootinfo_load.c b/libopenbios/bootinfo_load.c
index ceabdeb..c4dbbe5 100644
--- a/libopenbios/bootinfo_load.c
+++ b/libopenbios/bootinfo_load.c
@@ -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();
diff --git a/libopenbios/elf_load.c b/libopenbios/elf_load.c
index 36ae449..9c7850e 100644
--- a/libopenbios/elf_load.c
+++ b/libopenbios/elf_load.c
@@ -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;
diff --git a/libopenbios/initprogram.c b/libopenbios/initprogram.c
index 01be705..1fa33ba 100644
--- a/libopenbios/initprogram.c
+++ b/libopenbios/initprogram.c
@@ -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;
}
diff --git a/libopenbios/ofmem_common.c b/libopenbios/ofmem_common.c
index ceacbb6..22b268d 100644
--- a/libopenbios/ofmem_common.c
+++ b/libopenbios/ofmem_common.c
@@ -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");
}
diff --git a/libopenbios/xcoff_load.c b/libopenbios/xcoff_load.c
index 9868463..0dcb28c 100644
--- a/libopenbios/xcoff_load.c
+++ b/libopenbios/xcoff_load.c
@@ -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 !");
diff --git a/packages/deblocker.c b/packages/deblocker.c
index db66d12..5007185 100644
--- a/packages/deblocker.c
+++ b/packages/deblocker.c
@@ -96,7 +96,7 @@ deblk_tell( deblk_info_t *di )
#define DO_IO( xt, buf, blk, n ) \
- ({ PUSH3((ucell)(buf), blk, n); call_parent(xt); POP(); })
+ ({ PUSH3(pointer2cell(buf), blk, n); call_parent(xt); POP(); })
typedef struct {
/* block operation */
@@ -141,7 +141,7 @@ static int
do_readwrite( deblk_info_t *di, int is_write, xt_t xt )
{
int blk, i, n, len = POP();
- char *dest = (char*)POP();
+ char *dest = (char*)cell2pointer(POP());
int last=0, retlen=0;
work_t w[3];
ducell mark = ((ducell)di->mark_hi << BITS) | di->mark_lo;
diff --git a/packages/disk-label.c b/packages/disk-label.c
index c7b894a..44b9f9e 100644
--- a/packages/disk-label.c
+++ b/packages/disk-label.c
@@ -80,7 +80,7 @@ dlabel_open( dlabel_info_t *di )
call_package(di->parent_seek_xt, my_parent());
POP();
- PUSH((ucell)block0);
+ PUSH(pointer2cell(block0));
PUSH(sizeof(block0));
call_package(di->parent_read_xt, my_parent());
status = POP();
@@ -88,7 +88,7 @@ dlabel_open( dlabel_info_t *di )
goto out;
/* Find partition handler */
- PUSH( (ucell)block0 );
+ PUSH( pointer2cell(block0) );
selfword("find-part-handler");
ph = POP_ph();
if( ph ) {
diff --git a/packages/mac-parts.c b/packages/mac-parts.c
index ee28ce8..4747a55 100644
--- a/packages/mac-parts.c
+++ b/packages/mac-parts.c
@@ -42,7 +42,7 @@ typedef struct {
DECLARE_NODE( macparts, INSTALL_OPEN, sizeof(macparts_info_t), "+/packages/mac-parts" );
#define SEEK( pos ) ({ DPUSH(pos); call_parent(di->seek_xt); POP(); })
-#define READ( buf, size ) ({ PUSH((ucell)buf); PUSH(size); call_parent(di->read_xt); POP(); })
+#define READ( buf, size ) ({ PUSH(pointer2cell(buf)); PUSH(size); call_parent(di->read_xt); POP(); })
/* ( open -- flag ) */
static void
@@ -267,7 +267,7 @@ out:
static void
macparts_probe( macparts_info_t *dummy )
{
- desc_map_t *dmap = (desc_map_t*)POP();
+ desc_map_t *dmap = (desc_map_t*)(uintptr_t)POP();
DPRINTF("macparts_probe %x ?= %x\n", dmap->sbSig, DESC_MAP_SIGNATURE);
if( __be16_to_cpu(dmap->sbSig) != DESC_MAP_SIGNATURE )
diff --git a/packages/nvram.c b/packages/nvram.c
index 4052655..3182edf 100644
--- a/packages/nvram.c
+++ b/packages/nvram.c
@@ -167,7 +167,7 @@ show_partitions( void )
void
update_nvram( void )
{
- PUSH( (ucell)nvram.config->data );
+ PUSH( pointer2cell(nvram.config->data) );
PUSH( nvram.config_size );
fword("nvram-store-configs");
arch_nvram_put( nvram.data );
@@ -202,7 +202,7 @@ nvconf_init( void )
nvram.config_size = nvpart_size(p) - 0x10;
if( !once++ ) {
- PUSH( (ucell)p->data );
+ PUSH( pointer2cell(p->data) );
PUSH( nvram.config_size );
fword("nvram-load-configs");
}
@@ -256,7 +256,7 @@ static void
nvram_read( nvram_ibuf_t *nd )
{
int len = POP();
- char *p = (char*)POP();
+ char *p = (char*)cell2pointer(POP());
int n=0;
while( nd->mark_lo < nvram.size && n < len ) {
@@ -272,7 +272,7 @@ static void
nvram_write( nvram_ibuf_t *nd )
{
int len = POP();
- char *p = (char*)POP();
+ char *p = (char*)cell2pointer(POP());
int n=0;
while( nd->mark_lo < nvram.size && n < len ) {
diff --git a/packages/pc-parts.c b/packages/pc-parts.c
index 2ec6707..d3adb50 100644
--- a/packages/pc-parts.c
+++ b/packages/pc-parts.c
@@ -38,7 +38,7 @@ typedef struct {
DECLARE_NODE( pcparts, INSTALL_OPEN, sizeof(pcparts_info_t), "+/packages/pc-parts" );
#define SEEK( pos ) ({ DPUSH(pos); call_parent(di->seek_xt); POP(); })
-#define READ( buf, size ) ({ PUSH((ucell)buf); PUSH(size); call_parent(di->read_xt); POP(); })
+#define READ( buf, size ) ({ PUSH(pointer2cell(buf)); PUSH(size); call_parent(di->read_xt); POP(); })
/* three helper functions */
@@ -294,7 +294,7 @@ pcparts_open( pcparts_info_t *di )
static void
pcparts_probe( pcparts_info_t *dummy )
{
- unsigned char *buf = (unsigned char *)POP();
+ unsigned char *buf = (unsigned char *)cell2pointer(POP());
DPRINTF("probing for PC partitions\n");
diff --git a/packages/video.c b/packages/video.c
index 32a4469..9eddd0f 100644
--- a/packages/video.c
+++ b/packages/video.c
@@ -244,7 +244,7 @@ video_set_colors( void )
{
int count = POP();
int start = POP();
- unsigned char *p = (unsigned char*)POP();
+ unsigned char *p = (unsigned char*)cell2pointer(POP());
int i;
for( i=0; i<count; i++, p+=3 ) {
@@ -289,7 +289,7 @@ video_write(void)
int len;
len = POP();
- addr = (char *)POP();
+ addr = (char *)cell2pointer(POP());
console_draw_fstr(addr, len);
PUSH(len);
--
1.7.3
More information about the OpenBIOS
mailing list