New version of ldpp
This commit is contained in:
161
src/libvxWorks/ldpp_new.cc
Normal file
161
src/libvxWorks/ldpp_new.cc
Normal file
@@ -0,0 +1,161 @@
|
||||
|
||||
/*
|
||||
* $Log$
|
||||
* Revision 1.2 1996/09/16 21:56:03 jhill
|
||||
* added several compiler support functions and updated to gcc 2.7.2
|
||||
*
|
||||
* Revision 1.1 1996/01/29 17:05:58 jbk
|
||||
* Added the simple program to allow loading of C++ object modules.
|
||||
*
|
||||
* Revision 1.1.1.1 1994/12/12 16:07:06 hideos
|
||||
* Version 2 of hideos.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Author: Jim Kowalkowski
|
||||
Date: 6/94
|
||||
*/
|
||||
|
||||
#include <vxWorks.h>
|
||||
#include <vme.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <symLib.h>
|
||||
#include <ioLib.h>
|
||||
#include <sysSymTbl.h>
|
||||
#include <sysLib.h>
|
||||
#include <moduleLib.h>
|
||||
#include <usrLib.h>
|
||||
#include <a_out.h>
|
||||
#include <taskLib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void cpp_main(void);
|
||||
MODULE_ID ldpp (int syms, BOOL noAbort, char *name);
|
||||
void* __builtin_new(size_t);
|
||||
void* __builtin_vec_new(size_t);
|
||||
void __builtin_delete (void *);
|
||||
void __builtin_vec_delete(void *);
|
||||
void __pure_virtual(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef void (*func_ptr) (void);
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/*
|
||||
C++ loader for vxWorks, it runs constructors and such
|
||||
*/
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
MODULE_ID ldpp (int syms, BOOL noAbort, char *name)
|
||||
{
|
||||
MODULE_ID ret;
|
||||
|
||||
ret = ld(syms,noAbort,name);
|
||||
if(ret) cpp_main();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void cpp_main(void)
|
||||
{
|
||||
SYM_TYPE stype;
|
||||
func_ptr *ctorlist;
|
||||
|
||||
if( symFindByName(sysSymTbl,"___CTOR_LIST__",
|
||||
(char**)&ctorlist, &stype)==OK)
|
||||
{
|
||||
/*
|
||||
* this code was copied from gbl-ctors.h
|
||||
*
|
||||
* Change the __CTOR_LIST__ reference to ctorlist when copying
|
||||
* the code.
|
||||
*/
|
||||
|
||||
#if __GNUC__ == 2
|
||||
#if __GNUC_MINOR__ == 5
|
||||
/* DO_GLOBAL_CTORS_BODY for gcc 2.5.8 */
|
||||
do {
|
||||
func_ptr *p;
|
||||
for (p = ctorlist + 1; *p; )
|
||||
(*p++) ();
|
||||
} while (0);
|
||||
#else
|
||||
#if __GNUC_MINOR__ == 7
|
||||
/* DO_GLOBAL_CTORS_BODY for gcc 2.7.2 */
|
||||
do {
|
||||
unsigned long nptrs = (unsigned long) ctorlist[0];
|
||||
unsigned i;
|
||||
if (nptrs == (unsigned long)-1)
|
||||
for (nptrs = 0; ctorlist[nptrs + 1] != 0; nptrs++);
|
||||
for (i = nptrs; i >= 1; i--)
|
||||
ctorlist[i] ();
|
||||
} while (0);
|
||||
#else
|
||||
/* You_must_get_the_DO_GLOBAL_CTORS_BODY_for_this_compiler_version */
|
||||
#error You_must_get_the_DO_GLOBAL_CTORS_BODY_for_this_compiler_version
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
/*
|
||||
* remove the symbol so that this code isnt run again
|
||||
*/
|
||||
if(symRemove(sysSymTbl,"___CTOR_LIST__",stype)!=OK)
|
||||
{
|
||||
printf("ctor list just diappeared! - that sucks.\n");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void* __builtin_new(size_t sz)
|
||||
{
|
||||
void* p;
|
||||
|
||||
if(sz==0u) sz=1u;
|
||||
|
||||
p=(void*)malloc(sz);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void __builtin_delete (void *ptr)
|
||||
{
|
||||
if(ptr) free(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* __pure_virtual()
|
||||
* joh - 9-5-96
|
||||
*/
|
||||
void __pure_virtual(void)
|
||||
{
|
||||
printf("A pure virtual function was called\n");
|
||||
taskSuspend(taskIdSelf());
|
||||
}
|
||||
|
||||
/*
|
||||
* __builtin_vec_delete()
|
||||
* joh - 9-5-96
|
||||
*/
|
||||
void __builtin_vec_delete(void *ptr)
|
||||
{
|
||||
__builtin_delete(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* __builtin_vec_new()
|
||||
* joh - 9-5-96
|
||||
*/
|
||||
void* __builtin_vec_new(size_t sz)
|
||||
{
|
||||
return __builtin_new (sz);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user