/*
 This include file is used for the global memory map on the board. 
 It is referenced when building the MMU tables.                 

 The areas are defined as below.

	# Interrupt vectors
	# Processor Exception Dump Area
	# Cache Inhibited Memory
	#	- DXB Descriptors 
	#	- PQ Command Queue
	#	- 
	# PQ Code
	# PQ Data
	# PQ Stack
	# PQ Data Level One table
	# PQ Code Level One Table 1st - 4Meg
	# PQ Data Level Two table 1st - 4Meg
	# PQ Data Level Two table 2nd - 4Meg (Possibly reserved) 
	# PQ Data Level Two table IMMR Table
	# Main Body Code
	# Main Body Data
	# Cases described below:

	The memory maps are split up into four cases. 
	They are:
		Case 1: 
			- 603 not present 
			- DXB Slave mode
		Case 2:
			- 603 present, PTE of 64K, Stack of 32K
			- DXB Slave Mode
		Case 3:
			- 603 present, PTE of 64K, Stack of 32K
			- DXB Master Mode
		Case 4:
			- 603 not present
			- DXB Master Mode

	The memory can be 4-8Meg, so the top of memory is defined by the 
	BIOS and read from there. The defines below are for the size of the
	area and should be subtracted from the top of memory value.  

*/

/*	For each case the memory map is defined below:
*/	


#define MEMCONFIGCASE14MEGNO603SLAVE	0
#define MEMCONFIGCASE24MEG603SLAVE	1
#define MEMCONFIGCASE34MEG603MASTER	2 
#define MEMCONFIGCASE44MEGNO603MASTER	3
#define MEMCONFIGCASE58MEGNO603SLAVE	4
#define MEMCONFIGCASE68MEG603SLAVE	5
#define MEMCONFIGCASE78MEG603MASTER	6
#define MEMCONFIGCASE88MEGNO603MASTER	7
#define MEMCONFIGMAX			8


#define PQ603ENONCACHEDSHAREDSPACE 0x00002000
#define MAXMEMSIZE		   0x00800000
#define FOURMEGOFMEMORY		   0x00400000
#define EIGHTMEGOFMEMORY	   0x00800000
#define TOPOF4MEGOFMEMORY	   0x00400000
#define TOPOF8MEGOFMEMORY	   0x00800000


#define LITTLEENDIANFOURMEGOFMEMORY	   0x00004000
#define LITTLEENDIANEIGHTMEGOFMEMORY	   0x00008000

#define SLAVE			   0

#define SLAVEMODEEVENTBUFFERSIZE   0x00020000
#define SLAVEMODECOMMANDBUFFERSIZE 0x00020000
#define PTE603ETABLESIZEBYTES	   0x00010000
#define	STACKSIZE603E		   0x00008000
	
#define	CASE1MEMMAPEVENTBUFFER	 SLAVEMODEEVENTBUFFERSIZE
#define CASE1MEMMAPCOMMANDBUFFER (CASE1MEMMAPEVENTBUFFER + SLAVEMODECOMMANDBUFFERSIZE) 
#define CASE2MEMMAPEVENTBUFFER	 SLAVEMODEEVENTBUFFERSIZE

#define CASE2MEMMAPCOMMANDBUFFER (CASE2MEMMAPEVENTBUFFER + SLAVEMODECOMMANDBUFFERSIZE)

#define CASE2MEMMAP603EPTETABLE	 (CASE2MEMMAPCOMMANDBUFFER + PTE603ETABLESIZEBYTES)

#define CASE2MEMMAP603ESTACK	 (CASE2MEMMAP603EPTETABLE + STACKSIZE603E)

#define CASE2MEMMAP603ESTACKINIT (CASE2MEMMAP603ESTACK - STACKSIZE603E - 4) 

#define CASE3MEMMAP603EPTETABLE  PTE603ETABLESIZEBYTES

#define	CASE3MEMMAP603ESTACK	 (PTE603ETABLESIZEBYTES + STACKSIZE603E)

#define CASE3MEMMAP603ESTACKINIT (CASE3MEMMAP603ESTACK - STACKSIZE603E - 4)


#define CASE6MEMMAPEVENTBUFFER	 SLAVEMODEEVENTBUFFERSIZE

#define CASE6MEMMAPCOMMANDBUFFER (CASE6MEMMAPEVENTBUFFER + SLAVEMODECOMMANDBUFFERSIZE)

