| 1 | # ========== Copyright Header Begin ========================================== |
| 2 | # |
| 3 | # OpenSPARC T2 Processor File: Pfe_Io.py |
| 4 | # Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 6 | # |
| 7 | # The above named program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public |
| 9 | # License version 2 as published by the Free Software Foundation. |
| 10 | # |
| 11 | # The above named program is distributed in the hope that it will be |
| 12 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | # General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public |
| 17 | # License along with this work; if not, write to the Free Software |
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | # |
| 20 | # ========== Copyright Header End ============================================ |
| 21 | |
| 22 | from Pfe_Conversion import * |
| 23 | |
| 24 | #---------------------------------------------------------------------------- |
| 25 | # Io is the wrapper that provides the hooks to all the ways to access |
| 26 | # io: 1,2,4,8 bytes, int or double, or little endian ... |
| 27 | #---------------------------------------------------------------------------- |
| 28 | |
| 29 | class Io: |
| 30 | """ |
| 31 | Io io |
| 32 | """ |
| 33 | def __init__(self): |
| 34 | self.b = IoInterface(self,self.__ldb__, self.__stb__,1) |
| 35 | self.h = IoInterface(self,self.__ldh__, self.__sth__,2) |
| 36 | self.w = IoInterface(self,self.__ldw__, self.__stw__,4) |
| 37 | self.x = IoInterface(self,self.__ldx__ , self.__stx__,8) |
| 38 | self.f = IoInterface(self,self.__ldf__, self.__stf__,4) |
| 39 | self.d = IoInterface(self,self.__ldd__, self.__std__,8) |
| 40 | self.c = IoInterface(self,self.__ldc__, self.__stc__,1) |
| 41 | self.cl = self.c # ha, simply for completeness |
| 42 | self.bl = self.b # ha, simply for completeness |
| 43 | self.hl = IoInterface(self,self.__ldhl__, self.__sthl__,2) |
| 44 | self.wl = IoInterface(self,self.__ldwl__, self.__stwl__,4) |
| 45 | self.xl = IoInterface(self,self.__ldxl__, self.__stxl__,8) |
| 46 | self.fl = IoInterface(self,self.__ldfl__, self.__stfl__,4) |
| 47 | self.dl = IoInterface(self,self.__lddl__, self.__stdl__,8) |
| 48 | |
| 49 | |
| 50 | # __ldb__(), __ldh__(), __ldw__(), and __ldx__() implement 1, 2, 4 and |
| 51 | # 8 byte load operations. They need to be provided by the implementation. |
| 52 | |
| 53 | def __ldb__(self,sid,addr): pass |
| 54 | def __ldh__(self,sid,addr): pass |
| 55 | def __ldw__(self,sid,addr): pass |
| 56 | def __ldx__(self,sid,addr): pass |
| 57 | |
| 58 | # __stb__(), __sth__(), __stw__(), and __stx__() implement 1, 2, 4 and |
| 59 | # 8 byte store operations. They need to be provided by the implementation. |
| 60 | |
| 61 | def __stb__(self,sid,addr,data): pass |
| 62 | def __sth__(self,sid,addr,data): pass |
| 63 | def __stw__(self,sid,addr,data): pass |
| 64 | def __stx__(self,sid,addr,data): pass |
| 65 | |
| 66 | def __ldc__( self,sid,addr): return chr(self.__ldb__(sid,addr)) |
| 67 | def __ldf__( self,sid,addr): return w2f(self.__ldw__(sid,addr)) |
| 68 | def __ldd__( self,sid,addr): return x2d(long(self.__ldx__(sid,addr))) |
| 69 | def __ldhl__(self,sid,addr): return h2h(self.__ldh__(sid,addr)) |
| 70 | def __ldwl__(self,sid,addr): return w2w(self.__ldw__(sid,addr)) |
| 71 | def __ldxl__(self,sid,addr): return x2x(long(self.__ldx__(sid,addr))) |
| 72 | def __ldfl__(self,sid,addr): return w2f(self.__ldwl__(sid,addr)) |
| 73 | def __lddl__(self,sid,addr): return x2d(self.__ldxl__(sid,addr)) |
| 74 | |
| 75 | def __stc__( self,sid,addr,data): self.__stb__(sid,addr,ord(data)) |
| 76 | def __stf__( self,sid,addr,data): self.__stw__(sid,addr,f2w(data)) |
| 77 | def __std__( self,sid,addr,data): self.__stx__(sid,addr,d2x(data)) |
| 78 | def __sthl__(self,sid,addr,data): self.__sth__(sid,addr,h2h(data)) |
| 79 | def __stwl__(self,sid,addr,data): self.__stw__(sid,addr,w2w(data)) |
| 80 | def __stxl__(self,sid,addr,data): self.__stx__(sid,addr,x2x(long(data))) |
| 81 | def __stfl__(self,sid,addr,data): self.__stwl__(sid,addr,f2w(data)) |
| 82 | def __stdl__(self,sid,addr,data): self.__stxl__(sid,addr,d2x(data)) |
| 83 | |
| 84 | |
| 85 | #---------------------------------------------------------------------------- |
| 86 | # IoInterface implements the actual index operator for |
| 87 | # the various io sizes, expliting pythons slicing operator |
| 88 | #---------------------------------------------------------------------------- |
| 89 | |
| 90 | class IoInterface: |
| 91 | def __init__(self,io,load,store,size): |
| 92 | self.__io__ = io |
| 93 | self.__ld__ = load |
| 94 | self.__st__ = store |
| 95 | self.__size__ = size |
| 96 | |
| 97 | def slice_step(self,__slice__,step): |
| 98 | if __slice__.step == None: |
| 99 | return step |
| 100 | else: |
| 101 | return __slice__.step |
| 102 | |
| 103 | def __len__(self): |
| 104 | return long(1 << 55) |
| 105 | |
| 106 | def __getitem__(self,address): |
| 107 | if type(address) == slice: |
| 108 | m = [] |
| 109 | a = address.start |
| 110 | s = self.slice_step(address,self.__size__) |
| 111 | while a < address.stop: |
| 112 | m.append(self.__ld__(0,a)) |
| 113 | a += s |
| 114 | return m |
| 115 | else: |
| 116 | return self.__ld__(0,address) |
| 117 | |
| 118 | def __setitem__(self,address,value): |
| 119 | if type(address) == slice: |
| 120 | a = address.start |
| 121 | s = self.slice_step(address,self.__size__) |
| 122 | i = 0 |
| 123 | while a < address.stop and i < len(value): |
| 124 | self.__st__(0,a,value[i]) |
| 125 | a += s |
| 126 | i += 1 |
| 127 | else: |
| 128 | self.__st__(0,address,value) |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |