|
|
1.1 root 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 ([email protected])
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: #define DICTIONARY_SIZE (512*1024) /* 512K for the dictionary */
30:
31: static ucell *memory;
32:
33: /************************************************************************/
34: /* F U N C T I O N S */
35: /************************************************************************/
36:
37: int
38: forth_segv_handler( char *segv_addr )
39: {
40: ucell addr = 0xdeadbeef;
41:
42: if( PC >= (ucell) dict && PC <= (ucell) dict + dicthead )
43: addr = *(ucell *) PC;
44:
45: printk("panic: segmentation violation at %x\n", (int)segv_addr);
46: printk("dict=0x%x here=0x%x(dict+0x%x) pc=0x%x(dict+0x%x)\n",
47: (int)dict, (int)(dict + dicthead), dicthead,
48: PC, PC - (ucell) dict);
49: printk("dstackcnt=%d rstackcnt=%d instruction=%x\n",
50: dstackcnt, rstackcnt, addr);
51:
52: #ifdef DEBUG_DSTACK
53: printdstack();
54: #endif
55: #ifdef DEBUG_RSTACK
56: printrstack();
57: #endif
58: return -1;
59: }
60:
61: /*
62: * allocate memory and prepare engine for memory management.
63: */
64:
65: static void
66: init_memory( void )
67: {
68: memory = malloc(MEMORY_SIZE);
69: if( !memory )
70: panic("panic: not enough memory on host system.\n");
71:
72: /* we push start and end of memory to the stack
73: * so that it can be used by the forth word QUIT
74: * to initialize the memory allocator
75: */
76:
77: PUSH( (ucell)memory );
78: PUSH( (ucell)memory + MEMORY_SIZE );
79: }
80:
81: int
82: initialize_forth( void )
83: {
84: dict = malloc(DICTIONARY_SIZE);
85: load_dictionary( forth_dictionary, sizeof(forth_dictionary) );
86: forth_init();
87:
88: PUSH_xt( bind_noname_func(arch_of_init) );
89: fword("PREPOST-initializer");
90:
91: PC = (ucell)findword("initialize-of");
92: if( PC ) {
93: init_memory();
94: enterforth((xt_t)PC);
95: free( memory );
96: }
97: free( dict );
98: return 0;
99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.