Skip to content

Commit

Permalink
(wip) cpu/code-in-scratchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Dec 25, 2019
1 parent 5ac8a68 commit 57f7871
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 21 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TOPTARGETS = build clean

IMAGES = common \
cpu/code-in-scratchpad \
gpu/bandwidth \
gpu/benchmark \
gpu/quad \
Expand Down
51 changes: 36 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,45 @@ Collection of PlayStation 1 tests for emulator development and hardware verifica

## Tests

### CPU

Name | Description
-------------------------|------------
code-in-scratchpad | **(Not finished)** Check whether code execution from Scratchpad is possible

### GPU

Name | Description
-------------------------|------------
bandwidth | Measure GPU/VRAM bandwidth
benchmark | GPU test to benchmark rasterizer for various commands
quad | Semi-transparent polygon commands - for testing fill rules and transparency handling
transparency | Draws rectangles with 4 semi-transparent blending modes
triangle | Draws Gouroud shaded equilateral triangle
lines | Draws lines using different modes - for verifying Bresenham implementation, color blending, polyline handling
rectangles | Draws all combinations of Rectangle commands
texture-overflow | Draws textured rectangle with UV overflowing VRAM width
mask-bit | Check Mask bit behavior during VRAM copy operations
gp0-e1 | Check if GP0_E1, GPUSTAT and polygon render uses the same register internally
vram-to-vram-overlap | Test GP0(80) VRAM-VRAM copy behaviour in overlapping rects

### GTE

Name | Description
-------------------------|------------
gpu/bandwidth | Measure GPU/VRAM bandwidth
gpu/benchmark | GPU test to benchmark rasterizer for various commands
gpu/quad | Semi-transparent polygon commands - for testing fill rules and transparency handling
gpu/transparency | Draws rectangles with 4 semi-transparent blending modes
gpu/triangle | Draws Gouroud shaded equilateral triangle
gpu/lines | Draws lines using different modes - for verifying Bresenham implementation, color blending, polyline handling
gpu/rectangles | Draws all combinations of Rectangle commands
gpu/texture-overflow | Draws textured rectangle with UV overflowing VRAM width
gpu/mask-bit | Check Mask bit behavior during VRAM copy operations
gpu/gp0-e1 | Check if GP0_E1, GPUSTAT and polygon render uses the same register internally
gpu/vram-to-vram-overlap | Test GP0(80) VRAM-VRAM copy behaviour in overlapping rects
gte-fuzz | Executes GTE opcodes with random parameters, can be used to verify against real console
spu/test | Check SPU behavior (data is lost randomly on 32bit access, ok on 16bit)
spu/stereo | Play samples on first two voices

### SPU

Name | Description
-------------------------|------------
test | Check SPU behavior (data is lost randomly on 32bit access, ok on 16bit)
stereo | Play samples on first two voices

### Timer

Name | Description
-------------------------|------------
timers | Run Timer0,1,2 using various clock sources and sync modes and time them using busy loops and vblank interrupt

Note: Make sure your PS-EXE loaded does set default value for Stack Pointer - these .exes has SP set to 0.
Expand Down Expand Up @@ -48,5 +71,3 @@ diffvram | Diff two images and write diff png if image contents aren
```
docker run -it -v $(pwd):/build jaczekanski/psn00bsdk:latest make
```

Note: requires Docker
8 changes: 4 additions & 4 deletions common-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ LIBS += -lcommon -lpsxetc -lpsxgpu -lpsxapi -lc

TARGET_EXE := $(TARGET:.elf=.exe)

$(TARGET): $(OFILES)
build/$(TARGET): $(OFILES)
@echo "LD $(TARGET)"
@$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
@$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o build/$(TARGET)

$(TARGET_EXE): $(TARGET)
$(TARGET_EXE): build/$(TARGET)
@echo "ELF2X $(TARGET:.elf=.exe)"
@elf2x -q $(TARGET)
@elf2x -q build/$(TARGET) $(TARGET_EXE)

all: $(TARGET_EXE)

Expand Down
7 changes: 5 additions & 2 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ include ../common.mk

TARGET = libcommon.a

all: $(TARGET)

$(TARGET): $(OFILES)
@echo "AR $(TARGET)"
@$(AR) cr $(TARGET) $(OFILES)
@echo "RANLIB $(TARGET)"
@$(RANLIB) $(TARGET)

all: $(TARGET)

clean:
rm -Rf build $(TARGET)

.PHONY: all clean
.DEFAULT_GOAL := $(TARGET)
3 changes: 3 additions & 0 deletions cpu/code-in-scratchpad/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TARGET = code-in-scratchpad.elf

include ../../common-test.mk
6 changes: 6 additions & 0 deletions cpu/code-in-scratchpad/code.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <stdint.h>

void FlushCache();
uint32_t codeRam();
uint32_t codeScratchpad();
43 changes: 43 additions & 0 deletions cpu/code-in-scratchpad/code.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <asm.h>
#include <inline_s.h>

.extern FlushCache
FlushCache:
li $t1, 0x44
li $t2, 0xa0
jr $t2
nop

getPc:
move $v0, $ra
jr $ra
nop

.globl codeRam
codeRam:
addiu $sp, -4
sw $ra, 0($sp)

la $t0, getPc
jalr $ra, $t0 # Get PC
nop

lw $ra, 0($sp)
addiu $sp, 4
jr $ra
nop

.globl codeScratchpad
codeScratchpad:
addiu $sp, -4
sw $ra, 0($sp)

la $t0, getPc
jalr $ra, $t0 # Get PC
nop

lw $ra, 0($sp)
addiu $sp, 4
jr $ra
nop

41 changes: 41 additions & 0 deletions cpu/code-in-scratchpad/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <common.h>
#include <psxapi.h>
#include <string.h>
#include "code.h"

uint32_t RAM_FUN_ADDR = 0x00040000;
uint32_t SCRATCHPAD_FUN_ADDR = 0x1F800000;

typedef uint32_t (*func)();

// TODO: This test is not fully finished
// It is only for testing whether PS1 can execute code from Scratchpad

int main() {
initVideo(320, 240);
printf("\ncpu/code-in-scratchpad\n");

clearScreen();

EnterCriticalSection();

memcpy((void*)RAM_FUN_ADDR, codeRam, 64);
memcpy((void*)SCRATCHPAD_FUN_ADDR, codeScratchpad, 64);

FlushCache();

func codeInRam = (func)RAM_FUN_ADDR;
func codeInScratchpad = (func)SCRATCHPAD_FUN_ADDR;

printf("Code in ram returned PC: 0x%08x\n", codeInRam());
printf("Code in scratchpad returned PC: 0x%08x\n", codeInScratchpad());
// ^^^ This line crashes on real HW

printf("Done\n");

ExitCriticalSection();
for (;;) {
VSync(0);
}
return 0;
}

0 comments on commit 57f7871

Please sign in to comment.