FS#10756 - Free unused init code

Introduce a new .init section for initialisation code, so that it can be copied to an area which is later overwritten before calling. The stack/bss can then overwrite that code, effectively freeing the code size that the initialisation routines need. Gives a few kB ram usage back.
Only implemented for PP and as3525 so far. More targets could be added, as well as more functions.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25013 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2010-03-03 23:20:32 +00:00
parent e479853f15
commit f8edc32589
33 changed files with 98 additions and 37 deletions

View file

@ -56,7 +56,7 @@ void tree_get_filetypes(const struct filetype**, int*);
/* init the filetypes structs. /* init the filetypes structs.
uses audio buffer for storage, so call early in init... */ uses audio buffer for storage, so call early in init... */
void filetype_init(void); void filetype_init(void) INIT_ATTR;
void read_viewer_theme_file(void); void read_viewer_theme_file(void);
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
void read_color_theme_file(void); void read_color_theme_file(void);

View file

@ -35,7 +35,7 @@
void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile); void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile);
void sb_create_from_settings(enum screen_type screen); void sb_create_from_settings(enum screen_type screen);
void sb_skin_init(void); void sb_skin_init(void) INIT_ATTR;
struct viewport *sb_skin_get_info_vp(enum screen_type screen); struct viewport *sb_skin_get_info_vp(enum screen_type screen);
void sb_skin_update(enum screen_type screen, bool force); void sb_skin_update(enum screen_type screen, bool force);

View file

