Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / netinet / netload.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: netload.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)netload.fth 1.2 06/01/06
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
45copyright: Use is subject to license terms.
46
47headerless
48
49\ Frequently used strings in arg processing & property creation (space savings)
50: "net-config-strategy" ( -- $ ) " net-config-strategy" ;
51: "network-boot-file" ( -- $ ) " network-boot-file" ;
52: "host-ip" ( -- $ ) " host-ip" ;
53: "router-ip" ( -- $ ) " router-ip" ;
54: "subnet-mask" ( -- $ ) " subnet-mask" ;
55: "hostname" ( -- $ ) " hostname" ;
56: "http-proxy" ( -- $ ) " http-proxy" ;
57: "tftp-server" ( -- $ ) " tftp-server" ;
58: "client-id" ( -- $ ) " client-id" ;
59: "dhcp-retries" ( -- $ ) " dhcp-retries" ;
60: "tftp-retries" ( -- $ ) " tftp-retries" ;
61
62fload ${BP}/pkg/netinet/args.fth \ Argument processing
63fload ${BP}/pkg/netinet/props.fth \ Interface to client programs
64
65headerless
66
67: default-config-strategy$ ( -- $ ) " rarp" ;
68
69: init-config-parameters ( -- )
70 inaddr-any my-ip-addr copy-ip-addr
71 inaddr-any my-netmask copy-ip-addr
72 inaddr-any router-ip copy-ip-addr
73 inaddr-any tftp-server-ip copy-ip-addr
74
75 null$ bootfile pack drop
76 null$ hostname pack drop
77 null$ http-proxy pack drop
78 " /" " local-client-id" get-property client-id pack drop
79
80 default-config-strategy$ config-strategy pack drop
81;
82
83: default-boot-filename ( -- $ )
84 use-rarp? if ( )
85 my-ip-addr /ip-addr octet-to-hexascii ( $ )
86 else ( )
87 use-dhcp? if ( )
88 dhcp-classid count ( $ )
89 else ( )
90 null$ ( null$ )
91 then ( $ )
92 then ( $ )
93;
94
95: init-protocol-stack ( -- )
96 netif-init arp-init ip-init udp-init tcp-init
97;
98
99: close-protocol-stack ( -- )
100 tcp-close udp-close ip-close arp-close netif-close
101;
102
103: configure-protocol-stack ( -- )
104 ip-configure
105;
106
107: load-bootfile ( adr -- size )
108 bootfile count 2dup is-http-url? if ( adr url$ )
109 http-proxy count wanboot-load ( size )
110 else ( adr $ )
111 2dup is-tftp-uri? if ( adr tftpuri$ )
112 2dup tftpuri>srv tftp-server-ip inet-aton drop ( adr tftpuri$ )
113 tftpuri>file ( adr file$ )
114 then ( adr file$ )
115 dup 0= if ( adr null$ )
116 2drop default-boot-filename ( adr file$ )
117 then ( adr file$ )
118 tftp-server-ip tftp-load ( size )
119 then ( size )
120;
121
122\ Perform validity checks on configuration parameters before proceeding
123\ to download the file. If using DHCP and TFTP, the TFTP server must
124\ be known.
125
126: check-netconfig-params ( -- )
127 use-dhcp? bootfile count is-uri? 0= and if
128 tftp-server-ip inaddr-any? if
129 ." TFTP server not specified" -1 throw
130 then
131 then
132;
133
134external
135
136: open ( -- ok? )
137 init-protocol-stack
138 init-config-parameters
139 my-args ['] process-args catch if
140 2drop close-protocol-stack false
141 else
142 true
143 then
144;
145
146: close ( -- ) close-protocol-stack ;
147
148: load ( adr -- size )
149 publish-network-boot-props ( adr )
150 use-rarp? if ( adr )
151 my-ip-addr inaddr-any? if do-rarp then ( adr )
152 else ( adr )
153 use-dhcp? if do-dhcp then ( adr )
154 then ( adr )
155 check-netconfig-params ( adr )
156 configure-protocol-stack ( adr )
157 load-bootfile ( size )
158;
159
160headers