--- Gnu-Mach/i386/intel/pmap.h 2020/09/02 04:36:59 1.1 +++ Gnu-Mach/i386/intel/pmap.h 2020/09/02 04:46:55 1.1.1.3 @@ -2,24 +2,24 @@ * Mach Operating System * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ @@ -35,19 +35,20 @@ #ifndef _PMAP_MACHINE_ #define _PMAP_MACHINE_ 1 -#ifndef ASSEMBLER +#ifndef __ASSEMBLER__ -#include #include #include #include #include +#include +#include /* * Define the generic in terms of the specific */ -#if i386 +#if defined(__i386__) #define INTEL_PGBYTES I386_PGBYTES #define INTEL_PGSHIFT I386_PGSHIFT #define intel_btop(x) i386_btop(x) @@ -57,38 +58,54 @@ #define trunc_intel_to_vm(x) trunc_i386_to_vm(x) #define round_intel_to_vm(x) round_i386_to_vm(x) #define vm_to_intel(x) vm_to_i386(x) -#endif i386 -#if i860 -#define INTEL_PGBYTES I860_PGBYTES -#define INTEL_PGSHIFT I860_PGSHIFT -#define intel_btop(x) i860_btop(x) -#define intel_ptob(x) i860_ptob(x) -#define intel_round_page(x) i860_round_page(x) -#define intel_trunc_page(x) i860_trunc_page(x) -#define trunc_intel_to_vm(x) trunc_i860_to_vm(x) -#define round_intel_to_vm(x) round_i860_to_vm(x) -#define vm_to_intel(x) vm_to_i860(x) -#endif i860 +#endif /* __i386__ */ /* - * i386/i486/i860 Page Table Entry + * i386/i486 Page Table Entry */ +#if PAE +typedef unsigned long long pt_entry_t; +#else /* PAE */ typedef unsigned int pt_entry_t; +#endif /* PAE */ #define PT_ENTRY_NULL ((pt_entry_t *) 0) -#endif ASSEMBLER +#endif /* __ASSEMBLER__ */ #define INTEL_OFFMASK 0xfff /* offset within page */ +#if PAE +#define PDPSHIFT 30 /* page directory pointer */ +#define PDPNUM 4 /* number of page directory pointers */ +#define PDPMASK 3 /* mask for page directory pointer index */ +#define PDESHIFT 21 /* page descriptor shift */ +#define PDEMASK 0x1ff /* mask for page descriptor index */ +#define PTESHIFT 12 /* page table shift */ +#define PTEMASK 0x1ff /* mask for page table index */ +#else /* PAE */ +#define PDPNUM 1 /* number of page directory pointers */ #define PDESHIFT 22 /* page descriptor shift */ #define PDEMASK 0x3ff /* mask for page descriptor index */ #define PTESHIFT 12 /* page table shift */ #define PTEMASK 0x3ff /* mask for page table index */ +#endif /* PAE */ /* * Convert linear offset to page descriptor index */ +#if PAE +/* Making it include the page directory pointer table index too */ +#define lin2pdenum(a) (((a) >> PDESHIFT) & 0x7ff) +#else #define lin2pdenum(a) (((a) >> PDESHIFT) & PDEMASK) +#endif + +/* + * Convert linear offset to page directory pointer index + */ +#if PAE +#define lin2pdpnum(a) (((a) >> PDPSHIFT) & PDPMASK) +#endif /* * Convert page descriptor index to linear address @@ -101,45 +118,39 @@ typedef unsigned int pt_entry_t; #define ptenum(a) (((a) >> PTESHIFT) & PTEMASK) #define NPTES (intel_ptob(1)/sizeof(pt_entry_t)) -#define NPDES (intel_ptob(1)/sizeof(pt_entry_t)) +#define NPDES (PDPNUM * (intel_ptob(1)/sizeof(pt_entry_t))) /* * Hardware pte bit definitions (to be used directly on the ptes * without using the bit fields). */ -#if i860 -#define INTEL_PTE_valid 0x00000001 -#else #define INTEL_PTE_VALID 0x00000001 -#endif #define INTEL_PTE_WRITE 0x00000002 #define INTEL_PTE_USER 0x00000004 #define INTEL_PTE_WTHRU 0x00000008 #define INTEL_PTE_NCACHE 0x00000010 #define INTEL_PTE_REF 0x00000020 #define INTEL_PTE_MOD 0x00000040 +#ifdef MACH_PV_PAGETABLES +/* Not supported */ +#define INTEL_PTE_GLOBAL 0x00000000 +#else /* MACH_PV_PAGETABLES */ +#define INTEL_PTE_GLOBAL 0x00000100 +#endif /* MACH_PV_PAGETABLES */ #define INTEL_PTE_WIRED 0x00000200 +#ifdef PAE +#define INTEL_PTE_PFN 0x00007ffffffff000ULL +#else #define INTEL_PTE_PFN 0xfffff000 - -#if i860 -#if NOCACHE -#define INTEL_PTE_VALID (INTEL_PTE_valid \ - |INTEL_PTE_WTHRU \ - |INTEL_PTE_NCACHE \ - |INTEL_PTE_REF \ - |INTEL_PTE_MOD \ - ) -#else NOCACHE -#define INTEL_PTE_VALID (INTEL_PTE_valid \ - |INTEL_PTE_REF \ - |INTEL_PTE_MOD \ - ) -#endif NOCACHE -#endif i860 +#endif #define pa_to_pte(a) ((a) & INTEL_PTE_PFN) +#ifdef MACH_PSEUDO_PHYS +#define pte_to_pa(p) ma_to_pa((p) & INTEL_PTE_PFN) +#else /* MACH_PSEUDO_PHYS */ #define pte_to_pa(p) ((p) & INTEL_PTE_PFN) +#endif /* MACH_PSEUDO_PHYS */ #define pte_increment_pa(p) ((p) += INTEL_OFFMASK+1) /* @@ -147,12 +158,15 @@ typedef unsigned int pt_entry_t; */ #define ptetokv(a) (phystokv(pte_to_pa(a))) -#ifndef ASSEMBLER +#ifndef __ASSEMBLER__ typedef volatile long cpu_set; /* set of CPUs - must be <= 32 */ /* changed by other processors */ struct pmap { - pt_entry_t *dirbase; /* page directory pointer register */ + pt_entry_t *dirbase; /* page directory table */ +#if PAE + pt_entry_t *pdpbase; /* page directory pointer table */ +#endif /* PAE */ int ref_count; /* reference count */ decl_simple_lock_data(,lock) /* lock on map */ @@ -164,11 +178,19 @@ typedef struct pmap *pmap_t; #define PMAP_NULL ((pmap_t) 0) -#if i860 -/*#define set_dirbase(dirbase) flush_and_ctxsw(dirbase)*//*akp*/ -#else -#define set_dirbase(dirbase) set_cr3(dirbase) -#endif +#ifdef MACH_PV_PAGETABLES +extern void pmap_set_page_readwrite(void *addr); +extern void pmap_set_page_readonly(void *addr); +extern void pmap_set_page_readonly_init(void *addr); +extern void pmap_map_mfn(void *addr, unsigned long mfn); +extern void pmap_clear_bootstrap_pagetable(pt_entry_t *addr); +#endif /* MACH_PV_PAGETABLES */ + +#if PAE +#define set_pmap(pmap) set_cr3(kvtophys((vm_offset_t)(pmap)->pdpbase)) +#else /* PAE */ +#define set_pmap(pmap) set_cr3(kvtophys((vm_offset_t)(pmap)->dirbase)) +#endif /* PAE */ #if NCPUS > 1 /* @@ -195,14 +217,14 @@ boolean_t cpu_update_needed[NCPUS]; * External declarations for PMAP_ACTIVATE. */ -void process_pmap_updates(); -void pmap_update_interrupt(); +void process_pmap_updates(pmap_t); +void pmap_update_interrupt(void); extern pmap_t kernel_pmap; -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ /* - * Machine dependent routines that are used only for i386/i486/i860. + * Machine dependent routines that are used only for i386/i486. */ pt_entry_t *pmap_pte(pmap_t pmap, vm_offset_t addr); @@ -266,7 +288,7 @@ pt_entry_t *pmap_pte(pmap_t pmap, vm_off /* \ * If this is the kernel pmap, switch to its page tables. \ */ \ - set_dirbase(kvtophys(tpmap->dirbase)); \ + set_pmap(tpmap); \ } \ else { \ /* \ @@ -284,7 +306,7 @@ pt_entry_t *pmap_pte(pmap_t pmap, vm_off * No need to invalidate the TLB - the entire user pmap \ * will be invalidated by reloading dirbase. \ */ \ - set_dirbase(kvtophys(tpmap->dirbase)); \ + set_pmap(tpmap); \ \ /* \ * Mark that this cpu is using the pmap. \ @@ -355,7 +377,7 @@ pt_entry_t *pmap_pte(pmap_t pmap, vm_off splx(s); \ } -#else NCPUS > 1 +#else /* NCPUS > 1 */ /* * With only one CPU, we just have to indicate whether the pmap is @@ -363,28 +385,34 @@ pt_entry_t *pmap_pte(pmap_t pmap, vm_off */ #define PMAP_ACTIVATE_KERNEL(my_cpu) { \ + (void) (my_cpu); \ kernel_pmap->cpus_using = TRUE; \ } #define PMAP_DEACTIVATE_KERNEL(my_cpu) { \ + (void) (my_cpu); \ kernel_pmap->cpus_using = FALSE; \ } #define PMAP_ACTIVATE_USER(pmap, th, my_cpu) { \ register pmap_t tpmap = (pmap); \ + (void) (th); \ + (void) (my_cpu); \ \ - set_dirbase(kvtophys(tpmap->dirbase)); \ + set_pmap(tpmap); \ if (tpmap != kernel_pmap) { \ tpmap->cpus_using = TRUE; \ } \ } #define PMAP_DEACTIVATE_USER(pmap, thread, cpu) { \ + (void) (thread); \ + (void) (cpu); \ if ((pmap) != kernel_pmap) \ (pmap)->cpus_using = FALSE; \ } -#endif NCPUS > 1 +#endif /* NCPUS > 1 */ #define PMAP_CONTEXT(pmap, thread) @@ -396,6 +424,33 @@ pt_entry_t *pmap_pte(pmap_t pmap, vm_off #define pmap_attribute(pmap,addr,size,attr,value) \ (KERN_INVALID_ADDRESS) -#endif ASSEMBLER +/* + * Bootstrap the system enough to run with virtual memory. + * Allocate the kernel page directory and page tables, + * and direct-map all physical memory. + * Called with mapping off. + */ +extern void pmap_bootstrap(void); + +extern void pmap_unmap_page_zero (void); + +/* + * pmap_zero_page zeros the specified (machine independent) page. + */ +extern void pmap_zero_page (vm_offset_t); + +/* + * pmap_copy_page copies the specified (machine independent) pages. + */ +extern void pmap_copy_page (vm_offset_t, vm_offset_t); + +/* + * kvtophys(addr) + * + * Convert a kernel virtual address to a physical address + */ +extern vm_offset_t kvtophys (vm_offset_t); + +#endif /* __ASSEMBLER__ */ -#endif _PMAP_MACHINE_ +#endif /* _PMAP_MACHINE_ */