-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A simple ARM emulator in haskell -- -- A simple ARM virtual machine designed for teaching assembly. See -- http:tinyurl.com/639v6u for details on internals and examples -- of how to use it. It is advised you look through the source on the -- site and try following along to really learn what's going on. -- Currently the emulator does not use standard ARM assembly, but a -- custom variant. This will hopefully be changed in the near future. -- -- Two programs, runarm and dbgarm, are provided which can be used to run -- and debug the assembly. @package HARM @version 0.1.4 module Arm.Format data Radix Dec :: Radix Hex :: Radix formatHex :: Int -> Char -> String -> Word32 -> String hexChars :: Array Word32 Char formatDec :: Int -> Char -> Word32 -> String instance Show Radix module Arm.Memory type Memory = IOArray Address Word32 type Address = Word32 type WordAddress = Address type ByteAddress = Address emptyMem :: Address -> IO Memory wordAddress :: ByteAddress -> WordAddress getMemWord :: Memory -> WordAddress -> IO Word32 setMemWord :: Memory -> WordAddress -> Word32 -> IO () readMem :: Memory -> Address -> IO Word32 writeMem :: Memory -> Address -> Word32 -> IO () module Arm.BinaryNumber data Binary32 intToBinary32 :: Int -> Binary32 binary32ToInt :: Binary32 -> Int binary32ToWord32 :: Binary32 -> Word32 word32ToBinary32 :: Word32 -> Binary32 instance Num Binary32 instance Coerce Binary32 instance Bits Binary32 instance Enum Binary32 instance Ix Binary32 instance Integral Binary32 instance Real Binary32 instance Bounded Binary32 instance Ord Binary32 instance Eq Binary32 instance Read Binary32 instance Show Binary32 module Arm.RegisterName data RegisterName R0 :: RegisterName R1 :: RegisterName R2 :: RegisterName R3 :: RegisterName R4 :: RegisterName R5 :: RegisterName R6 :: RegisterName R7 :: RegisterName R8 :: RegisterName R9 :: RegisterName R10 :: RegisterName R11 :: RegisterName R12 :: RegisterName R13 :: RegisterName R14 :: RegisterName R15 :: RegisterName CPSR :: RegisterName nthReg :: Word32 -> RegisterName instance Enum RegisterName instance Eq RegisterName instance Ix RegisterName instance Ord RegisterName instance Read RegisterName instance Show RegisterName module Arm.Register type Registers = IOArray RegisterName Word32 emptyRegs :: IO Registers getReg :: Registers -> RegisterName -> IO Word32 setReg :: Registers -> RegisterName -> Word32 -> IO () cpsrGet :: Int -> Registers -> IO Word32 cpsrSet :: Int -> Registers -> IO () module Arm.CPU data CPU CPU :: Memory -> Registers -> IORef Bool -> IORef Bool -> CPU memory :: CPU -> Memory registers :: CPU -> Registers running :: CPU -> IORef Bool debug :: CPU -> IORef Bool emptyCPU :: Address -> IO CPU module Arm.ParseLib data Parser a item :: Parser Char papply :: Parser a -> String -> [(a, String)] (+++) :: Parser a -> Parser a -> Parser a sat :: (Char -> Bool) -> Parser Char many :: Parser a -> Parser [a] many1 :: Parser a -> Parser [a] sepby :: Parser a -> Parser b -> Parser [a] sepby1 :: Parser a -> Parser b -> Parser [a] chainl :: Parser a -> Parser (a -> a -> a) -> a -> Parser a chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a chainr :: Parser a -> Parser (a -> a -> a) -> a -> Parser a chainr1 :: Parser a -> Parser (a -> a -> a) -> Parser a ops :: [(Parser a, b)] -> Parser b bracket :: Parser a -> Parser b -> Parser c -> Parser b char :: Char -> Parser Char digit :: Parser Char lower :: Parser Char upper :: Parser Char letter :: Parser Char alphanum :: Parser Char string :: String -> Parser String ident :: Parser String nat :: Parser Int int :: Parser Int spaces :: Parser () comment :: Parser () junk :: Parser () parse :: Parser a -> Parser a token :: Parser a -> Parser a natural :: Parser Int integer :: Parser Int symbol :: String -> Parser String identifier :: [String] -> Parser String instance MonadPlus Parser instance Monad Parser instance Functor Parser module Arm.Operand data Operand Aut :: Operand -> Operand Bas :: RegisterName -> Word32 -> Operand Con :: Word32 -> Operand Ind :: RegisterName -> Operand Mrg :: [RegisterName] -> Operand Pos :: Operand -> Word32 -> Operand Reg :: RegisterName -> Operand Rel :: Int -> Operand Lab :: String -> Operand instance Show Operand module Arm.Instruction data Instruction Add :: Operand -> Operand -> Operand -> Instruction And :: Operand -> Operand -> Operand -> Instruction B :: Operand -> Instruction Beq :: Operand -> Instruction Bgt :: Operand -> Instruction Bic :: Operand -> Operand -> Operand -> Instruction Bl :: Operand -> Instruction Blt :: Operand -> Instruction Bne :: Operand -> Instruction Cmp :: Operand -> Operand -> Instruction Eor :: Operand -> Operand -> Operand -> Instruction Ldmea :: Operand -> Operand -> Instruction Ldr :: Operand -> Operand -> Instruction Ldrb :: Operand -> Operand -> Instruction Mov :: Operand -> Operand -> Instruction Mul :: Operand -> Operand -> Operand -> Instruction Orr :: Operand -> Operand -> Operand -> Instruction Stmea :: Operand -> Operand -> Instruction Str :: Operand -> Operand -> Instruction Strb :: Operand -> Operand -> Instruction Sub :: Operand -> Operand -> Operand -> Instruction Swi :: Operand -> Instruction instance Show Instruction module Arm.Decoder decode :: Word32 -> Maybe Instruction module Arm.Encoder encode :: Instruction -> Word32 module Arm.Program data Constant Array :: Word32 -> Constant -> Constant Int :: Int -> Constant List :: [Constant] -> Constant String :: String -> Constant Word :: Word32 -> Constant constSize :: Constant -> Word32 data Program Program :: Address -> Address -> [(RegisterName, Word32)] -> [Instruction] -> [(Address, Constant)] -> Program memorySize :: Program -> Address origin :: Program -> Address regInit :: Program -> [(RegisterName, Word32)] instructions :: Program -> [Instruction] constants :: Program -> [(Address, Constant)] instance Show Program instance Show Constant module Arm.Parser type Symbol = String data ParseElement Data :: [Operand] -> [Constant] -> ParseElement Instruction :: Instruction -> ParseElement Symbol :: Symbol -> ParseElement Address :: Address -> ParseElement Origin :: Address -> ParseElement RegInit :: RegisterName -> Operand -> ParseElement Comment :: ParseElement Newline :: ParseElement pWord :: Parser Word32 pBinary :: Parser Word32 pAut :: Parser Operand pBas :: Parser Operand pCon :: Parser Operand pInd :: Parser Operand pPos :: Parser Operand pReg :: Parser Operand pOperand :: Parser Operand instance Show ParseElement module Arm.Loader loadProgram :: CPU -> Program -> IO () loadRegisters :: Registers -> [(RegisterName, Word32)] -> IO () loadInstructions :: Memory -> Address -> [Instruction] -> IO () loadConstants :: Memory -> [(Address, Constant)] -> IO () loadConstant :: Memory -> Address -> Constant -> IO () loadArray :: Memory -> Address -> Word32 -> Constant -> IO () loadList :: Memory -> Address -> [Constant] -> IO () loadString :: Memory -> Address -> String -> IO () module Arm.Swi swi :: CPU -> Word32 -> Bool -> IO () fetchString :: Memory -> Address -> IO String module Arm.ExecutionUnit eval :: CPU -> Instruction -> IO () run' :: CPU -> IO () singleStep :: CPU -> IO () run :: Program -> IO () module Arm.Debugger data DebugState Debug :: [Address] -> Radix -> DebugState bkpts :: DebugState -> [Address] radix :: DebugState -> Radix dbg :: Program -> IO () addBreakpoint :: DebugState -> IO DebugState showHelp :: IO () showMem :: Radix -> CPU -> IO () showRegs :: Radix -> CPU -> IO () showInstruction :: Radix -> Memory -> Bool -> Address -> IO () instance Show DebugState module Arm.Assembler data AsmResult Res :: Program -> AsmResult Err :: String -> AsmResult resolveSymbols :: Word32 -> [ParseElement] -> [(String, Word32)] replaceSymbols :: [ParseElement] -> Int -> Word32 -> [(String, Word32)] -> Word32 -> [(RegisterName, Word32)] -> [Instruction] -> [(Word32, Constant)] -> Program asmString :: String -> Either Program String lines' :: String -> [String] asmFile :: String -> IO (Either Program String) instance Show AsmResult module Arm.Arm run :: String -> IO () dbg :: String -> IO ()