Пример #1
0
void create_init_process() {
    process *p = k_malloc(sizeof(process));
    p->pid = process_id;
    p->ppid = process_id;
    process_id += 1;
    p->timer_val =0;
    p->state = TASK_INTERRUPTIBLE;
    p->memory = NULL;
    p->kernel_stack = k_malloc_stack(4095);
    clear_registers(p->reg);
    p->cr3 = create_process_page_table();
    p->fdtable = k_malloc(sizeof(fd_obj)*50);
    p->maxfd=2;  //0,1,2 are reserved for stdin,stdout, and stderr respectively.
    p->fdtable[0].fileptr=NULL;
    p->fdtable[0].file_offset=0;
    p->fdtable[0].flags=O_RDONLY;  //std input is read only
    p->fdtable[0].filetype='S'; //standard i/o
    p->fdtable[1].fileptr=NULL;
    p->fdtable[1].file_offset=0;
    p->fdtable[1].flags=O_WRONLY;  //std output is write only
    p->fdtable[1].filetype='S'; //standard i/o
    tarfs_init("bin/init_process",p);
    //tarfs_init("bin/sbush",p);
    create_STACK_memory(p->memory,U_STACK);
    memcpy("bin/init_process",p->p_name,50);
    //////print("Working === %x",p->kernel_stack);
    //////print("Process created with id = %d ",p->pid);
    //	run_process(p);
    init_process = p;
}
Пример #2
0
process* create_process_new(process* pp,char* bin_file,int create_fd) {
    void *addr = k_malloc(sizeof(process));
    process *p = addr;
    p->pid = process_id;
    process_id += 1;
    p->ppid = pp->pid;
    p->timer_val =0;
    p->state = TASK_INTERRUPTIBLE;
    p->memory = NULL;
    p->self_memory = (uint64_t)addr;
    p->pp= pp;
    clear_registers(p->reg);
    p->cr3 = create_user_process_table();
    tarfs_init(bin_file,p);
    create_STACK_memory(p->memory,U_STACK);
    p->kernel_stack = k_malloc_stack(4095);
    p->env_set = 0;
    if(create_fd == 1) {
        p->fdtable = k_malloc(sizeof(fd_obj)*50);
        p->maxfd=2;  //0,1,2 are reserved for stdin,stdout, and stderr respectively.
        p->fdtable[0].fileptr=NULL;
        p->fdtable[0].file_offset=0;
        p->fdtable[0].flags=O_RDONLY;  //std input is read only
        p->fdtable[0].filetype='S'; //standard i/o
        p->fdtable[1].fileptr=NULL;
        p->fdtable[1].file_offset=0;
        p->fdtable[1].flags=O_WRONLY;  //std output is write only
        p->fdtable[1].filetype='S'; //standard i/o
    }
    //	uint64_t* a = (uint64_t*)p->kernel_stack;
    //	a[0] = 24;
    //////print("Working === %x",p->kernel_stack);
    //////print("Process created with id = %d ",p->pid);
    //	run_process(p);
    //	//print("strlen = %d",strlen(bin_file));
    //	//print("bin_file = %s",bin_file);
    int size = strlen(bin_file);
    size = size > 50 ? 49:size;
    memcpy(bin_file,p->p_name,size);
    //	//print("file name  = %s",p->p_name);
    add_to_readyQ(p);
    return p;

}
Пример #3
0
registers_t *kinit(mboot_info_t *mboot, uint32_t mboot_magic)
{

  kdbg_init();
  assert(mboot_magic == MBOOT_MAGIC2);

  mboot_mod_t *mods = (mboot_mod_t *)(assert_higher(mboot->mods_addr));

  kernel_elf_init(mboot);
  pmm_init(mboot);
  vmm_init(mods[0].mod_end);
  idt_init();
  tss_init();

  register_int_handler(INT_PF, page_fault_handler);
  register_int_handler(INT_SCHEDULE, switch_kernel_thread);

  scheduler_init();
  timer_init(500);
  /* vfs_init(); */
  syscall_init();
  process_init((void(*)(void))&_idle);

  tar_header_t *tarfs_location = assert_higher((tar_header_t *)mods[0].mod_start);
  debug_enabled = 1;

  debug("[info] Mboot flags %x\n", mboot->mods_addr);
  debug("[info] Mounting tarfs as root\n");
  vfs_init();
  vfs_mount("/", tarfs_init(tarfs_location));
  vfs_mount("/mnt/tarfs", tarfs_init(tarfs_location));
  vfs_mount("/dev/debug", debug_dev_init());
  keyboard_init();

  fopen("/dev/debug", "w");
  fopen("/dev/debug", "w");
  /* for(;;); */

  /* vfs_mount("/", tarfs_init(tarfs_location)); */
  /* keyboard_init(); */
  /* vfs_mount("/dev/debug", debug_dev_init()); */

  /* fopen("/dev/kbd", "r"); */
  /* fopen("/dev/debug", "w"); */
  /* fopen("/dev/debug", "w"); */

  execve("/bin/init",0,0);

  debug("[status]========================\n");
  debug("[status] Os5 by Thomas Lovén\n");
  debug("[status] Kernel git data: [%s (%s)] %s\n", __kernel_git_hash, (__kernel_git_dirty)?"dirty":"clean", __kernel_git_date);
  debug("[status] %s: %s\n", __kernel_git_branch, __kernel_git_message);
  debug("[status] Kernel compilation: %s %s\n", __kernel_build_date, __kernel_build_time);
  debug("[status]========================\n");

  thread_t *init = new_thread((void(*)(void))current->proc->mm.code_entry,1);
  init->proc = current->proc;

  debug("[status] Kernel booted\n");
  return switch_kernel_thread(0);
}
Пример #4
0
void start(uint32_t* modulep, void* physbase, void* physfree)
{       
  int i;
    struct smap_t {
                uint64_t base, length;
                uint32_t type;
        }__attribute__((packed)) *smap;
      
  
        // initially Mark all pages used  
        mm_set(freePage,MEM_SIZE); 
 
        while(modulep[0] != 0x9001) modulep += modulep[1]+2;
        for(smap = (struct smap_t*)(modulep+2); smap < (struct smap_t*)((char*)modulep+modulep[1]+2*4); ++smap) {
            if (smap->type == 1 /* memory */ && smap->length != 0) {
                        // Mark the memory available in the free list 
                        pmmngr_init_region(smap->base, smap->length);      
                  }
        }

      /* we need to mark the kernel memory as used kernel starts from 200000 and end at 220000 */ 
      /* so we will mark the memory till 400000 as used however we can keep it till 220000 as well */ 
      pmmngr_uninit_region((uint64_t)0,(uint64_t)0x400000);  // mark all kernel memory as used 
      
      /* we need to map the kernel memory to the page table */
      
      // initialize the page table
      set_page_table(&Page_Table);

     uint64_t *addr = (uint64_t*)physbase; 
    /* we need to map the kernel memory to the page table */ 
    for(addr = (uint64_t*)physbase; addr<=(uint64_t*)physfree; addr++)  
      {
       vmmngr_map_page(addr,(uint64_t *)((uint64_t)addr + KERNEL_VIRTUAL_BASE),&Page_Table);            
      }
   
 
      /* Map the Video memory This will map to single page 80*25*2 < 1 page */
      vmmngr_map_page((uint64_t *)0xb8000,(uint64_t*)VIDEO_VIRTUAL_MEMORY,&Page_Table);  
    //  printf("Video Memory has been marked in virtual address space\n"); 

      /* pass the pml4e value to cr3 register */
      kernel_pml4e = (uint64_t *)ALIGN_DOWN((uint64_t)Page_Table.root);
      write_cr3(&Page_Table);
      init_video();

/********************************* KERNEL CREATION ********************************/
 struct task_struct *pcb0 = (struct task_struct *)kmalloc(sizeof(struct task_struct));  //kernel 
 pcb0->pml4e =(uint64_t)kernel_pml4e;  // kernel's page table   
 pcb0->pid = 0;  // I'm kernel init process  so pid 0  
 pcb0->iswait = 0; //not waiting for any one
 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  
 for(i=0;i<100;i++)  {   
  zombie_queue[i] = 0;    // no process is zombie 
 }
 foreground_process = 3; // process with this pid will be foreground process  
 
  // put them in the ready queue
  ready_queue[0] =(uint64_t ) pcb0;  //kernel 

/*
char fname[] = "bin/hello";
malloc_pcb(fname);

char fname1[] = "bin/world";
malloc_pcb(fname1);

char fname2[] = "bin/proc3";
malloc_pcb(fname2);

char fname3[] = "bin/proc4";
malloc_pcb(fname3);    
*/
/*************************************** Please change here fname ******************/
char fname4[] = "bin/printf";
malloc_pcb(fname4); 

  idt_install();
  __asm__("sti");

  //init_context_switch();    
  asm volatile("mov $0x2b,%ax");
  asm volatile("ltr %ax");
  tarfs_init();    
  while(1);      
}
Пример #5
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);
}