├── .github └── workflows │ └── main.yml ├── .gitignore ├── LICENSE ├── README.md ├── assets └── d2x-logo.jpg ├── data ├── Changelog.txt ├── ReadMe.txt ├── ciosmaps-vWii.xml ├── ciosmaps.xml └── d2x-beta.bat ├── maked2x.bat ├── maked2x.sh ├── replace.awk ├── source ├── cios-lib │ ├── Makefile │ ├── direct_syscalls.h │ ├── direct_syscalls.s │ ├── fat_tools.c │ ├── fat_tools.h │ ├── hollywood.h │ ├── ios.c │ ├── ios.h │ ├── ipc.c │ ├── ipc.h │ ├── isfs.c │ ├── isfs.h │ ├── libc.c │ ├── libwbfs │ │ ├── libwbfs.c │ │ ├── libwbfs.h │ │ ├── rijndael.c │ │ ├── wiidisc.c │ │ └── wiidisc.h │ ├── libwbfs_os.h │ ├── log.c │ ├── log.h │ ├── mem.c │ ├── mem.h │ ├── sdhc_server.c │ ├── sdhc_server.h │ ├── sdio.c │ ├── sdio.h │ ├── stealth.c │ ├── stealth.h │ ├── str_utils.c │ ├── str_utils.h │ ├── swi_mload.c │ ├── swi_mload.h │ ├── syscalls.h │ ├── syscalls.s │ ├── syscalls_dbg.c │ ├── syscalls_dbg.h │ ├── timer.c │ ├── timer.h │ ├── tools.h │ ├── tools.s │ ├── types.h │ ├── usbstorage.c │ ├── usbstorage.h │ ├── vsprintf.c │ └── vsprintf.h ├── dip-plugin │ ├── LICENSE.txt │ ├── Makefile │ ├── config.c │ ├── config.h │ ├── dip.c │ ├── dip.h │ ├── dip_calls.h │ ├── dip_calls.s │ ├── dma.c │ ├── dma.h │ ├── errno.h │ ├── fat.c │ ├── fat.h │ ├── frag.c │ ├── frag.h │ ├── ioctl.h │ ├── link.ld │ ├── main.c │ ├── patches.c │ ├── patches.h │ ├── plugin.c │ ├── plugin.h │ ├── sdhc.c │ ├── sdhc.h │ ├── start.s │ ├── wbfs.c │ └── wbfs.h ├── ehci-module │ ├── Makefile │ ├── link.ld │ ├── loop.c │ ├── main.c │ ├── module.h │ ├── start.s │ ├── tinyehci.c │ ├── tinyehci.h │ ├── tinyehci │ │ ├── ehci-mem.c │ │ ├── ehci.c │ │ ├── ehci.h │ │ ├── ehci_defs.h │ │ ├── ehci_types.h │ │ ├── usb.c │ │ ├── usb.h │ │ ├── usbstorage.c │ │ └── usbstorage.h │ ├── usb_os.c │ ├── utils.h │ ├── wbfs.c │ └── wbfs.h ├── es-plugin │ ├── LICENSE.txt │ ├── Makefile │ ├── config.c │ ├── config.h │ ├── di.c │ ├── di.h │ ├── es_calls.h │ ├── es_calls.s │ ├── ioctl.h │ ├── link.ld │ ├── main.c │ ├── patches.c │ ├── patches.h │ ├── plugin.c │ ├── plugin.h │ └── start.s ├── fat-module │ ├── LICENSE.txt │ ├── Makefile │ ├── ccsbcs.c │ ├── diskio.c │ ├── diskio.h │ ├── fat_wrapper.c │ ├── fat_wrapper.h │ ├── ff.c │ ├── ff.h │ ├── ffconf.h │ ├── fs.h │ ├── integer.h │ ├── led.c │ ├── led.h │ ├── link.ld │ ├── main.c │ ├── main.h │ ├── module.h │ ├── start.s │ └── syscall.c ├── ffs-plugin │ ├── LICENSE.txt │ ├── Makefile │ ├── fat.c │ ├── fat.h │ ├── fs_calls.h │ ├── fs_calls.s │ ├── fs_dump.c │ ├── fs_dump.h │ ├── fs_tools.c │ ├── fs_tools.h │ ├── ioctl.h │ ├── iop.c │ ├── iop.h │ ├── iop_calls.h │ ├── iop_calls.s │ ├── isfs.h │ ├── link.ld │ ├── main.c │ ├── patches.c │ ├── patches.h │ ├── plugin.c │ ├── plugin.h │ └── start.s ├── mload-module │ ├── LICENSE.txt │ ├── Makefile │ ├── debug.c │ ├── debug.h │ ├── detect.c │ ├── detect.h │ ├── elf.c │ ├── elf.h │ ├── gecko.c │ ├── gecko.h │ ├── gpio.c │ ├── gpio.h │ ├── link.ld │ ├── main.c │ ├── module.h │ ├── patches.c │ ├── patches.h │ ├── start.s │ ├── swi.c │ ├── swi.h │ ├── swi_asm.s │ ├── tid.c │ ├── tid.h │ └── utils.h └── usb-module │ ├── LICENSE.txt │ ├── Makefile │ ├── compat.h │ ├── link.ld │ ├── main.c │ ├── module.h │ ├── start.s │ ├── usb2.c │ ├── usb2.h │ ├── usbglue.c │ ├── usbglue.h │ ├── usbstorage.c │ ├── usbstorage.h │ ├── wbfs.c │ └── wbfs.h └── stripios_src └── main.cpp /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Build cIOS 2 | 3 | on: 4 | push: 5 | branches: 6 | - "**" 7 | paths-ignore: 8 | - '**.md' 9 | - '.github/ISSUE_TEMPLATE/**' 10 | - '.github/FUNDING.yml' 11 | - '.github/**/*.md' 12 | pull_request: 13 | paths-ignore: 14 | - '**.md' 15 | - '.github/ISSUE_TEMPLATE/**' 16 | - '.github/FUNDING.yml' 17 | - '.github/**/*.md' 18 | 19 | jobs: 20 | build: 21 | runs-on: ubuntu-latest 22 | timeout-minutes: 10 23 | steps: 24 | - uses: actions/checkout@v4 25 | 26 | - name: Download devkitPPC r32 27 | run: | 28 | wget "https://github.com/Leseratte10/compile-devkitARM-r32/releases/download/2020-02-20/devkitARM-r32-linux_debian-buster.tar.gz" 29 | tar -xf devkitARM-r32-linux_debian-buster.tar.gz -C /opt 30 | rm devkitARM-r32-linux_debian-buster.tar.gz 31 | 32 | - name: Compile stripios 33 | run: | 34 | cd stripios_src 35 | g++ main.cpp -o stripios 36 | cp stripios .. 37 | 38 | - name: Compile cIOS 39 | run: | 40 | sudo apt-get install -y libfl2 41 | chmod +x maked2x.sh 42 | ./maked2x.sh ${{ secrets.VERSION }} 43 | echo "upload_name=v${{ secrets.VERSION }}-$(git rev-parse --short=7 HEAD)" | tr ' ' '-' >> $GITHUB_ENV 44 | 45 | - name: Upload artifact 46 | uses: actions/upload-artifact@v4 47 | with: 48 | name: d2x-${{ env.upload_name }} 49 | path: build 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.elf 4 | *.orig 5 | *.map 6 | *.exe 7 | build/ 8 | /stripios 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU General Public License v3 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

3 | 4 | 5 |

