These changes are the raw update to qemu-2.6.
[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 <stdio.h>
23 #include <string.h>
24 #include <stdint.h>
25 #include <ctype.h>
26 #include <cache.h>
27 #include <allocator.h>
28
29 #include ISTR(TARG,h)
30
31 #define LAST_ELEMENT(x) x[sizeof x / sizeof x[0] - 1]
32
33 /* Hack to get around static inline issues */
34 #include "../lib/libhvcall/libhvcall.h"
35
36
37 extern char _start_OF[];
38
39 unsigned long fdt_start;
40 unsigned long romfs_base;
41 unsigned long epapr_magic;
42 unsigned long epapr_ima_size;           // ePAPR initially mapped area size
43 unsigned char hash_table[HASHSIZE*CELLSIZE];
44
45 #include ISTR(TARG,c)
46
47 static int did_stackwarning;
48 extern char the_system_stack[];
49
50 // the actual engine
51 long engine(int mode, long param_1, long param_2)
52 {
53         // For Exceptions:
54         //      mode = ENGINE_MODE_PARAM_1 | MODE_PARAM_2
55         //      (param_1 = error, param_2 = reason)
56         //
57         // For Push:
58         //      mode = ENGINE_MODE_PARAM_1 | ENGINE_MODE_NOP
59         //
60         // For Pop:
61         //      mode = ENGINE_MODE_NOP | ENGINE_MODE_POP
62         //
63         // For Evaluate:
64         //      mode = ENGINE_MODE_PARAM_1 | MODE_PARAM_2 | ENGINE_MODE_EVAL
65         //      (param_1 = strlen(string), param_2 = string)
66
67         cell *restrict ip;
68         cell *restrict cfa;
69         static cell handler_stack[160];
70         static cell c_return[2];
71         static cell dummy;
72
73         #include "prep.h"
74         #include "dict.xt"
75
76         static int init_engine = 0;
77         if (init_engine == 0) {
78                 // one-time initialisation
79                 init_engine = 1;
80                 LAST_ELEMENT(xt_FORTH_X2d_WORDLIST).a = xt_LASTWORD;
81
82                 // stack-pointers
83                 dp = the_data_stack - 1;
84                 rp = handler_stack - 1;
85
86                 // return-address for "evaluate" personality
87                 dummy.a = &&over;
88                 c_return[1].a = &dummy;
89         }
90
91         if ((char *)&ip < the_system_stack && !did_stackwarning) {
92                 puts("ERROR: stack overflow in engine()!");
93                 did_stackwarning = 1;
94         }
95
96         if (mode & ENGINE_MODE_PARAM_2) {
97                 (++dp)->n = param_2;
98         }
99         if (mode & ENGINE_MODE_PARAM_1) {
100                 (++dp)->n = param_1;
101         }
102
103         if (mode & ENGINE_MODE_NOP ) {
104                 goto over;
105         }
106
107         if (mode & ENGINE_MODE_EVAL) {
108                 (++rp)->a = c_return;
109                 ip = xt_EVALUATE + 2 + ((10 + CELLSIZE - 1) / CELLSIZE);
110         } else {
111                 ip = xt_SYSTHROW;
112         }
113
114         #include "prim.code"
115         #include "board.code"
116         #include ISTR(TARG,code)
117
118
119         // Only reached in case of non-exception call
120 over:   if (mode & ENGINE_MODE_POP) {
121                 return ((dp--)->n);
122         } else {
123                 return 0;
124         }
125 }