From c7f9ca4067f26ba3d0471d50ed3f06b047171b50 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Wed, 13 Jun 2007 15:35:07 +0000 Subject: Accept FS#7264 'Build with -Os switch for coldfire targets'. Introduces MEM_FUNCTION_WRAPPERS(api) macro which adds wrappers functions to a plugin to make plugins link correctly when gcc calls mem* functions directly. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13625 a1c6a512-1295-4272-9138-f99709370657 --- apps/playback.c | 16 ++++++------ apps/plugin.h | 6 ++--- apps/plugins/battery_bench.c | 2 ++ apps/plugins/blackjack.c | 5 +++- apps/plugins/chessclock.c | 3 ++- apps/plugins/chip8.c | 2 +- apps/plugins/jpeg.c | 2 ++ apps/plugins/lib/mem_function_wrappers.h | 44 ++++++++++++++++++++++++++++++++ apps/plugins/lib/playback_control.c | 10 +++++--- apps/plugins/mazezam.c | 3 +++ apps/plugins/metronome.c | 5 +++- apps/plugins/mp3_encoder.c | 3 +++ apps/plugins/properties.c | 4 ++- apps/plugins/rockpaint.c | 3 +++ apps/plugins/video.c | 2 +- apps/plugins/xobox.c | 5 +++- apps/talk.c | 4 +-- 17 files changed, 95 insertions(+), 24 deletions(-) create mode 100644 apps/plugins/lib/mem_function_wrappers.h (limited to 'apps') diff --git a/apps/playback.c b/apps/playback.c index ca88b5f5e3..329e8b856b 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -332,7 +332,7 @@ static struct mutex mutex_codecthread NOCACHEBSS_ATTR; static volatile bool voice_thread_start = false; /* Triggers voice playback (A/V) */ static volatile bool voice_is_playing NOCACHEBSS_ATTR = false; /* Is voice currently playing? (V) */ static volatile bool voice_codec_loaded NOCACHEBSS_ATTR = false; /* Is voice codec loaded (V/A-) */ -static char *voicebuf = NULL; +static unsigned char *voicebuf = NULL; static size_t voice_remaining = 0; #ifdef IRAM_STEAL @@ -340,12 +340,12 @@ static size_t voice_remaining = 0; static bool voice_iram_stolen = false; #endif -static void (*voice_getmore)(unsigned char** start, int* size) = NULL; +static void (*voice_getmore)(unsigned char** start, size_t* size) = NULL; struct voice_info { - void (*callback)(unsigned char **start, int *size); - int size; - char *buf; + void (*callback)(unsigned char **start, size_t* size); + size_t size; + unsigned char *buf; }; static void voice_thread(void); static void voice_stop(void); @@ -355,12 +355,12 @@ static void voice_stop(void); /* --- External interfaces --- */ void mp3_play_data(const unsigned char* start, int size, - void (*get_more)(unsigned char** start, int* size)) + void (*get_more)(unsigned char** start, size_t* size)) { #ifdef PLAYBACK_VOICE static struct voice_info voice_clip; voice_clip.callback = get_more; - voice_clip.buf = (char *)start; + voice_clip.buf = (unsigned char*)start; voice_clip.size = size; LOGFQUEUE("mp3 > voice Q_VOICE_STOP"); queue_post(&voice_queue, Q_VOICE_STOP, 0); @@ -1238,7 +1238,7 @@ voice_play_clip: if (voice_remaining == 0 || voicebuf == NULL) { if (voice_getmore) - voice_getmore((unsigned char **)&voicebuf, (int *)&voice_remaining); + voice_getmore((unsigned char **)&voicebuf, &voice_remaining); /* If this clip is done */ if (voice_remaining == 0) diff --git a/apps/plugin.h b/apps/plugin.h index bc6adffab2..11bb80de66 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -114,12 +114,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 57 +#define PLUGIN_API_VERSION 58 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 56 +#define PLUGIN_MIN_API_VERSION 58 /* plugin return codes */ enum plugin_status { @@ -417,7 +417,7 @@ struct plugin_api { int (*sound_min)(int setting); int (*sound_max)(int setting); #ifndef SIMULATOR - void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size)); + void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, size_t* size)); void (*mp3_play_pause)(bool play); void (*mp3_play_stop)(void); bool (*mp3_is_playing)(void); diff --git a/apps/plugins/battery_bench.c b/apps/plugins/battery_bench.c index 13ce172f67..fef3f36db2 100644 --- a/apps/plugins/battery_bench.c +++ b/apps/plugins/battery_bench.c @@ -20,6 +20,7 @@ #ifndef SIMULATOR /* not for the simulator */ #include "plugin.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER #define BATTERY_LOG "/battery_bench.txt" @@ -98,6 +99,7 @@ PLUGIN_HEADER /****************************** Plugin Entry Point ****************************/ static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); int main(void); bool exit_tsr(bool); void thread(void); diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index f987eeb3b5..07af984a80 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c @@ -20,6 +20,7 @@ #include "plugin.h" #include "card_deck.h" #include "card_back.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER @@ -213,6 +214,8 @@ extern const fb_data card_back[]; /* global rockbox api */ static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + /* dealer and player card positions */ unsigned int dealer_x, dealer_y, player_x, player_y; @@ -1399,7 +1402,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { (void)parameter; rb = api; - + #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif diff --git a/apps/plugins/chessclock.c b/apps/plugins/chessclock.c index f1482df990..3dfb0fef6c 100644 --- a/apps/plugins/chessclock.c +++ b/apps/plugins/chessclock.c @@ -17,6 +17,7 @@ * ****************************************************************************/ #include "plugin.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER @@ -153,6 +154,7 @@ PLUGIN_HEADER it's nice not to have to pass the api pointer in all function calls in the plugin */ static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); #define MAX_PLAYERS 10 static struct { @@ -192,7 +194,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) (void)parameter; rb=api; - rb->memset(&settings, 0, sizeof(settings)); /* now go ahead and have fun! */ diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c index c38a5fd0bb..f76379e5f4 100644 --- a/apps/plugins/chip8.c +++ b/apps/plugins/chip8.c @@ -1062,7 +1062,7 @@ static unsigned char beep[]={255, 111,181,184,144, 17,148, 21,101,166,227,100, 86, 85, 85, 85}; /* callback to request more mp3 data */ -void callback(unsigned char** start, int* size) +void callback(unsigned char** start, size_t* size) { *start = beep; /* give it the same frame again */ *size = sizeof(beep); diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c index ff6df6d4e3..cd364f4d51 100644 --- a/apps/plugins/jpeg.c +++ b/apps/plugins/jpeg.c @@ -27,6 +27,7 @@ #include "plugin.h" #include "playback_control.h" #include "oldmenuapi.h" +#include "mem_function_wrappers.h" #ifdef HAVE_LCD_BITMAP #include "gray.h" @@ -186,6 +187,7 @@ PLUGIN_HEADER /******************************* Globals ***********************************/ static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); /* for portability of below JPEG code */ #define MEMSET(p,v,c) rb->memset(p,v,c) diff --git a/apps/plugins/lib/mem_function_wrappers.h b/apps/plugins/lib/mem_function_wrappers.h new file mode 100644 index 0000000000..ec3872c4c1 --- /dev/null +++ b/apps/plugins/lib/mem_function_wrappers.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Nils Wallménius + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef __MEM_FUNCTION_WRAPPERS_H__ +#define __MEM_FUNCTION_WRAPPERS_H__ + +/* Use this macro in plugins where gcc tries to optimize by calling + * these functions directly */ + +#define MEM_FUNCTION_WRAPPERS(api) \ + void *memcpy(void *dest, const void *src, size_t n) \ + { \ + return (api)->memcpy(dest, src, n); \ + } \ + void *memset(void *dest, int c, size_t n) \ + { \ + return (api)->memset(dest, c, n); \ + } \ + void *memmove(void *dest, const void *src, size_t n) \ + { \ + return (api)->memmove(dest, src, n); \ + } \ + int memcmp(const void *s1, const void *s2, size_t n) \ + { \ + return (api)->memcmp(s1, s2, n); \ + } + +#endif /* __MEM_FUNCTION_WRAPPERS_H__ */ + diff --git a/apps/plugins/lib/playback_control.c b/apps/plugins/lib/playback_control.c index 34401e1d4f..177f26a417 100644 --- a/apps/plugins/lib/playback_control.c +++ b/apps/plugins/lib/playback_control.c @@ -65,10 +65,12 @@ static bool volume(void) static bool shuffle(void) { - struct opt_items names[] = { - { "No", -1 }, - { "Yes", -1 } - }; + struct opt_items names[2]; + names[0].string = "No"; + names[0].voice_id = -1; + names[1].string = "Yes"; + names[1].voice_id = -1; + return api->set_option("Shuffle", &api->global_settings->playlist_shuffle, BOOL, names, 2,NULL); } diff --git a/apps/plugins/mazezam.c b/apps/plugins/mazezam.c index 607348e91c..ee93d10024 100644 --- a/apps/plugins/mazezam.c +++ b/apps/plugins/mazezam.c @@ -20,12 +20,15 @@ ****************************************************************************/ #include "plugin.h" #include "configfile.h" +#include "mem_function_wrappers.h" /* Include standard plugin macro */ PLUGIN_HEADER static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + #if CONFIG_KEYPAD == RECORDER_PAD #define MAZEZAM_UP BUTTON_UP #define MAZEZAM_DOWN BUTTON_DOWN diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index 19a37a580a..daf3294b75 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -18,6 +18,7 @@ ****************************************************************************/ #include "plugin.h" #include "pluginlib_actions.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER @@ -70,6 +71,8 @@ static const struct button_mapping iriver_syncaction[] = static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + static int bpm = 120; static int period = 0; static int minitick = 0; @@ -159,7 +162,7 @@ static unsigned char sound[] = { 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85}; -void callback(unsigned char** start, int* size){ +void callback(unsigned char** start, size_t* size){ (void)start; /* unused parameter, avoid warning */ *size = NULL; /* end of data */ sound_active = false; diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index 70372933e0..d1ef2e0a7c 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c @@ -12,12 +12,15 @@ * Library General Public License for more details. */ #include "plugin.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER PLUGIN_IRAM_DECLARE static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + #define SAMP_PER_FRAME 1152 #define SAMPL2 576 #define SBLIMIT 32 diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c index ee7ff86cb7..2e2e057b64 100644 --- a/apps/plugins/properties.c +++ b/apps/plugins/properties.c @@ -17,11 +17,14 @@ * ****************************************************************************/ #include "plugin.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + bool its_a_dir = false; char str_filename[MAX_PATH]; @@ -247,7 +250,6 @@ char * get_props(int selected_item, void* data, char *buffer) enum plugin_status plugin_start(struct plugin_api* api, void* file) { rb = api; - struct gui_synclist properties_lists; int button; bool prev_show_statusbar; diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c index da8f8052cb..29296ac1b6 100644 --- a/apps/plugins/rockpaint.c +++ b/apps/plugins/rockpaint.c @@ -30,6 +30,7 @@ #include "errno.h" #include "lib/bmp.h" #include "lib/rgb_hsv.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER @@ -224,6 +225,8 @@ int errno; static struct plugin_api* rb; +MEM_FUNCTION_WRAPPERS(rb); + static int drawcolor=0; /* Current color (in palette) */ static int bgdrawcolor=9; /* Current background color (in palette) */ bool isbg = false; /* gruik ugly hack alert */ diff --git a/apps/plugins/video.c b/apps/plugins/video.c index f049974023..b56a9d0612 100644 --- a/apps/plugins/video.c +++ b/apps/plugins/video.c @@ -423,7 +423,7 @@ void timer4_isr(void) /* ISR function to get more mp3 data */ -void GetMoreMp3(unsigned char** start, int* size) +void GetMoreMp3(unsigned char** start, size_t* size) { int available; int advance; diff --git a/apps/plugins/xobox.c b/apps/plugins/xobox.c index 33ef4d04e9..0d1bdc4f72 100644 --- a/apps/plugins/xobox.c +++ b/apps/plugins/xobox.c @@ -19,6 +19,7 @@ ****************************************************************************/ #include "plugin.h" +#include "mem_function_wrappers.h" PLUGIN_HEADER @@ -204,6 +205,9 @@ static int difficulty = 75; /* Percentage of screen that needs to be filled * in order to win the game */ static struct plugin_api *rb; + +MEM_FUNCTION_WRAPPERS(rb); + static bool quit = false; static unsigned int board[BOARD_H][BOARD_W]; @@ -295,7 +299,6 @@ static inline void emptyStack (void) /*********************** END OF STACK STUFF *********************/ - /* calculate the new x coordinate of the ball according to angle and speed */ static inline int get_newx (int x, int len, int deg) { diff --git a/apps/talk.c b/apps/talk.c index 1f1eefd51d..1610fa95ec 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -132,7 +132,7 @@ static int talk_menu_disable; /* if non-zero, temporarily disable voice UI (not /***************** Private prototypes *****************/ static void load_voicefile(void); -static void mp3_callback(unsigned char** start, int* size); +static void mp3_callback(unsigned char** start, size_t* size); static int shutup(void); static int queue_clip(unsigned char* buf, long size, bool enqueue); static int open_voicefile(void); @@ -262,7 +262,7 @@ load_err: /* called in ISR context if mp3 data got consumed */ -static void mp3_callback(unsigned char** start, int* size) +static void mp3_callback(unsigned char** start, size_t* size) { queue[queue_read].len -= sent; /* we completed this */ queue[queue_read].buf += sent; -- cgit v1.2.3