Line 4... |
Line 4... |
# Operation:
|
# Operation:
|
# 1.- If the trapped opcode is one of the emulated opcodes, it is emulated.
|
# 1.- If the trapped opcode is one of the emulated opcodes, it is emulated.
|
# 2.- Otherwise, nothing is done (as if the trapped opcode was a NOP) and a flag
|
# 2.- Otherwise, nothing is done (as if the trapped opcode was a NOP) and a flag
|
# is set in the emu_frame area (meant for debugging, mostly).
|
# is set in the emu_frame area (meant for debugging, mostly).
|
# 3.- In either case, if the trapped opcode is in a jump delay slot, the jump
|
# 3.- In either case, if the trapped opcode is in a jump delay slot, the jump
|
# instruction is emulated. FIXME it isn't yet
|
# instruction is emulated.
|
|
# FIXME it isn't yet
|
#
|
#
|
# Uses a small workspace in the BSS section. Does NOT use the regular stack
|
# Uses a small workspace in the BSS section. Does NOT use the regular stack
|
# nor makes any assumptions about any registers, including the sp.
|
# nor makes any assumptions about any registers, including the sp.
|
#
|
#
|
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
Line 48... |
Line 49... |
sw $t0,-24($k1)
|
sw $t0,-24($k1)
|
sw $t1,-28($k1)
|
sw $t1,-28($k1)
|
sw $t2,-32($k1)
|
sw $t2,-32($k1)
|
move $sp,$k1
|
move $sp,$k1
|
|
|
# FIXME handle delay slot situation: emulate jump if necessary
|
mfc0 $t0,$14 # get bad opcode (or branch opcode if in DS)
|
|
|
# get bad opcode
|
|
mfc0 $t0,$14
|
|
lw $k0,0($t0)
|
lw $k0,0($t0)
|
|
|
|
# Handle delay slot situation: emulate jump if necessary
|
|
mfc0 $k1,$13 # Check bit 31 (BD) from C0 cause register
|
|
bltzal $k1,emulate_branch
|
|
nop
|
|
|
# decode instruction: either SPECIAL3 or SPECIAL2
|
# decode instruction: either SPECIAL3 or SPECIAL2
|
srl $t1,$k0,26
|
srl $t1,$k0,26
|
xori $t0,$t1,0x01f
|
xori $t0,$t1,0x01f
|
beqz $t0,mips32_special3
|
beqz $t0,mips32_special3
|
xori $t0,$t1,0x01c
|
xori $t0,$t1,0x01c
|
Line 118... |
Line 122... |
li $t0,0x20010000 # Write ignored opcode to debug register
|
li $t0,0x20010000 # Write ignored opcode to debug register
|
sw $k0,1024($t0)
|
sw $k0,1024($t0)
|
j opcode_emu_return
|
j opcode_emu_return
|
nop
|
nop
|
|
|
|
# Get the branch opcode, decode it and emulate it
|
|
# entry: $k0 = opcode, $t0 = address of branch
|
|
# exit: $k0 = opcode that triggered exception (in branch delay)
|
|
emulate_branch:
|
|
|
|
# FIXME branch emulation is missing!
|
|
lw $k0,4($t0) # read actual guilty opcode
|
|
jr $ra
|
|
nop
|
|
|
|
#---- Branch emulation routines --------------------------------------------
|
|
# FIXME branch emulation missing
|
|
|
#---- Opcode emulation routines --------------------------------------------
|
#---- Opcode emulation routines --------------------------------------------
|
|
|
# CLZ: rd <- count leading zeros on rs
|
# CLZ: rd <- count leading zeros on rs
|
mips32_CLZ:
|
mips32_CLZ:
|
jal get_source_register # $k1 = source register (Rs)
|
jal get_source_register # $k1 = source register (Rs)
|