diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/a52.c rockbox.2/apps/codecs/a52.c
--- rockbox.1/apps/codecs/a52.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/a52.c	2006-11-21 22:02:53.000000000 +0100
@@ -28,8 +28,6 @@
 
 #define A52_SAMPLESPERFRAME (6*256)
 
-struct codec_api *ci;
-
 static a52_state_t *state;
 unsigned long samplesdone;
 unsigned long frequency;
@@ -117,16 +115,8 @@
     }
 }
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
     size_t n;
     unsigned char *filebuf;
@@ -134,19 +124,12 @@
     int retval;
 
     /* Generic codec initialisation */
-    ci = api;
-
-    #ifdef USE_IRAM 
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-    #endif
-
     ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED);
     ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28);
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128));
 
 next_track:
-    if (codec_init(api)) {
+    if (codec_init()) {
         retval = CODEC_ERROR;
         goto exit;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/aac.c rockbox.2/apps/codecs/aac.c
--- rockbox.1/apps/codecs/aac.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/aac.c	2006-11-21 22:02:53.000000000 +0100
@@ -25,19 +25,8 @@
 
 CODEC_HEADER
 
-#ifndef SIMULATOR
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
-struct codec_api* rb;
-struct codec_api* ci;
-
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     /* Note that when dealing with QuickTime/MPEG4 files, terminology is
      * a bit confusing. Files with sound are split up in chunks, where
@@ -62,14 +51,6 @@
     unsigned char c = 0;
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-
-#ifndef SIMULATOR
-    ci->memcpy(iramstart, iramcopy, iramend-iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*16));
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
 
@@ -79,7 +60,7 @@
 next_track:
     err = CODEC_OK;
 
-    if (codec_init(api)) {
+    if (codec_init()) {
         LOGF("FAAD: Codec init error\n");
         err = CODEC_ERROR;
         goto exit;
@@ -90,7 +71,7 @@
   
     sound_samples_done = ci->id3->offset;
 
-    ci->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
+    ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
 
     stream_create(&input_stream,ci);
 
@@ -138,7 +119,7 @@
 
     /* The main decoding loop */
     while (i < demux_res.num_sample_byte_sizes) {
-        rb->yield();
+        ci->yield();
 
         if (ci->stop_codec || ci->new_track) {
             break;
@@ -194,12 +175,12 @@
         ci->advance_buffer(n);
 
         /* Output the audio */
-        rb->yield();
-        while (!rb->pcmbuf_insert_split(decoder->time_out[0],
+        ci->yield();
+        while (!ci->pcmbuf_insert_split(decoder->time_out[0],
                                         decoder->time_out[1],
                                         frame_info.samples * 2))
         {
-            rb->sleep(1);
+            ci->sleep(1);
         }
 
         /* Update the elapsed-time indicator */
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/adx.c rockbox.2/apps/codecs/adx.c
--- rockbox.1/apps/codecs/adx.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/adx.c	2006-11-21 22:15:46.000000000 +0100
@@ -21,8 +21,6 @@
 
 CODEC_HEADER
 
-struct codec_api *rb;
-
 /* Maximum number of bytes to process in one iteration */
 #define WAV_CHUNK_SIZE (1024*2)
 
@@ -38,9 +36,8 @@
 static int16_t samples[WAV_CHUNK_SIZE] IBSS_ATTR;
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
-    struct codec_api *ci;
     int channels;
     int sampleswritten, i;
     uint8_t *buf;
@@ -56,16 +53,13 @@
     off_t chanstart, bufoff;
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-    
     /* we only render 16 bits */
     ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)16);
     /*ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));*/
   
 next_track:
     DEBUGF("ADX: next_track\n");
-    if (codec_init(api)) {
+    if (codec_init()) {
         return CODEC_ERROR;
     }
     DEBUGF("ADX: after init\n");
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/aiff.c rockbox.2/apps/codecs/aiff.c
--- rockbox.1/apps/codecs/aiff.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/aiff.c	2006-11-21 22:02:53.000000000 +0100
@@ -25,8 +25,6 @@
 /* Macro that sign extends an unsigned byte */
 #define SE(x) ((int32_t)((int8_t)(x)))
 
-struct codec_api *rb;
-
 /* This codec supports AIFF files with the following formats:
  * - PCM, 8, 16 and 24 bits, mono or stereo
  */
@@ -43,19 +41,10 @@
 /* for 44.1kHz stereo 16bits, this represents 0.023s ~= 1/50s */
 #define AIF_CHUNK_SIZE (1024*2)
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 static int32_t samples[AIF_CHUNK_SIZE] IBSS_ATTR;
 
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
-    struct codec_api *ci;
     uint32_t numbytes, bytesdone;
     uint16_t num_channels = 0;
     uint32_t num_sample_frames = 0;
@@ -73,19 +62,11 @@
     off_t firstblockposn;     /* position of the first block in file */
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-
-#ifdef USE_IRAM 
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
   
 next_track:
-    if (codec_init(api)) {
+    if (codec_init()) {
         i = CODEC_ERROR;
         goto exit;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/alac.c rockbox.2/apps/codecs/alac.c
--- rockbox.1/apps/codecs/alac.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/alac.c	2006-11-21 22:02:53.000000000 +0100
@@ -23,21 +23,10 @@
 
 CODEC_HEADER
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
 
-struct codec_api* rb;
-struct codec_api* ci;
-
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
   size_t n;
   demux_res_t demux_res;
@@ -53,14 +42,6 @@
   int retval;
 
   /* Generic codec initialisation */
-  rb = api;
-  ci = api;
-
-#ifdef USE_IRAM
-  rb->memcpy(iramstart, iramcopy, iramend-iramstart);
-  rb->memset(iedata, 0, iend - iedata);
-#endif
-
   ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
   ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
 
@@ -69,16 +50,16 @@
 
   next_track:
 
-  if (codec_init(api)) {
+  if (codec_init()) {
     LOGF("ALAC: Error initialising codec\n");
     retval = CODEC_ERROR;
     goto exit;
   }
 
-  while (!rb->taginfo_ready)
-    rb->yield();
+  while (!ci->taginfo_ready)
+    ci->yield();
   
-  ci->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
+  ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
 
   stream_create(&input_stream,ci);
 
@@ -98,7 +79,7 @@
   samplesdone=0;
   /* The main decoding loop */
   while (i < demux_res.num_sample_byte_sizes) {
-    rb->yield();
+    ci->yield();
     if (ci->stop_codec || ci->new_track) {
       break;
     }
@@ -131,18 +112,18 @@
     }
 
     /* Decode one block - returned samples will be host-endian */
-    rb->yield();
-    samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, rb->yield);
+    ci->yield();
+    samplesdecoded=alac_decode_frame(&alac, buffer, outputbuffer, ci->yield);
 
     /* Advance codec buffer n bytes */
     ci->advance_buffer(n);
 
     /* Output the audio */
-    rb->yield();
+    ci->yield();
     while(!ci->pcmbuf_insert_split(outputbuffer[0],
                                    outputbuffer[1],
                                    samplesdecoded*sizeof(int32_t)))
-      rb->yield();
+      ci->yield();
 
     /* Update the elapsed-time indicator */
     samplesdone+=sample_duration;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/codec_crt0.c rockbox.2/apps/codecs/codec_crt0.c
--- rockbox.1/apps/codecs/codec_crt0.c	1970-01-01 01:00:00.000000000 +0100
+++ rockbox.2/apps/codecs/codec_crt0.c	2006-11-21 22:02:53.000000000 +0100
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *             __________               __   ___.
+ *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
+ *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
+ *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
+ *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
+ *                     \/            \/     \/    \/            \/
+ * $Id: $
+ *
+ * Copyright (C) 2006 Tomasz Malesinski
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#include "codeclib.h"
+
+struct codec_api *ci;
+
+extern unsigned char iramcopy[];
+extern unsigned char iramstart[];
+extern unsigned char iramend[];
+extern unsigned char iedata[];
+extern unsigned char iend[];
+extern unsigned char plugin_bss_start[];
+extern unsigned char plugin_end_addr[];
+
+extern enum codec_status codec_main(void);
+
+enum codec_status codec_start(struct codec_api *api)
+{
+#ifndef SIMULATOR
+#ifdef USE_IRAM
+    api->memcpy(iramstart, iramcopy, iramend - iramstart);
+    api->memset(iedata, 0, iend - iedata);
+#endif
+    api->memset(plugin_bss_start, 0, plugin_end_addr - plugin_bss_start);
+#endif
+    ci = api;
+    return codec_main();
+}
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/codec.h rockbox.2/apps/codecs/codec.h
--- rockbox.1/apps/codecs/codec.h	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/codec.h	2006-11-21 22:02:53.000000000 +0100
@@ -24,6 +24,8 @@
 
 #include <sys/types.h>
 
+extern struct codec_api *ci;
+
 /* Get these functions 'out of the way' of the standard functions. Not doing
  * so confuses the cygwin linker, and maybe others. These functions need to
  * be implemented elsewhere */
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/flac.c rockbox.2/apps/codecs/flac.c
--- rockbox.1/apps/codecs/flac.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/flac.c	2006-11-21 22:02:53.000000000 +0100
@@ -22,17 +22,6 @@
 
 CODEC_HEADER
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
-struct codec_api* rb;
-struct codec_api* ci;
-
 /* The output buffers containing the decoded samples (channels 0 and 1) */
 int32_t decoded0[MAX_BLOCKSIZE] IBSS_ATTR_FLAC_DECODED0;
 int32_t decoded1[MAX_BLOCKSIZE] IBSS_ATTR;
@@ -423,7 +412,7 @@
 }
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     int8_t *buf;
     FLACContext fc;
@@ -436,14 +425,6 @@
     int retval;
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend-iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
 
@@ -455,7 +436,7 @@
     /* Need to save offset for later use (cleared indirectly by flac_init) */
     samplesdone=ci->id3->offset;
 
-    if (codec_init(api)) {
+    if (codec_init()) {
         LOGF("FLAC: Error initialising codec\n");
         retval = CODEC_ERROR;
         goto exit;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/lib/codeclib.c rockbox.2/apps/codecs/lib/codeclib.c
--- rockbox.1/apps/codecs/lib/codeclib.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/lib/codeclib.c	2006-11-21 22:02:53.000000000 +0100
@@ -24,29 +24,26 @@
 #include "codeclib.h"
 #include "id3.h"
 
-struct codec_api *local_rb;
-
 long mem_ptr;
 long bufsize;
 unsigned char* mp3buf;     // The actual MP3 buffer from Rockbox
 unsigned char* mallocbuf;  // 512K from the start of MP3 buffer
 unsigned char* filebuf;    // The rest of the MP3 buffer
 
-int codec_init(struct codec_api* rb)
+int codec_init(void)
 {
-    local_rb = rb;
     mem_ptr = 0;
-    mallocbuf = (unsigned char *)rb->get_codec_memory((size_t *)&bufsize);
+    mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize);
   
     return 0;
 }
 
 void codec_set_replaygain(struct mp3entry* id3)
 {
-    local_rb->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain);
-    local_rb->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain);
-    local_rb->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak);
-    local_rb->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak);
+    ci->configure(DSP_SET_TRACK_GAIN, (long *) id3->track_gain);
+    ci->configure(DSP_SET_ALBUM_GAIN, (long *) id3->album_gain);
+    ci->configure(DSP_SET_TRACK_PEAK, (long *) id3->track_peak);
+    ci->configure(DSP_SET_ALBUM_PEAK, (long *) id3->album_peak);
 }
 
 /* Various "helper functions" common to all the xxx2wav decoder plugins  */
@@ -71,7 +68,7 @@
     x = codec_malloc(nmemb*size);
     if (x == NULL)
         return NULL;
-    local_rb->memset(x,0,nmemb*size);
+    ci->memset(x,0,nmemb*size);
     return(x);
 }
 
@@ -89,71 +86,71 @@
 
 size_t strlen(const char *s)
 {
-    return(local_rb->strlen(s));
+    return(ci->strlen(s));
 }
 
 char *strcpy(char *dest, const char *src)
 {
-    return(local_rb->strcpy(dest,src));
+    return(ci->strcpy(dest,src));
 }
 
 char *strcat(char *dest, const char *src)
 {
-    return(local_rb->strcat(dest,src));
+    return(ci->strcat(dest,src));
 }
 
 int strcmp(const char *s1, const char *s2)
 {
-    return(local_rb->strcmp(s1,s2));
+    return(ci->strcmp(s1,s2));
 }
 
 int strncasecmp(const char *s1, const char *s2, size_t n)
 {
-    return(local_rb->strncasecmp(s1,s2,n));
+    return(ci->strncasecmp(s1,s2,n));
 }
 
 void *memcpy(void *dest, const void *src, size_t n)
 {
-    return(local_rb->memcpy(dest,src,n));
+    return(ci->memcpy(dest,src,n));
 }
 
 void *memset(void *s, int c, size_t n)
 {
-    return(local_rb->memset(s,c,n));
+    return(ci->memset(s,c,n));
 }
 
 int memcmp(const void *s1, const void *s2, size_t n)
 {
-    return(local_rb->memcmp(s1,s2,n));
+    return(ci->memcmp(s1,s2,n));
 }
 
 void* memchr(const void *s, int c, size_t n)
 {
-    return(local_rb->memchr(s,c,n));
+    return(ci->memchr(s,c,n));
 }
 
 void *memmove(void *dest, const void *src, size_t n)
 {
-    return(local_rb->memmove(dest,src,n));
+    return(ci->memmove(dest,src,n));
 }
 
 void qsort(void *base, size_t nmemb, size_t size,
            int(*compar)(const void *, const void *))
 {
-    local_rb->qsort(base,nmemb,size,compar);
+    ci->qsort(base,nmemb,size,compar);
 }
 
 #ifdef RB_PROFILE
 void __cyg_profile_func_enter(void *this_fn, void *call_site) {
 #ifdef CPU_COLDFIRE
     (void)call_site;
-    local_rb->profile_func_enter(this_fn, __builtin_return_address(1));
+    ci->profile_func_enter(this_fn, __builtin_return_address(1));
 #else
-    local_rb->profile_func_enter(this_fn, call_site);
+    ci->profile_func_enter(this_fn, call_site);
 #endif
 }
 
 void __cyg_profile_func_exit(void *this_fn, void *call_site) {
-    local_rb->profile_func_exit(this_fn,call_site);
+    ci->profile_func_exit(this_fn,call_site);
 }
 #endif
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/lib/codeclib.h rockbox.2/apps/codecs/lib/codeclib.h
--- rockbox.1/apps/codecs/lib/codeclib.h	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/lib/codeclib.h	2006-11-21 22:02:53.000000000 +0100
@@ -24,6 +24,7 @@
 
 #define MALLOC_BUFSIZE (512*1024)
 
+extern struct codec_api *ci;
 extern long mem_ptr;
 extern long bufsize;
 extern unsigned char* mp3buf;     // The actual MP3 buffer from Rockbox
@@ -55,7 +56,7 @@
 
 /* Various codec helper functions */
 
-int codec_init(struct codec_api* rb);
+int codec_init(void);
 void codec_set_replaygain(struct mp3entry* id3);
 
 #ifdef RB_PROFILE
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/Makefile rockbox.2/apps/codecs/Makefile
--- rockbox.1/apps/codecs/Makefile	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/Makefile	2006-11-21 22:02:53.000000000 +0100
@@ -65,7 +65,7 @@
 $(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o
 $(OBJDIR)/wavpack_enc.elf: $(OBJDIR)/wavpack_enc.o $(BUILDDIR)/libwavpack.a
 
-$(OBJDIR)/%.elf:
+$(OBJDIR)/%.elf: $(OBJDIR)/codec_crt0.o
 	$(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $^ -L$(BUILDDIR) -lcodec -lgcc -T$(LINKCODEC) -Wl,-Map,$(OBJDIR)/$*.map
 
 $(OBJDIR)/%.codec : $(OBJDIR)/%.elf
@@ -76,8 +76,8 @@
 ###################################################
 # This is the X11 simulator version
 
-$(OBJDIR)/%.codec : $(OBJDIR)/%.o  $(BUILDDIR)/libcodec.a $(OUTPUT)
-	$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
+$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
+	$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
 ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
 # 'x' must be kept or you'll have "Win32 error 5"
 #     $ fgrep 5 /usr/include/w32api/winerror.h | head -1
@@ -91,8 +91,8 @@
 ###################################################
 # This is the SDL simulator version
 
-$(OBJDIR)/%.codec : $(OBJDIR)/%.o  $(BUILDDIR)/libcodec.a $(OUTPUT)
-	$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
+$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
+	$(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $< $(OBJDIR)/codec_crt0.o -L$(BUILDDIR) $(CODECLIBS) -lcodec -o $@
 ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
 # 'x' must be kept or you'll have "Win32 error 5"
 #     $ fgrep 5 /usr/include/w32api/winerror.h | head -1
@@ -107,9 +107,9 @@
 DLLTOOLFLAGS = --export-all
 DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin
 
-$(OBJDIR)/%.codec : $(OBJDIR)/%.o  $(BUILDDIR)/libcodec.a $(OUTPUT)
-	$(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $<
-	$(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< \
+$(OBJDIR)/%.codec : $(OBJDIR)/%.o $(OBJDIR)/codec_crt0.o $(BUILDDIR)/libcodec.a $(OUTPUT)
+	$(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o
+	$(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $< $(OBJDIR)/codec_crt0.o\
 		$(BUILDDIR)/libcodec.a $(patsubst -l%,$(BUILDDIR)/lib%.a,$(CODECLIBS)) \
 		-o $@
 ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/mp3_enc.c rockbox.2/apps/codecs/mp3_enc.c
--- rockbox.1/apps/codecs/mp3_enc.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/mp3_enc.c	2006-11-21 22:02:53.000000000 +0100
@@ -53,14 +53,6 @@
 #define putlong(c, s)  if(s+sz <= 32) { cc = (cc << s) | c;      sz+= s; } \
                        else           { putbits(cc, sz); cc = c; sz = s; }
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 typedef struct {
     int   type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */
     int   mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono  */
@@ -181,7 +173,6 @@
 static unsigned samp_per_frame                   IBSS_ATTR;
 
 static config_t          cfg                     IBSS_ATTR;
-static struct codec_api *ci;
 static char             *res_buffer;
 
 static const uint8_t ht_count_const[2][2][16] =
@@ -2460,18 +2451,11 @@
     return true;
 } /* enc_init */
 
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     bool cpu_boosted;
 
     /* Generic codec initialisation */
-    ci = api;
-
-#ifdef USE_IRAM
-    memcpy(iramstart, iramcopy, iramend - iramstart);
-    memset(iedata, 0, iend - iedata);
-#endif
-
     if (!enc_init())
     {
         ci->enc_codec_loaded = -1;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/mpa.c rockbox.2/apps/codecs/mpa.c
--- rockbox.1/apps/codecs/mpa.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/mpa.c	2006-11-21 22:02:53.000000000 +0100
@@ -42,16 +42,6 @@
 int mpeg_latency[3] = { 0, 481, 529 };
 int mpeg_framesize[3] = {384, 1152, 1152};
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
-struct codec_api *ci;
-
 void init_mad(void)
 {
     ci->memset(&stream, 0, sizeof(struct mad_stream));
@@ -69,7 +59,7 @@
 }
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
     int status;
     size_t size;
@@ -83,14 +73,7 @@
     int framelength;
     int padding = MAD_BUFFER_GUARD; /* to help mad decode the last frame */
 
-    ci = api;
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
-    if (codec_init(api))
+    if (codec_init())
         return CODEC_ERROR;
 
     /* Create a decoder instance */
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/mpc.c rockbox.2/apps/codecs/mpc.c
--- rockbox.1/apps/codecs/mpc.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/mpc.c	2006-11-21 22:14:09.000000000 +0100
@@ -67,18 +67,9 @@
 IBSS_ATTR_MPC_SAMPLE_BUF;
 mpc_uint32_t    seek_table[10000];
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
-    struct codec_api *ci = api;
     mpc_int64_t samplesdone;
     unsigned long frequency;
     unsigned status;
@@ -86,11 +77,6 @@
     mpc_streaminfo info;
     int retval = CODEC_OK;
     
-    #ifdef USE_IRAM 
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-    #endif
-    
     ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16));
     ci->configure(CODEC_SET_FILEBUF_PRESEEK, (long *)(0));
@@ -109,7 +95,7 @@
     mpc_decoder_set_seek_table(&decoder, seek_table, sizeof(seek_table));
 
 next_track:    
-    if (codec_init(api)) {
+    if (codec_init()) {
         retval = CODEC_ERROR;
         goto exit;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/shorten.c rockbox.2/apps/codecs/shorten.c
--- rockbox.1/apps/codecs/shorten.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/shorten.c	2006-11-21 22:02:53.000000000 +0100
@@ -20,23 +20,12 @@
 #include "codeclib.h"
 #include <codecs/libffmpegFLAC/shndec.h>
 
-#ifndef IBSS_ATTR_SHORTEN_DECODED0
-#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR
-#endif
-
 CODEC_HEADER
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
+#ifndef IBSS_ATTR_SHORTEN_DECODED0
+#define IBSS_ATTR_SHORTEN_DECODED0 IBSS_ATTR
 #endif
 
-struct codec_api* rb;
-struct codec_api* ci;
-
 int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR_SHORTEN_DECODED0;
 int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR;
 
@@ -46,7 +35,7 @@
 int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR;
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     ShortenContext sc;
     uint32_t samplesdone;
@@ -56,14 +45,6 @@
     size_t bytesleft;
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend-iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
 
@@ -72,7 +53,7 @@
     
 next_track:
     /* Codec initialization */
-    if (codec_init(api)) {
+    if (codec_init()) {
         LOGF("Shorten: codec_init error\n");
         return CODEC_ERROR;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/sid.c rockbox.2/apps/codecs/sid.c
--- rockbox.1/apps/codecs/sid.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/sid.c	2006-11-21 22:15:35.000000000 +0100
@@ -65,21 +65,10 @@
 
 #define CHUNK_SIZE (1024*2)
 
-
-struct codec_api *rb;
-
 /* This codec supports SID Files:
  * 
  */
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 static int32_t samples[CHUNK_SIZE] IBSS_ATTR;   /* The sample buffer */
 
 /* Static buffer for the plain SID-File */
@@ -1213,9 +1202,8 @@
 }
 
 
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
-    struct codec_api *ci;
     size_t n, bytesfree;
     unsigned char *p;
     unsigned int filesize;
@@ -1228,20 +1216,11 @@
     int nSamplesToRender = 0;
 
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-        
-
-#ifdef USE_IRAM 
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
 
 next_track:
-    if (codec_init(api)) {
+    if (codec_init()) {
         return CODEC_ERROR;
     }
 
@@ -1251,7 +1230,7 @@
     /* Load SID file */    
     p = sidfile;
     bytesfree=sizeof(sidfile);
-    while ((n = rb->read_filebuf(p, bytesfree)) > 0) {
+    while ((n = ci->read_filebuf(p, bytesfree)) > 0) {
         p += n;
         bytesfree -= n;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/vorbis.c rockbox.2/apps/codecs/vorbis.c
--- rockbox.1/apps/codecs/vorbis.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/vorbis.c	2006-11-21 22:02:53.000000000 +0100
@@ -23,14 +23,12 @@
 
 CODEC_HEADER
 
-static struct codec_api *rb;
-
 /* Some standard functions and variables needed by Tremor */
 
 size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource)
 {
     (void)datasource;
-    return rb->read_filebuf(ptr, nmemb*size);
+    return ci->read_filebuf(ptr, nmemb*size);
 }
 
 int initial_seek_handler(void *datasource, ogg_int64_t offset, int whence)
@@ -46,12 +44,12 @@
     (void)datasource;
 
     if (whence == SEEK_CUR) {
-        offset += rb->curpos;
+        offset += ci->curpos;
     } else if (whence == SEEK_END) {
-        offset += rb->filesize;
+        offset += ci->filesize;
     }
 
-    if (rb->seek_buffer(offset)) {
+    if (ci->seek_buffer(offset)) {
         return 0;
     }
 
@@ -67,7 +65,7 @@
 long tell_handler(void *datasource)
 {
     (void)datasource;
-    return rb->curpos;
+    return ci->curpos;
 }
 
 /* This sets the DSP parameters based on the current logical bitstream
@@ -81,17 +79,17 @@
     vi = ov_info(vf, -1);
 
     if (vi == NULL) {
-        //rb->splash(HZ*2, true, "Vorbis Error");
+        //ci->splash(HZ*2, true, "Vorbis Error");
         return false;
     }
 
-    rb->configure(DSP_SET_FREQUENCY, (int *)rb->id3->frequency);
-    codec_set_replaygain(rb->id3);
+    ci->configure(DSP_SET_FREQUENCY, (int *)ci->id3->frequency);
+    codec_set_replaygain(ci->id3);
 
     if (vi->channels == 2) {
-          rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED);
+          ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED);
     } else if (vi->channels == 1) {
-          rb->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
+          ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO);
     }
 
     return true;
@@ -106,7 +104,7 @@
 #endif
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
     ov_callbacks callbacks;
     OggVorbis_File vf;
@@ -122,16 +120,9 @@
     ogg_uint32_t vf_serialnos;
     ogg_int64_t vf_pcmlengths[2];
 
-    rb = api;
-
-    #ifdef USE_IRAM
-    rb->memcpy(iramstart, iramcopy, iramend - iramstart);
-    rb->memset(iedata, 0, iend - iedata);
-    #endif
-
-    rb->configure(DSP_SET_SAMPLE_DEPTH, (long *)24);
-    rb->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1));
-    rb->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1));
+    ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)24);
+    ci->configure(DSP_SET_CLIP_MAX, (long *)((1 << 24) - 1));
+    ci->configure(DSP_SET_CLIP_MIN, (long *)-((1 << 24) - 1));
     /* Note: These are sane defaults for these values.  Perhaps
      * they should be set differently based on quality setting
      */
@@ -139,17 +130,17 @@
     /* The chunk size below is magic.  If set any lower, resume
      * doesn't work properly (ov_raw_seek() does the wrong thing).
      */
-    rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256));
+    ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256));
 
 /* We need to flush reserver memory every track load. */
 next_track:
-    if (codec_init(rb)) {
+    if (codec_init()) {
         error = CODEC_ERROR;
         goto exit;
     }
 
-    while (!*rb->taginfo_ready && !rb->stop_codec)
-        rb->sleep(1);
+    while (!*ci->taginfo_ready && !ci->stop_codec)
+        ci->sleep(1);
 
     /* Create a decoder instance */
     callbacks.read_func = read_handler;
@@ -158,14 +149,14 @@
     callbacks.close_func = close_handler;
 
     /* Open a non-seekable stream */
-    error = ov_open_callbacks(rb, &vf, NULL, 0, callbacks);
+    error = ov_open_callbacks(ci, &vf, NULL, 0, callbacks);
     
     /* If the non-seekable open was successful, we need to supply the missing
      * data to make it seekable.  This is a hack, but it's reasonable since we
      * don't want to run the whole file through the buffer before we start
      * playing.  Using Tremor's seekable open routine would cause us to do
      * this, so we pretend not to be seekable at first.  Then we fill in the
-     * missing fields of vf with 1) information in rb->id3, and 2) info
+     * missing fields of vf with 1) information in ci->id3, and 2) info
      * obtained by Tremor in the above ov_open call.
      *
      * Note that this assumes there is only ONE logical Vorbis bitstream in our
@@ -179,40 +170,40 @@
          vf.pcmlengths = vf_pcmlengths;
 
          vf.offsets[0] = 0;
-         vf.offsets[1] = rb->id3->filesize;
+         vf.offsets[1] = ci->id3->filesize;
          vf.dataoffsets[0] = vf.offset;
          vf.pcmlengths[0] = 0;
-         vf.pcmlengths[1] = rb->id3->samples;
+         vf.pcmlengths[1] = ci->id3->samples;
          vf.serialnos[0] = vf.current_serialno;
          vf.callbacks.seek_func = seek_handler;
          vf.seekable = 1;
-         vf.end = rb->id3->filesize;
+         vf.end = ci->id3->filesize;
          vf.ready_state = OPENED;
          vf.links = 1;
     } else {
-         //rb->logf("ov_open: %d", error);
+         //ci->logf("ov_open: %d", error);
          error = CODEC_ERROR;
          goto done;
     }
 
-    if (rb->id3->offset) {
-        rb->advance_buffer(rb->id3->offset);
-        ov_raw_seek(&vf, rb->id3->offset);
-        rb->set_elapsed(ov_time_tell(&vf));
-        rb->set_offset(ov_raw_tell(&vf));
+    if (ci->id3->offset) {
+        ci->advance_buffer(ci->id3->offset);
+        ov_raw_seek(&vf, ci->id3->offset);
+        ci->set_elapsed(ov_time_tell(&vf));
+        ci->set_offset(ov_raw_tell(&vf));
     }
 
     eof = 0;
     while (!eof) {
-        rb->yield();
-        if (rb->stop_codec || rb->new_track)
+        ci->yield();
+        if (ci->stop_codec || ci->new_track)
             break;
 
-        if (rb->seek_time) {
-            if (ov_time_seek(&vf, rb->seek_time - 1)) {
-                //rb->logf("ov_time_seek failed");
+        if (ci->seek_time) {
+            if (ov_time_seek(&vf, ci->seek_time - 1)) {
+                //ci->logf("ov_time_seek failed");
             }
-            rb->seek_complete();
+            ci->seek_complete();
         }
 
         /* Read host-endian signed 24-bit PCM samples */
@@ -233,18 +224,18 @@
         } else if (n < 0) {
             DEBUGF("Error decoding frame\n");
         } else {
-            while (!rb->pcmbuf_insert_split(pcm[0], pcm[1], 
+            while (!ci->pcmbuf_insert_split(pcm[0], pcm[1], 
                    n*sizeof(ogg_int32_t))) {
-                rb->sleep(1);
+                ci->sleep(1);
             }
-            rb->set_offset(ov_raw_tell(&vf));
-            rb->set_elapsed(ov_time_tell(&vf));
+            ci->set_offset(ov_raw_tell(&vf));
+            ci->set_elapsed(ov_time_tell(&vf));
         }
     }
     error = CODEC_OK;
     
 done:
-    if (rb->request_next_track()) {
+    if (ci->request_next_track()) {
         /* Clean things up for the next track */
         vf.dataoffsets = NULL;
         vf.offsets = NULL;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/wav.c rockbox.2/apps/codecs/wav.c
--- rockbox.1/apps/codecs/wav.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/wav.c	2006-11-21 22:02:53.000000000 +0100
@@ -25,8 +25,6 @@
 /* Macro that sign extends an unsigned byte */
 #define SE(x) ((int32_t)((int8_t)(x)))
 
-struct codec_api *rb;
-
 /* This codec support WAVE files with the following formats:
  * - PCM, up to 32 bits, supporting 32 bits playback when useful.
  * - ALAW and MULAW (16 bits compressed on 8 bits).
@@ -213,9 +211,8 @@
                  size_t *pcmoutsize);
 
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api *api)
+enum codec_status codec_main(void)
 {
-    struct codec_api *ci;
     uint32_t numbytes, bytesdone;
     uint32_t totalsamples = 0;
     uint16_t channels = 0;
@@ -235,20 +232,12 @@
     
  
     /* Generic codec initialisation */
-    rb = api;
-    ci = api;
-
-#ifdef USE_IRAM 
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)28);
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*256));
   
 next_track:
-    if (codec_init(api)) {
+    if (codec_init()) {
         i = CODEC_ERROR;
         goto exit;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/wav_enc.c rockbox.2/apps/codecs/wav_enc.c
--- rockbox.1/apps/codecs/wav_enc.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/wav_enc.c	2006-11-21 22:02:53.000000000 +0100
@@ -24,14 +24,6 @@
 
 CODEC_ENC_HEADER
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 struct riff_header
 {
     uint8_t  riff_id[4];      /* 00h - "RIFF"                            */
@@ -65,7 +57,6 @@
 #define PCM_SAMP_PER_CHUNK       2048
 #define PCM_CHUNK_SIZE          (PCM_SAMP_PER_CHUNK*4)
 
-static struct codec_api *ci;
 static int    num_channels;
 uint32_t      sample_rate;
 uint32_t      enc_size;
@@ -321,17 +312,10 @@
 } /* init_encoder */
 
 /* main codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     bool cpu_boosted;
 
-    ci = api; // copy to global api pointer
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     if (!init_encoder())
     {
         ci->enc_codec_loaded = -1;
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/wavpack.c rockbox.2/apps/codecs/wavpack.c
--- rockbox.1/apps/codecs/wavpack.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/wavpack.c	2006-11-21 22:02:53.000000000 +0100
@@ -22,8 +22,6 @@
 
 CODEC_HEADER
 
-static struct codec_api *ci;
-
 #define BUFFER_SIZE 4096
 
 static int32_t temp_buffer [BUFFER_SIZE] IBSS_ATTR;
@@ -35,16 +33,8 @@
     return retval;
 }
 
-#ifdef USE_IRAM 
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 /* this is the codec entry point */
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     WavpackContext *wpc;
     char error [80];
@@ -52,13 +42,6 @@
     int retval;
 
     /* Generic codec initialisation */
-    ci = api;
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend-iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     ci->configure(CODEC_SET_FILEBUF_WATERMARK, (int *)(1024*512));
     ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
   
@@ -66,7 +49,7 @@
 
     next_track:
 
-    if (codec_init(api)) {
+    if (codec_init()) {
         retval = CODEC_ERROR;
         goto exit;
     }
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs/wavpack_enc.c rockbox.2/apps/codecs/wavpack_enc.c
--- rockbox.1/apps/codecs/wavpack_enc.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs/wavpack_enc.c	2006-11-21 22:02:53.000000000 +0100
@@ -24,14 +24,6 @@
 
 CODEC_ENC_HEADER
 
-#ifdef USE_IRAM
-extern char iramcopy[];
-extern char iramstart[];
-extern char iramend[];
-extern char iedata[];
-extern char iend[];
-#endif
-
 /** Types **/
 typedef struct
 {
@@ -73,7 +65,6 @@
 #define PCM_CHUNK_SIZE      (4*PCM_SAMP_PER_CHUNK)
 
 /** Data **/
-static struct codec_api *ci;
 static int8_t input_buffer[PCM_CHUNK_SIZE*2]     IBSS_ATTR;
 static WavpackConfig config                      IBSS_ATTR;
 static WavpackContext *wpc;
@@ -381,17 +372,10 @@
     return true;
 } /* init_encoder */
 
-enum codec_status codec_start(struct codec_api* api)
+enum codec_status codec_main(void)
 {
     bool cpu_boosted;
 
-    ci = api; /* copy to global api pointer */
-
-#ifdef USE_IRAM
-    ci->memcpy(iramstart, iramcopy, iramend - iramstart);
-    ci->memset(iedata, 0, iend - iedata);
-#endif
-
     /* initialize params and config */
     if (!init_encoder())
     {
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs.c rockbox.2/apps/codecs.c
--- rockbox.1/apps/codecs.c	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs.c	2006-11-21 22:02:53.000000000 +0100
@@ -243,9 +243,6 @@
     int copy_n;
     
     if ((char *)&codecbuf[0] != codecptr) {
-        /* zero out codec buffer to ensure a properly zeroed bss area */
-        memset(codecbuf, 0, CODEC_SIZE);
-
         size = MIN(size, CODEC_SIZE);
         copy_n = MIN(size, bufwrap);
         memcpy(codecbuf, codecptr, copy_n);         
@@ -308,9 +305,6 @@
 
     codec_get_full_path(path, plugin);
     
-    /* zero out codec buffer to ensure a properly zeroed bss area */
-    memset(codecbuf, 0, CODEC_SIZE);
-
     fd = open(path, O_RDONLY);
     if (fd < 0) {
         snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", path);
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/codecs.h rockbox.2/apps/codecs.h
--- rockbox.1/apps/codecs.h	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/codecs.h	2006-11-21 22:02:53.000000000 +0100
@@ -61,9 +61,9 @@
 
 #if defined(DEBUG) || defined(SIMULATOR)
 #undef DEBUGF
-#define DEBUGF  rb->debugf
+#define DEBUGF  ci->debugf
 #undef LDEBUGF
-#define LDEBUGF rb->debugf
+#define LDEBUGF ci->debugf
 #else
 #define DEBUGF(...)
 #define LDEBUGF(...)
@@ -71,7 +71,7 @@
 
 #ifdef ROCKBOX_HAS_LOGF
 #undef LOGF
-#define LOGF rb->logf
+#define LOGF ci->logf
 #else
 #define LOGF(...)
 #endif
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugin.c rockbox.2/apps/plugin.c
--- rockbox.1/apps/plugin.c	2006-11-19 20:29:17.000000000 +0100
+++ rockbox.2/apps/plugin.c	2006-11-21 22:05:41.000000000 +0100
@@ -696,6 +696,7 @@
     audio_iram_steal();
     memcpy(iramstart, iramcopy, iram_size);
     memset(iedata, 0, iedata_size);
+    memset(iramcopy, 0, iram_size);
 }
 #endif /* IRAM_STEAL */
 
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/doom/rockdoom.c rockbox.2/apps/plugins/doom/rockdoom.c
--- rockbox.1/apps/plugins/doom/rockdoom.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/doom/rockdoom.c	2006-11-21 22:18:41.000000000 +0100
@@ -769,6 +769,8 @@
 /* this is the plugin entry point */
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
+   PLUGIN_IRAM_INIT(api)
+
    rb = api;
    (void)parameter;
 
@@ -778,8 +780,6 @@
    rb->cpu_boost(true);
 #endif
 
-   PLUGIN_IRAM_INIT(rb)
-
    rb->lcd_setfont(0);
 
 #ifdef FANCY_MENU
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/midiplay.c rockbox.2/apps/plugins/midiplay.c
--- rockbox.1/apps/plugins/midiplay.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/midiplay.c	2006-11-21 22:07:29.000000000 +0100
@@ -105,8 +105,10 @@
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
     int retval = 0;
-    rb = api;
 
+    PLUGIN_IRAM_INIT(api)
+
+    rb = api;
     if(parameter == NULL)
     {
         rb->splash(HZ*2, true, " Play .MID file ");
@@ -114,8 +116,6 @@
     }
     rb->lcd_setfont(0);
 
-    PLUGIN_IRAM_INIT(rb)
-
 #if defined(HAVE_ADJUSTABLE_CPU_FREQ)
     rb->cpu_boost(true);
 #endif
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/mp3_encoder.c rockbox.2/apps/plugins/mp3_encoder.c
--- rockbox.1/apps/plugins/mp3_encoder.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/mp3_encoder.c	2006-11-21 22:07:56.000000000 +0100
@@ -2364,14 +2364,14 @@
     int   brate[] = { 64,  80,  96,  112,  128,  160,  192,  224,  256,  320 };
 
     (void)parameter;
-    rb = api;
+
+    PLUGIN_IRAM_INIT(api)
 
 #ifdef CPU_COLDFIRE
     asm volatile ("move.l #0, %macsr"); /* integer mode */
 #endif
 
-    PLUGIN_IRAM_INIT(rb)
-
+    rb = api;
     rb->lcd_setfont(FONT_SYSFIXED);
 
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/mpegplayer/mpegplayer.c rockbox.2/apps/plugins/mpegplayer/mpegplayer.c
--- rockbox.1/apps/plugins/mpegplayer/mpegplayer.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/mpegplayer/mpegplayer.c	2006-11-21 22:11:04.000000000 +0100
@@ -297,10 +297,11 @@
     uint8_t* buffer;
     size_t buffer_size;
 
-    rb = api;
-
     /* This also stops audio playback - so we do it before using IRAM */
-    audiobuf = rb->plugin_get_audio_buffer(&audiosize);
+    audiobuf = api->plugin_get_audio_buffer(&audiosize);
+
+    PLUGIN_IRAM_INIT(api)
+    rb = api;
 
     /* Initialise our malloc buffer */
     mpeg2_alloc_init(audiobuf,audiosize);
@@ -312,8 +313,6 @@
     if (buffer == NULL)
         return PLUGIN_ERROR;
 
-    PLUGIN_IRAM_INIT(rb)
-
     rb->lcd_set_backdrop(NULL);
 
 #ifdef HAVE_LCD_COLOR
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/pacbox/pacbox.c rockbox.2/apps/plugins/pacbox/pacbox.c
--- rockbox.1/apps/plugins/pacbox/pacbox.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/pacbox/pacbox.c	2006-11-21 22:19:33.000000000 +0100
@@ -364,10 +364,9 @@
 {
     (void)parameter;
 
+    PLUGIN_IRAM_INIT(api)
     rb = api;
 
-    PLUGIN_IRAM_INIT(rb)
-
 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
     rb->cpu_boost(true);
 #endif
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/plugin.lds rockbox.2/apps/plugins/plugin.lds
--- rockbox.1/apps/plugins/plugin.lds	2006-11-21 22:02:49.000000000 +0100
+++ rockbox.2/apps/plugins/plugin.lds	2006-11-21 22:03:56.000000000 +0100
@@ -119,12 +119,11 @@
         . = ALIGN(0x4);
         iend = .;
     } > PLUGIN_IRAM
-
-    .bss ADDR(.data) + SIZEOF(.data) + SIZEOF(.iram):
-#else
-    .bss :
 #endif
+
+    .bss (NOLOAD) :
     {
+	plugin_bss_start = .;
         *(.bss*)
         *(COMMON)
         . = ALIGN(0x4);
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/rockboy/rockboy.c rockbox.2/apps/plugins/rockboy/rockboy.c
--- rockbox.1/apps/plugins/rockboy/rockboy.c	2006-11-18 23:34:13.000000000 +0100
+++ rockbox.2/apps/plugins/rockboy/rockboy.c	2006-11-21 22:10:32.000000000 +0100
@@ -157,6 +157,8 @@
 /* this is the plugin entry point */
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
+    PLUGIN_IRAM_INIT(api)
+
     /* if you are using a global api pointer, don't forget to copy it!
        otherwise you will get lovely "I04: IllInstr" errors... :-) */
     rb = api;
@@ -181,8 +183,6 @@
 #endif
     setoptions();
 
-    PLUGIN_IRAM_INIT(rb)
-
     shut=0;
     cleanshut=0;
 
diff -urN -x build -x '*~' -x '*.orig' -x '*.rej' rockbox.1/apps/plugins/zxbox/zxbox.c rockbox.2/apps/plugins/zxbox/zxbox.c
--- rockbox.1/apps/plugins/zxbox/zxbox.c	2006-11-18 23:34:14.000000000 +0100
+++ rockbox.2/apps/plugins/zxbox/zxbox.c	2006-11-21 22:20:02.000000000 +0100
@@ -61,14 +61,16 @@
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
 
-    rb = api;
 #if CODEC == SWCODEC && !defined SIMULATOR
-    rb->pcm_play_stop();
+    api->pcm_play_stop();
 #endif
+
+    PLUGIN_IRAM_INIT(api)
+
+    rb = api;
     rb->lcd_set_backdrop(NULL);
     rb->splash(HZ, true, "Welcome to ZXBox");
 
-    PLUGIN_IRAM_INIT(rb)
 
     sp_init();
 
Binary files rockbox.1/tools/bmp2rb and rockbox.2/tools/bmp2rb differ
Binary files rockbox.1/tools/codepages and rockbox.2/tools/codepages differ
Binary files rockbox.1/tools/convbdf and rockbox.2/tools/convbdf differ
Binary files rockbox.1/tools/gigabeat.o and rockbox.2/tools/gigabeat.o differ
Binary files rockbox.1/tools/ipod_fw and rockbox.2/tools/ipod_fw differ
Binary files rockbox.1/tools/iriver.o and rockbox.2/tools/iriver.o differ
Binary files rockbox.1/tools/mi4.o and rockbox.2/tools/mi4.o differ
Binary files rockbox.1/tools/rdf2binary and rockbox.2/tools/rdf2binary differ
Binary files rockbox.1/tools/scramble and rockbox.2/tools/scramble differ
Binary files rockbox.1/tools/scramble.o and rockbox.2/tools/scramble.o differ
