From 5cc425330d84492b36b51ba11d282a1a9451a79d Mon Sep 17 00:00:00 2001 From: Sven Peter Date: Thu, 10 Apr 2008 16:11:54 +0200 Subject: [PATCH] created branch for tcp loader (should've done this before...) --- .gitignore | 1 + sdelfloader/COPYING | 340 ------ sdelfloader/Makefile | 13 - sdelfloader/README | 21 - sdelfloader/loader/Makefile | 144 --- sdelfloader/loader/source/asm.h | 340 ------ sdelfloader/loader/source/diskio.c | 77 -- sdelfloader/loader/source/diskio.h | 60 - sdelfloader/loader/source/dol.c | 74 -- sdelfloader/loader/source/dol.h | 29 - sdelfloader/loader/source/elf.c | 103 -- sdelfloader/loader/source/elf.h | 9 - sdelfloader/loader/source/elf_abi.h | 594 ---------- sdelfloader/loader/source/integer.h | 25 - sdelfloader/loader/source/main.c | 357 ------ sdelfloader/loader/source/processor.h | 115 -- sdelfloader/loader/source/sdio.c | 239 ---- sdelfloader/loader/source/sdio.h | 4 - sdelfloader/loader/source/tff.c | 1710 ----------------------------- sdelfloader/loader/source/tff.h | 299 ----- sdelfloader/miniloader/Makefile | 143 --- sdelfloader/miniloader/source/asm.h | 340 ------ sdelfloader/miniloader/source/dol.c | 74 -- sdelfloader/miniloader/source/dol.h | 29 - sdelfloader/miniloader/source/main.c | 61 - sdelfloader/miniloader/source/processor.h | 115 -- 26 files changed, 1 insertion(+), 5315 deletions(-) create mode 100644 .gitignore delete mode 100644 sdelfloader/COPYING delete mode 100644 sdelfloader/Makefile delete mode 100644 sdelfloader/README delete mode 100644 sdelfloader/loader/Makefile delete mode 100644 sdelfloader/loader/source/asm.h delete mode 100644 sdelfloader/loader/source/diskio.c delete mode 100644 sdelfloader/loader/source/diskio.h delete mode 100644 sdelfloader/loader/source/dol.c delete mode 100644 sdelfloader/loader/source/dol.h delete mode 100644 sdelfloader/loader/source/elf.c delete mode 100644 sdelfloader/loader/source/elf.h delete mode 100644 sdelfloader/loader/source/elf_abi.h delete mode 100644 sdelfloader/loader/source/integer.h delete mode 100644 sdelfloader/loader/source/main.c delete mode 100644 sdelfloader/loader/source/processor.h delete mode 100644 sdelfloader/loader/source/sdio.c delete mode 100644 sdelfloader/loader/source/sdio.h delete mode 100644 sdelfloader/loader/source/tff.c delete mode 100644 sdelfloader/loader/source/tff.h delete mode 100644 sdelfloader/miniloader/Makefile delete mode 100644 sdelfloader/miniloader/source/asm.h delete mode 100644 sdelfloader/miniloader/source/dol.c delete mode 100644 sdelfloader/miniloader/source/dol.h delete mode 100644 sdelfloader/miniloader/source/main.c delete mode 100644 sdelfloader/miniloader/source/processor.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eaafce7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sdelfloader diff --git a/sdelfloader/COPYING b/sdelfloader/COPYING deleted file mode 100644 index 623b625..0000000 --- a/sdelfloader/COPYING +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/sdelfloader/Makefile b/sdelfloader/Makefile deleted file mode 100644 index 4ae314b..0000000 --- a/sdelfloader/Makefile +++ /dev/null @@ -1,13 +0,0 @@ - -all: - @make -C loader - @bin2s loader/loader.dol > miniloader/source/loader.S - @make -C miniloader - @cp miniloader/miniloader.dol trucha-disc-loader.dol - @cp loader/loader.elf tp-hack-loader.elf - @cp miniloader/miniloader.elf homebrew-channel-loader.elf - -clean: - make -C loader clean - make -C miniloader clean - rm -f miniloader/source/loader.S diff --git a/sdelfloader/README b/sdelfloader/README deleted file mode 100644 index 96a7e3a..0000000 --- a/sdelfloader/README +++ /dev/null @@ -1,21 +0,0 @@ -Just a small Front SD ELF loader with a menu -Written by svpe, #wiidev@efnet, svpe@gmx.net - -Create an elf directory on your SD card and put all your ELF files in there. -You can load the main file with a trucha disc or the twilight hack. - -The miniloader is just a quick hack to make this work with trucha discs because -the apploader i used didn't seem to support a non-standard entry point. - -Just type make to compile (Hint: a precompiled binary is included.) - -There are probably still some bugs so don't blame me if something goes wrong. - -See COPYING for the license (GNU GPL 2; and _only_ version 2) - -Credits: -Internal SD stuff by bushing, marcan and maybe some more people. I just reversed the twilight hack elf loader. -FatFs by elm-chan.org -ELF loading code taken from geckoloader by dhewg, #wiidev at efnet. Written by dhewg, tmbinc and William L. Pitts -People from #wiidev who helped me with a few problems ;) - diff --git a/sdelfloader/loader/Makefile b/sdelfloader/loader/Makefile deleted file mode 100644 index f0608c7..0000000 --- a/sdelfloader/loader/Makefile +++ /dev/null @@ -1,144 +0,0 @@ -#--------------------------------------------------------------------------------- -# Clear the implicit built in rules -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) -endif - -include $(DEVKITPPC)/wii_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- - -CFLAGS = -Os -mrvl -Wall $(MACHDEP) $(INCLUDE) -CXXFLAGS = $(CFLAGS) - -LDFLAGS = $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map,--section-start,.header=0x80a00000 -#LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -logc - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) -else - export LD := $(CXX) -endif - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(LIBOGC_INC) - -#--------------------------------------------------------------------------------- -# build a list of library paths -#--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBOGC_LIB) - -export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol - -#--------------------------------------------------------------------------------- -run: - psoload $(TARGET).dol - -#--------------------------------------------------------------------------------- -reload: - psoload -r $(TARGET).dol - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).dol: $(OUTPUT).elf -$(OUTPUT).elf: $(OFILES) - -#--------------------------------------------------------------------------------- -# This rule links in binary data with the .jpg extension -#--------------------------------------------------------------------------------- -%.jpg.o : %.jpg -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - --include $(DEPENDS) - -$(OUTPUT).dol: $(OUTPUT).elf - @echo "Output ... "$(notdir $@) - @$(OBJCOPY) -O binary $< $@ - -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- diff --git a/sdelfloader/loader/source/asm.h b/sdelfloader/loader/source/asm.h deleted file mode 100644 index 8e335b4..0000000 --- a/sdelfloader/loader/source/asm.h +++ /dev/null @@ -1,340 +0,0 @@ -// this file was taken from libogc, see http://www.devkitpro.org/ - -#ifndef __ASM_H__ -#define __ASM_H__ - -#ifdef _LANGUAGE_ASSEMBLY -/* Condition Register Bit Fields */ - -#define cr0 0 -#define cr1 1 -#define cr2 2 -#define cr3 3 -#define cr4 4 -#define cr5 5 -#define cr6 6 -#define cr7 7 - - -/* General Purpose Registers (GPRs) */ - -#define r0 0 -#define r1 1 -#define sp 1 -#define r2 2 -#define toc 2 -#define r3 3 -#define r4 4 -#define r5 5 -#define r6 6 -#define r7 7 -#define r8 8 -#define r9 9 -#define r10 10 -#define r11 11 -#define r12 12 -#define r13 13 -#define r14 14 -#define r15 15 -#define r16 16 -#define r17 17 -#define r18 18 -#define r19 19 -#define r20 20 -#define r21 21 -#define r22 22 -#define r23 23 -#define r24 24 -#define r25 25 -#define r26 26 -#define r27 27 -#define r28 28 -#define r29 29 -#define r30 30 -#define r31 31 - - -/* Floating Point Registers (FPRs) */ - -#define fr0 0 -#define fr1 1 -#define fr2 2 -#define fr3 3 -#define fr4 4 -#define fr5 5 -#define fr6 6 -#define fr7 7 -#define fr8 8 -#define fr9 9 -#define fr10 10 -#define fr11 11 -#define fr12 12 -#define fr13 13 -#define fr14 14 -#define fr15 15 -#define fr16 16 -#define fr17 17 -#define fr18 18 -#define fr19 19 -#define fr20 20 -#define fr21 21 -#define fr22 22 -#define fr23 23 -#define fr24 24 -#define fr25 25 -#define fr26 26 -#define fr27 27 -#define fr28 28 -#define fr29 29 -#define fr30 30 -#define fr31 31 - -#define vr0 0 -#define vr1 1 -#define vr2 2 -#define vr3 3 -#define vr4 4 -#define vr5 5 -#define vr6 6 -#define vr7 7 -#define vr8 8 -#define vr9 9 -#define vr10 10 -#define vr11 11 -#define vr12 12 -#define vr13 13 -#define vr14 14 -#define vr15 15 -#define vr16 16 -#define vr17 17 -#define vr18 18 -#define vr19 19 -#define vr20 20 -#define vr21 21 -#define vr22 22 -#define vr23 23 -#define vr24 24 -#define vr25 25 -#define vr26 26 -#define vr27 27 -#define vr28 28 -#define vr29 29 -#define vr30 30 -#define vr31 31 - -#endif //_LANGUAGE_ASSEMBLY - -#define SPRG0 272 -#define SPRG1 273 -#define SPRG2 274 -#define SPRG3 275 - -#define PMC1 953 -#define PMC2 954 -#define PMC3 957 -#define PMC4 958 - -#define MMCR0 952 -#define MMCR1 956 - - -#define LINK_REGISTER_CALLEE_UPDATE_ROOM 4 -#define EXCEPTION_NUMBER 8 -#define SRR0_OFFSET 12 -#define SRR1_OFFSET 16 -#define GPR0_OFFSET 20 -#define GPR1_OFFSET 24 -#define GPR2_OFFSET 28 -#define GPR3_OFFSET 32 -#define GPR4_OFFSET 36 -#define GPR5_OFFSET 40 -#define GPR6_OFFSET 44 -#define GPR7_OFFSET 48 -#define GPR8_OFFSET 52 -#define GPR9_OFFSET 56 -#define GPR10_OFFSET 60 -#define GPR11_OFFSET 64 -#define GPR12_OFFSET 68 -#define GPR13_OFFSET 72 -#define GPR14_OFFSET 76 -#define GPR15_OFFSET 80 -#define GPR16_OFFSET 84 -#define GPR17_OFFSET 88 -#define GPR18_OFFSET 92 -#define GPR19_OFFSET 96 -#define GPR20_OFFSET 100 -#define GPR21_OFFSET 104 -#define GPR22_OFFSET 108 -#define GPR23_OFFSET 112 -#define GPR24_OFFSET 116 -#define GPR25_OFFSET 120 -#define GPR26_OFFSET 124 -#define GPR27_OFFSET 128 -#define GPR28_OFFSET 132 -#define GPR29_OFFSET 136 -#define GPR30_OFFSET 140 -#define GPR31_OFFSET 144 - -#define GQR0_OFFSET 148 -#define GQR1_OFFSET 152 -#define GQR2_OFFSET 156 -#define GQR3_OFFSET 160 -#define GQR4_OFFSET 164 -#define GQR5_OFFSET 168 -#define GQR6_OFFSET 172 -#define GQR7_OFFSET 176 - -#define CR_OFFSET 180 -#define LR_OFFSET 184 -#define CTR_OFFSET 188 -#define XER_OFFSET 192 -#define MSR_OFFSET 196 -#define DAR_OFFSET 200 - -#define STATE_OFFSET 204 -#define MODE_OFFSET 206 - -#define FPR0_OFFSET 208 -#define FPR1_OFFSET 216 -#define FPR2_OFFSET 224 -#define FPR3_OFFSET 232 -#define FPR4_OFFSET 240 -#define FPR5_OFFSET 248 -#define FPR6_OFFSET 256 -#define FPR7_OFFSET 264 -#define FPR8_OFFSET 272 -#define FPR9_OFFSET 280 -#define FPR10_OFFSET 288 -#define FPR11_OFFSET 296 -#define FPR12_OFFSET 304 -#define FPR13_OFFSET 312 -#define FPR14_OFFSET 320 -#define FPR15_OFFSET 328 -#define FPR16_OFFSET 336 -#define FPR17_OFFSET 344 -#define FPR18_OFFSET 352 -#define FPR19_OFFSET 360 -#define FPR20_OFFSET 368 -#define FPR21_OFFSET 376 -#define FPR22_OFFSET 384 -#define FPR23_OFFSET 392 -#define FPR24_OFFSET 400 -#define FPR25_OFFSET 408 -#define FPR26_OFFSET 416 -#define FPR27_OFFSET 424 -#define FPR28_OFFSET 432 -#define FPR29_OFFSET 440 -#define FPR30_OFFSET 448 -#define FPR31_OFFSET 456 - -#define FPSCR_OFFSET 464 - -#define PSR0_OFFSET 472 -#define PSR1_OFFSET 480 -#define PSR2_OFFSET 488 -#define PSR3_OFFSET 496 -#define PSR4_OFFSET 504 -#define PSR5_OFFSET 512 -#define PSR6_OFFSET 520 -#define PSR7_OFFSET 528 -#define PSR8_OFFSET 536 -#define PSR9_OFFSET 544 -#define PSR10_OFFSET 552 -#define PSR11_OFFSET 560 -#define PSR12_OFFSET 568 -#define PSR13_OFFSET 576 -#define PSR14_OFFSET 584 -#define PSR15_OFFSET 592 -#define PSR16_OFFSET 600 -#define PSR17_OFFSET 608 -#define PSR18_OFFSET 616 -#define PSR19_OFFSET 624 -#define PSR20_OFFSET 632 -#define PSR21_OFFSET 640 -#define PSR22_OFFSET 648 -#define PSR23_OFFSET 656 -#define PSR24_OFFSET 664 -#define PSR25_OFFSET 672 -#define PSR26_OFFSET 680 -#define PSR27_OFFSET 688 -#define PSR28_OFFSET 696 -#define PSR29_OFFSET 704 -#define PSR30_OFFSET 712 -#define PSR31_OFFSET 720 -/* - * maintain the EABI requested 8 bytes aligment - * As SVR4 ABI requires 16, make it 16 (as some - * exception may need more registers to be processed...) - */ -#define EXCEPTION_FRAME_END 728 - -#define IBAT0U 528 -#define IBAT0L 529 -#define IBAT1U 530 -#define IBAT1L 531 -#define IBAT2U 532 -#define IBAT2L 533 -#define IBAT3U 534 -#define IBAT3L 535 -#define IBAT4U 560 -#define IBAT4L 561 -#define IBAT5U 562 -#define IBAT5L 563 -#define IBAT6U 564 -#define IBAT6L 565 -#define IBAT7U 566 -#define IBAT7L 567 - -#define DBAT0U 536 -#define DBAT0L 537 -#define DBAT1U 538 -#define DBAT1L 538 -#define DBAT2U 540 -#define DBAT2L 541 -#define DBAT3U 542 -#define DBAT3L 543 -#define DBAT4U 568 -#define DBAT4L 569 -#define DBAT5U 570 -#define DBAT5L 571 -#define DBAT6U 572 -#define DBAT6L 573 -#define DBAT7U 574 -#define DBAT7L 575 - -#define HID0 1008 -#define HID1 1009 -#define HID2 920 -#define HID4 1011 - -#define GQR0 912 -#define GQR1 913 -#define GQR2 914 -#define GQR3 915 -#define GQR4 916 -#define GQR5 917 -#define GQR6 918 -#define GQR7 919 - -#define L2CR 1017 - -#define WPAR 921 - -#define DMAU 922 -#define DMAL 923 - -#define MSR_RI 0x00000002 -#define MSR_DR 0x00000010 -#define MSR_IR 0x00000020 -#define MSR_IP 0x00000040 -#define MSR_SE 0x00000400 -#define MSR_ME 0x00001000 -#define MSR_FP 0x00002000 -#define MSR_POW 0x00004000 -#define MSR_EE 0x00008000 - -#define PPC_ALIGNMENT 8 - -#define PPC_CACHE_ALIGNMENT 32 - -#endif //__ASM_H__ diff --git a/sdelfloader/loader/source/diskio.c b/sdelfloader/loader/source/diskio.c deleted file mode 100644 index a38a559..0000000 --- a/sdelfloader/loader/source/diskio.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2008 svpe, #wiidev at efnet - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include "sdio.h" -#include "diskio.h" - - -DSTATUS disk_initialize (BYTE drv) -{ - s32 r; - if(drv != 0) - return RES_PARERR; - - r = sd_init(); - - if(r == 0) - return RES_OK; - else - return RES_NOTRDY; -} - -DSTATUS disk_status ( BYTE drv ) -{ - return RES_OK; -} - -DRESULT disk_read ( - BYTE drv, /* Physical drive nmuber (0) */ - BYTE *buff, /* Data buffer to store read data */ - DWORD sector, /* Sector number (LBA) */ - BYTE count /* Sector count (1..255) */ -) -{ - s32 r = -1; - u32 i; - - for(i = 0; i < count; i++) - { - r = sd_read(sector + i, buff + (0x200 * i)); - if(r < 0) - return RES_NOTRDY; - } - - return RES_OK; -} - -DRESULT disk_ioctl ( - BYTE drv, /* Physical drive nmuber */ - BYTE ctrl, /* Control code */ - void *buff /* Buffer to send/receive data block */ -) -{ - return RES_OK; -} - -u32 get_fattime( void ) -{ - return 0; -} - diff --git a/sdelfloader/loader/source/diskio.h b/sdelfloader/loader/source/diskio.h deleted file mode 100644 index 73c8c44..0000000 --- a/sdelfloader/loader/source/diskio.h +++ /dev/null @@ -1,60 +0,0 @@ -/*----------------------------------------------------------------------- -/ Low level disk interface modlue include file R0.04a (C)ChaN, 2007 -/-----------------------------------------------------------------------*/ - -#ifndef _DISKIO - -#define _READONLY 0 /* 1: Read-only mode */ - -#include "integer.h" - - -/* Status of Disk Functions */ -typedef BYTE DSTATUS; - -/* Results of Disk Functions */ -typedef enum { - RES_OK = 0, /* 0: Successful */ - RES_ERROR, /* 1: R/W Error */ - RES_WRPRT, /* 2: Write Protected */ - RES_NOTRDY, /* 3: Not Ready */ - RES_PARERR /* 4: Invalid Parameter */ -} DRESULT; - - -/*---------------------------------------*/ -/* Prototypes for disk control functions */ - -DSTATUS disk_initialize (BYTE); -DSTATUS disk_status (BYTE); -DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); -DRESULT disk_ioctl (BYTE, BYTE, void*); -void disk_timerproc (void); - - - - -/* Disk Status Bits (DSTATUS) */ - -#define STA_NOINIT 0x01 /* Drive not initialized */ -#define STA_NODISK 0x02 /* No medium in the drive */ -#define STA_PROTECT 0x04 /* Write protected */ - - -/* Command code for disk_ioctrl() */ - -#define GET_SECTOR_COUNT 1 -#define GET_SECTOR_SIZE 2 -#define CTRL_SYNC 3 -#define CTRL_POWER 4 -#define CTRL_LOCK 5 -#define CTRL_EJECT 6 -#define MMC_GET_CSD 10 -#define MMC_GET_CID 11 -#define MMC_GET_OCR 12 -#define ATA_GET_REV 20 -#define ATA_GET_MODEL 21 -#define ATA_GET_SN 22 - -#define _DISKIO -#endif diff --git a/sdelfloader/loader/source/dol.c b/sdelfloader/loader/source/dol.c deleted file mode 100644 index 35fedea..0000000 --- a/sdelfloader/loader/source/dol.c +++ /dev/null @@ -1,74 +0,0 @@ -// this code was contributed by shagkur of the devkitpro team, thx! - -#include -#include - -#include -#include - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -u32 load_dol_image (void *dolstart) { - u32 i; - dolheader *dolfile; - - if (dolstart) { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) { - if ((!dolfile->text_size[i]) || - (dolfile->text_start[i] < 0x100)) - continue; - - printf ("loading text section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->text_start[i], - dolfile->text_size[i]); - VIDEO_WaitVSync(); - - ICInvalidateRange ((void *) dolfile->text_start[i], - dolfile->text_size[i]); - memmove ((void *) dolfile->text_start[i], - dolstart+dolfile->text_pos[i], - dolfile->text_size[i]); - } - - for(i = 0; i < 11; i++) { - if ((!dolfile->data_size[i]) || - (dolfile->data_start[i] < 0x100)) - continue; - - printf ("loading data section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->data_start[i], - dolfile->data_size[i]); - VIDEO_WaitVSync(); - - memmove ((void*) dolfile->data_start[i], - dolstart+dolfile->data_pos[i], - dolfile->data_size[i]); - DCFlushRangeNoSync ((void *) dolfile->data_start[i], - dolfile->data_size[i]); - } - - printf ("clearing bss\n"); - VIDEO_WaitVSync(); - - memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - - return dolfile->entry_point; - } - - return 0; -} - diff --git a/sdelfloader/loader/source/dol.h b/sdelfloader/loader/source/dol.h deleted file mode 100644 index d338d4c..0000000 --- a/sdelfloader/loader/source/dol.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2008 dhewg, #wiidev efnet - * - * this file is part of geckoloader - * http://wiibrew.org/index.php?title=Geckoloader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _DOL_H_ - -#include - -u32 load_dol_image (void *dolstart); - -#endif - diff --git a/sdelfloader/loader/source/elf.c b/sdelfloader/loader/source/elf.c deleted file mode 100644 index 8d1e8d7..0000000 --- a/sdelfloader/loader/source/elf.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2001 William L. Pitts - * Modifications (c) 2004 Felix Domke - * All rights reserved. - * - * Redistribution and use in source and binary forms are freely - * permitted provided that the above copyright notice and this - * paragraph and the following disclaimer are duplicated in all - * such forms. - * - * This software is provided "AS IS" and without any express or - * implied warranties, including, without limitation, the implied - * warranties of merchantability and fitness for a particular - * purpose. - */ - -#include -#include - -#include - -#include "elf_abi.h" - -/* ====================================================================== - * Determine if a valid ELF image exists at the given memory location. - * First looks at the ELF header magic field, the makes sure that it is - * executable and makes sure that it is for a PowerPC. - * ====================================================================== */ -s32 valid_elf_image (void *addr) -{ - Elf32_Ehdr *ehdr; /* Elf header structure pointer */ - - ehdr = (Elf32_Ehdr *) addr; - - if (!IS_ELF (*ehdr)) - return 0; - - if (ehdr->e_type != ET_EXEC) - return -1; - - if (ehdr->e_machine != EM_PPC) - return -1; - - return 1; -} - - -/* ====================================================================== - * A very simple elf loader, assumes the image is valid, returns the - * entry point address. - * ====================================================================== */ -u32 load_elf_image (void *addr) -{ - Elf32_Ehdr *ehdr; - Elf32_Shdr *shdr; - u8 *strtab = 0; - u8 *image; - int i; - - ehdr = (Elf32_Ehdr *) addr; - /* Find the section header string table for output info */ - shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff + - (ehdr->e_shstrndx * sizeof (Elf32_Shdr))); - - if (shdr->sh_type == SHT_STRTAB) - strtab = (u8 *) (addr + shdr->sh_offset); - - /* Load each appropriate section */ - for (i = 0; i < ehdr->e_shnum; ++i) { - shdr = (Elf32_Shdr *) (addr + ehdr->e_shoff + - (i * sizeof (Elf32_Shdr))); - - if (!(shdr->sh_flags & SHF_ALLOC) - || shdr->sh_addr == 0 || shdr->sh_size == 0) { - continue; - } - - shdr->sh_addr &= 0x3FFFFFFF; - shdr->sh_addr |= 0x80000000; - - if (strtab) { - printf ("%sing section %s @ 0x%08x (0x%08x bytes)\n", - (shdr->sh_type == SHT_NOBITS) ? - "clear" : "load", - &strtab[shdr->sh_name], - (u32) shdr->sh_addr, - (u32) shdr->sh_size); - } - - if (shdr->sh_type == SHT_NOBITS) { - memset ((void *) shdr->sh_addr, 0, shdr->sh_size); - } else { - image = (u8 *) addr + shdr->sh_offset; - memcpy ((void *) shdr->sh_addr, - (const void *) image, - shdr->sh_size); - } - DCFlushRangeNoSync ((void *) shdr->sh_addr, shdr->sh_size); - } - - return (ehdr->e_entry & 0x3FFFFFFF) | 0x80000000; -} - diff --git a/sdelfloader/loader/source/elf.h b/sdelfloader/loader/source/elf.h deleted file mode 100644 index 2bbb7bd..0000000 --- a/sdelfloader/loader/source/elf.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _ELF_H_ -#define _ELF_H_ - -#include - -s32 valid_elf_image (void *addr); -u32 load_elf_image (void *addr); - -#endif diff --git a/sdelfloader/loader/source/elf_abi.h b/sdelfloader/loader/source/elf_abi.h deleted file mode 100644 index c9e705e..0000000 --- a/sdelfloader/loader/source/elf_abi.h +++ /dev/null @@ -1,594 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 2001, 2002 - * Erik Theisen. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is the ELF ABI header file - * formerly known as "elf_abi.h". - */ - -#ifndef _ELF_ABI_H -#define _ELF_ABI_H - -#include - -/* - * This version doesn't work for 64-bit ABIs - Erik. - */ - -/* - * These typedefs need to be handled better. - */ -typedef u32 Elf32_Addr; /* Unsigned program address */ -typedef u32 Elf32_Off; /* Unsigned file offset */ -typedef s32 Elf32_Sword; /* Signed large integer */ -typedef u32 Elf32_Word; /* Unsigned large integer */ -typedef u16 Elf32_Half; /* Unsigned medium integer */ - -/* e_ident[] identification indexes */ -#define EI_MAG0 0 /* file ID */ -#define EI_MAG1 1 /* file ID */ -#define EI_MAG2 2 /* file ID */ -#define EI_MAG3 3 /* file ID */ -#define EI_CLASS 4 /* file class */ -#define EI_DATA 5 /* data encoding */ -#define EI_VERSION 6 /* ELF header version */ -#define EI_OSABI 7 /* OS/ABI specific ELF extensions */ -#define EI_ABIVERSION 8 /* ABI target version */ -#define EI_PAD 9 /* start of pad bytes */ -#define EI_NIDENT 16 /* Size of e_ident[] */ - -/* e_ident[] magic number */ -#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ -#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ -#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ -#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ -#define ELFMAG "\177ELF" /* magic */ -#define SELFMAG 4 /* size of magic */ - -/* e_ident[] file class */ -#define ELFCLASSNONE 0 /* invalid */ -#define ELFCLASS32 1 /* 32-bit objs */ -#define ELFCLASS64 2 /* 64-bit objs */ -#define ELFCLASSNUM 3 /* number of classes */ - -/* e_ident[] data encoding */ -#define ELFDATANONE 0 /* invalid */ -#define ELFDATA2LSB 1 /* Little-Endian */ -#define ELFDATA2MSB 2 /* Big-Endian */ -#define ELFDATANUM 3 /* number of data encode defines */ - -/* e_ident[] OS/ABI specific ELF extensions */ -#define ELFOSABI_NONE 0 /* No extension specified */ -#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */ -#define ELFOSABI_NETBSD 2 /* NetBSD */ -#define ELFOSABI_LINUX 3 /* Linux */ -#define ELFOSABI_SOLARIS 6 /* Sun Solaris */ -#define ELFOSABI_AIX 7 /* AIX */ -#define ELFOSABI_IRIX 8 /* IRIX */ -#define ELFOSABI_FREEBSD 9 /* FreeBSD */ -#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */ -#define ELFOSABI_MODESTO 11 /* Novell Modesto */ -#define ELFOSABI_OPENBSD 12 /* OpenBSD */ -/* 64-255 Architecture-specific value range */ - -/* e_ident[] ABI Version */ -#define ELFABIVERSION 0 - -/* e_ident */ -#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ - (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ - (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ - (ehdr).e_ident[EI_MAG3] == ELFMAG3) - -/* ELF Header */ -typedef struct elfhdr{ - unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ - Elf32_Half e_type; /* object file type */ - Elf32_Half e_machine; /* machine */ - Elf32_Word e_version; /* object file version */ - Elf32_Addr e_entry; /* virtual entry point */ - Elf32_Off e_phoff; /* program header table offset */ - Elf32_Off e_shoff; /* section header table offset */ - Elf32_Word e_flags; /* processor-specific flags */ - Elf32_Half e_ehsize; /* ELF header size */ - Elf32_Half e_phentsize; /* program header entry size */ - Elf32_Half e_phnum; /* number of program header entries */ - Elf32_Half e_shentsize; /* section header entry size */ - Elf32_Half e_shnum; /* number of section header entries */ - Elf32_Half e_shstrndx; /* section header table's "section - header string table" entry offset */ -} Elf32_Ehdr; - -/* e_type */ -#define ET_NONE 0 /* No file type */ -#define ET_REL 1 /* relocatable file */ -#define ET_EXEC 2 /* executable file */ -#define ET_DYN 3 /* shared object file */ -#define ET_CORE 4 /* core file */ -#define ET_NUM 5 /* number of types */ -#define ET_LOOS 0xfe00 /* reserved range for operating */ -#define ET_HIOS 0xfeff /* system specific e_type */ -#define ET_LOPROC 0xff00 /* reserved range for processor */ -#define ET_HIPROC 0xffff /* specific e_type */ - -/* e_machine */ -#define EM_NONE 0 /* No Machine */ -#define EM_M32 1 /* AT&T WE 32100 */ -#define EM_SPARC 2 /* SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola 68000 */ -#define EM_88K 5 /* Motorola 88000 */ -#if 0 -#define EM_486 6 /* RESERVED - was Intel 80486 */ -#endif -#define EM_860 7 /* Intel 80860 */ -#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ -#define EM_S370 9 /* IBM System/370 Processor */ -#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ -#if 0 -#define EM_SPARC64 11 /* RESERVED - was SPARC v9 - 64-bit unoffical */ -#endif -/* RESERVED 11-14 for future use */ -#define EM_PARISC 15 /* HPPA */ -/* RESERVED 16 for future use */ -#define EM_VPP500 17 /* Fujitsu VPP500 */ -#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ -#define EM_960 19 /* Intel 80960 */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* 64-bit PowerPC */ -#define EM_S390 22 /* IBM System/390 Processor */ -/* RESERVED 23-35 for future use */ -#define EM_V800 36 /* NEC V800 */ -#define EM_FR20 37 /* Fujitsu FR20 */ -#define EM_RH32 38 /* TRW RH-32 */ -#define EM_RCE 39 /* Motorola RCE */ -#define EM_ARM 40 /* Advanced Risc Machines ARM */ -#define EM_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC Version 9 */ -#define EM_TRICORE 44 /* Siemens TriCore embedded processor */ -#define EM_ARC 45 /* Argonaut RISC Core */ -#define EM_H8_300 46 /* Hitachi H8/300 */ -#define EM_H8_300H 47 /* Hitachi H8/300H */ -#define EM_H8S 48 /* Hitachi H8S */ -#define EM_H8_500 49 /* Hitachi H8/500 */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_MIPS_X 51 /* Stanford MIPS-X */ -#define EM_COLDFIRE 52 /* Motorola Coldfire */ -#define EM_68HC12 53 /* Motorola M68HC12 */ -#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ -#define EM_PCP 55 /* Siemens PCP */ -#define EM_NCPU 56 /* Sony nCPU embeeded RISC */ -#define EM_NDR1 57 /* Denso NDR1 microprocessor */ -#define EM_STARCORE 58 /* Motorola Start*Core processor */ -#define EM_ME16 59 /* Toyota ME16 processor */ -#define EM_ST100 60 /* STMicroelectronic ST100 processor */ -#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ -#define EM_X86_64 62 /* AMD x86-64 */ -#define EM_PDSP 63 /* Sony DSP Processor */ -/* RESERVED 64,65 for future use */ -#define EM_FX66 66 /* Siemens FX66 microcontroller */ -#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ -#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ -#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ -#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ -#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ -#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ -#define EM_SVX 73 /* Silicon Graphics SVx */ -#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ -#define EM_VAX 75 /* Digital VAX */ -#define EM_CHRIS 76 /* Axis Communications embedded proc. */ -#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */ -#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ -#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ -#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */ -#define EM_HUANY 81 /* Harvard University mach-indep objs */ -#define EM_PRISM 82 /* SiTera Prism */ -#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ -#define EM_FR30 84 /* Fujitsu FR30 */ -#define EM_D10V 85 /* Mitsubishi DV10V */ -#define EM_D30V 86 /* Mitsubishi DV30V */ -#define EM_V850 87 /* NEC v850 */ -#define EM_M32R 88 /* Mitsubishi M32R */ -#define EM_MN10300 89 /* Matsushita MN10200 */ -#define EM_MN10200 90 /* Matsushita MN10200 */ -#define EM_PJ 91 /* picoJava */ -#define EM_NUM 92 /* number of machine types */ - -/* Version */ -#define EV_NONE 0 /* Invalid */ -#define EV_CURRENT 1 /* Current */ -#define EV_NUM 2 /* number of versions */ - -/* Section Header */ -typedef struct { - Elf32_Word sh_name; /* name - index into section header - string table section */ - Elf32_Word sh_type; /* type */ - Elf32_Word sh_flags; /* flags */ - Elf32_Addr sh_addr; /* address */ - Elf32_Off sh_offset; /* file offset */ - Elf32_Word sh_size; /* section size */ - Elf32_Word sh_link; /* section header table index link */ - Elf32_Word sh_info; /* extra information */ - Elf32_Word sh_addralign; /* address alignment */ - Elf32_Word sh_entsize; /* section entry size */ -} Elf32_Shdr; - -/* Special Section Indexes */ -#define SHN_UNDEF 0 /* undefined */ -#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ -#define SHN_LOPROC 0xff00 /* reserved range for processor */ -#define SHN_HIPROC 0xff1f /* specific section indexes */ -#define SHN_LOOS 0xff20 /* reserved range for operating */ -#define SHN_HIOS 0xff3f /* specific semantics */ -#define SHN_ABS 0xfff1 /* absolute value */ -#define SHN_COMMON 0xfff2 /* common symbol */ -#define SHN_XINDEX 0xffff /* Index is an extra table */ -#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ - -/* sh_type */ -#define SHT_NULL 0 /* inactive */ -#define SHT_PROGBITS 1 /* program defined information */ -#define SHT_SYMTAB 2 /* symbol table section */ -#define SHT_STRTAB 3 /* string table section */ -#define SHT_RELA 4 /* relocation section with addends*/ -#define SHT_HASH 5 /* symbol hash table section */ -#define SHT_DYNAMIC 6 /* dynamic section */ -#define SHT_NOTE 7 /* note section */ -#define SHT_NOBITS 8 /* no space section */ -#define SHT_REL 9 /* relation section without addends */ -#define SHT_SHLIB 10 /* reserved - purpose unknown */ -#define SHT_DYNSYM 11 /* dynamic symbol table section */ -#define SHT_INIT_ARRAY 14 /* Array of constructors */ -#define SHT_FINI_ARRAY 15 /* Array of destructors */ -#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ -#define SHT_GROUP 17 /* Section group */ -#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */ -#define SHT_NUM 19 /* number of section types */ -#define SHT_LOOS 0x60000000 /* Start OS-specific */ -#define SHT_HIOS 0x6fffffff /* End OS-specific */ -#define SHT_LOPROC 0x70000000 /* reserved range for processor */ -#define SHT_HIPROC 0x7fffffff /* specific section header types */ -#define SHT_LOUSER 0x80000000 /* reserved range for application */ -#define SHT_HIUSER 0xffffffff /* specific indexes */ - -/* Section names */ -#define ELF_BSS ".bss" /* uninitialized data */ -#define ELF_COMMENT ".comment" /* version control information */ -#define ELF_DATA ".data" /* initialized data */ -#define ELF_DATA1 ".data1" /* initialized data */ -#define ELF_DEBUG ".debug" /* debug */ -#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ -#define ELF_DYNSTR ".dynstr" /* dynamic string table */ -#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ -#define ELF_FINI ".fini" /* termination code */ -#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */ -#define ELF_GOT ".got" /* global offset table */ -#define ELF_HASH ".hash" /* symbol hash table */ -#define ELF_INIT ".init" /* initialization code */ -#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */ -#define ELF_INTERP ".interp" /* Pathname of program interpreter */ -#define ELF_LINE ".line" /* Symbolic line numnber information */ -#define ELF_NOTE ".note" /* Contains note section */ -#define ELF_PLT ".plt" /* Procedure linkage table */ -#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */ -#define ELF_REL_DATA ".rel.data" /* relocation data */ -#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ -#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ -#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */ -#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ -#define ELF_REL_TEXT ".rel.text" /* relocation code */ -#define ELF_RODATA ".rodata" /* read-only data */ -#define ELF_RODATA1 ".rodata1" /* read-only data */ -#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ -#define ELF_STRTAB ".strtab" /* string table */ -#define ELF_SYMTAB ".symtab" /* symbol table */ -#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */ -#define ELF_TBSS ".tbss" /* thread local uninit data */ -#define ELF_TDATA ".tdata" /* thread local init data */ -#define ELF_TDATA1 ".tdata1" /* thread local init data */ -#define ELF_TEXT ".text" /* code */ - -/* Section Attribute Flags - sh_flags */ -#define SHF_WRITE 0x1 /* Writable */ -#define SHF_ALLOC 0x2 /* occupies memory */ -#define SHF_EXECINSTR 0x4 /* executable */ -#define SHF_MERGE 0x10 /* Might be merged */ -#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */ -#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */ -#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/ -#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */ -#define SHF_GROUP 0x200 /* Member of section group */ -#define SHF_TLS 0x400 /* Thread local storage */ -#define SHF_MASKOS 0x0ff00000 /* OS specific */ -#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ - /* specific section attributes */ - -/* Section Group Flags */ -#define GRP_COMDAT 0x1 /* COMDAT group */ -#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */ -#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */ - -/* Symbol Table Entry */ -typedef struct elf32_sym { - Elf32_Word st_name; /* name - index into string table */ - Elf32_Addr st_value; /* symbol value */ - Elf32_Word st_size; /* symbol size */ - unsigned char st_info; /* type and binding */ - unsigned char st_other; /* 0 - no defined meaning */ - Elf32_Half st_shndx; /* section header index */ -} Elf32_Sym; - -/* Symbol table index */ -#define STN_UNDEF 0 /* undefined */ - -/* Extract symbol info - st_info */ -#define ELF32_ST_BIND(x) ((x) >> 4) -#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) -#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) -#define ELF32_ST_VISIBILITY(x) ((x) & 0x3) - -/* Symbol Binding - ELF32_ST_BIND - st_info */ -#define STB_LOCAL 0 /* Local symbol */ -#define STB_GLOBAL 1 /* Global symbol */ -#define STB_WEAK 2 /* like global - lower precedence */ -#define STB_NUM 3 /* number of symbol bindings */ -#define STB_LOOS 10 /* reserved range for operating */ -#define STB_HIOS 12 /* system specific symbol bindings */ -#define STB_LOPROC 13 /* reserved range for processor */ -#define STB_HIPROC 15 /* specific symbol bindings */ - -/* Symbol type - ELF32_ST_TYPE - st_info */ -#define STT_NOTYPE 0 /* not specified */ -#define STT_OBJECT 1 /* data object */ -#define STT_FUNC 2 /* function */ -#define STT_SECTION 3 /* section */ -#define STT_FILE 4 /* file */ -#define STT_NUM 5 /* number of symbol types */ -#define STT_TLS 6 /* Thread local storage symbol */ -#define STT_LOOS 10 /* reserved range for operating */ -#define STT_HIOS 12 /* system specific symbol types */ -#define STT_LOPROC 13 /* reserved range for processor */ -#define STT_HIPROC 15 /* specific symbol types */ - -/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */ -#define STV_DEFAULT 0 /* Normal visibility rules */ -#define STV_INTERNAL 1 /* Processor specific hidden class */ -#define STV_HIDDEN 2 /* Symbol unavailable in other mods */ -#define STV_PROTECTED 3 /* Not preemptible, not exported */ - - -/* Relocation entry with implicit addend */ -typedef struct -{ - Elf32_Addr r_offset; /* offset of relocation */ - Elf32_Word r_info; /* symbol table index and type */ -} Elf32_Rel; - -/* Relocation entry with explicit addend */ -typedef struct -{ - Elf32_Addr r_offset; /* offset of relocation */ - Elf32_Word r_info; /* symbol table index and type */ - Elf32_Sword r_addend; -} Elf32_Rela; - -/* Extract relocation info - r_info */ -#define ELF32_R_SYM(i) ((i) >> 8) -#define ELF32_R_TYPE(i) ((unsigned char) (i)) -#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) - -/* Program Header */ -typedef struct { - Elf32_Word p_type; /* segment type */ - Elf32_Off p_offset; /* segment offset */ - Elf32_Addr p_vaddr; /* virtual address of segment */ - Elf32_Addr p_paddr; /* physical address - ignored? */ - Elf32_Word p_filesz; /* number of bytes in file for seg. */ - Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ - Elf32_Word p_flags; /* flags */ - Elf32_Word p_align; /* memory alignment */ -} Elf32_Phdr; - -/* Segment types - p_type */ -#define PT_NULL 0 /* unused */ -#define PT_LOAD 1 /* loadable segment */ -#define PT_DYNAMIC 2 /* dynamic linking section */ -#define PT_INTERP 3 /* the RTLD */ -#define PT_NOTE 4 /* auxiliary information */ -#define PT_SHLIB 5 /* reserved - purpose undefined */ -#define PT_PHDR 6 /* program header */ -#define PT_TLS 7 /* Thread local storage template */ -#define PT_NUM 8 /* Number of segment types */ -#define PT_LOOS 0x60000000 /* reserved range for operating */ -#define PT_HIOS 0x6fffffff /* system specific segment types */ -#define PT_LOPROC 0x70000000 /* reserved range for processor */ -#define PT_HIPROC 0x7fffffff /* specific segment types */ - -/* Segment flags - p_flags */ -#define PF_X 0x1 /* Executable */ -#define PF_W 0x2 /* Writable */ -#define PF_R 0x4 /* Readable */ -#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */ -#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ - /* specific segment flags */ -/* Dynamic structure */ -typedef struct -{ - Elf32_Sword d_tag; /* controls meaning of d_val */ - union - { - Elf32_Word d_val; /* Multiple meanings - see d_tag */ - Elf32_Addr d_ptr; /* program virtual address */ - } d_un; -} Elf32_Dyn; - -extern Elf32_Dyn _DYNAMIC[]; - -/* Dynamic Array Tags - d_tag */ -#define DT_NULL 0 /* marks end of _DYNAMIC array */ -#define DT_NEEDED 1 /* string table offset of needed lib */ -#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ -#define DT_PLTGOT 3 /* address PLT/GOT */ -#define DT_HASH 4 /* address of symbol hash table */ -#define DT_STRTAB 5 /* address of string table */ -#define DT_SYMTAB 6 /* address of symbol table */ -#define DT_RELA 7 /* address of relocation table */ -#define DT_RELASZ 8 /* size of relocation table */ -#define DT_RELAENT 9 /* size of relocation entry */ -#define DT_STRSZ 10 /* size of string table */ -#define DT_SYMENT 11 /* size of symbol table entry */ -#define DT_INIT 12 /* address of initialization func. */ -#define DT_FINI 13 /* address of termination function */ -#define DT_SONAME 14 /* string table offset of shared obj */ -#define DT_RPATH 15 /* string table offset of library - search path */ -#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ -#define DT_REL 17 /* address of rel. tbl. w addends */ -#define DT_RELSZ 18 /* size of DT_REL relocation table */ -#define DT_RELENT 19 /* size of DT_REL relocation entry */ -#define DT_PLTREL 20 /* PLT referenced relocation entry */ -#define DT_DEBUG 21 /* bugger */ -#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ -#define DT_JMPREL 23 /* add. of PLT's relocation entries */ -#define DT_BIND_NOW 24 /* Process relocations of object */ -#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ -#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ -#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ -#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ -#define DT_RUNPATH 29 /* Library search path */ -#define DT_FLAGS 30 /* Flags for the object being loaded */ -#define DT_ENCODING 32 /* Start of encoded range */ -#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ -#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ -#define DT_NUM 34 /* Number used. */ -#define DT_LOOS 0x60000000 /* reserved range for OS */ -#define DT_HIOS 0x6fffffff /* specific dynamic array tags */ -#define DT_LOPROC 0x70000000 /* reserved range for processor */ -#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ - -/* Dynamic Tag Flags - d_un.d_val */ -#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */ -#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */ -#define DF_TEXTREL 0x04 /* Object contains text relocations */ -#define DF_BIND_NOW 0x08 /* No lazy binding for this object */ -#define DF_STATIC_TLS 0x10 /* Static thread local storage */ - -/* Standard ELF hashing function */ -unsigned long elf_hash(const unsigned char *name); - -#define ELF_TARG_VER 1 /* The ver for which this code is intended */ - -/* - * XXX - PowerPC defines really don't belong in here, - * but we'll put them in for simplicity. - */ - -/* Values for Elf32/64_Ehdr.e_flags. */ -#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ - -/* Cygnus local bits below */ -#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ -#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib - flag */ - -/* PowerPC relocations defined by the ABIs */ -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 /* 32bit absolute address */ -#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ -#define R_PPC_ADDR16 3 /* 16bit absolute address */ -#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ -#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ -#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ -#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 /* PC relative 26 bit */ -#define R_PPC_REL14 11 /* PC relative 16 bit */ -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 -/* Keep this the last entry. */ -#define R_PPC_NUM 37 - -/* The remaining relocs are from the Embedded ELF ABI, and are not - in the SVR4 ELF ABI. */ -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ - -/* Diab tool relocations. */ -#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ -#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ -#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ -#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ -#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ -#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ - -/* This is a phony reloc to handle any old fashioned TOC16 references - that may still be in object files. */ -#define R_PPC_TOC16 255 - -#endif /* _ELF_H */ - diff --git a/sdelfloader/loader/source/integer.h b/sdelfloader/loader/source/integer.h deleted file mode 100644 index e8cc71e..0000000 --- a/sdelfloader/loader/source/integer.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _INTEGER - -typedef signed int INT; -typedef unsigned int UINT; - -/* These types are assumed as 8-bit integer */ -typedef signed char CHAR; -typedef unsigned char UCHAR; -typedef unsigned char BYTE; - -/* These types are assumed as 16-bit integer */ -typedef signed short SHORT; -typedef unsigned short USHORT; -typedef unsigned short WORD; - -/* These types are assumed as 32-bit integer */ -typedef signed long LONG; -typedef unsigned long ULONG; -typedef unsigned long DWORD; - -/* Boolean type */ -//typedef enum { FALSE = 0, TRUE } BOOL; - -#define _INTEGER -#endif diff --git a/sdelfloader/loader/source/main.c b/sdelfloader/loader/source/main.c deleted file mode 100644 index 6b1e595..0000000 --- a/sdelfloader/loader/source/main.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2008 svpe, #wiidev at efnet - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include -#include - -#define FILES_PER_PAGE 24 - -#include "sdio.h" -#include "tff.h" -#include "elf.h" -#include "dol.h" - -#include "asm.h" -#include "processor.h" - -static void *xfb = NULL; -static GXRModeObj *rmode = NULL; - -extern void __exception_closeall(); -extern s32 __IOS_ShutdownSubsystems(); - -#define USB_ALIGN __attribute__((aligned(32))) -static const char *usb_path USB_ALIGN = "/dev/usb/oh1/57e/305"; -char bluetoothResetData1[] USB_ALIGN = { - /* bmRequestType */ - 0x20 -}; - -char bluetoothResetData2[] USB_ALIGN = { - /* bmRequest */ - 0x00 -}; - -char bluetoothResetData3[] USB_ALIGN = { - /* wValue */ - 0x00, 0x00 -}; - -char bluetoothResetData4[] USB_ALIGN = { - /* wIndex */ - 0x00, 0x00 -}; - -char bluetoothResetData5[] USB_ALIGN = { - /* wLength */ - 0x03, 0x00 -}; - -char bluetoothResetData6[] USB_ALIGN = { - /* unknown; set to zero. */ - 0x00 -}; - -char bluetoothResetData7[] USB_ALIGN = { - /* Mesage payload. */ - 0x03, 0x0c, 0x00 -}; - -/** Vectors of data transfered. */ -ioctlv bluetoothReset[] USB_ALIGN = { - { - bluetoothResetData1, - sizeof(bluetoothResetData1) - }, - { - bluetoothResetData2, - sizeof(bluetoothResetData2) - }, - { - bluetoothResetData3, - sizeof(bluetoothResetData3) - }, - { - bluetoothResetData4, - sizeof(bluetoothResetData4) - }, - { - bluetoothResetData5, - sizeof(bluetoothResetData5) - }, - { - bluetoothResetData6, - sizeof(bluetoothResetData6) - }, - { - bluetoothResetData7, - sizeof(bluetoothResetData7) - } -}; - - - -int main(int argc, char **argv) { - - FATFS ffs; - DIR elfdir; - FILINFO finfo; - - char filename[4+13+1]; - - char filelist[999][13]; // FIXME: use a dynamic filelist here - u32 files; - - FIL fp; - WORD bytes_read; - u32 bytes_read_total; - u8 *data = (u8 *)0x92000000; - - u32 offset; - u32 selection; - u32 i; - u32 level; - u32 buttons; - - s32 res; - - s32 usb_fd = -1; - - void (*ep)(); - - - VIDEO_Init(); - PAD_Init(); - AUDIO_Init (NULL); - DSP_Init (); - AUDIO_StopDMA(); - AUDIO_RegisterDMACallback(NULL); - - switch(VIDEO_GetCurrentTvMode()) { - case VI_NTSC: - rmode = &TVNtsc480IntDf; - break; - case VI_PAL: - rmode = &TVPal528IntDf; - break; - case VI_MPAL: - rmode = &TVMpal480IntDf; - break; - default: - rmode = &TVNtsc480IntDf; - break; - } - - xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); - - VIDEO_Configure(rmode); - VIDEO_SetNextFramebuffer(xfb); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); - - - printf("\n\n"); - printf("Front SD ELF Loader\n"); - printf("(c) 2008 Sven Peter (svpe, #wiidev at blitzed/efnet)\n"); - printf("Internal SD stuff by bushing, marcan and maybe some more ppl i don't know about.\n"); - printf("TinyFAT FS by elm-chan.org\n"); - printf("Some ELF loader code by dhewg and tmbinc\n"); - - redo_top: - printf("Press A to continue\n"); - while(1) - { - VIDEO_WaitVSync(); - PAD_ScanPads(); - if(PAD_ButtonsDown(0) & PAD_BUTTON_A) - break; - } - - // shutdown wiimote - printf("Shutting down wiimote\n"); -// printf("Open Bluetooth Dongle\n"); - usb_fd = IOS_Open(usb_path, 2 /* 2 = write, 1 = read */); - printf("fd = %d\n", usb_fd); - -// printf("Closing connection to blutooth\n"); - res = IOS_Ioctlv(usb_fd, 0, 6, 1, bluetoothReset); -// printf("ret = %d\n", res); - - IOS_Close(usb_fd); - - - files = 0; - if(f_mount(0, &ffs) != FR_OK) - { - printf("f_mount() failed. No FAT filesystem on the SD card?\n"); - goto redo_top; - } - - res = f_opendir(&elfdir, "elf"); - if(res != FR_OK) - { - printf("f_opendir() failed with %d. Does elf/ exist?\n", res); - goto redo_top; - } - - printf("Loading filelist...\n"); - files = 0; - memset(&finfo, 0, sizeof(finfo)); - f_readdir(&elfdir, &finfo); - while(strlen(finfo.fname) != 0) - { - if(!(finfo.fattrib & AM_DIR)) - { - printf("Adding %s\n", finfo.fname); - memcpy(filelist[files], finfo.fname, 13); - files++; - } - f_readdir(&elfdir, &finfo); - } - - goto while_loop; - - redo: - - printf("Press A..\n"); - while(1) - { - VIDEO_WaitVSync(); - PAD_ScanPads(); - if(PAD_ButtonsDown(0) & PAD_BUTTON_A) - break; - } - - while_loop: - offset = selection = 0; - while(1) - { - printf("\x1b[2J\n"); - - for(i = offset; i < (offset + FILES_PER_PAGE) && i < files; i++) - { - if(selection == i) - printf(">>%s\n", filelist[i]); - else - printf("%s\n", filelist[i]); - } - printf("\n\n"); - - while(1) - { - PAD_ScanPads(); - buttons = PAD_ButtonsDown(0); - if(buttons & PAD_BUTTON_A) - { - snprintf(filename, 4+13, "elf/%s", filelist[selection]); - if(f_stat(filename, &finfo) != FR_OK) - { - printf("error: f_stat() failed :/\n"); - goto redo; - } - if(f_open(&fp, filename, FA_READ) != FR_OK) - { - printf("error: f_open() failed\n"); - goto redo; - } - printf("Reading %u bytes\n", (unsigned int)finfo.fsize); - bytes_read = bytes_read_total = 0; - while(bytes_read_total < finfo.fsize) - { - if(f_read(&fp, data + bytes_read_total, 0x200, &bytes_read) != FR_OK) - { - printf("error: f_read failed.\n"); - goto redo; - } - if(bytes_read == 0) - break; - bytes_read_total += bytes_read; -// printf("%d/%d bytes read (%d this time)\n", bytes_read_total, (unsigned int)finfo.fsize, bytes_read); - } - if(bytes_read_total < finfo.fsize) - { - printf("error: read %u of %u bytes.\n", bytes_read_total, (unsigned int)finfo.fsize); - goto redo; - } - res = valid_elf_image(data); - if(res == 1) - { - printf("ELF image found.\n"); - ep = (void(*)())load_elf_image(data); - } - else - { - printf("Assuming that this is a DOL file. Your Wii will crash if it isn't...\n"); - ep = (void(*)())load_dol_image(data); - } - f_close(&fp); - sd_deinit(); - - printf("entry point: 0x%X\n", (unsigned int)ep); - VIDEO_WaitVSync(); - - // code from geckoloader - __IOS_ShutdownSubsystems (); - printf("IOS_ShutdownSubsystems() done\n"); - _CPU_ISR_Disable (level); - printf("_CPU_ISR_Disable() done\n"); - __exception_closeall (); - printf("__exception_closeall() done. Jumping to ep now...\n"); - ep(); - _CPU_ISR_Restore (level); - - printf("binaries really shouldn't return here...\n"); - while(1) - VIDEO_WaitVSync(); - } - else if(buttons & PAD_BUTTON_DOWN) - { - if(selection+1 < files) - selection++; - if(selection >= offset + FILES_PER_PAGE) - offset += FILES_PER_PAGE; - break; - } - else if(buttons & PAD_BUTTON_UP) - { - if(selection > 0) - selection--; - if(selection < offset) - { - if(FILES_PER_PAGE > offset) - offset = 0; - else - offset -= FILES_PER_PAGE; - } - break; - } - - VIDEO_WaitVSync(); - } - } - printf("this should not happen\n"); - while(1) - VIDEO_WaitVSync(); - return 0; -} diff --git a/sdelfloader/loader/source/processor.h b/sdelfloader/loader/source/processor.h deleted file mode 100644 index 01618b6..0000000 --- a/sdelfloader/loader/source/processor.h +++ /dev/null @@ -1,115 +0,0 @@ -// this file was taken from libogc, see http://www.devkitpro.org/ - -#ifndef __PROCESSOR_H__ -#define __PROCESSOR_H__ - -#include - -#define __stringify(rn) #rn -#define ATTRIBUTE_ALIGN(v) __attribute__((aligned(v))) - -#define _sync() asm volatile("sync") -#define _nop() asm volatile("nop") -#define ppcsync() asm volatile("sc") -#define ppchalt() ({ \ - asm volatile("sync"); \ - while(1) { \ - asm volatile("nop"); \ - asm volatile("li 3,0"); \ - asm volatile("nop"); \ - } \ -}) - -#define mfdcr(_rn) ({register u32 _rval; \ - asm volatile("mfdcr %0," __stringify(_rn) \ - : "=r" (_rval)); _rval;}) -#define mtdcr(rn, val) asm volatile("mtdcr " __stringify(rn) ",%0" : : "r" (val)) - -#define mfmsr() ({register u32 _rval; \ - asm volatile("mfmsr %0" : "=r" (_rval)); _rval;}) -#define mtmsr(val) asm volatile("mtmsr %0" : : "r" (val)) - -#define mfdec() ({register u32 _rval; \ - asm volatile("mfdec %0" : "=r" (_rval)); _rval;}) -#define mtdec(_val) asm volatile("mtdec %0" : : "r" (_val)) - -#define mfspr(_rn) \ -({ register u32 _rval = 0; \ - asm volatile("mfspr %0," __stringify(_rn) \ - : "=r" (_rval));\ - _rval; \ -}) - -#define mtspr(_rn, _val) asm volatile("mtspr " __stringify(_rn) ",%0" : : "r" (_val)) - -#define mfwpar() mfspr(WPAR) -#define mtwpar(_val) mtspr(WPAR,_val) - -#define mfmmcr0() mfspr(MMCR0) -#define mtmmcr0(_val) mtspr(MMCR0,_val) -#define mfmmcr1() mfspr(MMCR1) -#define mtmmcr1(_val) mtspr(MMCR1,_val) - -#define mfpmc1() mfspr(PMC1) -#define mtpmc1(_val) mtspr(PMC1,_val) -#define mfpmc2() mfspr(PMC2) -#define mtpmc2(_val) mtspr(PMC2,_val) -#define mfpmc3() mfspr(PMC3) -#define mtpmc3(_val) mtspr(PMC3,_val) -#define mfpmc4() mfspr(PMC4) -#define mtpmc4(_val) mtspr(PMC4,_val) - -#define mfhid0() mfspr(HID0) -#define mthid0(_val) mtspr(HID0,_val) -#define mfhid1() mfspr(HID1) -#define mthid1(_val) mtspr(HID1,_val) -#define mfhid2() mfspr(HID2) -#define mthid2(_val) mtspr(HID2,_val) -#define mfhid4() mfspr(HID4) -#define mthid4(_val) mtspr(HID4,_val) - -#define cntlzw(_val) ({register u32 _rval; \ - asm volatile("cntlzw %0, %1" : "=r"((_rval)) : "r"((_val))); _rval;}) - -#define _CPU_MSR_GET( _msr_value ) \ - do { \ - _msr_value = 0; \ - asm volatile ("mfmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); \ - } while (0) - -#define _CPU_MSR_SET( _msr_value ) \ -{ asm volatile ("mtmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); } - -#define _CPU_ISR_Enable() \ - { register u32 _val = 0; \ - asm volatile ("mfmsr %0; ori %0,%0,0x8000; mtmsr %0" : \ - "=&r" (_val) : "0" (_val));\ - } - -#define _CPU_ISR_Disable( _isr_cookie ) \ - { register u32 _disable_mask = MSR_EE; \ - _isr_cookie = 0; \ - asm volatile ( \ - "mfmsr %0; andc %1,%0,%1; mtmsr %1" : \ - "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) : \ - "0" ((_isr_cookie)), "1" ((_disable_mask)) \ - ); \ - } - -#define _CPU_ISR_Restore( _isr_cookie ) \ - { \ - asm volatile ( "mtmsr %0" : \ - "=r" ((_isr_cookie)) : \ - "0" ((_isr_cookie))); \ - } - -#define _CPU_ISR_Flash( _isr_cookie ) \ - { register u32 _disable_mask = MSR_EE; \ - asm volatile ( \ - "mtmsr %0; andc %1,%0,%1; mtmsr %1" : \ - "=r" ((_isr_cookie)), "=r" ((_disable_mask)) : \ - "0" ((_isr_cookie)), "1" ((_disable_mask)) \ - ); \ - } - -#endif diff --git a/sdelfloader/loader/source/sdio.c b/sdelfloader/loader/source/sdio.c deleted file mode 100644 index a863012..0000000 --- a/sdelfloader/loader/source/sdio.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (C) 2008 svpe, #wiidev at efnet - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -// pretty much everything here has been reversed from the twilight hack elf loader -// my implementation is *really* bad and will fail fail in random situations. -// it should not be used anywhere else. i recommend waiting for the libogc update. -// you have been warned.... - -#include - -#include -#include -#include - -static char *sd_path __attribute__((aligned(32))) = "/dev/sdio/slot0"; -static s32 sd_fd = -1; - -static u32 status __attribute__((aligned(32))); - -s32 sd_send_cmd(u32 cmd, u32 type, u32 resp, u32 arg, u32 blocks, u32 bsize, u32 addr) -{ - static u32 request[9] __attribute__((aligned(32))); - static u32 reply[4] __attribute__((aligned(32))); - u32 r; - - memset(request, 0, sizeof(request)); - memset(reply, 0, sizeof(reply)); - - request[0] = cmd; - request[1] = type; - request[2] = resp; - request[3] = arg; - request[4] = blocks; - request[5] = bsize; - request[6] = addr; -// request[7] = 0; -// request[8] = 0; - - r = IOS_Ioctl(sd_fd, 7, (u8 *)request, 36, (u8 *)reply, 0x10); -// printf("sd_send_cmd(%x, %x, %x, %x, %x, %x, %x) = %d", cmd, type, resp, arg, blocks, bsize, addr, r); -// printf(" -> %x %x %x %x\n", reply[0], reply[1], reply[2], reply[3]); // TODO: add some argument for this reply - - return r; -} - -s32 sd_reset() -{ - s32 r; - - r = IOS_Ioctl(sd_fd, 4, 0, 0, (u8 *)&status, 4); -// printf("sd_reset(): r = %d; status = %d\n", r, status); - return r; -} - -s32 sd_select() -{ - s32 r; - - r = sd_send_cmd(7, 3, 2, status & 0xFFFF0000, 0, 0, 0); -// printf("sd_select(): r = %d\n", r); - return r; -} - -s32 sd_set_blocklen(u32 len) -{ - s32 r; - - r = sd_send_cmd(0x10, 3, 1, len, 0, 0, 0); -// printf("sd_set_blocklen(%x) = %d\n", len, r); - return r; -} - -u8 sd_get_hcreg() -{ - s32 r; - static u32 data __attribute__((aligned(32))); - static u32 query[6] __attribute__((aligned(32))); - - memset(&data, 0, 4); - memset(query, 0, 0x18); - - query[0] = 0x28; - query[3] = 1; -// query[4] = 0; - - r = IOS_Ioctl(sd_fd, 2, (u8 *)query, 0x18, (u8 *)&data, 4); -// printf("sd_get_hcreg() = %d; r = %d\n", data & 0xFF, r); - return data & 0xFF; -} - -s32 sd_set_hcreg(u8 value) -{ - s32 r; - static u32 query[6] __attribute__((aligned(32))); - - memset(query, 0, 0x18); - - query[0] = 0x28; - query[3] = 1; - query[4] = value; - - r = IOS_Ioctl(sd_fd, 1, (u8 *)query, 0x18, 0, 0); -// printf("sd_set_hcreg(%d) = %d\n", value, r); - return r; -} - -s32 sd_set_buswidth(u8 w) -{ - s32 r; - u8 reg; - - r = sd_send_cmd(0x37, 3, 1, status & 0xFFFF0000, 0, 0, 0); - if(r < 0) - return r; - r = sd_send_cmd(6, 3, 1, (w == 4 ? 2 : 0), 0, 0, 0); - if(r < 0) - return r; - - reg = sd_get_hcreg(); - - reg &= ~2; - if(w == 4) - reg |= 2; - return sd_set_hcreg(reg); -} - -s32 sd_clock() -{ - s32 r; - static u32 c __attribute__((aligned(32))); - - c = 1; - r = IOS_Ioctl(sd_fd, 6, &c, 4, 0, 0); -// printf("sd_clock() = %d\n", r); - return r; -} - -s32 sd_read(u32 n, u8 *buf) -{ - s32 r; - static u8 buffer[0x200] __attribute__((aligned(32))); - static u32 query[9] __attribute__((aligned(32))); - static u32 res[4] __attribute__((aligned(32))); - - static ioctlv v[3] __attribute__((aligned(32))); - -// printf("sd_read(%d) called\n", n); - - memset(buffer, 0xAA, 0x200); // why is this buffer filled with 0xAA? is this really needed? - memset(query, 0, 0x24); - memset(res, 0, 0x10); - - query[0] = 0x12; - query[1] = 3; - query[2] = 1; - query[3] = n * 0x200; // arg - query[4] = 1; // block_count - query[5] = 0x200; // sector size - query[6] = (u32)buffer; // buffer - query[7] = 1; // ? - query[8] = 0; // ? - - v[0].data = (u32 *)query; - v[0].len = 0x24; - v[1].data =(u32 *)buffer; - v[1].len = 0x200; - v[2].data = (u32 *)res; - v[2].len = 0x10; - - r = IOS_Ioctlv(sd_fd, 7, 2, 1, v); - - if(r != 0) - { - printf("sd_read() = %d\n", r); - printf(" %x %x %x %x\n", res[0], res[1], res[2], res[3]); - return r; - } - - memcpy(buf, buffer, 0x200); - - return 0; -} - -s32 sd_init() -{ - s32 r; - - if(sd_fd > 0) - { -// printf("sd_init() called more than once. using old sd_fd: %d\n", sd_fd); - return 0; - } - - sd_fd = IOS_Open(sd_path, 0); -// printf("sd_fd = %d\n", sd_fd); - if(sd_fd < 0) - return sd_fd; - - - // TODO: close sd_fd on failure and do proper error check here - r = sd_reset(); - if(r < 0) - return r; - - sd_select(); - r = sd_set_blocklen(0x200); - if(r < 0) - return sd_fd; - r = sd_set_buswidth(4); - if(r < 0) - return sd_fd; - r = sd_clock(); - if(r < 0) - return sd_fd; - - return 0; - -} - -s32 sd_deinit() -{ - sd_reset(); - return IOS_Close(sd_fd); -} - - diff --git a/sdelfloader/loader/source/sdio.h b/sdelfloader/loader/source/sdio.h deleted file mode 100644 index df717d2..0000000 --- a/sdelfloader/loader/source/sdio.h +++ /dev/null @@ -1,4 +0,0 @@ -extern s32 sd_read(u32 n, u8 *buf); -extern s32 sd_init(); -extern s32 sd_deinit(); - diff --git a/sdelfloader/loader/source/tff.c b/sdelfloader/loader/source/tff.c deleted file mode 100644 index 0dcb07c..0000000 --- a/sdelfloader/loader/source/tff.c +++ /dev/null @@ -1,1710 +0,0 @@ -/*--------------------------------------------------------------------------/ -/ FatFs - Tiny FAT file system module R0.04b (C)ChaN, 2007 -/---------------------------------------------------------------------------/ -/ The FatFs module is an experimenal project to implement FAT file system to -/ cheap microcontrollers. This is a free software and is opened for education, -/ research and development under license policy of following trems. -/ -/ Copyright (C) 2007, ChaN, all right reserved. -/ -/ * The FatFs module is a free software and there is no warranty. -/ * You can use, modify and/or redistribute it for personal, non-profit or -/ profit use without any restriction under your responsibility. -/ * Redistributions of source code must retain the above copyright notice. -/ -/---------------------------------------------------------------------------/ -/ Feb 26, 2006 R0.00 Prototype. -/ Apr 29, 2006 R0.01 First stable version. -/ Jun 01, 2006 R0.02 Added FAT12 support. -/ Removed unbuffered mode. -/ Fixed a problem on small (<32M) patition. -/ Jun 10, 2006 R0.02a Added a configuration option (_FS_MINIMUM). -/ Sep 22, 2006 R0.03 Added f_rename(). -/ Changed option _FS_MINIMUM to _FS_MINIMIZE. -/ Dec 09, 2006 R0.03a Improved cluster scan algolithm to write files fast. -/ Feb 04, 2007 R0.04 Added FAT32 supprt. -/ Changed some interfaces incidental to FatFs. -/ Changed f_mountdrv() to f_mount(). -/ Apr 01, 2007 R0.04a Added a capability of extending file size to f_lseek(). -/ Added minimization level 3. -/ Fixed a problem in FAT32 support. -/ May 05, 2007 R0.04b Added a configuration option _USE_NTFLAG. -/ Added FSInfo support. -/ Fixed some problems corresponds to FAT32 support. -/ Fixed DBCS name can result FR_INVALID_NAME. -/ Fixed short seek (<= csize) collapses the file object. -/---------------------------------------------------------------------------*/ - -#include -#include "tff.h" /* Tiny-FatFs declarations */ -#include "diskio.h" /* Include file for user provided disk functions */ - -typedef enum { FALSE = 0, TRUE } BOOL; - -static -FATFS *FatFs; /* Pointer to the file system objects (logical drive) */ -static -WORD fsid; /* File system mount ID */ - - -/*------------------------------------------------------------------------- - - Module Private Functions - --------------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* Change window offset */ -/*-----------------------------------------------------------------------*/ - -static -BOOL move_window ( /* TRUE: successful, FALSE: failed */ - DWORD sector /* Sector number to make apperance in the FatFs->win */ -) /* Move to zero only writes back dirty window */ -{ - DWORD wsect; - FATFS *fs = FatFs; - - - wsect = fs->winsect; - if (wsect != sector) - { /* Changed current window */ -#if !_FS_READONLY - BYTE n; - if (fs->winflag) - { /* Write back dirty window if needed */ - if (disk_write(0, fs->win, wsect, 1) != RES_OK) - return FALSE; - fs->winflag = 0; - if (wsect < (fs->fatbase + fs->sects_fat)) - { /* In FAT area */ - for (n = fs->n_fats; n >= 2; n--) - { /* Refrect the change to all FAT copies */ - wsect += fs->sects_fat; - disk_write(0, fs->win, wsect, 1); - } - } - } -#endif - if (sector) - { - if (disk_read(0, fs->win, sector, 1) != RES_OK) - return FALSE; - fs->winsect = sector; - } - } - return TRUE; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Clean-up cached data */ -/*-----------------------------------------------------------------------*/ - -#if !_FS_READONLY -static -FRESULT sync (void) /* FR_OK: successful, FR_RW_ERROR: failed */ -{ - FATFS *fs = FatFs; - - - fs->winflag = 1; - if (!move_window(0)) return FR_RW_ERROR; -#if _USE_FSINFO - if (fs->fs_type == FS_FAT32 && fs->fsi_flag) - { /* Update FSInfo sector if needed */ - fs->winsect = 0; - memset(fs->win, 0, 512); - ST_WORD(&fs->win[BS_55AA], 0xAA55); - ST_DWORD(&fs->win[FSI_LeadSig], 0x41615252); - ST_DWORD(&fs->win[FSI_StrucSig], 0x61417272); - ST_DWORD(&fs->win[FSI_Free_Count], fs->free_clust); - ST_DWORD(&fs->win[FSI_Nxt_Free], fs->last_clust); - disk_write(0, fs->win, fs->fsi_sector, 1); - fs->fsi_flag = 0; - } -#endif - if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK) return FR_RW_ERROR; - return FR_OK; -} -#endif - - - - -/*-----------------------------------------------------------------------*/ -/* Get a cluster status */ -/*-----------------------------------------------------------------------*/ - -static -CLUST get_cluster ( /* 0,>=2: successful, 1: failed */ - CLUST clust /* Cluster# to get the link information */ -) -{ - WORD wc, bc; - DWORD fatsect; - FATFS *fs = FatFs; - - - if (clust >= 2 && clust < fs->max_clust) - { /* Valid cluster# */ - fatsect = fs->fatbase; - switch (fs->fs_type) - { - case FS_FAT12 : - bc = (WORD)clust * 3 / 2; - if (!move_window(fatsect + bc / 512)) break; - wc = fs->win[bc % 512]; - bc++; - if (!move_window(fatsect + bc / 512)) break; - wc |= (WORD)fs->win[bc % 512] << 8; - return (clust & 1) ? (wc >> 4) : (wc & 0xFFF); - - case FS_FAT16 : - if (!move_window(fatsect + clust / 256)) break; - return LD_WORD(&fs->win[((WORD)clust * 2) % 512]); -#if _FAT32 - case FS_FAT32 : - if (!move_window(fatsect + clust / 128)) break; - return LD_DWORD(&fs->win[((WORD)clust * 4) % 512]) & 0x0FFFFFFF; -#endif - } - } - - return 1; /* There is no cluster information, or an error occured */ -} - - - - -/*-----------------------------------------------------------------------*/ -/* Change a cluster status */ -/*-----------------------------------------------------------------------*/ - -#if !_FS_READONLY -static -BOOL put_cluster ( /* TRUE: successful, FALSE: failed */ - CLUST clust, /* Cluster# to change */ - CLUST val /* New value to mark the cluster */ -) -{ - WORD bc; - BYTE *p; - DWORD fatsect; - FATFS *fs = FatFs; - - - fatsect = fs->fatbase; - switch (fs->fs_type) - { - case FS_FAT12 : - bc = (WORD)clust * 3 / 2; - if (!move_window(fatsect + bc / 512)) return FALSE; - p = &fs->win[bc % 512]; - *p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; - bc++; - fs->winflag = 1; - if (!move_window(fatsect + bc / 512)) return FALSE; - p = &fs->win[bc % 512]; - *p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); - break; - - case FS_FAT16 : - if (!move_window(fatsect + clust / 256)) return FALSE; - ST_WORD(&fs->win[((WORD)clust * 2) % 512], (WORD)val); - break; -#if _FAT32 - case FS_FAT32 : - if (!move_window(fatsect + clust / 128)) return FALSE; - ST_DWORD(&fs->win[((WORD)clust * 4) % 512], val); - break; -#endif - default : - return FALSE; - } - fs->winflag = 1; - return TRUE; -} -#endif /* !_FS_READONLY */ - - - - -/*-----------------------------------------------------------------------*/ -/* Remove a cluster chain */ -/*-----------------------------------------------------------------------*/ - -#if !_FS_READONLY -static -BOOL remove_chain ( /* TRUE: successful, FALSE: failed */ - CLUST clust /* Cluster# to remove chain from */ -) -{ - CLUST nxt; - FATFS *fs = FatFs; - - - while (clust >= 2 && clust < fs->max_clust) - { - nxt = get_cluster(clust); - if (nxt == 1) return FALSE; - if (!put_cluster(clust, 0)) return FALSE; - if (fs->free_clust != (CLUST)0xFFFFFFFF) - { - fs->free_clust++; -#if _USE_FSINFO - fs->fsi_flag = 1; -#endif - } - clust = nxt; - } - return TRUE; -} -#endif - - - - -/*-----------------------------------------------------------------------*/ -/* Stretch or create a cluster chain */ -/*-----------------------------------------------------------------------*/ - -#if !_FS_READONLY -static -CLUST create_chain ( /* 0: no free cluster, 1: error, >=2: new cluster number */ - CLUST clust /* Cluster# to stretch, 0 means create new */ -) -{ - CLUST cstat, ncl, scl, mcl; - FATFS *fs = FatFs; - - - mcl = fs->max_clust; - if (clust == 0) - { /* Create new chain */ - scl = fs->last_clust; /* Get last allocated cluster */ - if (scl < 2 || scl >= mcl) scl = 1; - } - else - { /* Stretch existing chain */ - cstat = get_cluster(clust); /* Check the cluster status */ - if (cstat < 2) return 1; /* It is an invalid cluster */ - if (cstat < mcl) return cstat; /* It is already followed by next cluster */ - scl = clust; - } - - ncl = scl; /* Start cluster */ - for (;;) - { - ncl++; /* Next cluster */ - if (ncl >= mcl) - { /* Wrap around */ - ncl = 2; - if (ncl > scl) return 0; /* No free custer */ - } - cstat = get_cluster(ncl); /* Get the cluster status */ - if (cstat == 0) break; /* Found a free cluster */ - if (cstat == 1) return 1; /* Any error occured */ - if (ncl == scl) return 0; /* No free custer */ - } - - if (!put_cluster(ncl, (CLUST)0x0FFFFFFF)) return 1; /* Mark the new cluster "in use" */ - if (clust && !put_cluster(clust, ncl)) return 1; /* Link it to previous one if needed */ - - fs->last_clust = ncl; /* Update fsinfo */ - if (fs->free_clust != (CLUST)0xFFFFFFFF) - { - fs->free_clust--; -#if _USE_FSINFO - fs->fsi_flag = 1; -#endif - } - - return ncl; /* Return new cluster number */ -} -#endif /* !_FS_READONLY */ - - - - -/*-----------------------------------------------------------------------*/ -/* Get sector# from cluster# */ -/*-----------------------------------------------------------------------*/ - -static -DWORD clust2sect ( /* !=0: sector number, 0: failed - invalid cluster# */ - CLUST clust /* Cluster# to be converted */ -) -{ - FATFS *fs = FatFs; - - - clust -= 2; - if (clust >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */ - return (DWORD)clust * fs->sects_clust + fs->database; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Move directory pointer to next */ -/*-----------------------------------------------------------------------*/ - -static -BOOL next_dir_entry ( /* TRUE: successful, FALSE: could not move next */ - DIR *dirobj /* Pointer to directory object */ -) -{ - CLUST clust; - WORD idx; - FATFS *fs = FatFs; - - - idx = dirobj->index + 1; - if ((idx & 15) == 0) - { /* Table sector changed? */ - dirobj->sect++; /* Next sector */ - if (!dirobj->clust) - { /* In static table */ - if (idx >= fs->n_rootdir) return FALSE; /* Reached to end of table */ - } - else - { /* In dynamic table */ - if (((idx / 16) & (fs->sects_clust - 1)) == 0) - { /* Cluster changed? */ - clust = get_cluster(dirobj->clust); /* Get next cluster */ - if (clust < 2 || clust >= fs->max_clust) /* Reached to end of table */ - return FALSE; - dirobj->clust = clust; /* Initialize for new cluster */ - dirobj->sect = clust2sect(clust); - } - } - } - dirobj->index = idx; /* Lower 4 bit of dirobj->index indicates offset in dirobj->sect */ - return TRUE; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Get file status from directory entry */ -/*-----------------------------------------------------------------------*/ - -#if _FS_MINIMIZE <= 1 -static -void get_fileinfo ( /* No return code */ - FILINFO *finfo, /* Ptr to store the File Information */ - const BYTE *dir /* Ptr to the directory entry */ -) -{ - BYTE n, c, a; - char *p; - - - p = &finfo->fname[0]; - a = _USE_NTFLAG ? dir[DIR_NTres] : 0; /* NT flag */ - for (n = 0; n < 8; n++) - { /* Convert file name (body) */ - c = dir[n]; - if (c == ' ') break; - if (c == 0x05) c = 0xE5; - if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20; - *p++ = c; - } - if (dir[8] != ' ') - { /* Convert file name (extension) */ - *p++ = '.'; - for (n = 8; n < 11; n++) - { - c = dir[n]; - if (c == ' ') break; - if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20; - *p++ = c; - } - } - *p = '\0'; - - finfo->fattrib = dir[DIR_Attr]; /* Attribute */ - finfo->fsize = LD_DWORD(&dir[DIR_FileSize]); /* Size */ - finfo->fdate = LD_WORD(&dir[DIR_WrtDate]); /* Date */ - finfo->ftime = LD_WORD(&dir[DIR_WrtTime]); /* Time */ -} -#endif /* _FS_MINIMIZE <= 1 */ - - - - -/*-----------------------------------------------------------------------*/ -/* Pick a paragraph and create the name in format of directory entry */ -/*-----------------------------------------------------------------------*/ - -static -char make_dirfile ( /* 1: error - detected an invalid format, '\0'or'/': next character */ - const char **path, /* Pointer to the file path pointer */ - char *dirname /* Pointer to directory name buffer {Name(8), Ext(3), NT flag(1)} */ -) -{ - BYTE n, t, c, a, b; - - - memset(dirname, ' ', 8+3); /* Fill buffer with spaces */ - a = 0; - b = 0x18; /* NT flag */ - n = 0; - t = 8; - for (;;) - { - c = *(*path)++; - if (c == '\0' || c == '/') - { /* Reached to end of str or directory separator */ - if (n == 0) break; - dirname[11] = _USE_NTFLAG ? (a & b) : 0; - return c; - } - if (c <= ' ' || c == 0x7F) break; /* Reject invisible chars */ - if (c == '.') - { - if (!(a & 1) && n >= 1 && n <= 8) - { /* Enter extension part */ - n = 8; - t = 11; - continue; - } - break; - } - if (_USE_SJIS && - ((c >= 0x81 && c <= 0x9F) || /* Accept S-JIS code */ - (c >= 0xE0 && c <= 0xFC))) - { - if (n == 0 && c == 0xE5) /* Change heading \xE5 to \x05 */ - c = 0x05; - a ^= 1; - goto md_l2; - } - if (c == '"') break; /* Reject " */ - if (c <= ')') goto md_l1; /* Accept ! # $ % & ' ( ) */ - if (c <= ',') break; /* Reject * + , */ - if (c <= '9') goto md_l1; /* Accept - 0-9 */ - if (c <= '?') break; /* Reject : ; < = > ? */ - if (!(a & 1)) - { /* These checks are not applied to S-JIS 2nd byte */ - if (c == '|') break; /* Reject | */ - if (c >= '[' && c <= ']') break;/* Reject [ \ ] */ - if (_USE_NTFLAG && c >= 'A' && c <= 'Z') - (t == 8) ? (b &= ~0x08) : (b &= ~0x10); - if (c >= 'a' && c <= 'z') - { /* Convert to upper case */ - c -= 0x20; - if (_USE_NTFLAG) (t == 8) ? (a |= 0x08) : (a |= 0x10); - } - } -md_l1: - a &= ~1; -md_l2: - if (n >= t) break; - dirname[n++] = c; - } - return 1; -} - - - -/*-----------------------------------------------------------------------*/ -/* Trace a file path */ -/*-----------------------------------------------------------------------*/ - -static -FRESULT trace_path ( /* FR_OK(0): successful, !=0: error code */ - DIR *dirobj, /* Pointer to directory object to return last directory */ - char *fn, /* Pointer to last segment name to return */ - const char *path, /* Full-path string to trace a file or directory */ - BYTE **dir /* Directory pointer in Win[] to retutn */ -) -{ - CLUST clust; - char ds; - BYTE *dptr = NULL; - FATFS *fs = FatFs; - - /* Initialize directory object */ - clust = fs->dirbase; -#if _FAT32 - if (fs->fs_type == FS_FAT32) - { - dirobj->clust = dirobj->sclust = clust; - dirobj->sect = clust2sect(clust); - } - else -#endif - { - dirobj->clust = dirobj->sclust = 0; - dirobj->sect = clust; - } - dirobj->index = 0; - dirobj->fs = fs; - - if (*path == '\0') - { /* Null path means the root directory */ - *dir = NULL; - return FR_OK; - } - - for (;;) - { - ds = make_dirfile(&path, fn); /* Get a paragraph into fn[] */ - if (ds == 1) return FR_INVALID_NAME; - for (;;) - { - if (!move_window(dirobj->sect)) return FR_RW_ERROR; - dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */ - if (dptr[DIR_Name] == 0) /* Has it reached to end of dir? */ - return !ds ? FR_NO_FILE : FR_NO_PATH; - if (dptr[DIR_Name] != 0xE5 /* Matched? */ - && !(dptr[DIR_Attr] & AM_VOL) - && !memcmp(&dptr[DIR_Name], fn, 8+3) ) break; - if (!next_dir_entry(dirobj)) /* Next directory pointer */ - return !ds ? FR_NO_FILE : FR_NO_PATH; - } - if (!ds) - { - *dir = dptr; - return FR_OK; - } /* Matched with end of path */ - if (!(dptr[DIR_Attr] & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */ - clust = /* Get cluster# of the directory */ -#if _FAT32 - ((DWORD)LD_WORD(&dptr[DIR_FstClusHI]) << 16) | -#endif - LD_WORD(&dptr[DIR_FstClusLO]); - dirobj->clust = dirobj->sclust = clust; /* Restart scannig with the new directory */ - dirobj->sect = clust2sect(clust); - dirobj->index = 2; - } -} - - - -/*-----------------------------------------------------------------------*/ -/* Reserve a directory entry */ -/*-----------------------------------------------------------------------*/ - -#if !_FS_READONLY -static -FRESULT reserve_direntry ( /* FR_OK: successful, FR_DENIED: no free entry, FR_RW_ERROR: a disk error occured */ - DIR *dirobj, /* Target directory to create new entry */ - BYTE **dir /* Pointer to pointer to created entry to retutn */ -) -{ - CLUST clust; - DWORD sector; - BYTE c, n, *dptr; - FATFS *fs = FatFs; - - - /* Re-initialize directory object */ - clust = dirobj->sclust; - if (clust) - { /* Dyanmic directory table */ - dirobj->clust = clust; - dirobj->sect = clust2sect(clust); - } - else - { /* Static directory table */ - dirobj->sect = fs->dirbase; - } - dirobj->index = 0; - - do - { - if (!move_window(dirobj->sect)) return FR_RW_ERROR; - dptr = &fs->win[(dirobj->index & 15) * 32]; /* Pointer to the directory entry */ - c = dptr[DIR_Name]; - if (c == 0 || c == 0xE5) - { /* Found an empty entry! */ - *dir = dptr; - return FR_OK; - } - } - while (next_dir_entry(dirobj)); /* Next directory pointer */ - /* Reached to end of the directory table */ - - /* Abort when static table or could not stretch dynamic table */ - if (!clust || !(clust = create_chain(dirobj->clust))) return FR_DENIED; - if (clust == 1 || !move_window(0)) return FR_RW_ERROR; - - fs->winsect = sector = clust2sect(clust); /* Cleanup the expanded table */ - memset(fs->win, 0, 512); - for (n = fs->sects_clust; n; n--) - { - if (disk_write(0, fs->win, sector, 1) != RES_OK) - return FR_RW_ERROR; - sector++; - } - fs->winflag = 1; - *dir = fs->win; - return FR_OK; -} -#endif /* !_FS_READONLY */ - - - - -/*-----------------------------------------------------------------------*/ -/* Load boot record and check if it is a FAT boot record */ -/*-----------------------------------------------------------------------*/ - -static -BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record or error */ - DWORD sect /* Sector# to check if it is a FAT boot record or not */ -) -{ - FATFS *fs = FatFs; - - if (disk_read(0, fs->win, sect, 1) != RES_OK) /* Load boot record */ - return 2; - if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */ - return 2; - - if (!memcmp(&fs->win[BS_FilSysType], "FAT", 3)) /* Check FAT signature */ - return 0; -#if _FAT32 - if (!memcmp(&fs->win[BS_FilSysType32], "FAT32", 5) && !(fs->win[BPB_ExtFlags] & 0x80)) - return 0; -#endif - return 1; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Make sure that the file system is valid */ -/*-----------------------------------------------------------------------*/ - -static -FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */ - const char **path, /* Pointer to pointer to the path name (drive number) */ - BYTE chk_wp /* !=0: Check media write protection for wrinting fuctions */ -) -{ - BYTE fmt; - DSTATUS stat; - DWORD bootsect, fatsize, totalsect, maxclust; - const char *p = *path; - FATFS *fs = FatFs; - - - - while (*p == ' ') p++; /* Strip leading spaces */ - if (*p == '/') p++; /* Strip heading slash */ - *path = p; /* Return pointer to the path name */ - - /* Is the file system object registered? */ - if (!fs) return FR_NOT_ENABLED; - - /* Chekck if the logical drive has been mounted or not */ - if (fs->fs_type) - { - stat = disk_status(0); - if (!(stat & STA_NOINIT)) - { /* If the physical drive is kept initialized */ -#if !_FS_READONLY - if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */ - return FR_WRITE_PROTECTED; -#endif - return FR_OK; /* The file system object is valid */ - } - } - - /* The logical drive has not been mounted, following code attempts to mount the logical drive */ - - memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */ - stat = disk_initialize(0); /* Initialize low level disk I/O layer */ - if (stat & STA_NOINIT) /* Check if the drive is ready */ - return FR_NOT_READY; -#if !_FS_READONLY - if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */ - return FR_WRITE_PROTECTED; -#endif - - /* Search FAT partition on the drive */ - fmt = check_fs(bootsect = 0); /* Check sector 0 as an SFD format */ - if (fmt == 1) - { /* Not a FAT boot record, it may be patitioned */ - /* Check a partition listed in top of the partition table */ - if (fs->win[MBR_Table+4]) - { /* Is the 1st partition existing? */ - bootsect = LD_DWORD(&fs->win[MBR_Table+8]); /* Partition offset in LBA */ - fmt = check_fs(bootsect); /* Check the partition */ - } - } - if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512) /* No valid FAT patition is found */ - return FR_NO_FILESYSTEM; - - /* Initialize the file system object */ - fatsize = LD_WORD(&fs->win[BPB_FATSz16]); /* Number of sectors per FAT */ - if (!fatsize) fatsize = LD_DWORD(&fs->win[BPB_FATSz32]); - fs->sects_fat = (CLUST)fatsize; - fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */ - fatsize *= fs->n_fats; /* (Number of sectors in FAT area) */ - fs->fatbase = bootsect + LD_WORD(&fs->win[BPB_RsvdSecCnt]); /* FAT start sector (lba) */ - fs->sects_clust = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */ - fs->n_rootdir = LD_WORD(&fs->win[BPB_RootEntCnt]); /* Nmuber of root directory entries */ - totalsect = LD_WORD(&fs->win[BPB_TotSec16]); /* Number of sectors on the file system */ - if (!totalsect) totalsect = LD_DWORD(&fs->win[BPB_TotSec32]); - fs->max_clust = maxclust = (totalsect /* Last cluster# + 1 */ - - LD_WORD(&fs->win[BPB_RsvdSecCnt]) - fatsize - fs->n_rootdir / 16 - ) / fs->sects_clust + 2; - - fmt = FS_FAT12; /* Determine the FAT sub type */ - if (maxclust > 0xFF7) fmt = FS_FAT16; - if (maxclust > 0xFFF7) -#if !_FAT32 - return FR_NO_FILESYSTEM; -#else - fmt = FS_FAT32; - if (fmt == FS_FAT32) - fs->dirbase = LD_DWORD(&fs->win[BPB_RootClus]); /* Root directory start cluster */ - else -#endif - fs->dirbase = fs->fatbase + fatsize; /* Root directory start sector (lba) */ - fs->database = fs->fatbase + fatsize + fs->n_rootdir / 16; /* Data start sector (lba) */ - fs->fs_type = fmt; /* FAT sub-type */ - -#if !_FS_READONLY - fs->free_clust = (CLUST)0xFFFFFFFF; -#if _USE_FSINFO - /* Load fsinfo sector if needed */ - if (fmt == FS_FAT32) - { - fs->fsi_sector = bootsect + LD_WORD(&fs->win[BPB_FSInfo]); - if (disk_read(0, fs->win, fs->fsi_sector, 1) == RES_OK && - LD_WORD(&fs->win[BS_55AA]) == 0xAA55 && - LD_DWORD(&fs->win[FSI_LeadSig]) == 0x41615252 && - LD_DWORD(&fs->win[FSI_StrucSig]) == 0x61417272) - { - fs->last_clust = LD_DWORD(&fs->win[FSI_Nxt_Free]); - fs->free_clust = LD_DWORD(&fs->win[FSI_Free_Count]); - } - } -#endif -#endif - fs->id = ++fsid; /* File system mount ID */ - return FR_OK; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Check if the file/dir object is valid or not */ -/*-----------------------------------------------------------------------*/ - -static -FRESULT validate ( /* FR_OK(0): The id is valid, !=0: Not valid */ - const FATFS *fs, /* Pointer to the file system object */ - WORD id /* id member of the target object to be checked */ -) -{ - if (!fs || fs->id != id) - return FR_INVALID_OBJECT; - if (disk_status(0) & STA_NOINIT) - return FR_NOT_READY; - - return FR_OK; -} - - - - -/*-------------------------------------------------------------------------- - - Public Functions - ---------------------------------------------------------------------------*/ - - -/*-----------------------------------------------------------------------*/ -/* Mount/Unmount a Locical Drive */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_mount ( - BYTE drv, /* Logical drive number to be mounted/unmounted */ - FATFS *fs /* Pointer to new file system object (NULL for unmount)*/ -) -{ - FATFS *fsobj; - - - if (drv) return FR_INVALID_DRIVE; - fsobj = FatFs; - FatFs = fs; - if (fsobj) memset(fsobj, 0, sizeof(FATFS)); - if (fs) memset(fs, 0, sizeof(FATFS)); - - return FR_OK; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Open or Create a File */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_open ( - FIL *fp, /* Pointer to the blank file object */ - const char *path, /* Pointer to the file name */ - BYTE mode /* Access mode and file open mode flags */ -) -{ - FRESULT res; - BYTE *dir; - DIR dirobj; - char fn[8+3+1]; - FATFS *fs = FatFs; - - - fp->fs = NULL; -#if !_FS_READONLY - mode &= (FA_READ|FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW); - res = auto_mount(&path, (BYTE)(mode & (FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW))); -#else - mode &= FA_READ; - res = auto_mount(&path, 0); -#endif - if (res != FR_OK) return res; - - /* Trace the file path */ - res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */ - -#if !_FS_READONLY - /* Create or Open a File */ - if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS|FA_CREATE_NEW)) - { - CLUST rs; - DWORD dw; - if (res != FR_OK) - { /* No file, create new */ - if (res != FR_NO_FILE) return res; - res = reserve_direntry(&dirobj, &dir); - if (res != FR_OK) return res; - memset(dir, 0, 32); /* Initialize the new entry */ - memcpy(&dir[DIR_Name], fn, 8+3); - dir[DIR_NTres] = fn[11]; - mode |= FA_CREATE_ALWAYS; - } - else - { /* Any object is already existing */ - if (mode & FA_CREATE_NEW) /* Cannot create new */ - return FR_EXIST; - if (dir == NULL || (dir[DIR_Attr] & (AM_RDO|AM_DIR))) /* Cannot overwrite (R/O or DIR) */ - return FR_DENIED; - if (mode & FA_CREATE_ALWAYS) - { /* Resize it to zero */ -#if _FAT32 - rs = ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | LD_WORD(&dir[DIR_FstClusLO]); - ST_WORD(&dir[DIR_FstClusHI], 0); -#else - rs = LD_WORD(&dir[DIR_FstClusLO]); -#endif - ST_WORD(&dir[DIR_FstClusLO], 0); /* cluster = 0 */ - ST_DWORD(&dir[DIR_FileSize], 0); /* size = 0 */ - fs->winflag = 1; - dw = fs->winsect; /* Remove the cluster chain */ - if (!remove_chain(rs) || !move_window(dw)) - return FR_RW_ERROR; - fs->last_clust = rs - 1; /* Reuse the cluster hole */ - } - } - if (mode & FA_CREATE_ALWAYS) - { - dir[DIR_Attr] = AM_ARC; /* New attribute */ - dw = get_fattime(); - ST_DWORD(&dir[DIR_WrtTime], dw); /* Updated time */ - ST_DWORD(&dir[DIR_CrtTime], dw); /* Created time */ - fs->winflag = 1; - } - } - /* Open a File */ - else - { -#endif /* !_FS_READONLY */ - if (res != FR_OK) return res; /* Trace failed */ - if (dir == NULL || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */ - return FR_NO_FILE; -#if !_FS_READONLY - if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */ - return FR_DENIED; - } - - fp->dir_sect = fs->winsect; /* Pointer to the directory entry */ - fp->dir_ptr = dir; -#endif - fp->flag = mode; /* File access mode */ - fp->org_clust = /* File start cluster */ -#if _FAT32 - ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | -#endif - LD_WORD(&dir[DIR_FstClusLO]); - fp->fsize = LD_DWORD(&dir[DIR_FileSize]); /* File size */ - fp->fptr = 0; /* File ptr */ - fp->sect_clust = 1; /* Sector counter */ - fp->fs = fs; - fp->id = fs->id; /* Owner file system object of the file */ - - return FR_OK; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Read File */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_read ( - FIL *fp, /* Pointer to the file object */ - void *buff, /* Pointer to data buffer */ - WORD btr, /* Number of bytes to read */ - WORD *br /* Pointer to number of bytes read */ -) -{ - DWORD sect, remain; - WORD rcnt; - CLUST clust; - BYTE cc, *rbuff = buff; - FRESULT res; - FATFS *fs = fp->fs; - - - *br = 0; - res = validate(fs, fp->id); /* Check validity of the object */ - if (res) return res; - if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */ - if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */ - remain = fp->fsize - fp->fptr; - if (btr > remain) btr = (WORD)remain; /* Truncate read count by number of bytes left */ - - for ( ; btr; /* Repeat until all data transferred */ - rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) - { - if ((fp->fptr % 512) == 0) - { /* On the sector boundary */ - if (--fp->sect_clust) - { /* Decrement left sector counter */ - sect = fp->curr_sect + 1; /* Get current sector */ - } - else - { /* On the cluster boundary, get next cluster */ - clust = (fp->fptr == 0) ? - fp->org_clust : get_cluster(fp->curr_clust); - if (clust < 2 || clust >= fs->max_clust) - goto fr_error; - fp->curr_clust = clust; /* Current cluster */ - sect = clust2sect(clust); /* Get current sector */ - fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */ - } - fp->curr_sect = sect; /* Update current sector */ - cc = btr / 512; /* When left bytes >= 512, */ - if (cc) - { /* Read maximum contiguous sectors directly */ - if (cc > fp->sect_clust) cc = fp->sect_clust; - if (disk_read(0, rbuff, sect, cc) != RES_OK) - goto fr_error; - fp->sect_clust -= cc - 1; - fp->curr_sect += cc - 1; - rcnt = cc * 512; - continue; - } - } - if (!move_window(fp->curr_sect)) goto fr_error; /* Move sector window */ - rcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes from sector window */ - if (rcnt > btr) rcnt = btr; - memcpy(rbuff, &fs->win[(WORD)fp->fptr % 512], rcnt); - } - - return FR_OK; - -fr_error: /* Abort this function due to an unrecoverable error */ - fp->flag |= FA__ERROR; - return FR_RW_ERROR; -} - - - - -#if !_FS_READONLY -/*-----------------------------------------------------------------------*/ -/* Write File */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_write ( - FIL *fp, /* Pointer to the file object */ - const void *buff, /* Pointer to the data to be written */ - WORD btw, /* Number of bytes to write */ - WORD *bw /* Pointer to number of bytes written */ -) -{ - DWORD sect; - WORD wcnt; - CLUST clust; - BYTE cc; - FRESULT res; - const BYTE *wbuff = buff; - FATFS *fs = fp->fs; - - - *bw = 0; - res = validate(fs, fp->id); /* Check validity of the object */ - if (res) return res; - if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */ - if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */ - if (fp->fsize + btw < fp->fsize) return FR_OK; /* File size cannot reach 4GB */ - - for ( ; btw; /* Repeat until all data transferred */ - wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) - { - if ((fp->fptr % 512) == 0) - { /* On the sector boundary */ - if (--(fp->sect_clust)) - { /* Decrement left sector counter */ - sect = fp->curr_sect + 1; /* Get current sector */ - } - else - { /* On the cluster boundary, get next cluster */ - if (fp->fptr == 0) - { /* Is top of the file */ - clust = fp->org_clust; - if (clust == 0) /* No cluster is created yet */ - fp->org_clust = clust = create_chain(0); /* Create a new cluster chain */ - } - else - { /* Middle or end of file */ - clust = create_chain(fp->curr_clust); /* Trace or streach cluster chain */ - } - if (clust == 0) break; /* Disk full */ - if (clust == 1 || clust >= fs->max_clust) goto fw_error; - fp->curr_clust = clust; /* Current cluster */ - sect = clust2sect(clust); /* Get current sector */ - fp->sect_clust = fs->sects_clust; /* Re-initialize the left sector counter */ - } - fp->curr_sect = sect; /* Update current sector */ - cc = btw / 512; /* When left bytes >= 512, */ - if (cc) - { /* Write maximum contiguous sectors directly */ - if (cc > fp->sect_clust) cc = fp->sect_clust; - if (disk_write(0, wbuff, sect, cc) != RES_OK) - goto fw_error; - fp->sect_clust -= cc - 1; - fp->curr_sect += cc - 1; - wcnt = cc * 512; - continue; - } - if (fp->fptr >= fp->fsize) - { /* Flush R/W window if needed */ - if (!move_window(0)) goto fw_error; - fs->winsect = fp->curr_sect; - } - } - if (!move_window(fp->curr_sect)) /* Move sector window */ - goto fw_error; - wcnt = 512 - (WORD)(fp->fptr % 512); /* Copy fractional bytes bytes to sector window */ - if (wcnt > btw) wcnt = btw; - memcpy(&fs->win[(WORD)fp->fptr % 512], wbuff, wcnt); - fs->winflag = 1; - } - - if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */ - fp->flag |= FA__WRITTEN; /* Set file changed flag */ - return FR_OK; - -fw_error: /* Abort this function due to an unrecoverable error */ - fp->flag |= FA__ERROR; - return FR_RW_ERROR; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Synchronize between File and Disk */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_sync ( - FIL *fp /* Pointer to the file object */ -) -{ - DWORD tim; - BYTE *dir; - FRESULT res; - FATFS *fs = fp->fs; - - - res = validate(fs, fp->id); /* Check validity of the object */ - if (res == FR_OK) - { - if (fp->flag & FA__WRITTEN) - { /* Has the file been written? */ - /* Update the directory entry */ - if (!move_window(fp->dir_sect)) - return FR_RW_ERROR; - dir = fp->dir_ptr; - dir[DIR_Attr] |= AM_ARC; /* Set archive bit */ - ST_DWORD(&dir[DIR_FileSize], fp->fsize); /* Update file size */ - ST_WORD(&dir[DIR_FstClusLO], fp->org_clust); /* Update start cluster */ -#if _FAT32 - ST_WORD(&dir[DIR_FstClusHI], fp->org_clust >> 16); -#endif - tim = get_fattime(); /* Updated time */ - ST_DWORD(&dir[DIR_WrtTime], tim); - fp->flag &= ~FA__WRITTEN; - res = sync(); - } - } - return res; -} - -#endif /* !_FS_READONLY */ - - - - -/*-----------------------------------------------------------------------*/ -/* Close File */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_close ( - FIL *fp /* Pointer to the file object to be closed */ -) -{ - FRESULT res; - - -#if !_FS_READONLY - res = f_sync(fp); -#else - res = validate(fp->fs, fp->id); -#endif - if (res == FR_OK) - fp->fs = NULL; - - return res; -} - - - - -#if _FS_MINIMIZE <= 2 -/*-----------------------------------------------------------------------*/ -/* Seek File Pointer */ -/*-----------------------------------------------------------------------*/ -#if 0 -FRESULT f_lseek ( - FIL *fp, /* Pointer to the file object */ - DWORD ofs /* File pointer from top of file */ -) -{ - CLUST clust; - DWORD csize; - BYTE csect; - FRESULT res; - FATFS *fs = fp->fs; - - - res = validate(fs, fp->id); /* Check validity of the object */ - if (res) return res; - - if (fp->flag & FA__ERROR) return FR_RW_ERROR; -#if !_FS_READONLY - if (ofs > fp->fsize && !(fp->flag & FA_WRITE)) -#else - if (ofs > fp->fsize) -#endif - ofs = fp->fsize; - fp->fptr = 0; - fp->sect_clust = 1; /* Set file R/W pointer to top of the file */ - - /* Move file R/W pointer if needed */ - if (ofs) - { - clust = fp->org_clust; /* Get start cluster */ -#if !_FS_READONLY - if (!clust) - { /* If the file does not have a cluster chain, create new cluster chain */ - clust = create_chain(0); - if (clust == 1) goto fk_error; - fp->org_clust = clust; - } -#endif - if (clust) - { /* If the file has a cluster chain, it can be followed */ - csize = (DWORD)fs->sects_clust * 512; /* Cluster size in unit of byte */ - for (;;) - { /* Loop to skip leading clusters */ - fp->curr_clust = clust; /* Update current cluster */ - if (ofs <= csize) break; -#if !_FS_READONLY - if (fp->flag & FA_WRITE) /* Check if in write mode or not */ - clust = create_chain(clust); /* Force streached if in write mode */ - else -#endif - clust = get_cluster(clust); /* Only follow cluster chain if not in write mode */ - if (clust == 0) - { /* Stop if could not follow the cluster chain */ - ofs = csize; - break; - } - if (clust == 1 || clust >= fs->max_clust) goto fk_error; - fp->fptr += csize; /* Update R/W pointer */ - ofs -= csize; - } - csect = (BYTE)((ofs - 1) / 512); /* Sector offset in the cluster */ - fp->curr_sect = clust2sect(clust) + csect; /* Current sector */ - fp->sect_clust = fs->sects_clust - csect; /* Left sector counter in the cluster */ - fp->fptr += ofs; /* Update file R/W pointer */ - } - } -#if !_FS_READONLY - if ((fp->flag & FA_WRITE) && fp->fptr > fp->fsize) - { /* Set updated flag if in write mode */ - fp->fsize = fp->fptr; - fp->flag |= FA__WRITTEN; - } -#endif - - return FR_OK; - -fk_error: /* Abort this function due to an unrecoverable error */ - fp->flag |= FA__ERROR; - return FR_RW_ERROR; -} - -#endif - - -#if _FS_MINIMIZE <= 1 -/*-----------------------------------------------------------------------*/ -/* Open a directroy */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_opendir ( - DIR *dirobj, /* Pointer to directory object to create */ - const char *path /* Pointer to the directory path */ -) -{ - BYTE *dir; - char fn[8+3+1]; - FRESULT res; - FATFS *fs = FatFs; - - - res = auto_mount(&path, 0); - if (res != FR_OK) return res; - - res = trace_path(dirobj, fn, path, &dir); /* Trace the directory path */ - if (res == FR_OK) - { /* Trace completed */ - if (dir != NULL) - { /* It is not the root dir */ - if (dir[DIR_Attr] & AM_DIR) - { /* The entry is a directory */ - dirobj->clust = -#if _FAT32 - ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | -#endif - LD_WORD(&dir[DIR_FstClusLO]); - dirobj->sect = clust2sect(dirobj->clust); - dirobj->index = 2; - } - else - { /* The entry is not a directory */ - res = FR_NO_FILE; - } - } - dirobj->id = fs->id; - } - return res; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Read Directory Entry in Sequense */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_readdir ( - DIR *dirobj, /* Pointer to the directory object */ - FILINFO *finfo /* Pointer to file information to return */ -) -{ - BYTE *dir, c; - FRESULT res; - FATFS *fs = dirobj->fs; - - - res = validate(fs, dirobj->id); /* Check validity of the object */ - if (res) return res; - - finfo->fname[0] = 0; - while (dirobj->sect) - { - if (!move_window(dirobj->sect)) - return FR_RW_ERROR; - dir = &fs->win[(dirobj->index & 15) * 32]; /* pointer to the directory entry */ - c = dir[DIR_Name]; - if (c == 0) break; /* Has it reached to end of dir? */ - if (c != 0xE5 && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */ - get_fileinfo(finfo, dir); - if (!next_dir_entry(dirobj)) dirobj->sect = 0; /* Next entry */ - if (finfo->fname[0]) break; /* Found valid entry */ - } - - return FR_OK; -} - - - - -#if _FS_MINIMIZE == 0 -/*-----------------------------------------------------------------------*/ -/* Get File Status */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_stat ( - const char *path, /* Pointer to the file path */ - FILINFO *finfo /* Pointer to file information to return */ -) -{ - BYTE *dir; - char fn[8+3+1]; - FRESULT res; - DIR dirobj; - - - res = auto_mount(&path, 0); - if (res != FR_OK) return res; - - res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */ - if (res == FR_OK) - { /* Trace completed */ - if (dir) /* Found an object */ - get_fileinfo(finfo, dir); - else /* It is root dir */ - res = FR_INVALID_NAME; - } - - return res; -} - - - - -#if !_FS_READONLY -/*-----------------------------------------------------------------------*/ -/* Get Number of Free Clusters */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_getfree ( - const char *drv, /* Logical drive number */ - DWORD *nclust, /* Pointer to the double word to return number of free clusters */ - FATFS **fatfs /* Pointer to pointer to the file system object to return */ -) -{ - DWORD n, sect; - CLUST clust; - BYTE fat, f, *p; - FRESULT res; - FATFS *fs; - - - /* Get drive number */ - res = auto_mount(&drv, 0); - if (res != FR_OK) return res; - *fatfs = fs = FatFs; - - /* If number of free cluster is valid, return it without cluster scan. */ - if (fs->free_clust <= fs->max_clust - 2) - { - *nclust = fs->free_clust; - return FR_OK; - } - - /* Count number of free clusters */ - fat = fs->fs_type; - n = 0; - if (fat == FS_FAT12) - { - clust = 2; - do - { - if ((WORD)get_cluster(clust) == 0) n++; - } - while (++clust < fs->max_clust); - } - else - { - clust = fs->max_clust; - sect = fs->fatbase; - f = 0; - p = 0; - do - { - if (!f) - { - if (!move_window(sect++)) return FR_RW_ERROR; - p = fs->win; - } - if (!_FAT32 || fat == FS_FAT16) - { - if (LD_WORD(p) == 0) n++; - p += 2; - f += 1; - } - else - { - if (LD_DWORD(p) == 0) n++; - p += 4; - f += 2; - } - } - while (--clust); - } - fs->free_clust = n; -#if _USE_FSINFO - if (fat == FS_FAT32) fs->fsi_flag = 1; -#endif - - *nclust = n; - return FR_OK; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Delete a File or a Directory */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_unlink ( - const char *path /* Pointer to the file or directory path */ -) -{ - BYTE *dir, *sdir; - DWORD dsect; - char fn[8+3+1]; - CLUST dclust; - FRESULT res; - DIR dirobj; - FATFS *fs = FatFs; - - - res = auto_mount(&path, 1); - if (res != FR_OK) return res; - - res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */ - if (res != FR_OK) return res; /* Trace failed */ - if (dir == NULL) return FR_INVALID_NAME; /* It is the root directory */ - if (dir[DIR_Attr] & AM_RDO) return FR_DENIED; /* It is a R/O object */ - dsect = fs->winsect; - dclust = -#if _FAT32 - ((DWORD)LD_WORD(&dir[DIR_FstClusHI]) << 16) | -#endif - LD_WORD(&dir[DIR_FstClusLO]); - if (dir[DIR_Attr] & AM_DIR) - { /* It is a sub-directory */ - dirobj.clust = dclust; /* Check if the sub-dir is empty or not */ - dirobj.sect = clust2sect(dclust); - dirobj.index = 2; - do - { - if (!move_window(dirobj.sect)) return FR_RW_ERROR; - sdir = &fs->win[(dirobj.index & 15) * 32]; - if (sdir[DIR_Name] == 0) break; - if (sdir[DIR_Name] != 0xE5 && !(sdir[DIR_Attr] & AM_VOL)) - return FR_DENIED; /* The directory is not empty */ - } - while (next_dir_entry(&dirobj)); - } - - if (!move_window(dsect)) return FR_RW_ERROR; /* Mark the directory entry 'deleted' */ - dir[DIR_Name] = 0xE5; - fs->winflag = 1; - if (!remove_chain(dclust)) return FR_RW_ERROR; /* Remove the cluster chain */ - - return sync(); -} - - - - -/*-----------------------------------------------------------------------*/ -/* Create a Directory */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_mkdir ( - const char *path /* Pointer to the directory path */ -) -{ - BYTE *dir, *fw, n; - char fn[8+3+1]; - DWORD sect, dsect, tim; - CLUST dclust, pclust; - FRESULT res; - DIR dirobj; - FATFS *fs = FatFs; - - - res = auto_mount(&path, 1); - if (res != FR_OK) return res; - - res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */ - if (res == FR_OK) return FR_EXIST; /* Any file or directory is already existing */ - if (res != FR_NO_FILE) return res; - - res = reserve_direntry(&dirobj, &dir); /* Reserve a directory entry */ - if (res != FR_OK) return res; - sect = fs->winsect; - dclust = create_chain(0); /* Allocate a cluster for new directory table */ - if (dclust == 1) return FR_RW_ERROR; - dsect = clust2sect(dclust); - if (!dsect) return FR_DENIED; - if (!move_window(dsect)) return FR_RW_ERROR; - - fw = fs->win; - memset(fw, 0, 512); /* Clear the directory table */ - for (n = 1; n < fs->sects_clust; n++) - { - if (disk_write(0, fw, ++dsect, 1) != RES_OK) - return FR_RW_ERROR; - } - - memset(&fw[DIR_Name], ' ', 8+3); /* Create "." entry */ - fw[DIR_Name] = '.'; - fw[DIR_Attr] = AM_DIR; - tim = get_fattime(); - ST_DWORD(&fw[DIR_WrtTime], tim); - memcpy(&fw[32], &fw[0], 32); - fw[33] = '.'; /* Create ".." entry */ - pclust = dirobj.sclust; -#if _FAT32 - ST_WORD(&fw[ DIR_FstClusHI], dclust >> 16); - if (fs->fs_type == FS_FAT32 && pclust == fs->dirbase) pclust = 0; - ST_WORD(&fw[32+DIR_FstClusHI], pclust >> 16); -#endif - ST_WORD(&fw[ DIR_FstClusLO], dclust); - ST_WORD(&fw[32+DIR_FstClusLO], pclust); - fs->winflag = 1; - - if (!move_window(sect)) return FR_RW_ERROR; - memset(&dir[0], 0, 32); /* Clean-up the new entry */ - memcpy(&dir[DIR_Name], fn, 8+3); /* Name */ - dir[DIR_NTres] = fn[11]; - dir[DIR_Attr] = AM_DIR; /* Attribute */ - ST_DWORD(&dir[DIR_WrtTime], tim); /* Crated time */ - ST_WORD(&dir[DIR_FstClusLO], dclust); /* Table start cluster */ -#if _FAT32 - ST_WORD(&dir[DIR_FstClusHI], dclust >> 16); -#endif - - return sync(); -} - - - - -/*-----------------------------------------------------------------------*/ -/* Change File Attribute */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_chmod ( - const char *path, /* Pointer to the file path */ - BYTE value, /* Attribute bits */ - BYTE mask /* Attribute mask to change */ -) -{ - FRESULT res; - BYTE *dir; - DIR dirobj; - char fn[8+3+1]; - - - res = auto_mount(&path, 1); - if (res == FR_OK) - { - res = trace_path(&dirobj, fn, path, &dir); /* Trace the file path */ - if (res == FR_OK) - { /* Trace completed */ - if (dir == NULL) - { - res = FR_INVALID_NAME; - } - else - { - mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ - dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ - res = sync(); - } - } - } - return res; -} - - - - -/*-----------------------------------------------------------------------*/ -/* Rename File/Directory */ -/*-----------------------------------------------------------------------*/ - -FRESULT f_rename ( - const char *path_old, /* Pointer to the old name */ - const char *path_new /* Pointer to the new name */ -) -{ - FRESULT res; - DWORD sect_old; - BYTE *dir_old, *dir_new, direntry[32-11]; - DIR dirobj; - char fn[8+3+1]; - FATFS *fs = FatFs; - - - res = auto_mount(&path_old, 1); - if (res != FR_OK) return res; - - res = trace_path(&dirobj, fn, path_old, &dir_old); /* Check old object */ - if (res != FR_OK) return res; /* The old object is not found */ - if (!dir_old) return FR_NO_FILE; - sect_old = fs->winsect; /* Save the object information */ - memcpy(direntry, &dir_old[11], 32-11); - - res = trace_path(&dirobj, fn, path_new, &dir_new); /* Check new object */ - if (res == FR_OK) return FR_EXIST; /* The new object name is already existing */ - if (res != FR_NO_FILE) return res; /* Is there no old name? */ - res = reserve_direntry(&dirobj, &dir_new); /* Reserve a directory entry */ - if (res != FR_OK) return res; - - memcpy(&dir_new[DIR_Attr], direntry, 32-11); /* Create new entry */ - memcpy(&dir_new[DIR_Name], fn, 8+3); - dir_new[DIR_NTres] = fn[11]; - fs->winflag = 1; - - if (!move_window(sect_old)) return FR_RW_ERROR; /* Remove old entry */ - dir_old[DIR_Name] = 0xE5; - - return sync(); -} - -#endif /* !_FS_READONLY */ -#endif /* _FS_MINIMIZE == 0 */ -#endif /* _FS_MINIMIZE <= 1 */ -#endif /* _FS_MINIMIZE <= 2 */ - diff --git a/sdelfloader/loader/source/tff.h b/sdelfloader/loader/source/tff.h deleted file mode 100644 index 32d16e3..0000000 --- a/sdelfloader/loader/source/tff.h +++ /dev/null @@ -1,299 +0,0 @@ -/*--------------------------------------------------------------------------/ -/ Tiny-FatFs - FAT file system module include file R0.04b (C)ChaN, 2007 -/---------------------------------------------------------------------------/ -/ FatFs module is an experimenal project to implement FAT file system to -/ cheap microcontrollers. This is a free software and is opened for education, -/ research and development under license policy of following trems. -/ -/ Copyright (C) 2007, ChaN, all right reserved. -/ -/ * The FatFs module is a free software and there is no warranty. -/ * You can use, modify and/or redistribute it for personal, non-profit or -/ profit use without any restriction under your responsibility. -/ * Redistributions of source code must retain the above copyright notice. -/ -/---------------------------------------------------------------------------*/ - -#ifndef _FATFS - - -#define _MCU_ENDIAN 2 -/* The _MCU_ENDIAN defines which access method is used to the FAT structure. -/ 1: Enable word access. -/ 2: Disable word access and use byte-by-byte access instead. -/ When the architectural byte order of the MCU is big-endian and/or address -/ miss-aligned access is prohibited, the _MCU_ENDIAN must be set to 2. -/ If it is not the case, it can be set to 1 for good code efficiency. */ - -#define _FS_READONLY 1 -/* Setting _FS_READONLY to 1 defines read only configuration. This removes -/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename -/ and useless f_getfree. */ - -#define _FS_MINIMIZE 0 -/* The _FS_MINIMIZE option defines minimization level to remove some functions. -/ 0: Full function. -/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod and f_rename are removed. -/ 2: f_opendir and f_readdir are removed in addition to level 1. -/ 3: f_lseek is removed in addition to level 2. */ - -#define _FAT32 1 -/* To enable FAT32 support in addition of FAT12/16, set _FAT32 to 1. */ - -#define _USE_FSINFO 0 -/* To enable FSInfo support on FAT32 volume, set _USE_FSINFO to 1. */ - -#define _USE_SJIS 0 -/* When _USE_SJIS is set to 1, Shift-JIS code transparency is enabled, otherwise -/ only US-ASCII(7bit) code can be accepted as file/directory name. */ - -#define _USE_NTFLAG 0 -/* When _USE_NTFLAG is set to 1, upper/lower case of the file name is preserved. -/ Note that the files are always accessed in case insensitive. */ - - -#include "integer.h" - - -/* Type definition for cluster number */ -#if _FAT32 -typedef DWORD CLUST; -#else -typedef WORD CLUST; -#undef _USE_FSINFO -#define _USE_FSINFO 0 -#endif - - -/* File system object structure */ -typedef struct _FATFS - { - WORD id; /* File system mount ID */ - WORD n_rootdir; /* Number of root directory entries */ - DWORD winsect; /* Current sector appearing in the win[] */ - DWORD fatbase; /* FAT start sector */ - DWORD dirbase; /* Root directory start sector */ - DWORD database; /* Data start sector */ - CLUST sects_fat; /* Sectors per fat */ - CLUST max_clust; /* Maximum cluster# + 1 */ -#if !_FS_READONLY - CLUST last_clust; /* Last allocated cluster */ - CLUST free_clust; /* Number of free clusters */ -#if _USE_FSINFO - DWORD fsi_sector; /* fsinfo sector */ - BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ - BYTE pad1; -#endif -#endif - BYTE fs_type; /* FAT sub type */ - BYTE sects_clust; /* Sectors per cluster */ - BYTE n_fats; /* Number of FAT copies */ - BYTE winflag; /* win[] dirty flag (1:must be written back) */ - BYTE win[512]; /* Disk access window for Directory/FAT/File */ - } -FATFS; - - -/* Directory object structure */ -typedef struct _DIR - { - WORD id; /* Owner file system mount ID */ - WORD index; /* Current index */ - FATFS* fs; /* Pointer to the owner file system object */ - CLUST sclust; /* Start cluster */ - CLUST clust; /* Current cluster */ - DWORD sect; /* Current sector */ - } -DIR; - - -/* File object structure */ -typedef struct _FIL - { - WORD id; /* Owner file system mount ID */ - BYTE flag; /* File status flags */ - BYTE sect_clust; /* Left sectors in cluster */ - FATFS* fs; /* Pointer to owner file system */ - DWORD fptr; /* File R/W pointer */ - DWORD fsize; /* File size */ - CLUST org_clust; /* File start cluster */ - CLUST curr_clust; /* Current cluster */ - DWORD curr_sect; /* Current sector */ -#if !_FS_READONLY - DWORD dir_sect; /* Sector containing the directory entry */ - BYTE* dir_ptr; /* Ponter to the directory entry in the window */ -#endif - } -FIL; - - -/* File status structure */ -typedef struct _FILINFO - { - DWORD fsize; /* Size */ - WORD fdate; /* Date */ - WORD ftime; /* Time */ - BYTE fattrib; /* Attribute */ - char fname[8+1+3+1]; /* Name (8.3 format) */ - } -FILINFO; - - -/* File function return code (FRESULT) */ - -typedef enum { - FR_OK = 0, /* 0 */ - FR_NOT_READY, /* 1 */ - FR_NO_FILE, /* 2 */ - FR_NO_PATH, /* 3 */ - FR_INVALID_NAME, /* 4 */ - FR_INVALID_DRIVE, /* 5 */ - FR_DENIED, /* 6 */ - FR_EXIST, /* 7 */ - FR_RW_ERROR, /* 8 */ - FR_WRITE_PROTECTED, /* 9 */ - FR_NOT_ENABLED, /* 10 */ - FR_NO_FILESYSTEM, /* 11 */ - FR_INVALID_OBJECT /* 12 */ -} FRESULT; - - - -/*-----------------------------------------------------*/ -/* FatFs module application interface */ - -FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ -FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ -FRESULT f_read (FIL*, void*, WORD, WORD*); /* Read data from a file */ -FRESULT f_write (FIL*, const void*, WORD, WORD*); /* Write data to a file */ -FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ -FRESULT f_close (FIL*); /* Close an open file object */ -FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */ -FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ -FRESULT f_stat (const char*, FILINFO*); /* Get file status */ -FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ -FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ -FRESULT f_unlink (const char*); /* Delete an existing file or directory */ -FRESULT f_mkdir (const char*); /* Create a new directory */ -FRESULT f_chmod (const char*, BYTE, BYTE); /* Change file/dir attriburte */ -FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ - - -/* User defined function to give a current time to fatfs module */ - -DWORD get_fattime (void); /* 31-25: Year(0-127 +1980), 24-21: Month(1-12), 20-16: Day(1-31) */ -/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ - - - -/* File access control and file status flags (FIL.flag) */ - -#define FA_READ 0x01 -#define FA_OPEN_EXISTING 0x00 -#if !_FS_READONLY -#define FA_WRITE 0x02 -#define FA_CREATE_NEW 0x04 -#define FA_CREATE_ALWAYS 0x08 -#define FA_OPEN_ALWAYS 0x10 -#define FA__WRITTEN 0x20 -#endif -#define FA__ERROR 0x80 - - -/* FAT sub type (FATFS.fs_type) */ - -#define FS_FAT12 1 -#define FS_FAT16 2 -#define FS_FAT32 3 - - -/* File attribute bits for directory entry */ - -#define AM_RDO 0x01 /* Read only */ -#define AM_HID 0x02 /* Hidden */ -#define AM_SYS 0x04 /* System */ -#define AM_VOL 0x08 /* Volume label */ -#define AM_LFN 0x0F /* LFN entry */ -#define AM_DIR 0x10 /* Directory */ -#define AM_ARC 0x20 /* Archive */ - - - -/* Offset of FAT structure members */ - -#define BS_jmpBoot 0 -#define BS_OEMName 3 -#define BPB_BytsPerSec 11 -#define BPB_SecPerClus 13 -#define BPB_RsvdSecCnt 14 -#define BPB_NumFATs 16 -#define BPB_RootEntCnt 17 -#define BPB_TotSec16 19 -#define BPB_Media 21 -#define BPB_FATSz16 22 -#define BPB_SecPerTrk 24 -#define BPB_NumHeads 26 -#define BPB_HiddSec 28 -#define BPB_TotSec32 32 -#define BS_55AA 510 - -#define BS_DrvNum 36 -#define BS_BootSig 38 -#define BS_VolID 39 -#define BS_VolLab 43 -#define BS_FilSysType 54 - -#define BPB_FATSz32 36 -#define BPB_ExtFlags 40 -#define BPB_FSVer 42 -#define BPB_RootClus 44 -#define BPB_FSInfo 48 -#define BPB_BkBootSec 50 -#define BS_DrvNum32 64 -#define BS_BootSig32 66 -#define BS_VolID32 67 -#define BS_VolLab32 71 -#define BS_FilSysType32 82 - -#define FSI_LeadSig 0 -#define FSI_StrucSig 484 -#define FSI_Free_Count 488 -#define FSI_Nxt_Free 492 - -#define MBR_Table 446 - -#define DIR_Name 0 -#define DIR_Attr 11 -#define DIR_NTres 12 -#define DIR_CrtTime 14 -#define DIR_CrtDate 16 -#define DIR_FstClusHI 20 -#define DIR_WrtTime 22 -#define DIR_WrtDate 24 -#define DIR_FstClusLO 26 -#define DIR_FileSize 28 - - - -/* Multi-byte word access macros */ - -#if _MCU_ENDIAN == 1 /* Use word access */ -#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) -#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) -#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) -#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) -#else -#if _MCU_ENDIAN == 2 /* Use byte-by-byte access */ -#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) -#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr)) -#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) -#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8); *(BYTE*)((ptr)+2)=(BYTE)((DWORD)(val)>>16); *(BYTE*)((ptr)+3)=(BYTE)((DWORD)(val)>>24) -#else -#error Do not forget to set _MCU_ENDIAN properly! -#endif -#endif - - - -#define _FATFS -#endif /* _FATFS */ diff --git a/sdelfloader/miniloader/Makefile b/sdelfloader/miniloader/Makefile deleted file mode 100644 index 79d6a41..0000000 --- a/sdelfloader/miniloader/Makefile +++ /dev/null @@ -1,143 +0,0 @@ -#--------------------------------------------------------------------------------- -# Clear the implicit built in rules -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC) -endif - -include $(DEVKITPPC)/wii_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# INCLUDES is a list of directories containing extra header files -#--------------------------------------------------------------------------------- -TARGET := $(notdir $(CURDIR)) -BUILD := build -SOURCES := source -DATA := data -INCLUDES := - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- - -CFLAGS = -g -Os -mrvl -Wall $(MACHDEP) $(INCLUDE) -CXXFLAGS = $(CFLAGS) - -LDFLAGS = -g $(MACHDEP) -mrvl -Wl,-Map,$(notdir $@).map - -#--------------------------------------------------------------------------------- -# any extra libraries we wish to link with the project -#--------------------------------------------------------------------------------- -LIBS := -logc - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/$(TARGET) - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -#--------------------------------------------------------------------------------- -# automatically build a list of object files for our project -#--------------------------------------------------------------------------------- -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) - export LD := $(CC) -else - export LD := $(CXX) -endif - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ - $(sFILES:.s=.o) $(SFILES:.S=.o) - -#--------------------------------------------------------------------------------- -# build a list of include paths -#--------------------------------------------------------------------------------- -export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) \ - -I$(LIBOGC_INC) - -#--------------------------------------------------------------------------------- -# build a list of library paths -#--------------------------------------------------------------------------------- -export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ - -L$(LIBOGC_LIB) - -export OUTPUT := $(CURDIR)/$(TARGET) -.PHONY: $(BUILD) clean - -#--------------------------------------------------------------------------------- -$(BUILD): - @[ -d $@ ] || mkdir -p $@ - @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol - -#--------------------------------------------------------------------------------- -run: - psoload $(TARGET).dol - -#--------------------------------------------------------------------------------- -reload: - psoload -r $(TARGET).dol - - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT).dol: $(OUTPUT).elf -$(OUTPUT).elf: $(OFILES) - -#--------------------------------------------------------------------------------- -# This rule links in binary data with the .jpg extension -#--------------------------------------------------------------------------------- -%.jpg.o : %.jpg -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - $(bin2o) - --include $(DEPENDS) - -$(OUTPUT).dol: $(OUTPUT).elf - @echo "Output ... "$(notdir $@) - @$(OBJCOPY) -O binary $< $@ - -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- diff --git a/sdelfloader/miniloader/source/asm.h b/sdelfloader/miniloader/source/asm.h deleted file mode 100644 index 8e335b4..0000000 --- a/sdelfloader/miniloader/source/asm.h +++ /dev/null @@ -1,340 +0,0 @@ -// this file was taken from libogc, see http://www.devkitpro.org/ - -#ifndef __ASM_H__ -#define __ASM_H__ - -#ifdef _LANGUAGE_ASSEMBLY -/* Condition Register Bit Fields */ - -#define cr0 0 -#define cr1 1 -#define cr2 2 -#define cr3 3 -#define cr4 4 -#define cr5 5 -#define cr6 6 -#define cr7 7 - - -/* General Purpose Registers (GPRs) */ - -#define r0 0 -#define r1 1 -#define sp 1 -#define r2 2 -#define toc 2 -#define r3 3 -#define r4 4 -#define r5 5 -#define r6 6 -#define r7 7 -#define r8 8 -#define r9 9 -#define r10 10 -#define r11 11 -#define r12 12 -#define r13 13 -#define r14 14 -#define r15 15 -#define r16 16 -#define r17 17 -#define r18 18 -#define r19 19 -#define r20 20 -#define r21 21 -#define r22 22 -#define r23 23 -#define r24 24 -#define r25 25 -#define r26 26 -#define r27 27 -#define r28 28 -#define r29 29 -#define r30 30 -#define r31 31 - - -/* Floating Point Registers (FPRs) */ - -#define fr0 0 -#define fr1 1 -#define fr2 2 -#define fr3 3 -#define fr4 4 -#define fr5 5 -#define fr6 6 -#define fr7 7 -#define fr8 8 -#define fr9 9 -#define fr10 10 -#define fr11 11 -#define fr12 12 -#define fr13 13 -#define fr14 14 -#define fr15 15 -#define fr16 16 -#define fr17 17 -#define fr18 18 -#define fr19 19 -#define fr20 20 -#define fr21 21 -#define fr22 22 -#define fr23 23 -#define fr24 24 -#define fr25 25 -#define fr26 26 -#define fr27 27 -#define fr28 28 -#define fr29 29 -#define fr30 30 -#define fr31 31 - -#define vr0 0 -#define vr1 1 -#define vr2 2 -#define vr3 3 -#define vr4 4 -#define vr5 5 -#define vr6 6 -#define vr7 7 -#define vr8 8 -#define vr9 9 -#define vr10 10 -#define vr11 11 -#define vr12 12 -#define vr13 13 -#define vr14 14 -#define vr15 15 -#define vr16 16 -#define vr17 17 -#define vr18 18 -#define vr19 19 -#define vr20 20 -#define vr21 21 -#define vr22 22 -#define vr23 23 -#define vr24 24 -#define vr25 25 -#define vr26 26 -#define vr27 27 -#define vr28 28 -#define vr29 29 -#define vr30 30 -#define vr31 31 - -#endif //_LANGUAGE_ASSEMBLY - -#define SPRG0 272 -#define SPRG1 273 -#define SPRG2 274 -#define SPRG3 275 - -#define PMC1 953 -#define PMC2 954 -#define PMC3 957 -#define PMC4 958 - -#define MMCR0 952 -#define MMCR1 956 - - -#define LINK_REGISTER_CALLEE_UPDATE_ROOM 4 -#define EXCEPTION_NUMBER 8 -#define SRR0_OFFSET 12 -#define SRR1_OFFSET 16 -#define GPR0_OFFSET 20 -#define GPR1_OFFSET 24 -#define GPR2_OFFSET 28 -#define GPR3_OFFSET 32 -#define GPR4_OFFSET 36 -#define GPR5_OFFSET 40 -#define GPR6_OFFSET 44 -#define GPR7_OFFSET 48 -#define GPR8_OFFSET 52 -#define GPR9_OFFSET 56 -#define GPR10_OFFSET 60 -#define GPR11_OFFSET 64 -#define GPR12_OFFSET 68 -#define GPR13_OFFSET 72 -#define GPR14_OFFSET 76 -#define GPR15_OFFSET 80 -#define GPR16_OFFSET 84 -#define GPR17_OFFSET 88 -#define GPR18_OFFSET 92 -#define GPR19_OFFSET 96 -#define GPR20_OFFSET 100 -#define GPR21_OFFSET 104 -#define GPR22_OFFSET 108 -#define GPR23_OFFSET 112 -#define GPR24_OFFSET 116 -#define GPR25_OFFSET 120 -#define GPR26_OFFSET 124 -#define GPR27_OFFSET 128 -#define GPR28_OFFSET 132 -#define GPR29_OFFSET 136 -#define GPR30_OFFSET 140 -#define GPR31_OFFSET 144 - -#define GQR0_OFFSET 148 -#define GQR1_OFFSET 152 -#define GQR2_OFFSET 156 -#define GQR3_OFFSET 160 -#define GQR4_OFFSET 164 -#define GQR5_OFFSET 168 -#define GQR6_OFFSET 172 -#define GQR7_OFFSET 176 - -#define CR_OFFSET 180 -#define LR_OFFSET 184 -#define CTR_OFFSET 188 -#define XER_OFFSET 192 -#define MSR_OFFSET 196 -#define DAR_OFFSET 200 - -#define STATE_OFFSET 204 -#define MODE_OFFSET 206 - -#define FPR0_OFFSET 208 -#define FPR1_OFFSET 216 -#define FPR2_OFFSET 224 -#define FPR3_OFFSET 232 -#define FPR4_OFFSET 240 -#define FPR5_OFFSET 248 -#define FPR6_OFFSET 256 -#define FPR7_OFFSET 264 -#define FPR8_OFFSET 272 -#define FPR9_OFFSET 280 -#define FPR10_OFFSET 288 -#define FPR11_OFFSET 296 -#define FPR12_OFFSET 304 -#define FPR13_OFFSET 312 -#define FPR14_OFFSET 320 -#define FPR15_OFFSET 328 -#define FPR16_OFFSET 336 -#define FPR17_OFFSET 344 -#define FPR18_OFFSET 352 -#define FPR19_OFFSET 360 -#define FPR20_OFFSET 368 -#define FPR21_OFFSET 376 -#define FPR22_OFFSET 384 -#define FPR23_OFFSET 392 -#define FPR24_OFFSET 400 -#define FPR25_OFFSET 408 -#define FPR26_OFFSET 416 -#define FPR27_OFFSET 424 -#define FPR28_OFFSET 432 -#define FPR29_OFFSET 440 -#define FPR30_OFFSET 448 -#define FPR31_OFFSET 456 - -#define FPSCR_OFFSET 464 - -#define PSR0_OFFSET 472 -#define PSR1_OFFSET 480 -#define PSR2_OFFSET 488 -#define PSR3_OFFSET 496 -#define PSR4_OFFSET 504 -#define PSR5_OFFSET 512 -#define PSR6_OFFSET 520 -#define PSR7_OFFSET 528 -#define PSR8_OFFSET 536 -#define PSR9_OFFSET 544 -#define PSR10_OFFSET 552 -#define PSR11_OFFSET 560 -#define PSR12_OFFSET 568 -#define PSR13_OFFSET 576 -#define PSR14_OFFSET 584 -#define PSR15_OFFSET 592 -#define PSR16_OFFSET 600 -#define PSR17_OFFSET 608 -#define PSR18_OFFSET 616 -#define PSR19_OFFSET 624 -#define PSR20_OFFSET 632 -#define PSR21_OFFSET 640 -#define PSR22_OFFSET 648 -#define PSR23_OFFSET 656 -#define PSR24_OFFSET 664 -#define PSR25_OFFSET 672 -#define PSR26_OFFSET 680 -#define PSR27_OFFSET 688 -#define PSR28_OFFSET 696 -#define PSR29_OFFSET 704 -#define PSR30_OFFSET 712 -#define PSR31_OFFSET 720 -/* - * maintain the EABI requested 8 bytes aligment - * As SVR4 ABI requires 16, make it 16 (as some - * exception may need more registers to be processed...) - */ -#define EXCEPTION_FRAME_END 728 - -#define IBAT0U 528 -#define IBAT0L 529 -#define IBAT1U 530 -#define IBAT1L 531 -#define IBAT2U 532 -#define IBAT2L 533 -#define IBAT3U 534 -#define IBAT3L 535 -#define IBAT4U 560 -#define IBAT4L 561 -#define IBAT5U 562 -#define IBAT5L 563 -#define IBAT6U 564 -#define IBAT6L 565 -#define IBAT7U 566 -#define IBAT7L 567 - -#define DBAT0U 536 -#define DBAT0L 537 -#define DBAT1U 538 -#define DBAT1L 538 -#define DBAT2U 540 -#define DBAT2L 541 -#define DBAT3U 542 -#define DBAT3L 543 -#define DBAT4U 568 -#define DBAT4L 569 -#define DBAT5U 570 -#define DBAT5L 571 -#define DBAT6U 572 -#define DBAT6L 573 -#define DBAT7U 574 -#define DBAT7L 575 - -#define HID0 1008 -#define HID1 1009 -#define HID2 920 -#define HID4 1011 - -#define GQR0 912 -#define GQR1 913 -#define GQR2 914 -#define GQR3 915 -#define GQR4 916 -#define GQR5 917 -#define GQR6 918 -#define GQR7 919 - -#define L2CR 1017 - -#define WPAR 921 - -#define DMAU 922 -#define DMAL 923 - -#define MSR_RI 0x00000002 -#define MSR_DR 0x00000010 -#define MSR_IR 0x00000020 -#define MSR_IP 0x00000040 -#define MSR_SE 0x00000400 -#define MSR_ME 0x00001000 -#define MSR_FP 0x00002000 -#define MSR_POW 0x00004000 -#define MSR_EE 0x00008000 - -#define PPC_ALIGNMENT 8 - -#define PPC_CACHE_ALIGNMENT 32 - -#endif //__ASM_H__ diff --git a/sdelfloader/miniloader/source/dol.c b/sdelfloader/miniloader/source/dol.c deleted file mode 100644 index 35fedea..0000000 --- a/sdelfloader/miniloader/source/dol.c +++ /dev/null @@ -1,74 +0,0 @@ -// this code was contributed by shagkur of the devkitpro team, thx! - -#include -#include - -#include -#include - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -u32 load_dol_image (void *dolstart) { - u32 i; - dolheader *dolfile; - - if (dolstart) { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) { - if ((!dolfile->text_size[i]) || - (dolfile->text_start[i] < 0x100)) - continue; - - printf ("loading text section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->text_start[i], - dolfile->text_size[i]); - VIDEO_WaitVSync(); - - ICInvalidateRange ((void *) dolfile->text_start[i], - dolfile->text_size[i]); - memmove ((void *) dolfile->text_start[i], - dolstart+dolfile->text_pos[i], - dolfile->text_size[i]); - } - - for(i = 0; i < 11; i++) { - if ((!dolfile->data_size[i]) || - (dolfile->data_start[i] < 0x100)) - continue; - - printf ("loading data section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->data_start[i], - dolfile->data_size[i]); - VIDEO_WaitVSync(); - - memmove ((void*) dolfile->data_start[i], - dolstart+dolfile->data_pos[i], - dolfile->data_size[i]); - DCFlushRangeNoSync ((void *) dolfile->data_start[i], - dolfile->data_size[i]); - } - - printf ("clearing bss\n"); - VIDEO_WaitVSync(); - - memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - - return dolfile->entry_point; - } - - return 0; -} - diff --git a/sdelfloader/miniloader/source/dol.h b/sdelfloader/miniloader/source/dol.h deleted file mode 100644 index d338d4c..0000000 --- a/sdelfloader/miniloader/source/dol.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2008 dhewg, #wiidev efnet - * - * this file is part of geckoloader - * http://wiibrew.org/index.php?title=Geckoloader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _DOL_H_ - -#include - -u32 load_dol_image (void *dolstart); - -#endif - diff --git a/sdelfloader/miniloader/source/main.c b/sdelfloader/miniloader/source/main.c deleted file mode 100644 index d041dae..0000000 --- a/sdelfloader/miniloader/source/main.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -#include "dol.h" -#include "processor.h" -#include "asm.h" - -static void *xfb = NULL; -static GXRModeObj *rmode = NULL; - -extern u8 loader_dol[]; - -extern void __exception_closeall(); -extern s32 __IOS_ShutdownSubsystems(); - -int main(int argc, char **argv) { - u32 level; - - VIDEO_Init(); - switch(VIDEO_GetCurrentTvMode()) { - case VI_NTSC: - rmode = &TVNtsc480IntDf; - break; - case VI_PAL: - rmode = &TVPal528IntDf; - break; - case VI_MPAL: - rmode = &TVMpal480IntDf; - break; - default: - rmode = &TVNtsc480IntDf; - break; - } - - PAD_Init(); - - xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); - - VIDEO_Configure(rmode); - VIDEO_SetNextFramebuffer(xfb); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - - if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); - - printf("\n\nloading\n"); - VIDEO_WaitVSync(); - void (*ep)() = (void(*)())load_dol_image(loader_dol); - printf("jumping to 0x%08X\n", (unsigned int)ep); - - __IOS_ShutdownSubsystems(); - _CPU_ISR_Disable (level); - __exception_closeall (); - printf("__exception_closeall() done. Jumping to ep now...\n"); - ep(); - _CPU_ISR_Restore (level); - - return 0; // fixes gcc warning -} diff --git a/sdelfloader/miniloader/source/processor.h b/sdelfloader/miniloader/source/processor.h deleted file mode 100644 index 01618b6..0000000 --- a/sdelfloader/miniloader/source/processor.h +++ /dev/null @@ -1,115 +0,0 @@ -// this file was taken from libogc, see http://www.devkitpro.org/ - -#ifndef __PROCESSOR_H__ -#define __PROCESSOR_H__ - -#include - -#define __stringify(rn) #rn -#define ATTRIBUTE_ALIGN(v) __attribute__((aligned(v))) - -#define _sync() asm volatile("sync") -#define _nop() asm volatile("nop") -#define ppcsync() asm volatile("sc") -#define ppchalt() ({ \ - asm volatile("sync"); \ - while(1) { \ - asm volatile("nop"); \ - asm volatile("li 3,0"); \ - asm volatile("nop"); \ - } \ -}) - -#define mfdcr(_rn) ({register u32 _rval; \ - asm volatile("mfdcr %0," __stringify(_rn) \ - : "=r" (_rval)); _rval;}) -#define mtdcr(rn, val) asm volatile("mtdcr " __stringify(rn) ",%0" : : "r" (val)) - -#define mfmsr() ({register u32 _rval; \ - asm volatile("mfmsr %0" : "=r" (_rval)); _rval;}) -#define mtmsr(val) asm volatile("mtmsr %0" : : "r" (val)) - -#define mfdec() ({register u32 _rval; \ - asm volatile("mfdec %0" : "=r" (_rval)); _rval;}) -#define mtdec(_val) asm volatile("mtdec %0" : : "r" (_val)) - -#define mfspr(_rn) \ -({ register u32 _rval = 0; \ - asm volatile("mfspr %0," __stringify(_rn) \ - : "=r" (_rval));\ - _rval; \ -}) - -#define mtspr(_rn, _val) asm volatile("mtspr " __stringify(_rn) ",%0" : : "r" (_val)) - -#define mfwpar() mfspr(WPAR) -#define mtwpar(_val) mtspr(WPAR,_val) - -#define mfmmcr0() mfspr(MMCR0) -#define mtmmcr0(_val) mtspr(MMCR0,_val) -#define mfmmcr1() mfspr(MMCR1) -#define mtmmcr1(_val) mtspr(MMCR1,_val) - -#define mfpmc1() mfspr(PMC1) -#define mtpmc1(_val) mtspr(PMC1,_val) -#define mfpmc2() mfspr(PMC2) -#define mtpmc2(_val) mtspr(PMC2,_val) -#define mfpmc3() mfspr(PMC3) -#define mtpmc3(_val) mtspr(PMC3,_val) -#define mfpmc4() mfspr(PMC4) -#define mtpmc4(_val) mtspr(PMC4,_val) - -#define mfhid0() mfspr(HID0) -#define mthid0(_val) mtspr(HID0,_val) -#define mfhid1() mfspr(HID1) -#define mthid1(_val) mtspr(HID1,_val) -#define mfhid2() mfspr(HID2) -#define mthid2(_val) mtspr(HID2,_val) -#define mfhid4() mfspr(HID4) -#define mthid4(_val) mtspr(HID4,_val) - -#define cntlzw(_val) ({register u32 _rval; \ - asm volatile("cntlzw %0, %1" : "=r"((_rval)) : "r"((_val))); _rval;}) - -#define _CPU_MSR_GET( _msr_value ) \ - do { \ - _msr_value = 0; \ - asm volatile ("mfmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); \ - } while (0) - -#define _CPU_MSR_SET( _msr_value ) \ -{ asm volatile ("mtmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); } - -#define _CPU_ISR_Enable() \ - { register u32 _val = 0; \ - asm volatile ("mfmsr %0; ori %0,%0,0x8000; mtmsr %0" : \ - "=&r" (_val) : "0" (_val));\ - } - -#define _CPU_ISR_Disable( _isr_cookie ) \ - { register u32 _disable_mask = MSR_EE; \ - _isr_cookie = 0; \ - asm volatile ( \ - "mfmsr %0; andc %1,%0,%1; mtmsr %1" : \ - "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) : \ - "0" ((_isr_cookie)), "1" ((_disable_mask)) \ - ); \ - } - -#define _CPU_ISR_Restore( _isr_cookie ) \ - { \ - asm volatile ( "mtmsr %0" : \ - "=r" ((_isr_cookie)) : \ - "0" ((_isr_cookie))); \ - } - -#define _CPU_ISR_Flash( _isr_cookie ) \ - { register u32 _disable_mask = MSR_EE; \ - asm volatile ( \ - "mtmsr %0; andc %1,%0,%1; mtmsr %1" : \ - "=r" ((_isr_cookie)), "=r" ((_disable_mask)) : \ - "0" ((_isr_cookie)), "1" ((_disable_mask)) \ - ); \ - } - -#endif -- 2.11.4.GIT