pifmon.s
3.94 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* pifmon.s
*/
#include "sys/regdef.h"
#include "sys/asm.h"
#include "tinymon.h"
.text
.set noat # allows us to use register $1 ($at)
.set noreorder
LEAF (Boot) # Address = 0xbfc00000.
#
# Rom entry point; on reset, the R4300 fetches instructions starting at
# address 0xbfc00000; we tell the R4300 to immediately jump to cartridge
# rom address 0xb0000400 (0x400 bytes into the cartridge rom).
#
lui s0, 0xb000
addiu s0, s0, 0x400
j s0
#
# Cartridge ramrom read/write access routines. We provide them here, so that
# ramrom resident programs may jump briefly into the pif rom to send or fetch
# data to/from ramrom without running into memory arbitration problems caused
# by accessing the ramrom while the cpu is fetching instructions from ramrom.
#
# NOTE: these routines assume that the caller has already read the
# PI_STATUS_REG to guarantee that neither busy bits
# (PI_STATUS_IO_BUSY or PI_STATUS_DMA_BUSY) are set.
#
#
# Read from cartridge ramrom co-routine. Register usage:
#
# t0 cartridge ramrom address to read from
# t1 read return value
# ra return address to jr to
#
#ifdef BROKEN_PIF_ROUTINES
rdCart: lw t1, 0x0(t0)
nop
jr ra
nop
#
# Write to cartridge ramrom co-routine. Register usage:
#
# t0 cartridge ramrom address to write to
# t1 data value to write into cartridge ramrom
# ra return address to jr to
#
wrCart: sw t1, 0x0(t0)
jr ra
nop
#else
nop
nop
nop
nop
nop
nop
nop
nop
nop
#endif
#
# Write to cartridge ramrom co-routine. Register usage:
#
# t0 cartridge ramrom address to write to
# t1 data value to write into cartridge ramrom
# ra return address to jr to
#
wrCart: sw t1, 0x0(t0)
lui t7, PI_BASE_REG_UPPER
waitForIdle:
lw t6, PI_STATUS_REG_OFFSET(t7)
nop
andi t6, t6, (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)
bne t6, zero, waitForIdle
nop
jr ra
nop
#
# Now prepare a default interrupt exception vector table. There are three
# types of exceptions in all, user tlb miss, extended address tlb miss,
# and all others. The condition codes in the CAUSE register will be set.
#
# Each exception will simply spin forever, jumping back to its entry point
# (making it easy to capture which exception was triggered by looking at the
# memory bus address on a logic analyzer).
#
.align 9 # Align to start of the vector table.
# Address = 0xbfc00200.
#ifdef OLD_VECTOR_ROUTINES
lui s0, 0xbfc0
addiu s0, s0, 0x200 # Spin forever at 0xbfc00200
j s0 # utlbmiss boot exception vector
#else
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
lui s0, RAMROM_BASE_UPPER
addiu s0, s0, 0x780 # utlbmiss boot exception vector
j s0 # jump to 0xb0000780 (0x780 into ramrom)
nop
#endif
.align 7 # Align to next exception vector
# Address = 0xbfc00280.
#ifdef OLD_VECTOR_ROUTINES
lui s0, 0xbfc0
addiu s0, s0, 0x280 # Spin forever at 0xbfc00280
j s0 # xutlbmiss boot exception vector
#else
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
lui s0, RAMROM_BASE_UPPER
addiu s0, s0, 0x780 # utlbmiss boot exception vector
j s0 # jump to 0xb0000780 (0x780 into ramrom)
nop
#endif
.align 8 # Align to next exception vector
# Address = 0xbfc00380.
#ifdef OLD_VECTOR_ROUTINES
lui s0, 0xbfc0
addiu s0, s0, 0x380 # Spin forever at 0xbfc00380
j s0 # "Others" (all other exceptions)
#else
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
nop # overwrite old instructions
lui s0, RAMROM_BASE_UPPER
addiu s0, s0, 0x780 # utlbmiss boot exception vector
j s0 # jump to 0xb0000780 (0x780 into ramrom)
nop
#endif
END (Boot)