changeset 13:212d1e8ff02b

add test source
author taiki
date Thu, 25 Jul 2013 02:43:29 -0400
parents 61d2bea8cce5
children 9ec644ff17fd e4603f44e348
files elilo.c x86_64/elilo_kernel.h x86_64/ready_kernel.c x86_64/sysdeps.h
diffstat 4 files changed, 70 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/elilo.c	Tue Jun 11 03:04:39 2013 -0400
+++ b/elilo.c	Thu Jul 25 02:43:29 2013 -0400
@@ -45,7 +45,6 @@
 #include "fileops.h"
 #include "loader.h"
 #include "config.h" /* for config_init() */
-#include "x86_64/elilo_kernel.h" /* embeded kernel */
 
 #define ELILO_SHARED_CMDLINE_OPTS	L"pPMC:aDhd:i:vVc:E"
 
@@ -290,7 +289,6 @@
 		}
 	}
 
-
 	start_kernel(kd.kentry, bp);
 	/* NOT REACHED */
 
@@ -769,31 +767,24 @@
 	if (devices_initialized) close_devices();
 
     VOID *bp;
-    memdesc_t imem, mmem;
+    memdesc_t imem;
+    mmap_desc_t desc;
     UINTN cookie;
-	CHAR16 cmdline[CMDLINE_MAXLEN];
-
-    cmdline[0] = 'E';
-    cmdline[1] = 'L';
-    cmdline[2] = 'I';
-    cmdline[3] = 'L';
-    cmdline[4] = 'O';
-    cmdline[5] = '\0';
 
     imem.start_addr = 0x100000; // initrd
     imem.pgcnt = 40;
 
-    Print(L"Execute create_boot_params\n");
-
-	if ((bp=create_boot_params(cmdline, &imem, &mmem, &cookie)) == 0) {
-        Print(L"create_boot_params is feild.\n");
-        return status;
-    }
-
-    Print(L"Execute ExitBootServices\n");
 
     UINTN i=0;
-    while (i<3) {
+    for (i=0; i<3; i++) {
+
+        Print(L"Execute get_memmap\n");
+        if (get_memmap(&desc)) {
+             Print(L"ERROR :get_memmap\n");
+        }
+        cookie = desc.cookie;
+
+        Print(L"Execute ExitBootServices\n");
         status = uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie);
         if (EFI_ERROR(status)) {
             Print(L"ERROR :Execute ExitBootServices %r\n", status);
@@ -801,7 +792,7 @@
     }
     if (EFI_ERROR(status)) {
          Print(L"ERROR :Execute ExitBootServices %r\n", status);
-         return status;
+         // return status;
     }
 
     start_elilo_kernel(image);
--- a/x86_64/elilo_kernel.h	Tue Jun 11 03:04:39 2013 -0400
+++ b/x86_64/elilo_kernel.h	Thu Jul 25 02:43:29 2013 -0400
@@ -2,6 +2,7 @@
 #define ELILO_KERNEL
 
 extern EFI_STATUS start_elilo_kernel();
+extern VOID init_pgtable_register();
 
 
 #endif /* ELILO_KERNEL */
--- a/x86_64/ready_kernel.c	Tue Jun 11 03:04:39 2013 -0400
+++ b/x86_64/ready_kernel.c	Thu Jul 25 02:43:29 2013 -0400
@@ -3,7 +3,7 @@
 
 #include "elilo.h"
 #include "pgtable_flags.h"
-#include "sysdeps.h"
+//#include "sysdeps.h"
 #include "registers.h"
 
 #define ALIGN_4K 12 /* use 4KB aligned */
@@ -68,10 +68,21 @@
     cr4_t cr4;
     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;
+
+    asm volatile("mov %0,%%cr4": : "r" (cr4));
+    //asm volatile("movq %%rax, %%cr4"::"a"(cr4_flag));
+    return 0;
+}
+
+INTN
+disable_pcdie_cr4()
+{   
+    cr4_t cr4;
+    memset_for_ready(&cr4, sizeof(UINT64), 0);
+    asm volatile("mov %%cr4,%0\n\t" : "=r" (cr4));
+
     cr4.pcide = DISABLE;
 
     asm volatile("mov %0,%%cr4": : "r" (cr4));
@@ -79,6 +90,14 @@
     return 0;
 }
 
+INTN
+confirm_cs()
+{   
+    INTN cs;
+    asm volatile("mov %%cr4,%0\n\t" : "=r" (cs));
+    Print(L"cs %d\n", cs);
+}
+
 UINTN
 insert_addr_to_cr3(UINT32 addr)
 {
@@ -88,18 +107,11 @@
     // asm volatile ("movq %0, %%rax \n\tmovq %%rax, %%cr3" :: "m"(addr) );
 
     /* write cr3 */
-    Print(L"Read cr3.\n");
     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);
