From 37d82a50b93991f63a91581eb5467642fffc1400 Mon Sep 17 00:00:00 2001 From: John Winans Date: Wed, 30 Mar 1994 11:03:24 +0000 Subject: [PATCH] added devLibA24Malloc, devLibA24Calloc, and devLibA24Free --- src/db/devLib.c | 72 +++++++++++++++++++++++++++++++++++++++++ src/vxWorks/db/devLib.c | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/src/db/devLib.c b/src/db/devLib.c index c0c846f83..9f259ccd7 100644 --- a/src/db/devLib.c +++ b/src/db/devLib.c @@ -65,6 +65,7 @@ static char *sccsID = "$Id$\t$Date$"; #include #include #include +#include #include #define devLibGlobal @@ -1231,3 +1232,74 @@ void *pLocation return SUCCESS; } +/****************************************************************************** + * + * The follwing may, or may not be present in the BSP for the CPU in use. + * + */ +void *sysA24Malloc(unsigned long size); +STATUS sysA24Free(void *pBlock); + +/****************************************************************************** + * + * Routines to use to allocate and free memory present in the A24 region. + * + ******************************************************************************/ + +static void * (*A24MallocFunc)(size_t) = NULL; +static void (*A24FreeFunc)(void *) = NULL; +int devLibA24Debug = 0; /* Debugging flag */ + +void *devLibA24Calloc(size_t size) +{ + void *ret; + + ret = devLibA24Malloc(size); + + if (ret == NULL) + return (NULL); + + memset(ret, 0x00, size); + return(ret); +} + +void *devLibA24Malloc(size_t size) +{ + SYM_TYPE stype; + static int UsingBSP = 0; + void *ret; + + if (devLibA24Debug) + printf("devLibA24Malloc(%d) entered\n", size); + + if (A24MallocFunc == NULL) + { + /* See if the sysA24Malloc() function is present. */ + if(symFindByName(sysSymTbl,"_sysA24Malloc", (char**)&A24MallocFunc,&stype)==ERROR) + { /* Could not find sysA24Malloc... use the malloc one and hope we are OK */ + A24MallocFunc = malloc; + A24FreeFunc = free; + } + else + { + if(symFindByName(sysSymTbl,"_sysA24Free", (char**)&A24FreeFunc, &stype) == ERROR) + { /* That's strange... we have malloc, but no free! */ + A24MallocFunc = malloc; + A24FreeFunc = free; + } + else + UsingBSP = 1; + } + } + ret = A24MallocFunc(size); + + if ((ret == NULL) && (UsingBSP)) + errMessage(S_dev_noMemory, "devLibA24Malloc ran out of A24 memory, try sysA24MapRam(size)"); + + return(ret); +} + +void devLibA24Free(void *pBlock) +{ + A24FreeFunc(pBlock); +} diff --git a/src/vxWorks/db/devLib.c b/src/vxWorks/db/devLib.c index c0c846f83..9f259ccd7 100644 --- a/src/vxWorks/db/devLib.c +++ b/src/vxWorks/db/devLib.c @@ -65,6 +65,7 @@ static char *sccsID = "$Id$\t$Date$"; #include #include #include +#include #include #define devLibGlobal @@ -1231,3 +1232,74 @@ void *pLocation return SUCCESS; } +/****************************************************************************** + * + * The follwing may, or may not be present in the BSP for the CPU in use. + * + */ +void *sysA24Malloc(unsigned long size); +STATUS sysA24Free(void *pBlock); + +/****************************************************************************** + * + * Routines to use to allocate and free memory present in the A24 region. + * + ******************************************************************************/ + +static void * (*A24MallocFunc)(size_t) = NULL; +static void (*A24FreeFunc)(void *) = NULL; +int devLibA24Debug = 0; /* Debugging flag */ + +void *devLibA24Calloc(size_t size) +{ + void *ret; + + ret = devLibA24Malloc(size); + + if (ret == NULL) + return (NULL); + + memset(ret, 0x00, size); + return(ret); +} + +void *devLibA24Malloc(size_t size) +{ + SYM_TYPE stype; + static int UsingBSP = 0; + void *ret; + + if (devLibA24Debug) + printf("devLibA24Malloc(%d) entered\n", size); + + if (A24MallocFunc == NULL) + { + /* See if the sysA24Malloc() function is present. */ + if(symFindByName(sysSymTbl,"_sysA24Malloc", (char**)&A24MallocFunc,&stype)==ERROR) + { /* Could not find sysA24Malloc... use the malloc one and hope we are OK */ + A24MallocFunc = malloc; + A24FreeFunc = free; + } + else + { + if(symFindByName(sysSymTbl,"_sysA24Free", (char**)&A24FreeFunc, &stype) == ERROR) + { /* That's strange... we have malloc, but no free! */ + A24MallocFunc = malloc; + A24FreeFunc = free; + } + else + UsingBSP = 1; + } + } + ret = A24MallocFunc(size); + + if ((ret == NULL) && (UsingBSP)) + errMessage(S_dev_noMemory, "devLibA24Malloc ran out of A24 memory, try sysA24MapRam(size)"); + + return(ret); +} + +void devLibA24Free(void *pBlock) +{ + A24FreeFunc(pBlock); +}