void _init( void ) { pcb_t *pcb; context_t *context; status_t stat; /* ** BOILERPLATE CODE - taken from basic framework ** ** Initialize interrupt stuff. */ __init_interrupts(); // IDT and PIC initialization /* ** Console I/O system. */ c_io_init(); c_setscroll( 0, 7, 99, 99 ); c_puts_at( 0, 6, "================================================================================" ); /* ** 20103-SPECIFIC CODE STARTS HERE */ /* ** Initialize various OS modules */ c_puts( "Starting module init: " ); _q_init(); // must be first _pcb_init(); _stack_init(); _sio_init(); _syscall_init(); _sched_init(); _clock_init(); //_pci_init(); build_lapic_info(); _paging_init(); c_puts( "\n" ); c_puts(" Ending init\n"); initSMP(); /* ** Create the initial system ESP ** ** This will be the address of the next-to-last ** longword in the system stack. */ _system_esp = ((uint32_t *) ( (&_system_stack) + 1)) - 2; /* ** Install the ISRs */ __install_isr( INT_VEC_TIMER, _isr_clock ); __install_isr( INT_VEC_SYSCALL, _isr_syscall ); __install_isr( INT_VEC_SERIAL_PORT_1, _isr_sio ); /* ** Create the initial process ** ** Code mostly stolen from _sys_fork() and _sys_exec(); ** if either of those routines change, SO MUST THIS!!! ** ** First, get a PCB and a stack */ stat = _pcb_alloc( &pcb ); if( stat != E_SUCCESS ) { _kpanic( "_init", "first pcb alloc status %s", stat ); } stat = _stack_alloc( &(pcb->stack) ); if( stat != E_SUCCESS ) { _kpanic( "_init", "first stack alloc status %s", stat ); } /* ** Next, set up various PCB fields */ pcb->pid = PID_INIT; pcb->ppid = PID_INIT; pcb->prio = PRIO_MAXIMUM; /* ** Set up the initial process context. */ context = _setup_stack( pcb->stack, (uint32_t) init ); // Finally, set up the process' ESP context->esp = (uint32_t) context; // Make it the "current" process _current = pcb; _current->context = context; /* ** Starting up the idle routine is the responsibility ** of the initial user process. */ /* ** Turn on the SIO receiver (the transmitter will be turned ** on/off as characters are being sent) */ _sio_enable( SIO_RX ); /* ** END OF 20103-SPECIFIC CODE ** ** Finally, report that we're all done. */ c_puts( "System initialization complete.\n" ); }
void _init( void ) { pcb_t *pcb; /* ** BOILERPLATE CODE - taken from basic framework ** ** Initialize interrupt stuff. */ __init_interrupts(); // IDT and PIC initialization // Ignore the 0x2A interrupt which happens when removing or inserting a // flash drive. __install_isr( 0x2A, _ignore_isr ); /* ** Console I/O system. */ c_io_init(); c_clearscreen(); #ifdef ISR_DEBUGGING_CODE c_setscroll( 0, 7, 99, 99 ); c_puts_at( 0, 6, "================================================================================" ); #endif /* ** 20123-SPECIFIC CODE STARTS HERE */ /* ** Initialize various OS modules ** ** Note: the clock, SIO, and syscall modules also install ** their ISRs. */ c_puts( "Module init: " ); _q_init(); // must be first _pcb_init(); _stack_init(); _sio_init(); _sys_init(); _sched_init(); _clock_init(); _pci_init(); _disk_init(); _net_init(); c_puts( "\n" ); c_puts("Launching the shell. Please be patient\n"); __delay(1000); c_clearscreen(); /* ** Create the initial system ESP ** ** This will be the address of the next-to-last ** longword in the system stack. */ _system_esp = ((uint32_t *) ( (&_system_stack) + 1)) - 2; /* ** Create the initial process ** ** Code mostly stolen from _sys_fork(); if that routine ** changes, SO MUST THIS!!! */ // allocate a PCB and stack pcb = _create_process( NULL ); if( pcb == NULL ) { _kpanic( "_init", "init() creation failed", FAILURE ); } // initialize the stack with the standard context pcb->context = _create_stack( pcb->stack ); if( pcb->context == NULL ) { _kpanic( "_init", "init() stack setup failed", FAILURE ); } // define the entry point for init() pcb->context->eip = (uint32_t) init; // set up various PCB fields pcb->pid = pcb->ppid = PID_INIT; // next PID is initially 1 pcb->prio = PRIO_HIGH; pcb->children = 1000; // remember this PCB for use in reparenting orphan processes _init_pcb = pcb; // make it the first process _schedule( pcb ); _dispatch(); /* ** Turn on the SIO receiver (the transmitter will be turned ** on/off as characters are being sent) */ _sio_enable( SIO_RX ); /* ** END OF 20123-SPECIFIC CODE ** ** Finally, report that we're all done. */ c_puts( "System initialization complete.\n" ); }
int main( void ) { c_puts( "Clearing screen\n"); c_clearscreen(); _interrupt_init(); _pci_alloc_device_list(&pciDevices); status_t status = _pci_scan(pciDevices); if(status != E_SUCCESS){ c_printf("PCI bus scan failed with error 0x%x\n", status); while(1); } c_printf("Detected %d PCI devices\n", pciDevices->size); //bcm_driver_init(pciDevices); status = i8255x_driver_init(pciDevices); c_io_init(); //HACK: To avoid updating c_io for the moment if(status != E_SUCCESS){ c_printf("ERROR: Failed to initialize network card!\n"); } else{ c_printf("SUCCESS: Network card initialized\n"); } pci_device_t* dev = pciDevices->first; struct ethframe frame; frame.header.proto = htons(0xcafe); int j=0; for(; j<ETH_ALEN; j++){ frame.header.dest[j] = 0xff; frame.header.source[j] = j; } while(dev!=NULL){ char scan = c_getchar(); switch(scan){ case 0x34: //Left arrow if(dev->prev == NULL){ dev=pciDevices->last; } else{ dev = dev->prev; } c_clearscreen(); c_moveto(0,1); _pci_print_config(dev); break; case 0x36: //Right arrow if(dev->next == NULL){ dev = pciDevices->first; } else{ dev = dev->next; } c_clearscreen(); c_moveto(0,1); _pci_print_config(dev); break; case 0x0A: //Enter key //Mask device's interrupt //_pci_mask_inta(dev); c_clearscreen(); //_pci_read_config(dev->address, &dev->config); c_moveto(0, 24); c_printf("> "); readline((char*)frame.data); c_moveto(0,24); c_printf("> Sending... "); c_moveto(0,24); i8255x_driver_transmit((uint8_t*)&frame, sizeof(struct ethframe), 0); c_moveto(0,1); c_moveto(0,24); c_printf("> "); //_pci_print_config(dev); //c_printf("MASKED"); break; default: c_printf_at(78, 0, "%x", (int)scan); break; } //__delay(2); } return( 0 ); }
void _init( void ) { Pcb *pcb; // // BOILERPLATE CODE - taken from basic framework // // Initialize interrupt stuff. // __init_interrupts(); // IDT and PIC initialization // // I/O system. // c_io_init(); c_clearscreen(); c_setscroll( 0, 7, 99, 99 ); c_puts_at( 0, 6, "================================================================================" ); c_puts( "Init: " ); // // 20073-SPECIFIC CODE STARTS HERE // // // Initialize various OS modules // _init_queues(); // must be first _init_memory(); _init_processes(); _init_stacks(); _init_sio(); _init_clock(); _init_syscalls(); c_puts( "\n" ); // // Create the initial process // // Code mostly stolen from _sys_fork() and _sys_exec(); // if either of those routines change, SO MUST THIS!!! // // // First, get a PCB and a stack // pcb = _get_pcb(); if( pcb == 0 ) { _kpanic( "_init - can't allocate first pcb" ); } pcb->stack = _get_stack(); if( pcb->stack == 0 ) { _kpanic( "_init - can't allocate first stack" ); } // // Next, set up various PCB fields // pcb->pid = g_next_pid++; pcb->prio = PRI_NORMAL; // // Set up the initial process context. // // See _sys_exec() for an explanation of how this works. // pcb->context = _setup_stack( pcb->stack, (unsigned int) first_main ); // Initialize memory segment. Equals that of the kernel's in the GDT. pcb->seg.mem.offset = 0x0; pcb->seg.mem.length = 0xFFFFFFFF; // Initialize LDT entries for this PCB // This is a "kernel" process, so we will just copy over the // descriptors from the GDT and stick them into this process' LDT. __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) ); __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) ); // Allocate a slot in the GDT for the LDT descriptor, // and initialize this PCB's LDT register variable. pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0); // Initialize the LDT descriptor located in the GDT __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr), (u32_t)&(pcb->seg.ldt), sizeof(ldt_t), ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT ); // // Give it to the scheduler. // _schedule( pcb ); // // Do it all again for the idle process. // pcb = _get_pcb(); if( pcb == 0 ) { _kpanic( "_init - can't allocate idle pcb" ); } pcb->stack = _get_stack(); if( pcb->stack == 0 ) { _kpanic( "_init - can't allocate idle stack" ); } pcb->pid = g_next_pid++; pcb->prio = PRI_MINIMUM; pcb->context = _setup_stack( pcb->stack, (unsigned int) idle_main ); pcb->seg.mem.offset = 0x0; pcb->seg.mem.length = 0xFFFFFFFF; __copy_gdt_entry( &(pcb->seg.ldt.cseg), (GDT_INDEX(GDT_CODE)) ); __copy_gdt_entry( &(pcb->seg.ldt.dseg), (GDT_INDEX(GDT_DATA)) ); pcb->seg.ldtr = SEL_SETINDEX(_gdt_alloc()) | SEL_GDT | SEL_RPL(0); __gdt_set_entry( SEL_GETINDEX(pcb->seg.ldtr), (u32_t)&(pcb->seg.ldt), sizeof(ldt_t), ACC_PRES | ACC_DPL(0) | ACC_SYS | SYS_LDT ); _schedule( pcb ); // // Dispatch the initial current process // _dispatch(); // // END OF 20073-SPECIFIC CODE // // Finally, report that we're all done. // c_puts( "System initialization complete.\n" ); }