Skip to content

Commit 5367adc

Browse files
committed
Added support for standard libc I/O functions
1 parent 50e764f commit 5367adc

16 files changed

+2259
-36
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DATA := data
3838
LIBS :=
3939

4040
MACHDEP := -DBIGENDIAN
41-
CFLAGS += -O2 -Wall -mcpu=cell $(MACHDEP) -fno-strict-aliasing $(INCLUDES) -DPS3_GEKKO -DHAVE_CONFIG_H
41+
CFLAGS += -O2 -Wall -mcpu=cell $(MACHDEP) -fno-strict-aliasing $(INCLUDES) -DPS3_GEKKO -DHAVE_CONFIG_H -DPS3_STDIO
4242
LD := ppu-ld
4343

4444
ifneq ($(BUILD),$(notdir $(CURDIR)))

README_PS3.txt

+44-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ https://github.com/Estwald/PSDK3v2 // psl1ght and environment for Windows
77
https://github.com/Estwald/libntfs_ext // this library
88

99

10-
See "ps3_example"
10+
See "ps3_example". See below for "Standard I/O C functions"
1111

12-
Tris library now support NTFS partitions (Read/Write operations) and ext 2/3/4 (Read only operations)
12+
This library now support NTFS partitions (Read/Write operations) and ext 2/3/4 (Read only operations)
1313

1414
The support for write operations is experimental (use as you own risk)
1515

@@ -34,7 +34,6 @@ int ps3ntfs_stat(const char *file, struct stat *st);
3434
int ps3ntfs_link(const char *existing, const char *newLink);
3535
int ps3ntfs_unlink(const char *name); // for files and folders
3636

37-
;
3837
int ps3ntfs_rename(const char *oldName, const char *newName);
3938
int ps3ntfs_mkdir(const char *path, int mode);
4039

@@ -95,6 +94,48 @@ bool PS3_NTFS_IsInserted(int fd); // fd -> (0 to 7), return true if usb00X (fd i
9594
bool PS3_NTFS_Shutdown(int fd); // fd -> (0 to 7), cause the close of the usb00X device (sector read/write operations fails)
9695

9796

97+
/***********************************************************************************************************/
98+
/***********************************************************************************************************/
99+
100+
Standard I/O C functions
101+
------------------------
102+
103+
Now the library support some standard I/O function. By default PS3_STDIO is defined and ps3_io.c
104+
compiles this support defining libc syscalls function from the __syscalls struct
105+
106+
NOTE: including sys/mutext.h and sys/syscalls.h, it cause an error because sys_mutex_attr is re-defined. For this
107+
reason i define struct __syscalls_t directly and maybe you needs to do soe changes if you are using a different newlib
108+
109+
To initialize the standard function you must call at first function in the main(), NTFS_init_system_io();
110+
111+
Deinit function (NTFS_deinit_system_io()) is called mean atexit function.
112+
113+
Remember you that is possible to use PS3 system devices (as "/dev_usb000"), NTFS (as "/ntfs0:") a EXT2/3/4 (as "/ext0:")
114+
devices with this library.
115+
116+
Standard functions supported:
117+
118+
open_r -> for stdio.h fopen()...
119+
close_r -> for stdio.h fclose()...
120+
read_r -> for stdio.h fread()...
121+
write_r -> for stdio.h fwrite()...
122+
lseek_r -> for stdio.h fseek()...
123+
lseek64_r -> for using with large files (see ps3_example_stdio for this)
124+
fstat_r -> for stat.h fstat()
125+
stat_r -> for stat.h stat()
126+
127+
ftruncate_r -> for unistd.h ftruncate()
128+
truncate_r -> for unistd.h truncate()
129+
fsync_r -> for stdio.h fflush()
130+
link_r -> for unistd.h link()
131+
unlink_r -> for unistd.h unlink()
132+
rename_r -> for stdio.h rename()
133+
mkdir_r -> for stat.h mkdir()
134+
rmdir_r -> for unistd.h rmdir()
98135

