Add Makefile, implement more instructions

This commit is contained in:
Lycoder
2023-05-26 14:56:46 -03:00
parent babfdd8423
commit cf0b2a9a6c
4 changed files with 277 additions and 109 deletions
+20
View File
@@ -0,0 +1,20 @@
.ONESHELL:
VERSION_TAG := $(shell git describe --always --tags --abbrev=0)
COMMIT_HASH := $(shell git rev-parse --short HEAD)
OS_INFO := $(shell uname -rmo)
SOURCES := $(wildcard psx/*.c)
SOURCES += main.c
bin/psxe main.c:
mkdir -p bin
gcc $(SOURCES) -o bin/psxe \
-DOS_INFO="$(OS_INFO)" \
-DREP_VERSION="$(VERSION_TAG)" \
-DREP_COMMIT_HASH="$(COMMIT_HASH)" \
-g -DLOG_USE_COLOR
clean:
rm -rf "bin"
+6 -2
View File
@@ -16,11 +16,15 @@ void psx_bios_init(psx_bios_t* bios) {
void psx_bios_load(psx_bios_t* bios, const char* path) {
FILE* file = fopen(path, "rb");
if (!file) {
log_error("Couldn't open BIOS file \"%s\", path");
exit(1);
}
fread(bios->buf, 1, PSX_BIOS_SIZE, file);
#ifdef PSXE_DEBUG_BIOS
log_info("Loaded BIOS file \"%s\"", path);
#endif
fclose(file);
}
+122 -106
View File
File diff suppressed because it is too large Load Diff
+129 -1
View File
@@ -6,14 +6,142 @@
#include "bus.h"
typedef struct {
// Pointer to bus structure
psx_bus_t* bus;
// Registers (including $zero and $ra)
uint32_t r[32];
uint32_t buf[2], pc;
// Pipeline simulation (for branch delay slots)
uint32_t buf[2];
// Program Counter
uint32_t pc;
// Result registers for mult and div
uint32_t hi, lo;
/*
cop0r0 - N/A
cop0r1 - N/A
cop0r2 - N/A
cop0r3 - BPC - Breakpoint on execute (R/W)
cop0r4 - N/A
cop0r5 - BDA - Breakpoint on data access (R/W)
cop0r6 - JUMPDEST - Randomly memorized jump address (R)
cop0r7 - DCIC - Breakpoint control (R/W)
cop0r8 - BadVaddr - Bad Virtual Address (R)
cop0r9 - BDAM - Data Access breakpoint mask (R/W)
cop0r10 - N/A
cop0r11 - BPCM - Execute breakpoint mask (R/W)
cop0r12 - SR - System status register (R/W)
cop0r13 - CAUSE - Describes the most recently recognised exception (R)
cop0r14 - EPC - Return Address from Trap (R)
cop0r15 - PRID - Processor ID (R)
*/
// r3 - BPC - Breakpoint on execute (R/W)
uint32_t cop0_bpc;
// r5 - BDA - Breakpoint on data access (R/W)
uint32_t cop0_bda;
// r6 - JUMPDEST - Randomly memorized jump address (R)
uint32_t cop0_jumpdest;
// r7 - DCIC - Breakpoint control (R/W)
uint32_t cop0_dcic;
// r8 - BadVaddr - Bad Virtual Address (R)
uint32_t cop0_badvaddr;
// r9 - BDAM - Data Access breakpoint mask (R/W)
uint32_t cop0_bdam;
// r11 - BPCM - Execute breakpoint mask (R/W)
uint32_t cop0_bpcm;
// r12 - SR - System status register (R/W)
uint32_t cop0_sr;
// r13 - CAUSE - Describes the most recently recognised exception (R)
uint32_t cop0_cause;
// r14 - EPC - Return Address from Trap (R)
uint32_t cop0_epc;
// r15 - PRID - Processor ID (R)
uint32_t cop0_prid;
} psx_cpu_t;
/*
0 IEc Current Interrupt Enable (0=Disable, 1=Enable) ;rfe pops IUp here
1 KUc Current Kernel/User Mode (0=Kernel, 1=User) ;rfe pops KUp here
2 IEp Previous Interrupt Disable ;rfe pops IUo here
3 KUp Previous Kernel/User Mode ;rfe pops KUo here
4 IEo Old Interrupt Disable ;left unchanged by rfe
5 KUo Old Kernel/User Mode ;left unchanged by rfe
6-7 - Not used (zero)
8-15 Im 8 bit interrupt mask fields. When set the corresponding
interrupts are allowed to cause an exception.
16 Isc Isolate Cache (0=No, 1=Isolate)
When isolated, all load and store operations are targetted
to the Data cache, and never the main memory.
(Used by PSX Kernel, in combination with Port FFFE0130h)
17 Swc Swapped cache mode (0=Normal, 1=Swapped)
Instruction cache will act as Data cache and vice versa.
Use only with Isc to access & invalidate Instr. cache entries.
(Not used by PSX Kernel)
18 PZ When set cache parity bits are written as 0.
19 CM Shows the result of the last load operation with the D-cache
isolated. It gets set if the cache really contained data
for the addressed memory location.
20 PE Cache parity error (Does not cause exception)
21 TS TLB shutdown. Gets set if a programm address simultaneously
matches 2 TLB entries.
(initial value on reset allows to detect extended CPU version?)
22 BEV Boot exception vectors in RAM/ROM (0=RAM/KSEG0, 1=ROM/KSEG1)
23-24 - Not used (zero)
25 RE Reverse endianness (0=Normal endianness, 1=Reverse endianness)
Reverses the byte order in which data is stored in
memory. (lo-hi -> hi-lo)
(Affects only user mode, not kernel mode) (?)
(The bit doesn't exist in PSX ?)
26-27 - Not used (zero)
28 CU0 COP0 Enable (0=Enable only in Kernel Mode, 1=Kernel and User Mode)
29 CU1 COP1 Enable (0=Disable, 1=Enable) (none in PSX)
30 CU2 COP2 Enable (0=Disable, 1=Enable) (GTE in PSX)
31 CU3 COP3 Enable (0=Disable, 1=Enable) (none in PSX)
*/
#define SR_IEC 0x00000001
#define SR_KUC 0x00000002
#define SR_IEP 0x00000004
#define SR_KUP 0x00000008
#define SR_IEO 0x00000010
#define SR_KUO 0x00000020
#define SR_IM 0x0000ff00
#define SR_IM0 0x00000100
#define SR_IM1 0x00000200
#define SR_IM2 0x00000400
#define SR_IM3 0x00000800
#define SR_IM4 0x00001000
#define SR_IM5 0x00002000
#define SR_IM6 0x00004000
#define SR_IM7 0x00008000
#define SR_ISC 0x00010000
#define SR_SWC 0x00020000
#define SR_PZ 0x00040000
#define SR_CM 0x00080000
#define SR_PE 0x00100000
#define SR_TS 0x00200000
#define SR_BEV 0x00400000
#define SR_RE 0x02000000
#define SR_CU0 0x10000000
#define SR_CU1 0x20000000
#define SR_CU2 0x40000000
#define SR_CU3 0x80000000
psx_cpu_t* psx_cpu_create();
void psx_cpu_init(psx_cpu_t*, psx_bus_t*);
void psx_cpu_destroy(psx_cpu_t*);