diff options
| author | 2015-03-26 12:54:16 -0400 | |
|---|---|---|
| committer | 2015-04-02 00:19:11 -0400 | |
| commit | 5e5954c63b1a22ba2d333d23ae4c194798fe5412 (patch) | |
| tree | b002936fff0450760eff4469a06e48e745200a36 /src/core/arm/interpreter | |
| parent | dyncom: Migrate InAPrivilegedMode to armsupp (diff) | |
| download | yuzu-5e5954c63b1a22ba2d333d23ae4c194798fe5412.tar.gz yuzu-5e5954c63b1a22ba2d333d23ae4c194798fe5412.tar.xz yuzu-5e5954c63b1a22ba2d333d23ae4c194798fe5412.zip | |
dyncom: Move CP15 register reading into its own function.
Keeps everything contained. Added all supported readable registers in an ARM11 MPCore.
Diffstat (limited to 'src/core/arm/interpreter')
| -rw-r--r-- | src/core/arm/interpreter/armsupp.cpp | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp index f826ccb2d..ad713b561 100644 --- a/src/core/arm/interpreter/armsupp.cpp +++ b/src/core/arm/interpreter/armsupp.cpp | |||
| @@ -15,7 +15,9 @@ | |||
| 15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 17 | 17 | ||
| 18 | #include "core/mem_map.h" | ||
| 18 | #include "core/arm/skyeye_common/armdefs.h" | 19 | #include "core/arm/skyeye_common/armdefs.h" |
| 20 | #include "core/arm/skyeye_common/arm_regformat.h" | ||
| 19 | 21 | ||
| 20 | // Unsigned sum of absolute difference | 22 | // Unsigned sum of absolute difference |
| 21 | u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right) | 23 | u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right) |
| @@ -213,3 +215,197 @@ bool InAPrivilegedMode(ARMul_State* cpu) | |||
| 213 | { | 215 | { |
| 214 | return (cpu->Mode != USER32MODE); | 216 | return (cpu->Mode != USER32MODE); |
| 215 | } | 217 | } |
| 218 | |||
| 219 | // Reads from the CP15 registers. Used with implementation of the MRC instruction. | ||
| 220 | // Note that since the 3DS does not have the hypervisor extensions, these registers | ||
| 221 | // are not implemented. | ||
| 222 | u32 ReadCP15Register(ARMul_State* cpu, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2) | ||
| 223 | { | ||
| 224 | // Unprivileged registers | ||
| 225 | if (crn == 13 && opcode_1 == 0 && crm == 0) | ||
| 226 | { | ||
| 227 | if (opcode_2 == 2) | ||
| 228 | return cpu->CP15[CP15(CP15_THREAD_UPRW)]; | ||
| 229 | |||
| 230 | // TODO: Whenever TLS is implemented, this should return | ||
| 231 | // "cpu->CP15[CP15(CP15_THREAD_URO)];" | ||
| 232 | // which contains the address of the 0x200-byte TLS | ||
| 233 | if (opcode_2 == 3) | ||
| 234 | return Memory::KERNEL_MEMORY_VADDR; | ||
| 235 | } | ||
| 236 | |||
| 237 | if (InAPrivilegedMode(cpu)) | ||
| 238 | { | ||
| 239 | if (crn == 0 && opcode_1 == 0) | ||
| 240 | { | ||
| 241 | if (crm == 0) | ||
| 242 | { | ||
| 243 | if (opcode_2 == 0) | ||
| 244 | return cpu->CP15[CP15(CP15_MAIN_ID)]; | ||
| 245 | |||
| 246 | if (opcode_2 == 1) | ||
| 247 | return cpu->CP15[CP15(CP15_CACHE_TYPE)]; | ||
| 248 | |||
| 249 | if (opcode_2 == 3) | ||
| 250 | return cpu->CP15[CP15(CP15_TLB_TYPE)]; | ||
| 251 | |||
| 252 | if (opcode_2 == 5) | ||
| 253 | return cpu->CP15[CP15(CP15_CPU_ID)]; | ||
| 254 | } | ||
| 255 | else if (crm == 1) | ||
| 256 | { | ||
| 257 | if (opcode_2 == 0) | ||
| 258 | return cpu->CP15[CP15(CP15_PROCESSOR_FEATURE_0)]; | ||
| 259 | |||
| 260 | if (opcode_2 == 1) | ||
| 261 | return cpu->CP15[CP15(CP15_PROCESSOR_FEATURE_1)]; | ||
| 262 | |||
| 263 | if (opcode_2 == 2) | ||
| 264 | return cpu->CP15[CP15(CP15_DEBUG_FEATURE_0)]; | ||
| 265 | |||
| 266 | if (opcode_2 == 4) | ||
| 267 | return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_0)]; | ||
| 268 | |||
| 269 | if (opcode_2 == 5) | ||
| 270 | return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_1)]; | ||
| 271 | |||
| 272 | if (opcode_2 == 6) | ||
| 273 | return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_2)]; | ||
| 274 | |||
| 275 | if (opcode_2 == 7) | ||
| 276 | return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_3)]; | ||
| 277 | } | ||
| 278 | else if (crm == 2) | ||
| 279 | { | ||
| 280 | if (opcode_2 == 0) | ||
| 281 | return cpu->CP15[CP15(CP15_ISA_FEATURE_0)]; | ||
| 282 | |||
| 283 | if (opcode_2 == 1) | ||
| 284 | return cpu->CP15[CP15(CP15_ISA_FEATURE_1)]; | ||
| 285 | |||
| 286 | if (opcode_2 == 2) | ||
| 287 | return cpu->CP15[CP15(CP15_ISA_FEATURE_2)]; | ||
| 288 | |||
| 289 | if (opcode_2 == 3) | ||
| 290 | return cpu->CP15[CP15(CP15_ISA_FEATURE_3)]; | ||
| 291 | |||
| 292 | if (opcode_2 == 4) | ||
| 293 | return cpu->CP15[CP15(CP15_ISA_FEATURE_4)]; | ||
| 294 | } | ||
| 295 | } | ||
| 296 | |||
| 297 | if (crn == 1 && opcode_1 == 0 && crm == 0) | ||
| 298 | { | ||
| 299 | if (opcode_2 == 0) | ||
| 300 | return cpu->CP15[CP15(CP15_CONTROL)]; | ||
| 301 | |||
| 302 | if (opcode_2 == 1) | ||
| 303 | return cpu->CP15[CP15(CP15_AUXILIARY_CONTROL)]; | ||
| 304 | |||
| 305 | if (opcode_2 == 2) | ||
| 306 | return cpu->CP15[CP15(CP15_COPROCESSOR_ACCESS_CONTROL)]; | ||
| 307 | } | ||
| 308 | |||
| 309 | if (crn == 2 && opcode_1 == 0 && crm == 0) | ||
| 310 | { | ||
| 311 | if (opcode_2 == 0) | ||
| 312 | return cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_0)]; | ||
| 313 | |||
| 314 | if (opcode_2 == 1) | ||
| 315 | return cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_1)]; | ||
| 316 | |||
| 317 | if (opcode_2 == 2) | ||
| 318 | return cpu->CP15[CP15(CP15_TRANSLATION_BASE_CONTROL)]; | ||
| 319 | } | ||
| 320 | |||
| 321 | if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0) | ||
| 322 | return cpu->CP15[CP15(CP15_DOMAIN_ACCESS_CONTROL)]; | ||
| 323 | |||
| 324 | if (crn == 5 && opcode_1 == 0 && crm == 0) | ||
| 325 | { | ||
| 326 | if (opcode_2 == 0) | ||
| 327 | return cpu->CP15[CP15(CP15_FAULT_STATUS)]; | ||
| 328 | |||
| 329 | if (opcode_2 == 1) | ||
| 330 | return cpu->CP15[CP15(CP15_INSTR_FAULT_STATUS)]; | ||
| 331 | } | ||
| 332 | |||
| 333 | if (crn == 6 && opcode_1 == 0 && crm == 0) | ||
| 334 | { | ||
| 335 | if (opcode_2 == 0) | ||
| 336 | return cpu->CP15[CP15(CP15_FAULT_ADDRESS)]; | ||
| 337 | |||
| 338 | if (opcode_2 == 1) | ||
| 339 | return cpu->CP15[CP15(CP15_WFAR)]; | ||
| 340 | } | ||
| 341 | |||
| 342 | if (crn == 7 && opcode_1 == 0 && crm == 4 && opcode_2 == 0) | ||
| 343 | return cpu->CP15[CP15(CP15_PHYS_ADDRESS)]; | ||
| 344 | |||
| 345 | if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0) | ||
| 346 | return cpu->CP15[CP15(CP15_DATA_CACHE_LOCKDOWN)]; | ||
| 347 | |||
| 348 | if (crn == 10 && opcode_1 == 0) | ||
| 349 | { | ||
| 350 | if (crm == 0 && opcode_2 == 0) | ||
| 351 | return cpu->CP15[CP15(CP15_TLB_LOCKDOWN)]; | ||
| 352 | |||
| 353 | if (crm == 2) | ||
| 354 | { | ||
| 355 | if (opcode_2 == 0) | ||
| 356 | return cpu->CP15[CP15(CP15_PRIMARY_REGION_REMAP)]; | ||
| 357 | |||
| 358 | if (opcode_2 == 1) | ||
| 359 | return cpu->CP15[CP15(CP15_NORMAL_REGION_REMAP)]; | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | if (crn == 13 && crm == 0) | ||
| 364 | { | ||
| 365 | if (opcode_2 == 0) | ||
| 366 | return cpu->CP15[CP15(CP15_PID)]; | ||
| 367 | |||
| 368 | if (opcode_2 == 1) | ||
| 369 | return cpu->CP15[CP15(CP15_CONTEXT_ID)]; | ||
| 370 | |||
| 371 | if (opcode_2 == 4) | ||
| 372 | return cpu->CP15[CP15(CP15_THREAD_PRW)]; | ||
| 373 | } | ||
| 374 | |||
| 375 | if (crn == 15) | ||
| 376 | { | ||
| 377 | if (opcode_1 == 0 && crm == 12) | ||
| 378 | { | ||
| 379 | if (opcode_2 == 0) | ||
| 380 | return cpu->CP15[CP15(CP15_PERFORMANCE_MONITOR_CONTROL)]; | ||
| 381 | |||
| 382 | if (opcode_2 == 1) | ||
| 383 | return cpu->CP15[CP15(CP15_CYCLE_COUNTER)]; | ||
| 384 | |||
| 385 | if (opcode_2 == 2) | ||
| 386 | return cpu->CP15[CP15(CP15_COUNT_0)]; | ||
| 387 | |||
| 388 | if (opcode_2 == 3) | ||
| 389 | return cpu->CP15[CP15(CP15_COUNT_1)]; | ||
| 390 | } | ||
| 391 | |||
| 392 | if (opcode_1 == 5 && opcode_2 == 2) | ||
| 393 | { | ||
| 394 | if (crm == 5) | ||
| 395 | return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS)]; | ||
| 396 | |||
| 397 | if (crm == 6) | ||
| 398 | return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS)]; | ||
| 399 | |||
| 400 | if (crm == 7) | ||
| 401 | return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE)]; | ||
| 402 | } | ||
| 403 | |||
| 404 | if (opcode_1 == 7 && crm == 1 && opcode_2 == 0) | ||
| 405 | return cpu->CP15[CP15(CP15_TLB_DEBUG_CONTROL)]; | ||
| 406 | } | ||
| 407 | } | ||
| 408 | |||
| 409 | LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2); | ||
| 410 | return 0; | ||
| 411 | } | ||