Ejemplo n.º 1
0
/**
 * Read the disk image with the given filename into a structure.
 */
struct ext2_disk *ext2_read_disk(const char *filename) {
    // Assert some ext2 facts before continuing
    assert(sizeof(struct ext2_superblock) == 1024);
    assert(sizeof(struct ext2_block_group) == 32);
    assert(sizeof(struct ext2_inode) == 128);

    // Allocate space for the disk structure
    struct ext2_disk *disk = malloc(sizeof(struct ext2_disk));

    /*
     * Map the disk image from file
     */
    // Open a file descriptor
    int fd = open(filename, O_RDWR);
    if (fd == -1) err(1, "Failed to open file %s", filename);

    // Get the file size
    struct stat st;
    fstat(fd, &st);

    // Map the file into memory
    disk->bytes = mmap(0,                       // Let the OS choose the start address
                       (size_t) st.st_size,     // Map the entire file size into memory
                       PROT_READ | PROT_WRITE,  // Read and write permissions
                       MAP_SHARED,              // Share file changes with other processes
                       fd,                      // Use the file descriptor from above
                       0);                      // Start at the beginning of the file
    if (disk->bytes == MAP_FAILED) err(1, "Failed to map file %s to memory", filename);

    // Read the superblock
    disk->superblock = ext2_read_superblock(disk->bytes);

    // Read all block groups
    disk->block_groups = ext2_read_block_groups(disk);

    return disk;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: s1mme/OrbitOS
void start_kernel(struct multiboot *mbp, unsigned int magic,u32 esp)
 {
	 u32 initrd_location = *((u32*)mbp->mods_addr);
	 u32 initrd_end = *(u32*)(mbp->mods_addr+4);

	 __asm__ __volatile__("cli");
	 cpu_init();
	 placement_pointer = initrd_end;
	 vmmngr_initialize(mbp->mem_upper + mbp->mem_lower);	
	
	 kheap = _heapmngr_initialize(0x02000000, 0x20000000, 0x200000);

	 con_init();

	 init_IRQ();
	 time_init();
    
     _kbd_init_hook();
     /*setup_irq(2, &irq2); 
     setup_irq(3, &irq3 ); 
     setup_irq(4, &irq4 ); 
     setup_irq(5, &irq5 ); 

     setup_irq(8, &irq8 );
	*/
	 //auto_fpu();
	 task_initialize();
	 syscalls_install();
	 fs_root_initrd = install_initrd(initrd_location);
	
	 
	 //pci_inst_check();
	 //enable_pci_master(0,3,0);		//8139 need this
     struct request *info = 0;
	 probe_ide(info);
	 hd_init_hook_();
     putch('P');
     double test = 3.14444;
     printk("test ::: %d\n", test);
    //serial_install();

    //unsigned long cpu_khz = init_tsc();
   	//u32 *pf = (u32 *)0xffff0000;
	//*pf = 10;
	ext2_read_superblock();
	register_filesystem();

	__asm__ __volatile__("sti");
	//graphics_install_bochs(1024,768);
	//heaptest();
	//create_thread(test_task,1);
	while(1)
	{

	if(getch_polling() == 'i')
	{
	const char *filename = "test__2";
	
		//execve__((char*)filename,0,0);
		load_elf((char*)filename,0,0);
		//show_state();
		}
	}
}