2 % (c) The AQUA Project, Glasgow University, 1994-1995
4 \section[I386Desc]{The I386 Machine Description}
7 #include "HsVersions.h"
12 -- and assorted nonsense referenced by the class methods
16 import PrelInfo ( PrimOp(..)
17 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
18 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
20 import AsmRegAlloc ( Reg, MachineCode(..), MachineRegisters(..),
21 RegLiveness(..), RegUsage(..), FutureLive(..)
23 import CLabel ( CLabel )
24 import CmdLineOpts ( GlobalSwitch(..), stringSwitchSet, switchIsOn, SwitchResult(..) )
25 import HeapOffs ( hpRelToInt )
27 import Maybes ( Maybe(..) )
30 import SMRep ( SMRep(..), SMSpecRepKind(..), SMUpdateKind(..) )
32 import I386Gen ( i386CodeGen )
40 Header sizes depend only on command-line options, not on the target
41 architecture. (I think.)
45 fhs :: (GlobalSwitch -> SwitchResult) -> Int
47 fhs switches = 1 + profFHS + ageFHS
49 profFHS = if switchIsOn switches SccProfilingOn then 1 else 0
50 ageFHS = if switchIsOn switches SccProfilingOn then 1 else 0
52 vhs :: (GlobalSwitch -> SwitchResult) -> SMRep -> Int
54 vhs switches sm = case sm of
56 SpecialisedRep _ _ _ _ -> 0
59 MuTupleRep _ -> 2 {- (1 + GC_MUT_RESERVED_WORDS) -}
63 PhantomRep -> panic "vhs:phantom"
67 Here we map STG registers onto appropriate Stix Trees. First, we
68 handle the two constants, @STK_STUB_closure@ and @vtbl_StdUpdFrame@.
69 The rest are either in real machine registers or stored as offsets
74 i386Reg :: (GlobalSwitch -> SwitchResult) -> MagicId -> RegLoc
78 Just reg -> Save nonReg
79 Nothing -> Always nonReg
80 where nonReg = case x of
81 StkStubReg -> sStLitLbl SLIT("STK_STUB_closure")
82 StdUpdRetVecReg -> sStLitLbl SLIT("vtbl_StdUpdFrame")
83 BaseReg -> sStLitLbl SLIT("MainRegTable")
84 --Hp -> StInd PtrRep (sStLitLbl SLIT("StorageMgrInfo"))
85 --HpLim -> StInd PtrRep (sStLitLbl SLIT("StorageMgrInfo+4"))
86 TagReg -> StInd IntRep (StPrim IntSubOp [infoptr, StInt (1*4)])
88 r2 = VanillaReg PtrRep ILIT(2)
89 infoptr = case i386Reg switches r2 of
91 Save _ -> StReg (StixMagicId r2)
92 _ -> StInd (kindFromMagicId x)
93 (StPrim IntAddOp [baseLoc, StInt (toInteger (offset*4))])
94 baseLoc = case stgRegMap BaseReg of
95 Just _ -> StReg (StixMagicId BaseReg)
96 Nothing -> sStLitLbl SLIT("MainRegTable")
97 offset = baseRegOffset x
105 size pk = case kindToSize pk of
106 {B -> 1; S -> 2; L -> 4; F -> 4; D -> 8 }
110 Now the volatile saves and restores. We add the basic guys to the list of ``user''
111 registers provided. Note that there are more basic registers on the restore list,
112 because some are reloaded from constants.
116 vsaves switches vols =
117 map save ((filter callerSaves) ([BaseReg,SpA,SuA,SpB,SuB,Hp,HpLim,RetReg{-,ActivityReg-}] ++ vols))
119 save x = StAssign (kindFromMagicId x) loc reg
120 where reg = StReg (StixMagicId x)
121 loc = case i386Reg switches x of
123 Always loc -> panic "vsaves"
125 vrests switches vols =
126 map restore ((filter callerSaves)
127 ([BaseReg,SpA,SuA,SpB,SuB,Hp,HpLim,RetReg{-,ActivityReg-},StkStubReg,StdUpdRetVecReg] ++ vols))
129 restore x = StAssign (kindFromMagicId x) reg loc
130 where reg = StReg (StixMagicId x)
131 loc = case i386Reg switches x of
133 Always loc -> panic "vrests"
137 Static closure sizes.
141 charLikeSize, intLikeSize :: Target -> Int
143 charLikeSize target =
144 size PtrRep * (fixedHeaderSize target + varHeaderSize target charLikeRep + 1)
145 where charLikeRep = SpecialisedRep CharLikeRep 0 1 SMNormalForm
148 size PtrRep * (fixedHeaderSize target + varHeaderSize target intLikeRep + 1)
149 where intLikeRep = SpecialisedRep IntLikeRep 0 1 SMNormalForm
151 mhs, dhs :: (GlobalSwitch -> SwitchResult) -> StixTree
153 mhs switches = StInt (toInteger words)
155 words = fhs switches + vhs switches (MuTupleRep 0)
157 dhs switches = StInt (toInteger words)
159 words = fhs switches + vhs switches (DataRep 0)
163 Setting up a i386 target.
167 -> (GlobalSwitch -> SwitchResult)
169 (PprStyle -> [[StixTree]] -> UniqSM Unpretty), -- codeGen
171 (String -> String)) -- fmtAsmLbl
173 mkI386 decentOS switches =
174 let fhs' = fhs switches
176 i386Reg' = i386Reg switches
177 vsaves' = vsaves switches
178 vrests' = vrests switches
179 hprel = hpRelToInt target
180 as = amodeCode target
181 as' = amodeCode' target
182 csz = charLikeSize target
183 isz = intLikeSize target
186 ps = genPrimCode target
187 mc = genMacroCode target
189 target = mkTarget {-switches-} fhs' vhs' i386Reg' {-id-} size
191 (vsaves', vrests', csz, isz, mhs', dhs', ps, mc, hc)
192 {-i386CodeGen decentOS id-}
194 (target, i386CodeGen, decentOS, id)