Skip to content

Commit 09ceb2b

Browse files
asmblurnicolasnoble
authored andcommitted
Added hello.psx. Needs fixing.
1 parent 45242e4 commit 09ceb2b

File tree

9 files changed

+453
-9
lines changed

9 files changed

+453
-9
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
name: Build
1919
command: |
2020
make -j 2
21+
make -C src/mips/hello -j 2
2122
make -C src/mips/shell -j 2
2223
make -C src/mips/openbios -j 2
2324

src/mips/common.mk

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,38 @@ PREFIX = mipsel-linux-gnu
22

33
CC = $(PREFIX)-gcc
44

5+
TARGETBASE = $(basename $(TARGET))
6+
57
ARCHFLAGS = -march=mips1 -mabi=32 -EL -msoft-float -Wa,-msoft-float -fno-pic -mno-shared -mno-abicalls
68
CPPFLAGS = -mno-gpopt -fomit-frame-pointer
79
CPPFLAGS += -fno-builtin
810
CPPFLAGS += $(ARCHFLAGS)
9-
CPPFLAGS += -I..
11+
CPPFLAGS += -I.. -I../common/include
1012

11-
LDFLAGS = -Wl,-Map=$(TARGET).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections
13+
LDFLAGS += -Wl,-Map=$(TARGETBASE).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections -Wl,-v
1214
LDFLAGS += $(ARCHFLAGS)
1315

1416
LDFLAGS += -g -O3 -flto
1517
CPPFLAGS += -g -O3 -flto
1618

1719
OBJS += $(addsuffix .o, $(basename $(SRCS)))
1820

19-
all: $(TARGET).bin
21+
all: $(TARGET)
2022

2123
clean:
22-
rm -f $(OBJS) $(TARGET).elf $(TARGET).map $(TARGET).bin
24+
rm -f $(OBJS) $(TARGETBASE).psx $(TARGETBASE).elf $(TARGET).map $(TARGETBASE).bin $(TARGET)
2325

24-
$(TARGET).bin: $(TARGET).elf
26+
$(TARGETBASE).bin: $(TARGETBASE).elf
2527
$(PREFIX)-objcopy -O binary $< $@
2628

27-
$(TARGET).elf: $(OBJS)
28-
$(CC) $(LDFLAGS) -g -o $(TARGET).elf $(OBJS)
29+
$(TARGETBASE).psx: $(OBJS)
30+
$(CC) $(LDFLAGS) -g -o $@ $(OBJS)
31+
32+
$(TARGETBASE).elf: $(OBJS)
33+
$(CC) $(LDFLAGS) -g -o $(TARGETBASE).elf $(OBJS)
34+
35+
%.o: %.S
36+
$(CC) $(CPPFLAGS) -I.. -g -c -o $@ $<
2937

3038
%.o: %.s
3139
$(CC) $(ARCHFLAGS) -I.. -g -c -o $@ $<