136+
closedir_r -> for dirent.h closedir()
137+
opendir_r -> for dirent.h opendir()
138+
readdir_r -> for dirent.h readdir()
139+
readdir_r_r -> for dirent.h readdir_r()
99140

100141

include/ntfs.h

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ int ps3ntfs_dirreset(DIR_ITER *dirState);
209209
int ps3ntfs_dirnext(DIR_ITER *dirState, char *filename, struct stat *filestat);
210210
int ps3ntfs_dirclose(DIR_ITER *dirState);
211211

212+
// map file functions to libc open, fopen, ...
213+
void NTFS_init_system_io(void);
214+
void NTFS_deinit_system_io(void);
215+
212216

213217
#ifndef _SYS_STATVFS_H
214218
#define _SYS_STATVFS_H

ps3_example/ps3_example.pkg

1.88 KB
Binary file not shown.

ps3_example_stdio/Make_EBOOT.BIN.bat

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
set PS3SDK=/f/PSDK3v2
3+
set WIN_PS3SDK=F:/PSDK3v2
4+
set PATH=%WIN_PS3SDK%/mingw/msys/1.0/bin;%WIN_PS3SDK%/mingw/bin;%WIN_PS3SDK%/ps3dev/bin;%WIN_PS3SDK%/ps3dev/ppu/bin;%WIN_PS3SDK%/ps3dev/spu/bin;%WIN_PS3SDK%/mingw/Python27;%PATH%;
5+
set PSL1GHT=%PS3SDK%/psl1ght
6+
set PS3DEV=%PS3SDK%/ps3dev
7+
8+
make npdrm
9+
10+
pause

ps3_example_stdio/Make_PKG.bat

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
set PS3SDK=/f/PSDK3v2
3+
set WIN_PS3SDK=F:/PSDK3v2
4+
set PATH=%WIN_PS3SDK%/mingw/msys/1.0/bin;%WIN_PS3SDK%/mingw/bin;%WIN_PS3SDK%/ps3dev/bin;%WIN_PS3SDK%/ps3dev/ppu/bin;%WIN_PS3SDK%/ps3dev/spu/bin;%WIN_PS3SDK%/mingw/Python27;%PATH%;
5+
set PSL1GHT=%PS3SDK%/psl1ght
6+
set PS3DEV=%PS3SDK%/ps3dev
7+
8+
make pkg
9+
10+
pause

ps3_example_stdio/Make_clean.bat

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
set PS3SDK=/f/PSDK3v2
3+
set WIN_PS3SDK=F:/PSDK3v2
4+
set PATH=%WIN_PS3SDK%/mingw/msys/1.0/bin;%WIN_PS3SDK%/mingw/bin;%WIN_PS3SDK%/ps3dev/bin;%WIN_PS3SDK%/ps3dev/ppu/bin;%WIN_PS3SDK%/ps3dev/spu/bin;%WIN_PS3SDK%/mingw/Python27;%PATH%;
5+
set PSL1GHT=%PS3SDK%/psl1ght
6+
set PS3DEV=%PS3SDK%/ps3dev
7+
8+
make clean
9+
10+
pause

