completed phase 1?
This commit is contained in:
parent
0332001ef8
commit
bc78a83838
11 changed files with 306 additions and 44 deletions
|
|
@ -1,3 +1,5 @@
|
|||
open OpcodeTable
|
||||
|
||||
type nixbpe = {
|
||||
n : int;
|
||||
i : int;
|
||||
|
|
@ -7,6 +9,10 @@ type nixbpe = {
|
|||
e : int
|
||||
}
|
||||
|
||||
let string_of_nixbpe nixbpe =
|
||||
Printf.sprintf "n=%d,i=%d,x=%d,b=%d,p=%d,e=%d"
|
||||
nixbpe.n nixbpe.i nixbpe.x nixbpe.b nixbpe.p nixbpe.e
|
||||
|
||||
(*kreiramo začetno stanje -> TODO prestavi v main*)
|
||||
let regs = Processor.{a = 0; x = 0; l = 0; b = 0; s = 0; t = 0; f = 0.0; pc = 0; sw = 0}
|
||||
let memSize = 1 lsl 20 (*2^20*)
|
||||
|
|
@ -84,6 +90,10 @@ let getAddress (state : Processor.state) : int =
|
|||
(*execute format 1*)
|
||||
let executeFormat1 (state : Processor.state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||
Processor.pcIncrement state 1;
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat1] Mnemonic: %s\n"
|
||||
(string_of_mnemonic mnemonic);
|
||||
|
||||
match mnemonic with
|
||||
| FIX -> IzvajalnikF1.fix state
|
||||
| FLOAT -> IzvajalnikF1.floatF state
|
||||
|
|
@ -98,6 +108,10 @@ let executeFormat1 (state : Processor.state) (mnemonic : OpcodeTable.mnemonic) :
|
|||
(*execute format 2*)
|
||||
let executeFormat2 (state: Processor.state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||
let (r1, r2) = readR1R2 state in
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat2] Mnemonic: %s, r1: %d, r2: %d\n"
|
||||
(string_of_mnemonic mnemonic) r1 r2;
|
||||
|
||||
Processor.pcIncrement state 2;
|
||||
match mnemonic with
|
||||
| ADDR -> IzvajalnikF2.addr state r1 r2
|
||||
|
|
@ -119,6 +133,10 @@ let executeFormat2 (state: Processor.state) (mnemonic : OpcodeTable.mnemonic) :
|
|||
let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit =
|
||||
let disp = getDisp state in
|
||||
let operand = getOperand state nixbpe disp in
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat3] Mnemonic: %s, nixbpe: %s, operand: %d = 0x%02X\n"
|
||||
(string_of_mnemonic mnemonic) (string_of_nixbpe nixbpe) operand operand;
|
||||
|
||||
Processor.pcIncrement state 3; (*povecamo pc pred izvedbo ukaza*)
|
||||
match mnemonic with
|
||||
| ADD -> IzvajalnikF3.add state operand
|
||||
|
|
@ -169,73 +187,85 @@ let executeFormat3 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: Opcode
|
|||
|
||||
let executeFormat4 (state : Processor.state) (nixbpe : nixbpe) (mnemonic: OpcodeTable.mnemonic): unit =
|
||||
let address = getAddress state in
|
||||
let operand = getOperand state nixbpe address in
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat4] Mnemonic: %s, nixbpe: %s, operand: %d = 0x%02X\n"
|
||||
(string_of_mnemonic mnemonic) (string_of_nixbpe nixbpe) operand operand;
|
||||
|
||||
Processor.pcIncrement state 3;
|
||||
match mnemonic with
|
||||
(*aritmetika*)
|
||||
| ADD -> notImplemented "ADD4"
|
||||
| ADDF -> notImplemented "ADDF4"
|
||||
| AND -> notImplemented "AND4"
|
||||
| COMP -> notImplemented "COMP4"
|
||||
| COMPF -> notImplemented "COMPF4"
|
||||
| DIV -> notImplemented "DIV4"
|
||||
| MUL -> notImplemented "MUL4"
|
||||
| OR -> notImplemented "OR4"
|
||||
| SUB -> notImplemented "SUB4"
|
||||
| SUBF -> notImplemented "SUBF4"
|
||||
| TD -> notImplemented "TD4"
|
||||
| WD -> notImplemented "WD4"
|
||||
| ADD -> IzvajalnikF4.add state operand
|
||||
| ADDF -> notImplemented "ADDF3"
|
||||
| AND -> IzvajalnikF4.andF state operand
|
||||
| COMP -> IzvajalnikF4.comp state operand
|
||||
| COMPF -> notImplemented "COMPF3"
|
||||
| DIV -> IzvajalnikF4.div state operand
|
||||
| MUL -> IzvajalnikF4.mul state operand
|
||||
| OR -> IzvajalnikF4.orF state operand
|
||||
| SUB -> IzvajalnikF4.sub state operand
|
||||
| SUBF -> notImplemented "SUBF3"
|
||||
| TD -> notImplemented "TD3"
|
||||
| WD -> notImplemented "WD3"
|
||||
|
||||
(* Jump / subroutine *)
|
||||
| J -> notImplemented "J4"
|
||||
| JEQ -> notImplemented "JEQ4"
|
||||
| JGT -> notImplemented "JGT4"
|
||||
| JLT -> notImplemented "JLT4"
|
||||
| JSUB -> notImplemented "JSUB4"
|
||||
| RSUB -> notImplemented "RSUB4"
|
||||
| J -> IzvajalnikF4.j state operand
|
||||
| JEQ -> IzvajalnikF4.jeq state operand
|
||||
| JGT -> IzvajalnikF4.jgt state operand
|
||||
| JLT -> IzvajalnikF4.jlt state operand
|
||||
| JSUB -> IzvajalnikF4.jsub state operand
|
||||
| RSUB -> IzvajalnikF4.rsub state operand
|
||||
|
||||
(* Load/store *)
|
||||
| LDA -> notImplemented "LDA4"
|
||||
| LDB -> notImplemented "LDB4"
|
||||
| LDCH -> notImplemented "LDCH4"
|
||||
| LDF -> notImplemented "LDF4"
|
||||
| LDL -> notImplemented "LDL4"
|
||||
| LDS -> notImplemented "LDS4"
|
||||
| LDT -> notImplemented "LDT4"
|
||||
| LDX -> notImplemented "LDX4"
|
||||
| LDA -> IzvajalnikF4.lda state operand
|
||||
| LDB -> IzvajalnikF4.ldb state operand
|
||||
| LDCH -> notImplemented "LDCH3"
|
||||
| LDF -> notImplemented "LDF3"
|
||||
| LDL -> IzvajalnikF4.ldl state operand
|
||||
| LDS -> IzvajalnikF4.lds state operand
|
||||
| LDT -> IzvajalnikF4.ldt state operand
|
||||
| LDX -> IzvajalnikF4.ldx state operand
|
||||
| LPS -> notImplemented "LPS4"
|
||||
| STA -> notImplemented "STA4"
|
||||
| STB -> notImplemented "STB4"
|
||||
| STA -> IzvajalnikF4.sta state operand
|
||||
| STB -> IzvajalnikF4.stb state operand
|
||||
| STCH -> notImplemented "STCH4"
|
||||
| STF -> notImplemented "STF4"
|
||||
| STL -> notImplemented "STL4"
|
||||
| STS -> notImplemented "STS4"
|
||||
| STSW -> notImplemented "STSW4"
|
||||
| STT -> notImplemented "STT4"
|
||||
| STX -> notImplemented "STX4"
|
||||
| STL -> IzvajalnikF4.stl state operand
|
||||
| STS -> IzvajalnikF4.sts state operand
|
||||
| STSW -> IzvajalnikF4.stsw state operand
|
||||
| STT -> IzvajalnikF4.stt state operand
|
||||
| STX -> IzvajalnikF4.stx state operand
|
||||
|
||||
(* Control / IO *)
|
||||
| TIX -> notImplemented "TIX4"
|
||||
|_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 4")
|
||||
| TIX -> IzvajalnikF3.tix state operand
|
||||
|_ -> failwith ("Mnemonic" ^ (OpcodeTable.string_of_mnemonic mnemonic) ^ "falsely flaged as format 3")
|
||||
|
||||
|
||||
|
||||
(*execute format 3_4*)
|
||||
let executeFormat3_4 (state : Processor.state) (mnemonic : OpcodeTable.mnemonic) : unit =
|
||||
let nixbpe = getNIXBPE state in
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/executeFormat3_4]n=%d,i=%d,x=%d,b=%d,p=%d,e=%d\n" nixbpe.n nixbpe.i nixbpe.x nixbpe.b nixbpe.p nixbpe.e;
|
||||
|
||||
match nixbpe.e with
|
||||
| 0 -> executeFormat3 state nixbpe mnemonic
|
||||
| 1 -> executeFormat4 state nixbpe mnemonic
|
||||
| _ -> failwith "invalid computation of nxbpe"
|
||||
|
||||
|
||||
(*execute ukaza*)
|
||||
let execute (state : Processor.state) : unit =
|
||||
let byte1 = Processor.readMem state 0 in (*read the 1st byte of the instruction*)
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/execute]Prebral byte1 %c = 0x%02X\n" byte1 (Char.code byte1);
|
||||
|
||||
try
|
||||
let {OpcodeTable.mnemonic; OpcodeTable.format} = Decoder.decoder byte1 in (*determen the format of the instruction from the 1st byte*)
|
||||
match format with
|
||||
| F1 -> executeFormat1 state mnemonic
|
||||
| F2 -> executeFormat2 state mnemonic
|
||||
| F3_4 -> executeFormat3_4 state mnemonic
|
||||
let info = Decoder.decoder byte1 in (*determen the format of the instruction from the 1st byte*)
|
||||
(*debugging*)
|
||||
Printf.printf "[Izvajalnik/execute]Opcode %s, format %s\n" (string_of_mnemonic info.mnemonic) (format_str info.format);
|
||||
|
||||
match info.format with
|
||||
| F1 -> executeFormat1 state info.mnemonic
|
||||
| F2 -> executeFormat2 state info.mnemonic
|
||||
| F3_4 -> executeFormat3_4 state info.mnemonic
|
||||
with
|
||||
| Failure msg -> byte1 |> Char.code |> invalidOpcode
|
||||
| Failure msg -> Printf.printf "Cought faliure %s \n" msg;
|
||||
Loading…
Add table
Add a link
Reference in a new issue