Skip to content

Commit 89c8e0c

Browse files
committed
added tinyload, improved some definitions in headers.
1 parent c13a481 commit 89c8e0c

33 files changed

+2339
-398
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
make -C src/mips/serial -j 2
2222
make -C src/mips/hello -j 2
2323
make -C src/mips/pshittyload -j 2
24+
make -C src/mips/tinyload -j 2
2425
make -C src/mips/shell -j 2
2526
make -C src/mips/openbios -j 2
2627

src/mips/ps1sdk/include/cop0regs.h

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* COP0 Registers */
2+
3+
#ifndef _COP0REGS_H
4+
#define _COP0REGS_H
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
/* BreakPoint Control */
11+
#define C0_BPC $3
12+
/* BreakPoint on Data Access */
13+
#define C0_BDA $5
14+
/* BreakPoint on Data Access */
15+
#define C0_DCIC $7
16+
/* Bad Virtual Address */
17+
#define C0_BADVADDR $8
18+
// Breakpoint Data Access Mask
19+
#define C0_BDAM $9
20+
// Breakpoint Program Counter Mask
21+
#define C0_BPCM $11
22+
23+
/* Status Register */
24+
#define C0_STATUS $12
25+
26+
/* Cause Register */
27+
#define C0_CAUSE $13
28+
29+
/* Error PC Register */
30+
#define C0_EPC $14
31+
32+
/* Processor ID */
33+
#define C0_PRID $15
34+
35+
// Interrupt Enable(current)
36+
#define C0_SR_IEC (1 << 0)
37+
// Kernel/User mode(current)
38+
#define C0_SR_KUC (1 << 1)
39+
// Interrupt Enable(previous)
40+
#define C0_SR_IEP (1 << 2)
41+
// Kernel/User mode(previous)
42+
#define C0_SR_KUP (1 << 3)
43+
// Interrupt Enable(old)
44+
#define C0_SR_IEO (1 << 4)
45+
// Kernel/User mode(old)
46+
#define C0_SR_KUO (1 << 5)
47+
48+
/* Interrupt Mask 0 */
49+
#define C0_SR_IMO (1 << 8)
50+
/* Interrupt Mask 1 */
51+
#define C0_SR_IM1 (1 << 9)
52+
/* Interrupt Mask 2 */
53+
#define C0_SR_IM2 (1 << 10)
54+
/* Interrupt Mask 3 */
55+
#define C0_SR_IM3 (1 << 11)
56+
/* Interrupt Mask 4 */
57+
#define C0_SR_IM4 (1 << 12)
58+
/* Interrupt Mask 5 */
59+
#define C0_SR_IM5 (1 << 13)
60+
/* Interrupt Mask 6 */
61+
#define C0_SR_IM6 (1 << 14)
62+
/* Interrupt Mask 7 */
63+
#define C0_SR_IM7 (1 << 15)
64+
65+
/* Isolate Cache */
66+
#define C0_SR_ISC (1 << 16)
67+
/* Swap Caches */
68+
#define C0_SR_SWC (1 << 17)
69+
/* Parity Zero */
70+
#define C0_SR_PZ (1 << 18)
71+
/* Cache Miss */
72+
#define C0_SR_CM (1 << 19)
73+
/* Parity Error */
74+
#define C0_SR_PE (1 << 20)
75+
/* TLB Shutdown */
76+
#define C0_SR_TS (1 << 21)
77+
/* Boot-time Exception Vector */
78+
#define C0_SR_BEV (1 << 22)
79+
80+
/* Reverse Endian enable */
81+
#define C0_SR_RE (1 << 25)
82+
83+
/* Coprocessor 0 Usable */
84+
#define C0_SR_CU0 (1 << 28)
85+
/* Coprocessor 1 Usable */
86+
#define C0_SR_CU1 (1 << 29)
87+
/* Coprocessor 2 Usable */
88+
#define C0_SR_CU2 (1 << 30)
89+
/* Coprocessor 3 Usable */
90+
#define C0_SR_CU3 (1 << 31)
91+
92+
// R3000A COP0 DCIC register bits
93+
94+
/* These are R/W, used to enable/disable various debug/cache things */
95+
#define C0_DCIC_TR (1 << 31) /* Trap enable */
96+
#define C0_DCIC_UD (1 << 30) /* User debug enable */
97+
#define C0_DCIC_KD (1 << 29) /* Kernel debug enable */
98+
#define C0_DCIC_TE (1 << 28) /* Trace enable */
99+
#define C0_DCIC_DW (1 << 27) /* Enable data access breakpoints on write */
100+
#define C0_DCIC_DR (1 << 26) /* Enable data access breakpoints on read */
101+
#define C0_DCIC_DAE (1 << 25) /* Enable data addresss breakpoints(Is this valid?) */
102+
#define C0_DCIC_PCE (1 << 24) /* Enable instruction breakpoints */
103+
#define C0_DCIC_DE (1 << 23) /* Debug Enable */
104+
#define C0_DCIC_DL (1 << 15) /* Data cache line invalidate */
105+
#define C0_DCIC_IL (1 << 14) /* Instruction cache line invalidate */
106+
#define C0_DCIC_D (1 << 13) /* Data cache invalidate enable */
107+
#define C0_DCIC_I (1 << 12) /* Instr. cache invalidate enable */
108+
/* The rest of these are R/O, set by the CPU to indicate the type of debug exception that occured */
109+
#define C0_DCIC_T (1 << 5) /* Trace */
110+
#define C0_DCIC_W (1 << 4) /* Write reference */
111+
#define C0_DCIC_R (1 << 3) /* Read reference */
112+
#define C0_DCIC_DA (1 << 2) /* Data address */
113+
#define C0_DCIC_PC (1 << 1) /* Program counter */
114+
#define C0_DCIC_DB (1 << 0) /* Debug */
115+
116+
#ifdef __cplusplus
117+
}
118+
#endif
119+
120+
#endif /* _COP0REGS_H */

