-
Notifications
You must be signed in to change notification settings - Fork 16
/
ExecuteA64.hs
94 lines (93 loc) · 2.96 KB
/
ExecuteA64.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{-# LANGUAGE ScopedTypeVariables #-}
module Spec.ExecuteA64 where
import Spec.Decode
import Spec.Machine
import Utility.Utility
import Spec.VirtualMemory
import Control.Monad
import Data.Bits
import Prelude
execute :: forall p t. (RiscvMachine p t) => InstructionA64 -> p ()
-- begin ast
execute (Lr_d rd rs1 aqrl) = do
a <- getRegister rs1
addr <- translate Load 8 a
makeReservation addr
x <- loadDouble Execute addr
setRegister rd (int64ToReg x)
execute (Sc_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 8 a
valid <- checkReservation addr
if valid
then do
x <- getRegister rs2
storeDouble Execute addr (regToInt64 x)
setRegister rd 0
else setRegister rd 1
-- TODO: Eventually stop cheating.
execute (Amoswap_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (regToInt64 y)
execute (Amoadd_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (regToInt64 (int64ToReg x + y))
execute (Amoand_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (regToInt64 (int64ToReg x .&. y))
execute (Amoor_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (regToInt64 (int64ToReg x .|. y))
execute (Amoxor_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (regToInt64 (xor (int64ToReg x) y))
execute (Amomax_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (if y < (int64ToReg x) then x else regToInt64 y)
execute (Amomaxu_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (if ltu y (uInt64ToReg x) then x else regToInt64 y)
execute (Amomin_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (if (int64ToReg x) < y then x else regToInt64 y)
execute (Amominu_d rd rs1 rs2 aqrl) = do
a <- getRegister rs1
addr <- translate Store 4 a
x <- loadDouble Execute addr
y <- getRegister rs2
setRegister rd (int64ToReg x)
storeDouble Execute addr (if ltu (uInt64ToReg x) y then x else regToInt64 y)
-- end ast
execute inst = error $ "dispatch bug: " ++ show inst