예제 #1
0
파일: initialize.c 프로젝트: Str8AWay/os
/**
 * Intializes all XINU data structures and devices.
 * @return OK if everything is initialized successfully
 */
local sysinit(void)
{
	int     i = 0;
	pcb     *ppcb = NULL;               /* process control block pointer */
	semblk  *psem = NULL;               /* semaphore block pointer       */
	memblk  *pmem = NULL;               /* memory block pointer          */

	/* Initialize system variables */
	/* Count this NULLPROC as the first process in the system. */
	numproc   = 1;

    /* Initialize free memory list */
	freelist.next   = pmem = (memblk *) roundmb(minheap);
	freelist.length = (ulong)truncew((ulong)platform.maxaddr - (ulong)minheap);
	pmem->next      = NULL;
	pmem->length    = freelist.length;

	/* Initialize process table */
	for (i = 0; i < NPROC; i++)
		{ proctab[i].state = PRFREE; }

	/* initialize null process entry */
	ppcb = &proctab[NULLPROC];
	ppcb->state        = PRCURR;
	strncpy(ppcb->name, "prnull", 7);
	ppcb->stkbase      = (void *)&end;
	ppcb->stkptr       = NULL;
	ppcb->stklen       = (ulong)minheap - (ulong)&end;
	ppcb->priority     = 0;
	currpid            = NULLPROC;

	/* Initialize semaphores */
	for (i = 0; i < NSEM; i++)
	{
		psem = &semtab[i];
		psem->state = SFREE;
		psem->count = 0;
		psem->queue = newqueue();
	}

	/* initialize bounded-waiting mutex subsystems */
	mutexInit();

	/* initialize process ready list */
	readylist = newqueue();

#if RTCLOCK
	/* initialize real time clock */
	clockinit();
#endif

	return OK;
}
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL int sysinit()
{
	int	i,j;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > (char *)HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew(((unsigned) HOLESTART -
	     		 (unsigned)&end));
        mptr->mlen -= 4;

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND -
	      		NULLSTK);
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
	

	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#endif

	pci_init();	/* PCI */

	mon_init();	/* init monitor */
//	ripinit();

#ifdef NDEVS
	for (i=0 ; i<NDEVS ; i++ ) {	    
	    init_dev(i);
	}