src/mips/ps1sdk/include/dma.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* PS1 DMA
3+
*/
4+
5+
#ifndef _PS1DMA_H
6+
#define _PS1DMA_H
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
// DMA channels
13+
// FIXME: properly define channels 5 and 6
14+
#define PS1_DMA_CH_MDEC_IN (0)
15+
#define PS1_DMA_CH_MDEC_OUT (1)
16+
#define PS1_DMA_CH_GPU (2)
17+
#define PS1_DMA_CH_CDROM (3)
18+
#define PS1_DMA_CH_SPU (4)
19+
#define PS1_DMA_CH_5 (5)
20+
#define PS1_DMA_CH_6 (6)
21+
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
#endif /* _PS1DMA_H */

src/mips/ps1sdk/include/exec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int ReadExecHeader(int fd, ExecInfo* exec);
5252
int LoadEx(const char* fname, ExecInfo* exec);
5353
int LoadExBuffer(const void* fbuf, ExecInfo* exec);
5454
void LoadExecEx(const void* f, uint32_t stack_addr, int stack_size);
55-
int ExecEx(ExecInfo* exec, int arg1, int arg2);
55+
int ExecEx(ExecInfo* exec, uint32_t stack_addr, uint32_t stack_size);
5656

5757
#ifdef __cplusplus
5858
}

