Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun / idprom.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: idprom.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: @(#)idprom.fth 2.19 06/07/13
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47headerless
48
49h# 20 constant /idprom
50/idprom buffer: idprom-buf
51
52[ifndef] SUN4V
530 value idprom-phandle
54
55also magic-device-types definitions
56headers
57
58: idprom ( xdr,len prop$ -- )
59 idprom-phandle if exit then
60 my-self ihandle>phandle to idprom-phandle
61;
62
63previous definitions
64[then]
65
66headerless
67: idprom@ ( -- byte ) idprom-buf + c@ ;
68: idprom-checksum ( -- n )
69 0 d# 15 0 do i idprom@ xor loop
70;
71
72\ Verifying ID PROM format and checksum is sufficient
73\ to validate ID PROM structure
74: (idprom-valid? ( -- flag )
75 0 idprom@ 1 = \ Verify the ID PROM format
76 idprom-checksum d# 15 idprom@ = and \ Verify the checksum
77;
78' (idprom-valid? is idprom-valid?
79
80: .idbytes ( offset count -- ) bounds do i idprom@ .h loop ;
81
82: hostid ( -- n )
83 d# 14 idprom@ ( b.lo )
84 d# 13 idprom@ ( b.mlo )
85 d# 12 idprom@ ( b.mhi )
86 1 idprom@ ( b.hi )
87 bljoin ( n )
88;
89
90: (serial# ( -- n ) hostid 1 d# 31 lshift invert and ;
91' (serial# is serial#
92
93: (system-mac-address ( -- adr len ) idprom-buf 2+ 6 ;
94' (system-mac-address is system-mac-address
95
96headers
97: .idprom ( -- )
98 ." Format/Type: " 0 2 .idbytes
99 ." Ethernet: " 2 6 .idbytes
100 ." Date: " 8 4 .idbytes
101 cr
102 ." Serial: " d# 12 3 .idbytes
103 ." Checksum: " d# 15 1 .idbytes
104\ ." Reserved: " d# 16 d# 16 .idbytes
105;
106
107[ifdef] SUN4V
108: idprom! ( d n -- ) idprom-buf + c! ;
109
110: init-idprom ( -- )
111 idprom-buf /idprom erase
112 h# 01 0 idprom!
113 0 " platform" md-find-node ( node )
114 dup " hostid" ascii v md-find-prop ?dup if ( node prop )
115 md-decode-prop drop ( node n )
116 lbsplit
117 1 idprom! 3 0 do d# 12 i + idprom! loop ( node )
118 then ( )
119 " mac-address" ascii v md-find-prop ?dup if ( prop )
120 md-decode-prop drop ( n )
121 6 0 do dup 7 i - idprom! 8 >> loop drop ( )
122 then ( )
123 idprom-checksum d# 15 idprom! ( )
124 root-device
125 idprom-buf /idprom encode-bytes " idprom" property
126 device-end
127;
128[else]
129: init-idprom ( -- )
130 idprom-phandle ?dup 0= abort" No IDPROM"r"n"
131 phandle>devname open-dev ?dup if
132 >r
133 idprom-buf /idprom " read" r@ $call-method drop
134 r> close-dev
135 root-device
136 idprom-buf /idprom encode-bytes " idprom" property
137 device-end
138 else
139 ." IDPROM device didn't open" cr
140 then
141;
142[then]
143
144stand-init: Setting IDPROM property
145 ['] init-idprom catch drop
146;