Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / paflof.c
1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
4  * This program and the accompanying materials
5  * are made available under the terms of the BSD License
6  * which accompanies this distribution, and is available at
7  * http://www.opensource.org/licenses/bsd-license.php
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12 //
13 // Copyright 2002,2003,2004  Segher Boessenkool  <segher@kernel.crashing.org>
14 //
15
16
17 #define XSTR(x) #x
18 #define ISTR(x,y) XSTR(x.y)
19 #undef unix
20
21 #include "paflof.h"
22 #include <string.h>
23 #include <stdint.h>
24 #include <ctype.h>
25 #include <cache.h>
26 #include <allocator.h>
27
28 #include ISTR(TARG,h)
29
30 #define LAST_ELEMENT(x) x[sizeof x / sizeof x[0] - 1]
31
32 /* Hack to get around static inline issues */
33 #include "../lib/libhvcall/libhvcall.h"
34
35
36 extern char _start_OF[];
37
38 unsigned long fdt_start;
39 unsigned long romfs_base;
40 unsigned long epapr_magic;
41 unsigned long epapr_ima_size;           // ePAPR initially mapped area size
42 unsigned char hash_table[HASHSIZE*CELLSIZE];
43
44 #include ISTR(TARG,c)
45
46 // the actual engine
47 long engine(int mode, long param_1, long param_2)
48 {
49         // For Exceptions:
50         //      mode = ENGINE_MODE_PARAM_1 | MODE_PARAM_2
51         //      (param_1 = error, param_2 = reason)
52         //
53         // For Push:
54         //      mode = ENGINE_MODE_PARAM_1 | ENGINE_MODE_NOP
55         //
56         // For Pop:
57         //      mode = ENGINE_MODE_NOP | ENGINE_MODE_POP
58         //
59         // For Evaluate:
60         //      mode = ENGINE_MODE_PARAM_1 | MODE_PARAM_2 | ENGINE_MODE_EVAL
61         //      (param_1 = strlen(string), param_2 = string)
62
63         cell *restrict ip;
64         cell *restrict cfa;
65         static cell handler_stack[160];
66         static cell c_return[2];
67         static cell dummy;
68
69         #include "prep.h"
70         #include "dict.xt"
71
72         static int init_engine = 0;
73         if (init_engine == 0) {
74                 // one-time initialisation
75                 init_engine = 1;
76                 LAST_ELEMENT(xt_FORTH_X2d_WORDLIST).a = xt_LASTWORD;
77
78                 // stack-pointers
79                 dp = the_data_stack - 1;
80                 rp = handler_stack - 1;
81
82                 // return-address for "evaluate" personality
83                 dummy.a = &&over;
84                 c_return[1].a = &dummy;
85         }
86
87         if (mode & ENGINE_MODE_PARAM_2) {
88                 (++dp)->n = param_2;
89         }
90         if (mode & ENGINE_MODE_PARAM_1) {
91                 (++dp)->n = param_1;
92         }
93
94         if (mode & ENGINE_MODE_NOP ) {
95                 goto over;
96         }
97
98         if (mode & ENGINE_MODE_EVAL) {
99                 (++rp)->a = c_return;
100                 ip = xt_EVALUATE + 2 + ((10 + CELLSIZE - 1) / CELLSIZE);
101         } else {
102                 ip = xt_SYSTHROW;
103         }
104
105         #include "prim.code"
106         #include "board.code"
107         #include ISTR(TARG,code)
108
109
110         // Only reached in case of non-exception call
111 over:   if (mode & ENGINE_MODE_POP) {
112                 return ((dp--)->n);
113         } else {
114                 return 0;
115         }
116 }