6 |
7 | 8 | 9 | #### DISCLAIMER 10 | 11 | ```` 12 | THIS APPLICATION COMES WITH NO WARRANTY AT ALL, NEITHER EXPRESSED NOR IMPLIED. 13 | NO ONE BUT YOURSELF IS RESPONSIBLE FOR ANY DAMAGE TO YOUR WII CONSOLE BECAUSE OF A IMPROPER USAGE OF THIS SOFTWARE. 14 | ```` 15 | 16 | 17 | 18 | #### DESCRIPTION 19 | 20 | This is a custom IOS for the Wii console, i.e. an IOS modified to add some new features 21 | not available in the official IOS. 22 | 23 | This custom IOS has been made to be used ONLY with homebrew software. 24 | 25 | The d2x cIOS is an enhanced version of the cIOSX rev21 by Waninkoko. 26 | 27 | 28 | 29 | #### DOCUMENTATION 30 | 31 | For documentation and tutorials visit our [Wiki](https://github.com/wiidev/d2x-cios/wiki). 32 | 33 | 34 | 35 | #### KUDOS 36 | 37 | * *rodries*, for the help with EHCI improvements. 38 | * *Crediar*, for all I learned studying [Sneek](http://code.google.com/p/sneek) source code. 39 | * *Oggzee*, for his brilliant fraglist. 40 | * *WiiPower*, for the great help with ios reload block from usb. 41 | * *dragbe* and *NutNut*, for their [d2x cIOS Installer](http://code.google.com/p/d2x-cios-installer). 42 | * *XFlak*, for his wonderful [ModMii](http://gbatemp.net/topic/207126-modmii-for-windows) which supported d2x wads since its birth. Without ModMii d2x cIOS would probably never have existed. Also, XFlak had the original idea to replace the buggy EHCI module of cIOSX rev21 with the working one from rev19. 43 | * *[HackWii](http://www.hackwii.it)* and *[GBAtemp](http://www.gbatemp.net)* communities, for their ideas and support. 44 | * *Totoro*, for the official d2x logo 45 | * *ChaN*, for his [FatFs](http://elm-chan.org/fsw/ff/00index_e.html). 46 | * *Waninkoko*, for his cIOSX rev21. 47 | * *Team Twiizers* and *devkitPRO devs* for their great work in libogc. 48 | * *WiiGator*, for his work in the DIP plugin. 49 | * *kwiirk*, for his EHCI module. 50 | * *Hermes*, for his EHCI improvements. 51 | * *neimod*, for his [Custom IOS Module Toolkit](http://wiibrew.org/wiki/Custom_IOS_Module_Toolkit). 52 | * All the betatesters. 53 | -------------------------------------------------------------------------------- /assets/d2x-logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiidev/d2x-cios/33ad1eeeb8f562df99e7d7ca428fdd36e0e31be7/assets/d2x-logo.jpg -------------------------------------------------------------------------------- /data/ReadMe.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * cIOS d2x v${MAJOR_VER} ${MINOR_VER} by blackb0x 3 | * 4 | * Previous releases were by davebaol 5 | * 6 | */ 7 | 8 | 9 | [ DISCLAIMER ] 10 | 11 | THIS APPLICATION COMES WITH NO WARRANTY AT ALL, NEITHER EXPRESSED NOR 12 | IMPLIED. NO ONE BUT YOURSELF IS RESPONSIBLE FOR ANY DAMAGE TO YOUR WII 13 | CONSOLE BECAUSE OF A IMPROPER USAGE OF THIS SOFTWARE. 14 | 15 | 16 | [ DESCRIPTION ] 17 | 18 | This is a Custom IOS, an IOS modified to add some new features 19 | not available in the official IOS. 20 | 21 | This IOS has been made to be used ONLY with homebrew software. 22 | 23 | The d2x cIOS is an enhanced version of the cIOSX rev21 by Waninkoko. 24 | To see what's new read the file Changelog.txt or visit the d2x GitHub 25 | page: https://github.com/wiidev/d2x-cios 26 | 27 | 28 | [ HOW TO INSTALL IT ] 29 | 30 | You can install d2x cios through ModMii or d2x-cios-installer. 31 | 32 | ModMii: 33 | 34 | - If you're going to install a d2x vWii edition don't use ModMii. In this 35 | case use the d2x-cios-installer (see below). 36 | - Download and install ModMii v6.2.3 or higher on your PC. Download link: 37 | http://gbatemp.net/topic/207126-modmii-for-windows 38 | - From ModMii's Main Menu, enter "4", then "beta" 39 | - Select the d2x beta you want to build 40 | - Mark some or all d2x cIOSs for download (i.e. "d2x") 41 | - Enter "D" then "Y" to build d2x beta cIOSs\WADs 42 | - Install cIOSs using a WAD Manager - i.e. WiiMod\MMM\YAWMM (available on 43 | ModMii's Download Page 2) 44 | 45 | d2x-cios-installer: 46 | 47 | - Download the latest d2x-cios-installer from its google code page: 48 | http://code.google.com/p/d2x-cios-installer/downloads/list 49 | - Extract it into the apps folder of your sd card or usb device 50 | - Extract d2x-v${MAJOR_VER}-${MINOR_VER}.zip on your sd card or usb device 51 | into the folder /apps/d2x-cios-installer. 52 | NOTE: This will overwrite the file /apps/d2x-cios-installer/ciosmaps.xml 53 | possibly present in that folder. You might want to rename it before 54 | extracting the d2x package. 55 | - Launch the Homebrew Channel, start the installer and follow the 56 | instructions on the screen 57 | 58 | 59 | [ KUDOS ] 60 | 61 | - rodries, for the help with EHCI improvements. 62 | - Crediar, for all I learned studying Sneek source code. 63 | - Oggzee, for his brilliant fraglist. 64 | - WiiPower, for the great help with ios reload block from usb. 65 | - dragbe and NutNut, for their d2x cios installer. 66 | - XFlak, for his wonderful ModMii which supported d2x wads since its birth. 67 | Without ModMii d2x cios would probably never have existed. Also, XFlak had 68 | the original idea to replace the buggy EHCI module of cIOSX rev21 with the 69 | working one from rev19. 70 | - HackWii.it and GBAtemp.net communities, for their ideas and support. 71 | - Totoro, for the official d2x logo 72 | - ChaN, for his FatFs. 73 | - Waninkoko, for his cIOSX rev21. 74 | - Team Twiizers and devkitPRO devs for their great work in libogc. 75 | - WiiGator, for his work in the DIP plugin. 76 | - kwiirk, for his EHCI module. 77 | - Hermes, for his EHCI improvements. 78 | - neimod, for the Custom IOS module. 79 | - All the betatesters. 80 | -------------------------------------------------------------------------------- /replace.awk: -------------------------------------------------------------------------------- 1 | BEGIN { 2 | _ord_init(); 3 | 4 | hex_major_ver = sprintf("0x%02x,0x%02x,0x%02x,0x%02x", and(rshift(major_ver,24),0xff), and(rshift(major_ver,16),0xff), and(rshift(major_ver,8),0xff), and(major_ver,0xff)); 5 | 6 | hex_minor_ver = ""; 7 | len = length(minor_ver); 8 | for (i=1; i<=16; i++) { 9 | c = (i > len) ? "\0" : substr(minor_ver, i, 1); 10 | hex_minor_ver = hex_minor_ver (i > 1 ? "," : "") sprintf("0x%02x",_ord_[c]); 11 | } 12 | 13 | vars["${MAJOR_VER}"] = major_ver; 14 | vars["${MINOR_VER}"] = minor_ver; 15 | vars["${HEX_MAJOR_VER}"] = hex_major_ver; 16 | vars["${HEX_MINOR_VER}"] = hex_minor_ver; 17 | vars["${IOS_REV}"] = 21000 + major_ver; 18 | 19 | } 20 | 21 | function _ord_init(low, high, i, t) 22 | { 23 | low = sprintf("%c", 7) # BEL is ascii 7 24 | if (low == "\a") { # regular ascii 25 | low = 0 26 | high = 127 27 | } else if (sprintf("%c", 128 + 7) == "\a") { 28 | # ascii, mark parity 29 | low = 128 30 | high = 255 31 | } else { # ebcdic(!) 32 | low = 0 33 | high = 255 34 | } 35 | 36 | for (i = low; i <= high; i++) { 37 | t = sprintf("%c", i) 38 | _ord_[t] = i 39 | } 40 | } 41 | 42 | { 43 | line_in = $0; 44 | line_out = ""; 45 | for (;;) { 46 | match(line_in, /[$][{][^}.]+[}]/); 47 | 48 | if (RSTART == 0 && RLENGTH == -1) { 49 | line_out = line_out line_in; 50 | break; 51 | } 52 | 53 | var = substr(line_in, RSTART, RLENGTH); 54 | value = (var in vars) ? vars[var] : var; 55 | line_out = line_out substr(line_in, 1, RSTART - 1) value; 56 | line_in = substr(line_in, RSTART + RLENGTH); 57 | } 58 | print line_out; 59 | } -------------------------------------------------------------------------------- /source/cios-lib/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | AR = $(PREFIX)ar 10 | 11 | # Flags 12 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 13 | CFLAGS = $(ARCH) -I. -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wstrict-prototypes 14 | ARFLAGS = rcs 15 | 16 | # Libraries 17 | LIBS = 18 | 19 | # Target 20 | TARGET = cios-lib 21 | 22 | # Objects 23 | OBJS = direct_syscalls.o \ 24 | fat_tools.o \ 25 | ios.o \ 26 | ipc.o \ 27 | isfs.o \ 28 | libc.o \ 29 | log.o \ 30 | mem.o \ 31 | sdhc_server.o \ 32 | sdio.o \ 33 | stealth.o \ 34 | str_utils.o \ 35 | swi_mload.o \ 36 | syscalls.o \ 37 | syscalls_dbg.o \ 38 | timer.o \ 39 | tools.o \ 40 | usbstorage.o \ 41 | vsprintf.o 42 | 43 | OBJS2 = libwbfs/libwbfs.o \ 44 | libwbfs/rijndael.o \ 45 | libwbfs/wiidisc.o 46 | 47 | 48 | $(TARGET).a: $(OBJS) $(OBJS2) 49 | @echo -e " AR\t$@" 50 | @$(AR) $(ARFLAGS) $@ $(OBJS) $(OBJS2) 51 | 52 | %.o: %.s 53 | @echo -e " CC\t$@" 54 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 55 | 56 | libwbfs/%.o: libwbfs/%.c 57 | @echo -e " CC\t$@" 58 | @$(CC) $(CFLAGS) -c -o $@ $< 59 | 60 | %.o: %.c 61 | @echo -e " CC\t$@" 62 | @$(CC) $(CFLAGS) -c -o $@ $< 63 | 64 | clean: 65 | @echo -e "Cleaning..." 66 | @rm -f $(OBJS) $(OBJS2) $(TARGET).a 67 | -------------------------------------------------------------------------------- /source/cios-lib/direct_syscalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _DIRECT_SYSCALLS_H_ 26 | #define _DIRECT_SYSCALLS_H_ 27 | 28 | #include "types.h" 29 | 30 | /* Prototypes */ 31 | s32 direct_os_get_thread_id(void); 32 | void direct_os_sync_before_read(void *ptr, s32 size); 33 | void direct_os_sync_after_write(void *ptr, s32 size); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/cios-lib/direct_syscalls.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | 26 | /* 27 | * Macros 28 | */ 29 | .macro direct_syscall num name 30 | .align 4 31 | .code 32 32 | .global \name 33 | \name: 34 | mov r11, #(\num) 35 | b invoke_direct_syscall 36 | .endm 37 | 38 | 39 | #define syscall_base ios 40 | 41 | 42 | .text 43 | 44 | /* 45 | * Direct syscall invocation 46 | * 47 | * NOTE: 48 | * Input register r11 specifies the syscall number to jump to. 49 | */ 50 | .align 4 51 | .code 32 52 | 53 | invoke_direct_syscall: 54 | ldr r12, =syscall_base 55 | ldr r12, [r12] 56 | nop 57 | ldr r12, [r12, r11, lsl#2] 58 | nop 59 | bx r12 60 | 61 | /* 62 | * Direct syscalls 63 | * 64 | * NOTE: 65 | * Direct syscalls are required when you have to call 66 | * a syscall from inside a syscall. 67 | */ 68 | direct_syscall 0x03, direct_os_get_thread_id 69 | direct_syscall 0x3f, direct_os_sync_before_read 70 | direct_syscall 0x40, direct_os_sync_after_write 71 | -------------------------------------------------------------------------------- /source/cios-lib/fat_tools.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | 26 | #include 27 | 28 | #include "types.h" 29 | 30 | void FAT_Escape(char *dst, const char *src) 31 | { 32 | char c; 33 | 34 | /* Escape invalid FAT characters */ 35 | while ((c = *(src++)) != '\0') { 36 | char *esc; 37 | 38 | /* Check character */ 39 | switch (c) { 40 | case '"': esc = "&qt;"; break; // Escape double quote 41 | case '*': esc = "&st;"; break; // Escape star 42 | case ':': esc = "&cl;"; break; // Escape colon 43 | case '<': esc = "<"; break; // Escape lesser than 44 | case '>': esc = ">"; break; // Escape greater than 45 | case '?': esc = "&qm;"; break; // Escape question mark 46 | case '|': esc = "&vb;"; break; // Escape vertical bar 47 | default: *(dst++) = c; continue; // Copy valid FAT character 48 | } 49 | 50 | /* Replace escape sequence */ 51 | strcpy(dst, esc); 52 | dst += 4; 53 | } 54 | 55 | /* End of string */ 56 | *dst = '\0'; 57 | } 58 | 59 | /* 60 | * Unescape in place and return the length of the unescaped path 61 | */ 62 | s32 FAT_Unescape(char *path) 63 | { 64 | char *src = path; 65 | char *dst = path; 66 | char c; 67 | 68 | /* Unescape invalid FAT characters */ 69 | while ((c = *(src++)) != '\0') { 70 | 71 | /* Check character */ 72 | if (c == '&') { 73 | if (!strncmp(src, "qt;", 3)) c = '"'; // Unescape double quote 74 | else if (!strncmp(src, "st;", 3)) c = '*'; // Unescape star 75 | else if (!strncmp(src, "cl;", 3)) c = ':'; // Unescape colon 76 | else if (!strncmp(src, "lt;", 3)) c = '<'; // Unescape lesser than 77 | else if (!strncmp(src, "gt;", 3)) c = '>'; // Unescape greater than 78 | else if (!strncmp(src, "qm;", 3)) c = '?'; // Unescape question mark 79 | else if (!strncmp(src, "vb;", 3)) c = '|'; // Unescape vertical bar 80 | 81 | /* Skip matched escape sequence */ 82 | if (c != '&') 83 | src += 3; 84 | } 85 | 86 | /* Copy character */ 87 | *(dst++) = c; 88 | } 89 | 90 | /* End of string */ 91 | *dst = '\0'; 92 | 93 | /* Return length */ 94 | return dst - path; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /source/cios-lib/fat_tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _FAT_TOOLS_H_ 26 | #define _FAT_TOOLS_H_ 27 | 28 | #include "types.h" 29 | 30 | /* Prototypes */ 31 | void FAT_Escape(char *dst, const char *src); 32 | s32 FAT_Unescape(char *path); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/cios-lib/ios.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _IOS_H_ 26 | #define _IOS_H_ 27 | 28 | #include "types.h" 29 | 30 | //#define CIOSLIB_DEBUG 31 | 32 | #define IOS_ERROR_DIP -1 33 | #define IOS_ERROR_ES -2 34 | #define IOS_ERROR_FFS -3 35 | #define IOS_ERROR_IOP -4 36 | 37 | /* IOS info structure */ 38 | typedef struct { 39 | /* Syscall base */ 40 | u32 syscallBase; 41 | 42 | /* Module versions */ 43 | u32 dipVersion; 44 | u32 esVersion; 45 | u32 ffsVersion; 46 | u32 iopVersion; 47 | } iosInfo; 48 | 49 | /* Module patcher function */ 50 | typedef s32(*PatcherFunc)(void); 51 | 52 | /* Patcher structure */ 53 | typedef struct { 54 | PatcherFunc function; 55 | s32 status; 56 | } patcher; 57 | 58 | 59 | /* Extern global variable */ 60 | extern iosInfo ios; 61 | extern char *moduleName; 62 | 63 | /* Prototypes */ 64 | s32 IOS_InitSystem(patcher patchers[], u32 size); 65 | s32 IOS_CheckPatches(patcher patchers[], u32 size); 66 | s32 IOS_PatchModules(patcher patchers[], u32 size); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /source/cios-lib/ipc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "ipc.h" 26 | #include "syscalls.h" 27 | #include "types.h" 28 | 29 | 30 | void InvalidateVector(ioctlv *vector, u32 inlen, u32 iolen) 31 | { 32 | u32 cnt; 33 | 34 | for (cnt = 0; cnt < (inlen + iolen); cnt++) { 35 | void *buffer = vector[cnt].data; 36 | u32 len = vector[cnt].len; 37 | 38 | /* Invalidate cache */ 39 | os_sync_before_read(buffer, len); 40 | } 41 | } 42 | 43 | void FlushVector(ioctlv *vector, u32 inlen, u32 iolen) 44 | { 45 | u32 cnt; 46 | 47 | for (cnt = inlen; cnt < (inlen + iolen); cnt++) { 48 | void *buffer = vector[cnt].data; 49 | u32 len = vector[cnt].len; 50 | 51 | /* Flush cache */ 52 | os_sync_after_write(buffer, len); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /source/cios-lib/ipc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _IPC_H_ 26 | #define _IPC_H_ 27 | 28 | #include "types.h" 29 | 30 | /* IPC error codes */ 31 | #define IPC_ENOENT -6 32 | #define IPC_ENOMEM -22 33 | #define IPC_EINVAL -101 34 | #define IPC_EACCESS -102 35 | #define IPC_EEXIST -105 36 | #define IPC_NOENT -106 37 | 38 | /* IOS calls */ 39 | #define IOS_OPEN 0x01 40 | #define IOS_CLOSE 0x02 41 | #define IOS_READ 0x03 42 | #define IOS_WRITE 0x04 43 | #define IOS_SEEK 0x05 44 | #define IOS_IOCTL 0x06 45 | #define IOS_IOCTLV 0x07 46 | 47 | /* Async reply */ 48 | typedef struct { 49 | s32 unk; 50 | s32 result; 51 | } areply; 52 | 53 | /* IOCTLV vector */ 54 | typedef struct iovec { 55 | void *data; 56 | u32 len; 57 | } ioctlv; 58 | 59 | /* IPC message */ 60 | typedef struct ipcmessage { 61 | u32 command; 62 | u32 result; 63 | u32 fd; 64 | 65 | union 66 | { 67 | struct 68 | { 69 | char *device; 70 | u32 mode; 71 | u32 resultfd; 72 | } open; 73 | 74 | struct 75 | { 76 | void *data; 77 | u32 length; 78 | } read, write; 79 | 80 | struct 81 | { 82 | s32 offset; 83 | s32 origin; 84 | } seek; 85 | 86 | struct 87 | { 88 | u32 command; 89 | 90 | u32 *buffer_in; 91 | u32 length_in; 92 | u32 *buffer_io; 93 | u32 length_io; 94 | } ioctl; 95 | struct 96 | { 97 | u32 command; 98 | 99 | u32 num_in; 100 | u32 num_io; 101 | ioctlv *vector; 102 | } ioctlv; 103 | }; 104 | } ATTRIBUTE_PACKED ipcmessage; 105 | 106 | 107 | /* Prototypes */ 108 | void InvalidateVector(ioctlv *vector, u32 inlen, u32 iolen); 109 | void FlushVector(ioctlv *vector, u32 inlen, u32 iolen); 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /source/cios-lib/isfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _ISFS_H_ 26 | #define _ISFS_H_ 27 | 28 | #include "ipc.h" 29 | #include "types.h" 30 | 31 | /* Constants */ 32 | #define ISFS_MAXPATH 64 33 | 34 | #define ISFS_OPEN_READ 0x01 35 | #define ISFS_OPEN_WRITE 0x02 36 | #define ISFS_OPEN_RW (ISFS_OPEN_READ | ISFS_OPEN_WRITE) 37 | 38 | /* ISFS Mode codes */ 39 | #define ISFS_MODE_NAND 0x00 40 | #define ISFS_MODE_SDHC 0x01 41 | #define ISFS_MODE_USB 0x02 42 | #define ISFS_MODE_FULL 0x100 43 | 44 | 45 | /* ISFS structure */ 46 | struct isfs 47 | { 48 | char filepath[ISFS_MAXPATH]; 49 | 50 | union { 51 | struct { 52 | char filepathOld[ISFS_MAXPATH]; 53 | char filepathNew[ISFS_MAXPATH]; 54 | } fsrename; 55 | 56 | struct { 57 | char filepath[ISFS_MAXPATH]; 58 | } fsdelete; 59 | 60 | struct { 61 | u32 owner_id; 62 | u16 group_id; 63 | char filepath[ISFS_MAXPATH]; 64 | u8 ownerperm; 65 | u8 groupperm; 66 | u8 otherperm; 67 | u8 attributes; 68 | u8 pad0[2]; 69 | } fsattr; 70 | 71 | struct { 72 | ioctlv vector[4]; 73 | u32 no_entries; 74 | } fsreaddir; 75 | 76 | struct { 77 | ioctlv vector[4]; 78 | u32 usage1; 79 | u8 pad0[28]; 80 | u32 usage2; 81 | } fsusage; 82 | 83 | struct { 84 | u32 a; 85 | u32 b; 86 | u32 c; 87 | u32 d; 88 | u32 e; 89 | u32 f; 90 | u32 g; 91 | } fsstats; 92 | 93 | struct { 94 | ioctlv vector[4]; 95 | u32 mode; 96 | u8 pad0[28]; 97 | char path[ISFS_MAXPATH]; 98 | } fsconfig; 99 | }; 100 | }; 101 | 102 | 103 | /* Prototypes */ 104 | s32 ISFS_Open(void); 105 | void ISFS_Close(void); 106 | s32 ISFS_CreateFile(const char *filename); 107 | s32 ISFS_Delete(const char *filename); 108 | s32 ISFS_SetMode(u32 mode, char *path); 109 | s32 ISFS_GetMode(u32 *mode, char *path); 110 | 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /source/cios-lib/libwbfs/wiidisc.h: -------------------------------------------------------------------------------- 1 | #ifndef WIIDISC_H 2 | #define WIIDISC_H 3 | #include 4 | #include "libwbfs_os.h" // this file is provided by the project wanting to compile libwbfs and wiidisc 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif /* __cplusplus */ 9 | #if 0 //removes extra automatic indentation by editors 10 | } 11 | #endif 12 | // callback definition. Return 1 on fatal error (callback is supposed to make retries until no hopes..) 13 | // offset points 32bit words, count counts bytes 14 | typedef int (*read_wiidisc_callback_t)(void*fp,u32 offset,u32 count,void*iobuf); 15 | 16 | typedef enum{ 17 | UPDATE_PARTITION_TYPE=0, 18 | GAME_PARTITION_TYPE, 19 | OTHER_PARTITION_TYPE, 20 | // value in between selects partition types of that value 21 | ALL_PARTITIONS=0xffffffff-3, 22 | REMOVE_UPDATE_PARTITION, // keeps game + channel installers 23 | ONLY_GAME_PARTITION, 24 | }partition_selector_t; 25 | 26 | typedef struct wiidisc_s 27 | { 28 | read_wiidisc_callback_t read; 29 | void *fp; 30 | u8 *sector_usage_table; 31 | 32 | // everything points 32bit words. 33 | u32 disc_raw_offset; 34 | u32 partition_raw_offset; 35 | u32 partition_data_offset; 36 | u32 partition_data_size; 37 | u32 partition_block; 38 | 39 | u8 *tmp_buffer; 40 | u8 *tmp_buffer2; 41 | u8 disc_key[16]; 42 | int dont_decrypt; 43 | 44 | partition_selector_t part_sel; 45 | 46 | char *extract_pathname; 47 | u8 *extracted_buffer; 48 | }wiidisc_t; 49 | 50 | wiidisc_t *wd_open_disc(read_wiidisc_callback_t read,void*fp); 51 | void wd_close_disc(wiidisc_t *); 52 | // returns a buffer allocated with wbfs_ioalloc() or NULL if not found of alloc error 53 | u8 * wd_extract_file(wiidisc_t *d, partition_selector_t partition_type, char *pathname); 54 | 55 | void wd_build_disc_usage(wiidisc_t *d, partition_selector_t selector, u8* usage_table); 56 | 57 | // effectively remove not copied partition from the partition table. 58 | void wd_fix_partition_table(wiidisc_t *d, partition_selector_t selector, u8* partition_table); 59 | 60 | #if 0 61 | { 62 | #endif 63 | #ifdef __cplusplus 64 | } 65 | #endif /* __cplusplus */ 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /source/cios-lib/libwbfs_os.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _LIBWBFS_OS_H_ 26 | #define _LIBWBFS_OS_H_ 27 | 28 | #include "mem.h" 29 | #include "types.h" 30 | 31 | #define debug_printf(fmt, ...) 32 | 33 | #define wbfs_fatal(x) do { debug_printf("\nwbfs panic:%s\n\n", x); while(1); } while(0) 34 | #define wbfs_error(x) do { debug_printf("\nwbfs error:%s\n\n", x); } while(0) 35 | #define wbfs_malloc(x) Mem_Alloc(x) 36 | #define wbfs_free(x) Mem_Free(x) 37 | #define wbfs_ioalloc(x) Mem_Alloc(x) 38 | #define wbfs_iofree(x) Mem_Free(x) 39 | #define wbfs_ntohl(x) (x) 40 | #define wbfs_htonl(x) (x) 41 | #define wbfs_ntohs(x) (x) 42 | #define wbfs_htons(x) (x) 43 | 44 | #include 45 | 46 | #define wbfs_memcmp(x,y,z) memcmp(x,y,z) 47 | #define wbfs_memcpy(x,y,z) memcpy(x,y,z) 48 | #define wbfs_memset(x,y,z) memset(x,y,z) 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /source/cios-lib/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | 27 | #include "ios.h" 28 | #include "str_utils.h" 29 | #include "syscalls.h" 30 | #include "types.h" 31 | 32 | void LOG_Write(const char *msg, const char* func, u32 line) 33 | { 34 | static char buffer[8]; 35 | 36 | svc_write(moduleName); 37 | svc_write(": ("); 38 | svc_write(func); 39 | svc_write(", "); 40 | svc_write(itoa(line, buffer, 10)); 41 | svc_write(") : "); 42 | svc_write(msg); 43 | } 44 | -------------------------------------------------------------------------------- /source/cios-lib/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _LOG_H_ 26 | #define _LOG_H_ 27 | 28 | #include "types.h" 29 | 30 | 31 | /* Prototypes */ 32 | void LOG_Write(const char *msg, const char* func, u32 line); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/cios-lib/mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | 26 | #include "ios.h" 27 | #include "log.h" 28 | #include "syscalls.h" 29 | 30 | /* Variables */ 31 | static s32 hid = -1; 32 | 33 | 34 | s32 Mem_Init(u32 *heapspace, u32 heapspaceSize) 35 | { 36 | /* Heap already created */ 37 | if (hid >= 0) 38 | return 0; 39 | 40 | /* Create heap */ 41 | hid = os_heap_create(heapspace, heapspaceSize); 42 | 43 | return (hid < 0) ? hid : 0; 44 | } 45 | 46 | void *Mem_Alloc(u32 size) 47 | { 48 | /* Allocate memory */ 49 | return os_heap_alloc_aligned(hid, size, 32); 50 | } 51 | 52 | #ifdef CIOSLIB_DEBUG 53 | void *Mem_Alloc_Debug(u32 size, const char* func, u32 line) 54 | { 55 | void *p; 56 | 57 | if (hid < 0) { 58 | LOG_Write("Mem subsystem not initialized.\n", func, line); 59 | return NULL; 60 | } 61 | 62 | /* Allocate memory */ 63 | p = Mem_Alloc(size); 64 | 65 | if (p == NULL) 66 | LOG_Write("Can't allocate memory.\n", func, line); 67 | 68 | return p; 69 | } 70 | #endif 71 | 72 | void Mem_Free(void *ptr) 73 | { 74 | /* Free memory */ 75 | os_heap_free(hid, ptr); 76 | } -------------------------------------------------------------------------------- /source/cios-lib/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _MEM_H_ 26 | #define _MEM_H_ 27 | 28 | #include "ios.h" 29 | #include "types.h" 30 | 31 | #define MEM1_SIZE 0x1800000 32 | 33 | /* Prototypes */ 34 | s32 Mem_Init(u32 *heapspace, u32 heapspaceSize); 35 | #ifdef CIOSLIB_DEBUG 36 | void *Mem_Alloc_Debug(u32 size, const char* func, u32 line); 37 | #define Mem_Alloc(S) Mem_Alloc_Debug(S, __FUNCTION__, __LINE__) 38 | #else 39 | void *Mem_Alloc(u32 size); 40 | #endif 41 | void Mem_Free(void *ptr); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /source/cios-lib/sdhc_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2009 Waninkoko. 5 | Copyright (C) 2011 davebaol. 6 | Copyright (C) 2022 blackb0x. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef _SDHC_H_ 24 | #define _SDHC_H_ 25 | 26 | #include "ipc.h" 27 | #include "types.h" 28 | 29 | /* SDHC descriptor */ 30 | #define SDHC_FD 0x5D4CFD 31 | 32 | /* Prototypes */ 33 | s32 SDHC_RegisterDevice(s32 queuehandle); 34 | s32 SDHC_CheckDevicePath(char *devpath); 35 | s32 SDHC_Close(void); 36 | s32 SDHC_Ioctlv(u32 cmd, ioctlv *vector, u32 inlen, u32 iolen); 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /source/cios-lib/sdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDIO_H_ 2 | #define _SDIO_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Prototypes */ 7 | bool sdio_Startup(void); 8 | bool sdio_Shutdown(void); 9 | bool sdio_ReadSectors (sec_t sector, sec_t numSectors, void *buffer); 10 | bool sdio_WriteSectors(sec_t sector, sec_t numSectors, const void *buffer); 11 | bool sdio_IsInserted(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /source/cios-lib/stealth.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "stealth.h" 26 | #include "swi_mload.h" 27 | #include "syscalls.h" 28 | #include "types.h" 29 | 30 | 31 | s32 Stealth_CheckRunningTitle(const char* command) 32 | { 33 | s32 ret; 34 | 35 | /* Get stealth mode */ 36 | ret = Swi_GetRunningTitle(); 37 | 38 | /* Trace blocked request */ 39 | if (ret) 40 | Stealth_Log(STEALTH_RUNNING_TITLE, command); 41 | 42 | return ret; 43 | } 44 | 45 | s32 Stealth_CheckEsRequest(const char* command) 46 | { 47 | s32 ret; 48 | 49 | /* Get ES status */ 50 | ret = Swi_GetEsRequest(); 51 | 52 | /* Trace blocked request */ 53 | if (!ret) 54 | Stealth_Log(STEALTH_ES_REQUEST, command); 55 | 56 | return ret; 57 | } 58 | 59 | void Stealth_Log(u32 type, const char* command) 60 | { 61 | svc_write(moduleName); 62 | svc_write(": "); 63 | if (type & STEALTH_RUNNING_TITLE) { 64 | svc_write("Title identified"); 65 | if (type & STEALTH_ES_REQUEST) 66 | svc_write(" or "); 67 | } 68 | if (type & STEALTH_ES_REQUEST) 69 | svc_write("Request not coming from ES"); 70 | svc_write(". Blocking "); 71 | if (command) { 72 | svc_write("custom command "); 73 | svc_write(command); 74 | } 75 | else 76 | svc_write("opening request"); 77 | svc_write(".\n"); 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /source/cios-lib/stealth.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STEALTH_H_ 26 | #define _STEALTH_H_ 27 | 28 | #include "types.h" 29 | 30 | /* Constants */ 31 | #define STEALTH_RUNNING_TITLE 0x01 32 | #define STEALTH_ES_REQUEST 0x02 33 | 34 | #define TID_RIGHTS_FORCE_REAL_NAND 0x01 35 | #define TID_RIGHTS_OPEN_FAT 0x02 36 | 37 | 38 | /* Prototypes */ 39 | s32 Stealth_CheckRunningTitle(const char* command); 40 | s32 Stealth_CheckEsRequest(const char* command); 41 | void Stealth_Log(u32 type, const char* command); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /source/cios-lib/str_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | 27 | #include "types.h" 28 | 29 | char *strrev(char *str) { 30 | char *p1, *p2; 31 | 32 | if (!str || !*str) 33 | return str; 34 | 35 | for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { 36 | *p1 ^= *p2; 37 | *p2 ^= *p1; 38 | *p1 ^= *p2; 39 | } 40 | 41 | return str; 42 | } 43 | 44 | char *itoa(int n, char *s, int b) { 45 | static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 46 | int i=0, sign; 47 | 48 | if ((sign = n) < 0) 49 | n = -n; 50 | 51 | do { 52 | s[i++] = digits[n % b]; 53 | } while ((n /= b) > 0); 54 | 55 | if (sign < 0) 56 | s[i++] = '-'; 57 | s[i] = '\0'; 58 | 59 | return strrev(s); 60 | } 61 | -------------------------------------------------------------------------------- /source/cios-lib/str_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _STR_UTILS_H_ 26 | #define _STR_UTILS_H_ 27 | 28 | #include "types.h" 29 | 30 | 31 | /* Prototypes */ 32 | char *strrev(char *str); 33 | char *itoa(int n, char *s, int b); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/cios-lib/swi_mload.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "swi_mload.h" 26 | #include "tools.h" 27 | #include "types.h" 28 | 29 | 30 | void Swi_Memcpy(void *dst, void *src, s32 len) 31 | { 32 | /* Wrong length */ 33 | if (len <= 0) 34 | return; 35 | 36 | /* Call function */ 37 | Swi_MLoad(2, (u32)dst, (u32)src, (u32)len); 38 | } 39 | 40 | void Swi_uMemcpy(void *dst, void *src, s32 len) 41 | { 42 | /* Wrong length */ 43 | if (len <= 0) 44 | return; 45 | 46 | /* Call function */ 47 | Swi_MLoad(9, (u32)dst, (u32)src, (u32)len); 48 | } 49 | 50 | s32 Swi_CallFunc(s32 (*func)(void *in, void *out), void *in, void *out) 51 | { 52 | /* Call function */ 53 | return Swi_MLoad(16, (u32)func, (u32)in, (u32)out); 54 | } 55 | 56 | u32 Swi_GetIosInfo(iosInfo *buffer) 57 | { 58 | return Swi_MLoad(18, (u32)buffer, 0, 0); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /source/cios-lib/swi_mload.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _SWI_MLOAD_H_ 26 | #define _SWI_MLOAD_H_ 27 | 28 | #include "ios.h" 29 | #include "tools.h" 30 | #include "types.h" 31 | 32 | typedef s32(*TRCheckFunc)(s32 tid, u32 rights); 33 | 34 | /* Macros */ 35 | #define Swi_SetRegister(A, V) Swi_MLoad( 5, (A), (V), 0) 36 | #define Swi_ClearRegister(A, V) Swi_MLoad( 6, (A), (V), 0) 37 | #define Swi_GetSyscallBase() Swi_MLoad( 17, 0, 0, 0) 38 | #define Swi_SetRunningTitle(V) Swi_MLoad( 32, (V), 0, 0) 39 | #define Swi_GetRunningTitle() Swi_MLoad( 33, 0, 0, 0) 40 | #define Swi_SetEsRequest(V) Swi_MLoad( 34, (V), 0, 0) 41 | #define Swi_GetEsRequest() Swi_MLoad( 35, 0, 0, 0) 42 | #define Swi_AddThreadRights(T, R) Swi_MLoad( 36, (T), (R), 0) 43 | #define Swi_GetThreadRightsCheckFunc() ((TRCheckFunc)Swi_MLoad( 37, 0, 0, 0)) 44 | #define Swi_LedOn() Swi_MLoad(128, 0, 0, 0) 45 | #define Swi_LedOff() Swi_MLoad(129, 0, 0, 0) 46 | #define Swi_LedBlink() Swi_MLoad(130, 0, 0, 0) 47 | 48 | /* Prototypes */ 49 | void Swi_Memcpy(void *dst, void *src, s32 len); 50 | void Swi_uMemcpy(void *dst, void *src, s32 len); 51 | s32 Swi_CallFunc(s32 (*func)(void *in, void *out), void *in, void *out); 52 | u32 Swi_GetIosInfo(iosInfo *buffer); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /source/cios-lib/syscalls_dbg.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "ios.h" 26 | #include "log.h" 27 | #include "syscalls.h" 28 | #include "types.h" 29 | 30 | 31 | static void __dbg_os_sync_check_args(void *ptr, s32 size, const char* func, u32 line) 32 | { 33 | if (ptr == NULL) { 34 | if (size > 0) 35 | LOG_Write("buffer is NULL\n", func, line); 36 | } 37 | else if ((u32)ptr & 31) 38 | LOG_Write("buffer non 32 bytes aligned\n", func, line); 39 | else if (size & 3) 40 | LOG_Write("len non 4 bytes aligned\n", func, line); 41 | } 42 | 43 | void dbg_os_sync_before_read(void *ptr, s32 size, const char* func, u32 line) 44 | { 45 | __dbg_os_sync_check_args(ptr, size, func, line); 46 | __os_sync_before_read(ptr, size); 47 | } 48 | 49 | void dbg_os_sync_after_write(void *ptr, s32 size, const char* func, u32 line) 50 | { 51 | __dbg_os_sync_check_args(ptr, size, func, line); 52 | __os_sync_after_write(ptr, size); 53 | } -------------------------------------------------------------------------------- /source/cios-lib/syscalls_dbg.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _SYSCALLS_DBG_H_ 26 | #define _SYSCALLS_DBG_H_ 27 | 28 | #include "types.h" 29 | 30 | 31 | /* Prototypes */ 32 | void dbg_os_sync_before_read(void *ptr, s32 size, const char* func, u32 line); 33 | void dbg_os_sync_after_write(void *ptr, s32 size, const char* func, u32 line); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/cios-lib/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "ios.h" 26 | #include "mem.h" 27 | #include "syscalls.h" 28 | #include "types.h" 29 | 30 | /* Variables */ 31 | static s32 queuehandle = -1; 32 | static s32 timerId = -1; 33 | 34 | // Fix d2x v1 35 | // Back to timing logic from rev19 and below. 36 | // This solves the controller lag introduced by rev20 for certain HDD 37 | // when the watchdog is reading. 38 | s32 Timer_Init(void) 39 | { 40 | void *queuespace = NULL; 41 | 42 | /* Queue already created */ 43 | if (queuehandle >= 0) 44 | return 0; 45 | 46 | /* Alloc queue space */ 47 | queuespace = Mem_Alloc(0x40); 48 | if (!queuespace) 49 | return IPC_ENOMEM; 50 | 51 | /* Create queue */ 52 | queuehandle = os_message_queue_create(queuespace, 16); 53 | if (queuehandle < 0) { 54 | Mem_Free(queuespace); 55 | return queuehandle; 56 | } 57 | 58 | /* Create timer */ 59 | timerId = os_create_timer(1000000, 1, queuehandle, 0x666); 60 | if (timerId < 0) { 61 | os_message_queue_destroy(queuehandle); 62 | queuehandle = -1; 63 | Mem_Free(queuespace); 64 | return timerId; 65 | } 66 | 67 | /* Stop timer */ 68 | os_stop_timer(timerId); 69 | 70 | return 0; 71 | } 72 | 73 | void Timer_Sleep(u32 time) 74 | { 75 | u32 message; 76 | 77 | #ifdef CIOSLIB_DEBUG 78 | if (queuehandle == -1 || timerId == -1) { 79 | svc_write(moduleName); 80 | svc_write(": Timer susbsystem not initialized.\n"); 81 | } 82 | #endif 83 | 84 | /* Send message */ 85 | os_message_queue_send(queuehandle, 0x555, 0); 86 | 87 | /* Restart timer */ 88 | os_restart_timer(timerId, time, 0); 89 | 90 | while (1) { 91 | /* Wait to receive message */ 92 | os_message_queue_receive(queuehandle, (void *)&message, 0); 93 | 94 | /* Message received */ 95 | if (message == 0x555) 96 | break; 97 | } 98 | 99 | /* Wait to receive message */ 100 | os_message_queue_receive(queuehandle, (void *)&message, 0); 101 | 102 | /* Stop timer */ 103 | os_stop_timer(timerId); 104 | } 105 | -------------------------------------------------------------------------------- /source/cios-lib/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _TIMER_H_ 26 | #define _TIMER_H_ 27 | 28 | /* Macros */ 29 | #define udelay(t) Timer_Sleep(t) 30 | #define usleep(t) Timer_Sleep(t) 31 | #define msleep(t) Timer_Sleep((t)*1000) 32 | 33 | /* Prototypes */ 34 | s32 Timer_Init(void); 35 | void Timer_Sleep(u32 time); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /source/cios-lib/tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _TOOLS_H_ 26 | #define _TOOLS_H_ 27 | 28 | #include "types.h" 29 | 30 | 31 | /* Macros */ 32 | #define DCWrite8(addr, val) do { \ 33 | *(vu8 *)(addr) = (val); \ 34 | DCFlushRange((void *)(addr), sizeof(u8)); \ 35 | } while (0) 36 | 37 | #define DCWrite16(addr, val) do { \ 38 | *(vu16 *)(addr) = (val); \ 39 | DCFlushRange((void *)(addr), sizeof(u16)); \ 40 | } while (0) 41 | 42 | #define DCWrite32(addr, val) do { \ 43 | *(vu32 *)(addr) = (val); \ 44 | DCFlushRange((void *)(addr), sizeof(u32)); \ 45 | } while (0) 46 | 47 | 48 | /* Direct syscalls */ 49 | void DCInvalidateRange(void* ptr, int size); 50 | void DCFlushRange(void* ptr, int size); 51 | void ICInvalidate(void); 52 | 53 | /* MLoad syscalls */ 54 | s32 Swi_MLoad(u32 arg0, u32 arg1, u32 arg2, u32 arg3); 55 | 56 | /* ARM permissions */ 57 | u32 Perms_Read(void); 58 | void Perms_Write(u32 flags); 59 | 60 | /* MEM2 routines */ 61 | void MEM2_Prot(u32 flag); 62 | 63 | /* Tools */ 64 | void *VirtToPhys(void *address); 65 | void *PhysToVirt(void *address); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /source/cios-lib/tools.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | .text 26 | 27 | .align 4 28 | .code 32 29 | 30 | /* Direct syscalls */ 31 | .global DCInvalidateRange 32 | DCInvalidateRange: 33 | mcr p15, 0, r0, c7, c6, 1 34 | add r0, #0x20 35 | subs r1, #1 36 | bne DCInvalidateRange 37 | bx lr 38 | 39 | .global DCFlushRange 40 | DCFlushRange: 41 | mcr p15, 0, r0, c7, c10, 1 42 | add r0, #0x20 43 | subs r1, #1 44 | bne DCFlushRange 45 | bx lr 46 | 47 | .global ICInvalidate 48 | ICInvalidate: 49 | mov r0, #0 50 | mcr p15, 0, r0, c7, c5, 0 51 | bx lr 52 | 53 | 54 | /* MLoad syscalls */ 55 | .global Swi_MLoad 56 | Swi_MLoad: 57 | svc 0xcc 58 | bx lr 59 | 60 | 61 | /* ARM permissions */ 62 | .global Perms_Read 63 | Perms_Read: 64 | mrc p15, 0, r0, c3, c0 65 | bx lr 66 | 67 | .global Perms_Write 68 | Perms_Write: 69 | mcr p15, 0, r0, c3, c0 70 | bx lr 71 | 72 | 73 | /* MEM2 routines */ 74 | .global MEM2_Prot 75 | MEM2_Prot: 76 | ldr r1, =0xD8B420A 77 | strh r0, [r1] 78 | bx lr 79 | 80 | 81 | /* Tools */ 82 | .global VirtToPhys 83 | VirtToPhys: 84 | and r0, #0x7fffffff 85 | bx lr 86 | 87 | .global PhysToVirt 88 | PhysToVirt: 89 | orr r0, #0x80000000 90 | bx lr 91 | -------------------------------------------------------------------------------- /source/cios-lib/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2010 Hermes. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _IOS_TYPES_H_ 26 | #define _IOS_TYPES_H_ 27 | 28 | #include 29 | 30 | /* NULL constant */ 31 | #ifndef NULL 32 | # define NULL ((void *)0) 33 | #endif 34 | 35 | /* Data types */ 36 | typedef char s8; 37 | typedef short s16; 38 | typedef long s32; 39 | typedef unsigned char u8; 40 | typedef unsigned short u16; 41 | typedef unsigned int u32; 42 | typedef unsigned long long u64; 43 | typedef volatile unsigned char vu8; 44 | typedef volatile unsigned short vu16; 45 | typedef volatile unsigned int vu32; 46 | 47 | typedef uint32_t sec_t; 48 | 49 | typedef int bool; 50 | 51 | /* Boolean constants */ 52 | #define true 1 53 | #define false 0 54 | 55 | /* Attributes */ 56 | #ifndef ATTRIBUTE_ALIGN 57 | # define ATTRIBUTE_ALIGN(v) __attribute__((aligned(v))) 58 | #endif 59 | #ifndef ATTRIBUTE_PACKED 60 | # define ATTRIBUTE_PACKED __attribute__((packed)) 61 | #endif 62 | 63 | /* Stack align */ 64 | #define STACK_ALIGN(type, name, cnt, alignment) \ 65 | u8 _al__##name[((sizeof(type)*(cnt)) + (alignment) + (((sizeof(type)*(cnt))%(alignment)) > 0 ? ((alignment) - ((sizeof(type)*(cnt))%(alignment))) : 0))]; \ 66 | type *name = (type*)(((u32)(_al__##name)) + ((alignment) - (((u32)(_al__##name))&((alignment)-1)))) 67 | 68 | #endif -------------------------------------------------------------------------------- /source/cios-lib/usbstorage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Library 3 | 4 | Copyright (C) 2009 Kwiirk. 5 | Copyright (C) 2010 Waninkoko. 6 | Copyright (C) 2011 davebaol. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | 24 | #ifndef _USBSTORAGE_H_ 25 | #define _USBSTORAGE_H_ 26 | 27 | #include "types.h" 28 | 29 | /* Prototypes */ 30 | bool usbstorage_Init(void); 31 | bool usbstorage_Shutdown(void); 32 | bool usbstorage_IsInserted(void); 33 | bool usbstorage_ReadSectors(u32 sector, u32 numSectors, void *buffer); 34 | bool usbstorage_WriteSectors(u32 sector, u32 numSectors, void *buffer); 35 | u32 usbstorage_GetSectorSize(void); 36 | bool usbstorage_ClearStatus(void); 37 | bool __usbstorage_Read_Write(u32 write, u32 sector, u32 numSectors, void *buffer); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /source/cios-lib/vsprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef _VSPRINTF_H_ 2 | #define _VSPRINTF_H_ 3 | 4 | #include "types.h" 5 | 6 | int svc_printf(const char *format, ...); 7 | 8 | #endif -------------------------------------------------------------------------------- /source/dip-plugin/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wno-address-of-packed-member -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = dip-plugin 32 | 33 | # Objects 34 | OBJS = config.o \ 35 | dip.o \ 36 | dip_calls.o \ 37 | dma.o \ 38 | fat.o \ 39 | frag.o \ 40 | main.o \ 41 | patches.o \ 42 | plugin.o \ 43 | sdhc.o \ 44 | start.o \ 45 | wbfs.o 46 | 47 | 48 | $(TARGET).elf: $(OBJS) $(LIBS) 49 | @echo -e " LD\t$@" 50 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 51 | @$(STRIP) $@.orig $@ 52 | 53 | %.o: %.s 54 | @echo -e " CC\t$@" 55 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 56 | 57 | %.o: %.c 58 | @echo -e " CC\t$@" 59 | @$(CC) $(CFLAGS) -c -o $@ $< 60 | 61 | clean: 62 | @echo -e "Cleaning..." 63 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 64 | -------------------------------------------------------------------------------- /source/dip-plugin/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2011 davebaol, oggzee. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _CONFIG_H_ 21 | #define _CONFIG_H_ 22 | 23 | #include "plugin.h" 24 | #include "types.h" 25 | 26 | /* Prototypes */ 27 | s32 DI_Config_Load(struct dipConfigState *cfg); 28 | s32 DI_Config_Save(struct dipConfigState *cfg); 29 | s32 FFS_Config_Load(struct ffsConfigState *cfg); 30 | s32 FFS_Config_Save(struct ffsConfigState *cfg); 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /source/dip-plugin/dip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _DIP_H_ 21 | #define _DIP_H_ 22 | 23 | #include "types.h" 24 | 25 | /* Disc lengths */ 26 | #define DVD5_LENGTH 0x46090000 27 | #define DVD9_LENGTH 0x7ED38000 28 | 29 | /* Disc sector */ 30 | #define SECTOR_SIZE 0x800 31 | #define MAX_SECTOR_SIZE 0x7F8000 32 | 33 | 34 | /* Prototypes */ 35 | u32 DI_CustomCmd(void *inbuf, void *outbuf); 36 | s32 DI_StopMotor(void); 37 | s32 DI_ReadDvd(u8 *outbuf, u32 len, u32 offset); 38 | s32 DI_ReadWod(void *outbuf, u32 len, u32 offset); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /source/dip-plugin/dip_calls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _DIP_CALLS_H_ 22 | #define _DIP_CALLS_H_ 23 | 24 | #include "types.h" 25 | 26 | //#define DEBUG 27 | 28 | /* DIP functions */ 29 | #ifdef DEBUG 30 | s32 (*DI_Printf)(const char * fmt, ...); 31 | #else 32 | #define DI_Printf(fmt, ...) do {} while (0) 33 | #endif 34 | extern s32 (*DI_ReadHash)(void); 35 | extern void *(*DI_Alloc)(u32 size, u32 align); 36 | extern void (*DI_Free)(void *ptr); 37 | 38 | /* DIP handlers */ 39 | extern s32 DI_HandleIoctl(void *buffer, u32 fd); 40 | extern s32 DI_HandleCmd(void *inbuf, const void *outbuf, u32 size); 41 | extern s32 DI_HandleInitDrive(void); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /source/dip-plugin/dip_calls.s: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | 22 | /* 23 | * Macros 24 | */ 25 | .macro jump addr 26 | ldr r3, =(\addr) 27 | ldr r3, [r3] 28 | bx r3 29 | .endm 30 | 31 | 32 | .align 4 33 | 34 | /* 35 | * DIP handlers 36 | */ 37 | .code 16 38 | .thumb_func 39 | 40 | .global DI_HandleIoctl 41 | DI_HandleIoctl: 42 | push {r4-r7, lr} 43 | mov r7, r10 44 | mov r6, r8 45 | push {r6, r7} 46 | ldr r5, [r0] 47 | mov r10, r1 48 | jump addr_handleIoctl 49 | 50 | .code 16 51 | .thumb_func 52 | 53 | .global DI_HandleCmd 54 | DI_HandleCmd: 55 | push {r4-r7, lr} 56 | mov r7, r11 57 | mov r6, r10 58 | mov r5, r9 59 | mov r4, r8 60 | push {r4-r7} 61 | jump addr_handleCmd 62 | 63 | 64 | /* 65 | * DVD driver initializer (2nd stage) 66 | */ 67 | .code 32 68 | .global DI_HandleInitDrive 69 | DI_HandleInitDrive: 70 | push {r4, lr} 71 | bl os_check_DI_reset 72 | lsls r0, r0, #0x18 73 | jump addr_handleInitDrive 74 | -------------------------------------------------------------------------------- /source/dip-plugin/dma.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "types.h" 21 | 22 | /* DMA constants */ 23 | #define DMA1_START_ADDRESS 0x00000000 24 | #define DMA1_END_ADDRESS 0x01800000 25 | #define DMA2_START_ADDRESS 0x10000000 26 | #define DMA2_END_ADDRESS 0x13618000 27 | 28 | 29 | s32 DMA_CheckRange(void *outbuf, u32 size, u32 alignment) 30 | { 31 | u32 mem; 32 | s32 ret = 0; 33 | 34 | /* Output buffer address */ 35 | mem = (u32)outbuf; 36 | 37 | /* Check for memory alignment */ 38 | if (!(mem & 31)) { 39 | u32 dmalen = 0; 40 | 41 | /* DMA1 range check */ 42 | if ((mem >= DMA1_START_ADDRESS) && (mem < DMA1_END_ADDRESS)) 43 | dmalen = (DMA1_END_ADDRESS - mem); 44 | 45 | /* DMA2 range check */ 46 | if ((mem >= DMA2_START_ADDRESS) && (mem < DMA2_END_ADDRESS)) 47 | dmalen = (DMA2_END_ADDRESS - mem); 48 | 49 | if (dmalen >= alignment) 50 | ret = (dmalen < size) ? dmalen : size; 51 | 52 | ret -= (ret & (alignment - 1)); 53 | } 54 | 55 | return ret; 56 | } 57 | -------------------------------------------------------------------------------- /source/dip-plugin/dma.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _DMA_H_ 21 | #define _DMA_H_ 22 | 23 | #include "types.h" 24 | 25 | /* Prototypes */ 26 | s32 DMA_CheckRange(void *outbuf, u32 size, u32 alignment); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /source/dip-plugin/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _ERRNO_H_ 21 | #define _ERRNO_H_ 22 | 23 | /* Return codes */ 24 | #define DIP_EIO 0xA000 25 | 26 | /* Error codes */ 27 | #define ERROR_BLOCK_RANGE 0x52100 28 | #define ERROR_WRONG_DISC 0x53100 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /source/dip-plugin/fat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2011 davebaol. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _FAT_H_ 21 | #define _FAT_H_ 22 | 23 | #include "types.h" 24 | 25 | 26 | /* Prototypes */ 27 | s32 FAT_Mount(u32 device, u32 partition); 28 | s32 FAT_GetPartition(u32 device, u32 *partition); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /source/dip-plugin/frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS 3 | * 4 | * Copyright (C) 2010-2011 Waninkoko, WiiGator, oggzee, davebaol. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _FRAG_H_ 21 | #define _FRAG_H_ 22 | 23 | #define FRAG_MAX 20000 24 | 25 | typedef struct 26 | { 27 | u32 offset; // file offset, in sectors unit 28 | u32 sector; 29 | u32 count; 30 | } Fragment; 31 | 32 | typedef struct 33 | { 34 | u32 size; // num sectors 35 | u32 num; // num fragments 36 | u32 maxnum; 37 | Fragment frag[FRAG_MAX]; 38 | } FragList; 39 | 40 | extern FragList fraglist_data; 41 | extern FragList *frag_list; 42 | 43 | /* Prototypes */ 44 | s32 Frag_Init(u32 device, void *fraglist, s32 size); 45 | void Frag_Close(void); 46 | s32 Frag_Read(void *data, u32 len, u32 woffset); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /source/dip-plugin/ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol, oggzee. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _IOCTL_H_ 22 | #define _IOCTL_H_ 23 | 24 | /* IOCTL commands */ 25 | #define IOCTL_DI_LOW_READ 0x71 26 | #define IOCTL_DI_READID 0x70 27 | #define IOCTL_DI_WAITCVRCLOSE 0x79 28 | #define IOCTL_DI_COVER_REG 0x7A 29 | #define IOCTL_DI_COVER_CLEAR 0x86 30 | #define IOCTL_DI_COVER_STATUS 0x88 31 | #define IOCTL_DI_COVER_SET 0x89 32 | #define IOCTL_DI_RESET 0x8A 33 | #define IOCTL_DI_UNENCREAD 0x8D 34 | #define IOCTL_DI_STATUS_REG 0x95 35 | #define IOCTL_DI_REPORT_KEY 0xA4 36 | #define IOCTL_DI_READ_A8 0xA8 37 | #define IOCTL_DI_SEEK 0xAB 38 | #define IOCTL_DI_READ_D0 0xD0 39 | #define IOCTL_DI_OFFSET 0xD9 40 | #define IOCTL_DI_READBCA 0xDA 41 | #define IOCTL_DI_REQCOVER 0xDB 42 | #define IOCTL_DI_REQERROR 0xE0 43 | #define IOCTL_DI_STOP_MOTOR 0xE3 44 | #define IOCTL_DI_AUDIO_CONFIG 0xE4 45 | 46 | /* Custom IOCTL commands */ 47 | #define IOCTL_DI_OFFSET_SET 0xF0 48 | #define IOCTL_DI_OFFSET_GET 0xF1 49 | #define IOCTL_DI_CRYPT_SET 0xF2 50 | #define IOCTL_DI_CRYPT_GET 0xF3 51 | #define IOCTL_DI_WBFS_SET 0xF4 52 | #define IOCTL_DI_WBFS_GET 0xF5 53 | #define IOCTL_DI_RESET_DISABLE 0xF6 54 | #define IOCTL_DI_FRAG_SET 0xF9 55 | #define IOCTL_DI_MODE_GET 0xFA 56 | #define IOCTL_DI_SAVE_CONFIG 0xFE 57 | #define IOCTL_DI_CUSTOMCMD 0xFF 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /source/dip-plugin/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x13800000, LENGTH = 0x2000 9 | ram(rw) : ORIGIN = 0x13802000, LENGTH = 0x40000 10 | } 11 | 12 | __exe_start_phys__ = 0x13800000; 13 | __ram_start_phys__ = 0x13802000; 14 | 15 | SECTIONS { 16 | .ios_info_table : { 17 | KEEP (*(.ios_info_table)) 18 | } > table 19 | 20 | .init : AT (__exe_start_phys__) { 21 | *(.init) 22 | . = ALIGN(4); 23 | } > exe 24 | 25 | .text : { 26 | *(.text*) 27 | *(.gnu.warning) 28 | *(.gnu.linkonce.t.*) 29 | *(.init) 30 | *(.glue_7) 31 | *(.glue_7t) 32 | . = ALIGN(4); 33 | } > exe 34 | 35 | .data : AT (__ram_start_phys__) { 36 | *(.data*) 37 | *(.data.*) 38 | *(.gnu.linkonce.d.*) 39 | . = ALIGN(4); 40 | } > ram 41 | 42 | .rodata : { 43 | *(.rodata) 44 | *all.rodata*(*) 45 | *(.roda) 46 | *(.rodata.*) 47 | *(.gnu.linkonce.r.*) 48 | . = ALIGN(4); 49 | } > ram 50 | 51 | .bss : { 52 | *(.dynsbss) 53 | *(.gnu.linkonce.sb.*) 54 | *(.bss*) 55 | *(COMMON) 56 | KEEP(*(.ios_bss)) 57 | . = ALIGN(4); 58 | } > ram 59 | } 60 | -------------------------------------------------------------------------------- /source/dip-plugin/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "ios.h" 22 | #include "patches.h" 23 | #include "syscalls.h" 24 | #include "types.h" 25 | 26 | 27 | char *moduleName = "DIP"; 28 | 29 | int main(void) 30 | { 31 | /* System patchers */ 32 | static patcher patchers[] = {{Patch_DipModule, 0}}; 33 | 34 | /* Print info */ 35 | svc_write("$IOSVersion: DIPP: " __DATE__ " " __TIME__ " 64M$\n"); 36 | 37 | /* Initialize plugin */ 38 | IOS_InitSystem(patchers, sizeof(patchers)); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /source/dip-plugin/patches.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _PATCHES_H_ 21 | #define _PATCHES_H_ 22 | 23 | #include "types.h" 24 | 25 | /* Prototypes */ 26 | s32 Patch_DipModule(void); 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /source/dip-plugin/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol, oggzee. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _PLUGIN_H_ 22 | #define _PLUGIN_H_ 23 | 24 | #include "ipc.h" 25 | #include "isfs.h" 26 | #include "tools.h" 27 | #include "types.h" 28 | 29 | /* WOD magic word */ 30 | #define WOD_MAGIC 0x5D1C9EA3 31 | 32 | /* GameCube disc magic word */ 33 | #define GC_MAGIC 0xC2339F3D 34 | 35 | /* Mode codes */ 36 | #define MODE_DVDROM 0x01 37 | #define MODE_CRYPT 0x02 38 | #define MODE_WBFS 0x04 39 | #define MODE_FRAG 0x10 40 | #define MODE_EMUL ( MODE_WBFS | MODE_FRAG ) 41 | 42 | /* Macros */ 43 | #define DI_SetMode(bit) BIT_SET(config.mode, (bit)) 44 | #define DI_DelMode(bit) BIT_DEL(config.mode, (bit)) 45 | #define DI_ChkMode(bit) BIT_CHK(config.mode, (bit)) 46 | 47 | /* Macros */ 48 | #define BIT_SET(x, y) (x |= y) 49 | #define BIT_DEL(x, y) (x &= ~y) 50 | #define BIT_CHK(x, y) (x & y) 51 | 52 | /* Disc types */ 53 | enum { 54 | DISC_UNKNOWN = 0, 55 | DISC_DVD5, 56 | DISC_DVD9, 57 | }; 58 | 59 | 60 | /* Config structure */ 61 | struct dipConfig { 62 | /* Modes */ 63 | u32 mode; 64 | 65 | /* Type */ 66 | u32 type; 67 | 68 | /* Offsets */ 69 | u32 offset[2]; 70 | 71 | /* Last error */ 72 | u32 error; 73 | 74 | /* Misc variables */ 75 | u32 cover; 76 | u32 noreset; 77 | }; 78 | 79 | /* DIP config state */ 80 | struct dipConfigState { 81 | /* DIP mode */ 82 | u32 mode; 83 | 84 | /* DIP device */ 85 | u32 device; 86 | 87 | /* DIP fraglist size */ 88 | u32 frag_size; 89 | }; 90 | 91 | /* FFS config state */ 92 | struct ffsConfigState { 93 | /* FFS mode */ 94 | u32 mode; 95 | 96 | /* FFS partition */ 97 | u32 partition; 98 | 99 | /* FFS path */ 100 | char path[ISFS_MAXPATH]; 101 | }; 102 | 103 | /* IOCTL structure */ 104 | typedef struct { 105 | u32 command; 106 | 107 | u32 *inbuf; 108 | u32 inlen; 109 | u32 *iobuf; 110 | u32 iolen; 111 | } ioctl; 112 | 113 | /* Prototypes */ 114 | s32 DI_EmulateIoctl(ioctl *buffer, s32 fd); 115 | s32 DI_EmulateCmd(u32 *inbuf, u32 *outbuf, u32 size); 116 | void DI_EmulateInitDrive(void); 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /source/dip-plugin/sdhc.c: -------------------------------------------------------------------------------- 1 | 2 | #include "syscalls.h" 3 | #include "types.h" 4 | #include "sdhc.h" 5 | 6 | #include 7 | #include 8 | 9 | /* IOCTL commands */ 10 | #define IOCTL_SDHC_INIT 0x01 11 | #define IOCTL_SDHC_READ 0x02 12 | #define IOCTL_SDHC_WRITE 0x03 13 | #define IOCTL_SDHC_ISINSERTED 0x04 14 | 15 | /* Constants */ 16 | #define SDHC_SECTOR_SIZE 0x200 17 | 18 | /* Variables */ 19 | static char fs[] ATTRIBUTE_ALIGN(32) = "/dev/sdio/sdhc"; 20 | static ioctlv io_vector[3] ATTRIBUTE_ALIGN(32); 21 | static u32 io_buffer[3] ATTRIBUTE_ALIGN(32); 22 | static s32 fd = -1; 23 | static u32 sectorSz = SDHC_SECTOR_SIZE; 24 | 25 | 26 | bool sdhc_Init(void) 27 | { 28 | //s32 ret; 29 | 30 | /* Already open */ 31 | if (fd >= 0) 32 | return true; 33 | 34 | /* Open USB device */ 35 | fd = os_open(fs, 1); 36 | if (fd < 0) 37 | return false; 38 | 39 | /* Initialize USB storage */ 40 | os_ioctlv(fd, IOCTL_SDHC_INIT, 0, 0, NULL); 41 | 42 | sectorSz = SDHC_SECTOR_SIZE; 43 | 44 | return true; 45 | } 46 | 47 | 48 | bool sdhc_Read(u32 sector, u32 numSectors, void *buffer) 49 | { 50 | u32 cnt; 51 | s32 ret; 52 | 53 | /* Device not opened */ 54 | if (fd < 0) 55 | return false; 56 | 57 | /* Sector info */ 58 | io_buffer[0] = sector; 59 | io_buffer[1] = numSectors; 60 | 61 | /* Setup io_vector */ 62 | io_vector[0].data = &io_buffer[0]; 63 | io_vector[0].len = sizeof(u32); 64 | io_vector[1].data = &io_buffer[1]; 65 | io_vector[1].len = sizeof(u32); 66 | io_vector[2].data = buffer; 67 | io_vector[2].len = (sectorSz * numSectors); 68 | 69 | /* Flush cache */ 70 | for (cnt = 0; cnt < 3; cnt++) 71 | os_sync_after_write(io_vector[cnt].data, io_vector[cnt].len); 72 | 73 | os_sync_after_write(io_vector, sizeof(ioctlv) * 3); 74 | 75 | /* Read data */ 76 | ret = os_ioctlv(fd, IOCTL_SDHC_READ, 2, 1, io_vector); 77 | if (ret < 0) 78 | return false; 79 | 80 | /* Invalidate cache */ 81 | for (cnt = 0; cnt < 3; cnt++) 82 | os_sync_before_read(io_vector[cnt].data, io_vector[cnt].len); 83 | 84 | return true; 85 | } 86 | 87 | 88 | bool sdhc_Shutdown(void) 89 | { 90 | if (fd >= 0) { 91 | /* Close USB device */ 92 | os_close(fd); 93 | /* Remove descriptor */ 94 | fd = -1; 95 | } 96 | return true; 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /source/dip-plugin/sdhc.h: -------------------------------------------------------------------------------- 1 | #ifndef _SDHC_H_ 2 | #define _SDHC_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Prototypes */ 7 | bool sdhc_Init(void); 8 | bool sdhc_Read(u32 sector, u32 numSectors, void *buffer); 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /source/dip-plugin/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS module for Wii. 3 | Copyright (C) 2008 neimod. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | .section ".init" 21 | .arm 22 | 23 | .EQU ios_thread_arg, 4 24 | .EQU ios_thread_priority, 0x48 25 | .EQU ios_thread_stacksize, 0x1000 26 | 27 | 28 | .global _start 29 | _start: 30 | mov r0, #0 @ int argc 31 | mov r1, #0 @ char *argv[] 32 | ldr r3, =main 33 | bx r3 34 | 35 | 36 | 37 | /* 38 | * IOS bss 39 | */ 40 | .section ".ios_bss", "a", %nobits 41 | 42 | .space ios_thread_stacksize 43 | .global ios_thread_stack /* stack decrements from high address.. */ 44 | ios_thread_stack: 45 | 46 | 47 | /* 48 | * IOS info table 49 | */ 50 | .section ".ios_info_table", "ax", %progbits 51 | 52 | .global ios_info_table 53 | ios_info_table: 54 | .long 0x0 55 | .long 0x28 @ numentries * 0x28 56 | .long 0x6 57 | 58 | .long 0xB 59 | .long ios_thread_arg @ passed to thread entry func, maybe module id 60 | 61 | .long 0x9 62 | .long _start 63 | 64 | .long 0x7D 65 | .long ios_thread_priority 66 | 67 | .long 0x7E 68 | .long ios_thread_stacksize 69 | 70 | .long 0x7F 71 | .long ios_thread_stack 72 | -------------------------------------------------------------------------------- /source/dip-plugin/wbfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include 22 | 23 | #include "dip_calls.h" 24 | #include "syscalls.h" 25 | 26 | /* Commands */ 27 | #define IOCTL_WBFS_BASE (('W'<<24) | ('F'<<16) | ('S'<<8)) 28 | #define IOCTL_WBFS_OPEN (IOCTL_WBFS_BASE + 0x1) 29 | #define IOCTL_WBFS_READ (IOCTL_WBFS_BASE + 0x2) 30 | 31 | /* Variables */ 32 | static char *devFs[] = { "/dev/usb2", "/dev/sdio/sdhc" }; 33 | static s32 devFd = -1; 34 | 35 | 36 | /* I/O buffer */ 37 | static ioctlv vector[4] ATTRIBUTE_ALIGN(32); 38 | static u32 buffer[9] ATTRIBUTE_ALIGN(32); 39 | 40 | 41 | s32 WBFS_Open(u32 device, u8 *discid) 42 | { 43 | /* Open device */ 44 | devFd = os_open(devFs[device], 1); 45 | if (devFd < 0) 46 | return devFd; 47 | 48 | /* Copy disc ID */ 49 | memcpy(buffer, discid, 6); 50 | 51 | /* Setup vector */ 52 | vector[0].data = buffer; 53 | vector[0].len = 6; 54 | 55 | /* Open disc */ 56 | return os_ioctlv(devFd, IOCTL_WBFS_OPEN, 1, 0, vector); 57 | } 58 | 59 | void WBFS_Close(void) 60 | { 61 | /* Close device */ 62 | if (devFd >= 0) 63 | os_close(devFd); 64 | 65 | /* Reset descriptor */ 66 | devFd = -1; 67 | } 68 | 69 | s32 WBFS_Read(void *outbuf, u32 len, u32 offset) 70 | { 71 | s32 ret; 72 | 73 | /* Set buffers */ 74 | buffer[0] = offset; 75 | buffer[8] = len; 76 | 77 | /* Setup vector */ 78 | vector[0].data = &buffer[0]; 79 | vector[0].len = 4; 80 | vector[1].data = &buffer[8]; 81 | vector[1].len = 4; 82 | vector[2].data = outbuf; 83 | vector[2].len = len; 84 | 85 | /* Flush cache */ 86 | os_sync_after_write(vector, sizeof(vector)); 87 | os_sync_after_write(buffer, sizeof(buffer)); 88 | 89 | /* Read data */ 90 | ret = os_ioctlv(devFd, IOCTL_WBFS_READ, 2, 1, vector); 91 | if (ret) 92 | return ret; 93 | 94 | /* Invalidate cache */ 95 | os_sync_before_read(outbuf, len); 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /source/dip-plugin/wbfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DIP plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _WBFS_H_ 21 | #define _WBFS_H_ 22 | 23 | /* Prototypes */ 24 | s32 WBFS_Open (u32 device, u8 *disid); 25 | void WBFS_Close(void); 26 | s32 WBFS_Read (void *outbuf, u32 len, u32 offset); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /source/ehci-module/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -Itinyehci -I../cios-lib -fomit-frame-pointer -Os -Wall -Wstrict-prototypes -ffunction-sections -Wno-address-of-packed-member -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = ehci-module 32 | 33 | # Objects 34 | OBJS = loop.o \ 35 | main.o \ 36 | start.o \ 37 | tinyehci.o \ 38 | usb_os.o \ 39 | wbfs.o 40 | 41 | 42 | $(TARGET).elf: $(OBJS) $(LIBS) 43 | @echo -e " LD\t$@" 44 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 45 | @$(STRIP) $@.orig $@ 46 | 47 | %.o: %.s 48 | @echo -e " CC\t$@" 49 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 50 | 51 | %.o: %.c 52 | @echo -e " CC\t$@" 53 | @$(CC) $(CFLAGS) -c -o $@ $< 54 | 55 | clean: 56 | @echo -e "Cleaning..." 57 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 58 | -------------------------------------------------------------------------------- /source/ehci-module/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x13780000, LENGTH = 0x5000 9 | ram(rw) : ORIGIN = 0x13785000, LENGTH = 0x24000 10 | } 11 | 12 | __exe_start_phys__ = 0x13780000; 13 | __ram_start_phys__ = 0x13785000; 14 | 15 | 16 | SECTIONS { 17 | .ios_info_table : { 18 | KEEP (*(.ios_info_table)) 19 | } > table 20 | 21 | .init : AT (__exe_start_phys__) { 22 | *(.init) 23 | . = ALIGN(4); 24 | } > exe 25 | 26 | .text : { 27 | *(.text*) 28 | *(.gnu.warning) 29 | *(.gnu.linkonce.t.*) 30 | *(.init) 31 | *(.glue_7) 32 | *(.glue_7t) 33 | . = ALIGN(4); 34 | } > exe 35 | 36 | .data : AT (__ram_start_phys__) { 37 | *(.data*) 38 | *(.data.*) 39 | *(.gnu.linkonce.d.*) 40 | . = ALIGN(4); 41 | } > ram 42 | 43 | .rodata : { 44 | *(.rodata) 45 | *all.rodata*(*) 46 | *(.roda) 47 | *(.rodata.*) 48 | *(.gnu.linkonce.r.*) 49 | . = ALIGN(4); 50 | } > ram 51 | 52 | .bss : { 53 | *(.dynsbss) 54 | *(.gnu.linkonce.sb.*) 55 | *(.bss*) 56 | *(COMMON) 57 | KEEP(*(.ios_bss)) 58 | . = ALIGN(4); 59 | } > ram 60 | } 61 | -------------------------------------------------------------------------------- /source/ehci-module/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (EHCI) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 kwiirk. 6 | Copyright (C) 2009 Hermes. 7 | Copyright (C) 2009 Waninkoko. 8 | Copyright (C) 2022 blackb0x. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include "mem.h" 26 | #include "syscalls.h" 27 | #include "timer.h" 28 | #include "tinyehci.h" 29 | #include "types.h" 30 | 31 | 32 | char *moduleName = "EHCI/SDHC"; 33 | 34 | int main(void) 35 | { 36 | /* Heap space */ 37 | static u32 heapspace[0x1000] ATTRIBUTE_ALIGN(32); 38 | 39 | s32 ret; 40 | 41 | /* Print info */ 42 | svc_write("$IOSVersion: EHCI: " __DATE__ " " __TIME__ " 64M$\n"); 43 | 44 | /* Initialize memory heap */ 45 | ret = Mem_Init(heapspace, sizeof(heapspace)); 46 | if (ret < 0) 47 | return ret; 48 | 49 | /* Initialize timer subsystem */ 50 | ret = Timer_Init(); 51 | if (ret < 0) 52 | return ret; 53 | 54 | /* Initialize TinyEhci */ 55 | ret = EHCI_Init(); 56 | if (ret < 0) 57 | return ret; 58 | 59 | /* Main loop */ 60 | EHCI_Loop(); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /source/ehci-module/module.h: -------------------------------------------------------------------------------- 1 | #ifndef _MODULE_H_ 2 | #define _MODULE_H_ 3 | 4 | /* Device name */ 5 | #define DEVICE "/dev/usb2" 6 | 7 | /* USB IOCTL commands */ 8 | #define USB_IOCTL_CTRLMSG 0 9 | #define USB_IOCTL_BLKMSG 1 10 | #define USB_IOCTL_INTRMSG 2 11 | #define USB_IOCTL_SUSPENDDEV 5 12 | #define USB_IOCTL_RESUMEDEV 6 13 | #define USB_IOCTL_GETDEVLIST 12 14 | #define USB_IOCTL_DEVREMOVALHOOK 26 15 | #define USB_IOCTL_DEVINSERTHOOK 27 16 | 17 | /* UMS IOCTL commands */ 18 | #define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) 19 | #define USB_IOCTL_UMS_INIT (UMS_BASE+0x1) 20 | #define USB_IOCTL_UMS_GET_CAPACITY (UMS_BASE+0x2) 21 | #define USB_IOCTL_UMS_READ_SECTORS (UMS_BASE+0x3) 22 | #define USB_IOCTL_UMS_WRITE_SECTORS (UMS_BASE+0x4) 23 | #define USB_IOCTL_UMS_READ_STRESS (UMS_BASE+0x5) 24 | #define USB_IOCTL_UMS_SET_VERBOSE (UMS_BASE+0x6) 25 | #define USB_IOCTL_UMS_UMOUNT (UMS_BASE+0x10) 26 | #define USB_IOCTL_UMS_WATCHDOG (UMS_BASE+0x80) 27 | 28 | /* WBFS IOCTL commands */ 29 | #define WBFS_BASE (('W'<<24)|('F'<<16)|('S'<<8)) 30 | #define USB_IOCTL_WBFS_OPEN_DISC (WBFS_BASE+0x1) 31 | #define USB_IOCTL_WBFS_READ_DISC (WBFS_BASE+0x2) 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /source/ehci-module/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (EHCI) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 kwiirk. 6 | Copyright (C) 2009 Hermes. 7 | Copyright (C) 2009 Waninkoko. 8 | Copyright (C) 2011 davebaol. 9 | 10 | This program is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation; either version 2 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | .section ".init" 26 | .arm 27 | 28 | .EQU ios_thread_arg, 4 29 | 30 | // FIX d2x v2 31 | // Thread priority decreased from 0x78 to 0x48, like it was in rev18 and below, 32 | // to fix the lag on secondary usb port when the watchdog is reading. 33 | .EQU ios_thread_priority, 0x48 34 | 35 | .EQU ios_thread_stacksize, 0x3000 36 | 37 | 38 | .global _start 39 | _start: 40 | mov r0, #0 @ int argc 41 | mov r1, #0 @ char *argv[] 42 | ldr r3, =main 43 | bx r3 44 | 45 | 46 | 47 | /* 48 | * IOS bss 49 | */ 50 | .section ".ios_bss", "a", %nobits 51 | 52 | .global ios_thread_stack_start 53 | ios_thread_stack_start: 54 | .space ios_thread_stacksize 55 | .global ios_thread_stack /* stack decrements from high address.. */ 56 | ios_thread_stack: 57 | 58 | 59 | /* 60 | * IOS info table 61 | */ 62 | .section ".ios_info_table", "ax", %progbits 63 | 64 | .global ios_info_table 65 | ios_info_table: 66 | .long 0x0 67 | .long 0x28 @ numentries * 0x28 68 | .long 0x6 69 | 70 | .long 0xB 71 | .long ios_thread_arg @ passed to thread entry func, maybe module id 72 | 73 | .long 0x9 74 | .long _start 75 | 76 | .long 0x7D 77 | .long ios_thread_priority 78 | 79 | .long 0x7E 80 | .long ios_thread_stacksize 81 | 82 | .long 0x7F 83 | .long ios_thread_stack 84 | -------------------------------------------------------------------------------- /source/ehci-module/tinyehci.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (EHCI) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 kwiirk. 6 | Copyright (C) 2009 Hermes. 7 | Copyright (C) 2009 Waninkoko. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "ehci_types.h" 28 | #include "ehci.h" 29 | #include "syscalls.h" 30 | #include "timer.h" 31 | #include "utils.h" 32 | 33 | #define static 34 | #define inline extern 35 | 36 | /* Macros */ 37 | #define debug_printf(a...) 38 | #define print_hex_dump_bytes(a, b, c, d) 39 | 40 | #define ehci_dbg(a...) debug_printf(a) 41 | #define printk(a...) debug_printf(a) 42 | #define BUG() while(1) 43 | #define BUG_ON(a) while(1) 44 | #define cpu_to_le32(a) swab32(a) 45 | #define le32_to_cpu(a) swab32(a) 46 | #define cpu_to_le16(a) swab16(a) 47 | #define le16_to_cpu(a) swab16(a) 48 | #define cpu_to_be32(a) (a) 49 | #define be32_to_cpu(a) (a) 50 | #define ehci_readl(a) (*(volatile u32 *)a) 51 | #define ehci_writel(v,a) do { *(volatile u32 *)a = v; } while(0) 52 | 53 | /* EHCI structure */ 54 | struct ehci_hcd _ehci; 55 | struct ehci_hcd *ehci = &_ehci; 56 | 57 | #include "ehci.c" 58 | 59 | 60 | s32 EHCI_Init(void) 61 | { 62 | s32 ret; 63 | 64 | ehci = &_ehci; 65 | 66 | /* EHCI addresses */ 67 | ehci->caps = (void *)(0x0D040000); 68 | ehci->regs = (void *)(0x0D040000 + HC_LENGTH(ehci_readl(&ehci->caps->hc_capbase))); 69 | 70 | /* Setup EHCI */ 71 | ehci->num_port = 4; 72 | ehci->hcs_params = ehci_readl(&ehci->caps->hcs_params); 73 | 74 | /* Initialize EHCI */ 75 | ret = ehci_init(); 76 | if (ret) 77 | return ret; 78 | 79 | /* Release non USB2 ports */ 80 | ehci_release_ports(); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /source/ehci-module/tinyehci.h: -------------------------------------------------------------------------------- 1 | #ifndef _TINYEHCI_H_ 2 | #define _TINYEHCI_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Prototypes */ 7 | s32 EHCI_Init(void); 8 | s32 EHCI_Loop(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /source/ehci-module/tinyehci/ehci-mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Original Copyright (c) 2001 by David Brownell 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation; either version 2 of the License, or (at your 7 | * option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * 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 Free Software Foundation, 16 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | */ 18 | 19 | /* this file is part of ehci.c */ 20 | 21 | 22 | static inline void ehci_qtd_init(struct ehci_qtd *qtd 23 | ) 24 | { 25 | dma_addr_t dma = ehci_virt_to_dma(qtd); 26 | memset (qtd, 0, sizeof *qtd); 27 | qtd->qtd_dma = dma; 28 | qtd->hw_token = (QTD_STS_HALT); 29 | qtd->hw_next = EHCI_LIST_END(); 30 | qtd->hw_alt_next = EHCI_LIST_END(); 31 | } 32 | static inline struct ehci_qtd * ehci_qtd_alloc(void) 33 | { 34 | struct ehci_qtd *qtd ; 35 | //debug_printf("ehci_qtd used=%x\n",ehci->qtd_used); 36 | if(ehci->qtd_used>=EHCI_MAX_QTD) return NULL; 37 | qtd = ehci->qtds[ehci->qtd_used++]; 38 | ehci_qtd_init(qtd); 39 | return qtd; 40 | } 41 | 42 | int ehci_mem_init (void) 43 | { 44 | int i; 45 | #if 1 46 | ehci->periodic = ehci_maligned(DEFAULT_I_TDPS * sizeof(__le32),32,4096); 47 | ehci->periodic_dma = ehci_virt_to_dma(ehci->periodic); 48 | 49 | for (i = 0; i < DEFAULT_I_TDPS; i++) 50 | ehci->periodic [i] = EHCI_LIST_END(); 51 | ehci_writel(ehci->periodic_dma, &ehci->regs->frame_list); 52 | #else 53 | debug_printf("ehci periodic:%x\n",ehci_readl(ehci, &ehci->regs->frame_list)); 54 | debug_printf("ehci *periodic:%x\n",*(u32*)ehci_readl(ehci, &ehci->regs->frame_list)); 55 | #endif 56 | for(i=0;iqtds[i] = ehci_maligned(sizeof(struct ehci_qtd),32,4096); 58 | ehci->qtd_used = 0; 59 | ehci->asyncqh = ehci_maligned(sizeof(struct ehci_qh),32,4096); 60 | ehci->asyncqh->ehci = ehci; 61 | ehci->asyncqh->qh_dma = ehci_virt_to_dma(ehci->asyncqh); 62 | ehci->asyncqh->qtd_head = NULL; 63 | 64 | ehci->async = ehci_maligned(sizeof(struct ehci_qh),32,4096); 65 | ehci->async->ehci = ehci; 66 | ehci->async->qh_dma = ehci_virt_to_dma(ehci->async); 67 | ehci->async->qtd_head = NULL; 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /source/ehci-module/tinyehci/ehci.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiidev/d2x-cios/33ad1eeeb8f562df99e7d7ca428fdd36e0e31be7/source/ehci-module/tinyehci/ehci.c -------------------------------------------------------------------------------- /source/ehci-module/tinyehci/ehci_types.h: -------------------------------------------------------------------------------- 1 | #ifndef EHCI_TYPES_H 2 | #define EHCI_TYPES_H 3 | /* linux kernel types needed by our code */ 4 | #define __iomem 5 | 6 | #include "types.h" 7 | 8 | #define __u32 u32 9 | #define __le32 u32 10 | #define dma_addr_t u32 11 | #define __GNUG__ 12 | #define size_t u32 13 | typedef unsigned int spinlock_t; 14 | typedef enum 15 | { 16 | GFP_KERNEL=1 17 | }gfp_t; 18 | struct timer_list 19 | { 20 | int time; 21 | }; 22 | 23 | enum{ 24 | ENODEV =1, 25 | ETIMEDOUT, 26 | EINVAL, 27 | ENOMEM, 28 | 29 | }; 30 | #define jiffies 0 31 | #define likely(x) __builtin_expect(!!(x), 1) 32 | #define unlikely(x) __builtin_expect(!!(x), 0) 33 | #define container_of(ptr, type, member) ({ \ 34 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 35 | (type *)( (char *)__mptr - offsetof(type,member) );}) 36 | 37 | #undef offsetof 38 | #ifdef __compiler_offsetof 39 | #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) 40 | #else 41 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 42 | #endif 43 | #endif 44 | -------------------------------------------------------------------------------- /source/ehci-module/tinyehci/usbstorage.h: -------------------------------------------------------------------------------- 1 | #ifndef __USBSTORAGE_H__ 2 | #define __USBSTORAGE_H__ 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif /* __cplusplus */ 8 | 9 | #include "ehci.h" 10 | 11 | 12 | #define USBSTORAGE_OK 0 13 | #define USBSTORAGE_ENOINTERFACE -10000 14 | #define USBSTORAGE_ESENSE -10001 15 | #define USBSTORAGE_ESHORTWRITE -10002 16 | #define USBSTORAGE_ESHORTREAD -10003 17 | #define USBSTORAGE_ESIGNATURE -10004 18 | #define USBSTORAGE_ETAG -10005 19 | #define USBSTORAGE_ESTATUS -10006 20 | #define USBSTORAGE_EDATARESIDUE -10007 21 | #define USBSTORAGE_ETIMEDOUT -ETIMEDOUT 22 | #define USBSTORAGE_EINIT -10009 23 | 24 | typedef struct 25 | { 26 | u8 configuration; 27 | u32 interface; 28 | u32 altInterface; 29 | 30 | u8 ep_in; 31 | u8 ep_out; 32 | 33 | u8 max_lun; 34 | u32 sector_size[16]; 35 | u32 n_sector[16]; 36 | 37 | struct ehci_device * usb_fd; 38 | 39 | //mutex_t lock; 40 | //cond_t cond; 41 | s32 retval; 42 | 43 | u32 tag; 44 | u8 ata_protocol; 45 | 46 | u8 *buffer; 47 | } usbstorage_handle; 48 | 49 | s32 USBStorage_Init(void); 50 | void USBStorage_Umount(void); 51 | 52 | s32 USBStorage_Open(usbstorage_handle *dev, struct ehci_device *fd); 53 | s32 USBStorage_Close(usbstorage_handle *dev); 54 | s32 USBStorage_Reset(usbstorage_handle *dev); 55 | 56 | s32 USBStorage_GetMaxLUN(usbstorage_handle *dev); 57 | s32 USBStorage_MountLUN(usbstorage_handle *dev, u8 lun); 58 | s32 USBStorage_Suspend(usbstorage_handle *dev); 59 | 60 | s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors); 61 | s32 USBStorage_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer); 62 | s32 USBStorage_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer); 63 | s32 USBStorage_Inquiry(usbstorage_handle *dev, u8 lun); 64 | 65 | #define DEVICE_TYPE_WII_USB (('W'<<24)|('U'<<16)|('S'<<8)|'B') 66 | 67 | s32 USBStorage_Try_Device(struct ehci_device *fd); 68 | void USBStorage_Umount(void); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif /* __cplusplus */ 73 | 74 | 75 | #endif /* __USBSTORAGE_H__ */ 76 | -------------------------------------------------------------------------------- /source/ehci-module/usb_os.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (EHCI) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 kwiirk. 6 | Copyright (C) 2009 Hermes. 7 | Copyright (C) 2009 Waninkoko. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | 26 | #include "ehci_types.h" 27 | #include "ehci.h" 28 | #include "mem.h" 29 | #include "syscalls.h" 30 | #include "timer.h" 31 | #include "usb.h" 32 | 33 | /* Heap */ 34 | static u32 heapspace[0x4000] ATTRIBUTE_ALIGN(32); 35 | 36 | /* Variables */ 37 | static u8 *aligned_mem = 0; 38 | static u8 *aligned_base = 0; 39 | 40 | 41 | void *ehci_maligned(int size, int alignement, int crossing) 42 | { 43 | if (!aligned_mem) { 44 | aligned_base = (u8 *)(((u32)heapspace + 4095) & ~4095); 45 | aligned_mem = aligned_base; 46 | } 47 | 48 | u32 addr = (u32)aligned_mem; 49 | 50 | alignement--; 51 | 52 | /* Calculate aligned address */ 53 | addr += alignement; 54 | addr &= ~alignement; 55 | 56 | if (((addr + size - 1) & ~(crossing - 1)) != (addr & ~(crossing - 1))) 57 | addr = (addr + size - 1) & ~(crossing - 1); 58 | 59 | aligned_mem = (void *)(addr + size); 60 | 61 | /* Clear buffer */ 62 | memset((void *)addr, 0, size); 63 | 64 | return (void *)addr; 65 | } 66 | 67 | dma_addr_t ehci_virt_to_dma(void *a) 68 | { 69 | return (dma_addr_t)a; 70 | } 71 | 72 | dma_addr_t ehci_dma_map_to(void *buf, size_t len) 73 | { 74 | os_sync_after_write(buf, len); 75 | return (dma_addr_t)buf; 76 | } 77 | 78 | dma_addr_t ehci_dma_map_from(void *buf, size_t len) 79 | { 80 | os_sync_after_write(buf, len); 81 | return (dma_addr_t)buf; 82 | } 83 | 84 | dma_addr_t ehci_dma_map_bidir(void *buf, size_t len) 85 | { 86 | os_sync_after_write(buf, len); 87 | return (dma_addr_t)buf; 88 | } 89 | 90 | void ehci_dma_unmap_to(dma_addr_t buf,size_t len) 91 | { 92 | os_sync_before_read((void *)buf, len); 93 | } 94 | 95 | void ehci_dma_unmap_from(dma_addr_t buf, size_t len) 96 | { 97 | os_sync_before_read((void *)buf, len); 98 | } 99 | 100 | void ehci_dma_unmap_bidir(dma_addr_t buf, size_t len) 101 | { 102 | os_sync_before_read((void *)buf, len); 103 | } 104 | 105 | void ehci_usleep(int time) 106 | { 107 | usleep(time); 108 | } 109 | 110 | void ehci_msleep(int time) 111 | { 112 | msleep(time); 113 | } 114 | 115 | 116 | void *USB_Alloc(int size) 117 | { 118 | return Mem_Alloc(size); 119 | } 120 | 121 | void USB_Free(void *ptr) 122 | { 123 | return Mem_Free(ptr); 124 | } 125 | -------------------------------------------------------------------------------- /source/ehci-module/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H 3 | 4 | /* Macros */ 5 | #define swab32(x) ((u32)( \ 6 | (((u32)(x) & (u32)0x000000ffUL) << 24) | \ 7 | (((u32)(x) & (u32)0x0000ff00UL) << 8) | \ 8 | (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \ 9 | (((u32)(x) & (u32)0xff000000UL) >> 24))) 10 | 11 | #define swab16(x) ((u16)( \ 12 | (((u16)(x) & (u16)0x00ffU) << 8) | \ 13 | (((u16)(x) & (u16)0xff00U) >> 8))) 14 | 15 | #endif -------------------------------------------------------------------------------- /source/ehci-module/wbfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (EHCI) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 kwiirk. 6 | Copyright (C) 2009 Hermes. 7 | Copyright (C) 2009 Waninkoko. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "ehci_types.h" 28 | #include "ehci.h" 29 | #include "syscalls.h" 30 | #include "libwbfs/libwbfs.h" 31 | 32 | /* Variables */ 33 | static wbfs_t *hdd = NULL; 34 | static wbfs_disc_t *disc = NULL; 35 | 36 | static u32 nbSector, sectorSize; 37 | 38 | 39 | static int __WBFS_ReadSector(void *cbdata, u32 lba, u32 count, void *buffer) 40 | { 41 | s32 ret; 42 | 43 | /* Read data */ 44 | ret = USBStorage_Read_Sectors(lba, count, buffer); 45 | if (!ret) 46 | return 1; 47 | 48 | /* Invalidate range */ 49 | os_sync_before_read(buffer, sectorSize * count); 50 | 51 | return 0; 52 | } 53 | 54 | 55 | s32 WBFS_OpenDisc(u8 *discid) 56 | { 57 | s32 ret; 58 | 59 | /* Initialize USB storage */ 60 | ret = USBStorage_Init(); 61 | if (ret) 62 | return 1; 63 | 64 | /* Get sector size */ 65 | nbSector = USBStorage_Get_Capacity(§orSize); 66 | if (!nbSector) 67 | return 2; 68 | 69 | /* Close disc/device */ 70 | if (disc) 71 | wbfs_close_disc(disc); 72 | if (hdd) 73 | wbfs_close(hdd); 74 | 75 | /* Open device */ 76 | hdd = wbfs_open_hd(__WBFS_ReadSector, NULL, NULL, sectorSize, nbSector, 0); 77 | if (!hdd) 78 | return 3; 79 | 80 | /* Open disc */ 81 | disc = wbfs_open_disc(hdd, discid); 82 | if (!disc) 83 | return 4; 84 | 85 | return 0; 86 | } 87 | 88 | s32 WBFS_Read(void *buffer, u32 len, u32 offset) 89 | { 90 | /* No disc opened */ 91 | if (!disc) 92 | return 1; 93 | 94 | /* Disc read */ 95 | return wbfs_disc_read(disc, offset, buffer, len); 96 | } 97 | -------------------------------------------------------------------------------- /source/ehci-module/wbfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _WBFS_H_ 2 | #define _WBFS_H_ 3 | 4 | /* Prototypes */ 5 | s32 WBFS_OpenDisc(u8 *discid); 6 | s32 WBFS_Read(void *buffer, u32 len, u32 offset); 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /source/es-plugin/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = es-plugin 32 | 33 | # Objects 34 | OBJS = config.o \ 35 | di.o \ 36 | es_calls.o \ 37 | main.o \ 38 | patches.o \ 39 | plugin.o \ 40 | start.o 41 | 42 | 43 | $(TARGET).elf: $(OBJS) $(LIBS) 44 | @echo -e " LD\t$@" 45 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 46 | @$(STRIP) $@.orig $@ 47 | 48 | %.o: %.s 49 | @echo -e " CC\t$@" 50 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 51 | 52 | %.o: %.c 53 | @echo -e " CC\t$@" 54 | @$(CC) $(CFLAGS) -c -o $@ $< 55 | 56 | clean: 57 | @echo -e "Cleaning..." 58 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 59 | -------------------------------------------------------------------------------- /source/es-plugin/config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "isfs.h" 22 | #include "syscalls.h" 23 | #include "types.h" 24 | #include "es_calls.h" 25 | 26 | /* Constants */ 27 | #define FILENAME "/sys/esp.cfg" 28 | 29 | 30 | static s32 __Config_Create(void) 31 | { 32 | s32 ret; 33 | 34 | /* Open ISFS */ 35 | ret = ISFS_Open(); 36 | if (ret < 0) 37 | return ret; 38 | 39 | /* Create file */ 40 | ret = ISFS_CreateFile(FILENAME); 41 | 42 | /* Close ISFS */ 43 | ISFS_Close(); 44 | 45 | return ret; 46 | } 47 | 48 | static s32 __Config_Delete(void) 49 | { 50 | s32 ret; 51 | 52 | /* Open ISFS */ 53 | ret = ISFS_Open(); 54 | if (ret < 0) 55 | return ret; 56 | 57 | /* Delete file */ 58 | ret = ISFS_Delete(FILENAME); 59 | 60 | /* Close ISFS */ 61 | ISFS_Close(); 62 | 63 | return ret; 64 | } 65 | 66 | // NOTE: 67 | // This function is called by the main before patching Nintendo's ES module. 68 | // Since this code is not running in ES thread don't use ES_printf for 69 | // debugging purpose. Use svc_write instead. 70 | s32 Config_Load(void *cfg, u32 size) 71 | { 72 | s32 fd, ret; 73 | 74 | #ifdef DEBUG 75 | svc_write("ESP: Config_Load(): Loading config file "FILENAME"\n"); 76 | #endif 77 | 78 | /* Open config file */ 79 | fd = os_open(FILENAME, ISFS_OPEN_READ); 80 | #ifdef DEBUG 81 | svc_write("ESP: Config_Load(): Config file ");svc_write(fd<0? "NOT found\n": "found\n"); 82 | #endif 83 | if (fd < 0) 84 | return fd; 85 | 86 | /* Read config */ 87 | ret = os_read(fd, cfg, size); 88 | 89 | /* Close config */ 90 | os_close(fd); 91 | 92 | /* Delete config file */ 93 | __Config_Delete(); 94 | 95 | return ret; 96 | } 97 | 98 | s32 Config_Save(void *cfg, u32 size) 99 | { 100 | s32 fd, ret; 101 | 102 | /* Create config file */ 103 | __Config_Create(); 104 | 105 | /* Open config file */ 106 | fd = os_open(FILENAME, ISFS_OPEN_WRITE); 107 | if (fd < 0) 108 | return fd; 109 | 110 | /* Write config */ 111 | ret = os_write(fd, cfg, size); 112 | 113 | /* Close config */ 114 | os_close(fd); 115 | 116 | return ret; 117 | } -------------------------------------------------------------------------------- /source/es-plugin/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _CONFIG_H_ 22 | #define _CONFIG_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Prototypes */ 27 | s32 Config_Load(void *cfg, u32 size); 28 | s32 Config_Save(void *cfg, u32 size); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /source/es-plugin/di.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2011 davebaol. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include "syscalls.h" 21 | #include "types.h" 22 | 23 | #define IOCTL_DI_SAVE_CONFIG 0xFE 24 | 25 | static u32 inbuf[8] ATTRIBUTE_ALIGN(32); 26 | static u32 outbuf[8] ATTRIBUTE_ALIGN(32); 27 | 28 | s32 DI_Config_Save(void) 29 | { 30 | s32 fd, ret; 31 | 32 | /* Open /dev/di */ 33 | fd = os_open("/dev/di", 0); 34 | if (fd < 0) 35 | return fd; 36 | 37 | /* Save config */ 38 | inbuf[0] = IOCTL_DI_SAVE_CONFIG << 24; 39 | ret = os_ioctl(fd, IOCTL_DI_SAVE_CONFIG, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); 40 | 41 | /* Close /dev/di */ 42 | os_close(fd); 43 | 44 | return ret; 45 | } 46 | -------------------------------------------------------------------------------- /source/es-plugin/di.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2011 davebaol. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #ifndef _DI_H_ 21 | #define _DI_H_ 22 | 23 | #include "types.h" 24 | 25 | /* Prototypes */ 26 | s32 DI_Config_Save(void); 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /source/es-plugin/es_calls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _ES_CALLS_H_ 22 | #define _ES_CALLS_H_ 23 | 24 | #include "types.h" 25 | 26 | //#define DEBUG 27 | 28 | /* Prototypes */ 29 | #ifdef DEBUG 30 | s32 (*ES_printf)(const char * fmt, ...); 31 | #else 32 | #define ES_printf(fmt, ...) do {} while (0) 33 | #endif 34 | extern s32 (*ES_snprintf)(char *str, u32 size, const char *fmt, ...); 35 | extern s32 (*ES_LaunchTitle)(u32 tidh, u32 tidl, void *view, u32 reset); 36 | extern void *(*ES_memcpy)(void *dst, void *src, s32 n); 37 | 38 | /* ES handlers */ 39 | extern s32 ES_HandleOpen(void *message); 40 | extern s32 ES_HandleIoctlv(void *message); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /source/es-plugin/es_calls.s: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | 22 | /* 23 | * Macros 24 | */ 25 | .macro jump addr 26 | ldr r3, =(\addr) 27 | ldr r3, [r3] 28 | bx r3 29 | .endm 30 | 31 | 32 | .align 4 33 | 34 | 35 | /* 36 | * ES handlers 37 | */ 38 | .code 16 39 | .thumb_func 40 | 41 | .global ES_HandleOpen 42 | ES_HandleOpen: 43 | push {r4-r6, lr} 44 | movs r6, r0 45 | add r6, #0xC 46 | ldr r0, [r0, #0xC] 47 | 48 | jump addrOpen 49 | 50 | 51 | .code 16 52 | .thumb_func 53 | 54 | .global ES_HandleIoctlv 55 | ES_HandleIoctlv: 56 | push {r4-r6, lr} 57 | sub sp, sp, #0x20 58 | ldr r5, [r0, #8] 59 | add r1, r0, #0 60 | 61 | jump addrIoctlv 62 | -------------------------------------------------------------------------------- /source/es-plugin/ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef _IOCTL_H_ 2 | #define _IOCTL_H_ 3 | 4 | /* IOCTL commands */ 5 | #define IOCTL_ES_LAUNCH 0x08 6 | #define IOCTL_ES_DIVERIFY 0x1C 7 | #define IOCTL_ES_GETNUMTICKETVIEWS 0x12 8 | #define IOCTL_ES_GETTICKETVIEWS 0x13 9 | #define IOCTL_ES_KOREANCHECK 0x45 10 | 11 | /* Custom IOCTL commands */ 12 | #define IOCTL_ES_SET_FAKE_IOS_LAUNCH 0xA0 13 | #define IOCTL_ES_SET_FAKE_SM_LAUNCH 0xA1 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /source/es-plugin/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm", "elf32-bigarm", "elf32-littlearm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | ios_info_table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x13849000, LENGTH = 0x2000 9 | ram(rwx) : ORIGIN = 0x1384b000, LENGTH = 0x4000 10 | } 11 | 12 | __exe_start_virt__ = 0x13849000; 13 | __exe_start_phys__ = 0x13849000; 14 | __ram_start_virt__ = 0x1384b000; 15 | __ram_start_phys__ = 0x1384b000; 16 | __ios_info_table_start = 0x0; 17 | 18 | 19 | SECTIONS { 20 | .debug_aranges 0 : { 21 | *(.debug_aranges) 22 | } 23 | .debug_pubnames 0 : { 24 | *(.debug_pubnames) 25 | } 26 | .debug_info 0 : { 27 | *(.debug_info) 28 | } 29 | .debug_abbrev 0 : { 30 | *(.debug_abbrev) 31 | } 32 | .debug_line 0 : { 33 | *(.debug_line) 34 | } 35 | .debug_frame 0 : { 36 | *(.debug_frame) 37 | } 38 | .debug_str 0 : { 39 | *(.debug_str) 40 | } 41 | .debug_loc 0 : { 42 | *(.debug_loc) 43 | } 44 | .debug_macinfo 0 : { 45 | *(.debug_macinfo) 46 | } 47 | .note.arm.ident 0 : { 48 | KEEP (*(.note.arm.ident)) 49 | } 50 | 51 | .ios_info_table __ios_info_table_start : { 52 | . = .; 53 | KEEP (*(.ios_info_table)) 54 | } > ios_info_table 55 | 56 | .init __exe_start_virt__ : AT (__exe_start_phys__) { 57 | . = .; 58 | KEEP (*(.init)) 59 | } > exe 60 | 61 | .text ALIGN (0x4) : { 62 | *(.text*) 63 | *(.gnu.warning) 64 | *(.gnu.linkonce.t.*) 65 | *(.init) 66 | *(.glue_7) 67 | *(.glue_7t) 68 | } > exe 69 | 70 | .data __ram_start_virt__ : AT (__ram_start_phys__) { 71 | KEEP (*(.ios_data)) 72 | *(.data*) 73 | *(.data1) 74 | *(.gnu.linkonce.d.*) 75 | . = ALIGN (4); 76 | __CTOR_LIST__ = ABSOLUTE (.); 77 | KEEP (*(SORT (.ctors*))) 78 | __CTOR_END__ = ABSOLUTE (.); 79 | __DTOR_LIST__ = ABSOLUTE (.); 80 | KEEP (*(SORT (.dtors*))) 81 | __DTOR_END__ = ABSOLUTE (.); 82 | *(.dynamic) 83 | *(.sdata*) 84 | *(.gnu.linkonce.s.*) 85 | . = ALIGN (4); 86 | *(.2ram.*) 87 | } > ram 88 | 89 | .fini : { 90 | . = .; 91 | *(.fini) 92 | } > ram 93 | 94 | .rodata ALIGN (0x4) : { 95 | . = .; 96 | *(.rodata*) 97 | *(.gnu.linkonce.r.*) 98 | } > ram 99 | 100 | .rodata1 ALIGN (0x4) : { 101 | . = .; 102 | *(.rodata1) 103 | } > ram 104 | 105 | .fixup ALIGN (0x4) : { 106 | . = .; 107 | *(.fixup) 108 | } > ram 109 | 110 | .gcc_except_table ALIGN (0x4) : { 111 | . = .; 112 | *(.gcc_except_table) 113 | } > ram 114 | 115 | .got ALIGN (0x4) : { 116 | *(.got.plt) 117 | *(.got) 118 | } > ram 119 | 120 | .bss ALIGN (0x4) : { 121 | *(.scommon) 122 | *(.dynsbss) 123 | *(.sbss*) 124 | *(.gnu.linkonce.sb.*) 125 | *(.dynbss) 126 | *(.bss*) 127 | *(.gnu.linkonce.b.*) 128 | *(COMMON) 129 | KEEP (*(.ios_bss)) 130 | } > ram 131 | 132 | . = ALIGN(4); 133 | } 134 | -------------------------------------------------------------------------------- /source/es-plugin/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "config.h" 22 | #include "ios.h" 23 | #include "ipc.h" 24 | #include "patches.h" 25 | #include "plugin.h" 26 | #include "syscalls.h" 27 | #include "types.h" 28 | 29 | char *moduleName = "ES"; 30 | 31 | int main(void) 32 | { 33 | /* System patchers */ 34 | static patcher patchers[] = {{Patch_EsModule, 0}}; 35 | 36 | s32 fd; 37 | 38 | /* Print info */ 39 | svc_write("$IOSVersion: ESP: " __DATE__ " " __TIME__ " 64M$\n"); 40 | 41 | /* Load config */ 42 | Config_Load(&config, sizeof(config)); 43 | 44 | /* Initialize plugin */ 45 | IOS_InitSystem(patchers, sizeof(patchers)); 46 | 47 | /* Open ES to initialize 2nd stage */ 48 | fd = os_open("/dev/es", 0); 49 | if (fd < 0) 50 | svc_write("ESP: main: 2nd stage init failed.\n"); 51 | else 52 | os_close(fd); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /source/es-plugin/patches.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 20011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _PATCHES_H_ 22 | #define _PATCHES_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Prototypes */ 27 | s32 Patch_EsModule(void); 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /source/es-plugin/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ES plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _PLUGIN_H_ 22 | #define _PLUGIN_H_ 23 | 24 | #include "ipc.h" 25 | #include "types.h" 26 | 27 | 28 | /* Config structure */ 29 | struct esConfig { 30 | /* Fake launch mode */ 31 | u32 fakelaunch; 32 | 33 | /* ios to be launched in place of the requested one */ 34 | u32 ios; 35 | 36 | /* title_id of the game requesting ios reload */ 37 | u64 title_id; 38 | 39 | /* title_id to be launched in place of the system menu */ 40 | u64 sm_title_id; 41 | }; 42 | 43 | /* Prototypes */ 44 | s32 ES_EmulateOpen(ipcmessage *message); 45 | s32 ES_EmulateIoctlv(ipcmessage *message); 46 | 47 | /* Extern */ 48 | extern struct esConfig config; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /source/es-plugin/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS module for Wii. 3 | Copyright (C) 2008 neimod. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | .section ".init" 21 | .arm 22 | 23 | .EQU ios_thread_arg, 4 24 | .EQU ios_thread_priority, 0x48 25 | .EQU ios_thread_stacksize, 0x1000 26 | 27 | 28 | .global _start 29 | _start: 30 | mov r0, #0 @ int argc 31 | mov r1, #0 @ char *argv[] 32 | ldr r3, =main 33 | bx r3 34 | 35 | 36 | 37 | /* 38 | * IOS bss 39 | */ 40 | .section ".ios_bss", "a", %nobits 41 | 42 | .space ios_thread_stacksize 43 | .global ios_thread_stack /* stack decrements from high address.. */ 44 | ios_thread_stack: 45 | 46 | 47 | /* 48 | * IOS info table 49 | */ 50 | .section ".ios_info_table", "ax", %progbits 51 | 52 | .global ios_info_table 53 | ios_info_table: 54 | .long 0x0 55 | .long 0x28 @ numentries * 0x28 56 | .long 0x6 57 | 58 | .long 0xB 59 | .long ios_thread_arg @ passed to thread entry func, maybe module id 60 | 61 | .long 0x9 62 | .long _start 63 | 64 | .long 0x7D 65 | .long ios_thread_priority 66 | 67 | .long 0x7E 68 | .long ios_thread_stacksize 69 | 70 | .long 0x7F 71 | .long ios_thread_stack 72 | -------------------------------------------------------------------------------- /source/fat-module/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -ffunction-sections -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = fat-module 32 | 33 | # Objects 34 | OBJS = ccsbcs.o \ 35 | diskio.o \ 36 | fat_wrapper.o \ 37 | ff.o \ 38 | led.o \ 39 | main.o \ 40 | start.o \ 41 | syscall.o 42 | 43 | $(TARGET).elf: $(OBJS) $(LIBS) 44 | @echo -e " LD\t$@" 45 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 46 | @$(STRIP) $@.orig $@ 47 | 48 | %.o: %.s 49 | @echo -e " CC\t$@" 50 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 51 | 52 | %.o: %.c 53 | @echo -e " CC\t$@" 54 | @$(CC) $(CFLAGS) -c -o $@ $< 55 | 56 | clean: 57 | @echo -e "Cleaning..." 58 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 59 | -------------------------------------------------------------------------------- /source/fat-module/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Remove write functions */ 8 | #define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */ 9 | 10 | #include "integer.h" 11 | 12 | 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | 26 | /*---------------------------------------*/ 27 | /* Prototypes for disk control functions */ 28 | 29 | int assign_drives (int, int); 30 | DSTATUS disk_initialize (BYTE); 31 | DSTATUS disk_status (BYTE); 32 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 33 | #if _READONLY == 0 34 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 35 | #endif 36 | DRESULT disk_ioctl (BYTE, BYTE, void*); 37 | 38 | 39 | 40 | /* Disk Status Bits (DSTATUS) */ 41 | 42 | #define STA_NOINIT 0x01 /* Drive not initialized */ 43 | #define STA_NODISK 0x02 /* No medium in the drive */ 44 | #define STA_PROTECT 0x04 /* Write protected */ 45 | 46 | 47 | /* Command code for disk_ioctrl fucntion */ 48 | 49 | /* Generic command (defined for FatFs) */ 50 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ 51 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ 52 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ 53 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ 54 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ 55 | 56 | /* Generic command */ 57 | #define CTRL_POWER 5 /* Get/Set power status */ 58 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 59 | #define CTRL_EJECT 7 /* Eject media */ 60 | 61 | /* MMC/SDC specific ioctl command */ 62 | #define MMC_GET_TYPE 10 /* Get card type */ 63 | #define MMC_GET_CSD 11 /* Get CSD */ 64 | #define MMC_GET_CID 12 /* Get CID */ 65 | #define MMC_GET_OCR 13 /* Get OCR */ 66 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 67 | 68 | /* ATA/CF specific ioctl command */ 69 | #define ATA_GET_REV 20 /* Get F/W revision */ 70 | #define ATA_GET_MODEL 21 /* Get model name */ 71 | #define ATA_GET_SN 22 /* Get serial number */ 72 | 73 | /* NAND specific ioctl command */ 74 | #define NAND_FORMAT 30 /* Create physical format */ 75 | 76 | 77 | #define _DISKIO 78 | #endif 79 | -------------------------------------------------------------------------------- /source/fat-module/fat_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef _FAT_WRAPPER_H_ 2 | #define _FAT_WRAPPER_H_ 3 | 4 | #include "types.h" 5 | 6 | #define MAX_FILE 20 7 | 8 | /* Stats structure */ 9 | struct stats { 10 | /* Size */ 11 | u32 size; 12 | 13 | /* Date and time */ 14 | u16 date; 15 | u16 time; 16 | 17 | /* Attributes */ 18 | u8 attrib; 19 | 20 | /* Padding */ 21 | u8 pad[3]; 22 | }; 23 | 24 | /* File stats structure */ 25 | struct fstats { 26 | /* Length and position */ 27 | u32 length; 28 | u32 pos; 29 | }; 30 | 31 | 32 | /* Prototypes */ 33 | s32 FAT_Mount(u8 device, s32 partition); 34 | s32 FAT_Unmount(u8 dev); 35 | s32 FAT_Open(const char *path, u32 mode); 36 | s32 FAT_Close(s32 fd); 37 | s32 FAT_Read(s32 fd, void *buffer, u32 len); 38 | s32 FAT_Write(s32 fd, void *buffer, u32 len); 39 | s32 FAT_Seek(s32 fd, s32 where, s32 whence); 40 | s32 FAT_CreateDir(const char *dirpath); 41 | s32 FAT_CreateFile(const char *filepath); 42 | s32 FAT_ReadDir(const char *dirpath, char *outbuf, u32 buflen, u32 *outlen, u32 entries, u8 forFS); 43 | s32 FAT_Delete(const char *path); 44 | s32 FAT_DeleteDir(const char *dirpath); 45 | s32 FAT_Rename(const char *oldname, const char *newname); 46 | s32 FAT_GetStats(const char *path, struct stats *stats); 47 | s32 FAT_GetFileStats(s32 fd, struct fstats *stats); 48 | s32 FAT_GetUsage(const char *dirpath, u64 *size, u32 *files, u32 *dirs, u8 forFS); 49 | s32 FAT_GetPartition(u8 device, u32 *partition); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /source/fat-module/fs.h: -------------------------------------------------------------------------------- 1 | #ifndef _FS_H_ 2 | #define _FS_H_ 3 | 4 | /* FS error codes */ 5 | #define FS_SUCCESS 0 6 | #define FS_EINVAL -4 7 | #define FS_EFATAL -101 8 | #define FS_EACCESS -102 9 | #define FS_EEXIST -105 10 | #define FS_ENOENT -106 11 | #define FS_ENFILE -107 12 | #define FS_ENAMETOOLONG -110 13 | #define FS_ENOTEMPTY -115 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /source/fat-module/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /source/fat-module/led.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (FAT) 3 | 4 | Copyright (C) 2011 davebaol. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #include "syscalls.h" 22 | #include "swi_mload.h" 23 | #include "types.h" 24 | 25 | #define THREAD_STACK_SIZE 1024 26 | 27 | static vu32 state = 1; 28 | 29 | void Led_BlinkOn(void) 30 | { 31 | state &= ~7; 32 | } 33 | 34 | void Led_BlinkOff(void) 35 | { 36 | state |= 2; 37 | } 38 | 39 | s32 __Led_BlinkThread(void) 40 | { 41 | u32 queue_space[8]; 42 | s32 queue_handle; 43 | s32 timer_id; 44 | u32 message; 45 | 46 | /* Create message queue */ 47 | queue_handle = os_message_queue_create(queue_space, 8); 48 | 49 | /* Create timer */ 50 | timer_id = os_create_timer(1000*5, 1000*1000*10, queue_handle, 0); 51 | 52 | state = 4; 53 | 54 | /* Main loop */ 55 | while (1) { 56 | 57 | /* Wait for message */ 58 | s32 ret = os_message_queue_receive(queue_handle, (void*)&message, 0); 59 | if (ret) 60 | continue; 61 | 62 | os_stop_timer(timer_id); 63 | 64 | if ((state & 7) == 3) { 65 | state |= 4; 66 | Swi_LedOff(); 67 | } 68 | 69 | if ((state & 4) == 4) { 70 | os_restart_timer(timer_id, 1000*1000, 0); 71 | continue; 72 | } 73 | 74 | state ^= 128; 75 | 76 | if (state & 128) { 77 | Swi_LedOn(); 78 | os_restart_timer(timer_id, 1000*5, 0); 79 | state |= 1; 80 | } 81 | else { 82 | Swi_LedOff(); 83 | os_restart_timer(timer_id, 1000*1000, 0); 84 | } 85 | } 86 | 87 | return 0; 88 | } 89 | 90 | void Led_CreateBlinkThread(void) 91 | { 92 | static u8 thread_stack[THREAD_STACK_SIZE] ATTRIBUTE_ALIGN(32); 93 | 94 | s32 thread_id, priority; 95 | 96 | /* Get current thread priority */ 97 | priority = os_thread_get_priority(os_get_thread_id()); 98 | 99 | /* Create thread (in paused state) */ 100 | thread_id = os_thread_create( (void *) __Led_BlinkThread, NULL, &thread_stack[THREAD_STACK_SIZE], THREAD_STACK_SIZE, priority, 0); 101 | 102 | /* Resume thread */ 103 | if (thread_id >= 0) 104 | os_thread_continue(thread_id); 105 | } -------------------------------------------------------------------------------- /source/fat-module/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (FAT) 3 | 4 | Copyright (C) 2011 davebaol. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _LED_H_ 22 | #define _LED_H_ 23 | 24 | #define LED_ACTIVITY 25 | 26 | #ifdef LED_ACTIVITY 27 | void Led_BlinkOn(void); 28 | void Led_BlinkOff(void); 29 | void Led_CreateBlinkThread(void); 30 | #else 31 | #define Led_BlinkOn() do {} while (0) 32 | #define Led_BlinkOff() do {} while (0) 33 | #define Led_CreateBlinkThread() do {} while (0) 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /source/fat-module/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x137b5000, LENGTH = 0x5000 9 | ram(rw) : ORIGIN = 0x137ba000, LENGTH = 0x23000 10 | } 11 | 12 | __exe_start_phys__ = 0x137b5000; 13 | __ram_start_phys__ = 0x137ba000; 14 | 15 | 16 | SECTIONS { 17 | .ios_info_table : { 18 | KEEP (*(.ios_info_table)) 19 | } > table 20 | 21 | .init : AT (__exe_start_phys__) { 22 | *(.init) 23 | . = ALIGN(4); 24 | } > exe 25 | 26 | .text : { 27 | *(.text*) 28 | *(.gnu.warning) 29 | *(.gnu.linkonce.t.*) 30 | *(.init) 31 | *(.glue_7) 32 | *(.glue_7t) 33 | . = ALIGN(4); 34 | } > exe 35 | 36 | .data : AT (__ram_start_phys__) { 37 | *(.data*) 38 | *(.data.*) 39 | *(.gnu.linkonce.d.*) 40 | . = ALIGN(4); 41 | } > ram 42 | 43 | .rodata : { 44 | *(.rodata) 45 | *all.rodata*(*) 46 | *(.roda) 47 | *(.rodata.*) 48 | *(.gnu.linkonce.r.*) 49 | . = ALIGN(4); 50 | } > ram 51 | 52 | .bss : { 53 | *(.dynsbss) 54 | *(.gnu.linkonce.sb.*) 55 | *(.bss*) 56 | *(COMMON) 57 | KEEP(*(.ios_bss)) 58 | . = ALIGN(4); 59 | } > ram 60 | } 61 | -------------------------------------------------------------------------------- /source/fat-module/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (FAT) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _MAIN_H_ 25 | #define _MAIN_H_ 26 | 27 | //#define DEBUG 28 | 29 | #ifdef DEBUG 30 | #include "vsprintf.h" 31 | #define dbg_printf(fmt, ...) svc_printf(fmt, ## __VA_ARGS__) 32 | #else 33 | #define dbg_printf(fmt, ...) do {} while (0) 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /source/fat-module/module.h: -------------------------------------------------------------------------------- 1 | #ifndef _MODULE_H_ 2 | #define _MODULE_H_ 3 | 4 | /* IOCTL commands */ 5 | #define IOCTL_FAT_FILESTATS 11 6 | 7 | /* IOCTLV commands */ 8 | #define IOCTL_FAT_MKDIR 0x01 9 | #define IOCTL_FAT_MKFILE 0x02 10 | #define IOCTL_FAT_READDIR_FS 0x03 11 | #define IOCTL_FAT_READDIR 0x04 12 | #define IOCTL_FAT_DELETE 0x05 13 | #define IOCTL_FAT_DELETEDIR 0x06 14 | #define IOCTL_FAT_RENAME 0x07 15 | #define IOCTL_FAT_STATS 0x08 16 | #define IOCTL_FAT_GETUSAGE_FS 0x09 17 | #define IOCTL_FAT_GETUSAGE 0x0A 18 | #define IOCTL_FAT_MOUNT_SD 0xF0 19 | #define IOCTL_FAT_UMOUNT_SD 0xF1 20 | #define IOCTL_FAT_MOUNT_USB 0xF2 21 | #define IOCTL_FAT_UMOUNT_USB 0xF3 22 | #define IOCTL_FAT_GETPARTITION 0xF4 23 | #define IOCTL_FAT_SETNANDPATH 0xF5 24 | 25 | /* Device name */ 26 | #define DEVICE_FAT "fat" 27 | #define DEVICE_FAT_LEN (sizeof(DEVICE_FAT)-1) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /source/fat-module/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (FAT) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | .section ".init" 25 | .arm 26 | 27 | .EQU ios_thread_arg, 4 28 | .EQU ios_thread_priority, 0x62 29 | .EQU ios_thread_stacksize, 0x3000 30 | 31 | 32 | .global _start 33 | _start: 34 | mov r0, #0 @ int argc 35 | mov r1, #0 @ char *argv[] 36 | ldr r3, =main 37 | bx r3 38 | 39 | 40 | 41 | /* 42 | * IOS bss 43 | */ 44 | .section ".ios_bss", "a", %nobits 45 | 46 | .space ios_thread_stacksize 47 | .global ios_thread_stack /* stack decrements from high address.. */ 48 | ios_thread_stack: 49 | 50 | 51 | /* 52 | * IOS info table 53 | */ 54 | .section ".ios_info_table", "ax", %progbits 55 | 56 | .global ios_info_table 57 | ios_info_table: 58 | .long 0x0 59 | .long 0x28 @ numentries * 0x28 60 | .long 0x6 61 | 62 | .long 0xB 63 | .long ios_thread_arg @ passed to thread entry func, maybe module id 64 | 65 | .long 0x9 66 | .long _start 67 | 68 | .long 0x7D 69 | .long ios_thread_priority 70 | 71 | .long 0x7E 72 | .long ios_thread_stacksize 73 | 74 | .long 0x7F 75 | .long ios_thread_stack 76 | -------------------------------------------------------------------------------- /source/fat-module/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs R0.08 */ 3 | /* (C)ChaN, 2010 */ 4 | /*------------------------------------------------------------------------*/ 5 | 6 | #include "ff.h" 7 | #include "mem.h" 8 | 9 | 10 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 11 | /*------------------------------------------------------------------------*/ 12 | /* Allocate a memory block */ 13 | /*------------------------------------------------------------------------*/ 14 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 15 | */ 16 | 17 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 18 | UINT size /* Number of bytes to allocate */ 19 | ) 20 | { 21 | return Mem_Alloc(size); 22 | } 23 | 24 | 25 | /*------------------------------------------------------------------------*/ 26 | /* Free a memory block */ 27 | /*------------------------------------------------------------------------*/ 28 | 29 | void ff_memfree( 30 | void* mblock /* Pointer to the memory block to free */ 31 | ) 32 | { 33 | Mem_Free(mblock); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /source/ffs-plugin/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = ffs-plugin 32 | 33 | # Objects 34 | OBJS = iop.o \ 35 | iop_calls.o \ 36 | fat.o \ 37 | fs_calls.o \ 38 | fs_dump.o \ 39 | fs_tools.o \ 40 | main.o \ 41 | patches.o \ 42 | plugin.o \ 43 | start.o 44 | 45 | 46 | $(TARGET).elf: $(OBJS) $(LIBS) 47 | @echo -e " LD\t$@" 48 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 49 | @$(STRIP) $@.orig $@ 50 | 51 | %.o: %.s 52 | @echo -e " CC\t$@" 53 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 54 | 55 | %.o: %.c 56 | @echo -e " CC\t$@" 57 | @$(CC) $(CFLAGS) -c -o $@ $< 58 | 59 | clean: 60 | @echo -e "Cleaning..." 61 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 62 | -------------------------------------------------------------------------------- /source/ffs-plugin/fat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _FAT_H_ 22 | #define _FAT_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Stats structure */ 27 | struct stats { 28 | /* Size */ 29 | u32 size; 30 | 31 | /* Date and time */ 32 | u16 date; 33 | u16 time; 34 | 35 | /* Attributes */ 36 | u8 attrib; 37 | 38 | /* Padding */ 39 | u8 pad[3]; 40 | }; 41 | 42 | /* File stats structure */ 43 | struct fstats { 44 | /* Length and position */ 45 | u32 length; 46 | u32 pos; 47 | }; 48 | 49 | /* Constants */ 50 | #define FAT_MAXPATH 256 51 | 52 | /* Attributes */ 53 | #define AM_RDO 0x01 /* Read only */ 54 | #define AM_HID 0x02 /* Hidden */ 55 | #define AM_SYS 0x04 /* System */ 56 | #define AM_VOL 0x08 /* Volume label */ 57 | #define AM_LFN 0x0F /* LFN entry */ 58 | #define AM_DIR 0x10 /* Directory */ 59 | #define AM_ARC 0x20 /* Archive */ 60 | #define AM_MASK 0x3F /* Mask of defined bits */ 61 | 62 | 63 | /* Prototypes */ 64 | s32 FAT_Init(const char *nandpath); 65 | s32 FAT_CreateDir(const char *dirpath); 66 | s32 FAT_CreateFile(const char *filepath); 67 | s32 FAT_ReadDir(const char *dirpath, void *outbuf, u32 *entries); 68 | s32 FAT_Delete(const char *path); 69 | s32 FAT_DeleteDir(const char *dirpath); 70 | s32 FAT_Rename(const char *oldpath, const char *newpath); 71 | s32 FAT_GetStats(const char *path, struct stats *stats); 72 | s32 FAT_GetUsage(const char *path, u32 *blocks, u32 *inodes); 73 | s32 FAT_GetFileStats(s32 fd, struct fstats *stats); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /source/ffs-plugin/fs_calls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _FS_CALLS_H_ 22 | #define _FS_CALLS_H_ 23 | 24 | #include "types.h" 25 | 26 | //#define DEBUG 27 | #define FILTER_OPENING_REQUESTS 28 | 29 | 30 | /* Debug */ 31 | #ifdef DEBUG 32 | s32 (*FS_printf)(const char * fmt, ...); 33 | #else 34 | #define FS_printf(fmt, ...) do {} while (0) 35 | #endif 36 | 37 | /* FFS handlers */ 38 | s32 fs_unk (void *data); 39 | s32 fs_open (void *data); 40 | s32 fs_close (void *data); 41 | s32 fs_read (void *data); 42 | s32 fs_write (void *data); 43 | s32 fs_seek (void *data); 44 | s32 fs_ioctl (void *data); 45 | s32 fs_ioctlv(void *data); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /source/ffs-plugin/fs_calls.s: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | 22 | /* 23 | * Constants 24 | */ 25 | #define FS_CMD_OPEN 1 26 | #define FS_CMD_CLOSE 2 27 | #define FS_CMD_READ 3 28 | #define FS_CMD_WRITE 4 29 | #define FS_CMD_SEEK 5 30 | #define FS_CMD_IOCTL 6 31 | #define FS_CMD_IOCTLV 7 32 | 33 | /* 34 | * Macros 35 | */ 36 | .macro fs_call func cmd 37 | add r0, r4, #0 38 | push {r1-r7} 39 | push {r0} 40 | mov r1, sp 41 | bl \func 42 | pop {r3} 43 | cmp r3, #0 44 | bne fs_exit 45 | cmp r0, #0 46 | bge fs_exit 47 | 48 | // jump to the original fs command 49 | ldr r0, =addrTable 50 | ldr r3, [r0] 51 | ldr r0, [r3, #((\cmd) * 4)] 52 | pop {r1-r7} 53 | mov pc, r0 54 | .endm 55 | 56 | 57 | .text 58 | 59 | 60 | /* 61 | * FFS handlers 62 | */ 63 | .align 4 64 | .code 16 65 | 66 | .thumb 67 | 68 | .global fs_unk 69 | fs_unk: 70 | ldr r0, =addrTable 71 | ldr r0, [r0] 72 | nop 73 | ldr r0, [r0, #0] 74 | nop 75 | mov pc, r0 76 | 77 | .global fs_open 78 | fs_open: 79 | fs_call FS_Open, FS_CMD_OPEN 80 | 81 | .global fs_close 82 | fs_close: 83 | fs_call FS_Close, FS_CMD_CLOSE 84 | 85 | .global fs_read 86 | fs_read: 87 | fs_call FS_Read, FS_CMD_READ 88 | 89 | .global fs_write 90 | fs_write: 91 | fs_call FS_Write, FS_CMD_WRITE 92 | 93 | .global fs_seek 94 | fs_seek: 95 | fs_call FS_Seek, FS_CMD_SEEK 96 | 97 | .global fs_ioctl 98 | fs_ioctl: 99 | fs_call FS_Ioctl, FS_CMD_IOCTL 100 | 101 | .global fs_ioctlv 102 | fs_ioctlv: 103 | fs_call FS_Ioctlv, FS_CMD_IOCTLV 104 | 105 | fs_exit: 106 | pop {r1-r7} 107 | add r1, r0, #0 108 | ldr r0, =addrReentry 109 | ldr r0, [r0] 110 | mov pc, r0 111 | -------------------------------------------------------------------------------- /source/ffs-plugin/fs_dump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _FS_DUMP_H_ 22 | #define _FS_DUMP_H_ 23 | 24 | //#define DUMP 25 | 26 | #include "ipc.h" 27 | #include "types.h" 28 | 29 | void FS_os_message_queue_ack(struct ipcmessage *message, s32 result); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /source/ffs-plugin/fs_tools.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _FS_TOOLS_H_ 22 | #define _FS_TOOLS_H_ 23 | 24 | #include "types.h" 25 | 26 | 27 | /* Prototypes */ 28 | u16 FS_GetUID(void); 29 | u16 FS_GetGID(void); 30 | u32 FS_CheckRealPath(const char *path); 31 | u32 FS_MatchPath(char *path, const char *pattern, s32 strict); 32 | void FS_GenerateAbsolutePath(const char *realpath, char *emupath); 33 | s32 FS_GenerateRelativePath(const char *realpath, char *emupath); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/ffs-plugin/ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _IOCTL_H_ 22 | #define _IOCTL_H_ 23 | 24 | /* IOCTL commands */ 25 | #define IOCTL_ISFS_FORMAT 1 26 | #define IOCTL_ISFS_GETSTATS 2 27 | #define IOCTL_ISFS_CREATEDIR 3 28 | #define IOCTL_ISFS_READDIR 4 29 | #define IOCTL_ISFS_SETATTR 5 30 | #define IOCTL_ISFS_GETATTR 6 31 | #define IOCTL_ISFS_DELETE 7 32 | #define IOCTL_ISFS_RENAME 8 33 | #define IOCTL_ISFS_CREATEFILE 9 34 | #define IOCTL_ISFS_SETFILEVERCTRL 10 35 | #define IOCTL_ISFS_GETFILESTATS 11 36 | #define IOCTL_ISFS_GETUSAGE 12 37 | #define IOCTL_ISFS_SHUTDOWN 13 38 | 39 | /* Custom commands */ 40 | #define IOCTL_ISFS_SETMODE 100 41 | #define IOCTL_ISFS_GETMODE 101 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /source/ffs-plugin/iop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _IOP_H_ 22 | #define _IOP_H_ 23 | 24 | #include "types.h" 25 | 26 | 27 | /* Prototypes */ 28 | void IOP_Init(void); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /source/ffs-plugin/iop_calls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _IOP_CALLS_H_ 22 | #define _IOP_CALLS_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Prototypes */ 27 | s32 syscall_open(char *path, s32 mode); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /source/ffs-plugin/iop_calls.s: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | 22 | .text 23 | 24 | /* 25 | * Syscall open hook 26 | * 27 | * NOTE: 28 | * The original vector works in thumb mode, 29 | * but it has been patched with bx pc and ldr pc, =addr 30 | * to jump without modifying any register. 31 | * So we need to switch to thumb mode again. 32 | */ 33 | .align 4 34 | .code 32 35 | 36 | .arm 37 | .global syscall_open 38 | syscall_open: 39 | stmfd sp!, {r4-r7, lr} 40 | stmfd sp!, {r1-r3} 41 | nop 42 | ldr r4, =(_syscall_open_thumb + 1) 43 | bx r4 44 | 45 | .align 4 46 | .code 16 47 | 48 | .thumb 49 | _syscall_open_thumb: 50 | bl __IOP_SyscallOpen 51 | pop {r1-r3} 52 | mov r7, r11 53 | mov r6, r10 54 | mov r5, r9 55 | mov r4, r8 56 | push {r4-r7} 57 | ldr r4, =addrSysOpen 58 | ldr r4, [r4] 59 | nop 60 | mov pc, r4 61 | 62 | -------------------------------------------------------------------------------- /source/ffs-plugin/isfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _ISFS_H_ 22 | #define _ISFS_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Constants */ 27 | #define ISFS_MAXPATH 64 28 | 29 | #define ISFS_OPEN_READ 0x01 30 | #define ISFS_OPEN_WRITE 0x02 31 | #define ISFS_OPEN_RW (ISFS_OPEN_READ | ISFS_OPEN_WRITE) 32 | 33 | 34 | /* ISFS structures */ 35 | typedef struct { 36 | char filepathOld[ISFS_MAXPATH]; 37 | char filepathNew[ISFS_MAXPATH]; 38 | } fsrename; 39 | 40 | typedef struct { 41 | u32 owner_id; 42 | u16 group_id; 43 | char filepath[ISFS_MAXPATH]; 44 | u8 ownerperm; 45 | u8 groupperm; 46 | u8 otherperm; 47 | u8 attributes; 48 | u8 pad0[2]; 49 | } fsattr; 50 | 51 | typedef struct { 52 | ioctlv vector[4]; 53 | u32 no_entries; 54 | } fsreaddir; 55 | 56 | typedef struct { 57 | ioctlv vector[4]; 58 | u32 usage1; 59 | u8 pad0[28]; 60 | u32 usage2; 61 | } fsusage; 62 | 63 | typedef struct { 64 | u32 block_size; 65 | u32 free_blocks; 66 | u32 used_blocks; 67 | u32 unk3; 68 | u32 unk4; 69 | u32 free_inodes; 70 | u32 unk5; 71 | } fsstats; 72 | 73 | typedef struct { 74 | /* Length and position */ 75 | u32 length; 76 | u32 pos; 77 | } fsfilestats; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /source/ffs-plugin/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x13843000, LENGTH = 0x3000 9 | ram(rw) : ORIGIN = 0x13846000, LENGTH = 0x3000 10 | } 11 | 12 | __exe_start_phys__ = 0x13843000; 13 | __ram_start_phys__ = 0x13846000; 14 | 15 | 16 | SECTIONS { 17 | .ios_info_table : { 18 | KEEP (*(.ios_info_table)) 19 | } > table 20 | 21 | .init : AT (__exe_start_phys__) { 22 | *(.init) 23 | . = ALIGN(4); 24 | } > exe 25 | 26 | .text : { 27 | *(.text*) 28 | *(.gnu.warning) 29 | *(.gnu.linkonce.t.*) 30 | *(.init) 31 | *(.glue_7) 32 | *(.glue_7t) 33 | . = ALIGN(4); 34 | } > exe 35 | 36 | .data : AT (__ram_start_phys__) { 37 | *(.data*) 38 | *(.data.*) 39 | *(.gnu.linkonce.d.*) 40 | . = ALIGN(4); 41 | } > ram 42 | 43 | .rodata : { 44 | *(.rodata) 45 | *all.rodata*(*) 46 | *(.roda) 47 | *(.rodata.*) 48 | *(.gnu.linkonce.r.*) 49 | . = ALIGN(4); 50 | } > ram 51 | 52 | .bss : { 53 | *(.dynsbss) 54 | *(.gnu.linkonce.sb.*) 55 | *(.bss*) 56 | *(COMMON) 57 | KEEP(*(.ios_bss)) 58 | . = ALIGN(4); 59 | } > ram 60 | } 61 | -------------------------------------------------------------------------------- /source/ffs-plugin/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "iop.h" 22 | #include "ios.h" 23 | #include "patches.h" 24 | #include "syscalls.h" 25 | #include "types.h" 26 | 27 | 28 | char *moduleName = "FFS"; 29 | 30 | int main(void) 31 | { 32 | /* System patchers */ 33 | static patcher patchers[] = { 34 | {Patch_FfsModule, 0}, 35 | {Patch_IopModule, 0} 36 | }; 37 | 38 | /* Print info */ 39 | svc_write("$IOSVersion: FFSP: " __DATE__ " " __TIME__ " 64M$\n"); 40 | 41 | /* Initialize IOP */ 42 | IOP_Init(); 43 | 44 | /* Initialize plugin */ 45 | IOS_InitSystem(patchers, sizeof(patchers)); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /source/ffs-plugin/patches.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2008-2010 Waninkoko, WiiGator. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _PATCHES_H_ 22 | #define _PATCHES_H_ 23 | 24 | #include "types.h" 25 | 26 | /* Prototypes */ 27 | s32 Patch_FfsModule(void); 28 | s32 Patch_IopModule(void); 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /source/ffs-plugin/plugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FFS plugin for Custom IOS. 3 | * 4 | * Copyright (C) 2009-2010 Waninkoko. 5 | * Copyright (C) 2011 davebaol. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #ifndef _PLUGIN_H_ 22 | #define _PLUGIN_H_ 23 | 24 | #include "fat.h" 25 | #include "types.h" 26 | 27 | /* Mode codes */ 28 | #define MODE_SDHC 0x01 29 | #define MODE_USB 0x02 30 | #define MODE_REV17 0x80 31 | #define MODE_FULL 0x100 32 | 33 | 34 | /* Config structure */ 35 | struct fsConfig { 36 | /* Mode */ 37 | u32 mode; 38 | 39 | /* Nand path */ 40 | char path[FAT_MAXPATH]; 41 | 42 | /* Nand path length */ 43 | u32 pathlen; 44 | }; 45 | 46 | /* Extern */ 47 | extern struct fsConfig config; 48 | extern u32 forceRealPath; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /source/ffs-plugin/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS module for Wii. 3 | Copyright (C) 2008 neimod. 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | .section ".init" 21 | .arm 22 | 23 | .EQU ios_thread_arg, 4 24 | .EQU ios_thread_priority, 0x48 25 | .EQU ios_thread_stacksize, 0x1000 26 | 27 | 28 | .global _start 29 | _start: 30 | mov r0, #0 @ int argc 31 | mov r1, #0 @ char *argv[] 32 | ldr r3, =main 33 | bx r3 34 | 35 | 36 | 37 | /* 38 | * IOS bss 39 | */ 40 | .section ".ios_bss", "a", %nobits 41 | 42 | .space ios_thread_stacksize 43 | .global ios_thread_stack /* stack decrements from high address.. */ 44 | ios_thread_stack: 45 | 46 | 47 | /* 48 | * IOS info table 49 | */ 50 | .section ".ios_info_table", "ax", %progbits 51 | 52 | .global ios_info_table 53 | ios_info_table: 54 | .long 0x0 55 | .long 0x28 @ numentries * 0x28 56 | .long 0x6 57 | 58 | .long 0xB 59 | .long ios_thread_arg @ passed to thread entry func, maybe module id 60 | 61 | .long 0x9 62 | .long _start 63 | 64 | .long 0x7D 65 | .long ios_thread_priority 66 | 67 | .long 0x7E 68 | .long ios_thread_stacksize 69 | 70 | .long 0x7F 71 | .long ios_thread_stack 72 | -------------------------------------------------------------------------------- /source/mload-module/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Strip address 13 | SADDR = 0x13700000 14 | 15 | # Committer date for reproducible builds 16 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 17 | ifdef SOURCE_DATE_EPOCH 18 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 20 | else 21 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 22 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 23 | endif 24 | 25 | # Flags 26 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 27 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 28 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 29 | 30 | # Libraries 31 | LIBS = ../cios-lib/cios-lib.a 32 | 33 | # Target 34 | TARGET = mload-module 35 | 36 | # Objects 37 | OBJS = debug.o \ 38 | detect.o \ 39 | elf.o \ 40 | gecko.o \ 41 | gpio.o \ 42 | main.o \ 43 | patches.o \ 44 | start.o \ 45 | swi.o \ 46 | swi_asm.o \ 47 | tid.o 48 | 49 | 50 | $(TARGET).elf: $(OBJS) $(LIBS) 51 | @echo -e " LD\t$@" 52 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 53 | @$(STRIP) $@.orig $@ strip $(SADDR) 54 | 55 | %.o: %.s 56 | @echo -e " CC\t$@" 57 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 58 | 59 | %.o: %.c 60 | @echo -e " CC\t$@" 61 | @$(CC) $(CFLAGS) -c -o $@ $< 62 | 63 | clean: 64 | @echo -e "Cleaning..." 65 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 66 | -------------------------------------------------------------------------------- /source/mload-module/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _DEBUG_H_ 25 | #define _DEBUG_H_ 26 | 27 | #include "types.h" 28 | 29 | /* Constants */ 30 | #define DEBUG_NONE 0 31 | #define DEBUG_BUFFER 1 32 | #define DEBUG_GECKO 2 33 | 34 | #define NO_DEBUG_BUFFER 35 | 36 | /* Prototypes */ 37 | s32 Debug_SetMode(u8 mode); 38 | #ifndef NO_DEBUG_BUFFER 39 | s32 Debug_GetBuffer(char *outbuf, u32 len); 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /source/mload-module/detect.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _DETECT_H_ 25 | #define _DETECT_H_ 26 | 27 | #include "types.h" 28 | 29 | /* Prototypes */ 30 | s32 Detect_DipModule(void); 31 | s32 Detect_EsModule(void); 32 | s32 Detect_FfsModule(void); 33 | s32 Detect_IopModule(void); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/mload-module/elf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef _ELF_H_ 24 | #define _ELF_H_ 25 | 26 | #include "types.h" 27 | 28 | /* Prototypes */ 29 | s32 Elf_Load(void *data); 30 | s32 Elf_Run(void); 31 | s32 Elf_RunThread(void *start, void *arg, void *stack, u32 stacksize, u32 priority); 32 | s32 Elf_StopThread(s32 tid); 33 | s32 Elf_ContinueThread(s32 tid); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/mload-module/gecko.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 Nuke. 5 | Copyright (C) 2009 marcan. 6 | Copyright (C) 2009 dhewg. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef __GECKO_H__ 25 | #define __GECKO_H__ 26 | 27 | #include "types.h" 28 | 29 | void Gecko_Init(void); 30 | u8 Gecko_EnableConsole(const u8 enable); 31 | u32 Gecko_SendString(const char *string); 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /source/mload-module/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include "gpio.h" 25 | #include "hollywood.h" 26 | #include "types.h" 27 | #include "utils.h" 28 | 29 | /* Constants */ 30 | #define GPIO_OUT HW_GPIO1BOUT 31 | #define GPIO_IN HW_GPIO1IN 32 | 33 | 34 | u8 GPIO_Read(u8 bit) 35 | { 36 | /* Return bit value */ 37 | return Get32(GPIO_IN, bit); 38 | } 39 | 40 | void GPIO_Write(u8 bit, u8 set) 41 | { 42 | /* Set bit value */ 43 | if (set) 44 | Set32(GPIO_OUT, bit); 45 | else 46 | Clear32(GPIO_OUT, bit); 47 | } 48 | -------------------------------------------------------------------------------- /source/mload-module/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _GPIO_H_ 25 | #define _GPIO_H_ 26 | 27 | #include "types.h" 28 | 29 | 30 | /* Prototypes */ 31 | u8 GPIO_Read(u8 bit); 32 | void GPIO_Write(u8 bit, u8 set); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/mload-module/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x136d0000, LENGTH = 0x2000 9 | ram(rw) : ORIGIN = 0x136d2000, LENGTH = 0x9000 10 | mem(rw) : ORIGIN = 0x13700000, LENGTH = 0x80000 11 | } 12 | 13 | __exe_start_phys__ = 0x136d0000; 14 | __ram_start_phys__ = 0x136d2000; 15 | __mem_start_phys__ = 0x13700000; 16 | 17 | 18 | SECTIONS { 19 | .exe_mem : AT (__mem_start_phys__) { 20 | *(.exe_mem) 21 | } > mem 22 | 23 | .ios_info_table : { 24 | KEEP (*(.ios_info_table)) 25 | } > table 26 | 27 | .init : AT (__exe_start_phys__) { 28 | *(.init) 29 | . = ALIGN(4); 30 | } > exe 31 | 32 | .text : { 33 | *(.text*) 34 | *(.gnu.warning) 35 | *(.gnu.linkonce.t.*) 36 | *(.init) 37 | *(.glue_7) 38 | *(.glue_7t) 39 | . = ALIGN(4); 40 | } > exe 41 | 42 | .data : AT (__ram_start_phys__) { 43 | *(.data*) 44 | *(.data.*) 45 | *(.gnu.linkonce.d.*) 46 | . = ALIGN(4); 47 | } > ram 48 | 49 | .rodata : { 50 | *(.rodata) 51 | *all.rodata*(*) 52 | *(.roda) 53 | *(.rodata.*) 54 | *(.gnu.linkonce.r.*) 55 | . = ALIGN(4); 56 | } > ram 57 | 58 | .bss : { 59 | *(.dynsbss) 60 | *(.gnu.linkonce.sb.*) 61 | *(.bss*) 62 | *(COMMON) 63 | KEEP(*(.ios_bss)) 64 | . = ALIGN(4); 65 | } > ram 66 | } 67 | -------------------------------------------------------------------------------- /source/mload-module/module.h: -------------------------------------------------------------------------------- 1 | #ifndef _MODULE_H_ 2 | #define _MODULE_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Module info */ 7 | #define MLOAD_VER 1 8 | #define MLOAD_SUBVER 0 9 | 10 | /* Device name */ 11 | #define DEVICE_NAME "/dev/mload" 12 | 13 | /* IOCTL commands */ 14 | #define MLOAD_GET_IOS_INFO 0x4D4C4401 15 | #define MLOAD_GET_MLOAD_VERSION 0x4D4C4402 16 | #define MLOAD_LOAD_ELF 0x4D4C4480 17 | #define MLOAD_RUN_ELF 0x4D4C4481 18 | #define MLOAD_RUN_THREAD 0x4D4C4482 19 | #define MLOAD_STOP_THREAD 0x4D4C4484 20 | #define MLOAD_CONTINUE_THREAD 0x4D4C4485 21 | #define MLOAD_GET_LOAD_BASE 0x4D4C4490 22 | #define MLOAD_MEMSET 0x4D4C4491 23 | #define MLOAD_SET_LOG_MODE 0x4D4C44D0 24 | #define MLOAD_GET_LOG_BUFFER 0x4D4C44D1 25 | #define MLOAD_SET_STEALTH_MODE 0x4D4C44E0 26 | 27 | /* Module space */ 28 | extern u8 exe_mem[]; 29 | extern u32 exe_mem_size; 30 | 31 | extern u32 stealth_mode; 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /source/mload-module/patches.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _PATCHES_H_ 25 | #define _PATCHES_H_ 26 | 27 | #include "types.h" 28 | 29 | /* Prototypes */ 30 | s32 Patch_DipModule(void); 31 | s32 Patch_EsModule (void); 32 | s32 Patch_FfsModule(void); 33 | s32 Patch_IopModule(void); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /source/mload-module/swi.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2011 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _SWI_H_ 25 | #define _SWI_H_ 26 | 27 | #include "types.h" 28 | 29 | /* SWI function */ 30 | typedef s32 (*SwiFunc)(u32 arg0, u32 arg1, u32 arg2, u32 arg3); 31 | 32 | 33 | /* Prototypes */ 34 | s32 Swi_MLoad(u32 arg0, u32 arg1, u32 arg2, u32 arg3); 35 | 36 | /* Externs */ 37 | extern SwiFunc SwiTable[]; 38 | extern void SwiVector(void); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /source/mload-module/swi_asm.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | .text 24 | 25 | .code 16 26 | .global SwiVector 27 | SwiVector: 28 | bx pc 29 | 30 | .code 32 31 | ldr sp, =swi_stack 32 | nop 33 | stmfd sp!, {r1-r12,lr} 34 | nop 35 | mrs r12, cpsr 36 | stmfd sp!, {r12} 37 | nop 38 | 39 | ldr r12, =SwiAddr 40 | str lr, [r12] 41 | nop 42 | 43 | bl _Swi_Handler 44 | 45 | ldmfd sp!, {r12} 46 | nop 47 | msr cpsr_c, r12 48 | ldmfd sp!, {r1-r12,lr} 49 | nop 50 | 51 | movs pc, lr 52 | 53 | _Swi_Handler: 54 | ldr r12, =Swi_Handler 55 | bx r12 56 | -------------------------------------------------------------------------------- /source/mload-module/tid.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2010 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #include "module.h" 25 | #include "types.h" 26 | 27 | /* Constants */ 28 | #define MAX_NUM_TIDS 8 29 | 30 | typedef struct { 31 | s32 tid; 32 | u32 rights; 33 | } TID; 34 | 35 | /* Static variables */ 36 | static u32 num_tids = 0; 37 | static TID tids[MAX_NUM_TIDS]; 38 | 39 | s32 TID_AddRights(s32 tid, u32 rights) 40 | { 41 | s32 cnt; 42 | 43 | if (tid < 0) { 44 | /* Error: invalid tid */ 45 | return -1; 46 | } 47 | 48 | for (cnt = 0; cnt < num_tids; cnt++) { 49 | if (tids[cnt].tid == tid) { 50 | /* Tid already registered, add rights */ 51 | tids[cnt].rights |= rights; 52 | 53 | /* Success: already registered */ 54 | return 0; 55 | } 56 | } 57 | 58 | /* Register new tid */ 59 | if (num_tids < MAX_NUM_TIDS) { 60 | /* Set rights */ 61 | tids[num_tids].tid = tid; 62 | tids[num_tids].rights = rights; 63 | 64 | /* Increment counter */ 65 | num_tids++; 66 | 67 | /* Success: just registered */ 68 | return 0; 69 | } 70 | 71 | /* Error: Too many tids registered */ 72 | return -2; 73 | } 74 | 75 | s32 TID_CheckRights(s32 tid, u32 rights) 76 | { 77 | s32 cnt; 78 | 79 | /* Always authorized access when stealth mode is off */ 80 | if (!stealth_mode) 81 | return 1; 82 | 83 | /* Check thread rights */ 84 | for (cnt = 0; cnt < num_tids; cnt++) { 85 | if (tids[cnt].tid == tid) { 86 | /* Tid found, check rights */ 87 | return (tids[cnt].rights & rights) != 0; 88 | } 89 | } 90 | 91 | /* Unknown tid */ 92 | return 0; 93 | } 94 | 95 | -------------------------------------------------------------------------------- /source/mload-module/tid.h: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (MLOAD) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2010 Hermes. 6 | Copyright (C) 2010 Waninkoko. 7 | Copyright (C) 2010 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef _TID_H_ 25 | #define _TID_H_ 26 | 27 | #include "types.h" 28 | 29 | 30 | /* Prototypes */ 31 | s32 TID_AddRights(s32 tid, u32 rights); 32 | s32 TID_CheckRights(s32 tid, u32 rights); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /source/mload-module/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | #include "types.h" 5 | 6 | 7 | static inline u32 Read32(u32 addr) 8 | { 9 | u32 ret; 10 | 11 | __asm__ volatile("ldr\t%0, [%1]" : "=l"(ret) : "l"(addr)); 12 | 13 | return ret; 14 | } 15 | 16 | static inline void Write32(u32 addr, u32 val) 17 | { 18 | __asm__ volatile("str\t%0, [%1]" : : "l"(val), "l"(addr)); 19 | } 20 | 21 | static inline u32 Get32(u32 addr, u32 bit) 22 | { 23 | u32 val = (1 << bit); 24 | u32 ret; 25 | 26 | __asm__ volatile( 27 | "ldr\t%0, [%1]\n" 28 | "and\t%0, %2\n" 29 | "lsr\t%0, %3\n" 30 | : "=&l"(ret) 31 | : "l"(addr), "l"(val), "l"(bit) 32 | ); 33 | 34 | return ret; 35 | } 36 | 37 | static inline u32 Set32(u32 addr, u32 bit) 38 | { 39 | u32 val = (1 << bit); 40 | u32 ret; 41 | 42 | __asm__ volatile( 43 | "ldr\t%0, [%1]\n" 44 | "orr\t%0, %2\n" 45 | "str\t%0, [%1]\n" 46 | : "=&l"(ret) 47 | : "l"(addr), "l"(val) 48 | ); 49 | 50 | return ret; 51 | } 52 | 53 | static inline u32 Clear32(u32 addr, u32 bit) 54 | { 55 | u32 val = (1 << bit); 56 | u32 ret; 57 | 58 | __asm__ volatile( 59 | "ldr\t%0, [%1]\n" 60 | "bic\t%0, %2\n" 61 | "str\t%0, [%1]\n" 62 | : "=&l"(ret) 63 | : "l"(addr), "l"(val) 64 | ); 65 | 66 | return ret; 67 | } 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /source/usb-module/Makefile: -------------------------------------------------------------------------------- 1 | # devkitARM path 2 | DEVKITARM ?= /opt/devkitARM 3 | 4 | # Prefix 5 | PREFIX = $(DEVKITARM)/bin/arm-eabi- 6 | 7 | # Executables 8 | CC = $(PREFIX)gcc 9 | LD = $(PREFIX)gcc 10 | STRIP = ../stripios 11 | 12 | # Committer date for reproducible builds 13 | SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct) 14 | ifdef SOURCE_DATE_EPOCH 15 | BUILD_DATE ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%b %e %Y'" 2>/dev/null || LC_ALL=C date -u "+'%b %e %Y'") 16 | BUILD_TIME ?= $(shell LC_ALL=C date -u -d "@$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u -r "$(SOURCE_DATE_EPOCH)" "+'%H:%M:%S'" 2>/dev/null || LC_ALL=C date -u "+'%H:%M:%S'") 17 | else 18 | BUILD_DATE ?= $(shell date "+'%b %e %Y'") 19 | BUILD_TIME ?= $(shell date "+'%H:%M:%S'") 20 | endif 21 | 22 | # Flags 23 | ARCH = -mcpu=arm926ej-s -mthumb -mthumb-interwork -mbig-endian 24 | CFLAGS = $(ARCH) -I. -I../cios-lib -ffreestanding -fno-builtin -ffunction-sections -fomit-frame-pointer -Os -Wall -Wstrict-prototypes -ffunction-sections -Wno-builtin-macro-redefined -D__TIME__=\"$(BUILD_TIME)\" -D__DATE__=\"$(BUILD_DATE)\" 25 | LDFLAGS = $(ARCH) -nostartfiles -nostdlib -Wl,-T,link.ld,-Map,$(TARGET).map -Wl,--gc-sections -Wl,-static 26 | 27 | # Libraries 28 | LIBS = ../cios-lib/cios-lib.a 29 | 30 | # Target 31 | TARGET = usb-module 32 | 33 | # Objects 34 | OBJS = main.o \ 35 | start.o \ 36 | usb2.o \ 37 | usbglue.o \ 38 | usbstorage.o \ 39 | wbfs.o 40 | 41 | 42 | $(TARGET).elf: $(OBJS) $(LIBS) 43 | @echo -e " LD\t$@" 44 | @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -lgcc -o $@.orig 45 | @$(STRIP) $@.orig $@ 46 | 47 | %.o: %.s 48 | @echo -e " CC\t$@" 49 | @$(CC) $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c -x assembler-with-cpp -o $@ $< 50 | 51 | %.o: %.c 52 | @echo -e " CC\t$@" 53 | @$(CC) $(CFLAGS) -c -o $@ $< 54 | 55 | clean: 56 | @echo -e "Cleaning..." 57 | @rm -f $(OBJS) $(TARGET).elf $(TARGET).elf.orig $(TARGET).map 58 | -------------------------------------------------------------------------------- /source/usb-module/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPAT_H_ 2 | #define _COMPAT_H_ 3 | 4 | #define iosAlloc(hid, len) Mem_Alloc(len) 5 | #define iosFree(ptr) Mem_Free(ptr) 6 | #define IOS_Ioctl os_ioctl 7 | #define IOS_IoctlAsync os_ioctl_async 8 | #define IOS_Ioctlv os_ioctlv 9 | #define IOS_IoctlvAsync os_ioctlv_async 10 | #define IOS_Open os_open 11 | #define IOS_Close os_close 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /source/usb-module/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-bigarm") 2 | OUTPUT_ARCH(arm) 3 | ENTRY(_start) 4 | 5 | /* Sections area */ 6 | MEMORY { 7 | table : ORIGIN = 0x0, LENGTH = 0x4000 8 | exe(rwx) : ORIGIN = 0x13780000, LENGTH = 0x3000 9 | ram(rw) : ORIGIN = 0x13783000, LENGTH = 0xB000 10 | } 11 | 12 | __exe_start_phys__ = 0x13780000; 13 | __ram_start_phys__ = 0x13783000; 14 | 15 | 16 | SECTIONS { 17 | .ios_info_table : { 18 | KEEP (*(.ios_info_table)) 19 | } > table 20 | 21 | .init : AT (__exe_start_phys__) { 22 | *(.init) 23 | . = ALIGN(4); 24 | } > exe 25 | 26 | .text : { 27 | *(.text*) 28 | *(.gnu.warning) 29 | *(.gnu.linkonce.t.*) 30 | *(.init) 31 | *(.glue_7) 32 | *(.glue_7t) 33 | . = ALIGN(4); 34 | } > exe 35 | 36 | .data : AT (__ram_start_phys__) { 37 | *(.data*) 38 | *(.data.*) 39 | *(.gnu.linkonce.d.*) 40 | . = ALIGN(4); 41 | } > ram 42 | 43 | .rodata : { 44 | *(.rodata) 45 | *all.rodata*(*) 46 | *(.roda) 47 | *(.rodata.*) 48 | *(.gnu.linkonce.r.*) 49 | . = ALIGN(4); 50 | } > ram 51 | 52 | .bss : { 53 | *(.dynsbss) 54 | *(.gnu.linkonce.sb.*) 55 | *(.bss*) 56 | *(COMMON) 57 | KEEP(*(.ios_bss)) 58 | . = ALIGN(4); 59 | } > ram 60 | } 61 | -------------------------------------------------------------------------------- /source/usb-module/module.h: -------------------------------------------------------------------------------- 1 | #ifndef _MODULE_H_ 2 | #define _MODULE_H_ 3 | 4 | #include "ipc.h" 5 | 6 | /* IOCTL commands */ 7 | #define IOCTL_USB_INIT 0x01 8 | #define IOCTL_USB_READ 0x02 9 | #define IOCTL_USB_WRITE 0x03 10 | #define IOCTL_USB_ISINSERTED 0x04 11 | #define IOCTL_USB_UNMOUNT 0x05 12 | 13 | /* UMS IOCTL commands */ 14 | #define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) 15 | #define IOCTL_UMS_INIT (UMS_BASE + 0x1) 16 | #define IOCTL_UMS_GET_CAPACITY (UMS_BASE + 0x2) 17 | #define IOCTL_UMS_READ_SECTORS (UMS_BASE + 0x3) 18 | #define IOCTL_UMS_WRITE_SECTORS (UMS_BASE + 0x4) 19 | #define IOCTL_UMS_UMOUNT (UMS_BASE + 0x10) 20 | 21 | /* WBFS IOCTL commands */ 22 | #define WBFS_BASE (('W'<<24)|('F'<<16)|('S'<<8)) 23 | #define IOCTL_WBFS_OPEN_DISC (WBFS_BASE + 0x1) 24 | #define IOCTL_WBFS_READ_DISC (WBFS_BASE + 0x2) 25 | 26 | /* Message constants */ 27 | #define MESSAGE_DEVCHANGE (u32)&usbCb[0] 28 | #define MESSAGE_ATTACH (u32)&usbCb[1] 29 | #define MESSAGE_MOUNT 0x10000001 30 | 31 | /* Device name */ 32 | #define DEVICE_NAME "/dev/usb2" 33 | 34 | /* Externs */ 35 | extern s32 queuehandle; 36 | extern areply usbCb[]; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /source/usb-module/start.s: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (USB) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | Copyright (C) 2009 davebaol. 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License 20 | along with this program; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | .section ".init" 25 | .arm 26 | 27 | .EQU ios_thread_arg, 4 28 | .EQU ios_thread_priority, 0x48 29 | .EQU ios_thread_stacksize, 0x2000 30 | 31 | 32 | .global _start 33 | _start: 34 | mov r0, #0 @ int argc 35 | mov r1, #0 @ char *argv[] 36 | ldr r3, =main 37 | bx r3 38 | 39 | 40 | 41 | /* 42 | * IOS bss 43 | */ 44 | .section ".ios_bss", "a", %nobits 45 | 46 | .space ios_thread_stacksize 47 | .global ios_thread_stack /* stack decrements from high address.. */ 48 | ios_thread_stack: 49 | 50 | 51 | /* 52 | * IOS info table 53 | */ 54 | .section ".ios_info_table", "ax", %progbits 55 | 56 | .global ios_info_table 57 | ios_info_table: 58 | .long 0x0 59 | .long 0x28 @ numentries * 0x28 60 | .long 0x6 61 | 62 | .long 0xB 63 | .long ios_thread_arg @ passed to thread entry func, maybe module id 64 | 65 | .long 0x9 66 | .long _start 67 | 68 | .long 0x7D 69 | .long ios_thread_priority 70 | 71 | .long 0x7E 72 | .long ios_thread_stacksize 73 | 74 | .long 0x7F 75 | .long ios_thread_stack 76 | -------------------------------------------------------------------------------- /source/usb-module/usbglue.h: -------------------------------------------------------------------------------- 1 | #ifndef _USBGLUE_H_ 2 | #define _USBGLUE_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Prototypes */ 7 | bool usbstorage_Startup(void); 8 | bool usbstorage_IsInserted(void); 9 | bool usbstorage_ReadSectors (u32 sector, u32 numSectors, void *buffer); 10 | bool usbstorage_WriteSectors(u32 sector, u32 numSectors, const void *buffer); 11 | bool usbstorage_ReadCapacity(u32 *sectorSz, u32 *numSectors); 12 | bool usbstorage_Shutdown(void); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /source/usb-module/usbstorage.h: -------------------------------------------------------------------------------- 1 | #ifndef _USBSTORAGE_H_ 2 | #define _USBSTORAGE_H_ 3 | 4 | #include "types.h" 5 | 6 | /* Constants */ 7 | #define USBSTORAGE_OK 0 8 | #define USBSTORAGE_ENOINTERFACE -10000 9 | #define USBSTORAGE_ESENSE -10001 10 | #define USBSTORAGE_ESHORTWRITE -10002 11 | #define USBSTORAGE_ESHORTREAD -10003 12 | #define USBSTORAGE_ESIGNATURE -10004 13 | #define USBSTORAGE_ETAG -10005 14 | #define USBSTORAGE_ESTATUS -10006 15 | #define USBSTORAGE_EDATARESIDUE -10007 16 | #define USBSTORAGE_ETIMEDOUT -10008 17 | #define USBSTORAGE_EINIT -10009 18 | #define USBSTORAGE_PROCESSING -10010 19 | 20 | #define USB_CLASS_MASS_STORAGE 0x08 21 | 22 | 23 | /* USB storage structure */ 24 | typedef struct 25 | { 26 | u8 configuration; 27 | u32 interface; 28 | u32 altInterface; 29 | 30 | u8 ep_in; 31 | u8 ep_out; 32 | 33 | u8 max_lun; 34 | u32 *sector_size; 35 | 36 | s32 usb_fd; 37 | 38 | s32 retval; 39 | 40 | u32 tag; 41 | u8 suspended; 42 | 43 | u8 *buffer; 44 | } usbstorage_handle; 45 | 46 | /* Prototypes */ 47 | s32 USBStorage_Initialize(void); 48 | s32 USBStorage_Open(usbstorage_handle *dev, s32 device_id, u16 vid, u16 pid); 49 | s32 USBStorage_Close(usbstorage_handle *dev); 50 | s32 USBStorage_Reset(usbstorage_handle *dev); 51 | s32 USBStorage_GetMaxLUN(usbstorage_handle *dev); 52 | s32 USBStorage_MountLUN(usbstorage_handle *dev, u8 lun); 53 | s32 USBStorage_Suspend(usbstorage_handle *dev); 54 | s32 USBStorage_ReadCapacity(usbstorage_handle *dev, u8 lun, u32 *sector_size, u32 *n_sectors); 55 | s32 USBStorage_Read(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, u8 *buffer); 56 | s32 USBStorage_Write(usbstorage_handle *dev, u8 lun, u32 sector, u16 n_sectors, const u8 *buffer); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /source/usb-module/wbfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | Custom IOS Module (USB) 3 | 4 | Copyright (C) 2008 neimod. 5 | Copyright (C) 2009 WiiGator. 6 | Copyright (C) 2009 Waninkoko. 7 | 8 | This program is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation; either version 2 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program; if not, write to the Free Software 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | #include "syscalls.h" 27 | #include "usbglue.h" 28 | #include "libwbfs/libwbfs.h" 29 | 30 | /* Variables */ 31 | static wbfs_t *hdd = NULL; 32 | static wbfs_disc_t *disc = NULL; 33 | 34 | static u32 sectorSz = 0; 35 | static u32 nbSector = 0; 36 | 37 | 38 | static int __WBFS_ReadSector(void *cbdata, u32 lba, u32 count, void *buffer) 39 | { 40 | s32 ret; 41 | 42 | /* Read data */ 43 | ret = usbstorage_ReadSectors(lba, count, buffer); 44 | if (!ret) 45 | return 1; 46 | 47 | /* Invalidate range */ 48 | os_sync_before_read(buffer, sectorSz * count); 49 | 50 | return 0; 51 | } 52 | 53 | 54 | s32 WBFS_OpenDisc(u8 *discid) 55 | { 56 | s32 ret; 57 | 58 | /* Initialize USB */ 59 | ret = usbstorage_Startup(); 60 | if (!ret) 61 | return 1; 62 | 63 | /* Read capacity */ 64 | ret = usbstorage_ReadCapacity(§orSz, &nbSector); 65 | if (!ret) 66 | return 2; 67 | 68 | /* Close disc */ 69 | if (disc) 70 | wbfs_close_disc(disc); 71 | 72 | /* Close device */ 73 | if (hdd) 74 | wbfs_close(hdd); 75 | 76 | /* Open device */ 77 | hdd = wbfs_open_hd(__WBFS_ReadSector, NULL, NULL, sectorSz, 0, 0); 78 | if (!hdd) 79 | return 3; 80 | 81 | /* Open disc */ 82 | disc = wbfs_open_disc(hdd, discid); 83 | if (!disc) 84 | return 4; 85 | 86 | return 0; 87 | } 88 | 89 | s32 WBFS_Read(void *buffer, u32 len, u32 offset) 90 | { 91 | /* No disc opened */ 92 | if (!disc) 93 | return 1; 94 | 95 | /* Disc read */ 96 | return wbfs_disc_read(disc, offset, buffer, len); 97 | } 98 | -------------------------------------------------------------------------------- /source/usb-module/wbfs.h: -------------------------------------------------------------------------------- 1 | #ifndef _WBFS_H_ 2 | #define _WBFS_H_ 3 | 4 | /* Prototypes */ 5 | s32 WBFS_OpenDisc(u8 *discid); 6 | s32 WBFS_Read(void *buffer, u32 len, u32 offset); 7 | 8 | #endif 9 | 10 | --------------------------------------------------------------------------------