1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12 * Copyright (C) 2006 Jens Arnold
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
28 /* load and run a plugin linked as an overlay.
31 rb = pointer to plugin api, also passed on to the overlay
32 parameter = plugin parameter, passed on to the overlay
33 filename = overlay file name, absolute path as usual
34 name = overlay display name
37 return value from the overlay
39 As long as a large plugin to be overlayed doesn't use the audiobuffer
40 itself, no adjustments in the plugin source code are necessary to make
41 it work as an overlay, it only needs an adapted linker script.
43 If the overlayed plugin *does* use the audiobuffer itself, it needs
44 to make sure not to overwrite itself.
46 The linker script for the overlay should use a base address towards the
47 end of the audiobuffer, just low enough to make the overlay fit. */
49 enum plugin_status
run_overlay(const void* parameter
,
50 unsigned char *filename
, unsigned char *name
)
53 ssize_t audiobuf_size
;
54 unsigned char *audiobuf
;
55 static struct plugin_header header
;
57 fd
= rb
->open(filename
, O_RDONLY
);
60 rb
->splashf(2*HZ
, "Can't open %s", filename
);
63 readsize
= rb
->read(fd
, &header
, sizeof(header
));
65 /* Close for now. Less code than doing it in all error checks.
66 * Would need to seek back anyway. */
68 if (readsize
!= sizeof(header
))
70 rb
->splashf(2*HZ
, "Reading %s overlay failed.", name
);
73 if (header
.magic
!= PLUGIN_MAGIC
|| header
.target_id
!= TARGET_ID
)
75 rb
->splashf(2*HZ
, "%s overlay: Incompatible model.", name
);
78 if (header
.api_version
!= PLUGIN_API_VERSION
)
80 rb
->splashf(2*HZ
, "%s overlay: Incompatible version.", name
);
84 audiobuf
= rb
->plugin_get_audio_buffer((size_t *)&audiobuf_size
);
85 if (header
.load_addr
< audiobuf
||
86 header
.end_addr
> audiobuf
+ audiobuf_size
)
88 rb
->splashf(2*HZ
, "%s overlay doesn't fit into memory.", name
);
92 fd
= rb
->open(filename
, O_RDONLY
);
95 rb
->splashf(2*HZ
, "Can't open %s", filename
);
98 readsize
= rb
->read(fd
, header
.load_addr
, header
.end_addr
- header
.load_addr
);
103 rb
->splashf(2*HZ
, "Reading %s overlay failed.", name
);
106 /* Zero out bss area */
107 rb
->memset(header
.load_addr
+ readsize
, 0,
108 header
.end_addr
- (header
.load_addr
+ readsize
));
111 return header
.entry_point(parameter
);