Skip to content

Commit 65f03d3

Browse files
committed
Merge branch 'master' of github.com:grumpycoders/pcsx-redux into pshittyload
2 parents 771a780 + 7b50ce1 commit 65f03d3

File tree

18 files changed

+438
-11
lines changed

18 files changed

+438
-11
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
[submodule "third_party/zstr"]
2020
path = third_party/zstr
2121
url = https://github.com/mateidavid/zstr.git
22+
[submodule "third_party/uC-sdk"]
23+
path = third_party/uC-sdk
24+
url = https://github.com/grumpycoders/uC-sdk.git

src/mips/common.mk

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ endif
1010

1111
TARGETBASE = $(basename $(TARGET))
1212

13-
ARCHFLAGS = -march=mips1 -mabi=32 -EL -msoft-float -Wa,-msoft-float -fno-pic -mno-shared -mno-abicalls
14-
ARCHFLAGS += -mno-gpopt -fomit-frame-pointer -nostartfiles -nostdinc -fno-builtin -fno-pic -fno-stack-protector
15-
13+
ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32
14+
ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding
15+
CPPFLAGS += -mno-gpopt -fomit-frame-pointer -ffunction-sections
1616
CPPFLAGS += -fno-builtin
1717
CPPFLAGS += $(ARCHFLAGS)
1818
CPPFLAGS += -I..
1919

2020
LDFLAGS += -Wl,-Map=$(TARGETBASE).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections
2121
LDFLAGS += $(ARCHFLAGS) -L../ps1sdk
2222

23-
LDFLAGS += -g -O3 -flto
24-
CPPFLAGS += -g -O3 -flto
23+
LDFLAGS += -g -Os
24+
CPPFLAGS += -g -Os
2525

2626
OBJS += $(addsuffix .o, $(basename $(SRCS)))
2727

src/mips/common/hardware/hwregs.h

+6
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@
3232
#define SPU_MVOL_R HW_U16(0x1f801d82)
3333
#define SPU_REVERB_L HW_U16(0x1f801d84)
3434
#define SPU_REVERB_R HW_U16(0x1f801d86)
35+
36+
#define SIO1_DATA HW_U8(0x1f801050)
37+
#define SIO1_STAT HW_U16(0x1f801054)
38+
#define SIO1_MODE HW_U16(0x1f801058)
39+
#define SIO1_CTRL HW_U16(0x1f80105a)
40+
#define SIO1_BAUD HW_U16(0x1f80105e)

src/mips/common/hardware/sio1.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
* Copyright (C) 2019 PCSX-Redux authors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18+
***************************************************************************/
19+
20+
#include "common/hardware/hwregs.h"
21+
#include "common/hardware/sio1.h"
22+
23+
void sio1_init() {
24+
// enable TX and RX, and nothing else
25+
SIO1_CTRL = 5;
26+
// 01001110
27+
// Baudrate Reload Factor: MUL16 (2)
28+
// Character length: 8 (3)
29+
// Parity Disabled
30+
// Parity Type: irrelevant
31+
// Stop bit length: 1 (1)
32+
// --> 8N1
33+
SIO1_MODE = 0x4e;
34+
SIO1_BAUD = 2073600 / 115200;
35+
}
36+
37+
void sio1_putc(uint8_t byte) {
38+
while ((SIO1_STAT & 1) == 0);
39+
SIO1_DATA = byte;
40+
}

src/mips/common/hardware/sio1.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************************************************************
2+
* Copyright (C) 2019 PCSX-Redux authors *
3+
* *
4+
* This program is free software; you can redistribute it and/or modify *
5+
* it under the terms of the GNU General Public License as published by *
6+
* the Free Software Foundation; either version 2 of the License, or *
7+
* (at your option) any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, *
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12+
* GNU General Public License for more details. *
13+
* *
14+
* You should have received a copy of the GNU General Public License *
15+
* along with this program; if not, write to the *
16+
* Free Software Foundation, Inc., *
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18+
***************************************************************************/
19+
20+
#pragma once
21+
22+
#include <stdint.h>
23+
24+
void sio1_init();
25+
void sio1_putc(uint8_t byte);

