initial commit
[wavedrum/sharc-disassembler.git] / SHARC / Kernel.hs
1 {-
2 This file is part of shark-disassembler.
3
4 Copyright (C) 2014 Ricardo Wurmus
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 -}
19
20 {-# LANGUAGE OverloadedStrings #-}
21
22 module SHARC.Kernel where
23
24 import SHARC.Types
25 import SHARC.Word48
26 import SHARC.Instruction
27
28 import Control.Monad (replicateM,mapM_)
29 import Data.Word (Word64)
30 import Data.Binary.Get
31 import qualified Data.ByteString.Lazy as B
32
33
34 type Kernel = [Instruction]
35
36 -- the boot kernel is 256 48-bit words long,
37 -- each 48-bit is read as six 8-bit packages (LSB first)
38 getKernel :: Get Kernel
39 getKernel = replicateM 256 getInstruction
40
41 parseKernel :: B.ByteString -> Kernel
42 parseKernel = runGet getKernel
43
44 -- p.609, hw.pdf
45 -- ivt_start_address = 0x90000 :: Word64
46 -- ivt_end_address = 0x900ff :: Word64
47 printKernel :: B.ByteString -> IO ()
48 printKernel bs = mapM_ printInstructionWithAddr $ zip [offset..] kernel
49 where
50 offset = 0x90000 :: Word64
51 kernel = parseKernel bs