Create empty relocations section
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
module Language.Elna.Architecture.RiscV
|
||||
( BaseOpcode(..)
|
||||
, RelocationType(..)
|
||||
, Funct3(..)
|
||||
, Funct7(..)
|
||||
, Funct12(..)
|
||||
@ -15,6 +16,7 @@ module Language.Elna.Architecture.RiscV
|
||||
|
||||
import qualified Data.ByteString.Builder as ByteString.Builder
|
||||
import Data.Bits (Bits(..))
|
||||
import Data.Text (Text)
|
||||
import Data.Word (Word8, Word32)
|
||||
|
||||
data XRegister
|
||||
@ -137,8 +139,18 @@ data Type
|
||||
| U XRegister Word32
|
||||
| J XRegister Word32
|
||||
| Type XRegister Funct3 XRegister Funct12 -- Privileged.
|
||||
deriving Eq
|
||||
|
||||
data Instruction = Instruction BaseOpcode Type
|
||||
data RelocationType
|
||||
= Lower12I XRegister Funct3 XRegister Text
|
||||
| Lower12S Text Funct3 XRegister XRegister
|
||||
| Higher20 XRegister Text -- Type U.
|
||||
deriving Eq
|
||||
|
||||
data Instruction
|
||||
= Instruction BaseOpcode Type
|
||||
| RelocatableInstruction BaseOpcode RelocationType
|
||||
deriving Eq
|
||||
|
||||
xRegister :: XRegister -> Word8
|
||||
xRegister Zero = 0
|
||||
@ -285,8 +297,17 @@ type' (Type rd funct3' rs1 funct12')
|
||||
.|. (fromIntegral (xRegister rs1) `shiftL` 15)
|
||||
.|. (fromIntegral (funct12 funct12') `shiftL` 20);
|
||||
|
||||
relocationType :: RelocationType -> Word32
|
||||
relocationType (Lower12I rd funct3' rs1 _) = type' $ I rd funct3' rs1 0
|
||||
relocationType (Lower12S _ funct3' rs1 rs2) = type' $ S 0 funct3' rs1 rs2
|
||||
relocationType (Higher20 rd _) = type' $ U rd 0
|
||||
|
||||
instruction :: Instruction -> ByteString.Builder.Builder
|
||||
instruction (Instruction base instructionType)
|
||||
= ByteString.Builder.word32LE
|
||||
$ fromIntegral (baseOpcode base)
|
||||
.|. type' instructionType
|
||||
instruction = \case
|
||||
(Instruction base instructionType) -> go base $ type' instructionType
|
||||
(RelocatableInstruction base instructionType) -> go base $ relocationType instructionType
|
||||
where
|
||||
go base instructionType
|
||||
= ByteString.Builder.word32LE
|
||||
$ fromIntegral (baseOpcode base)
|
||||
.|. instructionType
|
||||
|
Reference in New Issue
Block a user