mini-os: Separating x86 specific memory management parts
PATCH 1/1 mini-os: Separating x86 specific memory management parts
Hi Gregor,
for the ia64 port I separated the most x86 specific parts and moved these to architecture specific files.
There are nowminios/mm.cminios/arch/x86/mm.cminios/include/mm.hminios/include/x86/arch_mm.h
In init_mm() now a special arch_init_mm() and arch_init_demand_mapping_area() are called. Maybe the arch_init_demand_mapping_area() can be moved/changed later, because it's not needed on ia64.
I also added a new macro PHYS_PFN() and used it in the buddy allocator. A second change is the use of to_virt() instead of VIRT_START. Please can you have a look and send your comments!
Thanks.
Dietmar.
# HG changeset patch
# User [email protected]
# Date 1161004815 -7200
# Node ID 7614ed2fa89bcd7b10be2488d42c890cca3359c0
# Parent 6ed4368b4a9e1924c983774c4b1a2b6baf8e98a6
I separated the parts special to the x86 architecture and moved it to the new files arch/x86/mm.c and include/x86/arch_mm.h.
extras/mini-os/include/mm.h +7 -171
@@ -29,182 +29,15 @@#include <xen/arch-x86_32.h> #elif defined(__x86_64__)#include <xen/arch-x86_64.h> +#elif defined(__ia64__) +#include <xen/arch-ia64.h> #else #error "Unsupported architecture"#endif #include <lib.h> +#include <arch_mm.h> -#define L1_FRAME 1 -#define L2_FRAME 2 -#define L3_FRAME 3 - -#define L1_PAGETABLE_SHIFT 12 - -#if defined(__i386__) - -#if !defined(CONFIG_X86_PAE ) - -#define L2_PAGETABLE_SHIFT 22 - -#define L1_PAGETABLE_ENTRIES 1024 -#define L2_PAGETABLE_ENTRIES 1024 - -#define PADDR_BITS 32 -#define PADDR_MASK (~0UL) - -#define NOT_L1_FRAMES 1 -#define PRIpte "08lx" -typedef unsigned long pgentry_t ; - -#else /* defined(CONFIG_X86_PAE) */ - -#define L2_PAGETABLE_SHIFT 21 -#define L3_PAGETABLE_SHIFT 30 - -#define L1_PAGETABLE_ENTRIES 512 -#define L2_PAGETABLE_ENTRIES 512 -#define L3_PAGETABLE_ENTRIES 4 - -#define PADDR_BITS 44 -#define PADDR_MASK ((1ULL << PADDR_BITS)-1) - -#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) - -/* -* If starting from virtual address greater than 0xc0000000, -* this value will be 2 to account for final mid-level page -* directory which is always mapped in at this location. -*/ -#define NOT_L1_FRAMES 3 -#define PRIpte "016llx" -typedef uint64_t pgentry_t ; - -#endif /* !defined(CONFIG_X86_PAE) */ - -#elif defined(__x86_64__) - -#define L2_PAGETABLE_SHIFT 21 -#define L3_PAGETABLE_SHIFT 30 -#define L4_PAGETABLE_SHIFT 39 - -#define L1_PAGETABLE_ENTRIES 512 -#define L2_PAGETABLE_ENTRIES 512 -#define L3_PAGETABLE_ENTRIES 512 -#define L4_PAGETABLE_ENTRIES 512 - -/* These are page-table limitations. Current CPUs support only 40-bit phys. */ -#define PADDR_BITS 52 -#define VADDR_BITS 48 -#define PADDR_MASK ((1UL << PADDR_BITS)-1) -#define VADDR_MASK ((1UL << VADDR_BITS)-1) - -#define L2_MASK ((1UL << L3_PAGETABLE_SHIFT) - 1) -#define L3_MASK ((1UL << L4_PAGETABLE_SHIFT) - 1) - -#define NOT_L1_FRAMES 3 -#define PRIpte "016lx" -typedef unsigned long pgentry_t ; - -#endif - -#define L1_MASK ((1UL << L2_PAGETABLE_SHIFT) - 1) - -/* Given a virtual address, get an entry offset into a page table. */ -#define l1_table_offset (_a) \ - (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)) -#define l2_table_offset (_a) \ - (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1)) -#if defined(__x86_64__) || defined(CONFIG_X86_PAE ) -#define l3_table_offset (_a) \ - (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1)) -#endif -#if defined(__x86_64__) -#define l4_table_offset (_a) \ - (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) -#endif - -#define _PAGE_PRESENT 0x001UL -#define _PAGE_RW 0x002UL -#define _PAGE_USER 0x004UL -#define _PAGE_PWT 0x008UL -#define _PAGE_PCD 0x010UL -#define _PAGE_ACCESSED 0x020UL -#define _PAGE_DIRTY 0x040UL -#define _PAGE_PAT 0x080UL -#define _PAGE_PSE 0x080UL -#define _PAGE_GLOBAL 0x100UL - -#if defined(__i386__) -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY |_PAGE_USER) -#if defined(CONFIG_X86_PAE ) -#define L3_PROT (_PAGE_PRESENT) -#endif /* CONFIG_X86_PAE */ -#elif defined(__x86_64__) -#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER) -#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) -#endif /* __i386__ || __x86_64__ */ - -#ifndef CONFIG_X86_PAE -#define PAGE_SIZE (1UL << L1_PAGETABLE_SHIFT) -#else -#define PAGE_SIZE (1ULL << L1_PAGETABLE_SHIFT) -#endif -#define PAGE_SHIFT L1_PAGETABLE_SHIFT -#define PAGE_MASK (~(PAGE_SIZE-1)) - -#define PFN_UP (x) (((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT) -#define PFN_DOWN (x) ((x) >> L1_PAGETABLE_SHIFT) -#define PFN_PHYS (x) ((x) << L1_PAGETABLE_SHIFT) - -/* to align the pointer to the (next) page boundary */ -#define PAGE_ALIGN (addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) - -/* Definitions for machine and pseudophysical addresses. */ -#ifdef CONFIG_X86_PAE -typedef unsigned long long paddr_t ; -typedef unsigned long long maddr_t ; -#else -typedef unsigned long paddr_t ; -typedef unsigned long maddr_t ; -#endif - -extern unsigned long *phys_to_machine_mapping; -extern char _text, _etext, _edata, _end; -#define pfn_to_mfn (_pfn) (phys_to_machine_mapping[(_pfn)]) -static __inline__maddr_t phys_to_machine (paddr_t phys) -{ -maddr_t machine =pfn_to_mfn (phys >>PAGE_SHIFT ); - machine = (machine <<PAGE_SHIFT ) | (phys & ~PAGE_MASK ); -return machine; -} - -#define mfn_to_pfn (_mfn) (machine_to_phys_mapping[(_mfn)]) -static __inline__paddr_t machine_to_phys (maddr_t machine) -{ -paddr_t phys =mfn_to_pfn (machine >>PAGE_SHIFT ); - phys = (phys <<PAGE_SHIFT ) | (machine & ~PAGE_MASK ); -return phys; -} - -#define VIRT_START ((unsigned long)&_text) - -#define to_phys (x) ((unsigned long)(x)-VIRT_START) -#define to_virt (x) ((void *)((unsigned long)(x)+VIRT_START)) - -#define virt_to_pfn (_virt) (PFN_DOWN(to_phys(_virt))) -#define virt_to_mfn (_virt) (pfn_to_mfn(virt_to_pfn(_virt))) -#define mach_to_virt (_mach) (to_virt(machine_to_phys(_mach))) -#define virt_to_mach (_virt) (phys_to_machine(to_phys(_virt))) -#define mfn_to_virt (_mfn) (to_virt(mfn_to_pfn(_mfn) << PAGE_SHIFT)) -#define pfn_to_virt (_pfn) (to_virt((_pfn) << PAGE_SHIFT)) - -/* Pagetable walking. */ -#define pte_to_mfn (_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT) -#define pte_to_virt (_pte) to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT)void init_mm (void );unsigned long alloc_pages (int order);
@@ -220,7 +53,10 @@ static __inline__ int get_order(unsigned return order; } +void arch_init_demand_mapping_area (unsigned long max_pfn); +void arch_init_mm (unsigned long * start_pfn_p,unsigned long * max_pfn_p); -void *map_frames (unsigned long *f,unsigned long n); +void *map_frames (unsigned long *f,unsigned long n); +#endif /* _MM_H_ */
extras/mini-os/mm.c +8 -379
423 lines not on this page · raw message
extras/mini-os/arch/x86/mm.c new file +429 -0
429 lines not on this page · raw message
extras/mini-os/include/x86/arch_mm.h new file +212 -0
212 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel