Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / ide / atapi / cdrom.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: cdrom.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: @(#)cdrom.fth 1.10 06/07/14
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
45copyright: Use is subject to license terms.
46
47headerless
48
49" cdrom" name
50" block" device-type
51
52fload ${BP}/dev/ide/atapi/misc.fth
53
54hex
550 instance value offset-low
560 instance value offset-high
570 instance value label-package
580 instance value blocksize
59
60: init-label-package ( -- okay? )
61 0 is offset-high 0 is offset-low
62 my-args " disk-label" $open-package is label-package
63 label-package if
64 0 0 " offset" label-package $call-method is offset-high is offset-low
65 true
66 else
67 ." Can't open disk label package" cr false
68 then
69;
70
710 instance value deblocker
72: init-deblocker ( -- okay? )
73 " " " deblocker" $open-package is deblocker
74 deblocker if
75 true
76 else
77 ." Can't open deblocker package" cr false
78 then
79;
80
81: .bail? ( flag -- ) 0= if r> drop false then ;
82
83: set-block-size ( n -- )
84 dup is blocksize
85 " disk-block-size" $call-parent
86;
87
88external
89
90: dma-alloc ( #bytes -- vaddr ) " dma-alloc" $call-parent ;
91: dma-free ( vaddr #bytes -- ) " dma-free" $call-parent ;
92
93: block-size ( -- n ) blocksize ;
94: max-transfer ( -- n ) blocksize h# 20 * ;
95
96\
97\ this routine expects to never be called with #blocks > 256
98\ (ie zero into the sector count reg)
99\
100headers
101: atapi-r/w-blocks ( adr block# #blocks read? -- #blocks )
102 if h# a8 else h# aa then ( adr block# #blocks cmd )
103 atapi-cmd >r ( adr block# #blocks )
104 r@ erase-cdb ( adr block# #blocks )
105 r@ c! ( adr block# #blocks )
106 r@ 6 + long>cdb ( adr block# )
107 r@ 2 + long>cdb ( adr )
108 r> d# 30.000 ( adr cdb timeout )
109 atapi-pkt set-pkt-data ( pkt )
110 run-atapi if ( -- )
111 0 ( 0 )
112 else ( -- )
113 atapi-pkt >transfer-bytes l@ ( bytes )
114 blocksize / ( #blocks )
115 then ( #blocks )
116;
117
118external
119
120: read-blocks ( adr block# #blocks -- #rd ) true atapi-r/w-blocks ;
121: write-blocks ( adr block# #blocks -- #wr ) false atapi-r/w-blocks ;
122
123: open ( -- flag )
124 my-unit ( lun target )
125 dup 8 >> ?dup if ( lun target port# )
126 " set-port" $call-parent .bail? ( lun target )
127 3 and ( lun target )
128 then
129 dup rot ( target target lun )
130 " set-address" $call-parent .bail? ( target )
131 h# 800 set-block-size ( target )
132 " device-present?" $call-parent .bail? ( -- )
133 init-deblocker .bail? ( -- )
134 init-label-package .bail? ( -- )
135 true ( true )
136;
137
138: seek ( offset.low offset.high -- okay? )
139 offset-low offset-high d+ " seek" deblocker $call-method
140;
141: read ( adr len -- actual-len ) " read" deblocker $call-method ;
142: write ( adr len -- actual-len ) " write" deblocker $call-method ;
143
144: load ( adr -- size ) " load" label-package $call-method ;
145
146: close ( -- )
147 label-package close-package 0 is label-package
148 deblocker close-package 0 is deblocker
149;
150