/** * @brief Setup the system * SystemInit() is called prior to the application and sets up system * clocking, memory, and any resources needed prior to the application * starting. * @return none */ void SystemInit(void) { #if defined(CORE_M3) || defined(CORE_M4) unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08; #if defined(__IAR_SYSTEMS_ICC__) extern void *__vector_table; *pSCB_VTOR = (unsigned int) &__vector_table; #elif defined(__CODE_RED) extern void *g_pfnVectors; *pSCB_VTOR = (unsigned int) &g_pfnVectors; #elif defined(__ARMCC_VERSION) extern void *__Vectors; *pSCB_VTOR = (unsigned int) &__Vectors; #endif #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif /* Setup system clocking and memory. This is done early to allow the application and tools to clear memory and use scatter loading to external memory. */ SystemSetupClocking(); SystemSetupMuxing(); SystemSetupMemory(); #endif }
/* Set up and initialize hardware prior to call to main */ void SystemInit(void) { #if defined(__CODE_RED) extern void(*const g_pfnVectors[]) (void); SCB->VTOR = (uint32_t) &g_pfnVectors; #else extern void *__Vectors; SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined(CORE_M4) #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif #endif #if !defined(__MULTICORE_M0SLAVE) && !defined(__MULTICORE_M4SLAVE) #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Board specific SystemInit */ Board_SystemInit(); #endif #endif }
/* this function initializes the platform with system level settings */ void platformInit(void) { SystemInit(); /* checks for presence of an FPU unit */ fpuInit(); clockInit(); vIOInit(); #if (USE_EXT_STATIC_MEM == YES) || (USE_EXT_DYNAMIC_MEM == YES) EMC_Init(); #endif #if (USE_EXT_FLASH == YES) // relocate vector table to internal ram // updates also VTOR relocIrqTable(); #endif }
/* Set up and initialize hardware prior to call to main */ void SystemInit(void) { unsigned int *pSCB_VTOR = (unsigned int *) 0xE000ED08; #if defined(__IAR_SYSTEMS_ICC__) extern void *__vector_table; *pSCB_VTOR = (unsigned int) &__vector_table; #elif defined(__CODE_RED) extern void *g_pfnVectors; *pSCB_VTOR = (unsigned int) &g_pfnVectors; #elif defined(__ARMCC_VERSION) extern void *__Vectors; *pSCB_VTOR = (unsigned int) &__Vectors; #endif #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Setup system clocking and muxing */ Board_SystemInit(); #endif }
/** * This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ WEAK void init_clocks( void ){ /** This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ //LPC54xx clock initialized in SystemInit(). #ifdef BOOTLOADER LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Enable RAM 2 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SRAM2); /* Board specific SystemInit */ Board_SystemInit(); //init pin muxing and clock. #endif LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe Chip_SYSCTL_PowerUp(PDRUNCFG_PD_IRC_OSC_EN|PDRUNCFG_PD_IRC_EN); /* Configure PIN0.21 as CLKOUT with pull-up, monitor the MAINCLK on scope */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21, IOCON_MODE_PULLUP | IOCON_FUNC1 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF); Chip_Clock_SetCLKOUTSource(SYSCTL_CLKOUTSRC_RTC, 1); Chip_Clock_EnableRTCOsc(); Chip_RTC_Init(LPC_RTC); Chip_RTC_Enable1KHZ(LPC_RTC); Chip_RTC_Enable(LPC_RTC); #endif }
/* * SystemInit() - Initialize the system */ void __section(SectionForBootstrapOperations) SystemInit(void) { #if !defined(CORE_M0) /* Initialize vector table in flash */ #if defined(__ARMCC_VERSION) extern void *__Vectors; SCB->VTOR = (unsigned int) &__Vectors; #elif defined(__IAR_SYSTEMS_ICC__) extern void *__vector_table; SCB->VTOR = (unsigned int) &__vector_table; #else /* defined(__GNUC__) and others */ extern void *g_pfnVectors; SCB->VTOR = (unsigned int) &g_pfnVectors; #endif #if 0 // defined(__FPU_PRESENT) && __FPU_PRESENT == 1 /* Initialize floating point */ fpuInit(); #endif SystemSetupPins(pre_clock_mux, COUNT_OF(pre_clock_mux)); /* Configure pins */ SystemSetupClock(); /* Configure processor and peripheral clocks */ SystemSetupPins(post_clock_mux, COUNT_OF(post_clock_mux)); /* Configure pins */ SystemSetupMemory(); /* Configure external memory */ #endif /* !defined(CORE_M0) */ }
CVMBool CVMthreadAttach(CVMThreadID *self, CVMBool orphan) { if (orphan) { self->taskID = taskIdSelf(); } else { assert(self->taskID == taskIdSelf()); } fpuInit(); if (!vxworksSyncInit(self)) { CVMdebugPrintf(("WARNING: CVMthreadAttach failed.\n")); return CVM_FALSE; } /* NOTE: taskVarAdd() creates a unique copy of the mySelf pointer for each task so that we can have a unique thread ID for each task: */ taskVarAdd(0, (int *)&mySelf); mySelf = self; { TASK_DESC desc; taskInfoGet(0, &desc); self->stackTop = desc.td_pStackLimit; } return CVM_TRUE; }
void kmain(MultibootInfo *info) { ASM("cli"); kernelStatus = KERNEL_RUNNING; initConsole(); kprintf("Successfully booted into 64-bit mode\n"); if (info->modsCount != 1) { panic("the initrd was not loaded"); }; kprintf_debug(" *** TO TRAP THE KERNEL *** \n"); kprintf_debug(" set r15=rip\n"); kprintf_debug(" set rip=%a\n", &trapKernel); kprintf_debug(" *** END OF INFO *** \n"); kprintf("Initializing the IDT... "); initIDT(); kprintf("%$\x02" "Done%#\n"); kprintf("Checking amount of memory... "); int memSize = info->memLower + info->memUpper; if (info->flags & 1) { kprintf("%$\x01%dMB%#\n", (memSize/1024)); } else { kprintf("%$\x04" "Failed%#\n"); panic("could not determine memory size"); }; if ((info->flags & (1 << 6)) == 0) { panic("no memory map from bootloader"); }; uint64_t mmapAddr = (uint64_t) info->mmapAddr + 0xFFFF800000000000; uint64_t mmapEnd = mmapAddr + info->mmapLen; kprintf("Memory map address: %a memory map size = %d\n", mmapAddr, info->mmapLen); MultibootMemoryMap *mmap = (MultibootMemoryMap*) mmapAddr; kprintf("Size\tBase\tLen\tType\n"); while ((uint64_t)mmap < mmapEnd) { kprintf("%d\t%a\t%d\t%d\n", mmap->size, mmap->baseAddr, mmap->len, mmap->type); mmap = (MultibootMemoryMap*) ((uint64_t) mmap + mmap->size + 4); }; MultibootModule *mod = (MultibootModule*) ((uint64_t) info->modsAddr + 0xFFFF800000000000); uint64_t end = (uint64_t) mod->modEnd + 0xFFFF800000000000; kprintf("Initializing memory allocation phase 1 (base=%a)... ", end); initMemoryPhase1(end); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the physical memory manager (%d pages)... ", (memSize/4)); initPhysMem(memSize/4, (MultibootMemoryMap*) mmapAddr, mmapEnd); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the ISP... "); ispInit(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing memory allocation phase 2... "); initMemoryPhase2(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the frame stack... "); initPhysMem2(); kprintf("%$\x02" "Done%#\n"); initModuleInterface(); kprintf("Getting ACPI info... "); acpiInit(); msrWrite(0x1B, 0xFEE00000 | (1 << 11) /*| (1 << 8)*/ ); apic->sivr = 0x1FF; kprintf("Initializing the FPU... "); fpuInit(); DONE(); kprintf("Initializing the VFS... "); vfsInit(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the initrdfs... "); initInitrdfs(info); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the procfs... "); initProcfs(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the devfs... "); initDevfs(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing PCI... "); pciInit(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the FS driver interface... "); initFSDrivers(); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the PIT... "); uint16_t divisor = 1193180 / 1000; // 1000 Hz outb(0x43, 0x36); uint8_t l = (uint8_t)(divisor & 0xFF); uint8_t h = (uint8_t)( (divisor>>8) & 0xFF ); outb(0x40, l); outb(0x40, h); kprintf("%$\x02" "Done%#\n"); kprintf("Initializing the APIC timer..."); ASM("sti"); apic->timerDivide = 3; apic->timerInitCount = 0xFFFFFFFF; sleep(35); apic->lvtTimer = 0; quantumTicks = 0xFFFFFFFF - apic->timerCurrentCount; apic->timerInitCount = 0; // put the timer in single-shot mode at the appropriate interrupt vector. apic->lvtTimer = I_APIC_TIMER; DONE(); kprintf("Initializing the scheduler and syscalls... "); //msrWrite(0xC0000080, msrRead(0xC0000080) | 1); //msrWrite(0xC0000081, ((uint64_t)8 << 32)); //msrWrite(0xC0000082, (uint64_t)(&_syscall_entry)); //msrWrite(0xC0000084, (1 << 9)); initSched(); // "Done" will be displayed by initSched(), and then kmain2() will be called. };