summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/board-js2x/slof/rtas.fs
blob: 0a90c2903fa8cd6c9f00e804afe45e9c4afe0761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

#include <rtas/rtas-init.fs>
#include <rtas/rtas-cpu.fs>
#include <rtas/rtas-reboot.fs>
#include <rtas/rtas-flash.fs>
#include <rtas/rtas-vpd.fs>

\ for update-flash
: (get-flashside)  ( -- flashside )  rtas-get-flashside  ;

' (get-flashside) to get-flashside

\ remember the current flashside
get-flashside to flashside? 

\ for update-flash
: (set-flashside)  ( flashside -- status )
   dup rtas-set-flashside =  IF  0  ELSE  -1  THEN
;

' (set-flashside) to set-flashside

: rtas-ibm-read-pci-config  ( size puid bus devfn off -- x )
   [ s" ibm,read-pci-config" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   4 rtas-cb rtas>nargs l!
   2 rtas-cb rtas>nret l!
   swap 8 lshift or swap 10 lshift or rtas-cb rtas>args0 l!
   dup 20 rshift rtas-cb rtas>args1 l!
   ffffffff and rtas-cb rtas>args2 l!
   rtas-cb rtas>args3 l!
   enter-rtas
   rtas-cb rtas>args5 l@
;

: rtas-fetch-cpus  ( mask -- status )
   [ s" rtas-fetch-slaves" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   1 rtas-cb rtas>nargs l!
   1 rtas-cb rtas>nret l!
   rtas-cb rtas>args0 l!
   0 rtas-cb rtas>args1 l!
   enter-rtas
   rtas-cb rtas>args1 l@
;

: rtas-stop-bootwatchdog  ( -- status )
   [ s" rtas-stop-bootwatchdog" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   0 rtas-cb rtas>nargs l!
   1 rtas-cb rtas>nret l!
   enter-rtas
   rtas-cb rtas>args0 l@
;

: rtas-set-bootwatchdog  ( seconds -- )
   [ s" rtas-set-bootwatchdog" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   1 rtas-cb rtas>nargs l!
   0 rtas-cb rtas>nret l!
   rtas-cb rtas>args0 l!
   enter-rtas
;

' rtas-set-bootwatchdog to set-watchdog

: rtas-dump-flash  ( offset cnt -- )
   [ s" rtas-dump-flash" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   2 rtas-cb rtas>nargs l!
   0 rtas-cb rtas>nret l!
   rtas-cb rtas>args0 l!
   rtas-cb rtas>args1 l!
   enter-rtas
;

create blist 50 allot
blist 50 erase

: build-blocklist_old
   \ set version
   1 blist c!
   \ set length of block list
   50 blist 7 + c!
   \ no more block list
   0000000000000000 blist 8 + !
   \ first block
   get-load-base 0 + blist 10 + !
   80000 blist 18 + !
   get-load-base 80000 + blist 20 + !
   80000 blist 28 + !
   get-load-base 100000 + blist 30 + !
   80000 blist 38 + !
   get-load-base 180000 + blist 40 + !
   8006C blist 48 + !
;

80000 constant _block_size

: build-blocklist
   \ set length of block list
   \ length of flashfs at load-base is at offset 30... get it...
   get-load-base 30 + @
   \ calculate the number of blocks we need
   _block_size / 1 +
   \ total number of blocks is 2 (for header and block_list extension + (number of blocks for flashfs * 2 (1 for address 1 for length))
   2 * 2 + 8 * blist !
   \ set version ( in first byte only )
   1 blist c!
   \ no more block list
   0000000000000000 blist 8 + !
   \ length of flashfs at load-base is at offset 30... get it...
   get-load-base 30 + @
   \ i define one block to be 64K, so calculate the number of blocks we need and loop over them
   _block_size / 1 + 0 do
      get-load-base _block_size i * +  \ which position of load-base to store
      blist 10 +             \ at what offset of blist ( 0x8 + for header 0x8 + for extension )
      i 10 * +               \ for each loop we have done 0x10 +
      !                      \ store it
      get-load-base 30 + @
      _block_size i * -      \ remaining length
      dup _block_size > 
      IF                     \ is the remaining length > block size
	drop _block_size     \ then store the block size as length
      ELSE
			     \ do nothing (store remaining length)
      THEN
      blist 10 +          \ store the length at
      i 10 * +            \ correct blist offset 
      8 +                 \ + 8 (we have stored address, now the length)
      !                   \ store it
   loop
;



: build-blocklist-v0_old
   \ set version
   0 blist c!
   48 blist 7 + c!
   \ first block
   get-load-base 0 + blist 8 + !
   80000 blist 10 + !
   get-load-base 80000 + blist 18 + !
   80000 blist 20 + !
   get-load-base 100000 + blist 28 + !
   80000 blist 30 + !
   get-load-base 180000 + blist 38 + !
   8006C blist 40 + !
;

: build-blocklist-v0
   \ set length of block list
   \ length of flashfs at load-base is at offset 30... get it...
   get-load-base 30 + @
   \ calculate the number of blocks we need
   _block_size / 1 +
   \ total number of blocks is 1 (for header + (number of blocks for flashfs * 2 (1 for address 1 for length))
   2 * 1 + 8 * blist !
   \ length of flashfs at load-base is at offset 30... get it...
   get-load-base 30 + @
   \ i define one block to be 64K, so calculate the number of blocks we need and loop over them
   _block_size / 1 + 0 do
      get-load-base _block_size i * +  \ which position of load-base to store
      blist 8 +             \ at what offset of blist ( 0x8 + for header)
      i 10 * +               \ for each loop we have done 0x10 +
      !                      \ store it
      get-load-base 30 + @
      _block_size i * -      \ remaining length
      dup _block_size > 
      IF                     \ is the remaining length > block size
	drop _block_size     \ then store the block size as length
      ELSE
			     \ do nothing (store remaining length)
      THEN
      blist 8 +          \ store the length at
      i 10 * +            \ correct blist offset 
      8 +                 \ + 8 (we have stored address, now the length)
      !                   \ store it
   loop
;


: yy
   build-blocklist
   blist rtas-ibm-update-flash-64-and-reboot
;

: yy0
   build-blocklist-v0
   blist rtas-ibm-update-flash-64-and-reboot
;

: rtas-ibm-update-flash-64  ( block-list -- status )
   [ s" ibm,update-flash-64" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   2 rtas-cb rtas>nargs l!
   1 rtas-cb rtas>nret l!
   rtas-cb rtas>args0 l!
   \ special unofficial parameter: if this is set to 1, the rtas function will not check, wether
   \ we are on the perm side... this is needed for "update-flash -c" to work...
   1 rtas-cb rtas>args1 l!
   enter-rtas
   rtas-cb rtas>args2 l@
;

\ for update-flash
: flash-write  ( image-address -- status)
   load-base-override >r to load-base-override build-blocklist-v0
   blist rtas-ibm-update-flash-64
   r> to load-base-override 0=  IF  true  ELSE  false  THEN
;

: commit  1 rtas-ibm-manage-flash-image ;
: reject  0 rtas-ibm-manage-flash-image ;

: rtas-ibm-validate-flash-image  ( image-to-commit -- status )
   [ s" ibm,validate-flash-image" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   2 rtas-cb rtas>nargs l!
   2 rtas-cb rtas>nret l!
   rtas-cb rtas>args0 l!
   enter-rtas
   rtas-cb rtas>args1 l@
;

: rtas-get-blade-descr ( address size -- len status )
   [ s" rtas-get-blade-descr" rtas-get-token ] LITERAL rtas-cb rtas>token l!
   2 rtas-cb rtas>nargs l!
   2 rtas-cb rtas>nret l!
   rtas-cb rtas>args1 l!
   rtas-cb rtas>args0 l!
   enter-rtas
   rtas-cb rtas>args2 l@
   rtas-cb rtas>args3 l@
;