char *InitSys( void ) { SEL sel_global; SEL sel_local; USHORT rc; if( MaxBaud == 0 ) { MaxBaud = 3; /* 19200 -- see table */ } rc = DosGetInfoSeg( &sel_global, &sel_local ); if( rc != 0 ) return( TRP_OS2_no_info ); GInfoSeg = MK_FP( sel_global, 0 ); LInfoSeg = MK_FP( sel_local, 0 ); rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, LInfoSeg->tidCurrent ); if( rc != 0 ) return( TRP_OS2_cannot_set_thread_priority ); ReadBuffAdd = 0; ReadBuffRemove = 0; ReadSemaphore = 0; rc = DosCreateThread( Reader, &ReaderId, ReaderStack+READER_STACKSIZE ); if( rc != 0 ) return( TRP_OS2_cannot_create_helper_thread ); rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, ReaderId ); if( rc != 0 ) return( TRP_OS2_cannot_set_thread_priority ); CurrentBaud = -1; return( NULL ); }
void runsys() { word apt, i; procaddr father; for (i = 0; i < MAXPROCESS; i++ ) /* initialize process descriptors */ { process[ i ].used = FALSE; /* not used */ process[ i ].mark = -1; /* initial mark for processes */ process[ i ].M = NULL; /* memory not allocated */ process[ i ].hash = NULL; } process[ 0 ].M = M; /* always contains code */ dispoff = VIRTSC-(lastprot+1); /* DISPLAY offset in process object */ disp2off = dispoff-(lastprot+1); /* indirect DISPLAY offset */ ready = qinit(); /* initialize Round-Robin queue */ ranset(); /* init pseudo-random no. generator */ #if OS2 { SEL gsel, lsel; DosGetInfoSeg(&gsel, &lsel); ginf = MAKEPGINFOSEG(gsel); } #endif if (!remote) /* create main process */ { father.node = 0; /* dummy DL for generated process */ father.pix = 0; father.mark = 0; thispix = 0; /* current process index */ thisp = &process[ thispix ]; /* current process descr pointer */ initprocess((word) 0, (word) MAINBLOCK, &father); mainprog = thisp->prochead; /* am of main */ c1 = thisp->c1; /* pointers to current object */ c2 = thisp->c2; ic = thisp->ic; /* instruction counter */ param = thisp->param; /* parameter vector */ apt = mainprog+M[ mainprog ]; /* LWA+1 of main */ display = apt+dispoff; /* DISPLAY in main */ display2 = apt+disp2off; /* indirect DISPLAY in main */ mnoff = 2; /* offset of variable mainprog */ storevirt(thisp->procref, mainprog+mnoff); /* init variable main */ M[ apt+STATSL ]++; /* flag main included in SL chain */ thisp->status = STOPPED; activate(thispix); /* activate main process */ } else /* remote */ { thispix = 1; /* a dirty trick: set junk current */ thisp = &process[ thispix ]; /* process for first transfer() */ } /* (must save 'context' somewhere) */ #if DLINK net_attention(); #endif }
char *InitSys() { SEL global; SEL local; int i; DosGetInfoSeg( &global, &local ); GInfoSeg = MK_FP( global, 0 ); PortsFound = 0; for( i = 0; i < NUM_ELTS( PortTest ); ++i ) { AccessPorts( PortTest[i], PortTest[i] ); if( CheckForPort( i, 0x55 ) && CheckForPort( i, 0xaa ) ) { PortAddress[ PortsFound++ ] = PortTest[ i ]; } FreePorts( PortTest[i], PortTest[i] ); } return( 0 ); }
void get_config_files( void ) /***************************/ { int drive_name; #ifdef __OS2__ SEL gbl_seg; SEL lcl_seg; PGINFOSEG gbl; DosGetInfoSeg( &gbl_seg, &lcl_seg ); gbl = MK_FP( gbl_seg, 0 ); techoutput( "OS/2 Version %d.%d%c\n", gbl->uchMajorVersion, gbl->uchMinorVersion, gbl->chRevisionLetter); drive_name = gbl->bootdrive + 'A' - 1; #else union REGS regs; char *comspec; regs.h.ah = 0x30; intdos( ®s, ®s ); techoutput( "DOS Version %d.%d\n", regs.h.al, regs.h.ah ); /* Get Drive that user booted off of */ if( regs.h.al >= 0x04 ) { regs.w.ax = 0x3305; intdos( ®s, ®s ); drive_name = regs.h.dl + 'A' - 1; } else { comspec = getenv( "COMSPEC" ); if( comspec != NULL ) { drive_name = toupper( *comspec ); } else { return; } } #endif dump_files( drive_name ); }
int _OS2Main( char far *stklow, char far * stktop, unsigned envseg, unsigned cmdoff ) /*************************************************/ { cmdoff = cmdoff; /* supress warnings */ envseg = envseg; stktop = stktop; /* set up global variables */ #if defined(__SW_BD) _STACKTOP = 0; _curbrk = _dynend = (unsigned)&end; stklow = NULL; #else _STACKTOP = FP_OFF( stktop ); _curbrk = _dynend = _STACKTOP; #endif DosGetHugeShift( (PUSHORT)&_HShift ); DosGetMachineMode( (PBYTE)&_osmode ); { unsigned short version; DosGetVersion( (PUSHORT)&version ); _osmajor = version >> 8; _osminor = version & 0xff; } #if defined(__SW_BD) _LpPgmName = ""; _LpCmdLine = ""; #else /* copy progname and arguments to bottom of stack */ { char far *src; char far *pgmp; src = MK_FP( envseg, cmdoff ); _LpPgmName = stklow; /* back up from the ao: pointer to the eo: pointer (see OS/2 2.0 docs)*/ for( pgmp = src - 1; *--pgmp != '\0'; ); ++pgmp; while( *stklow++ = *pgmp++ ); while( *src ) ++src; ++src; _LpCmdLine = stklow; while( *stklow++ = *src++ ); } #endif #if defined(__SW_BM) { SEL globalseg; SEL localseg; DosGetInfoSeg( &globalseg, &localseg ); _threadid = MK_FP( localseg, offsetof( LINFOSEG, tidCurrent ) ); if( __InitThreadProcessing() == NULL ) __fatal_runtime_error( "Not enough memory", 1 ); #if defined(__SW_BD) { unsigned i; unsigned j; j = __MaxThreads; for( i = 1; i <= j; i++ ) { __SetupThreadProcessing( i ); } } #else __SetupThreadProcessing( 1 ); #endif _STACKLOW = (unsigned)stklow; } #else _nothread = getpid(); _threadid = &_nothread; _STACKLOW = (unsigned)stklow; /* set bottom of stack */ #endif // { /* removed JBS 99/11/10 */ // // make sure the iomode array is of the proper length // // this needs to be done before the InitRtns // extern void __grow_iomode(int); // if( _osmode == OS2_MODE ) { // __grow_iomode( 100 ); // } // } __InitRtns( 255 ); #ifdef __SW_BD { int status; status = setjmp( JmpBuff ); if( status == 0 ) return( _CMain() ); return( RetCode ); } #else return( _CMain() ); #endif }
/* * netinitancbs - init async ncbs * * inits semaphores etc in async ncb pool * */ void netinitancbs(void) { register struct ncb_a *ncbp; /* pointer to each ncb */ register int i; /* temp index */ #ifndef NT int rc; /* return code */ union farptr global_seg; /* pointer to GDT info segment */ union farptr local_seg; /* pointer to LDT info segment */ char NEAR *sem_mask = "\\SEM\\NCB%05x.%03x"; #include "..\h\packon.h" struct ldt_info_seg { int ldti_pid; /* current process id */ int ldti_ppid; /* parrent process id */ int ldti_priority; /* priority of current thread */ int ldti_thread; /* current thread id */ int ldti_screengrp; /* current screengroup */ int ldti_subscreengrp; /* current subscreengroup */ int ldti_forground; /* current process is in forground */ }; #include "..\h\packoff.h" struct ldt_info_seg FAR *ldt_info_p; char sem_name[20]; lockncbpool(); if (async_ncbs_inited) { unlockncbpool(); return; } rc = DosGetInfoSeg( (PSEL) &global_seg.lp.lp_seg, /* addr to return segment value */ (PSEL) &local_seg.lp.lp_seg); /* addr to return segment value */ if (rc) { fprintf(stderr, "GETINFOSEG failed (%d)\n", rc); exit ( rc ); } local_seg.lp.lp_offset = 0; ldt_info_p = (struct ldt_info_seg FAR *) local_seg.fp; for (ncbp=&asyncncbs[0], i=0; ncbp < &asyncncbs[num_async_ncbs]; ncbp++, i++) { ncbp->ncb_status = NCB_FREE; /* starts out free */ sprintf(sem_name, sem_mask, ldt_info_p->ldti_pid, i); #ifdef DEBUG1 printf("creating semaphore %s\n", sem_name); #endif rc = DosCreateSem( (unsigned int) 1, /* non exclusive ownership of semaphore */ (PHSYSSEM) &ncbp->ncb_sem, /* place to return sem handle */ (char FAR *) &sem_name[0]); /* name for semaphore */ if (rc) { fprintf(stderr, "CREATESEM \"%s\" failed (%d)\n", sem_name, rc); exit ( rc ); } ncbp->ncb_sem_a = ncbp->ncb_sem; /* save away semaphore */ ncbp->ncb_seqno = 0L; /* none as yet */ #ifdef DEBUG1 printf("ncbp is 0x%x, semaphore handle is 0x%lx, saved handle is 0x%lx\n", ncbp, ncbp->ncb_sem, ncbp->ncb_sem_a); #endif } async_ncbs_inited = 1; unlockncbpool(); #else // // NT Pool Initialization - Create pool locking semaphore // if (NULL == (async_ncb_pool_sem = CreateSemaphore ( NULL, 1, 1, NULL ) ) ) { fprintf(stderr, "Semaphore create failed (%d)\n", GetLastError()); exit (GetLastError()); } lockncbpool(); if (async_ncbs_inited) { unlockncbpool(); return; } // // Create an event for each NCB // for (ncbp=&asyncncbs[0], i=0; ncbp < &asyncncbs[num_async_ncbs]; ncbp++, i++) { ncbp->ncb_status = NCB_FREE; /* starts out free */ if ( NULL == (ncbp->ncb_event = CreateEvent ( NULL, TRUE, // manual reset FALSE, // initially not signalled NULL ) ) ) { fprintf(stderr, "Create NCB event failed (%d)\n", GetLastError ()); exit ( GetLastError() ); } ncbp->ncb_sem_a = ncbp->ncb_event; /* save away event handle */ ncbp->ncb_seqno = 0L; /* none as yet */ } async_ncbs_inited = 1; unlockncbpool(); #endif }