AMD64 - Sync machine-independant bits from smtms.
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 12 Aug 2009 04:41:31 +0000 (21:41 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 12 Aug 2009 04:41:31 +0000 (21:41 -0700)
Submitted-by: Jordan Gordeev <jgordeev@dir.bg>
lib/libkvm/kvm_amd64.c
sbin/dump/optr.c
sys/cpu/i386/include/types.h
sys/dev/raid/asr/asr.c
sys/sys/types.h
sys/vm/vm_unix.c

index 9e945c6..33e73f1 100644 (file)
 #endif
 
 struct vmstate {
-       pd_entry_t      *PTD;
+       pml4_entry_t    *PML4;
 };
 
 void
 _kvm_freevtop(kvm_t *kd)
 {
        if (kd->vmst != 0) {
-               if (kd->vmst->PTD) {
-                       free(kd->vmst->PTD);
+               if (kd->vmst->PML4) {
+                       free(kd->vmst->PML4);
                }
                free(kd->vmst);
        }
@@ -87,7 +87,7 @@ _kvm_initvtop(kvm_t *kd)
        struct nlist nlist[2];
        u_long pa;
        u_long kernbase;
-       pd_entry_t      *PTD;
+       pml4_entry_t    *PML4;
 
        vm = (struct vmstate *)_kvm_malloc(kd, sizeof(*vm));
        if (vm == 0) {
@@ -95,34 +95,35 @@ _kvm_initvtop(kvm_t *kd)
                return (-1);
        }
        kd->vmst = vm;
-       vm->PTD = 0;
+       vm->PML4 = 0;
 
        nlist[0].n_name = "kernbase";
        nlist[1].n_name = 0;
 
-       if (kvm_nlist(kd, nlist) != 0)
-               kernbase = KERNBASE;    /* for old kernels */
-       else
-               kernbase = nlist[0].n_value;
+       if (kvm_nlist(kd, nlist) != 0) {
+               _kvm_err(kd, kd->program, "bad namelist - no kernbase");
+               return (-1);
+       }
+       kernbase = nlist[0].n_value;
 
-       nlist[0].n_name = "IdlePTD";
+       nlist[0].n_name = "KPML4phys";
        nlist[1].n_name = 0;
 
        if (kvm_nlist(kd, nlist) != 0) {
-               _kvm_err(kd, kd->program, "bad namelist");
+               _kvm_err(kd, kd->program, "bad namelist - no KPML4phys");
                return (-1);
        }
        if (kvm_read(kd, (nlist[0].n_value - kernbase), &pa, sizeof(pa)) !=
            sizeof(pa)) {
-               _kvm_err(kd, kd->program, "cannot read IdlePTD");
+               _kvm_err(kd, kd->program, "cannot read KPML4phys");
                return (-1);
        }
-       PTD = _kvm_malloc(kd, PAGE_SIZE);
-       if (kvm_read(kd, pa, PTD, PAGE_SIZE) != PAGE_SIZE) {
-               _kvm_err(kd, kd->program, "cannot read PTD");
+       PML4 = _kvm_malloc(kd, PAGE_SIZE);
+       if (kvm_read(kd, pa, PML4, PAGE_SIZE) != PAGE_SIZE) {
+               _kvm_err(kd, kd->program, "cannot read KPML4phys");
                return (-1);
        }
-       vm->PTD = PTD;
+       vm->PML4 = PML4;
        return (0);
 }
 
@@ -131,14 +132,20 @@ _kvm_vatop(kvm_t *kd, u_long va, u_long *pa)
 {
        struct vmstate *vm;
        u_long offset;
+       u_long pdpe_pa;
+       u_long pde_pa;
        u_long pte_pa;
+       pml4_entry_t pml4e;
+       pdp_entry_t pdpe;
        pd_entry_t pde;
        pt_entry_t pte;
+       u_long pml4eindex;
+       u_long pdpeindex;
        u_long pdeindex;
        u_long pteindex;
 
        if (kvm_ishost(kd)) {
-               _kvm_err(kd, 0, "vatop called in live kernel!");
+               _kvm_err(kd, 0, "kvm_vatop called in live kernel!");
                return((off_t)0);
        }
 
@@ -149,27 +156,55 @@ _kvm_vatop(kvm_t *kd, u_long va, u_long *pa)
         * If we are initializing (kernel page table descriptor pointer
         * not yet set) then return pa == va to avoid infinite recursion.
         */
-       if (vm->PTD == 0) {
+       if (vm->PML4 == 0) {
                *pa = va;
                return (PAGE_SIZE - offset);
        }
 
-       pdeindex = va >> PDRSHIFT;
-       pde = vm->PTD[pdeindex];
+       pml4eindex = (va >> PML4SHIFT) & (NPML4EPG - 1);
+       pml4e = vm->PML4[pml4eindex];
+       if (((u_long)pml4e & PG_V) == 0)
+               goto invalid;
+
+       pdpeindex = (va >> PDPSHIFT) & (NPDPEPG-1);
+       pdpe_pa = ((u_long)pml4e & PG_FRAME) + (pdpeindex * sizeof(pdp_entry_t));
+
+       /* XXX This has to be a physical address read, kvm_read is virtual */
+       if (lseek(kd->pmfd, pdpe_pa, 0) == -1) {
+               _kvm_syserr(kd, kd->program, "_kvm_vatop: lseek pdpe_pa");
+               goto invalid;
+       }
+       if (read(kd->pmfd, &pdpe, sizeof pdpe) != sizeof pdpe) {
+               _kvm_syserr(kd, kd->program, "_kvm_vatop: read pdpe");
+               goto invalid;
+       }
+       if (((u_long)pdpe & PG_V) == 0)
+               goto invalid;
+
+
+       pdeindex = (va >> PDRSHIFT) & (NPDEPG-1);
+       pde_pa = ((u_long)pdpe & PG_FRAME) + (pdeindex * sizeof(pd_entry_t));
+
+       /* XXX This has to be a physical address read, kvm_read is virtual */
+       if (lseek(kd->pmfd, pde_pa, 0) == -1) {
+               _kvm_syserr(kd, kd->program, "_kvm_vatop: lseek pde_pa");
+               goto invalid;
+       }
+       if (read(kd->pmfd, &pde, sizeof pde) != sizeof pde) {
+               _kvm_syserr(kd, kd->program, "_kvm_vatop: read pde");
+               goto invalid;
+       }
        if (((u_long)pde & PG_V) == 0)
                goto invalid;
 
        if ((u_long)pde & PG_PS) {
              /*
-              * No second-level page table; ptd describes one 4MB page.
-              * (We assume that the kernel wouldn't set PG_PS without enabling
-              * it cr0, and that the kernel doesn't support 36-bit physical
-              * addresses).
+              * No final-level page table; ptd describes one 2MB page.
               */
-#define        PAGE4M_MASK     (NBPDR - 1)
-#define        PG_FRAME4M      (~PAGE4M_MASK)
-               *pa = ((u_long)pde & PG_FRAME4M) + (va & PAGE4M_MASK);
-               return (NBPDR - (va & PAGE4M_MASK));
+#define        PAGE2M_MASK     (NBPDR - 1)
+#define        PG_FRAME2M      (~PAGE2M_MASK)
+               *pa = ((u_long)pde & PG_FRAME2M) + (va & PAGE2M_MASK);
+               return (NBPDR - (va & PAGE2M_MASK));
        }
 
        pteindex = (va >> PAGE_SHIFT) & (NPTEPG-1);
index b286e59..cc4cb27 100644 (file)
@@ -227,8 +227,10 @@ msg(const char *fmt, ...)
 #endif
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
+       va_end(ap);
        fflush(stdout);
        fflush(stderr);
+       va_start(ap, fmt);
        vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
        va_end(ap);
 }
index 22eb542..0246097 100644 (file)
@@ -59,6 +59,8 @@ typedef       unsigned int    vm_pindex_t;    /* physical page index */
 typedef __uint64_t     vm_poff_t;      /* physical offset */
 typedef __uint64_t     vm_paddr_t;     /* physical addr (same as vm_poff_t) */
 
+typedef        __int32_t       __segsz_t;      /* segment size */
+
 typedef        __int32_t       register_t;
 typedef        __uint32_t      u_register_t;
 
index 25ba50b..b45de94 100644 (file)
@@ -3779,16 +3779,7 @@ asr_ioctl(struct dev_ioctl_args *ap)
                 Info.numDrives = *((char *)ptok(0x475));
 
                 Info.processorFamily = ASR_sig.dsProcessorFamily;
-                switch (cpu) {
-                case CPU_386SX: case CPU_386:
-                        Info.processorType = PROC_386; break;
-                case CPU_486SX: case CPU_486:
-                        Info.processorType = PROC_486; break;
-                case CPU_586:
-                        Info.processorType = PROC_PENTIUM; break;
-                case CPU_686:
-                        Info.processorType = PROC_SEXIUM; break;
-                }
+               Info.processorType = PROC_SEXIUM; break;
                 Info.osType = OS_BSDI_UNIX;
                 Info.osMajorVersion = osrelease[0] - '0';
                 Info.osMinorVersion = osrelease[2] - '0';
index 6c41064..6f9dfce 100644 (file)
@@ -113,7 +113,7 @@ typedef     __pid_t         pid_t;          /* process id */
 #endif
 typedef        __pid_t         lwpid_t;        /* light weight process id */
 typedef        quad_t          rlim_t;         /* resource limit */
-typedef        __int32_t       segsz_t;        /* segment size */
+typedef        __segsz_t       segsz_t;        /* segment size */
 #ifndef _UID_T_DECLARED
 typedef        __uint32_t      uid_t;          /* user id */
 #define        _UID_T_DECLARED
index 2cd084a..550644a 100644 (file)
@@ -77,7 +77,7 @@ sys_obreak(struct obreak_args *uap)
                 * reduce their usage, even if they remain over the limit.
                 */
                if (new > old &&
-                   (new - base) > (unsigned) p->p_rlimit[RLIMIT_DATA].rlim_cur)
+                   (new - base) > (vm_offset_t) p->p_rlimit[RLIMIT_DATA].rlim_cur)
                        return ENOMEM;
                if (new >= VM_MAX_USER_ADDRESS)
                        return (ENOMEM);