2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[SparcDesc]{The Sparc Machine Description}
7 #include "HsVersions.h"
12 -- and assorted nonsense referenced by the class methods
14 PprStyle, SMRep, MagicId, RegLoc, StixTree, PrimKind, SwitchResult
19 import AbsPrel ( PrimOp(..)
20 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
21 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
23 import AsmRegAlloc ( Reg, MachineCode(..), MachineRegisters(..),
24 RegLiveness(..), RegUsage(..), FutureLive(..)
26 import CLabelInfo ( CLabel )
27 import CmdLineOpts ( GlobalSwitch(..), stringSwitchSet, switchIsOn, SwitchResult(..) )
28 import HeapOffs ( hpRelToInt )
30 import Maybes ( Maybe(..) )
33 import PrimKind ( PrimKind(..) )
34 import SMRep ( SMRep(..), SMSpecRepKind(..), SMUpdateKind(..) )
36 import SparcGen ( sparcCodeGen )
46 Header sizes depend only on command-line options, not on the target
47 architecture. (I think.)
51 fhs :: (GlobalSwitch -> SwitchResult) -> Int
53 fhs switches = 1 + profFHS + ageFHS
55 profFHS = if switchIsOn switches SccProfilingOn then 1 else 0
56 ageFHS = if switchIsOn switches SccProfilingOn then 1 else 0
58 vhs :: (GlobalSwitch -> SwitchResult) -> SMRep -> Int
60 vhs switches sm = case sm of
62 SpecialisedRep _ _ _ _ -> 0
65 MuTupleRep _ -> 2 {- (1 + GC_MUT_RESERVED_WORDS) -}
69 PhantomRep -> panic "vhs:phantom"
73 Here we map STG registers onto appropriate Stix Trees. First, we
74 handle the two constants, @STK_STUB_closure@ and @vtbl_StdUpdFrame@.
75 The rest are either in real machine registers or stored as offsets
80 sparcReg :: (GlobalSwitch -> SwitchResult) -> MagicId -> RegLoc
84 Just reg -> Save nonReg
85 Nothing -> Always nonReg
86 where nonReg = case x of
87 StkStubReg -> sStLitLbl SLIT("STK_STUB_closure")
88 StdUpdRetVecReg -> sStLitLbl SLIT("vtbl_StdUpdFrame")
89 BaseReg -> sStLitLbl SLIT("MainRegTable")
90 Hp -> StInd PtrKind (sStLitLbl SLIT("StorageMgrInfo"))
91 HpLim -> StInd PtrKind (sStLitLbl SLIT("StorageMgrInfo+4"))
92 TagReg -> StInd IntKind (StPrim IntSubOp [infoptr, StInt (1*4)])
94 r2 = VanillaReg PtrKind ILIT(2)
95 infoptr = case sparcReg switches r2 of
97 Save _ -> StReg (StixMagicId r2)
98 _ -> StInd (kindFromMagicId x)
99 (StPrim IntAddOp [baseLoc, StInt (toInteger (offset*4))])
100 baseLoc = case stgRegMap BaseReg of
101 Just _ -> StReg (StixMagicId BaseReg)
102 Nothing -> sStLitLbl SLIT("MainRegTable")
103 offset = baseRegOffset x
111 size pk = case kindToSize pk of
112 {SB -> 1; UB -> 1; HW -> 2; UHW -> 2; W -> 4; D -> 8; F -> 4; DF -> 8}
116 Now the volatile saves and restores. We add the basic guys to the list of ``user''
117 registers provided. Note that there are more basic registers on the restore list,
118 because some are reloaded from constants.
122 vsaves switches vols =
123 map save ((filter callerSaves) ([BaseReg,SpA,SuA,SpB,SuB,Hp,HpLim,RetReg,ActivityReg] ++ vols))
125 save x = StAssign (kindFromMagicId x) loc reg
126 where reg = StReg (StixMagicId x)
127 loc = case sparcReg switches x of
129 Always loc -> panic "vsaves"
131 vrests switches vols =
132 map restore ((filter callerSaves)
133 ([BaseReg,SpA,SuA,SpB,SuB,Hp,HpLim,RetReg,ActivityReg,StkStubReg,StdUpdRetVecReg] ++ vols))
135 restore x = StAssign (kindFromMagicId x) reg loc
136 where reg = StReg (StixMagicId x)
137 loc = case sparcReg switches x of
139 Always loc -> panic "vrests"
143 Static closure sizes.
147 charLikeSize, intLikeSize :: Target -> Int
149 charLikeSize target =
150 size PtrKind * (fixedHeaderSize target + varHeaderSize target charLikeRep + 1)
151 where charLikeRep = SpecialisedRep CharLikeRep 0 1 SMNormalForm
154 size PtrKind * (fixedHeaderSize target + varHeaderSize target intLikeRep + 1)
155 where intLikeRep = SpecialisedRep IntLikeRep 0 1 SMNormalForm
157 mhs, dhs :: (GlobalSwitch -> SwitchResult) -> StixTree
159 mhs switches = StInt (toInteger words)
161 words = fhs switches + vhs switches (MuTupleRep 0)
163 dhs switches = StInt (toInteger words)
165 words = fhs switches + vhs switches (DataRep 0)
169 Setting up a sparc target.
173 mkSparc :: Bool -> (GlobalSwitch -> SwitchResult) -> Target
175 mkSparc decentOS switches =
176 let fhs' = fhs switches
178 sparcReg' = sparcReg switches
179 vsaves' = vsaves switches
180 vrests' = vrests switches
181 hprel = hpRelToInt target
182 as = amodeCode target
183 as' = amodeCode' target
184 csz = charLikeSize target
185 isz = intLikeSize target
188 ps = genPrimCode target
189 mc = genMacroCode target
190 hc = doHeapCheck target
191 target = mkTarget switches fhs' vhs' sparcReg' id size vsaves' vrests'
192 hprel as as' csz isz mhs' dhs' ps mc hc
193 sparcCodeGen decentOS id