/*------- Include --------*/ //See DINK32 V12.0 User's Guide Appendix G on using //DINK's Dynamic Functions such as printf. #include "../../dinkusr.h" /*------- Prototypes -------*/ void main(); /*------- Externs ---------*/ extern void agentBoot(); extern void cacheDisable(); extern void pciConfigOutWord(); extern void pciConfigOutHalfWord(); extern void memcpy(); extern void mmuSetup(); extern void pgmreturn(); /*------ Typedefs ---------*/ typedef unsigned long ULONG; /*------- Defines ---------*/ #define DATA_CACHE 0xFFFFBFFF //to turn off D-Cache #define swapBytes(x) ((((x) & 0x000000ff) << 24)|\ (((x) & 0x0000ff00) << 8) |\ (((x) & 0x00ff0000) >> 8) |\ (((x) & 0xff000000) >> 24)) /*------- C Functions --------*/ /****************************************************** * main: routine to setup on the Agent a 1M Outbound * Translation Window starting at 0xFFF00000 to * translate to 0x00000000. The agent boot up code * is copied to the Host local memory space at * 0x00000100. The Agent is then allowed to begin * fetching instructions from the reset vector * 0xFFF00100, which is translated to 0x00000100 * in the Host's local memory space. * * input: none * output: none *****************************************************/ void main() { //Set up transfer base in order to use DINK's prinf command. //See DINK32 V12.0 User's Guide Appendix G on using //DINK's Dynamic Functions such as printf. set_up_transfer_base(); //Setup DBAT for PCI Space mmuSetup(); //Disable d-cache so agentBoot code will go to memory not cache cacheDisable(DATA_CACHE); //Copy agentBoot code to Host ram at 0x100 memcpy((ULONG)0x100, (ULONG)&agentBoot, (ULONG)0x100); ULONG PCSRBAR = 0xFC100000; ULONG* OTWR = (ULONG*)(PCSRBAR + 0x308); ULONG* OMBAR = (ULONG*)(PCSRBAR + 0x300); //Setup a valid PCSRBAR on Agent pciConfigOutWord(0x14, PCSRBAR); //Enable agent PCI Command Register to respond to memory //accesses before modifying the OTWR and OMBAR on the Agent pciConfigOutHalfWord(0x4, 2); //Setup the Agent's Outbound Translation Window and //Outbound Base Address *OTWR = swapBytes(19); // base = 0, size = 1M *OMBAR = swapBytes(0xFFF00000); //0xFFF00100 is reset address //Enable the agent PCI Command Register as a bus master pciConfigOutHalfWord(0x4, 6); //Wait for Agent to fetch and execute agent boot code while (1){ ULONG* msg = (ULONG*)0x4c04; if (*msg == 777) { printf("Agent: boot success.\n"); break; } } printf("Returning to DINK via exception handler.\n"); pgmreturn(); //return to dink via exception handler } /**************** end main ***************************/