Example #1
0
void kmain(void)
{

	init_bss();
	init_ro();

	setup_kernel_memory();
	setup_pages();
	setup_ints();
	setup_tss();
	setup_paging();
	setup_faults();
	setup_fs();
	setup_syscalls();

	init_devs();

	char vendor[12];
	if (has_cpuid()) {
		cpuid_string(0, vendor);
		dprintf("CPU Vendor ID: %s\n");
	}

	fexec("/prgm/start", 0, NULL, NULL);
	start_scheduler();

	asm volatile ("sti");
	asm volatile ("hlt");

	/* We should never reach this */
	assert(0);
}
Example #2
0
void boot(void)
{
	// note: function changes rsp, local stack variables can't be practically used
	register char *temp1, *temp2;
	__asm__(
		"movq %%rsp, %0;"
		"movq %1, %%rsp;"
		:"=g"(loader_stack)
		:"r"(&stack[INITIAL_STACK_SIZE])
	);
	reload_gdt();
	__asm__("cli");
        load_idt();
	setup_tss();
	start(
		(uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase),
		&physbase,
		(void*)(uint64_t)loader_stack[4]
	);
	for(
		temp1 = "!!!!! start() returned !!!!!", temp2 = (char*)0xb8000;
		*temp1;
		temp1 += 1, temp2 += 2
	) *temp2 = *temp1;
	while(1);
}
Example #3
0
void sched_init() {

    // Creamos la tarea ``init``
    task_t *init = kmalloc(sizeof(task_t));

    init->prog = kmalloc(sizeof(program_t));
    init->prog->name = "init";

    init->pd = kernel_pd;

    init->kernel_stack = KERNEL_STACK_TOP;
    init->kernel_stack_limit = KERNEL_STACK_BOTTOM;

    init->waiting = FALSE;
    init->waited = FALSE;
    init->parent = NULL;

    init->ticks = 0;
    init->quantum = SCHED_QUANTUM;
    restart_quantum(init);
    
    init->pid = get_next_pid();

    // El stack de nivel 0 no interesa. Deberia sobreescribirse al cambiar de
    // tarea. Ademas, como estamos en espacio de kernel, no se deberia utilizar
    // el valor del stack de nivel 0 que esta en la TSS.
    init->kernel_stack_pointer = NULL;
    setup_tss(NULL);

    add_task(init);

    sti();

    init_task();
}
Example #4
0
static void switch_context(task_t *old_task, task_t *new_task) {

    // Cargamos el PD de la tarea
    load_cr3((uint32_t)get_kphaddr(new_task->pd));

    // Actualizamos la TSS
    setup_tss((uint32_t)new_task->kernel_stack_limit);

    // Guardamos el stack pointer y cargamos el de la nueva tarea
    switch_stack_pointers(&old_task->kernel_stack_pointer,
        &new_task->kernel_stack_pointer);
}
Example #5
0
/*============================================================================*
 *				  schedpit_init				      *
 *============================================================================*/