#define CASE6MEMMAP603EPTETABLE	 (CASE6MEMMAPCOMMANDBUFFER + (PTE603ETABLESIZEBYTES *2))

#define CASE6MEMMAP603ESTACK	 (CASE6MEMMAP603EPTETABLE + STACKSIZE603E)

#define CASE6MEMMAP603ESTACKINIT (CASE6MEMMAP603ESTACK - STACKSIZE603E - 4) 

#define CASE7MEMMAP603EPTETABLE  (PTE603ETABLESIZEBYTES * 2)

#define	CASE7MEMMAP603ESTACK	 ((PTE603ETABLESIZEBYTES * 2) + STACKSIZE603E)

#define CASE7MEMMAP603ESTACKINIT (CASE7MEMMAP603ESTACK - STACKSIZE603E - 4)



typedef struct {
        long    eventbufferlocation ;
        long    commandbufferlocation ;
        long    ptetablelocation ;
        long    ec603stacklocation ;
	long	memsize ;
	long    maindatabodyend ;
} MemoryConfigTable ;

#if 0
#ifndef SIMULATION	
MemoryConfigTable MemConfig[MEMCONFIGMAX] = {   
			// 4-Meg Case 1
                      {TOPOF4MEGOFMEMORY - (CASE1MEMMAPEVENTBUFFER),
                       TOPOF4MEGOFMEMORY - (CASE1MEMMAPCOMMANDBUFFER),
		       0,
                       0,
		       0x400000 },
			// 4-Meg Case 2
		      {TOPOF4MEGOFMEMORY - (CASE2MEMMAPEVENTBUFFER),
 		       TOPOF4MEGOFMEMORY - (CASE2MEMMAPCOMMANDBUFFER),
                       TOPOF4MEGOFMEMORY - (CASE2MEMMAP603EPTETABLE),
                       TOPOF4MEGOFMEMORY - (CASE2MEMMAP603ESTACK),
		       0x400000},
			// 4-Meg Case 3
                      {0, 
		       0,
		       TOPOF4MEGOFMEMORY - (CASE3MEMMAP603EPTETABLE),
                       TOPOF4MEGOFMEMORY - (CASE3MEMMAP603ESTACKINIT),
		       0x400000},
			// 4-Meg Case 4
		      {0,
		       0,
                       0,
                       0,
		       0x400000},
			// 8-Meg Case 1
		      {TOPOF8MEGOFMEMORY - (CASE1MEMMAPEVENTBUFFER),
                       TOPOF8MEGOFMEMORY - (CASE1MEMMAPCOMMANDBUFFER),
		       0, 
		       0,
		       0x800000},
			// 8-Meg Case 2
                      {TOPOF8MEGOFMEMORY - (CASE2MEMMAPEVENTBUFFER),
		       TOPOF8MEGOFMEMORY - (CASE2MEMMAPCOMMANDBUFFER),
		       TOPOF8MEGOFMEMORY - (CASE2MEMMAP603EPTETABLE),
                       TOPOF8MEGOFMEMORY - (CASE2MEMMAP603ESTACKINIT),
	               0x800000},
			// 8-Meg Case 3
                      {0,
                       0,
                       TOPOF8MEGOFMEMORY - (CASE3MEMMAP603EPTETABLE),
                       TOPOF8MEGOFMEMORY - (CASE3MEMMAP603ESTACKINIT),
		       0x800000},
			// 8-Meg Case 4 
                      {0,
                       0,
                       0,
                       0,
		       0x800000}
		};                      
#endif
#endif

// Memory Map for the PQ Kernel
/*
#	- 
# 0x3000	PQ Code
#		PQ Data
# 		PQ Stack
# 		PQ Data Level One table
# 		PQ Code Level One Table 1st - 4Meg
# 		PQ Data Level Two table 1st - 4Meg
# 		PQ Data Level Two table 2nd - 4Meg (Possibly reserved) 
# 		PQ Data Level Two table IMMR Table
*/
#define LEVELTWOTABLESIZE	0x1000
#define LEVELONETABLESIZE	0x1000
#define PQMICROKERNELSTACKSIZE	0x8000

#ifdef GDB