src/mips/openbios/Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,45 @@ TARGET = openbios.bin
22

33
SRCS = \
44
../common/hardware/cop0.s \
5+
../common/hardware/sio1.c \
56
boot/boot.s \
67
kernel/flushcache.s \
78
kernel/handlers.c \
89
kernel/vectors.s \
910
main/main.c \
11+
\
12+
uC-sdk-glue/BoardConsole.c \
13+
uC-sdk-glue/BoardInit.c \
14+
uC-sdk-glue/init.c \
15+
\
16+
../../../third_party/uC-sdk/libc/src/cxx-glue.c \
17+
../../../third_party/uC-sdk/libc/src/errno.c \
18+
../../../third_party/uC-sdk/libc/src/initfini.c \
19+
../../../third_party/uC-sdk/libc/src/malloc.c \
20+
../../../third_party/uC-sdk/libc/src/qsort.c \
21+
../../../third_party/uC-sdk/libc/src/rand.c \
22+
../../../third_party/uC-sdk/libc/src/reent.c \
23+
../../../third_party/uC-sdk/libc/src/stdio.c \
24+
../../../third_party/uC-sdk/libc/src/strto.c \
25+
../../../third_party/uC-sdk/libc/src/unistd.c \
26+
../../../third_party/uC-sdk/libc/src/xprintf.c \
27+
../../../third_party/uC-sdk/libc/src/xscanf.c \
28+
../../../third_party/uC-sdk/libc/src/yscanf.c \
29+
../../../third_party/uC-sdk/os/src/devfs.c \
30+
../../../third_party/uC-sdk/os/src/filesystem.c \
31+
../../../third_party/uC-sdk/os/src/fio.c \
32+
../../../third_party/uC-sdk/os/src/hash-djb2.c \
33+
../../../third_party/uC-sdk/os/src/init.c \
34+
../../../third_party/uC-sdk/os/src/osdebug.c \
35+
../../../third_party/uC-sdk/os/src/romfs.c \
36+
../../../third_party/uC-sdk/os/src/sbrk.c \
37+
1038

1139
LDSCRIPT = psx-bios.ld
1240

41+
CPPFLAGS = -DNOFLOATINGPOINT
42+
CPPFLAGS += -I../../../third_party/uC-sdk/libc/include
43+
CPPFLAGS += -I../../../third_party/uC-sdk/os/include
44+
CPPFLAGS += -IuC-sdk-glue
45+
1346
include ../common.mk

src/mips/openbios/boot/boot.s

+62-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,67 @@ bss_init:
176176
bne $t0, $t1, bss_init
177177

178178
bss_init_skip:
179+
/* Displays the following:
180+
181+
**********
182+
0123456789
183+
**********
184+
185+
*/
186+
li $t3, 42
187+
lui $t1, 0x1f00
188+
sb $t3, 0($t1)
189+
sb $t3, 0($t1)
190+
sb $t3, 0($t1)
191+
sb $t3, 0($t1)
192+
sb $t3, 0($t1)
193+
sb $t3, 0($t1)
194+
sb $t3, 0($t1)
195+
sb $t3, 0($t1)
196+
sb $t3, 0($t1)
197+
sb $t3, 0($t1)
198+
li $t0, 13
199+
sb $t0, 0($t1)
200+
li $t0, 10
201+
sb $t0, 0($t1)
202+
li $t0, '0'
203+
sb $t0, 0($t1)
204+
addiu $t0, 1
205+
sb $t0, 0($t1)
206+
addiu $t0, 1
207+
sb $t0, 0($t1)
208+
addiu $t0, 1
209+
sb $t0, 0($t1)
210+
addiu $t0, 1
211+
sb $t0, 0($t1)
212+
addiu $t0, 1
213+
sb $t0, 0($t1)
214+
addiu $t0, 1
215+
sb $t0, 0($t1)
216+
addiu $t0, 1
217+
sb $t0, 0($t1)
218+
addiu $t0, 1
219+
sb $t0, 0($t1)
220+
addiu $t0, 1
221+
sb $t0, 0($t1)
222+
li $t0, 13
223+
sb $t0, 0($t1)
224+
li $t0, 10
225+
sb $t0, 0($t1)
226+
sb $t3, 0($t1)
227+
sb $t3, 0($t1)
228+
sb $t3, 0($t1)
229+
sb $t3, 0($t1)
230+
sb $t3, 0($t1)
231+
sb $t3, 0($t1)
232+
sb $t3, 0($t1)
233+
sb $t3, 0($t1)
234+
sb $t3, 0($t1)
235+
sb $t3, 0($t1)
236+
li $t0, 13
237+
sb $t0, 0($t1)
238+
li $t0, 10
239+
sb $t0, 0($t1)
179240

