/*===========================================================================
                              OEMHeap.c

  OEM REFERENCE HEAP ROUTINES
  
  This file contains a reference implementation of a heap.
    
        Copyright © 1999-2003 QUALCOMM Incorporated.
               All Rights Reserved.
            QUALCOMM Proprietary/GTDR
===========================================================================*/

#include "OEMFeatures.h"

#ifdef OEMHEAP

#include "OEMHeap.h"

//Supervisor mode heap. All MALLOCs in SVC mode allocate
//from this buffer. OEMs need to fine tune this size.
#if !defined(OEM_STATIC_SVC_HEAP_SIZE)
#define  OEM_STATIC_SVC_HEAP_SIZE      65536
#endif //OEM_STATIC_SVC_HEAP_SIZE


//--------------------------------------------------
//   SVC memory
//--------------------------------------------------

#if __ARMCC_VERSION >= 120000 // ADS 1.2
# pragma arm section zidata ="protected_svc_heapbytes"
#endif /* if __ARMCC_VERSION >= 120000 // ADS 1.2 */
// 
// Supervisor Heap - Must Modify this size to fit the size on the phone!
//
#if defined(OEM_STATIC_SVC_HEAP_SIZE)
static char   gSVCHeapBytes[OEM_STATIC_SVC_HEAP_SIZE];
#endif //OEM_STATIC_SVC_HEAP_SIZE

void  *gpSVCHeapBytes = NULL;
uint32 gSVCHeapBytesLen = 0;

#if __ARMCC_VERSION >= 120000 // ADS 1.2
# pragma arm section
#endif /* if __ARMCC_VERSION >= 120000 // ADS 1.2 */


//--------------------------------------------------
//   User memory
//--------------------------------------------------
#if __ARMCC_VERSION >= 120000 // ADS 1.2
# pragma arm section zidata ="unprotected_brew_heapbytes"
#endif /* if __ARMCC_VERSION >= 120000 // ADS 1.2 */
// 
// Static Heap - Must Modify this size to fit the size on the phone!
//
#ifndef FEATURE_DYNAMIC_OEM_HEAP
static char   guHeapBytes[OEM_STATIC_HEAP_SIZE];
#endif // !FEATURE_DYNAMIC_OEM_HEAP

void * gpuHeapBytes   = NULL;
uint32 guHeapBytesLen = 0;

#if __ARMCC_VERSION >= 120000 // ADS 1.2
# pragma arm section
#endif /* if __ARMCC_VERSION >= 120000 // ADS 1.2 */




int OEM_GetHeapInitBytes(void **ppHeapBytes, uint32 *puHeapBytesLen)
{
   if(BRIDLE_IS_ENABLED())
   {
      if(BRIDLE_IS_IN_SVC_MODE())
      {
         //--------------------------------------------------
         //   SVC memory
         //--------------------------------------------------
      #if defined(OEM_STATIC_SVC_HEAP_SIZE)
         *ppHeapBytes    = gSVCHeapBytes;
         *puHeapBytesLen = OEM_STATIC_SVC_HEAP_SIZE;
      #else
         *ppHeapBytes    = gpSVCHeapBytes;
         *puHeapBytesLen = gSVCHeapBytesLen;
      #endif
         return SUCCESS;
      }
   }
   //--------------------------------------------------
   //   User memory
   //--------------------------------------------------
#ifdef FEATURE_DYNAMIC_OEM_HEAP
   *ppHeapBytes    = gpuHeapBytes;
   *puHeapBytesLen = guHeapBytesLen;
#else
   *ppHeapBytes    = guHeapBytes;
   *puHeapBytesLen = OEM_STATIC_HEAP_SIZE;
#endif

   return SUCCESS;

}

#endif /* #ifdef OEMHEAP */
