Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / exception.fs
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 STRUCT
14    cell FIELD >r0   cell FIELD >r1   cell FIELD >r2   cell FIELD >r3
15    cell FIELD >r4   cell FIELD >r5   cell FIELD >r6   cell FIELD >r7
16    cell FIELD >r8   cell FIELD >r9   cell FIELD >r10  cell FIELD >r11
17    cell FIELD >r12  cell FIELD >r13  cell FIELD >r14  cell FIELD >r15
18    cell FIELD >r16  cell FIELD >r17  cell FIELD >r18  cell FIELD >r19
19    cell FIELD >r20  cell FIELD >r21  cell FIELD >r22  cell FIELD >r23
20    cell FIELD >r24  cell FIELD >r25  cell FIELD >r26  cell FIELD >r27
21    cell FIELD >r28  cell FIELD >r29  cell FIELD >r30  cell FIELD >r31
22    cell FIELD >cr   cell FIELD >xer  cell FIELD >lr   cell FIELD >ctr
23    cell FIELD >srr0 cell FIELD >srr1 cell FIELD >dar  cell FIELD >dsisr
24 CONSTANT ciregs-size
25
26
27
28 : .16  10 0.r 3 spaces ;
29 : .8   8 spaces 8 0.r 3 spaces ;
30 : .4regs  cr 4 0 DO dup @ .16 8 cells+ LOOP drop ;
31 : .fixed-regs
32    cr ."     R0 .. R7           R8 .. R15         R16 .. R23         R24 .. R31"
33    dup 8 0 DO dup .4regs cell+ LOOP drop
34 ;
35
36 : .special-regs
37    cr ."     CR / XER           LR / CTR          SRR0 / SRR1        DAR / DSISR"
38    cr dup >cr  @ .8   dup >lr  @ .16  dup >srr0 @ .16  dup >dar @ .16
39    cr dup >xer @ .16  dup >ctr @ .16  dup >srr1 @ .16    >dsisr @ .8
40 ;
41
42 : .regs
43    cr .fixed-regs
44    cr .special-regs
45    cr cr
46 ;
47
48 : .hw-exception ( reason-code exception-nr -- )
49    ." ( " dup . ." ) "
50    CASE
51       200 OF ." Machine Check" ENDOF
52       300 OF ." Data Storage" ENDOF
53       380 OF ." Data Segment" ENDOF
54       400 OF ." Instruction Storage" ENDOF
55       480 OF ." Instruction Segment" ENDOF
56       500 OF ." External" ENDOF
57       600 OF ." Alignment" ENDOF
58       700 OF ." Program" ENDOF
59       800 OF ." Floating-point unavailable" ENDOF
60       900 OF ." Decrementer" ENDOF
61       980 OF ." Hypervisor Decrementer" ENDOF
62       C00 OF ." System Call" ENDOF
63       D00 OF ." Trace" ENDOF
64       F00 OF ." Performance Monitor" ENDOF
65       F20 OF ." VMX Unavailable" ENDOF
66       1200 OF ." System Error" ENDOF
67       1600 OF ." Maintenance" ENDOF
68       1800 OF ." Thermal" ENDOF
69       dup OF ." Unknown" ENDOF
70    ENDCASE
71    ."  Exception [ " . ." ]"
72 ;
73
74 : .sw-exception ( exception-nr -- )
75    ."  Exception [ " . ." ] triggered by boot firmware."
76 ;
77
78 \ this word gets also called for non-hardware exceptions.
79 : be-hw-exception ( [reason-code] exception-nr -- )
80    cr cr
81    dup 0> IF .hw-exception ELSE .sw-exception THEN
82    cr eregs .regs
83 ;
84 ' be-hw-exception to hw-exception-handler
85
86 : (boot-exception-handler) ( x1...xn exception-nr -- x1...xn)
87    dup IF
88       dup 0 > IF
89          negate cp 9 emit ." : " type
90       ELSE
91          CASE
92             -6d OF cr ." W3411: Client application returned." cr ENDOF
93             -6c OF cr ." E3400: It was not possible to boot from any device "
94                 ." specified in the VPD." cr
95             ENDOF
96             -6b OF cr ." E3410: Boot list successfully read from VPD "
97                 ." but no useful information received." cr
98             ENDOF
99             -6a OF cr ." E3420: Boot list could not be read from VPD." cr
100             ENDOF
101             -69 OF
102                 cr ." E3406: Client application returned an error"
103                 abort"-str @ count dup IF
104                    ." :    " type cr
105                 ELSE
106                    ." ." cr
107                    2drop
108                 THEN
109             ENDOF
110             -68 OF cr ." E3405: No such device" cr ENDOF
111             -67 OF cr ." E3404: Not a bootable device!" cr ENDOF
112             -66 OF cr ." E3408: Failed to claim memory for the executable" cr
113             ENDOF
114             -65 OF cr ." E3407: Load failed" cr ENDOF
115             -64 OF cr ." E3403: Bad executable:   " abort"-str @ count type cr
116             ENDOF
117             -63 OF cr ." E3409: Unknown FORTH Word" cr ENDOF
118             -2 OF cr ." E3401: Aborting boot,  " abort"-str @ count type cr
119             ENDOF
120             dup OF ." E3402: Aborting boot, internal error" cr ENDOF
121          ENDCASE
122       THEN
123    ELSE
124       drop
125    THEN
126 ;
127
128 ' (boot-exception-handler) to boot-exception-handler
129
130 : throw-error ( error-code "error-string" -- )
131    skipws 0a parse rot throw
132 ;
133
134 \ Enable external interrupt in msr
135
136 : enable-ext-int ( -- )
137    msr@ 8000 or msr!
138 ;
139
140 \ Disable external interrupt in msr
141
142 : disable-ext-int ( -- )
143    msr@ 8000 not and msr!
144 ;
145
146 \ Generate external interrupt through Internal Interrupt Controller of BE
147
148 : gen-ext-int ( -- )
149    7fffffff dec!               \ Reset decrementer
150    enable-ext-int              \ Enable interrupt
151    FF 20000508418 rx!          \ Interrupt priority mask
152    10 20000508410 rx!          \ Interrupt priority
153 ;
154