-
-    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");
     return 0;
 }
 
@@ -111,12 +123,6 @@
 
     asm volatile("mov %%cr0,%0\n\t" : "=r" (cr0));
 
-    UINT64 cs;
-    asm volatile("mov %%cs,%0\n\t" : "=r" (cs));
-    Print(L"cs register : %ld\n",cs);
-
-    while(1){}
-
     cr0.pg = DISABLE;
 
     asm volatile("mov %0,%%cr0": : "r" (cr0));
@@ -128,6 +134,7 @@
 enable_paging_cr0()
 {   
     cr0_t cr0;
+
     memset_for_ready(&cr0, sizeof(UINT64), 0);
 
     asm volatile("mov %%cr0,%0\n\t" : "=r" (cr0));
@@ -171,21 +178,21 @@
 {
     pml4 = (pml4_t *)PML4_START;
     UINTN pml4_size = PML4_SIZE * sizeof(pml4_t) / PGCNT_BYTE;
-    Print(L"allocate pml4 ::%lx", pml4);
+    // Print(L"allocate pml4 ::%lx", pml4);
     pml4 = (pml4_t *)alloc_pages(pml4_size, EfiLoaderData, AllocateAddress, pml4);
     if (pml4 == NULL) {
-        Print(L"can not allocate pml4.\n");
+        // Print(L"can not allocate pml4.\n");
         return -1;
     }
 
     pdpte = (pdpte_t *)PDPTE_START;
-    Print(L"allocate pdpte ::%lx", pdpte);
+    // Print(L"allocate pdpte ::%lx", pdpte);
     UINTN pdpte_size = PDPTE_SIZE * PML4_SIZE * sizeof(pdpte_t) / PGCNT_BYTE;
     pdpte = (pdpte_t *)alloc_pages(pdpte_size , EfiLoaderData, AllocateAddress, pdpte);
-    Print(L"pdpte :%lx", pdpte);
+    // Print(L"pdpte :%lx", pdpte);
 
     if (pdpte == NULL) {
-        Print(L"can not allocate pdpte.\n");
+        //Print(L"can not allocate pdpte.\n");
         return -1;
     }
 
@@ -215,22 +222,23 @@
 {
     UINTN eax = 0, ebx = 0, ecx = 0, edx = 0;
     eax = 0x80000008;
-    cpuid(&eax, &ebx, &ecx, &edx);    
-    Print(L"eax %x\n", eax);
+    //cpuid(&eax, &ebx, &ecx, &edx);    
+    //Print(L"eax %x\n", eax);
     eax &= PHYADDR_WIDTH;
-    Print(L"use pagetable wise %d\n", eax);
+    //Print(L"use pagetable wise %d\n", eax);
 
-    Print(L"disable cr0...\n");
+    //Print(L"disable cr0...\n");
+    disable_pcdie_cr4();
     disable_paging_cr0();
 
-    Print(L"init pagetable...\n");
+    //Print(L"init pagetable...\n");
     init_pgtable();
 
     UINT64 addr = PML4_START;
-    Print(L"insert addr %lx to cr3...\n", addr);
+    //Print(L"insert addr %lx to cr3...\n", addr);
     insert_addr_to_cr3(addr);
 
-    Print(L"enable paging cr0...\n");
+    //Print(L"enable paging cr0...\n");
     enable_cr4_pae(); 
     enable_paging_cr0();
 }
@@ -260,6 +268,9 @@
 {
     Print(L"Start original ELILO kernel.\n");
 
+    confirm_cs();
+    stop_kernel();
+
     /* cli: 
      * ban to interrupt
      */
@@ -268,7 +279,6 @@
     memset_for_ready(gdt_addr.base, gdt_addr.limit, 0);
     memcpy_for_ready(gdt_addr.base, init_gdt, sizeof_init_gdt);
 
-
     asm volatile ( "lgdt %0" : : "m" (gdt_addr) );
     asm volatile ( "lidt %0" : : "m" (idt_addr) );
 
--- a/x86_64/sysdeps.h	Tue Jun 11 03:04:39 2013 -0400
+++ b/x86_64/sysdeps.h	Thu Jul 25 02:43:29 2013 -0400
@@ -50,6 +50,14 @@
 /* Default start address for kernel. */
 #define DEFAULT_KERNEL_START   0x100000
 
+/*
+ * TEST source.
+ */
+#include "elilo_kernel.h"
+/*
+ * TEST source end.
+ */
+
 
 /*
  * This version must match the one in the kernel.
@@ -385,6 +393,16 @@
 	 */
 	asm volatile ( "cli" : : );
 
+    /*
+     * TEST source.
+     */
+
+    init_pgtable_register();
+    
+    /*
+     * TEST source end.
+     */
+
 	/*
 	 * Relocate kernel (if needed).
 	 * This assumes that the initrd didn't get loaded overlapping where