src/mips/ps1sdk/include/fileio.h

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
extern "C" {
1515
#endif
1616

17+
/* IoBlock flags */
1718
#define O_RDONLY (0x0001)
1819
#define O_WRONLY (0x0002)
1920
#define O_RDWR (0x0003)
@@ -26,6 +27,7 @@ extern "C" {
2627

2728
#define FSCAN 0x1000
2829

30+
/* "whence" for seek functions */
2931
#ifndef SEEK_SET
3032
#define SEEK_SET 0
3133
#endif
@@ -37,13 +39,15 @@ extern "C" {
3739
#endif
3840

3941
/* device types */
42+
/* for DeviceDriver.type */
4043
#define DEV_TYPE_CHAR (1 << 0) /* character device */
4144
#define DEV_TYPE_TTY (1 << 1) /* TTY/console */
4245
#define DEV_TYPE_BLOCK (1 << 2) /* block device */
4346
#define DEV_TYPE_RAW (1 << 3) /* raw device that uses fs switch */
4447
#define DEV_TYPE_FS (1 << 4)
4548

4649
/* device FIFO flags */
50+
/* for device_fifo.flags */
4751
#define DEV_FIFO_RAW (1 << 0) /* don't interpret special chars */
4852
#define DEV_FIFO_STOPPED (1 << 1) /* stop output */
4953
#define DEV_FIFO_BREAK (1 << 2) /* cntl-c raise console interrpt */
@@ -56,50 +60,51 @@ typedef struct st_device_fifo {
5660
char buf[256]; // 0x0C - FIFO buffer.
5761
} device_fifo;
5862

59-
#define M_FIFO_FLUSH(__fifo) ((__fifo)->rd_ptr = (__fifo)->wr_ptr = (__fifo)->buf)
63+
#define M_FIFO_PURGE(__fifo) ((__fifo)->rd_ptr = (__fifo)->wr_ptr = (__fifo)->buf)
6064
#define M_IS_FIFO_EMPTY(__fifo) ((__fifo)->rd_ptr == (__fifo)->wr_ptr)
6165
#define M_IS_FIFO_STOPPED(__fifo) ((__fifo)->flags & DEV_FIFO_STOPPED)
6266
#define stdin (0)
6367
#define stdout (1)
6468

6569
/* sizeof() == 0x2C(44) */
6670
typedef struct st_PS1_IoBlock {
67-
int flags; // 0x00
68-
int dev_no; // 0x04
69-
char* buf; // 0x08 - address of the I/O buffer.
70-
uint32_t ccount; // 0x0C - character count
71-
uint32_t cur_pos; // 0x10 - current position in file.
72-
int fstype; // 0x14 - type of file system.
73-
int errno; // 0x18 - last "errno"
74-
struct st_FileSystemDriver* fsd; // 0x1C - pointer to fsd
75-
uint32_t size; // 0x20
76-
uint32_t head; // 0x24
77-
uint32_t fd; // 0x28 file descriptor
71+
int flags; // 0x00 - see IoBlock flags(TODO: fixme?)
72+
int dev_no; // 0x04 - ?
73+
char* buf; // 0x08 - address of the I/O buffer.
74+
uint32_t ccount; // 0x0C - character count
75+
uint32_t cur_pos; // 0x10 - current position in file.
76+
int fstype; // 0x14 - type of file system.
77+
int errno; // 0x18 - last "errno"
78+
struct st_DeviceDriver* dd; // 0x1C - pointer to fsd
79+
uint32_t size; // 0x20 - file size?
80+
uint32_t head; // 0x24 - ?
81+
uint32_t fd; // 0x28 file descriptor
7882
} IoBlock;
7983

84+
#warning "FIXME: add argument names to prototypes in DeviceDriver struct in fileio.h"
8085
/* sizeof() == 0x50(80) */
81-
typedef struct st_FileSystemDriver {
82-
const char* name; // 0x00 - pointer to unique name identifying file system.
83-
uint32_t modes; // 0x04 -
86+
typedef struct st_DeviceDriver {
87+
const char* name; // 0x00 - pointer to unique name identifying device.
88+
uint32_t type; // 0x04 - bitmask. see Device Types.
8489
uint32_t block_size; // 0x08 - size, in bytes, of a block.
85-
const char* desc; // 0x0C - pointer to ASCII-Z description of file system.
86-
int (*init)(); // 0x10 - pointer to "init" function. Called by AddDevice()
87-
int (*open)(); // 0x14 - pointer to "open" function.
88-
int (*strategy)(); // 0x18 - pointer to "strategy" function.
89-
int (*close)(); // 0x1C - pointer to "close" function.
90-
int (*ioctl)(); // 0x20 - pointer to "ioctl" function.
91-
int (*read)(); // 0x24 - pointer to "read" function.
92-
int (*write)(); // 0x28 - pointer to "write" function.
93-
int (*delete)(); // 0x2C - pointer to "delete" function.
94-
int (*undelete)(); // 0x30 - pointer to "undelete" function.
90+
const char* desc; // 0x0C - pointer to ASCII-Z description of device.
91+
int (*init)(IoBlock *iob); // 0x10 - pointer to "init" function. Called by AddDevice()
92+
int (*open)(IoBlock *iob, const char *fname, int mode); // 0x14 - pointer to "open" function.
93+
int (*strategy)(IoBlock *iob, int cmd); // 0x18 - pointer to "strategy" function.
94+
int (*close)(IoBlock *iob); // 0x1C - pointer to "close" function.
95+
int (*ioctl)(IoBlock *iob, int cmd, int param); // 0x20 - pointer to "ioctl" function.
96+
int (*read)(IoBlock *iob, void *p, int size); // 0x24 - pointer to "read" function.
97+
int (*write)(IoBlock *iob, const void *p, int size); // 0x28 - pointer to "write" function.
98+
int (*delete)(IoBlock *iob, const char *name); // 0x2C - pointer to "delete" function.
99+
int (*undelete)(IoBlock *iob, const char *name); // 0x30 - pointer to "undelete" function.
95100
int (*firstfile)(); // 0x34 - pointer to "firstfile" function.
96101
int (*nextfile)(); // 0x38 - pointer to "nextfile" function.
97102
int (*format)(); // 0x3C - pointer to "format" function.
98-
int (*chdir)(); // 0x40 - pointer to "cd" function.
99-
int (*rename)(); // 0x44 - pointer to "rename" function.
100-
int (*deinit)(); // 0x48 - pointer to "deinit" function. Called by RemDevice()
101-
int (*call15)(); // 0x4C - pointer to "lseek" function.
102-
} FileSystemDriver;
103+
int (*chdir)(const char *path); // 0x40 - pointer to "cd" function.
104+
int (*rename)(const char *oldname, const char *newname); // 0x44 - pointer to "rename" function.
105+
int (*deinit)(IoBlock *iob); // 0x48 - pointer to "deinit" function. Called by RemDevice()
106+
int (*lseek)(IoBlock*iob, int pos, int whence); // 0x4C - pointer to "lseek" function.
107+
} DeviceDriver;
103108

104109
typedef struct st_DirEntry {
105110
char name[20]; // 0x00 - ASCII file name.
@@ -110,24 +115,13 @@ typedef struct st_DirEntry {
110115
uint8_t system[4]; // 0x24 - ??? unused?
111116
} DirEntry;
112117

113-
int AddDevice(const FileSystemDriver* fsd);
114-
int DelDevice(const char* fs_name);
118+
int AddDevice(const DeviceDriver* dd);
119+
int DelDevice(const char* dev_name);
115120

116-
int open(const char*, uint32_t);
117-
int close(int);
118-
int lseek(int, int, int);
119-
int read(int, void*, int);
120-
int write(int, const void*, int);
121-
int ioctl(int, int, int);
121+
#warning "FIXME: add argument names to prototypes in fileio.h"
122122
DirEntry* firstfile(const char*, DirEntry*);
123123
DirEntry* nextfile(DirEntry*);
124124

125-
int erase(const char*);
126-
int undelete(const char*);
127-
int format(const char*);
128-
int rename(const char*, const char*);
129-
int chdir(const char*);
130-
131125
#ifdef __cplusplus
132126
}
133127
#endif

src/mips/ps1sdk/include/helpers.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
# _____ ___ __ ___ ____
3+
# ____| | | | | |____|
4+
# | ___| ___| ___| ____| | \
5+
#-----------------------------------------------------------------------
6+
#
7+
# Misc. Helpers
8+
#
9+
*/
10+
11+
#ifndef _HELPERS_H
12+
#define _HELPERS_H
13+
14+
#include <stddef.h>
15+
#include <sys/types.h>
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
uint32_t C0_get_BPC(void);
22+
uint32_t C0_get_BDA(void);
23+
uint32_t C0_get_DCIC(void);
24+
uint32_t C0_get_BADVADDR(void);
25+
uint32_t C0_get_BDAM(void);
26+
uint32_t C0_get_BPCM(void);
27+
uint32_t C0_get_STATUS(void);
28+
uint32_t C0_get_CAUSE(void);
29+
uint32_t C0_get_EPC(void);
30+
uint32_t C0_get_PRID(void);
31+
32+
void C0_set_BPC(uint32_t v);
33+
void C0_set_BDA(uint32_t v);
34+
void C0_set_DCIC(uint32_t v);
35+
void C0_set_BADVADDR(uint32_t v);
36+
void C0_set_BDAM(uint32_t v);
37+
void C0_set_BPCM(uint32_t v);
38+
void C0_set_STATUS(uint32_t v);
39+
void C0_set_CAUSE(uint32_t v);
40+
void C0_set_EPC(uint32_t v);
41+
void C0_set_PRID(uint32_t v);
42+
43+
#ifdef __cplusplus
44+
}
45+
#endif
46+
47+
#endif /* _HELPERS_H */

0 commit comments

Comments
 (0)