Dircache: Fix memory leak (and recently panic).
[maemo-rb.git] / apps / codecs / codec_crt0.c
blob33876272c65c7b71981333b7a67d66d07912e1f5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Tomasz Malesinski
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "codecs.h"
25 struct codec_api *ci DATA_ATTR;
27 extern unsigned char plugin_bss_start[];
28 extern unsigned char plugin_end_addr[];
30 extern enum codec_status codec_main(enum codec_entry_call_reason reason);
32 /* stub, the entry point is called via its reference in __header to
33 * avoid warning with certain compilers */
34 int _start(void) {return 0;}
36 enum codec_status codec_start(enum codec_entry_call_reason reason)
38 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
39 if (reason == CODEC_LOAD)
41 #ifdef USE_IRAM
42 extern char iramcopy[], iramstart[], iramend[], iedata[], iend[];
43 size_t iram_size = iramend - iramstart;
44 size_t ibss_size = iend - iedata;
45 if (iram_size > 0 || ibss_size > 0)
47 ci->memcpy(iramstart, iramcopy, iram_size);
48 ci->memset(iedata, 0, ibss_size);
49 /* make the icache (if it exists) up to date with the new code */
50 ci->cpucache_invalidate();
51 /* barrier to prevent reordering iram copy and BSS clearing,
52 * because the BSS segment alias the IRAM copy.
54 asm volatile ("" ::: "memory");
56 #endif /* PLUGIN_USE_IRAM */
57 ci->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start);
58 /* Some parts of bss may be used via a no-cache alias (at least
59 * portalplayer has this). If we don't clear the cache, those aliases
60 * may read garbage */
61 ci->cpucache_invalidate();
63 #endif /* CONFIG_PLATFORM */
65 /* Note: If for any reason codec_main would not be called with CODEC_LOAD
66 * because the above code failed then it must not be ever be called with
67 * any other value and some strategy to avoid doing so must be conceived */
68 return codec_main(reason);
71 #if defined(CPU_ARM) && (CONFIG_PLATFORM & PLATFORM_NATIVE)
72 void __attribute__((naked)) __div0(void)
74 asm volatile("bx %0" : : "r"(ci->__div0));
76 #endif