1
1
import { MAX_HARDWARE_IRQ } from './irq' ;
2
- import { RP2040 , SIO_START_ADDRESS } from './rp2040' ;
2
+ import { RP2040 , APB_START_ADDRESS , SIO_START_ADDRESS } from './rp2040' ;
3
3
4
4
/* eslint-disable @typescript-eslint/no-unused-vars */
5
5
const EXC_RESET = 1 ;
@@ -568,9 +568,15 @@ export class CortexM0Core {
568
568
return result & 0xffffffff ;
569
569
}
570
570
571
- slowIO ( addr : number ) {
571
+ cyclesIO ( addr : number , write = false ) {
572
572
addr = addr >>> 0 ;
573
- return addr < SIO_START_ADDRESS || addr > SIO_START_ADDRESS + 0x10000000 ;
573
+ if ( addr >= SIO_START_ADDRESS && addr < SIO_START_ADDRESS + 0x10000000 ) {
574
+ return 0 ;
575
+ }
576
+ if ( addr >= APB_START_ADDRESS && addr < APB_START_ADDRESS + 0x10000000 ) {
577
+ return write ? 4 : 3 ;
578
+ }
579
+ return 1 ;
574
580
}
575
581
576
582
executeInstruction ( ) {
@@ -828,13 +834,15 @@ export class CortexM0Core {
828
834
const Rn = ( opcode >> 3 ) & 0x7 ;
829
835
const Rt = opcode & 0x7 ;
830
836
const addr = this . registers [ Rn ] + imm5 ;
837
+ this . cycles += this . cyclesIO ( addr ) ;
831
838
this . registers [ Rt ] = this . readUint32 ( addr ) ;
832
839
}
833
840
// LDR (sp + immediate)
834
841
else if ( opcode >> 11 === 0b10011 ) {
835
842
const Rt = ( opcode >> 8 ) & 0x7 ;
836
843
const imm8 = opcode & 0xff ;
837
844
const addr = this . SP + ( imm8 << 2 ) ;
845
+ this . cycles += this . cyclesIO ( addr ) ;
838
846
this . registers [ Rt ] = this . readUint32 ( addr ) ;
839
847
}
840
848
// LDR (literal)
@@ -843,6 +851,7 @@ export class CortexM0Core {
843
851
const Rt = ( opcode >> 8 ) & 7 ;
844
852
const nextPC = this . PC + 2 ;
845
853
const addr = ( nextPC & 0xfffffffc ) + imm8 ;
854
+ this . cycles += this . cyclesIO ( addr ) ;
846
855
this . registers [ Rt ] = this . readUint32 ( addr ) ;
847
856
}
848
857
// LDR (register)
@@ -851,9 +860,7 @@ export class CortexM0Core {
851
860
const Rn = ( opcode >> 3 ) & 0x7 ;
852
861
const Rt = opcode & 0x7 ;
853
862
const addr = this . registers [ Rm ] + this . registers [ Rn ] ;
854
- if ( this . slowIO ( addr ) ) {
855
- this . cycles ++ ;
856
- }
863
+ this . cycles += this . cyclesIO ( addr ) ;
857
864
this . registers [ Rt ] = this . readUint32 ( addr ) ;
858
865
}
859
866
// LDRB (immediate)
@@ -862,9 +869,7 @@ export class CortexM0Core {
862
869
const Rn = ( opcode >> 3 ) & 0x7 ;
863
870
const Rt = opcode & 0x7 ;
864
871
const addr = this . registers [ Rn ] + imm5 ;
865
- if ( this . slowIO ( addr ) ) {
866
- this . cycles ++ ;
867
- }
872
+ this . cycles += this . cyclesIO ( addr ) ;
868
873
this . registers [ Rt ] = this . readUint8 ( addr ) ;
869
874
}
870
875
// LDRB (register)
@@ -873,9 +878,7 @@ export class CortexM0Core {
873
878
const Rn = ( opcode >> 3 ) & 0x7 ;
874
879
const Rt = opcode & 0x7 ;
875
880
const addr = this . registers [ Rm ] + this . registers [ Rn ] ;
876
- if ( this . slowIO ( addr ) ) {
877
- this . cycles ++ ;
878
- }
881
+ this . cycles += this . cyclesIO ( addr ) ;
879
882
this . registers [ Rt ] = this . readUint8 ( addr ) ;
880
883
}
881
884
// LDRH (immediate)
@@ -884,9 +887,7 @@ export class CortexM0Core {
884
887
const Rn = ( opcode >> 3 ) & 0x7 ;
885
888
const Rt = opcode & 0x7 ;
886
889
const addr = this . registers [ Rn ] + ( imm5 << 1 ) ;
887
- if ( this . slowIO ( addr ) ) {
888
- this . cycles ++ ;
889
- }
890
+ this . cycles += this . cyclesIO ( addr ) ;
890
891
this . registers [ Rt ] = this . readUint16 ( addr ) ;
891
892
}
892
893
// LDRH (register)
@@ -895,9 +896,7 @@ export class CortexM0Core {
895
896
const Rn = ( opcode >> 3 ) & 0x7 ;
896
897
const Rt = opcode & 0x7 ;
897
898
const addr = this . registers [ Rm ] + this . registers [ Rn ] ;
898
- if ( this . slowIO ( addr ) ) {
899
- this . cycles ++ ;
900
- }
899
+ this . cycles += this . cyclesIO ( addr ) ;
901
900
this . registers [ Rt ] = this . readUint16 ( addr ) ;
902
901
}
903
902
// LDRSB
@@ -906,9 +905,7 @@ export class CortexM0Core {
906
905
const Rn = ( opcode >> 3 ) & 0x7 ;
907
906
const Rt = opcode & 0x7 ;
908
907
const addr = this . registers [ Rm ] + this . registers [ Rn ] ;
909
- if ( this . slowIO ( addr ) ) {
910
- this . cycles ++ ;
911
- }
908
+ this . cycles += this . cyclesIO ( addr ) ;
912
909
this . registers [ Rt ] = signExtend8 ( this . readUint8 ( addr ) ) ;
913
910
}
914
911
// LDRSH
@@ -917,9 +914,7 @@ export class CortexM0Core {
917
914
const Rn = ( opcode >> 3 ) & 0x7 ;
918
915
const Rt = opcode & 0x7 ;
919
916
const addr = this . registers [ Rm ] + this . registers [ Rn ] ;
920
- if ( this . slowIO ( addr ) ) {
921
- this . cycles ++ ;
922
- }
917
+ this . cycles += this . cyclesIO ( addr ) ;
923
918
this . registers [ Rt ] = signExtend16 ( this . readUint16 ( addr ) ) ;
924
919
}
925
920
// LSLS (immediate)
@@ -1161,19 +1156,15 @@ export class CortexM0Core {
1161
1156
const Rn = ( opcode >> 3 ) & 0x7 ;
1162
1157
const Rt = opcode & 0x7 ;
1163
1158
const address = this . registers [ Rn ] + imm5 ;
1164
- if ( this . slowIO ( address ) ) {
1165
- this . cycles ++ ;
1166
- }
1159
+ this . cycles += this . cyclesIO ( address , true ) ;
1167
1160
this . writeUint32 ( address , this . registers [ Rt ] ) ;
1168
1161
}
1169
1162
// STR (sp + immediate)
1170
1163
else if ( opcode >> 11 === 0b10010 ) {
1171
1164
const Rt = ( opcode >> 8 ) & 0x7 ;
1172
1165
const imm8 = opcode & 0xff ;
1173
1166
const address = this . SP + ( imm8 << 2 ) ;
1174
- if ( this . slowIO ( address ) ) {
1175
- this . cycles ++ ;
1176
- }
1167
+ this . cycles += this . cyclesIO ( address , true ) ;
1177
1168
this . writeUint32 ( address , this . registers [ Rt ] ) ;
1178
1169
}
1179
1170
// STR (register)
@@ -1182,9 +1173,7 @@ export class CortexM0Core {
1182
1173
const Rn = ( opcode >> 3 ) & 0x7 ;
1183
1174
const Rt = opcode & 0x7 ;
1184
1175
const address = this . registers [ Rm ] + this . registers [ Rn ] ;
1185
- if ( this . slowIO ( address ) ) {
1186
- this . cycles ++ ;
1187
- }
1176
+ this . cycles += this . cyclesIO ( address , true ) ;
1188
1177
this . writeUint32 ( address , this . registers [ Rt ] ) ;
1189
1178
}
1190
1179
// STRB (immediate)
@@ -1193,9 +1182,7 @@ export class CortexM0Core {
1193
1182
const Rn = ( opcode >> 3 ) & 0x7 ;
1194
1183
const Rt = opcode & 0x7 ;
1195
1184
const address = this . registers [ Rn ] + imm5 ;
1196
- if ( this . slowIO ( address ) ) {
1197
- this . cycles ++ ;
1198
- }
1185
+ this . cycles += this . cyclesIO ( address , true ) ;
1199
1186
this . writeUint8 ( address , this . registers [ Rt ] ) ;
1200
1187
}
1201
1188
// STRB (register)
@@ -1204,9 +1191,7 @@ export class CortexM0Core {
1204
1191
const Rn = ( opcode >> 3 ) & 0x7 ;
1205
1192
const Rt = opcode & 0x7 ;
1206
1193
const address = this . registers [ Rm ] + this . registers [ Rn ] ;
1207
- if ( this . slowIO ( address ) ) {
1208
- this . cycles ++ ;
1209
- }
1194
+ this . cycles += this . cyclesIO ( address , true ) ;
1210
1195
this . writeUint8 ( address , this . registers [ Rt ] ) ;
1211
1196
}
1212
1197
// STRH (immediate)
@@ -1215,9 +1200,7 @@ export class CortexM0Core {
1215
1200
const Rn = ( opcode >> 3 ) & 0x7 ;
1216
1201
const Rt = opcode & 0x7 ;
1217
1202
const address = this . registers [ Rn ] + imm5 ;
1218
- if ( this . slowIO ( address ) ) {
1219
- this . cycles ++ ;
1220
- }
1203
+ this . cycles += this . cyclesIO ( address , true ) ;
1221
1204
this . writeUint16 ( address , this . registers [ Rt ] ) ;
1222
1205
}
1223
1206
// STRH (register)
@@ -1226,9 +1209,7 @@ export class CortexM0Core {
1226
1209
const Rn = ( opcode >> 3 ) & 0x7 ;
1227
1210
const Rt = opcode & 0x7 ;
1228
1211
const address = this . registers [ Rm ] + this . registers [ Rn ] ;
1229
- if ( this . slowIO ( address ) ) {
1230
- this . cycles ++ ;
1231
- }
1212
+ this . cycles += this . cyclesIO ( address , true ) ;
1232
1213
this . writeUint16 ( address , this . registers [ Rt ] ) ;
1233
1214
}
1234
1215
// SUB (SP minus immediate)
0 commit comments