~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/SLOF/board-qemu/slof/tree.fs

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\ *****************************************************************************
 
2
\ * Copyright (c) 2004, 2011 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
: strequal ( str1 len1 str2 len2 -- flag )
 
14
  rot dup rot = IF comp 0= ELSE 2drop drop 0 THEN ; 
 
15
 
 
16
400 cp
 
17
 
 
18
\ The root of the device tree and some of its kids.
 
19
" /" find-device
 
20
 
 
21
\ The following properties have been provided by the FDT from QEMU already,
 
22
\ so we do not have to create them on our own:
 
23
 
 
24
\ " QEMU" encode-string s" model" property
 
25
\ 2 encode-int s" #address-cells" property
 
26
\ 2 encode-int s" #size-cells" property
 
27
\ s" chrp" device-type
 
28
 
 
29
#include "archsupport.fs"
 
30
 
 
31
480 cp
 
32
 
 
33
\ See 3.6.5, and the PowerPC OF binding document.
 
34
new-device
 
35
s" mmu" 2dup device-name device-type
 
36
0 0 s" translations" property
 
37
 
 
38
: open  true ;
 
39
: close ;
 
40
 
 
41
finish-device
 
42
device-end
 
43
 
 
44
4c0 cp
 
45
 
 
46
\ Fixup timebase frequency from device-tree
 
47
: fixup-tbfreq
 
48
    " /cpus" find-device
 
49
    get-node child dup 0= ABORT" CPU not found"
 
50
    set-node
 
51
    " timebase-frequency" get-node get-package-property IF
 
52
        2drop
 
53
    ELSE
 
54
        decode-int to tb-frequency 2drop
 
55
    THEN
 
56
    device-end
 
57
;
 
58
fixup-tbfreq
 
59
 
 
60
4d0 cp
 
61
 
 
62
include fbuffer.fs
 
63
 
 
64
500 cp
 
65
 
 
66
: populate-vios ( -- )
 
67
    \ Populate the /vdevice children with their methods
 
68
    \ WARNING: Quite a few SLOFisms here like get-node, set-node, ...
 
69
 
 
70
    ." Populating /vdevice methods" cr
 
71
    " /vdevice" find-device get-node child
 
72
    BEGIN
 
73
        dup 0 <>
 
74
    WHILE
 
75
        dup set-node
 
76
        dup " compatible" rot get-package-property 0 = IF
 
77
            drop dup from-cstring
 
78
            2dup " hvterm1" strequal IF
 
79
                " vio-hvterm.fs" included
 
80
            THEN
 
81
            2dup " IBM,v-scsi" strequal IF
 
82
                " vio-vscsi.fs" included
 
83
            THEN
 
84
            2dup " IBM,l-lan" strequal IF
 
85
                " vio-veth.fs" included
 
86
            THEN
 
87
            2dup " qemu,spapr-nvram" strequal IF
 
88
                " rtas-nvram.fs" included
 
89
            THEN
 
90
            2drop
 
91
       THEN
 
92
       peer
 
93
    REPEAT drop
 
94
 
 
95
    device-end
 
96
;
 
97
 
 
98
\ Now do it
 
99
populate-vios
 
100
 
 
101
5a0 cp
 
102
 
 
103
#include "pci-scan.fs"
 
104
 
 
105
: populate-pci-busses ( -- )
 
106
    \ Populate the /pci* children with their methods
 
107
    " /" find-device get-node child
 
108
    BEGIN
 
109
        dup 0 <>
 
110
    WHILE
 
111
        dup set-node
 
112
        dup " name" rot get-package-property 0 = IF
 
113
            drop dup from-cstring
 
114
            2dup s" pci" strequal IF
 
115
                s" pci-phb.fs" included
 
116
            THEN
 
117
            2drop
 
118
       THEN
 
119
       peer
 
120
    REPEAT drop
 
121
 
 
122
    device-end
 
123
;
 
124
 
 
125
populate-pci-busses
 
126
 
 
127
600 cp
 
128
 
 
129
: check-patch-kernel-sc1 ( -- )
 
130
    \ At this point we can try our best to patch the kernel. This function
 
131
    \ gets called from the "quiesce" call that kernels execute before they
 
132
    \ take over the system.
 
133
    \
 
134
    \ Here we know that ciregs->r4 contains the return address that gets us
 
135
    \ back into enter_prom inside the guest kernel.
 
136
    \ We assume that within a range of +- 16MB of that pointer all sc 1
 
137
    \ instructions inside of that kernel reside.
 
138
 
 
139
    \ test_ins (instruction that tells us the kernel's endianness; we use the
 
140
    \           return address back into the kernel here.)
 
141
    ciregs >r4 @
 
142
    \ test_ins + 16MB (end of search range)
 
143
    dup 1000000 +
 
144
    \ MAX(test_ins - 16MB, 0) (start of search range)
 
145
    dup 2000000 < IF 0 ELSE dup 2000000 - THEN
 
146
    swap
 
147
    check-and-patch-sc1
 
148
;
 
149
 
 
150
\ Add sc 1 patching
 
151
' check-patch-kernel-sc1 add-quiesce-xt
 
152
 
 
153
\ Add rtas cleanup last
 
154
' rtas-quiesce add-quiesce-xt
 
155
 
 
156
6c0 cp
 
157
 
 
158
\ Do not assume that cpu0 is available
 
159
: set-chosen-cpu
 
160
    " /cpus" find-device
 
161
    get-node child dup 0= ABORT" CPU not found"
 
162
    node>path open-dev encode-int s" cpu" set-chosen
 
163
;
 
164
set-chosen-cpu
 
165
 
 
166
s" /memory@0" open-dev encode-int s" memory" set-chosen
 
167
 
 
168
700 cp
 
169
 
 
170
\ See 3.5.
 
171
s" /openprom" find-device
 
172
   s" SLOF," slof-build-id here swap rmove here slof-build-id nip $cat encode-string s" model" property
 
173
   0 0 s" relative-addressing" property
 
174
device-end
 
175
 
 
176
s" /aliases" find-device
 
177
   : open  true ;
 
178
   : close ;
 
179
device-end
 
180
 
 
181
s" /mmu" open-dev encode-int s" mmu" set-chosen
 
182
 
 
183
#include "available.fs"
 
184
 
 
185
\ Setup terminal IO
 
186
 
 
187
#include <term-io.fs>
 
188