@ -100,7 +100,7 @@ struct gui_syncstatusbar
struct gui_statusbar statusbars[NB_SCREENS]; struct gui_statusbar statusbars[NB_SCREENS];
}; };
extern void gui_syncstatusbar_init(struct gui_syncstatusbar * bars); extern void gui_syncstatusbar_init(struct gui_syncstatusbar * bars) INIT_ATTR;
extern void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars, extern void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars,
bool force_redraw); bool force_redraw);
void gui_statusbar_changed(enum screen_type screen, void gui_statusbar_changed(enum screen_type screen,

View file

@ -42,8 +42,7 @@ int viewport_get_nb_lines(const struct viewport *vp);
* Initialize the viewportmanager, which in turns initializes the UI vp and * Initialize the viewportmanager, which in turns initializes the UI vp and
* statusbar stuff * statusbar stuff
*/ */
void viewportmanager_init(void); void viewportmanager_init(void) INIT_ATTR;
void viewport_set_defaults(struct viewport *vp, void viewport_set_defaults(struct viewport *vp,
const enum screen_type screen); const enum screen_type screen);

View file

@ -28,7 +28,7 @@ long gui_wps_show(void);
/* wrapper for the wps to load the skin (.wps/.rwps) files */ /* wrapper for the wps to load the skin (.wps/.rwps) files */
void wps_data_load(enum screen_type, const char *, bool); void wps_data_load(enum screen_type, const char *, bool);
void gui_sync_wps_init(void); void gui_sync_wps_init(void) INIT_ATTR;
/* fades the volume, e.g. on pause or stop */ /* fades the volume, e.g. on pause or stop */
void fade(bool fade_in, bool updatewps); void fade(bool fade_in, bool updatewps);

View file

@ -127,7 +127,7 @@ static void init(void);
#ifdef SIMULATOR #ifdef SIMULATOR
void app_main(void) void app_main(void)
#else #else
int main(void) __attribute__((noreturn)); int main(void) INIT_ATTR __attribute__((noreturn));
int main(void) int main(void)
#endif #endif
{ {
@ -164,6 +164,7 @@ int main(void)
root_menu(); root_menu();
} }
static int init_dircache(bool preinit) INIT_ATTR;
static int init_dircache(bool preinit) static int init_dircache(bool preinit)
{ {
#ifdef HAVE_DIRCACHE #ifdef HAVE_DIRCACHE
@ -239,6 +240,7 @@ static int init_dircache(bool preinit)
} }
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
static void init_tagcache(void) INIT_ATTR;
static void init_tagcache(void) static void init_tagcache(void)
{ {
bool clear = false; bool clear = false;
@ -372,6 +374,7 @@ static void init(void)
#else #else
static void init(void) INIT_ATTR;
static void init(void) static void init(void)
{ {
int rc; int rc;

View file

@ -119,7 +119,7 @@ struct playlist_track_info
}; };
/* Exported functions only for current playlist. */ /* Exported functions only for current playlist. */
void playlist_init(void); void playlist_init(void) INIT_ATTR;
void playlist_shutdown(void); void playlist_shutdown(void);
int playlist_create(const char *dir, const char *file); int playlist_create(const char *dir, const char *file);
int playlist_resume(void); int playlist_resume(void);

View file

@ -27,7 +27,7 @@
#if CONFIG_TUNER #if CONFIG_TUNER
void radio_load_presets(char *filename); void radio_load_presets(char *filename);
void radio_init(void); void radio_init(void) INIT_ATTR;
int radio_screen(void); int radio_screen(void);
void radio_start(void); void radio_start(void);
void radio_pause(void); void radio_pause(void);

View file

@ -239,7 +239,7 @@ bool tagcache_is_ramcache(void);
bool tagcache_fill_tags(struct mp3entry *id3, const char *filename); bool tagcache_fill_tags(struct mp3entry *id3, const char *filename);
void tagcache_unload_ramcache(void); void tagcache_unload_ramcache(void);
#endif #endif
void tagcache_init(void); void tagcache_init(void) INIT_ATTR;
bool tagcache_is_initialized(void); bool tagcache_is_initialized(void);
bool tagcache_is_usable(void); bool tagcache_is_usable(void);
void tagcache_start_scan(void); void tagcache_start_scan(void);

View file

@ -38,7 +38,7 @@ struct tagentry {
bool tagtree_export(void); bool tagtree_export(void);
bool tagtree_import(void); bool tagtree_import(void);
void tagtree_init(void); void tagtree_init(void) INIT_ATTR;
int tagtree_enter(struct tree_context* c); int tagtree_enter(struct tree_context* c);
void tagtree_exit(struct tree_context* c); void tagtree_exit(struct tree_context* c);
int tagtree_load(struct tree_context* c); int tagtree_load(struct tree_context* c);

View file

@ -36,7 +36,7 @@
#define GET_STRETCH(pitch, speed) \ #define GET_STRETCH(pitch, speed) \
((speed * PITCH_SPEED_100 + pitch / 2L) / pitch) ((speed * PITCH_SPEED_100 + pitch / 2L) / pitch)
void tdspeed_init(void); void tdspeed_init(void) INIT_ATTR;
bool tdspeed_config(int samplerate, bool stereo, int32_t factor); bool tdspeed_config(int samplerate, bool stereo, int32_t factor);
long tdspeed_est_output_size(void); long tdspeed_est_output_size(void);
long tdspeed_est_input_size(long size); long tdspeed_est_input_size(long size);

View file

@ -71,8 +71,8 @@ struct tree_context {
}; };
void tree_drawlists(void); void tree_drawlists(void);
void tree_mem_init(void); void tree_mem_init(void) INIT_ATTR;
void tree_gui_init(void); void tree_gui_init(void) INIT_ATTR;
void get_current_file(char* buffer, int buffer_len); void get_current_file(char* buffer, int buffer_len);
void set_dirfilter(int l_dirfilter); void set_dirfilter(int l_dirfilter);
void set_current_file(char *path); void set_current_file(char *path);

View file

@ -25,7 +25,7 @@
#include "adc-target.h" #include "adc-target.h"
unsigned short adc_read(int channel); unsigned short adc_read(int channel);
void adc_init(void); void adc_init(void) INIT_ATTR;
#ifndef NEED_ADC_CLOSE #ifndef NEED_ADC_CLOSE
#define adc_close() #define adc_close()

View file

@ -53,7 +53,7 @@
#define AUDIO_GAIN_MIC 1 #define AUDIO_GAIN_MIC 1
void audio_init(void); void audio_init(void) INIT_ATTR;
void audio_play(long offset); void audio_play(long offset);
void audio_stop(void); void audio_stop(void);
void audio_pause(void); void audio_pause(void);

View file

@ -36,7 +36,7 @@ void backlight_off(void);
void backlight_set_timeout(int value); void backlight_set_timeout(int value);
#ifdef HAVE_BACKLIGHT #ifdef HAVE_BACKLIGHT
void backlight_init(void); void backlight_init(void) INIT_ATTR;
void backlight_close(void); void backlight_close(void);
int backlight_get_current_timeout(void); int backlight_get_current_timeout(void);

View file

@ -21,6 +21,7 @@
#ifndef BUFFER_H #ifndef BUFFER_H
#define BUFFER_H #define BUFFER_H
#include "config.h"
/* defined in linker script */ /* defined in linker script */
#ifdef SIMULATOR #ifdef SIMULATOR
extern unsigned char *audiobufend; extern unsigned char *audiobufend;
@ -30,7 +31,7 @@ extern unsigned char audiobufend[];
extern unsigned char *audiobuf; extern unsigned char *audiobuf;
void buffer_init(void); void buffer_init(void) INIT_ATTR;
void *buffer_alloc(size_t size); void *buffer_alloc(size_t size);
#endif #endif

View file

@ -30,7 +30,7 @@
extern struct event_queue button_queue; extern struct event_queue button_queue;
void button_init (void); void button_init (void) INIT_ATTR;
void button_close(void); void button_close(void);
int button_queue_count(void); int button_queue_count(void);
long button_get (bool block); long button_get (bool block);

View file

@ -747,6 +747,11 @@ Lyre prototype 1 */
#define IBSS_ATTR #define IBSS_ATTR
#define STATICIRAM static #define STATICIRAM static
#endif #endif
#if (defined(CPU_PP) || (CONFIG_CPU == AS3525)) && !defined(SIMULATOR)
#define INIT_ATTR __attribute__ ((section(".init")))
#else
#define INIT_ATTR
#endif
#if defined(SIMULATOR) && defined(__APPLE__) #if defined(SIMULATOR) && defined(__APPLE__)
#define DATA_ATTR __attribute__ ((section("__DATA, .data"))) #define DATA_ATTR __attribute__ ((section("__DATA, .data")))

View file

@ -115,7 +115,7 @@ struct font {
}; };
/* font routines*/ /* font routines*/
void font_init(void); void font_init(void) INIT_ATTR;
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
/* Load a font into the special remote ui font slot */ /* Load a font into the special remote ui font slot */
int font_load_remoteui(const char* path); int font_load_remoteui(const char* path);

View file

@ -214,7 +214,7 @@ static inline void call_tick_tasks(void)
#endif #endif
/* kernel functions */ /* kernel functions */
extern void kernel_init(void); extern void kernel_init(void) INIT_ATTR;
extern void yield(void); extern void yield(void);
extern void sleep(int ticks); extern void sleep(int ticks);
int tick_add_task(void (*f)(void)); int tick_add_task(void (*f)(void));

View file

@ -175,8 +175,8 @@ extern void lcd_write_command(int byte);
extern void lcd_write_command_e(int cmd, int data); extern void lcd_write_command_e(int cmd, int data);
extern void lcd_write_command_ex(int cmd, int data1, int data2); extern void lcd_write_command_ex(int cmd, int data1, int data2);
extern void lcd_write_data(const fb_data* p_bytes, int count); extern void lcd_write_data(const fb_data* p_bytes, int count);
extern void lcd_init(void); extern void lcd_init(void) INIT_ATTR;
extern void lcd_init_device(void); extern void lcd_init_device(void) INIT_ATTR;
extern void lcd_backlight(bool on); extern void lcd_backlight(bool on);
extern int lcd_default_contrast(void); extern int lcd_default_contrast(void);

View file

@ -83,7 +83,7 @@ bool charging_state(void);
#ifndef SIMULATOR #ifndef SIMULATOR
void power_init(void); void power_init(void) INIT_ATTR;
bool ide_powered(void); bool ide_powered(void);
#endif #endif

View file

@ -131,7 +131,7 @@ extern const unsigned short percent_to_volt_charge[11];
#endif #endif
/* Start up power management thread */ /* Start up power management thread */
void powermgmt_init(void); void powermgmt_init(void) INIT_ATTR;
#endif /* SIMULATOR */ #endif /* SIMULATOR */

View file

@ -28,7 +28,7 @@
#include <lcd.h> #include <lcd.h>
#include "file.h" #include "file.h"
void scroll_init(void); void scroll_init(void) INIT_ATTR;
void lcd_scroll_stop(const struct viewport* vp); void lcd_scroll_stop(const struct viewport* vp);
void lcd_scroll_stop_line(const struct viewport* vp, int y); void lcd_scroll_stop_line(const struct viewport* vp, int y);
void lcd_scroll_fn(void); void lcd_scroll_fn(void);

View file

@ -479,7 +479,7 @@ void core_idle(void);
void core_wake(IF_COP_VOID(unsigned int core)); void core_wake(IF_COP_VOID(unsigned int core));
/* Initialize the scheduler */ /* Initialize the scheduler */
void init_threads(void); void init_threads(void) INIT_ATTR;
/* Allocate a thread in the scheduler */ /* Allocate a thread in the scheduler */
#define CREATE_THREAD_FROZEN 0x00000001 /* Thread is frozen at create time */ #define CREATE_THREAD_FROZEN 0x00000001 /* Thread is frozen at create time */

View file

@ -158,7 +158,7 @@ enum
/** **/ /** **/
void tuner_init(void); void tuner_init(void) INIT_ATTR;
#endif /* #if CONFIG_TUNER */ #endif /* #if CONFIG_TUNER */

View file

@ -132,7 +132,7 @@ struct usb_transfer_completion_event_data
}; };
#endif /* HAVE_USBSTACK */ #endif /* HAVE_USBSTACK */
void usb_init(void); void usb_init(void) INIT_ATTR;
void usb_enable(bool on); void usb_enable(bool on);
void usb_attach(void); void usb_attach(void);
void usb_start_monitoring(void); void usb_start_monitoring(void);

View file

@ -92,7 +92,7 @@ typedef struct {
DIR_UNCACHED *regulardir; DIR_UNCACHED *regulardir;
} DIR_CACHED; } DIR_CACHED;
void dircache_init(void); void dircache_init(void) INIT_ATTR;
int dircache_load(void); int dircache_load(void);
int dircache_save(void); int dircache_save(void);
int dircache_build(int last_size); int dircache_build(int last_size);

