2 * Creation Date: <2003/10/25 14:07:17 samuel>
3 * Time-stamp: <2004/08/28 17:48:19 stepan>
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
22 #include "libopenbios/bindings.h"
23 #include "kernel/stack.h"
24 #include "kernel/kernel.h"
25 #include "libc/string.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))
32 #define DICTIONARY_BASE 0xfff08000 /* this must match the value in ldscript! */
33 #define DICTIONARY_SECTION __attribute__((section(".data.dict")))
35 #define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary))
36 #define DICTIONARY_SECTION
39 static ucell forth_dictionary
[DICTIONARY_SIZE
] DICTIONARY_SECTION
= {
40 #include "qemu-dict.h"
45 /************************************************************************/
46 /* F U N C T I O N S */
47 /************************************************************************/
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
);
74 * allocate memory and prepare engine for memory management.
80 memory
= malloc(MEMORY_SIZE
);
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
);
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
);
104 PUSH_xt( bind_noname_func(arch_of_init
) );
105 fword("PREPOST-initializer");
107 PC
= (ucell
)findword("initialize-of");
110 enterforth((xt_t
)PC
);