180241
/* technically have to set $gp, but we are not using it, so, not */
181242
la $sp, __sp
@@ -185,7 +246,7 @@ bss_init_skip:
185246
li $t0, 0xb88
186247
sw $t0, RAM_SIZE
187248

188-
jal main
249+
jal _ucsdk_start
189250

190251
stop:
191252
b stop

src/mips/openbios/kernel/handlers.c

+19-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
1818
***************************************************************************/
1919

20+
#include "osdebug.h"
21+
2022
#include "openbios/kernel/handlers.h"
2123
#include "common/compiler/stdint.h"
2224

@@ -147,6 +149,22 @@ typedef struct {
147149
uint32_t EPC;
148150
} InterruptData;
149151

152+
static void printInterruptData(InterruptData* data) {
153+
osDbgPrintf("epc = %p - status = %p - cause = %p\r\n", data->EPC, data->SR, data->Cause);
154+
osDbgPrintf("r0 = %p - at = %p - v0 = %p - v1 = %p\r\n", data->GPR.r[ 0], data->GPR.r[ 1], data->GPR.r[ 2], data->GPR.r[ 3]);
155+
osDbgPrintf("a0 = %p - a1 = %p - a2 = %p - a3 = %p\r\n", data->GPR.r[ 4], data->GPR.r[ 5], data->GPR.r[ 6], data->GPR.r[ 7]);
156+
osDbgPrintf("t0 = %p - t1 = %p - t2 = %p - t3 = %p\r\n", data->GPR.r[ 8], data->GPR.r[ 9], data->GPR.r[10], data->GPR.r[11]);
157+
osDbgPrintf("t4 = %p - t5 = %p - t6 = %p - t7 = %p\r\n", data->GPR.r[12], data->GPR.r[13], data->GPR.r[14], data->GPR.r[15]);
158+
osDbgPrintf("s0 = %p - s1 = %p - s2 = %p - s3 = %p\r\n", data->GPR.r[16], data->GPR.r[17], data->GPR.r[18], data->GPR.r[19]);
159+
osDbgPrintf("s4 = %p - s5 = %p - s6 = %p - s7 = %p\r\n", data->GPR.r[20], data->GPR.r[21], data->GPR.r[22], data->GPR.r[23]);
160+
osDbgPrintf("t8 = %p - t9 = %p - k0 = %p - k1 = %p\r\n", data->GPR.r[24], data->GPR.r[25], data->GPR.r[26], data->GPR.r[27]);
161+
osDbgPrintf("gp = %p - sp = %p - s8 = %p - ra = %p\r\n", data->GPR.r[28], data->GPR.r[29], data->GPR.r[30], data->GPR.r[31]);
162+
osDbgPrintf("hi = %p - lo = %p\r\n", data->GPR.r[32], data->GPR.r[33]);
163+
}
164+
150165
void breakHandler(InterruptData* data) {}
151166