View file

@ -99,6 +99,8 @@ SECTIONS
_iramend = .; _iramend = .;
} > IRAM AT> DRAM } > IRAM AT> DRAM
_iramcopy = LOADADDR(.iram);
.ibss (NOLOAD) : .ibss (NOLOAD) :
{ {
_iedata = .; _iedata = .;
@ -108,9 +110,17 @@ SECTIONS
_iend = .; _iend = .;
} > IRAM } > IRAM
_iramcopy = LOADADDR(.iram); .init ENDAUDIOADDR :
{
. = ALIGN(4);
_initstart = .;
*(.init)
_initend = .;
} AT> DRAM
.stack (NOLOAD) : _initcopy = LOADADDR(.init);
.stack _iramcopy (NOLOAD) :
{ {
*(.stack) *(.stack)
stackbegin = .; stackbegin = .;

View file

@ -213,6 +213,19 @@ cpu_init:
strhi r5, [r3], #4 strhi r5, [r3], #4
bhi 1b bhi 1b
#ifdef INIT_ATTR
/* copy init code to codec buffer */
ldr r2, =_initstart
ldr r3, =_initend
ldr r4, =_initcopy
1:
cmp r3, r2
ldrhi r5, [r4], #4
strhi r5, [r2], #4
bhi 1b
#endif
/* Zero out IBSS */ /* Zero out IBSS */
ldr r2, =_iedata ldr r2, =_iedata
ldr r3, =_iend ldr r3, =_iend

View file

@ -71,6 +71,7 @@ newstart:
bhi 1b bhi 1b
/* Copy the IRAM */ /* Copy the IRAM */
/* must be done before bss is zeroed */
ldr r2, =_iramcopy ldr r2, =_iramcopy
ldr r3, =_iramstart ldr r3, =_iramstart
ldr r4, =_iramend ldr r4, =_iramend
@ -79,6 +80,23 @@ newstart:
ldrhi r5, [r2], #4 ldrhi r5, [r2], #4
strhi r5, [r3], #4 strhi r5, [r3], #4
bhi 1b bhi 1b
#endif
#ifdef INIT_ATTR
/* copy init data to codec buffer */
/* must be done before bss is zeroed */
ldr r2, =_initcopy
ldr r3, =_initstart
ldr r4, =_initend
1:
cmp r4, r3
ldrhi r5, [r2], #4
strhi r5, [r3], #4
bhi 1b
mov r2, #0
mcr p15, 0, r2, c7, c5, 0 @ Invalidate ICache
#endif #endif
/* Initialise bss section to zero */ /* Initialise bss section to zero */
@ -115,7 +133,6 @@ newstart:
/* Switch back to supervisor mode */ /* Switch back to supervisor mode */
msr cpsr_c, #0xd3 msr cpsr_c, #0xd3
bl main bl main

View file

@ -126,6 +126,17 @@ SECTIONS
_iramcopy = LOADADDR(.iram); _iramcopy = LOADADDR(.iram);
.init ENDAUDIOADDR :
{
. = ALIGN(4);
_initstart = .;
*(.init)
_initend = .;
} AT> DRAM
_initcopy = LOADADDR(.init);
.idle_stacks (NOLOAD) : .idle_stacks (NOLOAD) :
{ {
*(.idle_stacks) *(.idle_stacks)
@ -175,6 +186,7 @@ SECTIONS
.audiobuf (NOLOAD) : .audiobuf (NOLOAD) :
{ {
_audiobuffer = .; _audiobuffer = .;
. = ALIGN(0x4);
audiobuffer = .; audiobuffer = .;
} > DRAM } > DRAM

View file

@ -724,6 +724,7 @@ static void __attribute__((naked))
* initializations. * initializations.
*--------------------------------------------------------------------------- *---------------------------------------------------------------------------
*/ */
static void core_thread_init(unsigned int core) INIT_ATTR;
static void core_thread_init(unsigned int core) static void core_thread_init(unsigned int core)
{ {
if (core == CPU) if (core == CPU)