/** * Intializes all Xinu data structures and devices. * @return OK if everything is initialized successfully */ static int sysinit(void) { int i; struct thrent *thrptr; /* thread control block pointer */ struct memblock *pmblock; /* memory block pointer */ /* Initialize system variables */ /* Count this NULLTHREAD as the first thread in the system. */ thrcount = 1; /* Initialize free memory list */ memheap = roundmb(memheap); platform.maxaddr = truncmb(platform.maxaddr); memlist.next = pmblock = (struct memblock *)memheap; memlist.length = (uint)(platform.maxaddr - memheap); pmblock->next = NULL; pmblock->length = (uint)(platform.maxaddr - memheap); /* Initialize thread table */ for (i = 0; i < NTHREAD; i++) { thrtab[i].state = THRFREE; } /* initialize null thread entry */ thrptr = &thrtab[NULLTHREAD]; thrptr->state = THRCURR; thrptr->prio = 0; strlcpy(thrptr->name, "prnull", TNMLEN); thrptr->stkbase = (void *)&_end; thrptr->stklen = (ulong)memheap - (ulong)&_end; thrptr->stkptr = 0; thrptr->memlist.next = NULL; thrptr->memlist.length = 0; thrcurrent = NULLTHREAD; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semtab[i].state = SFREE; semtab[i].queue = queinit(); } /* Initialize monitors */ for (i = 0; i < NMON; i++) { montab[i].state = MFREE; } /* Initialize buffer pools */ for (i = 0; i < NPOOL; i++) { bfptab[i].state = BFPFREE; } /* initialize thread ready list */ readylist = queinit(); #if SB_BUS backplaneInit(NULL); #endif /* SB_BUS */ #if RTCLOCK /* initialize real time clock */ clkinit(); #endif /* RTCLOCK */ #ifdef UHEAP_SIZE /* Initialize user memory manager */ { void *userheap; /* pointer to user memory heap */ userheap = stkget(UHEAP_SIZE); if (SYSERR != (int)userheap) { userheap = (void *)((uint)userheap - UHEAP_SIZE + sizeof(int)); memRegionInit(userheap, UHEAP_SIZE); /* initialize memory protection */ safeInit(); /* initialize kernel page mappings */ safeKmapInit(); } } #endif #if USE_TLB /* initialize TLB */ tlbInit(); /* register system call handler */ exceptionVector[EXC_SYS] = syscall_entry; #endif /* USE_TLB */ #if NMAILBOX /* intialize mailboxes */ mailboxInit(); #endif #if NDEVS for (i = 0; i < NDEVS; i++) { devtab[i].init((device*)&devtab[i]); } #endif #ifdef WITH_USB usbinit(); #endif #if NVRAM nvramInit(); #endif #if NNETIF netInit(); #endif #if GPIO gpioLEDOn(GPIO_LED_CISCOWHT); #endif return OK; }
/** * Intializes all Xinu data structures and devices. * @return OK if everything is initialized successfully */ static int sysinit(void) { int i; void *userheap; /* pointer to user memory heap */ struct thrent *thrptr; /* thread control block pointer */ device *devptr; /* device entry pointer */ struct sement *semptr; /* semaphore entry pointer */ struct memblock *pmblock; /* memory block pointer */ struct bfpentry *bfpptr; /* Initialize system variables */ /* Count this NULLTHREAD as the first thread in the system. */ thrcount = 1; kprintf("variable i in this function is at 0x%x\r\n", &i); kprintf("this function sysinit is at 0x%x\r\n", &sysinit); kprintf("_start is at 0x%x\r\n", _start); kprintf("_end is at (the end) at 0x%x\r\n", &_end); kprintf("readylist is at 0x%x\r\n", &readylist); kprintf("kputc is at 0x%x\r\n", &kputc); kprintf("NTHREAD is %d\r\n", NTHREAD); kprintf("memheap is 0x%x\r\n", memheap); /* Initialize free memory list */ memheap = roundmb(memheap); platform.maxaddr = truncmb(platform.maxaddr); kprintf("platform.maxaddr is 0x%x\r\n", platform.maxaddr); memlist.next = pmblock = (struct memblock *)memheap; memlist.length = (uint)(platform.maxaddr - memheap); pmblock->next = NULL; pmblock->length = (uint)(platform.maxaddr - memheap); /* Initialize thread table */ for (i = 0; i < NTHREAD; i++) { thrtab[i].state = THRFREE; } kprintf("thrtab is at 0x%x, size %d\r\n", thrtab, sizeof(thrtab)); /* initialize null thread entry */ thrptr = &thrtab[NULLTHREAD]; thrptr->state = THRCURR; thrptr->prio = 0; strncpy(thrptr->name, "prnull", 7); thrptr->stkbase = (void *)&_end; thrptr->stklen = (ulong)memheap - (ulong)&_end; thrptr->stkptr = 0; thrptr->memlist.next = NULL; thrptr->memlist.length = 0; thrcurrent = NULLTHREAD; kprintf("&_end is 0x%x\n", &_end); /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { semptr = &semtab[i]; semptr->state = SFREE; semptr->count = 0; semptr->queue = queinit(); } kprintf("NPOOL is %d\n", NPOOL); /* Initialize buffer pools */ for (i = 0; i < NPOOL; i++) { bfpptr = &bfptab[i]; bfpptr->state = BFPFREE; } kprintf("calling queinit() for readylist\r\n"); /* initialize thread ready list */ readylist = queinit(); #if SB_BUS backplaneInit(NULL); #endif /* SB_BUS */ #if RTCLOCK /* initialize real time clock */ kprintf("Clock being initialized.\r\n" ); clkinit(); #endif /* RTCLOCK */ #ifdef UHEAP_SIZE /* Initialize user memory manager */ userheap = stkget(UHEAP_SIZE); if (SYSERR != (int)userheap) { userheap = (void *)((uint)userheap - UHEAP_SIZE + sizeof(int)); memRegionInit(userheap, UHEAP_SIZE); /* initialize memory protection */ safeInit(); /* initialize kernel page mappings */ safeKmapInit(); } #else userheap = NULL; #endif /* UHEAP_SIZE */ #if USE_TLB /* initialize TLB */ tlbInit(); /* register system call handler */ exceptionVector[EXC_SYS] = syscall_entry; #endif /* USE_TLB */ #if NMAILBOX /* intialize mailboxes */ mailboxInit(); #endif #if NDEVS for (i = 0; i < NDEVS; i++) { if (!isbaddev(i)) { devptr = (device *)&devtab[i]; (devptr->init) (devptr); } } #endif #if 0 #if NVRAM nvramInit(); #endif kprintf("SO MUCH MORE NOT done with sysinit()\r\n"); #if NNETIF netInit(); #endif kprintf("NOT done with sysinit()\r\n"); #if GPIO gpioLEDOn(GPIO_LED_CISCOWHT); #endif #endif kprintf("done with sysinit()\r\n"); return OK; }