152-
void interruptHandler(InterruptData* data) {}
167+
void interruptHandler(InterruptData* data) {
168+
osDbgPrintf("***Exception***\r\n");
169+
printInterruptData(data);
170+
}

src/mips/openbios/main/main.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
1818
***************************************************************************/
1919

20+
#include <devfs.h>
21+
#include <stdio.h>
22+
#include <fio.h>
23+
2024
#include "common/hardware/cop0.h"
25+
#include "common/hardware/sio1.h"
2126
#include "common/hardware/spu.h"
2227
#include "common/util/djbhash.h"
2328
#include "openbios/kernel/handlers.h"
@@ -29,8 +34,21 @@ int main() {
2934
*((uint32_t*)0x64) = 0x00;
3035
*((uint32_t*)0x68) = 0xff;
3136
muteSpu();
32-
if (djbHash((const char*)0x1f000084, 44) == 0xf0772daf) {
33-
(*((void (**)())0x1f000080))();
37+
38+
sio1_init();
39+
register_devfs();
40+
register_stdio_devices();
41+
42+
printf("OpenBIOS starting.\r\n");
43+
44+
printf("Checking for EXP1...\r\n");
45+
46+
if (djbHash((const char *) 0x1f000084, 44) == 0xf0772daf) {
47+
void(*ptr)() = *(void(**)()) 0x1f000080;
48+
printf("Signature match, jumping to %p\r\n", ptr);
49+
(*ptr)();
50+
} else {
51+
printf("Signature not matching - skipping EXP1\r\n");
3452
}
3553

3654
start("cdrom:SYSTEM.CNF;1", "cdrom:PSX.EXE;1");

src/mips/openbios/psx-bios.ld

+28-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ MEMORY {
3131
dcache : ORIGIN = 0x1f800000, LENGTH = 0x400
3232
}
3333

34+
STACK_SIZE = 0x10000;
35+
3436
__ram_top = ORIGIN(ram) + LENGTH(ram);
3537
__sp = __ram_top - 0x100;
3638

@@ -40,12 +42,36 @@ __dcache_top = ORIGIN(dcache) + LENGTH(dcache);
4042
__rom_data_len = (__data_end - __data_start);
4143
__bss_len = (__bss_end - __bss_start);
4244

45+
__stack_start = ORIGIN(ram) + LENGTH(ram) - STACK_SIZE;
46+
4347
SECTIONS {
4448
__text_start = .;
4549
.text : {
4650
*(.boot)
51+
4752
*(.init)
53+
. = ALIGN(4);
54+
__preinit_array_start = .;
55+
KEEP (*(SORT(.preinit_array.*)))
56+
KEEP (*(.preinit_array))
57+
. = ALIGN(4);
58+
__preinit_array_end = .;
59+
__init_array_start = .;
60+
KEEP (*(SORT(.init_array.*)))
61+
KEEP (*(.init_array))
62+
KEEP (*(.ctors))
63+
. = ALIGN(4);
64+
__init_array_end = .;
65+
4866
KEEP (*(SORT_NONE(.fini)))
67+
. = ALIGN(4);
68+
__fini_array_start = .;
69+
KEEP (*(.fini_array))
70+
KEEP (*(SORT(.fini_array.*)))
71+
KEEP (*(.dtors))
72+
. = ALIGN(4);
73+
__fini_array_end = .;
74+
4975
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
5076
*(.text.exit .text.exit.*)
5177
*(.text.startup .text.startup.*)
@@ -54,8 +80,6 @@ SECTIONS {
5480
. = ALIGN(4);
5581
} > rom
5682

57-
.fini : {
58-
} > rom
5983
. = ALIGN(4);
6084
__text_end = .;
6185

@@ -93,6 +117,8 @@ SECTIONS {
93117
. = ALIGN(4);
94118
__bss_end = .;
95119

120+
__heap_start = .;
121+
96122
__end = .;
97123

98124
/DISCARD/ : { *(.MIPS.abiflags) }

0 commit comments

Comments
 (0)