Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / ppc / qemu / kernel.c
1 /*
2  *   Creation Date: <2003/10/25 14:07:17 samuel>
3  *   Time-stamp: <2004/08/28 17:48:19 stepan>
4  *
5  *      <kernel.c>
6  *
7  *   Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
8  *   Copyright (C) 2003, 2004 Stefan Reinauer
9  *
10  *   Based upon unix.c (from OpenBIOS):
11  *
12  *   Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer
13  *
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
17  *
18  */
19
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"
27
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
38
39 static ucell forth_dictionary[DICTIONARY_SIZE] DICTIONARY_SECTION = {
40 #include "qemu-dict.h"
41 };
42
43 static ucell            *memory;
44
45 /************************************************************************/
46 /*      F U N C T I O N S                                               */
47 /************************************************************************/
48
49 int
50 forth_segv_handler( char *segv_addr )
51 {
52         ucell addr = 0xdeadbeef;
53
54         if( PC >= pointer2cell(dict) && PC <= pointer2cell(dict) + dicthead )
55                 addr = *(ucell *)cell2pointer(PC);
56
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);
63
64 #ifdef DEBUG_DSTACK
65         printdstack();
66 #endif
67 #ifdef DEBUG_RSTACK
68         printrstack();
69 #endif
70         return -1;
71 }
72
73 /*
74  * allocate memory and prepare engine for memory management.
75  */
76
77 static void
78 init_memory( void )
79 {
80         memory = malloc(MEMORY_SIZE);
81         if( !memory )
82                 panic("panic: not enough memory on host system.\n");
83
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
87          */
88
89         PUSH( pointer2cell(memory) );
90         PUSH( pointer2cell(memory) + MEMORY_SIZE );
91 }
92
93 int
94 initialize_forth( void )
95 {
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);
101
102         forth_init();
103
104         PUSH_xt( bind_noname_func(arch_of_init) );
105         fword("PREPOST-initializer");
106
107         PC = (ucell)findword("initialize-of");
108         if( PC ) {
109                 init_memory();
110                 enterforth((xt_t)PC);
111                 free( memory );
112         }
113         free( dict );
114         return 0;
115 }