Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / loaders.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 \ \\\\\\\\\\\\\\ Global Data
14 CREATE bootdevice 2 cells allot bootdevice 2 cells erase
15 CREATE bootargs 2 cells allot bootargs 2 cells erase
16 CREATE load-list 2 cells allot load-list 2 cells erase
17
18 : start-elf ( arg len entry -- )
19    msr@ 7fffffffffffffff and 2000 or ciregs >srr1 ! call-client
20 ;
21
22 : start-elf64 ( arg len entry r2 -- )
23     msr@ 2000 or ciregs >srr1 !
24     ciregs >r2  !
25     call-client \ entry point is pointer to .opd
26 ;
27
28 : set-bootpath
29    s" disk" find-alias
30    dup IF ELSE drop s" boot-device" evaluate find-alias THEN
31    dup IF strdup ELSE 0 THEN
32    encode-string s" bootpath" set-chosen
33 ;
34
35 : set-netbootpath
36    s" net" find-alias
37    ?dup IF strdup encode-string s" bootpath" set-chosen THEN
38 ;
39
40 : set-bootargs
41    skipws 0 parse dup 0= IF
42       2drop s" boot-file" evaluate
43    THEN
44    encode-string s" bootargs" set-chosen
45 ;
46
47 : .(client-exec) ( arg len -- rc )
48    s" snk" romfs-lookup 0<> IF
49       \ Load SNK client 15 MiB after Paflof... FIXME: Hard-coded offset is ugly!
50       paflof-start f00000 +
51       elf-load-file-to-addr drop \ FIXME - check this for LE, currently its BE only
52       dup @ swap 8 + @         \ populate entry r2
53       start-elf64 client-data
54    ELSE
55       2drop false
56    THEN
57 ;
58 ' .(client-exec) to (client-exec)
59
60 : .client-exec ( arg len -- rc ) set-bootargs (client-exec) ;
61 ' .client-exec to client-exec
62
63 : netflash ( -- rc ) s" netflash 2000000 " (parse-line) $cat set-netbootpath
64    client-exec
65 ;
66
67 : netsave  ( "addr len {filename}[,params]" -- rc )
68    (parse-line) dup 0> IF
69       s" netsave " 2swap $cat set-netbootpath client-exec
70    ELSE
71       cr
72       ." Usage: netsave addr len [bootp|dhcp,]filename[,siaddr][,ciaddr][,giaddr][,bootp-retries][,tftp-retries][,use_ci]"
73       cr 2drop
74    THEN
75 ;
76
77 : ping  ( "{device-path:[device-args,]server-ip,[client-ip],[gateway-ip][,timeout]}" -- )
78    my-self >r current-node @ >r  \ Save my-self
79    (parse-line) open-dev dup  IF
80       dup to my-self dup ihandle>phandle set-node
81       dup
82       s" ping" rot ['] $call-method CATCH  IF
83          cr
84          ." Not a pingable device"
85          cr 3drop
86       THEN
87       swap close-dev
88    ELSE
89       cr
90       ." Usage: ping device-path:[device-args,]server-ip,[client-ip],[gateway-ip][,timeout]"
91       cr drop
92    THEN
93    r> set-node r> to my-self  \ Restore my-self
94 ;