-
Notifications
You must be signed in to change notification settings - Fork 1
/
op6.go
75 lines (68 loc) · 1.47 KB
/
op6.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
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
package m68k
import "fmt"
// opBcc implements:
// - BRA
// - BSR
// - Bcc (4-25)
func opBcc(c *Processor) (t *stepTrace) {
t = &stepTrace{
addr: c.PC,
sz: noSize,
n: 1,
}
c.PC += 2
cc := c.op & 0x0F00 >> 8
t.op = []string{
"bra", // bra
"bsr", // bsr (this should never happen)
"bhi", // high
"bls", // low or same
"bcc", // (hi) carry clear
"bcs", // (lo) carry set
"bne", // not equal
"beq", // equal
"bvc", // overflow clear
"bvs", // overflow set
"bpl", // plus
"bmi", // minus
"bge", // greater or equal
"blt", // less than
"bgt", // greater than
"ble", // less or equal
}[cc]
// compute displacement
var disp int32
switch c.op & 0xFF {
default: // 8-bit displacement
disp = byteToInt32(byte(c.op))
case 0: // 16-bit displacement
var n uint16
n, _, t.err = c.readImmWord()
disp = wordToInt32(n)
case 0xFF: // 32-bit displacement
if cc < 2 {
// 32-bit displacement is not implemented on the 68000 for bra and bsr
t.err = errBadOpcode
return
}
var n uint32
n, _, t.err = c.readImmLong()
disp = longToInt32(n)
}
if t.err != nil {
return
}
t.src = fmt.Sprintf("($%X,PC)", disp)
// branch
if !testCond(c, cc) {
return
}
c.PC = uint32((int32(t.addr+2) + disp))
if cc == 0 && c.PC == t.addr {
// this is a branch to self - a common pattern to terminate a program by
// placing the processor in an infinite loop. As a convenience to users,
// let's stop the processor.
t.err = c.Stop()
}
return
}