Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / decompressor / sparc / decomp.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: decomp.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: @(#)decomp.fth 1.2 01/04/06
43purpose:
44copyright: Copyright 1997-2001 Sun Microsystems, Inc. All Rights Reserved
45
46headerless
47
48\ In:
49\ scr = decomp data ptr
50\ sc1 = src addr
51\ sc2 = #bytes remaining
52\ Out:
53\ tos = byte|-1
54\
55label decomp-getabyte
56 scr 0 >source-addr sc1 ld \ scr = src addr
57 scr 0 >source-size sc2 ld \ sc1 = #bytes left
58 sc2 1 sc2 subcc
59 0>= if
60 %g0 -1 tos add \ (delay)
61 sc1 %g0 tos ldub \ get data
62 sc1 1 sc1 add
63 sc1 scr 0 >source-addr st \ update src pointer
64 then
65 retl
66 sc2 scr 0 >source-size st \ update #bytes left (delay)
67end-code
68
69\
70\ Forth Version of assembler routine
71\
72code decomp-getbyte ( data-buffer -- byte|-1 )
73 decomp-getabyte call tos scr move
74c;
75
76code decomp-putbyte ( byte buffer -- )
77 tos sc1 move
78 sp scr pop
79 sp tos pop
80 sc1 0 >dest-addr sc2 ld \ get dest address
81 scr sc2 %g0 stb \ write data
82 sc2 1 sc2 add
83 sc2 sc1 0 >dest-addr st \ update ptr
84c;
85
86\ In:
87\ tos
88\ Scratch:
89\ scr, sc1, sc2 - by getabyte
90\ sc3, sc4, sc5 - by getcode
91\ Out:
92\ tos
93\
94code decomp-getcode ( bits buffer -- code )
95 tos scr move \ preserve buffer ptr
96 sp sc3 pop
97 scr 0 >getcode-offset sc4 ld \ get previous offset
98 scr 0 >getcode-oldcode sc5 ld \ get previous code
99
100\ Watch the 'if' trick coming up.
101
102 begin
103 decomp-getabyte call nop
104 tos -1 %g0 subcc
105 <> if but
106 tos sc4 sc1 sll \ (byte << r_off) (delay)
107 sc4 8 sc4 add \ r_off += 8
108 sc4 sc3 cmp
109 >= until
110 sc5 sc1 sc5 add \ code += (byte << r_off) (delay)
111
112 sc5 sc3 sc1 srl \ (code >> bits)
113 sc4 sc3 sc2 sub \ r_off - bits
114 sc1 scr 0 >getcode-oldcode st \ getcode_oldcode = (code >> bits)
115 sc2 scr 0 >getcode-offset st \ getcode_offset = (r_off - bits)
116
117 %g0 1 scr sub
118 scr sc3 scr sllx \ mask = (-1 << bits)
119 sc5 scr tos andn \ tos = tos & ~mask
120 then
121c;