Exemplo n.º 1
0
Arquivo: init.c Projeto: akat1/impala
void
init_x86(const char *karg)
{
    enum {
        code = GATE_PRESENT | GATE_TYPE_RX,
        ucode = code | GATE_DPL3,
        data = GATE_PRESENT | GATE_TYPE_RW,
        udata = data | GATE_DPL3,
        attr = GATE_PAGEGRAN | GATE_OP32,
        tss0 = GATE_PRESENT | GATE_TYPE_TASK,
        intrpt_attr = GATE_PRESENT | GATE_TYPE_INTRPT,
        trap_attr = GATE_PRESENT | GATE_TYPE_TRAP
    };

    int i = 0;

    __kernarg = karg;
    if (1)
    for (i = 0; i < 255 && *karg; karg++, i++) {
        kernarg[i] = *karg;
    }
    kernarg[i] = 0;
    kargs_init();

    // Ustawienie GDT
    mem_zero(&p_gdt, sizeof(p_gdt));
    mem_zero(&p_tss0, sizeof(p_tss0));
    setgdt(SEL_CODE, 0x0, 0xfffff, code, attr);
    setgdt(SEL_DATA, 0x0, 0xfffff, data, attr);
    setgdt(SEL_UCODE, 0x0, 0xfffff, ucode, attr);
    setgdt(SEL_UDATA, 0x0, 0xfffff, udata, attr);
    setgdt(SEL_TSS0, (uintptr_t)&p_tss0, sizeof(p_tss0), tss0, 0);
    p_tss0.tss_io = 0;
    p_tss0.tss_ss0 = 0x10;
//    p_tss0.tss_cs=0x8;
//    p_tss0.tss_ds=p_tss0.tss_es=p_tss0.tss_fs=p_tss0.tss_gs=0x10;

    mem_zero(&p_gdtr, sizeof(p_gdtr));
    p_gdtr.base = &p_gdt;
    p_gdtr.limit = sizeof(p_gdt) -1;
    cpu_gdt_load(&p_gdtr);

    cpu_tr_load(SEL_MK(SEL_TSS0, SEL_DPL3));
    extern void megaloop(void);

    // Ustawienie IDT
    for (i = 0; i < 0x100; i++) {
        setidt(i, SEL_MK(SEL_CODE, SEL_DPL0), (uintptr_t)_unhnd_intrpt,
            intrpt_attr);
    }

    for (i = 0; i < 0x20; i++) {
        setidt(i, SEL_MK(SEL_CODE, SEL_DPL0), (uintptr_t)trap_table[i], trap_attr);
    }

    for (i = 0; i <= 23; i++) {
        setidt(i+0x20, SEL_MK(SEL_CODE, SEL_DPL0), irq_table[i], intrpt_attr);
    }

    setidt(INTRPT_SYSCALL, SEL_MK(SEL_CODE, SEL_DPL0),
        (uintptr_t)_intrpt_syscall, intrpt_attr | GATE_DPL3);

    mem_zero(&p_idtr, sizeof(p_idtr));
    p_idtr.base = &p_idt;
    p_idtr.limit = sizeof(p_idt)-1;
    cpu_idt_load(&p_idtr);
    i8259a_init();
    i8254_init();
    pckbd_init();
    vm_low_init();
    video_init();
    bus_isa_init();
    bus_pci_init();
    irq_enable();
    _cpu_info();

}
Exemplo n.º 2
0
void
init()
{
	struct ext_mem_format *ptr_exts; // structure-pointer to structure
	struct ext_mem_format temp_struc; // temporary structure
	struct inode ino_kern;
	struct ext_mem_format ext_mem_strucs[50]; // 386 usable RAM list format

	usec_t ino_sec;
	ubyte_t num_servs; // number of servers to read to memory
	uint_t tot_mem, counter, counter1; // counters
	byte *ptr_mem=(byte *)ext_mem_strucs; // byte-pointer to structure

	/* 
	 * Get absolute sector for first ivector.
	 * It is stored in a global variable.
	 */
	sosfs_ivec_first();

	/* read kernel's and server's inode sector */
	ino_sec = sosfs_iget("/boot/kernel");
	/* if error */
	if (ino_sec == -1) {
		low_putstr("Inode not found\n"); 
		while (1);
	}
	/* read kernel's inode */
	sosfs_read_raw(ino_sec, &ino_kern);

	/* zero out the vector */
	for (tot_mem=0; tot_mem<512; tot_mem++)
		buffer[tot_mem]=0;

	/* 
	 * Copy arguments from real-mode to protected-mode.
	 * The monitor program wishes to pass the arguments to the kernel.
	 * This is done by a little hack that uses an interrupt instruction
	 * passing a buffer to copy from real-mode to protected-mode using
	 * BIOS.
	 */
	kargs_init();

	/* 
	 * Get total amount of RAM.
	 * The most reliable way to know the system's memory-mapping
	 * is by using the BIOS; we use int $0x15 function 0xe820.
	 */
	low_tot_ram(ext_mem_strucs);

	/* point to memory-map vector */
	ptr_exts=ext_mem_strucs;
	/* 
	 * Traverse the structures until magic number found.
	 * Our interrupt handler set a magic number after the last
	 * entry returned by the BIOS handler.
	 */
	kprintf("\n");
	kprintf("BIOS-provided physical-memory mappings\n");
	kprintf("======================================================\n");
	while (ptr_exts->acpi_ext != 0x12345) {
		/* if we must ignore the entry, so we do */
		if (ptr_exts->reg_len == 0)
			continue;
		/* print type of memory to terminal */
		switch (ptr_exts->reg_type) {
			case 1:
				kprintf("Usable RAM at ");
				if (ptr_exts->base_addr[0] != 0) {
					zero_mem(ptr_exts);
					put_list(ptr_exts);
				}
				break;
			case 2:
				kprintf("Reserved/unusable RAM at ");
				break;
			case 3:
			case 4:
			case 5:
				kprintf("ACPI RAM at ");
				break;
		}
		/*
		 * Create a temporary structure and copy the entire structure
		 * to it.
		 * Print the address range.
		 */
		temp_struc = *ptr_exts; // copy structure
		temp_struc.reg_len[0] += temp_struc.base_addr[0];
		kprintf("%x-", &temp_struc);
		kprintf("%x", temp_struc.reg_len);
		kprintf("\n");
		for (tot_mem=0; tot_mem<512; tot_mem++)
			buffer[tot_mem]=0;
		ptr_exts++; // advance one structure
	}
	kprintf("======================================================\n");

	/* 
	 * Set up initial memory mappings.
	 * Load user-level servers to predefined physical memory and
	 * identically map them. Map the monitor program and the kernel
	 * also to identical physical addresses. Also map those programs'
	 * heaps.
	 */
	load_init();
	heap_init();
	/* list returned by BIOS might be unsorted */
	sort_free_list();
	/* machine-dependent format to machine-independent format */
	dep_2_indep_list(ptr_list);
	mmap_init();
	enable_paging();
	SOS_init();
}