# HG changeset patch # User taiki # Date 1369019498 14400 # Node ID 6eb39a8c991ffe170aa9a12379e80a57641a6d2d # Parent 28550dbb257996ac79cfe6c0e334b5549e6255ca confirm state of register diff -r 28550dbb2579 -r 6eb39a8c991f config.c --- a/config.c Tue Mar 26 18:15:35 2013 +0900 +++ b/config.c Sun May 19 23:11:38 2013 -0400 @@ -210,7 +210,8 @@ config_error(CHAR16 *msg,...) { Print(L"near line %d: ",line_num); - IPrint(systab->ConOut, msg); + Print(msg); + //IPrint(systab->ConOut, msg); Print(L"\n"); } diff -r 28550dbb2579 -r 6eb39a8c991f elilo.c --- a/elilo.c Tue Mar 26 18:15:35 2013 +0900 +++ b/elilo.c Sun May 19 23:11:38 2013 -0400 @@ -141,6 +141,7 @@ case ELILO_LOAD_SUCCESS: break; case ELILO_LOAD_ERROR: + Print(L"ELILO_LOAD_ERROR"); goto exit_error; case ELILO_LOAD_ABORTED: free_kmem(); @@ -235,6 +236,7 @@ case ELILO_LOAD_SUCCESS: goto do_launch; case ELILO_LOAD_ERROR: + Print(L"kernel load error\n"); goto exit_error; /* otherwise we retry ! */ } @@ -304,7 +306,6 @@ if (mmem.start_addr) free(mmem.start_addr); if (bp) free_boot_params(bp); exit_error: - start_elilo_kernel(image); return ELILO_LOAD_ERROR; } @@ -472,6 +473,7 @@ /* initialize global variable */ systab = system_tab; + /* initialize EFI library */ InitializeLib(image, systab); @@ -771,5 +773,7 @@ /* garbage collect all remaining allocations */ free_all_memory(); + start_elilo_kernel(image); + return ret; } diff -r 28550dbb2579 -r 6eb39a8c991f x86_64/elilo_kernel.o Binary file x86_64/elilo_kernel.o has changed diff -r 28550dbb2579 -r 6eb39a8c991f x86_64/ready_kernel.c --- a/x86_64/ready_kernel.c Tue Mar 26 18:15:35 2013 +0900 +++ b/x86_64/ready_kernel.c Sun May 19 23:11:38 2013 -0400 @@ -8,32 +8,33 @@ #define ALIGN_4K 12 /* use 4KB aligned */ -#define MEMCPY(to, from, cnt) { \ - UINT8 *t = (UINT8 *)(to); \ - UINT8 *f = (UINT8 *)(from); \ - UINTN n = cnt; \ - if (t && f && n && (tf)) { \ - t += n; \ - f += n; \ - while (n--) { \ - *t-- = *f--; \ - } \ - } \ +static void memcpy_for_ready(UINT16 *to, UINT16 *from, UINTN cnt) +{ + UINT16 *t = to; + UINT16 *f = from; + UINTN n = cnt; + + if (t && f && n && (tf)) { + t += n; + f += n; + while (n--) { + *t-- = *f--; + } + } } -#define MEMSET(ptr, size, val) { \ - UINT8 *p = (UINT8 *)(ptr); \ - UINTN n = (UINTN)(size); \ - UINT8 v = (UINT8)(val); \ - if (p && n) { \ - while (n--) { \ - *p++ = v; \ - } \ - } \ +static void memset_for_ready(UINT16 *ptr, UINT16 size, UINT16 val) +{ + UINT16 *p = ptr; + if (p && size) { + while (size--) { + *p++ = val; + } + } } /* @@ -65,9 +66,10 @@ enable_cr4_pae() { cr4_t cr4; - MEMSET(&cr4, sizeof(UINT64), 0); - + memset_for_ready(&cr4, sizeof(UINT64), 0); asm volatile("mov %%cr4,%0\n\t" : "=r" (cr4)); + Print(L"Register cr4 : %lx \n", cr4); + while(1) {} cr4.pae = ENABLE; cr4.pcide = DISABLE; @@ -78,10 +80,10 @@ } UINTN -insert_addr_to_cr3(UINT64 addr) +insert_addr_to_cr3(UINT32 addr) { cr3_t cr3; - MEMSET(&cr3, sizeof(UINT64), 0); + memset_for_ready(&cr3, sizeof(UINT32), 0); // asm volatile ("movq %0, %%rax \n\tmovq %%rax, %%cr3" :: "m"(addr) ); @@ -90,8 +92,11 @@ asm volatile("mov %%cr3,%0\n\t" : "=r" (cr3)); Print(L"Getting cr3 is %lx pwt:%d, pcd:%d pdb 0x%lx\n addr:%lx \n", cr3, cr3.pwt, cr3.pcd, cr3.pdb, addr); Print(L"%lx\n", cr3); - //addr = addr >> ALIGN_4K; - //cr3.pdb = addr; + + while(1){} + + addr = addr >> ALIGN_4K; + cr3.pdb = addr; Print(L"Write addr:%lx to cr3 / cr3.pdb: %lx.\n", addr, cr3.pdb); asm volatile("mov %0,%%cr3": : "r" (cr3)); Print(L"Written cr3.\n"); @@ -102,7 +107,7 @@ disable_paging_cr0() { cr0_t cr0; - MEMSET(&cr0, sizeof(UINT64), 0); + memset_for_ready(&cr0, sizeof(UINT64), 0); asm volatile("mov %%cr0,%0\n\t" : "=r" (cr0)); @@ -117,10 +122,9 @@ enable_paging_cr0() { cr0_t cr0; - MEMSET(&cr0, sizeof(UINT64), 0); + memset_for_ready(&cr0, sizeof(UINT64), 0); asm volatile("mov %%cr0,%0\n\t" : "=r" (cr0)); - Print(L"Register cr0 : %lx \n", cr0); cr0.pg = ENABLE; asm volatile("mov %0,%%cr0": : "r" (cr0)); // asm volatile("movl %0, %%eax \n\t movq %%rax, %%cr0"::"m"(cr0_flag)); @@ -201,6 +205,31 @@ } VOID +init_pgtable_register() +{ + UINTN eax = 0, ebx = 0, ecx = 0, edx = 0; + eax = 0x80000008; + cpuid(&eax, &ebx, &ecx, &edx); + Print(L"eax %x\n", eax); + eax &= PHYADDR_WIDTH; + Print(L"use pagetable wise %d\n", eax); + + Print(L"disable cr0...\n"); + disable_paging_cr0(); + + Print(L"init pagetable...\n"); + init_pgtable(); + + UINT64 addr = PML4_START; + Print(L"insert addr %lx to cr3...\n", addr); + insert_addr_to_cr3(addr); + + Print(L"enable paging cr0...\n"); + enable_cr4_pae(); + enable_paging_cr0(); +} + +VOID stop_kernel() { Print(L"stop\n"); @@ -262,75 +291,10 @@ return; } -VOID -set_memory_map(mmap_desc_t *mmapd) -{ - UINTN nr_map; - UINT64 start, end, size, type; - nr_map = mmapd->map_size/mmapd->desc_size; - estatus_t *est; - struct e820entry *map; - - UINTN i; - for (i=0; i md[i]; - switch (p.Type) { - case EfiReservedMemoryType: - Print(L"| reserved memory."); - break; - case EfiLoaderCode: - Print(L"| loader code."); - break; - case EfiLoaderData: - Print(L"| loader data."); - break; - case EfiBootServicesCode: - Print(L"| boot services code."); - break; - case EfiBootServicesData: - Print(L"| boot services data."); - break; - case EfiConventionalMemory: - Print(L"| conventional memory."); - break; - case EfiUnusableMemory: - Print(L"| unusable memory."); - break; - case EfiACPIReclaimMemory: - Print(L"| ACPI reclaim memory."); - break; - case EfiACPIMemoryNVS: - Print(L"| ACPI memory NVS."); - break; - case EfiMemoryMappedIO: - Print(L"| memory mapped IO."); - break; - case EfiMemoryMappedIOPortSpace: - Print(L"| memory mapped IO port space."); - break; - case EfiPalCode: - Print(L"| pal code. "); - break; - case EfiMaxMemoryType: - Print(L"| max memory type."); - break; - } - } - return; -} - - EFI_STATUS start_elilo_kernel(EFI_HANDLE image) { Print(L"Start original ELILO kernel.\n"); - close_devices(); - - /* - mmap_desc_t mmapd; - get_memmap(&mmapd); - set_memory_map(&mmapd); - */ UINTN map_size, cookie, size, version; map_size = EFI_PAGE_SIZE * 2; @@ -341,49 +305,31 @@ Print(L"error 'allocate pool' %r \n", status); } - status = uefi_call_wrapper(BS->GetMemoryMap, 5, &map_size, md, &cookie, &size, &version); - if (EFI_ERROR(status)) { - Print(L"error 'get memory map' %r \n", status); - } - - status = uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie); - if (EFI_ERROR(status)) { - Print(L"error 'exit boot services' %r \n", status); - } - + /* cli: + * ban to interrupt + */ asm volatile ("cli"::); - - MEMSET(gdt_addr.base, gdt_addr.limit, 0); - MEMCPY(gdt_addr.base, init_gdt, sizeof_init_gdt); - - asm volatile ( "lidt %0" : : "m" (idt_addr) ); - asm volatile ( "lgdt %0" : : "m" (gdt_addr) ); + + memset_for_ready(gdt_addr.base, gdt_addr.limit, 0); + memcpy_for_ready(gdt_addr.base, init_gdt, sizeof_init_gdt); - UINTN eax = 0, ebx = 0, ecx = 0, edx = 0; - eax = 0x80000008; - cpuid(&eax, &ebx, &ecx, &edx); - Print(L"eax %x\n", eax); - eax &= PHYADDR_WIDTH; - Print(L"use pagetable wise %d\n", eax); - Print(L"disable cr0...\n"); - disable_paging_cr0(); - - Print(L"init pagetable...\n"); - init_pgtable(); - - UINT64 addr = PML4_START; - Print(L"insert addr %lx to cr3...\n", addr); - insert_addr_to_cr3(addr); - - Print(L"enable paging cr0...\n"); - enable_cr4_pae(); - enable_paging_cr0(); + // asm volatile ( "lgdt %0" : : "m" (gdt_addr) ); + //asm volatile ( "lidt %0" : : "m" (idt_addr) ); + init_pgtable_register(); Print(L"finish to initialize...\n"); + + /* hlt: + * assembler instruction. + * stop cpu until next intrrupt. + */ + asm volatile ("hlt" : : ); Print(L"finish internal kernel\n"); + + return EFI_SUCCESS; }