6 /***************************************************************************
7 Includes used by XBox boot code
8 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 /////////////////////////////////
23 #include "cromwell_types.h"
26 unsigned int cromwell_config
;
27 unsigned int cromwell_retryload
;
28 unsigned int cromwell_loadbank
;
29 unsigned int cromwell_Biostype
;
31 unsigned int xbox_ram
;
37 #define ICON_HEIGHT 64
39 static double min (double a, double b)
41 if (a < b) return a; else return b;
44 static inline double max (double a, double b)
46 if (a > b) return a; else return b;
50 //#include "BootVideo.h"
52 //#define ASSERT(exp) { if(!(exp)) { bprintf("Assert failed file " __FILE__ " line %d\n", __LINE__); } }
55 extern volatile CURRENT_VIDEO_MODE_DETAILS vmode
;
56 unsigned int video_encoder
;
58 volatile u32 VIDEO_CURSOR_POSX
;
59 volatile u32 VIDEO_CURSOR_POSY
;
60 volatile u32 VIDEO_ATTR
;
61 volatile u32 VIDEO_LUMASCALING
;
62 volatile u32 VIDEO_RSCALING
;
63 volatile u32 VIDEO_BSCALING
;
64 volatile u32 BIOS_TICK_COUNT
;
65 volatile u32 VIDEO_VSYNC_POSITION
;
66 volatile u32 VIDEO_VSYNC_DIR
;
67 volatile u32 DVD_TRAY_STATE
;
76 /////////////////////////////////
77 // Superfunky i386 internal structures
79 typedef struct gdt_t
{
80 unsigned short m_wSize
__attribute__ ((packed
));
81 unsigned long m_dwBase32
__attribute__ ((packed
));
82 unsigned short m_wDummy
__attribute__ ((packed
));
83 } ts_descriptor_pointer
;
85 typedef struct { // inside an 8-byte protected mode interrupt vector
86 u16 m_wHandlerHighAddressLow16
;
89 u16 m_wHandlerLinearAddressHigh16
;
97 typedef struct tsHarddiskInfo
{ // this is the retained knowledge about an IDE device after init
98 unsigned short m_fwPortBase
;
99 unsigned short m_wCountHeads
;
100 unsigned short m_wCountCylinders
;
101 unsigned short m_wCountSectorsPerTrack
;
102 unsigned long m_dwCountSectorsTotal
; /* total */
103 unsigned char m_bLbaMode
; /* am i lba (0x40) or chs (0x00) */
104 unsigned char m_szIdentityModelNumber
[40];
105 unsigned char term_space_1
[2];
106 unsigned char m_szSerial
[20];
107 unsigned char term_space_2
[2];
108 char m_szFirmware
[8];
109 unsigned char term_space_3
[2];
110 unsigned char m_fDriveExists
;
111 unsigned char m_fAtapi
; // true if a CDROM, etc
112 enumDriveType m_enumDriveType
;
113 unsigned char m_bCableConductors
; // valid for device 0 if present
114 unsigned short m_wAtaRevisionSupported
;
115 unsigned char s_length
;
116 unsigned char m_length
;
117 unsigned char m_fHasMbr
;
118 unsigned short m_securitySettings
; //This contains the contents of the ATA security regs
121 /////////////////////////////////
122 // LED-flashing codes
123 // or these together as argument to I2cSetFrontpanelLed
130 I2C_LED_GREEN0
= 0x08,
131 I2C_LED_GREEN1
= 0x04,
132 I2C_LED_GREEN2
= 0x02,
133 I2C_LED_GREEN3
= 0x01
136 ///////////////////////////////
137 /* BIOS-wide error codes all have b31 set */
140 ERR_SUCCESS
= 0, // completed without error
142 ERR_I2C_ERROR_TIMEOUT
= 0x80000001, // I2C action failed because it did not complete in a reasonable time
143 ERR_I2C_ERROR_BUS
= 0x80000002, // I2C action failed due to non retryable bus error
145 ERR_BOOT_PIC_ALG_BROKEN
= 0x80000101 // PIC algorithm did not pass its self-test
148 /////////////////////////////////
149 // some Boot API prototypes
151 //////// BootPerformPicChallengeResponseAction.c
153 /* ---------------------------- IO primitives -----------------------------------------------------------
156 static __inline
void IoOutputByte(u16 wAds
, u8 bValue
) {
157 // __asm__ (" out %%al,%%dx" : : "edx" (dwAds), "al" (bValue) );
158 __asm__
__volatile__ ("outb %b0,%w1": :"a" (bValue
), "Nd" (wAds
));
161 static __inline
void IoOutputWord(u16 wAds
, u16 wValue
) {
162 // __asm__ (" out %%ax,%%dx " : : "edx" (dwAds), "ax" (wValue) );
163 __asm__
__volatile__ ("outw %0,%w1": :"a" (wValue
), "Nd" (wAds
));
166 static __inline
void IoOutputDword(u16 wAds
, u32 dwValue
) {
167 // __asm__ (" out %%eax,%%dx " : : "edx" (dwAds), "ax" (wValue) );
168 __asm__
__volatile__ ("outl %0,%w1": :"a" (dwValue
), "Nd" (wAds
));
172 static __inline u8
IoInputByte(u16 wAds
) {
175 __asm__
__volatile__ ("inb %w1,%0":"=a" (_v
):"Nd" (wAds
));
179 static __inline u16
IoInputWord(u16 wAds
) {
182 __asm__
__volatile__ ("inw %w1,%0":"=a" (_v
):"Nd" (wAds
));
186 static __inline u32
IoInputDword(u16 wAds
) {
189 __asm__
__volatile__ ("inl %w1,%0":"=a" (_v
):"Nd" (wAds
));
193 #define rdmsr(msr,val1,val2) \
194 __asm__ __volatile__("rdmsr" \
195 : "=a" (val1), "=d" (val2) \
198 #define wrmsr(msr,val1,val2) \
199 __asm__ __volatile__("wrmsr" \
201 : "c" (msr), "a" (val1), "d" (val2))
204 void BootPciInterruptEnable(void);
207 int BootPerformPicChallengeResponseAction(void);
208 // LED control (see associated enum above)
209 int I2cSetFrontpanelLed(u8 b
);
214 #define TRACE bprintf(__FILE__ " :%d\n\r",__LINE__);
219 typedef struct _LIST_ENTRY
{
220 struct _LIST_ENTRY
*m_plistentryNext
;
221 struct _LIST_ENTRY
*m_plistentryPrevious
;
224 void ListEntryInsertAfterCurrent(LIST_ENTRY
*plistentryCurrent
, LIST_ENTRY
*plistentryNew
);
225 void ListEntryRemove(LIST_ENTRY
*plistentryCurrent
);
227 ////////// BootPerformXCodeActions.c
229 int BootPerformXCodeActions(void);
231 #include "BootEEPROM.h"
232 #include "BootParser.h"
234 ////////// BootStartBios.c
236 void StartBios(CONFIGENTRY
*config
,int nActivePartition
, int nFATXPresent
,int bootfrom
);
237 int BootMenu(CONFIGENTRY
*config
,int nDrive
,int nActivePartition
, int nFATXPresent
);
239 ////////// BootResetActions.c
240 void ClearIDT (void);
241 void BootResetAction(void);
242 void BootCpuCache(bool fEnable
) ;
243 int printk(const char *szFormat
, ...);
244 void BiosCmosWrite(u8 bAds
, u8 bData
);
245 u8
BiosCmosRead(u8 bAds
);
248 ///////// BootPciPeripheralInitialization.c
249 void BootPciPeripheralInitialization(void);
250 void BootAGPBUSInitialization(void);
251 void BootDetectMemorySize(void);
252 extern void ReadPCIByte(unsigned int bus
, unsigned int dev
, unsigned intfunc
, unsigned int reg_off
, unsigned char *pbyteval
);
253 extern void WritePCIByte(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, unsigned char byteval
);
254 extern void ReadPCIDword(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, unsigned int *pdwordval
);
255 extern void WritePCIDword(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, unsigned int dwordval
);
256 extern void ReadPCIBlock(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, unsigned char *buf
, unsigned int nbytes
);
257 extern void WritePCIBlock(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, unsigned char *buf
, unsigned int nbytes
);
259 void PciWriteByte (unsigned int bus
, unsigned int dev
, unsigned int func
,
260 unsigned int reg_off
, unsigned char byteval
);
261 u8
PciReadByte(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
);
262 u32
PciWriteDword(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
, u32 dw
);
263 u32
PciReadDword(unsigned int bus
, unsigned int dev
, unsigned int func
, unsigned int reg_off
);
265 ///////// BootPerformPicChallengeResponseAction.c
267 int I2CTransmitWord(u8 bPicAddressI2cFormat
, u16 wDataToWrite
);
268 int I2CTransmitByteGetReturn(u8 bPicAddressI2cFormat
, u8 bDataToWrite
);
269 bool I2CGetTemperature(int *, int *);
270 void I2CModifyBits(u8 bAds
, u8 bReg
, u8 bData
, u8 bMask
);
274 extern tsHarddiskInfo tsaHarddiskInfo
[]; // static struct stores data about attached drives
275 int BootIdeInit(void);
276 int BootIdeReadSector(int nDriveIndex
, void * pbBuffer
, unsigned int block
, int byte_offset
, int n_bytes
);
277 int BootIdeBootSectorHddOrElTorito(int nDriveIndex
, u8
* pbaResult
);
278 int BootIdeAtapiAdditionalSenseCode(int nDrive
, u8
* pba
, int nLengthMaxReturn
);
279 int BootIdeSetTransferMode(int nIndexDrive
, int nMode
);
280 int BootIdeWaitNotBusy(unsigned uIoBase
);
281 bool BootIdeAtapiReportFriendlyError(int nDriveIndex
, char * szErrorReturn
, int nMaxLengthError
);
282 void BootIdeAtapiPrintkFriendlyError(int nDriveIndex
);
286 void BootStopUSB(void);
287 void BootStartUSB(void);
288 void USBGetEvents(void);
292 extern struct xpad_data XPAD_current
[4];
293 extern struct xpad_data XPAD_last
[4];
295 extern void wait_ms(u32 ticks
);
296 extern void wait_us(u32 ticks
);
297 extern void wait_smalldelay(void);
300 void * memcpy(void *dest
, const void *src
, size_t size
);
301 void * memset(void *dest
, int data
, size_t size
);
302 int memcmp(const void *buffer1
, const void *buffer2
, size_t num
);
303 int _strncmp(const char *sz1
, const char *sz2
, int nMax
);
304 char * strcpy(char *sz
, const char *szc
);
305 char * _strncpy (char * dest
, const char * src
, size_t n
);
306 void chrreplace(char *string
, char search
, char ch
);
308 #define printf printk
309 #define sleep wait_ms
313 void MemoryManagementInitialization(void * pvStartAddress
, u32 dwTotalMemoryAllocLength
);
314 void * malloc(size_t size
);
317 extern volatile int nCountI2cinterrupts
, nCountUnusedInterrupts
, nCountUnusedInterruptsPic2
, nCountInterruptsSmc
, nCountInterruptsIde
;
318 extern volatile bool fSeenPowerdown
;
320 ETS_OPEN_OR_OPENING
=0,
324 extern volatile TRAY_STATE traystate
;
327 extern void BootInterruptsWriteIdt(void);
329 int copy_swap_trim(unsigned char *dst
, unsigned char *src
, int len
);
330 void HMAC_SHA1( unsigned char *result
,
331 unsigned char *key
, int key_length
,
332 unsigned char *text1
, int text1_length
,
333 unsigned char *text2
, int text2_length
);
335 char *strrchr0(char *string
, char ch
);