PUBLIC void schedpit_init(unsigned code_base)
{
/* Setups 'schedpit' task.
   Creates a TSS, add a TSS descriptor to GDT and add an task gate to IDT.
   - code_base: Starting address of 'schedpit' code and data read from address
     0x05FC by kernel. 'schedpit' segment descriptors should have this value as
     their 'base' field.
 */
  
  /*register unsigned short *vga = 0xB8000L;
  
  *vga = 0xF440;*/
  struct segdesc_s desc;
  struct gatdesc_s gate;
  unsigned cs, ds, tss;
  reg_t esp;
  
  /* Setup code segment descriptor. */
  setup_seg_desc(&desc, code_base, 0x0FFFFF,
  		 SDESC_PRESENT | SDESC_DT | SDESC_CODE | SDESC_CO_RE, /* type */
		 SDESC_AVL | SDESC_GRAN | SDESC_BIGBIT /* mm */);
  cs = add2gdt(&desc, GDT_NEXT);
  
  /* Setup data segment descriptor. */
  setup_seg_desc(&desc, code_base, 0xFFFFF,
  		 SDESC_PRESENT | SDESC_DT | SDESC_DATA | SDESC_DA_RW, /* type */
		 SDESC_AVL | SDESC_GRAN | SDESC_BIGBIT /* mm */);
  ds = add2gdt(&desc, GDT_NEXT);
  
  /* Setup TSS. */
  esp = (reg_t)schedpit_stack + SCHEDPIT_STACK_SIZE;
  setup_tss(&schedpit_tss, (task_entry_t)schedpit_task_entry,
  	    cs, ds, esp, 0x0002, 0x00, 0x00);
  
  /* Setup TSS descriptor. */
  setup_tss_desc((struct tssdesc_s *)&desc, &schedpit_tss,
  		 TSSDESC_PRESENT | DESC_TASK | TSSDESC_TYPE, 0x00);
  
  tss = add2gdt(&desc, GDT_NEXT);
  
  /* Setup task gate descriptor. */
  setup_task_gate(&gate, tss, TSKGATE_PRESENT | DESC_TASK | IDT_TASK);
  add2idt(&gate, IRQ0_VECT + IRQ_PIT);
  
  /**** PROCS ARRAY INIT ****/
}
Example #6
0
void boot(void)
{
	// note: function changes rsp, local stack variables can't be practically used
	register char *s, *v;
	__asm__(
		"movq %%rsp, %0;"
		"movq %1, %%rsp;"
		:"=g"(loader_stack)
		:"r"(&stack[INITIAL_STACK_SIZE])
	);
	reload_gdt();
	setup_tss();
	start(
		(uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase),
		&physbase,
		(void*)(uint64_t)loader_stack[4]
	);
	s = "!!!!! start() returned !!!!!";
	for(v = (char*)0xb8000; *s; ++s, v += 2) *v = *s;
	while(1);
}
Example #7
0
void boot(void)
{
	// note: function changes rsp, local stack variables can't be practically used
	register char *temp1, *temp2;
        uint32_t* modulep;
        void* physfree;
	__asm__(
		"movq %%rsp, %0;"
		"movq %1, %%rsp;"
		:"=g"(loader_stack)
		:"r"(&stack[INITIAL_STACK_SIZE])
	);
	setup_tss();
	reload_gdt();
        reload_idt();
        irq_install();
        timer_install();
        keyboard_install();
        __asm__("sti");
        modulep = (uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase);
        physfree = (void*)(uint64_t)loader_stack[4];
        kphysfree = physfree;
        mm_phy_init(modulep);
        vmmgr_init();
        vmmgr_page_allocator_init();
        cls();
        scheduler_init();
	/*start(
		(uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase),
		&physbase,
		(void*)(uint64_t)loader_stack[4]
	);*/
	for(
		temp1 = "!!!!! start() returned !!!!!", temp2 = (char*)0xb8000;
		*temp1;
		temp1 += 1, temp2 += 2
	) *temp2 = *temp1;
	while(1);
}
Example #8
0
void start(uint32_t* modulep, void* physbase, void* physfree)
{
    //Memory Init
    mm_init(modulep,physbase,physfree);

    //Memory for PCI
    pages_for_ahci_start_virtual = (uint64_t *)kmalloc_ahci(32*4096);
    pages_for_ahci_start = (uint64_t *)PADDR(pages_for_ahci_start_virtual);
    pages_for_ahci_start = (uint64_t *)(((uint64_t)pages_for_ahci_start+0x0FFF) & ~ 0x0FFF);
    pages_for_ahci_start_virtual = (uint64_t *)(((uint64_t)pages_for_ahci_start_virtual+0x0FFF) & ~ 0x0FFF);
//    print("\n vir %x %x", pages_for_ahci_start_virtual, pages_for_ahci_start_virtual + 32*4096);
//    print("\n phy %x %x", pages_for_ahci_start, pages_for_ahci_start + 32*4096);

    //Initial setup
    reload_gdt();
    reload_idt();
    load_irq();
    setup_tss();
    print_line(30, 0, "Welcome To SBUnix");

    //Kernel process that will be at 0th place in ready queue
    struct task_struct *pcb0 = (struct task_struct *)kmalloc(sizeof(struct task_struct));  //kernel 
    pcb0->pml4e =(uint64_t)boot_pml4e;  // kernel's page table   
    pcb0->cr3 = boot_cr3; // kernel's page table   
    pcb0->pid = 0;  // I'm kernel init process  so pid 0  
    pcb0->stack =(uint64_t *)stack; //my stack is already created by prof :)  
    process_count = 0; //at this point we don't have any other process in ready_queue so go ahead and create one and update this 
    sleeping_process_count = 0; // at this point no body is sleeping 
    // initialize processes queue  
    int i=0;
    for(i=0;i<100;i++)  {   
        zombie_queue[i] = 0;    // no process is zombie 
    }

    ready_queue[0] =(uint64_t )pcb0;  //kernel 

    //User processes for test
    char fname1[]="bin/sh"; //Shell program
   // char fname2[]="bin/malloc"; //Scanf and malloc
   // char fname3[]="bin/fork"; // Fork test
   // char fname4[]="bin/fs"; // Fork test
   // char fname5[]="bin/execvpe"; // Execvpe test

    struct task_struct *pcb1 = malloc_pcb(fname1); // If you remove this shell wont start
   // struct task_struct *pcb2 = malloc_pcb(fname5);
   // struct task_struct *pcb3 = malloc_pcb(fname2);
   // struct task_struct *pcb4 = malloc_pcb(fname3);
    //struct task_struct *pcb5 = malloc_pcb(fname4);

    //print("pcb1 %x pcb2 %x rsp1 %x rsp2 %x\n",pcb1,pcb2,pcb1->rsp,pcb2->rsp); 
    print("pointer %p",pcb1); 
    //print("pointer %p",pcb2); 
    //print("pointer %p",pcb3); 
    //print("pointer %p",pcb4); 
    //print("pointer %p",pcb5); 

    //Initialize tarfs and Hard disk file system
    tarfs_init();
    probe_port((HBA_MEM *)(0xFFFFFFFF00000000+(uintptr_t)bar5)); 
    inialize_sata_table();
   
    asm volatile("mov $0x2b,%ax");
    asm volatile("ltr %ax");
    init_timer();
    __asm__("sti"); 
    while(1);
}