|
Nugget
Bare-metal libraries and examples for the original PlayStation
|
#include "common/hardware/dma.h"#include "common/hardware/hwregs.h"#include "common/syscalls/syscalls.h"#include "exotic/cester.h"#include "cester-cop0.c"
Macros | |
| #define | PCSX_TESTS 0 |
| #define | CESTER_MAYBE_TEST CESTER_TEST |
| #define | CESTER_NO_SIGNAL |
| #define | CESTER_NO_TIME |
| #define | EXIT_SUCCESS 0 |
| #define | EXIT_FAILURE 1 |
Functions | |
| CESTER_TEST (cpu_cop0_basic_write_bp, cpu_tests, uint32_t expectedEPC;uint32_t t;volatile uint32_t *ptr=(volatile uint32_t *) 0x58; *ptr=1;__asm__ volatile("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0xfffffff0\n" " mtc0 %0, $9\n" :"=r"(t));cester_assert_uint_eq(1, *ptr);__asm__ volatile("la %0, 1f\n1:\nsw $0, 0x58($0)" :"=r"(expectedEPC));__asm__ volatile("mtc0 $0, $7\n");cester_assert_uint_eq(0, *ptr);cester_assert_uint_eq(1, s_got40);cester_assert_uint_eq(0, s_got80);cester_assert_uint_eq(0x40, s_from);cester_assert_uint_eq(expectedEPC, s_epc);) CESTER_TEST(cpu_cop0_kseg_write_bp | |
| __asm__ | volatile ("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0xfffffff0\n" " mtc0 %0, $9\n" :"=r"(t)) |
| cester_assert_uint_eq (1, *ptr) | |
| __asm__ | volatile ("lui $at, 0x8000\nsw $0, 0x58($at)") |
| __asm__ | volatile ("mtc0 $0, $7\n") |
| cester_assert_uint_eq (0, *ptr) | |
| cester_assert_uint_eq (0, s_got40) | |
| cester_assert_uint_eq (0, s_got80) | |
| cester_assert_uint_eq (0, s_from) | |
| cester_assert_uint_eq (0, s_epc) | |
| CESTER_TEST (cpu_cop0_kseg_write_bp_kd_clear, cpu_tests, uint32_t t;volatile uint32_t *ptr=(volatile uint32_t *) 0x80000058; *ptr=1;__asm__ volatile("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0x1fffffff\n" " mtc0 %0, $9\n" :"=r"(t));cester_assert_uint_eq(1, *ptr);__asm__ volatile("lui $at, 0x8000\nsw $0, 0x58($at)");__asm__ volatile("mtc0 $0, $7\n");cester_assert_uint_eq(0, *ptr);cester_assert_uint_eq(0, s_got40);cester_assert_uint_eq(0, s_got80);) CESTER_TEST(cpu_cop0_kseg_write_bp_kd_set | |
| __asm__ | volatile ("" " lui %0, 0b1110101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0x1fffffff\n" " mtc0 %0, $9\n" :"=r"(t)) |
| __asm__ | volatile ("lui $at, 0x8000\nla %0, 1f\n1:\nsw $0, 0x58($at)" :"=r"(expectedEPC)) |
| cester_assert_uint_eq (1, s_got40) | |
| cester_assert_uint_eq (0x40, s_from) | |
| cester_assert_uint_eq (expectedEPC, s_epc) | |
| CESTER_TEST (cpu_cop0_upper_memory_write_bp, cpu_tests, uint32_t t;volatile uint32_t *ptr=(volatile uint32_t *) 0x00200058; *ptr=1;__asm__ volatile("" " lui %0, 0b1100101010000000\n" " mtc0 %0, $7\n" " li %0, 0x58\n" " mtc0 %0, $5\n" " li %0, 0xfffffff0\n" " mtc0 %0, $9\n" :"=r"(t));cester_assert_uint_eq(1, *ptr);__asm__ volatile("lui $at, 0x0020\nsw $0, 0x58($at)");__asm__ volatile("mtc0 $0, $7\n");cester_assert_uint_eq(0, *ptr);cester_assert_uint_eq(0, s_got40);cester_assert_uint_eq(0, s_got80);cester_assert_uint_eq(0, s_from);cester_assert_uint_eq(0, s_epc);) CESTER_TEST(cpu_cop0_unaligned_write_bp | |
| cester_assert_uint_eq (0x01020304, *ptr) | |
| __asm__ | volatile ("la %0, 1f\n1:\nsb $0, 0x59($0)" :"=r"(expectedEPC)) |
| cester_assert_uint_eq (0x01020004, *ptr) | |
| CESTER_TEST (cpu_unaligned_write_fault, CESTER_MAYBE_TEST(cpu_tests, uint32_t expectedEPC;__asm__ volatile("la %0, 1f\n1:\nsw $0, 1($0)" :"=r"(expectedEPC));cester_assert_uint_eq(0, s_got40);cester_assert_uint_eq(1, s_got80);cester_assert_uint_eq(0x80, s_from);cester_assert_uint_eq(expectedEPC, s_epc);) | |
| cester_assert_uint_eq (0xf04fff3d, mask) | |
| CESTER_MAYBE_TEST (cpu_cop0_cu1_unusable, cpu_tests, uint32_t old, sr;__asm__ volatile("mfc0 %0, $12\nnop" :"=r"(old));sr=old &~0x20000000;__asm__ volatile("mtc0 %0, $12\nnop\nnop" ::"r"(sr));__asm__ volatile(".word 0x44080000" :::"t0");__asm__ volatile("mtc0 %0, $12\nnop\nnop" ::"r"(old));cester_assert_uint_eq(1, s_got80);uint32_t ce=s_cause &0x3000007c;cester_assert_uint_eq(0x1000002c, ce);) CESTER_MAYBE_TEST(cpu_cop0_cu3_unusable | |
| __asm__ | volatile ("mfc0 %0, $12\nnop" :"=r"(old)) |
| __asm__ | volatile ("mtc0 %0, $12\nnop\nnop" ::"r"(sr)) |
| __asm__ | volatile (".word 0x4c080000" :::"t0") |
| __asm__ | volatile ("mtc0 %0, $12\nnop\nnop" ::"r"(old)) |
| cester_assert_uint_eq (1, s_got80) | |
| cester_assert_uint_eq (0x3000002c, ce) | |
| CESTER_TEST (cpu_ADD_overflow_in_delay_slot, CESTER_TEST(cpu_tests, s_resume=(uint32_t *) delayslot_resume;uint32_t branch=delayslot_add();uint32_t excode=(s_cause > > 2) &0x1f;uint32_t bd=s_cause > > 31;cester_assert_uint_eq(1, s_got80);cester_assert_uint_eq(12, excode);cester_assert_uint_eq(1, bd);cester_assert_uint_eq(branch, s_epc);) | |
| CESTER_TEST (cpu_software_interrupt, cpu_tests, uint32_t sr;__asm__ volatile("mfc0 %0, $12\nnop" :"=r"(sr));s_customhandler=delayslot_clear_cause;__asm__ volatile("mtc0 %0, $12\nnop\nnop" ::"r"((sr &~0xff00)|0x101));uint32_t next=plain_swi();__asm__ volatile("mtc0 %0, $12\nnop\nnop" ::"r"(sr));s_customhandler=NULL;uint32_t excode=(s_cause > > 2) &0x1f;uint32_t bd=s_cause > > 31;cester_assert_uint_eq(1, s_got80);cester_assert_uint_eq(0, excode);cester_assert_uint_eq(0, bd);cester_assert_uint_eq(next, s_epc);cester_assert_uint_eq(0, delayslot_taken);) CESTER_TEST(cpu_software_interrupt_in_delay_slot | |
| __asm__ | volatile ("mtc0 %0, $12\nnop\nnop" ::"r"((sr &~0xff00)|0x101)) |
| delayslot_swi () | |
| cester_assert_uint_eq (0, excode) | |
| cester_assert_uint_eq (0, bd) | |
| cester_assert_uint_eq ((uint32_t) delayslot_mark, s_epc) | |
| cester_assert_uint_eq (0, delayslot_taken) | |
Variables | |
| cpu_tests | |
| uint32_t | t |
| volatile uint32_t * | ptr = (volatile uint32_t *) 0x80000058 |
| uint32_t | expectedEPC |
| uint32_t | old |
| uint32_t | sr = old & ~0x80000000 |
| uint32_t | ce = s_cause & 0x3000007c |
| s_customhandler = delayslot_clear_cause | |
| uint32_t | excode = (s_cause >> 2) & 0x1f |
| uint32_t | bd = s_cause >> 31 |
| #define CESTER_MAYBE_TEST CESTER_TEST |
| #define CESTER_NO_SIGNAL |
| #define CESTER_NO_TIME |
| #define EXIT_FAILURE 1 |
| #define EXIT_SUCCESS 0 |
| #define PCSX_TESTS 0 |
| cester_assert_uint_eq | ( | (uint32_t) | delayslot_mark, |
| s_epc | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| * | ptr | ||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| bd | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| delayslot_taken | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| excode | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| s_epc | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| s_from | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| s_got40 | |||
| ) |
| cester_assert_uint_eq | ( | 0 | , |
| s_got80 | |||
| ) |
| cester_assert_uint_eq | ( | 0x01020004 | , |
| * | ptr | ||
| ) |
| cester_assert_uint_eq | ( | 0x01020304 | , |
| * | ptr | ||
| ) |
| cester_assert_uint_eq | ( | 0x3000002c | , |
| ce | |||
| ) |
| cester_assert_uint_eq | ( | 0x40 | , |
| s_from | |||
| ) |
| cester_assert_uint_eq | ( | 0xf04fff3d | , |
| mask | |||
| ) |
| cester_assert_uint_eq | ( | 1 | , |
| * | ptr | ||
| ) |
| cester_assert_uint_eq | ( | 1 | , |
| s_got40 | |||
| ) |
| cester_assert_uint_eq | ( | 1 | , |
| s_got80 | |||
| ) |
| cester_assert_uint_eq | ( | expectedEPC | , |
| s_epc | |||
| ) |
| CESTER_MAYBE_TEST | ( | cpu_cop0_cu1_unusable | , |
| cpu_tests | , | ||
| uint32_t | old, | ||
| sr;__asm__ volatile("mfc0 %0, $12\nnop" :"=r"(old)); | sr = old & ~0x20000000; __asm__ volatile("mtc0 %0, $12\nnop\nnop" : : "r"(sr)); __asm__ volatile(".word 0x44080000" : : : "t0"); __asm__ volatile("mtc0 %0, $12\nnop\nnop" : : "r"(old)); cester_assert_uint_eq(1, s_got80); uint32_t ce = s_cause & 0x3000007c; cester_assert_uint_eq(0x1000002c, ce); |
||
| ) |
| CESTER_TEST | ( | cpu_ADD_overflow_in_delay_slot | , |
| CESTER_TEST( | cpu_tests, | ||
| s_resume | = (uint32_t *)delayslot_resume; uint32_t branch = delayslot_add(); uint32_t excode = (s_cause >> 2) & 0x1f; uint32_t bd = s_cause >> 31; cester_assert_uint_eq(1, s_got80); cester_assert_uint_eq(12, excode); cester_assert_uint_eq(1, bd); cester_assert_uint_eq(branch, s_epc); |
||
| ) |
| CESTER_TEST | ( | cpu_cop0_basic_write_bp | , |
| cpu_tests | , | ||
| uint32_t expectedEPC;uint32_t t;volatile uint32_t * | ptr = (volatile uint32_t *) 0x58; *ptr = 1; __asm__ volatile(""" lui %0, 0b1100101010000000\n"" mtc0 %0, $7\n"" li %0, 0x58\n"" mtc0 %0, $5\n"" li %0, 0xfffffff0\n"" mtc0 %0, $9\n" : "=r"(t)); cester_assert_uint_eq(1, *ptr); __asm__ volatile("la %0, 1f\n1:\nsw $0, 0x58($0)" : "=r"(expectedEPC)); __asm__ volatile("mtc0 $0, $7\n"); cester_assert_uint_eq(0, *ptr); cester_assert_uint_eq(1, s_got40); cester_assert_uint_eq(0, s_got80); cester_assert_uint_eq(0x40, s_from); cester_assert_uint_eq(expectedEPC, s_epc); |
||
| ) |
| CESTER_TEST | ( | cpu_cop0_kseg_write_bp_kd_clear | , |
| cpu_tests | , | ||
| uint32_t t;volatile uint32_t * | ptr = (volatile uint32_t *) 0x80000058; *ptr = 1; __asm__ volatile(""" lui %0, 0b1100101010000000\n"" mtc0 %0, $7\n"" li %0, 0x58\n"" mtc0 %0, $5\n"" li %0, 0x1fffffff\n"" mtc0 %0, $9\n" : "=r"(t)); cester_assert_uint_eq(1, *ptr); __asm__ volatile("lui $at, 0x8000\nsw $0, 0x58($at)"); __asm__ volatile("mtc0 $0, $7\n"); cester_assert_uint_eq(0, *ptr); cester_assert_uint_eq(0, s_got40); cester_assert_uint_eq(0, s_got80); |
||
| ) |
| CESTER_TEST | ( | cpu_cop0_upper_memory_write_bp | , |
| cpu_tests | , | ||
| uint32_t t;volatile uint32_t * | ptr = (volatile uint32_t *) 0x00200058; *ptr = 1; __asm__ volatile(""" lui %0, 0b1100101010000000\n"" mtc0 %0, $7\n"" li %0, 0x58\n"" mtc0 %0, $5\n"" li %0, 0xfffffff0\n"" mtc0 %0, $9\n" : "=r"(t)); cester_assert_uint_eq(1, *ptr); __asm__ volatile("lui $at, 0x0020\nsw $0, 0x58($at)"); __asm__ volatile("mtc0 $0, $7\n"); cester_assert_uint_eq(0, *ptr); cester_assert_uint_eq(0, s_got40); cester_assert_uint_eq(0, s_got80); cester_assert_uint_eq(0, s_from); cester_assert_uint_eq(0, s_epc); |
||
| ) |
| CESTER_TEST | ( | cpu_software_interrupt | , |
| cpu_tests | , | ||
| uint32_t sr;__asm__ volatile("mfc0 %0, $12\nnop" :"=r"(sr)); | s_customhandler = delayslot_clear_cause; __asm__ volatile("mtc0 %0, $12\nnop\nnop" : : "r"((sr & ~0xff00) | 0x101)); uint32_t next = plain_swi(); __asm__ volatile("mtc0 %0, $12\nnop\nnop" : : "r"(sr)); s_customhandler = NULL; uint32_t excode = (s_cause >> 2) & 0x1f; uint32_t bd = s_cause >> 31; cester_assert_uint_eq(1, s_got80); cester_assert_uint_eq(0, excode); cester_assert_uint_eq(0, bd); cester_assert_uint_eq(next, s_epc); cester_assert_uint_eq(0, delayslot_taken); |
||
| ) |
| CESTER_TEST | ( | cpu_unaligned_write_fault | , |
| CESTER_MAYBE_TEST( | cpu_tests, | ||
| uint32_t expectedEPC;__asm__ volatile("la %0, 1f\n1:\nsw $0, 1($0)" :"=r"(expectedEPC));cester_assert_uint_eq(0, s_got40);cester_assert_uint_eq(1, s_got80);cester_assert_uint_eq(0x80, s_from);cester_assert_uint_eq(expectedEPC, s_epc); | |||
| ) |
| delayslot_swi | ( | ) |
| __asm__ volatile | ( | "" " lui % | 0, |
| 0b1100101010000000\n" " mtc0 % | 0, | ||
| $7\n" " li %, | |||
| 0x58\n" " mtc0 % | 0, | ||
| $5\n" " li %, | |||
| 0xfffffff0\n" " mtc0 % | 0 | ||
| ) |
| __asm__ volatile | ( | "" " lui % | 0, |
| 0b1110101010000000\n" " mtc0 % | 0, | ||
| $7\n" " li %, | |||
| 0x58\n" " mtc0 % | 0, | ||
| $5\n" " li %, | |||
| 0x1fffffff\n" " mtc0 % | 0 | ||
| ) |
| __asm__ volatile | ( | ".word 0x4c080000" :::"t0" | ) |
| __asm__ volatile | ( | "la % | 0, |
| 1f\n1:\nsb | $0 | ||
| ) |
| __asm__ volatile | ( | "lui | $at, |
| 0x8000\nla % | 0, | ||
| 1f\n1:\nsw | $0 | ||
| ) |
| __asm__ volatile | ( | "lui | $at, |
| 0x8000\nsw | $0, | ||
| 0x58($at)" | |||
| ) |
| __asm__ volatile | ( | "mfc0 % | 0 | ) |
| __asm__ volatile | ( | "mtc0 | $0, |
| $7\n" | |||
| ) |
| __asm__ volatile | ( | "mtc0 % | 0, |
| $12\nnop\nnop" ::"r" | (sr &~0xff00)|0x101 | ||
| ) |
| __asm__ volatile | ( | "mtc0 % | 0, |
| $12\nnop\nnop" ::"r" | old | ||
| ) |
| __asm__ volatile | ( | "mtc0 % | 0, |
| $12\nnop\nnop" ::"r" | sr | ||
| ) |
| uint32_t bd = s_cause >> 31 |
| uint32_t ce = s_cause & 0x3000007c |
| cpu_tests |
| uint32_t excode = (s_cause >> 2) & 0x1f |
| uint32_t expectedEPC |
| uint32_t old |
| * ptr = (volatile uint32_t *) 0x80000058 |
| s_customhandler = delayslot_clear_cause |
| uint32_t sr = old & ~0x80000000 |
| uint32_t t |