diff options
Diffstat (limited to 'lib/Language/Elna/PrinterWriter.hs')
| -rw-r--r-- | lib/Language/Elna/PrinterWriter.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Language/Elna/PrinterWriter.hs b/lib/Language/Elna/PrinterWriter.hs index ff8b9aa..ed5cbf0 100644 --- a/lib/Language/Elna/PrinterWriter.hs +++ b/lib/Language/Elna/PrinterWriter.hs @@ -44,11 +44,12 @@ import qualified Language.Elna.Architecture.RiscV as RiscV import qualified Data.Text.Encoding as Text.Encoding import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.State (get) +import Language.Elna.CodeGenerator (Asm(..)) data UnresolvedRelocation = UnresolvedRelocation ByteString Elf32_Addr Word8 data UnresolvedRelocations = UnresolvedRelocations (Vector UnresolvedRelocation) Elf32_Word -riscv32Elf :: Vector RiscV.Instruction -> Handle -> ElfWriter Elf32_Ehdr +riscv32Elf :: Vector Asm -> Handle -> ElfWriter Elf32_Ehdr riscv32Elf code objectHandle = text >>= uncurry symrel >>= strtab @@ -197,7 +198,7 @@ riscv32Elf code objectHandle = text pure (symbolResult, UnresolvedRelocations relocations $ fromIntegral $ Vector.length sectionHeaders) symbolEntry :: Elf32_Half - -> Vector RiscV.Instruction + -> Vector Asm -> (ElfHeaderResult Elf32_Sym, Elf32_Addr, Vector UnresolvedRelocation) -> ElfWriter (ElfHeaderResult Elf32_Sym, Elf32_Addr, Vector UnresolvedRelocation) symbolEntry shndx instructions (ElfHeaderResult names entries, offset, relocations) = do @@ -216,14 +217,14 @@ riscv32Elf code objectHandle = text , st_size = 0 , st_shndx = 0 , st_other = 0 - , st_name = fromIntegral (ByteString.length names) + 7 + , st_name = fromIntegral (ByteString.length names) + 5 , st_info = stInfo STB_GLOBAL STT_FUNC } liftIO $ ByteString.hPut objectHandle $ LazyByteString.toStrict encoded - let newResult = ElfHeaderResult (names <> "_start\0printi\0") + let newResult = ElfHeaderResult (names <> "main\0printi\0") $ Vector.snoc (Vector.snoc entries newEntry) printEntry pure (newResult, size, updatedRelocations) - encodeInstruction (instructions, offset, relocations) instruction = + encodeInstruction (instructions, offset, relocations) (Instruction instruction) = let unresolvedRelocation = case instruction of RiscV.RelocatableInstruction _ instructionType | RiscV.Higher20 _ symbolName <- instructionType @@ -238,7 +239,7 @@ riscv32Elf code objectHandle = text RiscV.CallInstruction symbolName -> Just -- R_RISCV_CALL_PLT $ UnresolvedRelocation (Text.Encoding.encodeUtf8 symbolName) offset 19 - RiscV.Instruction _ _ -> Nothing + RiscV.BaseInstruction _ _ -> Nothing encoded = ByteString.Builder.toLazyByteString $ RiscV.instruction instruction in @@ -246,3 +247,4 @@ riscv32Elf code objectHandle = text , offset + fromIntegral (LazyByteString.length encoded) , maybe relocations (Vector.snoc relocations) unresolvedRelocation ) + encodeInstruction accumulator (JumpLabel _ _) = accumulator |
