diff options
Diffstat (limited to 'apps/codecs/codec_crt0.c')
-rw-r--r-- | apps/codecs/codec_crt0.c | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/apps/codecs/codec_crt0.c b/apps/codecs/codec_crt0.c index cf14e460ec..33876272c6 100644 --- a/apps/codecs/codec_crt0.c +++ b/apps/codecs/codec_crt0.c | |||
@@ -27,39 +27,45 @@ struct codec_api *ci DATA_ATTR; | |||
27 | extern unsigned char plugin_bss_start[]; | 27 | extern unsigned char plugin_bss_start[]; |
28 | extern unsigned char plugin_end_addr[]; | 28 | extern unsigned char plugin_end_addr[]; |
29 | 29 | ||
30 | extern enum codec_status codec_main(void); | 30 | extern enum codec_status codec_main(enum codec_entry_call_reason reason); |
31 | 31 | ||
32 | /* stub, the entry point is called via its reference in __header to | 32 | /* stub, the entry point is called via its reference in __header to |
33 | * avoid warning with certain compilers */ | 33 | * avoid warning with certain compilers */ |
34 | int _start(void) {return 0;} | 34 | int _start(void) {return 0;} |
35 | 35 | ||
36 | enum codec_status codec_start(void) | 36 | enum codec_status codec_start(enum codec_entry_call_reason reason) |
37 | { | 37 | { |
38 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | 38 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) |
39 | #ifdef USE_IRAM | 39 | if (reason == CODEC_LOAD) |
40 | extern char iramcopy[], iramstart[], iramend[], iedata[], iend[]; | ||
41 | size_t iram_size = iramend - iramstart; | ||
42 | size_t ibss_size = iend - iedata; | ||
43 | if (iram_size > 0 || ibss_size > 0) | ||
44 | { | 40 | { |
45 | ci->memcpy(iramstart, iramcopy, iram_size); | 41 | #ifdef USE_IRAM |
46 | ci->memset(iedata, 0, ibss_size); | 42 | extern char iramcopy[], iramstart[], iramend[], iedata[], iend[]; |
47 | /* make the icache (if it exists) up to date with the new code */ | 43 | size_t iram_size = iramend - iramstart; |
44 | size_t ibss_size = iend - iedata; | ||
45 | if (iram_size > 0 || ibss_size > 0) | ||
46 | { | ||
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. | ||
53 | */ | ||
54 | asm volatile ("" ::: "memory"); | ||
55 | } | ||
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 */ | ||
48 | ci->cpucache_invalidate(); | 61 | ci->cpucache_invalidate(); |
49 | /* barrier to prevent reordering iram copy and BSS clearing, | ||
50 | * because the BSS segment alias the IRAM copy. | ||
51 | */ | ||
52 | asm volatile ("" ::: "memory"); | ||
53 | } | 62 | } |
54 | #endif /* PLUGIN_USE_IRAM */ | 63 | #endif /* CONFIG_PLATFORM */ |
55 | ci->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start); | ||
56 | /* Some parts of bss may be used via a no-cache alias (at least | ||
57 | * portalplayer has this). If we don't clear the cache, those aliases | ||
58 | * may read garbage */ | ||
59 | ci->cpucache_invalidate(); | ||
60 | #endif | ||
61 | 64 | ||
62 | return codec_main(); | 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); | ||
63 | } | 69 | } |
64 | 70 | ||
65 | #if defined(CPU_ARM) && (CONFIG_PLATFORM & PLATFORM_NATIVE) | 71 | #if defined(CPU_ARM) && (CONFIG_PLATFORM & PLATFORM_NATIVE) |