// 16K boundry
#define MICROKERNELTOPOFMEMORY	0x00030000
// 0x0002F000
#define PQLEVELTWODATATABLEIMMR	(MICROKERNELTOPOFMEMORY     - LEVELTWOTABLESIZE)
// 0x0002E000
#define PQLEVELTWODATATABLE8MEG	(PQLEVELTWODATATABLEIMMR    - LEVELTWOTABLESIZE)
// 0x0002D000
#define PQLEVELTWODATATABLE4MEG	(PQLEVELTWODATATABLE8MEG	   - LEVELTWOTABLESIZE)
// 0x0002C000
#define	PQLEVELTWOCODETABLE	(PQLEVELTWODATATABLE4MEG	   - LEVELTWOTABLESIZE)
// 0x0002B000
#define	PQLEVELONECODETABLE	(PQLEVELTWOCODETABLE	   - LEVELTWOTABLESIZE)
// 0x0002A000
#define PQLEVELONEDATATABLE	(PQLEVELONECODETABLE	   - LEVELONETABLESIZE)
// 0x00028000
#define PQRESERVED8K_1		(PQLEVELONEDATATABLE	   - (2 * LEVELONETABLESIZE))

//
// 0x00028000 
// 16K boundry.
// 

#else

// 16K boundry
#define MICROKERNELTOPOFMEMORY	0x0001C000
// 0x0001B000
#define PQLEVELTWODATATABLEIMMR	(MICROKERNELTOPOFMEMORY    - LEVELTWOTABLESIZE)
// 0x0001A000
#define PQLEVELTWODATATABLE8MEG	(PQLEVELTWODATATABLEIMMR   - LEVELTWOTABLESIZE)
// 0x00019000
#define PQLEVELTWODATATABLE4MEG	(PQLEVELTWODATATABLE8MEG   - LEVELTWOTABLESIZE)
// 0x00018000
#define	PQLEVELTWOCODETABLE		(PQLEVELTWODATATABLE4MEG   - LEVELTWOTABLESIZE)
// 0x00017000
#define	PQLEVELONECODETABLE		(PQLEVELTWOCODETABLE	   - LEVELTWOTABLESIZE)
// 0x00016000
#define PQLEVELONEDATATABLE		(PQLEVELONECODETABLE	   - LEVELONETABLESIZE)
// 0x00014000
#define PQRESERVED8K_1			(PQLEVELONEDATATABLE	   - (2 * LEVELONETABLESIZE))
// 0x00014000 
// 16K boundry.
// 



#endif

#define	PQSTACKINIT		(PQRESERVED8K_1    - \
				PQMICROKERNELSTACKSIZE + \
				PQMICROKERNELSTACKSIZE - 4)

#define	DXBCOMMANDLOCATION	0x2000
#define	DXBEVENTLOCATION	0x2100

#define PQTO603ECONFIGQUEUE	0x00002500
#define	TOHOSTQUEUE			0x00002700

#define PLX603EADDRESS		0xFF000000

#define PQPLXLOCATION		0xFFC00000
#define PQCONTROLSTATUSLOCATION 0xFFB00000
#define PQINTR860LOCATION  	0xFFA00000

#define PQMICROKERNELCODESTART	0x00004000
#define PQMICROKERNELDATASTART  0x0000C000

#define	PQMICROKERNELCODEEND	0x00008000
#define PQMICROKERNELDATAEND	0x00010000

#if GDB
#define MAINCODEBODYSTART	0x00030000
#else
#define MAINCODEBODYSTART	0x0001C000
#endif 

#define MAINCODEBODYEND		0x000FFFFF
#define MAINDATABODYSTART	0x00100000
#define MAINDATABODYEND		0x00400000

#define PPC603eSTARTUPLOCATION  0x00000028 
#define PPC603eCOMMANDLOCATION 	0x0000002C
#define PPC603eSTARTCOMMAND	0x00000001
#define PPC603eSTACKPTR		0x00003000

#define BIOSPPC603ePRESENT	0x00000020
#define BIOSBOARDMEMORYSIZE	0x0000000C

// Non-Cached Space Memory Locations 
#define	PPCDXBCOMMANDSTRUCTURELOCATION	0x2000 
#define	PPCDXBEVENTSTRUCTURELOCATION	0x2100
#define PPCSHAREDRAMSTRUCTURE		0x2F00
#define PPCHOSTINITSTRUCTURE		0x2E00
