From 5007bbc009ccc8c8e64fac5f5540c85573d4ae80 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Wed, 8 May 2013 04:50:56 +0800 Subject: Use uintptr_t when converting integer from/to pointer Perviously we use uint32_t for this, but this doesn't compile for 64-bit environment (and likely doesn't for 16-bit either.) Use uintptr_t so that we don't get size mismatch errors. BUG=chrome-os-partner:19257 TEST=Run host emulated tests BRANCH=None Change-Id: I3cd66a745fa171c41a5f142514284ec106586acb Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/50358 Reviewed-by: Vincent Palatin --- Makefile.toolchain | 4 +--- chip/host/system.c | 4 ++-- common/hooks.c | 2 +- common/memory_commands.c | 4 ++-- common/shared_mem.c | 2 +- common/system_common.c | 21 +++++++++++---------- common/util.c | 4 ++-- core/host/build.mk | 2 +- core/host/task.c | 2 +- include/flash.h | 2 +- include/system.h | 2 +- 11 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Makefile.toolchain b/Makefile.toolchain index 0ec8365d8f..82119e5462 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -50,6 +50,4 @@ BUILD_CFLAGS= $(LIBFTDI_CFLAGS) $(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) HOST_CFLAGS=$(CPPFLAGS) -O3 $(CFLAGS_DEBUG) $(CFLAGS_WARN) LDFLAGS=-nostdlib -X BUILD_LDFLAGS=$(LIBFTDI_LDLIBS) -# For EC emulation on host environment, we need to force 32-bit binary. -# TODO: Fix this. See crosbug.com/p/19257 -HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -m32 -lrt -pthread +HOST_TEST_LDFLAGS=-T core/host/host_exe.lds -lrt -pthread diff --git a/chip/host/system.c b/chip/host/system.c index c290f9ef69..dc824f58b7 100644 --- a/chip/host/system.c +++ b/chip/host/system.c @@ -92,9 +92,9 @@ uint32_t system_get_scratchpad(void) return 0; } -int system_usable_ram_end(void) +uintptr_t system_usable_ram_end(void) { - return (int)(__shared_mem_buf + SHARED_MEM_SIZE); + return (uintptr_t)(__shared_mem_buf + SHARED_MEM_SIZE); } void system_pre_init(void) diff --git a/common/hooks.c b/common/hooks.c index d239e3abc2..7dbe08b5fe 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -61,7 +61,7 @@ void hook_notify(enum hook_type type) start = hook_list[type].start; end = hook_list[type].end; - count = ((uint32_t)end - (uint32_t)start) / sizeof(struct hook_data); + count = end - start; /* Call all the hooks in priority order */ while (called < count) { diff --git a/common/memory_commands.c b/common/memory_commands.c index dae18777fd..c8a1ea76df 100644 --- a/common/memory_commands.c +++ b/common/memory_commands.c @@ -17,7 +17,7 @@ static int command_write_word(int argc, char **argv) if (argc != 3) return EC_ERROR_PARAM_COUNT; - address = (uint32_t *)strtoi(argv[1], &e, 0); + address = (uint32_t *)(uintptr_t)strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; @@ -46,7 +46,7 @@ static int command_read_word(int argc, char **argv) if (argc != 2) return EC_ERROR_PARAM_COUNT; - address = (uint32_t *)strtoi(argv[1], &e, 0); + address = (uint32_t *)(uintptr_t)strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; diff --git a/common/shared_mem.c b/common/shared_mem.c index 7ccf18c4b7..219019ef62 100644 --- a/common/shared_mem.c +++ b/common/shared_mem.c @@ -22,7 +22,7 @@ int shared_mem_size(void) * allocated from the start of RAM, so we can use everything up to the * jump data at the end of RAM. */ - return system_usable_ram_end() - (uint32_t)__shared_mem_buf; + return system_usable_ram_end() - (uintptr_t)__shared_mem_buf; } int shared_mem_acquire(int size, char **dest_ptr) diff --git a/common/system_common.c b/common/system_common.c index 239dd12a75..4df9aa70df 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -104,7 +104,7 @@ int system_is_locked(void) #endif } -test_mockable int system_usable_ram_end(void) +test_mockable uintptr_t system_usable_ram_end(void) { /* Leave space at the end of RAM for jump data and tags. * @@ -113,7 +113,7 @@ test_mockable int system_usable_ram_end(void) * tags after a sysjump. When verified boot runs after a reboot, it'll * have as much RAM as we can give it; after verified boot jumps to * another image there'll be less RAM, but we'll care less too. */ - return (uint32_t)jdata - jdata->jump_tag_total; + return (uintptr_t)jdata - jdata->jump_tag_total; } uint32_t system_get_reset_flags(void) @@ -215,7 +215,8 @@ void system_disable_jump(void) enum system_image_copy_t system_get_image_copy(void) { - uint32_t my_addr = (uint32_t)system_get_image_copy - CONFIG_FLASH_BASE; + uintptr_t my_addr = (uintptr_t)system_get_image_copy - + CONFIG_FLASH_BASE; if (my_addr >= CONFIG_SECTION_RO_OFF && my_addr < (CONFIG_SECTION_RO_OFF + CONFIG_SECTION_RO_SIZE)) @@ -293,7 +294,7 @@ const char *system_get_image_copy_string(void) * * @param init_addr Init address of target image */ -static void jump_to_image(uint32_t init_addr) +static void jump_to_image(uintptr_t init_addr) { void (*resetvec)(void) = (void(*)(void))init_addr; @@ -360,8 +361,8 @@ static uint32_t get_size(enum system_image_copy_t copy) int system_run_image_copy(enum system_image_copy_t copy) { - uint32_t base; - uint32_t init_addr; + uintptr_t base; + uintptr_t init_addr; /* If system is already running the requested image, done */ if (system_get_image_copy() == copy) @@ -408,7 +409,7 @@ int system_run_image_copy(enum system_image_copy_t copy) const char *system_get_version(enum system_image_copy_t copy) { - uint32_t addr; + uintptr_t addr; const struct version_struct *v; /* Handle version of current image */ @@ -421,7 +422,7 @@ const char *system_get_version(enum system_image_copy_t copy) /* The version string is always located after the reset vectors, so * it's the same as in the current image. */ - addr += ((uint32_t)&version_data - get_base(system_get_image_copy())); + addr += ((uintptr_t)&version_data - get_base(system_get_image_copy())); /* Make sure the version struct cookies match before returning the * version string. */ @@ -456,13 +457,13 @@ const char *system_get_build_info(void) void system_common_pre_init(void) { - uint32_t addr; + uintptr_t addr; /* * Put the jump data before the panic data, or at the end of RAM if * panic data is not present. */ - addr = (uint32_t)panic_get_data(); + addr = (uintptr_t)panic_get_data(); if (!addr) addr = CONFIG_RAM_BASE + CONFIG_RAM_SIZE; diff --git a/common/util.c b/common/util.c index d8670759c1..5ccebeb063 100644 --- a/common/util.c +++ b/common/util.c @@ -196,8 +196,8 @@ void *memset(void *dest, int c, int len) void *memmove(void *dest, const void *src, int len) { - if ((uint32_t)dest <= (uint32_t)src || - (uint32_t)dest >= (uint32_t)src + len) { + if ((uintptr_t)dest <= (uintptr_t)src || + (uintptr_t)dest >= (uintptr_t)src + len) { /* Start of destination doesn't overlap source, so just use * memcpy(). */ return memcpy(dest, src, len); diff --git a/core/host/build.mk b/core/host/build.mk index 879b9266fa..121ef98272 100644 --- a/core/host/build.mk +++ b/core/host/build.mk @@ -6,6 +6,6 @@ # emulator specific files build # -CFLAGS_CPU=-fno-builtin -m32 +CFLAGS_CPU=-fno-builtin core-y=main.o task.o timer.o panic.o disabled.o diff --git a/core/host/task.c b/core/host/task.c index caad622778..2049320e04 100644 --- a/core/host/task.c +++ b/core/host/task.c @@ -198,7 +198,7 @@ int task_start(void) tasks[i].wake_time.val = ~0ull; pthread_cond_init(&tasks[i].resume, NULL); pthread_create(&tasks[i].thread, NULL, _task_start_impl, - (void *)(size_t)i); + (void *)(uintptr_t)i); pthread_cond_wait(&scheduler_cond, &run_lock); } diff --git a/include/flash.h b/include/flash.h index cef27065dd..9a9454bf52 100644 --- a/include/flash.h +++ b/include/flash.h @@ -27,7 +27,7 @@ */ static inline char *flash_physical_dataptr(int offset) { - return (char *)(CONFIG_FLASH_BASE + offset); + return (char *)((uintptr_t)CONFIG_FLASH_BASE + offset); } /** diff --git a/include/system.h b/include/system.h index 174efa9388..fb31e54268 100644 --- a/include/system.h +++ b/include/system.h @@ -133,7 +133,7 @@ const uint8_t *system_get_jump_tag(uint16_t tag, int *version, int *size); /** * Return the address just past the last usable byte in RAM. */ -int system_usable_ram_end(void); +uintptr_t system_usable_ram_end(void); /** * Return non-zero if the given range is overlapped with the active image. -- cgit v1.2.1