#endif
	buf_init();
	return(OK);
}
예제 #3
0
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL
sysinit()
{
	static	long	currsp;
	int	i,j;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

#ifdef X__COM32__
	puts_com32("sysinit()\n");
#endif
	
#ifdef __COM32__
	/* initialize free memory list */
	kprintf("com32topmem %d\n", (unsigned long) com32topmem);
	com32topmem = com32topmem - 1024*64; /* !!! we need some space fort this code */
	maxaddr =  (char*) com32topmem;
	kprintf("maxaddr     %d\n", (unsigned long) maxaddr);
	memlist.mnext = mptr = (struct mblock *) roundmb(&end);
	mptr->mnext = 0;
	mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
#else
	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew((unsigned) HOLESTART -
	     		 (unsigned)&end - 4);

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew(maxaddr - HOLEEND - NULLSTK);
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
#endif
	
#ifdef X__COM32__
	puts_com32("sysinit() free memory list done\n");
#endif
	
	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;

#ifdef X__COM32__
	puts_com32("sysinit() proctab done\n");
#endif
	
	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;

	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

#ifdef X__COM32__
	puts_com32("sysinit() semaphores done\n");
#endif
	
#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#ifdef __COM32__
	puts_com32("sysinit()  memory marking done\n");
#endif
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#ifdef __COM32__
	puts_com32("sysinit() rtc done\n");
#endif
#endif

#ifdef NDEVS
	for ( i=0 ; i<NDEVS ; i++ ) {
	    init(i);
	}
#ifdef __COM32__
	puts_com32("sysinit() devs done\n");
#endif	
#endif

#ifdef	NNETS
	netinit();
#ifdef __COM32__
	puts_com32("sysinit() netinit() done\n");
#endif
#endif

	return(OK);
}
예제 #4
0
//------------------------------------------------------------------------
//  sysinit  --  initialize all Xinu data structures and devices
//------------------------------------------------------------------------
static int
sysinit(void)
{
	static int (*nulluserp)() = &nulluser;
	static uword *nulluserpp = (uword *)&nulluserp;

	struct pentry *pptr;
	struct mblock *mptr;

	// initialize system variables
	numproc = 0;
	nextproc = NPROC - 1;
	nextsem = NSEM - 1;
	nextqueue = NPROC;	// q[0..NPROC-1] are processes

	// initialize free memory list
	memlist.mnext = mptr = (struct mblock *)roundew(&end);
	mptr->mnext = (struct mblock *)NULL;
	mptr->mlen = (uword)truncew((uintptr_t)maxaddr - NULLSTK - (uintptr_t)&end);

	// initialize process table
	for (int k = 0; k < NPROC; k++)
		proctab[k].pstate = PRFREE;

	// initialize null process entry
	pptr = &proctab[NULLPROC];
	pptr->pstate = PRCURR;
	pptr->pprio = 0;
	strlcpy(pptr->pname, "prnull", PNMLEN);
	pptr->plimit = ((char *)maxaddr) - NULLSTK - sizeof(uword);
	pptr->pbase = (char *)maxaddr;
	*((uword *)pptr->pbase) = MAGIC;
	pptr->paddr = (char *)(*nulluserpp);
	pptr->phasmsg = FALSE;
	pptr->pargs = 0;
	currpid = NULLPROC;

	// initialize semaphores
	for (int k = 0; k < NSEM; k++) {
		struct sentry *sptr = &semaph[k];
		sptr->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	// initialize ready list
	rdyhead = newqueue();
	rdytail = 1 + rdyhead;

	// initialize memory marking
	_mkinit();

	// initialize r.t.clock
	clkinit();

	// initialize disk buffers
	dskdbp = mkpool(DBUFSIZ, NDBUFF);
	dskrbp = mkpool(DREQSIZ, NDREQ);

	// initialize devices
	for (int k = 0; k < NDEVS; k++)
		init(k);

	return OK;
}
예제 #5
0
/*------------------------------------------------------------------------
 *  sysinit  --  initialize all Xinu data structeres and devices
 *------------------------------------------------------------------------
 */
LOCAL
sysinit()
{
	static	long	currsp;
	int	i,j, avail;
	struct	pentry	*pptr;
	struct	sentry	*sptr;
	struct	mblock	*mptr;
	SYSCALL pfintr();

	/*********************/
	set_evec(14, pfintr);

	pptr = &proctab[NULLPROC]; /* initialize null process entry */
	/*********************/
	

	numproc = 0;			/* initialize system variables */
	nextproc = NPROC-1;
	nextsem = NSEM-1;
	nextqueue = NPROC;		/* q[0..NPROC-1] are processes */

	/* initialize free memory list */
	/* PC version has to pre-allocate 640K-1024K "hole" */
	if (maxaddr+1 > HOLESTART) {
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = (struct mblock *)HOLEEND;
		mptr->mlen = (int) truncew(((unsigned) HOLESTART -
	     		 (unsigned)&end));
        mptr->mlen -= 4;

		mptr = (struct mblock *) HOLEEND;
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - HOLEEND -
	      		NULLSTK);
/*
		mptr->mlen = (int) truncew((unsigned)maxaddr - (4096 - 1024 ) *  4096 - HOLEEND - NULLSTK);
*/
	} else {
		/* initialize free memory list */
		memlist.mnext = mptr = (struct mblock *) roundmb(&end);
		mptr->mnext = 0;
		mptr->mlen = (int) truncew((unsigned)maxaddr - (int)&end -
			NULLSTK);
	}
	

	for (i=0 ; i<NPROC ; i++)	/* initialize process table */
		proctab[i].pstate = PRFREE;


#ifdef	MEMMARK
	_mkinit();			/* initialize memory marking */
#endif

#ifdef	RTCLOCK
	clkinit();			/* initialize r.t.clock	*/
#endif

	mon_init();     /* init monitor */

#ifdef NDEVS
	for (i=0 ; i<NDEVS ; i++ ) {	    
	    init_dev(i);
	}
#endif

	pptr = &proctab[NULLPROC];	/* initialize null process entry */
	pptr->pstate = PRCURR;
	for (j=0; j<7; j++)
		pptr->pname[j] = "prnull"[j];
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK;
	pptr->pbase = (WORD) maxaddr - 3;
/*
	pptr->plimit = (WORD)(maxaddr + 1) - NULLSTK - (4096 - 1024 )*4096;
	pptr->pbase = (WORD) maxaddr - 3 - (4096-1024)*4096;
*/
	pptr->pesp = pptr->pbase-4;	/* for stkchk; rewritten before used */
	*( (int *)pptr->pbase ) = MAGIC;
	pptr->paddr = (WORD) nulluser;
	pptr->pargs = 0;
	pptr->pprio = 0;
	currpid = NULLPROC;
	
	
	for (i=0 ; i<NSEM ; i++) {	/* initialize semaphores */
		(sptr = &semaph[i])->sstate = SFREE;
		sptr->sqtail = 1 + (sptr->sqhead = newqueue());
	}

	rdytail = 1 + (rdyhead=newqueue());/* initialize ready list */

	init_bsm();
	init_frm();

	kprintf("initialize page tables for null process\n");
	init_glb_pgs(glb_pg_tbl_frm_mapping);
	// init pg dir for proc 0
	frame_t *pg_dir = get_free_frame();
	init_pg_dir(pg_dir, NULLPROC);
	pptr->pdbr = pg_dir->frm_num;
	pptr->pd = pg_dir;
	return(OK);
}