src/mips/common/include/mipsregs.h

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#ifndef _MIPSREGS_H
2+
#define _MIPSREGS_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
/* general registers */
9+
10+
#define r0 $0
11+
#define r1 $1
12+
#define r2 $2
13+
#define r3 $3
14+
#define r4 $4
15+
#define r5 $5
16+
#define r6 $6
17+
#define r7 $7
18+
#define r8 $8
19+
#define r9 $9
20+
#define r10 $10
21+
#define r11 $11
22+
#define r12 $12
23+
#define r13 $13
24+
#define r14 $14
25+
#define r15 $15
26+
#define r16 $16
27+
#define r17 $17
28+
#define r18 $18
29+
#define r19 $19
30+
#define r20 $20
31+
#define r21 $21
32+
#define r22 $22
33+
#define r23 $23
34+
#define r24 $24
35+
#define r25 $25
36+
#define r26 $26
37+
#define r27 $27
38+
#define r28 $28
39+
#define r29 $29
40+
#define r30 $30
41+
#define r31 $31
42+
43+
#define zero $0
44+
//#define at $1
45+
#define v0 $2
46+
#define v1 $3
47+
#define a0 $4
48+
#define a1 $5
49+
#define a2 $6
50+
#define a3 $7
51+
#define t0 $8
52+
#define t1 $9
53+
#define t2 $10
54+
#define t3 $11
55+
#define t4 $12
56+
#define t5 $13
57+
#define t6 $14
58+
#define t7 $15
59+
#define s0 $16
60+
#define s1 $17
61+
#define s2 $18
62+
#define s3 $19
63+
#define s4 $20
64+
#define s5 $21
65+
#define s6 $22
66+
#define s7 $23
67+
#define t8 $24
68+
#define t9 $25
69+
#define k0 $26
70+
#define k1 $27
71+
#define gp $28
72+
#define sp $29
73+
#define s8 $30
74+
#define fp $30
75+
#define ra $31
76+
77+
/* COP0 Registers */
78+
79+
/* BreakPoint Control */
80+
#define C0_BPC $3
81+
/* BreakPoint on Data Access */
82+
#define C0_BDA $5
83+
/* BreakPoint on Data Access */
84+
#define C0_DCIC $7
85+
#define C0_BADVADDR $8
86+
#define C0_BDAM $9
87+
#define C0_BPCM $11
88+
89+
/* Status Register */
90+
#define C0_STATUS $12
91+
92+
/* Cause Register */
93+
#define C0_CAUSE $13
94+
95+
/* Error PC Register */
96+
#define C0_EPC $14
97+
98+
/* Processor ID */
99+
#define C0_PRID $15
100+
101+
// Interrupt Enable(current)
102+
#define SR_IEC (1 << 0)
103+
// Kernel/User mode(current)
104+
#define SR_KUC (1 << 1)
105+
// Interrupt Enable(previous)
106+
#define SR_IEP (1 << 2)
107+
// Kernel/User mode(previous)
108+
#define SR_KUP (1 << 3)
109+
// Interrupt Enable(old)
110+
#define SR_IEO (1 << 4)
111+
// Kernel/User mode(old)
112+
#define SR_KUO (1 << 5)
113+
114+
/* Interrupt Mask 0 */
115+
#define SR_IMO (1 << 8)
116+
/* Interrupt Mask 1 */
117+
#define SR_IM1 (1 << 9)
118+
/* Interrupt Mask 2 */
119+
#define SR_IM2 (1 << 10)
120+
/* Interrupt Mask 3 */
121+
#define SR_IM3 (1 << 11)
122+
/* Interrupt Mask 4 */
123+
#define SR_IM4 (1 << 12)
124+
/* Interrupt Mask 5 */
125+
#define SR_IM5 (1 << 13)
126+
/* Interrupt Mask 6 */
127+
#define SR_IM6 (1 << 14)
128+
/* Interrupt Mask 7 */
129+
#define SR_IM7 (1 << 15)
130+
131+
/* Isolate Cache */
132+
#define SR_ISC (1 << 16)
133+
/* Swap Caches */
134+
#define SR_SWC (1 << 17)
135+
/* Parity Zero */
136+
#define SR_PZ (1 << 18)
137+
/* Cache Miss */
138+
#define SR_CM (1 << 19)
139+
/* Parity Error */
140+
#define SR_PE (1 << 20)
141+
/* TLB Shutdown */
142+
#define SR_TS (1 << 21)
143+
/* Boot-time Exception Vector */
144+
#define SR_BEV (1 << 22)
145+
146+
/* Reverse Endian enable */
147+
#define SR_RE (1 << 25)
148+
149+
/* Coprocessor 0 Usable */
150+
#define SR_CU0 (1 << 28)
151+
/* Coprocessor 1 Usable */
152+
#define SR_CU1 (1 << 29)
153+
/* Coprocessor 2 Usable */
154+
#define SR_CU2 (1 << 30)
155+
/* Coprocessor 3 Usable */
156+
#define SR_CU3 (1 << 31)
157+
158+
#ifdef __cplusplus
159+
}
160+
#endif
161+
162+
#endif /* _MIPSREGS_H */
163+

src/mips/hello/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
TARGET = hello.psx
2+
TLOAD_ADDR = 0x80010000
3+
SRCS = \
4+
../common/hardware/cop0.s \
5+
crt0/crt0.s \
6+
main/main.c \
7+
8+
LDSCRIPT = psx-exe.ld
9+
10+
## If "TLOAD_ADDR" was specified in the Makefile, pass it to the linker.
11+
ifneq ($(strip $(TLOAD_ADDR)),)
12+
LDFLAGS := -Wl,--defsym,TLOAD_ADDR=$(TLOAD_ADDR)
13+
else
14+
LDFLAGS =
15+
endif
16+
17+
include ../common.mk

src/mips/hello/crt0/crt0.s

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 <mipsregs.h>
21+
22+
.set push
23+
.set noreorder
24+
.set noat
25+
26+
.section .start, "ax", @progbits
27+
.align 2
28+
.global main
29+
.global _start
30+
.type _start, @function
31+
_start:
32+
la t0, __bss_start
33+
la t1, __bss_end
34+
addiu t1, t1, 3
35+
srl t1, t1, 2
36+
sll t1, t1, 2
37+
beq t0, t1, _zero_bss_done
38+
nop
39+
40+
_zero_bss:
41+
sw zero, 0(t0)
42+
addiu t0, t0, 4
43+
bne t0, t1, _zero_bss
44+
nop
45+
46+
_zero_bss_done:
47+
/* la gp, _gp*/
48+
li a0, 0
49+
j main
50+
li a1, 0
51+
52+
/*
53+
.end _start
54+
.data
55+
56+
.bss
57+
*/
58+
.extern __bss_start
59+
.extern __bss_end
60+
.extern _gp
61+
/* int _main(int argc, const char **argv, const char **envp) */
62+
.extern main
63+
64+
.set pop

src/mips/hello/main/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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/cop0.h"
21+
22+
int main() {
23+
return 0;
24+
}

0 commit comments

Comments
 (0)