-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.go
47 lines (37 loc) · 897 Bytes
/
machine.go
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
package main
import (
"fmt"
"os"
)
type Machine struct {
Mmu *Mmu
State *State
}
func (machine *Machine) MachineStep() ExitReason {
for {
ExecBlockInterp(machine.State)
if machine.State.exitReason == InDirectBranch || machine.State.exitReason == DirectBranch {
continue
}
break
}
assert(machine.State.exitReason == ECall, "not a reasonable exit reason")
return ECall
}
func (machine *Machine) MachineLoadProgram(path string) {
// 打开 ELF 文件
file, err := os.Open(path)
if err != nil {
DPrintf("Machine load program fail, err: %s\n", err.Error())
return
}
defer file.Close()
if err = machine.Mmu.MmuLoadElf(file); err != nil {
DPrintf("Machine fail load elf, err: %v\n", err.Error())
return
}
// 打印 ELF 头部信息
fmt.Printf("Entry: %d\n", machine.Mmu.EEntry)
fmt.Printf("MMU:%v\n", machine.Mmu)
machine.State.pc = machine.Mmu.EEntry
}