ppc: avoid runtime relocations
[openbios.git] / arch / ppc / qemu / kernel.c
blobb26fba5f757ee603e85d4fd3f8934c0c28221c3e
1 /*
2 * Creation Date: <2003/10/25 14:07:17 samuel>
3 * Time-stamp: <2004/08/28 17:48:19 stepan>
5 * <kernel.c>
7 * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
8 * Copyright (C) 2003, 2004 Stefan Reinauer
10 * Based upon unix.c (from OpenBIOS):
12 * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer
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 * version 2
20 #include "config.h"
21 #include "dict.h"
22 #include "libopenbios/bindings.h"
23 #include "kernel/stack.h"
24 #include "kernel/kernel.h"
25 #include "libc/string.h"
26 #include "kernel.h"
28 #define MEMORY_SIZE (256*1024) /* 256K ram for hosted system */
29 /* 512K for the dictionary */
30 #define DICTIONARY_SIZE (512 * 1024 / sizeof(ucell))
31 #ifdef __powerpc64__
32 #define DICTIONARY_BASE 0xfff08000 /* this must match the value in ldscript! */
33 #define DICTIONARY_SECTION __attribute__((section(".data.dict")))
34 #else
35 #define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary))
36 #define DICTIONARY_SECTION
37 #endif
39 static ucell forth_dictionary[DICTIONARY_SIZE] DICTIONARY_SECTION = {
40 #include "qemu-dict.h"
43 static ucell *memory;
45 /************************************************************************/
46 /* F U N C T I O N S */
47 /************************************************************************/
49 int
50 forth_segv_handler( char *segv_addr )
52 ucell addr = 0xdeadbeef;
54 if( PC >= pointer2cell(dict) && PC <= pointer2cell(dict) + dicthead )
55 addr = *(ucell *)cell2pointer(PC);
57 printk("panic: segmentation violation at 0x%p\n", segv_addr);
58 printk("dict=0x%p here=0x%p(dict+0x%x) pc=0x%x(dict+0x%x)\n",
59 dict, (char*)dict + dicthead, dicthead,
60 PC, PC - pointer2cell(dict));
61 printk("dstackcnt=%d rstackcnt=%d instruction=%x\n",
62 dstackcnt, rstackcnt, addr);
64 #ifdef DEBUG_DSTACK
65 printdstack();
66 #endif
67 #ifdef DEBUG_RSTACK
68 printrstack();
69 #endif
70 return -1;
74 * allocate memory and prepare engine for memory management.
77 static void
78 init_memory( void )
80 memory = malloc(MEMORY_SIZE);
81 if( !memory )
82 panic("panic: not enough memory on host system.\n");
84 /* we push start and end of memory to the stack
85 * so that it can be used by the forth word QUIT
86 * to initialize the memory allocator
89 PUSH( pointer2cell(memory) );
90 PUSH( pointer2cell(memory) + MEMORY_SIZE );
93 int
94 initialize_forth( void )
96 dict = (unsigned char *)forth_dictionary;
97 dicthead = (ucell)FORTH_DICTIONARY_END;
98 last = (ucell *)((unsigned char *)forth_dictionary +
99 FORTH_DICTIONARY_LAST);
100 dictlimit = sizeof(forth_dictionary);
102 forth_init();
104 PUSH_xt( bind_noname_func(arch_of_init) );
105 fword("PREPOST-initializer");
107 PC = (ucell)findword("initialize-of");
108 if( PC ) {
109 init_memory();
110 enterforth((xt_t)PC);
111 free( memory );
113 free( dict );
114 return 0;