ps3_example_stdio/Makefile

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#---------------------------------------------------------------------------------
2+
# Clear the implicit built in rules
3+
#---------------------------------------------------------------------------------
4+
.SUFFIXES:
5+
#---------------------------------------------------------------------------------
6+
ifeq ($(strip $(PSL1GHT)),)
7+
$(error "Please set PSL1GHT in your environment. export PSL1GHT=<path>")
8+
endif
9+
10+
#---------------------------------------------------------------------------------
11+
# TITLE, APPID, CONTENTID, ICON0 SFOXML before ppu_rules.
12+
#---------------------------------------------------------------------------------
13+
14+
TITLE := NTFS Test
15+
APPID := NTFS00001
16+
CONTENTID := UP0001-$(APPID)_00-0000000000000000
17+
18+
include $(PSL1GHT)/ppu_rules
19+
20+
# aditional scetool flags (--self-ctrl-flags, --self-cap-flags...)
21+
SCETOOL_FLAGS += --self-ctrl-flags 4000000000000000000000000000000000000000000000000000000000000002
22+
SCETOOL_FLAGS += --self-cap-flags 00000000000000000000000000000000000000000000007B0000000100000000
23+
24+
25+
#---------------------------------------------------------------------------------
26+
# TARGET is the name of the output
27+
# BUILD is the directory where object files & intermediate files will be placed
28+
# SOURCES is a list of directories containing source code
29+
# INCLUDES is a list of directories containing extra header files
30+
#---------------------------------------------------------------------------------
31+
TARGET := $(notdir $(CURDIR))
32+
BUILD := build
33+
SOURCES := source
34+
DATA := datas
35+
SHADERS := shaders
36+
INCLUDES := include ../include
37+
38+
39+
#---------------------------------------------------------------------------------
40+
# any extra libraries we wish to link with the project
41+
#---------------------------------------------------------------------------------
42+
LIBS := ../../libntfs_ext.a -lc -lsysfs -lfont -ltiny3d -lsimdmath -lgcm_sys -lio -lsysutil -lrt -llv2 -lsysmodule -lm
43+
44+
45+
#---------------------------------------------------------------------------------
46+
# options for code generation
47+
#---------------------------------------------------------------------------------
48+
49+
CFLAGS = -O2 -Wall -mcpu=cell $(MACHDEP) $(INCLUDE)
50+
CXXFLAGS = $(CFLAGS)
51+
52+
LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map
53+
54+
55+
#---------------------------------------------------------------------------------
56+
# list of directories containing libraries, this must be the top level containing
57+
# include and lib
58+
#---------------------------------------------------------------------------------
59+
LIBDIRS :=
60+
61+
#---------------------------------------------------------------------------------
62+
# no real need to edit anything past this point unless you need to add additional
63+
# rules for different file extensions
64+
#---------------------------------------------------------------------------------
65+
ifneq ($(BUILD),$(notdir $(CURDIR)))
66+
#---------------------------------------------------------------------------------
67+
68+
export OUTPUT := $(CURDIR)/$(TARGET)
69+
70+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
71+
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
72+
$(foreach dir,$(SHADERS),$(CURDIR)/$(dir))
73+
74+
export DEPSDIR := $(CURDIR)/$(BUILD)
75+
76+
export BUILDDIR := $(CURDIR)/$(BUILD)
77+
78+
#---------------------------------------------------------------------------------
79+
# automatically build a list of object files for our project
80+
#---------------------------------------------------------------------------------
81+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
82+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
83+
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
84+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
85+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))
86+
VCGFILES := $(foreach dir,$(SHADERS),$(notdir $(wildcard $(dir)/*.vcg)))
87+
FCGFILES := $(foreach dir,$(SHADERS),$(notdir $(wildcard $(dir)/*.fcg)))
88+
89+
VPOFILES := $(VCGFILES:.vcg=.vpo)
90+
FPOFILES := $(FCGFILES:.fcg=.fpo)
91+
92+
#---------------------------------------------------------------------------------
93+
# use CXX for linking C++ projects, CC for standard C
94+
#---------------------------------------------------------------------------------
95+
ifeq ($(strip $(CPPFILES)),)
96+
export LD := $(CC)
97+
else
98+
export LD := $(CXX)
99+
endif
100+
101+
export OFILES := $(addsuffix .o,$(BINFILES)) \
102+
$(addsuffix .o,$(VPOFILES)) \
103+
$(addsuffix .o,$(FPOFILES)) \
104+
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
105+
$(sFILES:.s=.o) $(SFILES:.S=.o)
106+
107+
#---------------------------------------------------------------------------------
108+
# build a list of include paths
109+
#---------------------------------------------------------------------------------
110+
export INCLUDE := $(foreach dir,$(INCLUDES), -I$(CURDIR)/$(dir)) \
111+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
112+
$(LIBPSL1GHT_INC) \
113+
-I$(CURDIR)/$(BUILD) -I$(PORTLIBS)/include
114+
115+
#---------------------------------------------------------------------------------
116+
# build a list of library paths
117+
#---------------------------------------------------------------------------------
118+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
119+
$(LIBPSL1GHT_LIB) -L$(PORTLIBS)/lib
120+
121+
export OUTPUT := $(CURDIR)/$(TARGET)
122+
.PHONY: $(BUILD) clean
123+
124+
125+
#---------------------------------------------------------------------------------
126+
$(BUILD):
127+
@[ -d $@ ] || mkdir -p $@
128+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
129+
130+
#---------------------------------------------------------------------------------
131+
clean:
132+
@echo clean ...
133+
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).self EBOOT.BIN
134+
135+
#---------------------------------------------------------------------------------
136+
run:
137+
ps3load $(OUTPUT).self
138+
139+
#---------------------------------------------------------------------------------
140+
#pkg: $(BUILD) $(OUTPUT).pkg
141+
pkg: $(BUILD) $(OUTPUT).pkg
142+
@echo Creating PKG...
143+
@mkdir -p $(BUILD)/pkg
144+
@mkdir -p $(BUILD)/pkg/USRDIR
145+
@cp $(ICON0) $(BUILD)/pkg/
146+
@$(SELF_NPDRM) $(SCETOOL_FLAGS) --np-content-id=$(CONTENTID) --encrypt $(BUILDDIR)/$(basename $(notdir $(OUTPUT))).elf $(BUILDDIR)/../EBOOT.BIN
147+
@$(SFO) --title "$(TITLE)" --appid "$(APPID)" -f $(SFOXML) $(BUILD)/pkg/PARAM.SFO
148+
@$(PKG) --contentid $(CONTENTID) $(BUILD)/pkg/ $(OUTPUT).pkg
149+
150+
#---------------------------------------------------------------------------------
151+
152+
npdrm: $(BUILD)
153+
@$(SELF_NPDRM) $(SCETOOL_FLAGS) --np-content-id=$(CONTENTID) --encrypt $(BUILDDIR)/$(basename $(notdir $(OUTPUT))).elf $(BUILDDIR)/../EBOOT.BIN
154+
155+
#---------------------------------------------------------------------------------
156+
157+
else
158+
159+
DEPENDS := $(OFILES:.o=.d)
160+
161+
#---------------------------------------------------------------------------------
162+
# main targets
163+
#---------------------------------------------------------------------------------
164+
$(OUTPUT).self: $(OUTPUT).elf
165+
$(OUTPUT).elf: $(OFILES)
166+
167+
#---------------------------------------------------------------------------------
168+
# This rule links in binary data with the .bin extension
169+
#---------------------------------------------------------------------------------
170+
%.bin.o : %.bin
171+
#---------------------------------------------------------------------------------
172+
@echo $(notdir $<)
173+
@$(bin2o)
174+
175+
#---------------------------------------------------------------------------------
176+
%.vpo.o : %.vpo
177+
#---------------------------------------------------------------------------------
178+
@echo $(notdir $<)
179+
@$(bin2o)
180+
181+
#---------------------------------------------------------------------------------
182+
%.fpo.o : %.fpo
183+
#---------------------------------------------------------------------------------
184+
@echo $(notdir $<)
185+
@$(bin2o)
186+
187+
-include $(DEPENDS)
188+
189+
#---------------------------------------------------------------------------------
190+
endif
191+
#---------------------------------------------------------------------------------
316 KB
Binary file not shown.

0 commit comments

Comments
 (0)