Use init_trampoline() for trampoline variable initialization.
Add calls to a new forth_init() function for each architecture to invoke it. Idea courtesy of Blue.
This fixes ppc64 compilation by avoiding a casted self-reference.
v2: * Share init_trampoline() with kernel/bootstrap.c, suggested by Mark. * Adopt QEMU coding style for new functions.
Cc: Blue Swirl blauwirbel@gmail.com Cc: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk Signed-off-by: Andreas Färber andreas.faerber@web.de --- arch/amd64/openbios.c | 1 + arch/ppc/kernel.c | 1 + arch/ppc/qemu/kernel.c | 1 + arch/sparc32/openbios.c | 1 + arch/sparc64/openbios.c | 1 + arch/unix/unix.c | 1 + arch/x86/openbios.c | 1 + include/kernel/kernel.h | 2 ++ kernel/bootstrap.c | 21 ++++++--------------- kernel/internal.c | 16 +++++++++++++++- 10 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/arch/amd64/openbios.c b/arch/amd64/openbios.c index df43943..db138ad 100644 --- a/arch/amd64/openbios.c +++ b/arch/amd64/openbios.c @@ -67,6 +67,7 @@ int openbios(void)
load_dictionary((char *)sys_info.dict_start, sys_info.dict_end-sys_info.dict_start); + forth_init();
relocate(&sys_info);
diff --git a/arch/ppc/kernel.c b/arch/ppc/kernel.c index 57efde7..28f2965 100644 --- a/arch/ppc/kernel.c +++ b/arch/ppc/kernel.c @@ -83,6 +83,7 @@ initialize_forth( void ) { dict = malloc(DICTIONARY_SIZE); load_dictionary( forth_dictionary, sizeof(forth_dictionary) ); + forth_init();
PUSH_xt( bind_noname_func(arch_of_init) ); fword("PREPOST-initializer"); diff --git a/arch/ppc/qemu/kernel.c b/arch/ppc/qemu/kernel.c index dbfca57..4cae525 100644 --- a/arch/ppc/qemu/kernel.c +++ b/arch/ppc/qemu/kernel.c @@ -86,6 +86,7 @@ initialize_forth( void ) dictlimit = DICTIONARY_SIZE;
load_dictionary( forth_dictionary, sizeof(forth_dictionary) ); + forth_init();
PUSH_xt( bind_noname_func(arch_of_init) ); fword("PREPOST-initializer"); diff --git a/arch/sparc32/openbios.c b/arch/sparc32/openbios.c index e368d6c..1c86752 100644 --- a/arch/sparc32/openbios.c +++ b/arch/sparc32/openbios.c @@ -970,6 +970,7 @@ int openbios(void) load_dictionary((char *)sys_info.dict_start, (unsigned long)sys_info.dict_end - (unsigned long)sys_info.dict_start); + forth_init();
#ifdef CONFIG_DEBUG_BOOT printk("forth started.\n"); diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c index 49bbe27..8c08814 100644 --- a/arch/sparc64/openbios.c +++ b/arch/sparc64/openbios.c @@ -623,6 +623,7 @@ int openbios(void) load_dictionary((char *)sys_info.dict_start, (unsigned long)sys_info.dict_end - (unsigned long)sys_info.dict_start); + forth_init();
#ifdef CONFIG_DEBUG_BOOT printk("forth started.\n"); diff --git a/arch/unix/unix.c b/arch/unix/unix.c index a8b9f78..e5c4590 100644 --- a/arch/unix/unix.c +++ b/arch/unix/unix.c @@ -514,6 +514,7 @@ int main(int argc, char *argv[]) printk("done.\n");
read_dictionary(argv[optind]); + forth_init();
PUSH_xt( bind_noname_func(arch_init) ); fword("PREPOST-initializer"); diff --git a/arch/x86/openbios.c b/arch/x86/openbios.c index 62ef587..24b886d 100644 --- a/arch/x86/openbios.c +++ b/arch/x86/openbios.c @@ -90,6 +90,7 @@ int openbios(void) load_dictionary((char *)sys_info.dict_start, (unsigned long)sys_info.dict_end - (unsigned long)sys_info.dict_start); + forth_init();
relocate(&sys_info);
diff --git a/include/kernel/kernel.h b/include/kernel/kernel.h index 15605b5..c887e24 100644 --- a/include/kernel/kernel.h +++ b/include/kernel/kernel.h @@ -32,6 +32,8 @@ extern void panic(const char *error) __attribute__ ((noreturn));
extern xt_t findword(const char *s1); extern void modules_init( void ); +extern void init_trampoline(ucell *t); +extern void forth_init(void);
/* arch kernel hooks */ extern void exception(cell no); diff --git a/kernel/bootstrap.c b/kernel/bootstrap.c index 90c93c1..c029c02 100644 --- a/kernel/bootstrap.c +++ b/kernel/bootstrap.c @@ -91,20 +91,6 @@ static const char *wordnames[] = { "$include", "$encode-file", "(debug", "(debug-off)" };
-static void init_trampoline(void) -{ - if (!trampoline) { - /* We're using side effects which is to some extent nasty */ - printf("WARNING: no trampoline!\n"); - return; - } - - trampoline[0]=DOCOL; - trampoline[1]=0; - trampoline[2]=target_ucell(pointer2cell(trampoline)+3*sizeof(ucell)); - trampoline[3]=0; -} - /* * dictionary related functions. */ @@ -1181,7 +1167,12 @@ int main(int argc, char *argv[]) TRAMPOLINE_SIZE); #endif
- init_trampoline(); + if (trampoline == NULL) { + /* We're using side effects which is to some extent nasty */ + printf("WARNING: no trampoline!\n"); + } else { + init_trampoline(trampoline); + }
if (!segfault) { if (verbose) diff --git a/kernel/internal.c b/kernel/internal.c index 91ab440..0bf9c64 100644 --- a/kernel/internal.c +++ b/kernel/internal.c @@ -50,8 +50,13 @@ char xtname[MAXNFALEN]; /* instead of pointing to an explicit 0 variable we * point behind the pointer. */ -static ucell t[] = { DOCOL, 0, (ucell)(t+3), 0 }; +static ucell t[] = { 0, 0, 0, 0 }; static ucell *trampoline = t; + +void forth_init(void) +{ + init_trampoline(trampoline); +} #endif
#ifndef CONFIG_DEBUG_INTERPRETER @@ -67,6 +72,15 @@ static ucell *trampoline = t; #endif
+void init_trampoline(ucell *tramp) +{ + tramp[0] = DOCOL; + tramp[1] = 0; + tramp[2] = target_ucell(pointer2cell(tramp) + 3 * sizeof(ucell)); + tramp[3] = 0; +} + + static inline void processxt(ucell xt) { void (*tokenp) (void);