void __grab_int_ctrl_break( void ) { if( __old_int_ctrl_break == 0 ) { #if defined(__WINDOWS_386__) __old_int_ctrl_break = _dos_getvect( CTRL_BRK_VEC ); TinySetVect( CTRL_BRK_VEC, (void (_WCNEAR *)(void))__int_ctrl_break_handler ); #elif defined( __386__ ) if( _IsPharLap() ) { __old_int_ctrl_break = pharlap_rm_getvect( CTRL_BRK_VEC ); __old_pm_int_ctrl_break = pharlap_pm_getvect( CTRL_BRK_VEC ); pharlap_setvect( CTRL_BRK_VEC, (pfun) (void (_WCNEAR *)(void))__int_ctrl_break_handler ); } else if( __DPMI_hosted() == 1 ) { DPMILockLinearRegion((long)__int_ctrl_break_handler, ((long)__restore_int23 - (long)__int_ctrl_break_handler)); __old_int_ctrl_break = DPMIGetRealModeInterruptVector( CTRL_BRK_VEC ); __old_pm_int_ctrl_break = DPMIGetPMInterruptVector( CTRL_BRK_VEC ); DPMISetPMInterruptVector( CTRL_BRK_VEC, __int_ctrl_break_handler ); } else { /* what it used to do */ __old_int_ctrl_break = _dos_getvect( CTRL_BRK_VEC ); _dos_setvect( CTRL_BRK_VEC, __int_ctrl_break_handler ); } #else __old_int_ctrl_break = _dos_getvect( CTRL_BRK_VEC ); _dos_setvect( CTRL_BRK_VEC, __int_ctrl_break_handler ); #endif if( __int23_exit == __null_int23_exit ) { __int23_exit = __restore_int_ctrl_break; } else if( __int23_exit == __restore_int23 ) { __int23_exit = __restore_int; } } }
void __restore_int_ctrl_break( void ) { if( __old_int_ctrl_break == 0 ) { return; } if( __int23_exit == __restore_int ) { __int23_exit = __restore_int23; } else if( __int23_exit == __restore_int_ctrl_break ) { __int23_exit = __null_int23_exit; } #if defined(__WINDOWS_386__) TinySetVect( CTRL_BRK_VEC, __old_int_ctrl_break ); #elif defined( __386__ ) if( _IsPharLap() ) { pharlap_rm_setvect( CTRL_BRK_VEC, __old_int_ctrl_break ); pharlap_pm_setvect( CTRL_BRK_VEC, __old_pm_int_ctrl_break ); } else if( __DPMI_hosted() == 1 ) { DPMISetRealModeInterruptVector( CTRL_BRK_VEC, __old_int_ctrl_break ); DPMISetPMInterruptVector( CTRL_BRK_VEC, __old_pm_int_ctrl_break ); } else { _dos_setvect( CTRL_BRK_VEC, __old_int_ctrl_break ); } #else _dos_setvect( CTRL_BRK_VEC, __old_int_ctrl_break ); #endif __old_int_ctrl_break = 0; }
void __restore_int23( void ) { if( __old_int23 == 0 ) { return; } if( __int23_exit == __restore_int ) { __int23_exit = __restore_int_ctrl_break; } else if( __int23_exit == __restore_int23 ) { __int23_exit = __null_int23_exit; } #if defined(__WINDOWS_386__) TinySetVect( 0x23, __old_int23 ); #elif defined( __386__ ) if( _IsPharLap() ) { pharlap_rm_setvect( 0x23, __old_int23 ); pharlap_pm_setvect( 0x23, __old_pm_int23 ); } else if( __DPMI_hosted() == 1 ) { DPMISetRealModeInterruptVector( 0x23, __old_int23 ); DPMISetPMInterruptVector( 0x23, __old_pm_int23 ); } else { /* this is what it used to do */ _dos_setvect( 0x23, __old_int23 ); } #else _dos_setvect( 0x23, __old_int23 ); #endif __old_int23 = 0; }
void R_TrapInit( void ) { //==================== int enable_excpt; enable_excpt = __EnableF77RTExceptionHandling(); if( enable_excpt ) { signal( SIGSEGV, AbnormalTerm ); signal( SIGILL, AbnormalTerm ); } #if !defined( __WINDOWS__ ) signal( SIGINT, BreakSignal ); #endif #if defined( __DOS__ ) if( __NonIBM ) { // Assume NEC BreakVector = 0x06; } CBSave = _dos_getvect( BreakVector ); _dos_setvect( BreakVector, BreakHandler ); #if defined( __386__ ) if( _IsPharLap() ) { CBRealSave = _dos_getrealvect( BreakVector ); _dos_setvectp( BreakVector, BreakHandler ); } #endif ISave = _dos_getvect( IntOverFlow ); _dos_setvect( IntOverFlow, IOvFlHandler ); ZSave = _dos_getvect( IntDivBy0 ); _dos_setvect( IntDivBy0, IDivZHandler ); #elif defined( __WINDOWS__ ) #if !defined( __386__ ) ISave = _dos_getvect( IntOverFlow ); _dos_setvect( IntOverFlow, IOvFlHandler ); ZSave = _dos_getvect( IntDivBy0 ); _dos_setvect( IntDivBy0, IDivZHandler ); #endif #elif defined( __OS2_386__ ) || defined( __NT__ ) signal( SIGBREAK, BreakSignal ); if( enable_excpt ) { signal( SIGIDIVZ, IDivZSignal ); signal( SIGIOVFL, IOvFlSignal ); } #elif defined( __OS2_286__ ) signal( SIGBREAK, BreakSignal ); DosSetVec( IntOverFlow, (PFN)IOvFlHandler, (PFN FAR *)&ISave ); DosSetVec( IntDivBy0, (PFN)IDivZHandler, (PFN FAR *)&ZSave ); #endif FPTrapInit(); }
_WCRTLINK void _dos_setvect( unsigned intnum, void (__interrupt _WCFAR *func)() ) { #if defined(__WINDOWS_386__) TinySetVect( intnum, (void _WCNEAR *) func ); #elif defined(__386__) if( _IsPharLap() ) { pharlap_setvect( intnum, func ); } else { /* DOS/4G style */ dos4g_setvect( intnum, func ); } #else _setvect( intnum, func ); #endif }
void __GrabFP87( void ) { #ifndef __WINDOWS__ if( _RWD_FPE_handler_exit != __Fini_FPE_handler ) { #ifdef __DOS_386__ if( !_IsPharLap() && ( __DPMI_hosted() == 1 )) { DPMILockLinearRegion((long)&__FPEHandlerStart_, ((long)&__FPEHandlerEnd_ - (long)&__FPEHandlerStart_)); } #endif __Init_FPE_handler(); _RWD_FPE_handler_exit = __Fini_FPE_handler; } #endif }
void __CommonInit( void ) /**************************/ { #if defined(__DOS_386__) && !defined(__OSI__) /* * If we are running under DOS/4G then we need to page lock interrupt * handlers (since we could be running under VMM). */ if (!_IsPharLap() && (__DPMI_hosted() == 1)) { DPMILockLinearRegion((long)&__GETDSStart_, ((long)&__GETDSEnd_ - (long)&__GETDSStart_)); } #endif }
size_t __LastFree( void ) /* used by nheapgrow to know about adjustment */ { frlptr p1; unsigned brk_value; if( __nheapbeg == NULL ) { /* no heap? can't have free blocks */ return( 0 ); } p1 = __nheapbeg->freehead.prev; /* point to last free block */ brk_value = (unsigned)((PTR)p1 + p1->len + TAG_SIZE ); #if defined(__DOS_EXT__) if( _IsPharLap() && !__X32VM) _curbrk = SegmentLimit(); /*19-feb-94*/ #endif if( brk_value == _curbrk ) { /* if last free block is at the end */ return( p1->len ); } return( 0 ); }
void R_TrapFini( void ) { //==================== #if defined( __DOS__ ) _dos_setvect( BreakVector, CBSave ); #if defined( __386__ ) if( _IsPharLap() ) { _dos_setrealvect( BreakVector, CBRealSave ); } #endif _dos_setvect( IntOverFlow, ISave ); _dos_setvect( IntDivBy0, ZSave ); #elif defined( __WINDOWS__ ) #if !defined( __386__ ) _dos_setvect( IntOverFlow, ISave ); _dos_setvect( IntDivBy0, ZSave ); #endif #elif defined( __OS2_286__ ) DosSetVec( IntOverFlow, (PFN)ISave, (PFN FAR *)&ISave ); DosSetVec( IntDivBy0, (PFN)ZSave, (PFN FAR *)&ZSave ); #endif FPTrapFini(); }
static unsigned short dos_get_code_page( void ) /*********************************************/ { if( _IsPharLap() ) { union REGPACK regs; memset( ®s, 0, sizeof( regs ) ); regs.w.ax = 0x6601; /* get extended country info */ intr( 0x21, ®s ); if( (regs.w.flags & 1) == 0 ) { return( regs.w.bx ); /* return active code page */ } } else if( _IsRational() ) { rm_call_struct dblock; memset( &dblock, 0, sizeof( dblock ) ); dblock.eax = 0x6601; /* get extended country info */ DPMISimulateRealModeInterrupt( 0x21, 0, 0, &dblock ); if( (dblock.flags & 1) == 0 ) { return( (unsigned short)dblock.ebx ); } } return( 437 ); /* return default */ }
int __ExpandDGROUP( unsigned amount ) { #if defined(__WINDOWS__) || defined(__WARP__) || defined(__NT__) \ || defined(__CALL21__) || defined(__RDOS__) // first try to free any available storage _nheapshrink(); return( __CreateNewNHeap( amount ) ); #else mheapptr p1; frlptr flp; unsigned brk_value; tag *last_tag; unsigned new_brk_value; void _WCNEAR *brk_ret; #if defined(__DOS_EXT__) if( !__IsCtsNHeap() ) { return( __CreateNewNHeap( amount ) ); // Won't slice either } // Rational non-zero based system should go through. #endif if( !__heap_enabled ) return( 0 ); if( _curbrk == ~1u ) return( 0 ); if( __AdjustAmount( &amount ) == 0 ) return( 0 ); #if defined(__DOS_EXT__) if( _IsPharLap() && !_IsFlashTek() ) { _curbrk = SegmentLimit(); } #endif new_brk_value = amount + _curbrk; if( new_brk_value < _curbrk ) { new_brk_value = ~1u; } brk_ret = __brk( new_brk_value ); if( brk_ret == (void _WCNEAR *)-1 ) { return( 0 ); } brk_value = (unsigned)brk_ret; if( brk_value > /*0xfff8*/ ~7u ) { return( 0 ); } if( new_brk_value <= brk_value ) { return( 0 ); } amount = new_brk_value - brk_value; if( amount - TAG_SIZE > amount ) { return( 0 ); } else { amount -= TAG_SIZE; } for( p1 = __nheapbeg; p1 != NULL; p1 = p1->next ) { if( p1->next == NULL ) break; if( (unsigned)p1 <= brk_value && ((unsigned)p1) + p1->len + TAG_SIZE >= brk_value ) { break; } } if( (p1 != NULL) && ((brk_value - TAG_SIZE) == (unsigned)( (PTR)p1 + p1->len) ) ) { /* we are extending the previous heap block (slicing) */ /* nb. account for the end-of-heap tag */ brk_value -= TAG_SIZE; amount += TAG_SIZE; flp = (frlptr) brk_value; /* adjust current entry in heap list */ p1->len += amount; /* fix up end of heap links */ last_tag = (tag *) ( (PTR)flp + amount ); last_tag[0] = END_TAG; } else { if( amount < sizeof( miniheapblkp ) + sizeof( frl ) ) { /* there isn't enough for a heap block (struct miniheapblkp) and one free block (frl) */ return( 0 ); } // Initializing the near heap if __nheapbeg == NULL, // otherwise, a new mini-heap is getting linked up p1 = (mheapptr)brk_value; p1->len = amount; flp = __LinkUpNewMHeap( p1 ); amount = flp->len; } /* build a block for _nfree() */ SET_MEMBLK_SIZE_USED( flp, amount ); ++p1->numalloc; /* 28-dec-90 */ p1->largest_blk = ~0; /* set to largest value to be safe */ _nfree( (PTR)flp + TAG_SIZE ); return( 1 ); #endif }