aboutsummaryrefslogtreecommitdiff
path: root/src/post.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2013-02-05 20:57:10 -0500
committerKevin O'Connor <kevin@koconnor.net>2013-02-07 00:10:21 -0500
commitbc628090011dc110bf55957316eaa4be7663ca0a (patch)
tree439b781fb64333d12786aca6df1d965d0d0168c2 /src/post.c
parent13fd0a5c37370951b77e9ed4891486728b03c0fb (diff)
downloadseabios-hppa-bc628090011dc110bf55957316eaa4be7663ca0a.zip
seabios-hppa-bc628090011dc110bf55957316eaa4be7663ca0a.tar.gz
seabios-hppa-bc628090011dc110bf55957316eaa4be7663ca0a.tar.bz2
Support calling a function other than maininit() from reloc_preinit().
Pass a function pointer to reloc_preinit() instead of always running maininit() after relocating the init code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/post.c')
-rw-r--r--src/post.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/post.c b/src/post.c
index 4b04740..7df021e 100644
--- a/src/post.c
+++ b/src/post.c
@@ -331,14 +331,15 @@ updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta)
*((u32*)(dest + *reloc)) += delta;
}
-// Relocate init code and then call maininit() at new address.
-static void
-reloc_preinit(void)
+// Relocate init code and then call a function at its new address.
+// The passed function should be in the "init" section and must not
+// return.
+static void __noreturn
+reloc_preinit(void *f, void *arg)
{
- if (!CONFIG_RELOCATE_INIT) {
- maininit();
- return;
- }
+ void (*func)(void *) __noreturn = f;
+ if (!CONFIG_RELOCATE_INIT)
+ func(arg);
// Symbols populated by the build.
extern u8 code32flat_start[];
extern u8 _reloc_min_align;
@@ -368,11 +369,12 @@ reloc_preinit(void)
updateRelocs(codedest, _reloc_abs_start, _reloc_abs_end, delta);
updateRelocs(codedest, _reloc_rel_start, _reloc_rel_end, -delta);
updateRelocs(code32flat_start, _reloc_init_start, _reloc_init_end, delta);
+ if (f >= (void*)code32init_start && f < (void*)code32init_end)
+ func = f + delta;
- // Call maininit() in relocated code.
- void (*func)(void) = (void*)maininit + delta;
+ // Call function in relocated code.
barrier();
- func();
+ func(arg);
}
// Setup for code relocation and then call reloc_init
@@ -387,7 +389,7 @@ dopost(void)
malloc_preinit();
// Relocate initialization code and call maininit().
- reloc_preinit();
+ reloc_preinit(maininit, NULL);
}
// Entry point for Power On Self Test (POST) - the BIOS initilization