00001 /* 00002 dldi.h 00003 00004 Copyright (c) 2006 Michael "Chishm" Chisholm 00005 00006 Redistribution and use in source and binary forms, with or without modification, 00007 are permitted provided that the following conditions are met: 00008 00009 1. Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 2. Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation and/or 00013 other materials provided with the distribution. 00014 3. The name of the author may not be used to endorse or promote products derived 00015 from this software without specific prior written permission. 00016 00017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00018 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00019 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 00020 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00025 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 00029 #ifndef NDS_DLDI_INCLUDE 00030 #define NDS_DLDI_INCLUDE 00031 00032 #include "../disc_io.h" 00033 00034 #define FIX_ALL 0x01 00035 #define FIX_GLUE 0x02 00036 #define FIX_GOT 0x04 00037 #define FIX_BSS 0x08 00038 00039 #define DLDI_MAGIC_STRING_LEN 8 00040 #define DLDI_FRIENDLY_NAME_LEN 48 00041 00042 extern const u32 DLDI_MAGIC_NUMBER; 00043 00044 // I/O interface with DLDI extensions 00045 typedef struct DLDI_INTERFACE { 00046 u32 magicNumber; 00047 char magicString [DLDI_MAGIC_STRING_LEN]; 00048 u8 versionNumber; 00049 u8 driverSize; // log-2 of driver size in bytes 00050 u8 fixSectionsFlags; 00051 u8 allocatedSize; // log-2 of the allocated space in bytes 00052 00053 char friendlyName [DLDI_FRIENDLY_NAME_LEN]; 00054 00055 // Pointers to sections that need address fixing 00056 void* dldiStart; 00057 void* dldiEnd; 00058 void* interworkStart; 00059 void* interworkEnd; 00060 void* gotStart; 00061 void* gotEnd; 00062 void* bssStart; 00063 void* bssEnd; 00064 00065 // Original I/O interface data 00066 DISC_INTERFACE ioInterface; 00067 } DLDI_INTERFACE; 00068 00069 00070 /* 00071 Pointer to the internal DLDI, not directly usable by libfat. 00072 You'll need to set the bus permissions appropriately before using. 00073 */ 00074 extern const DLDI_INTERFACE* io_dldi_data; 00075 00076 /* 00077 Return a pointer to the internal IO interface, 00078 setting up bus permissions in the process. 00079 */ 00080 extern const DISC_INTERFACE* dldiGetInternal (void); 00081 00082 /* 00083 Determines if an IO driver is a valid DLDI driver 00084 */ 00085 extern bool dldiIsValid (const DLDI_INTERFACE* io); 00086 00087 /* 00088 Adjust the pointer addresses within a DLDI driver 00089 */ 00090 extern void dldiFixDriverAddresses (DLDI_INTERFACE* io); 00091 00092 /* 00093 Load a DLDI from disc and set up the bus permissions. 00094 This returns a type not directly usable in libfat, 00095 but it does give extra information, such as a friendly name. 00096 To use in libfat: 00097 const DLDI_INTERFACE* loadedDldi = dldi_loadFromFile ("file"); 00098 loadedDldi->ioInterface.startup(); 00099 fatMount(&loadedDldi->ioInterface, "devname", 0); 00100 */ 00101 extern DLDI_INTERFACE* dldiLoadFromFile (const char* path); 00102 00103 /* 00104 Free resources used by a loaded DLDI. 00105 Remember to unmount and shutdown first: 00106 fatUnmount("devname"); 00107 loadedDldi->ioInterface.shutdown(); 00108 dldiFree(loadedDldi); 00109 */ 00110 extern void dldiFree (DLDI_INTERFACE* dldi); 00111 00112 #endif // NDS_DLDI_INCLUDE