[haiku-commits] haiku: hrev44957 - src/system/boot/arch/arm src/system/kernel/arch/arm src/system/kernel/arch/arm/paging/32bit headers/private/kernel/arch/arm src/system

  • From: mmlr@xxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 4 Dec 2012 23:58:32 +0100 (CET)

hrev44957 adds 20 changesets to branch 'master'
old head: 7271621fbe58529985108223858deb3676e9589a
new head: 760de9b200a5023e2f79e2ee04ba570869de7ae7
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=760de9b+%5E7271621

----------------------------------------------------------------------------

67d9fcc: Whitespace cleanup, no functional change.

2dcc1cf: Remove test pattern that is no longer needed.

3338834: Rephrase the debug output, it is not that early anymore.

d50875d: Use format macros in debug output.

eca34ad: Print page and cache using initial commands in panic message.

0589347: Style cleanup only.

0deac57: Simplify, don't do the calculation twice.

3d4175b: Map the page directory before turning on the MMU.
  
  And actually use the virtual address for it later on. This wasn't
  problematic as the virtual and physical addresses are identity mapped,
  but it seems more correct to do it in this order.

50c463f: Header cleanup, rename macros for more consistency.

89564c0: Simplify the page directory init loops.
  
  Also check and possibly reuse an existing page directory entry. This
  makes the possible memory maps a little more flexible.

a438da7: Clear the page tables on creation, use macros for counts.
  
  This makes it less likely that uninitialized entries cause troubles.
  Also panic if we encounter an unknown entry type instead of defaulting
  to 4K pages.

83f7c22: Reuse get_or_create_page_table() and remove similar add_page().
  
  The former also does the initialization, simplifying the code and
  reducing redundancy with the page directory init path.

7c45cf7: Remove tracking of sMaxVirtualAddress as it's not used.
  
  The value computed isn't actually used anywhere. It just ensured that
  a panic would be triggered if we "skipped" to virtual addresses further
  along. This shouldn't be problematic however.

fd6e3a1: Use the existing ARM MMU definitions and remove duplicates.

926d102: Fix wrong address mask (page directory vs. page table).

f0422c6: Only set the physical address if the entry is mapped.
  
  Otherwise, even when the address was 0, we would possibly set the
  physical address to != 0 as we always applied the page offset.

2b5d52a: Whitespace cleanup only.

1ed5f66: Add missing function end macro.

85db228: Style cleanup only.

760de9b: Tiny code style cleanup.

                                            [ Michael Lotz <mmlr@xxxxxxxx> ]

----------------------------------------------------------------------------

11 files changed, 267 insertions(+), 261 deletions(-)
headers/private/kernel/arch/arm/arm_mmu.h        |  57 +++--
src/system/boot/arch/arm/arch_mmu.cpp            | 209 +++++++++----------
.../raspberrypi_arm/arch_framebuffer_bcm2708.cpp |   9 -
.../boot/platform/raspberrypi_arm/video.cpp      |   3 +-
src/system/kernel/arch/arm/arch_exceptions.S     | 136 ++++++------
src/system/kernel/arch/arm/arch_int.cpp          |  43 ++--
.../arm/paging/32bit/ARMPagingMethod32Bit.cpp    |  17 +-
.../paging/32bit/ARMVMTranslationMap32Bit.cpp    |  13 +-
src/system/kernel/arch/arm/paging/32bit/paging.h |  33 +--
src/system/kernel/fs/vfs.cpp                     |   4 +-
src/system/kernel/vm/VMCache.cpp                 |   4 +-

############################################################################

Commit:      67d9fcc3baae89c0d3bad56b592dc81d86eff892
URL:         http://cgit.haiku-os.org/haiku/commit/?id=67d9fcc
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Sun Dec  2 13:10:02 2012 UTC

Whitespace cleanup, no functional change.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/arm/paging/32bit/paging.h 
b/src/system/kernel/arch/arm/paging/32bit/paging.h
index 5aef536..8bc0468 100644
--- a/src/system/kernel/arch/arm/paging/32bit/paging.h
+++ b/src/system/kernel/arch/arm/paging/32bit/paging.h
@@ -16,31 +16,31 @@
 #include <int.h>
 #include <kernel.h>
 
-#define VADDR_TO_PDENT(va) ((va) >> 20)
-#define VADDR_TO_PTENT(va) (((va) & 0xff000) >> 12)
-#define VADDR_TO_PGOFF(va) ((va) & 0x0fff)
+#define VADDR_TO_PDENT(va)                                     ((va) >> 20)
+#define VADDR_TO_PTENT(va)                                     (((va) & 
0xff000) >> 12)
+#define VADDR_TO_PGOFF(va)                                     ((va) & 0x0fff)
 
 // page directory entry bits
-#define ARM_PDE_TYPE_MASK                      0x00000003
+#define ARM_PDE_TYPE_MASK                                      0x00000003
 #define ARM_PDE_TYPE_COARSE_L2_PAGE_TABLE      0x00000001
-#define ARM_PDE_TYPE_SECTION                   0x00000002
+#define ARM_PDE_TYPE_SECTION                           0x00000002
 #define ARM_PDE_TYPE_FINE_L2_PAGE_TABLE                0x00000003
 
-#define ARM_PDE_ADDRESS_MASK                   0xfffffc00
+#define ARM_PDE_ADDRESS_MASK                           0xfffffc00
 
 // page table entry bits
-#define ARM_PTE_TYPE_MASK                      0x00000003
-#define ARM_PTE_TYPE_LARGE_PAGE                        0x00000001
-#define ARM_PTE_TYPE_SMALL_PAGE                        0x00000002
-#define ARM_PTE_TYPE_EXT_SMALL_PAGE            0x00000003
-
-#define ARM_PTE_ADDRESS_MASK           0xfffff000
-
-#define FIRST_USER_PGDIR_ENT    (VADDR_TO_PDENT(USER_BASE))
-#define NUM_USER_PGDIR_ENTS     (VADDR_TO_PDENT(ROUNDUP(USER_SIZE, \
-                                                                       
B_PAGE_SIZE * 1024)))
-#define FIRST_KERNEL_PGDIR_ENT  (VADDR_TO_PDENT(KERNEL_BASE))
-#define NUM_KERNEL_PGDIR_ENTS   (VADDR_TO_PDENT(KERNEL_SIZE))
+#define ARM_PTE_TYPE_MASK                                      0x00000003
+#define ARM_PTE_TYPE_LARGE_PAGE                                0x00000001
+#define ARM_PTE_TYPE_SMALL_PAGE                                0x00000002
+#define ARM_PTE_TYPE_EXT_SMALL_PAGE                    0x00000003
+
+#define ARM_PTE_ADDRESS_MASK                           0xfffff000
+
+#define FIRST_USER_PGDIR_ENT                           
(VADDR_TO_PDENT(USER_BASE))
+#define NUM_USER_PGDIR_ENTS                                    
(VADDR_TO_PDENT(ROUNDUP(USER_SIZE, \
+                                                                               
                B_PAGE_SIZE * 1024)))
+#define FIRST_KERNEL_PGDIR_ENT                         
(VADDR_TO_PDENT(KERNEL_BASE))
+#define NUM_KERNEL_PGDIR_ENTS                          
(VADDR_TO_PDENT(KERNEL_SIZE))
 
 
 static const size_t kPageTableAlignment = 1024 * B_PAGE_SIZE;

############################################################################

Commit:      2dcc1cfeb958be32f4462c96f49b80fd30cc154c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=2dcc1cf
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Sun Dec  2 21:36:25 2012 UTC

Remove test pattern that is no longer needed.

----------------------------------------------------------------------------

diff --git 
a/src/system/boot/platform/raspberrypi_arm/arch_framebuffer_bcm2708.cpp 
b/src/system/boot/platform/raspberrypi_arm/arch_framebuffer_bcm2708.cpp
index 57d6243..9eb913f 100644
--- a/src/system/boot/platform/raspberrypi_arm/arch_framebuffer_bcm2708.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/arch_framebuffer_bcm2708.cpp
@@ -161,15 +161,6 @@ ArchFramebufferBCM2708::SetVideoMode(int width, int 
height, int depth)
        fBase = (addr_t)mmu_map_physical_memory(fPhysicalBase, fSize,
                kDefaultPageFlags);
 
-       uint8* line = (uint8*)fBase;
-       for (uint32 y = 0; y < sFramebufferConfig.height; y++) {
-               volatile uint16* pixel = (volatile uint16*)line;
-               for (uint32 x = 0; x < sFramebufferConfig.width; x++)
-                       *(pixel++) = y % 2 == 0 ? 0xffff : 0x0000;
-
-               line += sFramebufferConfig.bytes_per_row;
-       }
-
        fCurrentWidth = width;
        fCurrentHeight = height;
        fCurrentDepth = depth;

############################################################################

Commit:      333883485c441f5cbe0708642141973577695a97
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3338834
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Sun Dec  2 21:40:16 2012 UTC

Rephrase the debug output, it is not that early anymore.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/raspberrypi_arm/video.cpp 
b/src/system/boot/platform/raspberrypi_arm/video.cpp
index 2bfe171..e33a32d 100644
--- a/src/system/boot/platform/raspberrypi_arm/video.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/video.cpp
@@ -82,8 +82,7 @@ platform_init_video(void)
        if (result != B_OK)
                return result;
 
-       blue_screen_clear_screen();
-       blue_screen_puts("Welcome to very early on-screen debug output on 
rPi!\n");
+       blue_screen_puts("Welcome to early on-screen debug output on rPi!\n");
        sOnScreenDebugOutputAvailable = true;
 
        gKernelArgs.frame_buffer.physical_buffer.start

############################################################################

Commit:      d50875de46aeb3378feda778b54d3fa288e2571a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=d50875d
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Sun Dec  2 21:42:55 2012 UTC

Use format macros in debug output.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp
index ace2308..ebca444 100644
--- a/src/system/kernel/fs/vfs.cpp
+++ b/src/system/kernel/fs/vfs.cpp
@@ -4617,8 +4617,8 @@ status_t
 vfs_get_file_map(struct vnode* vnode, off_t offset, size_t size,
        file_io_vec* vecs, size_t* _count)
 {
-       FUNCTION(("vfs_get_file_map: vnode %p, vecs %p, offset %Ld, size = 
%lu\n",
-               vnode, vecs, offset, size));
+       FUNCTION(("vfs_get_file_map: vnode %p, vecs %p, offset %" B_PRIdOFF
+               ", size = %" B_PRIuSIZE "\n", vnode, vecs, offset, size));
 
        return FS_CALL(vnode, get_file_map, offset, size, vecs, _count);
 }

############################################################################

Commit:      eca34ad1680056e2c7e757e4662199c80297cb4c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=eca34ad
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Sun Dec  2 21:43:50 2012 UTC

Print page and cache using initial commands in panic message.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp
index a174f1d..d9efe30 100644
--- a/src/system/kernel/vm/VMCache.cpp
+++ b/src/system/kernel/vm/VMCache.cpp
@@ -670,8 +670,8 @@ VMCache::Delete()
        // free all of the pages in the cache
        while (vm_page* page = pages.Root()) {
                if (!page->mappings.IsEmpty() || page->WiredCount() != 0) {
-                       panic("remove page %p from cache %p: page still has 
mappings!\n",
-                               page, this);
+                       panic("remove page %p from cache %p: page still has 
mappings!\n"
+                               "@!page %p; cache %p", page, this, page, this);
                }
 
                // remove it

############################################################################

Commit:      05893479e36bc1d18514ad41d2081acbc5f0a81d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0589347
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 20:24:41 2012 UTC

Style cleanup only.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 301c6fc..3e40e63 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -116,7 +116,7 @@ static struct memblock LOADER_MEMORYMAP[] = {
                "framebuffer", // 2MB framebuffer ram
                FB_BASE,
                FB_BASE + FB_SIZE - 1,
-               MMU_L2_FLAG_AP_RW|MMU_L2_FLAG_C,
+               MMU_L2_FLAG_AP_RW | MMU_L2_FLAG_C,
        },
 #endif
 };
@@ -151,7 +151,7 @@ get_next_virtual_address(size_t size)
 
 
 static addr_t
-get_next_virtual_address_alligned (size_t size, uint32 mask)
+get_next_virtual_address_alligned(size_t size, uint32 mask)
 {
        addr_t address = (sNextVirtualAddress) & mask;
        sNextVirtualAddress = address + size;
@@ -253,7 +253,7 @@ get_next_page_table(uint32 type)
                sNextPageTableAddress, kPageTableRegionEnd, type));
 
        size_t size = 0;
-       switch(type) {
+       switch (type) {
                case MMU_L1_TYPE_COARSE:
                default:
                        size = 1024;
@@ -281,22 +281,22 @@ void
 init_page_directory()
 {
        TRACE(("init_page_directory\n"));
-       uint32 smalltype;
+       uint32 smallType;
 
-       // see if subpages disabled
-       if (mmu_read_C1() & (1<<23))
-               smalltype = MMU_L2_TYPE_SMALLNEW;
+       // see if subpages are disabled
+       if (mmu_read_C1() & (1 << 23))
+               smallType = MMU_L2_TYPE_SMALLNEW;
        else
-               smalltype = MMU_L2_TYPE_SMALLEXT;
+               smallType = MMU_L2_TYPE_SMALLEXT;
 
        gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
 
-       // clear out the pgdir
+       // clear out the page directory
        for (uint32 i = 0; i < 4096; i++)
-       sPageDirectory[i] = 0;
+               sPageDirectory[i] = 0;
 
        uint32 *pageTable = NULL;
-       for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP);i++) {
+       for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
 
                pageTable = get_next_page_table(MMU_L1_TYPE_COARSE);
                TRACE(("BLOCK: %s START: %lx END %lx\n", 
LOADER_MEMORYMAP[i].name,
@@ -305,7 +305,7 @@ init_page_directory()
 
                int c = 0;
                while (pos < LOADER_MEMORYMAP[i].end) {
-                       pageTable[c] = pos |  LOADER_MEMORYMAP[i].flags | 
smalltype;
+                       pageTable[c] = pos | LOADER_MEMORYMAP[i].flags | 
smallType;
 
                        c++;
                        if (c > 255) { // we filled a pagetable => we need a 
new one
@@ -595,7 +595,7 @@ mmu_init(void)
 {
        TRACE(("mmu_init\n"));
 
-       mmu_write_C1(mmu_read_C1() & ~((1<<29)|(1<<28)|(1<<0)));
+       mmu_write_C1(mmu_read_C1() & ~((1 << 29) | (1 << 28) | (1 << 0)));
                // access flag disabled, TEX remap disabled, mmu disabled
 
        uint32 highestRAMAddress = SDRAM_BASE;
@@ -609,7 +609,7 @@ mmu_init(void)
                        sNextPageTableAddress = LOADER_MEMORYMAP[i].start
                                + MMU_L1_TABLE_SIZE;
                        kPageTableRegionEnd = LOADER_MEMORYMAP[i].end;
-                       sPageDirectory = (uint32 *) LOADER_MEMORYMAP[i].start;
+                       sPageDirectory = (uint32 *)LOADER_MEMORYMAP[i].start;
                }
 
                if (strncmp("RAM_", LOADER_MEMORYMAP[i].name, 4) == 0) {

############################################################################

Commit:      0deac574bda7221a6e1b557a7f943631011a6d11
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0deac57
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 20:24:53 2012 UTC

Simplify, don't do the calculation twice.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 3e40e63..b20b62c 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -634,10 +634,10 @@ mmu_init(void)
                (addr_t)sPageDirectory, MMU_L1_TABLE_SIZE, kDefaultPageFlags);
 
        // map in a kernel stack
-       gKernelArgs.cpu_kstack[0].start = (addr_t)mmu_allocate(NULL,
-               KERNEL_STACK_SIZE + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE);
        gKernelArgs.cpu_kstack[0].size = KERNEL_STACK_SIZE
                + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE;
+       gKernelArgs.cpu_kstack[0].start = (addr_t)mmu_allocate(NULL,
+               gKernelArgs.cpu_kstack[0].size);
 
        TRACE(("kernel stack at 0x%" B_PRIx64 " to 0x%" B_PRIx64 "\n",
                gKernelArgs.cpu_kstack[0].start,

############################################################################

Commit:      3d4175bfe19b7bcc7b79e9518095f17586bfee11
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3d4175b
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 20:22:15 2012 UTC

Map the page directory before turning on the MMU.

And actually use the virtual address for it later on. This wasn't
problematic as the virtual and physical addresses are identity mapped,
but it seems more correct to do it in this order.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index b20b62c..bd39d90 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -325,6 +325,10 @@ init_page_directory()
                }
        }
 
+       // Map the page directory itself.
+       addr_t virtualPageDirectory = mmu_map_physical_memory(
+               (addr_t)sPageDirectory, ARM_MMU_L1_TABLE_SIZE, 
kDefaultPageFlags);
+
        mmu_flush_TLB();
 
        /* set up the translation table base */
@@ -337,6 +341,10 @@ init_page_directory()
 
        /* turn on the mmu */
        mmu_write_C1(mmu_read_C1() | 0x1);
+
+       // Use the mapped page directory from now on.
+       sPageDirectory = (uint32 *)virtualPageDirectory;
+       gKernelArgs.arch_args.vir_pgdir = virtualPageDirectory;
 }
 
 
@@ -629,10 +637,6 @@ mmu_init(void)
 
        init_page_directory();
 
-       // map the page directory on the next vpage
-       gKernelArgs.arch_args.vir_pgdir = mmu_map_physical_memory(
-               (addr_t)sPageDirectory, MMU_L1_TABLE_SIZE, kDefaultPageFlags);
-
        // map in a kernel stack
        gKernelArgs.cpu_kstack[0].size = KERNEL_STACK_SIZE
                + KERNEL_STACK_GUARD_PAGES * B_PAGE_SIZE;

############################################################################

Commit:      50c463f4f1af22b46db3a4b7d1ead4a5e11bafa3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=50c463f
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 21:24:32 2012 UTC

Header cleanup, rename macros for more consistency.

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/arch/arm/arm_mmu.h 
b/headers/private/kernel/arch/arm/arm_mmu.h
index b125ef0..1ff3a97 100644
--- a/headers/private/kernel/arch/arm/arm_mmu.h
+++ b/headers/private/kernel/arch/arm/arm_mmu.h
@@ -18,21 +18,21 @@
 /*
  * L1 defines for the page directory (page table walk methods)
  */
-#define MMU_L1_TYPE_FAULT              0x0
+#define ARM_MMU_L1_TYPE_FAULT                  0x0
        // MMU Fault
        // 31                                                  2 10
        // |                                                    |00|
-#define MMU_L1_TYPE_SECTION            0x2
+#define ARM_MMU_L1_TYPE_SECTION                        0x2
        // Single step table walk, 4096 entries
        // 1024K pages, 16K consumed
        // 31                   20 19   12 11  10 9 8      5 432 10
        // | page table address   |  0?   |  AP  |0| domain |1CB|10|
-#define MMU_L1_TYPE_FINE               0x3
+#define ARM_MMU_L1_TYPE_FINE                   0x3
        // Three(?) step table walk, 1024 entries
        // 1K, 4K, 64K pages, 4K consumed
        // 31                           12 11     9 8      5 432 10
        // | page table address           |   0?   | domain |100|11|
-#define MMU_L1_TYPE_COARSE             0x1
+#define ARM_MMU_L1_TYPE_COARSE                 0x1
        // Two step table walk, 256 entries
        // 4K(Haiku), 64K pages, 1K consumed
        // 31                                  10 9 8      5 432 10
@@ -52,37 +52,47 @@
  * I will use the old format...
  */
 
-#define MMU_L2_TYPE_SMALLEXT 0x3
+#define ARM_MMU_L2_TYPE_SMALLEXT               0x3
+
 /* for new format entries (cortex-a8) */
-#define MMU_L2_TYPE_SMALLNEW 0x2
+#define ARM_MMU_L2_TYPE_SMALLNEW               0x2
 
 // for B C and TEX see ARM arm B4-11
-#define MMU_L2_FLAG_B 0x4
-#define MMU_L2_FLAG_C 0x8
-#define MMU_L2_FLAG_TEX 0      // use 0b000 as TEX
-#define MMU_L2_FLAG_AP_RW 0x30 // allow read and write for user and system
-// #define MMU_L2_FLAG_AP_
+#define ARM_MMU_L2_FLAG_B                              0x4
+#define ARM_MMU_L2_FLAG_C                              0x8
+#define ARM_MMU_L2_FLAG_TEX                            0       // use 0b000 as 
TEX
+#define ARM_MMU_L2_FLAG_AP_RW                  0x30
+       // allow read and write for user and system
 
+#define ARM_MMU_L1_TABLE_ENTRY_COUNT   4096
+#define ARM_MMU_L1_TABLE_SIZE                  (ARM_MMU_L1_TABLE_ENTRY_COUNT \
+                                                                               
        * sizeof(uint32))
 
-#define MMU_L1_TABLE_SIZE (4096 * 4)
-       //4096 entries (one entry per MB) -> 16KB
-#define MMU_L2_COARSE_TABLE_SIZE (256 * 4)
-       //256 entries (one entry per 4KB) -> 1KB
+#define ARM_MMU_L2_COARSE_ENTRY_COUNT  256
+#define ARM_MMU_L2_COARSE_TABLE_SIZE   (ARM_MMU_L2_COARSE_ENTRY_COUNT \
+                                                                               
        * sizeof(uint32))
 
+#define ARM_MMU_L2_FINE_ENTRY_COUNT            1024
+#define ARM_MMU_L2_FINE_TABLE_SIZE             (ARM_MMU_L2_FINE_ENTRY_COUNT \
+                                                                               
        * sizeof(uint32))
 
 /*
  * definitions for CP15 r1
  */
 
-#define CR_R1_MMU 0x1          // enable MMU
-#define CP_R1_XP 0x800000      // if XP=0 then use backwards comaptible
-                               // translation tables
+#define CR_R1_MMU                                              0x1             
// enable MMU
+#define CP_R1_XP                                               0x800000
+       // if XP=0 then use backwards comaptible translation tables
+
+
+#define VADDR_TO_PDENT(va)                             ((va) >> 20)
+#define VADDR_TO_PTENT(va)                             (((va) & 0xff000) >> 12)
+#define VADDR_TO_PGOFF(va)                             ((va) & 0x0fff)
 
-#define VADDR_TO_PDENT(va)     ((va) >> 20)
-#define VADDR_TO_PTENT(va)     (((va) & 0xff000) >> 12)
-#define VADDR_TO_PGOFF(va)     ((va) & 0x0fff)
+#define ARM_PDE_ADDRESS_MASK                   0xfffffc00
+#define ARM_PDE_TYPE_MASK                              0x00000003
 
-#define ARM_PDE_ADDRESS_MASK   0xfffffc00
-#define ARM_PTE_ADDRESS_MASK   0xfffff000
+#define ARM_PTE_ADDRESS_MASK                   0xfffff000
+#define ARM_PTE_TYPE_MASK                              0x00000003
 
 #endif /* _ARCH_ARM_ARM_MMU_H */
diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index bd39d90..6a522a7 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -78,37 +78,37 @@ static struct memblock LOADER_MEMORYMAP[] = {
                "devices",
                DEVICE_BASE,
                DEVICE_BASE + DEVICE_SIZE - 1,
-               MMU_L2_FLAG_B,
+               ARM_MMU_L2_FLAG_B,
        },
        {
                "RAM_loader", // 1MB loader
                SDRAM_BASE + 0,
                SDRAM_BASE + 0x0fffff,
-               MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_C,
        },
        {
                "RAM_pt", // Page Table 1MB
                SDRAM_BASE + 0x100000,
                SDRAM_BASE + 0x1FFFFF,
-               MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_C,
        },
        {
                "RAM_free", // 16MB free RAM (more but we don't map it 
automaticaly)
                SDRAM_BASE + 0x0200000,
                SDRAM_BASE + 0x11FFFFF,
-               MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_C,
        },
        {
                "RAM_stack", // stack
                SDRAM_BASE + 0x1200000,
                SDRAM_BASE + 0x2000000,
-               MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_C,
        },
        {
                "RAM_initrd", // stack
                SDRAM_BASE + 0x2000000,
                SDRAM_BASE + 0x2500000,
-               MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_C,
        },
 
 #ifdef FB_BASE
@@ -116,7 +116,7 @@ static struct memblock LOADER_MEMORYMAP[] = {
                "framebuffer", // 2MB framebuffer ram
                FB_BASE,
                FB_BASE + FB_SIZE - 1,
-               MMU_L2_FLAG_AP_RW | MMU_L2_FLAG_C,
+               ARM_MMU_L2_FLAG_AP_RW | ARM_MMU_L2_FLAG_C,
        },
 #endif
 };
@@ -254,14 +254,14 @@ get_next_page_table(uint32 type)
 
        size_t size = 0;
        switch (type) {
-               case MMU_L1_TYPE_COARSE:
+               case ARM_MMU_L1_TYPE_COARSE:
                default:
-                       size = 1024;
+                       size = ARM_MMU_L2_COARSE_TABLE_SIZE;
                        break;
-               case MMU_L1_TYPE_FINE:
-                       size = 4096;
+               case ARM_MMU_L1_TYPE_FINE:
+                       size = ARM_MMU_L2_FINE_TABLE_SIZE;
                        break;
-               case MMU_L1_TYPE_SECTION:
+               case ARM_MMU_L1_TYPE_SECTION:
                        size = 16384;
                        break;
        }
@@ -285,20 +285,20 @@ init_page_directory()
 
        // see if subpages are disabled
        if (mmu_read_C1() & (1 << 23))
-               smallType = MMU_L2_TYPE_SMALLNEW;
+               smallType = ARM_MMU_L2_TYPE_SMALLNEW;
        else
-               smallType = MMU_L2_TYPE_SMALLEXT;
+               smallType = ARM_MMU_L2_TYPE_SMALLEXT;
 
        gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
 
        // clear out the page directory
-       for (uint32 i = 0; i < 4096; i++)
+       for (uint32 i = 0; i < ARM_MMU_L1_TABLE_ENTRY_COUNT; i++)
                sPageDirectory[i] = 0;
 
        uint32 *pageTable = NULL;
        for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
 
-               pageTable = get_next_page_table(MMU_L1_TYPE_COARSE);
+               pageTable = get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
                TRACE(("BLOCK: %s START: %lx END %lx\n", 
LOADER_MEMORYMAP[i].name,
                        LOADER_MEMORYMAP[i].start, LOADER_MEMORYMAP[i].end));
                addr_t pos = LOADER_MEMORYMAP[i].start;
@@ -311,8 +311,8 @@ init_page_directory()
                        if (c > 255) { // we filled a pagetable => we need a 
new one
                                // there is 1MB per pagetable so:
                                sPageDirectory[VADDR_TO_PDENT(pos)]
-                                       = (uint32)pageTable | 
MMU_L1_TYPE_COARSE;
-                               pageTable = 
get_next_page_table(MMU_L1_TYPE_COARSE);
+                                       = (uint32)pageTable | 
ARM_MMU_L1_TYPE_COARSE;
+                               pageTable = 
get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
                                c = 0;
                        }
 
@@ -321,7 +321,7 @@ init_page_directory()
 
                if (c > 0) {
                        sPageDirectory[VADDR_TO_PDENT(pos)]
-                               = (uint32)pageTable | MMU_L1_TYPE_COARSE;
+                               = (uint32)pageTable | ARM_MMU_L1_TYPE_COARSE;
                }
        }
 
@@ -355,7 +355,7 @@ add_page_table(addr_t base)
        TRACE(("add_page_table(base = %p)\n", (void *)base));
 
        // Get new page table and clear it out
-       uint32 *pageTable = get_next_page_table(MMU_L1_TYPE_COARSE);
+       uint32 *pageTable = get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
 /*
        if (pageTable > (uint32 *)(8 * 1024 * 1024)) {
                panic("tried to add page table beyond the indentity mapped 8 MB 
"
@@ -367,7 +367,7 @@ add_page_table(addr_t base)
 
        // put the new page table into the page directory
        sPageDirectory[VADDR_TO_PDENT(base)]
-               = (uint32)pageTable | MMU_L1_TYPE_COARSE;
+               = (uint32)pageTable | ARM_MMU_L1_TYPE_COARSE;
 }
 
 
@@ -615,7 +615,7 @@ mmu_init(void)
 
                if (strcmp("RAM_pt", LOADER_MEMORYMAP[i].name) == 0) {
                        sNextPageTableAddress = LOADER_MEMORYMAP[i].start
-                               + MMU_L1_TABLE_SIZE;
+                               + ARM_MMU_L1_TABLE_SIZE;
                        kPageTableRegionEnd = LOADER_MEMORYMAP[i].end;
                        sPageDirectory = (uint32 *)LOADER_MEMORYMAP[i].start;
                }
diff --git a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
index 91bfa29..b95d399 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
@@ -314,8 +314,9 @@ ARMPagingMethod32Bit::InitPostArea(kernel_args* args)
        area_id area;
 
        temp = (void*)fKernelVirtualPageDirectory;
-       area = create_area("kernel_pgdir", &temp, B_EXACT_ADDRESS, 
MMU_L1_TABLE_SIZE,
-               B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
+       area = create_area("kernel_pgdir", &temp, B_EXACT_ADDRESS,
+               ARM_MMU_L1_TABLE_SIZE, B_ALREADY_WIRED, B_KERNEL_READ_AREA
+                       | B_KERNEL_WRITE_AREA);
        if (area < B_OK)
                return area;
 

############################################################################

Commit:      89564c0a10d4c48382df732ae1b9826260ccdcbd
URL:         http://cgit.haiku-os.org/haiku/commit/?id=89564c0
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 21:48:58 2012 UTC

Simplify the page directory init loops.

Also check and possibly reuse an existing page directory entry. This
makes the possible memory maps a little more flexible.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 6a522a7..c8ed8a4 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -277,6 +277,33 @@ get_next_page_table(uint32 type)
 }
 
 
+static uint32 *
+get_or_create_page_table(addr_t address, uint32 type)
+{
+       uint32 *pageTable = NULL;
+       uint32 pageDirectoryIndex = VADDR_TO_PDENT(address);
+       uint32 pageDirectoryEntry = sPageDirectory[pageDirectoryIndex];
+
+       uint32 entryType = pageDirectoryEntry & ARM_PDE_TYPE_MASK;
+       if (entryType == ARM_MMU_L1_TYPE_FAULT) {
+               // This page directory entry has not been set yet, allocate it.
+               pageTable = get_next_page_table(type);
+               sPageDirectory[pageDirectoryIndex] = (uint32)pageTable | type;
+               return pageTable;
+       }
+
+       if (entryType != type) {
+               // This entry has been allocated with a different type!
+               panic("tried to reuse page directory entry %" B_PRIu32
+                       " with different type (entry: %#" B_PRIx32 ", new type: 
%#" B_PRIx32
+                       ")\n", pageDirectoryIndex, pageDirectoryEntry, type);
+               return NULL;
+       }
+
+       return (uint32 *)(pageDirectoryEntry & ARM_PDE_ADDRESS_MASK);
+}
+
+
 void
 init_page_directory()
 {
@@ -295,33 +322,28 @@ init_page_directory()
        for (uint32 i = 0; i < ARM_MMU_L1_TABLE_ENTRY_COUNT; i++)
                sPageDirectory[i] = 0;
 
-       uint32 *pageTable = NULL;
        for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
 
-               pageTable = get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
                TRACE(("BLOCK: %s START: %lx END %lx\n", 
LOADER_MEMORYMAP[i].name,
                        LOADER_MEMORYMAP[i].start, LOADER_MEMORYMAP[i].end));
-               addr_t pos = LOADER_MEMORYMAP[i].start;
-
-               int c = 0;
-               while (pos < LOADER_MEMORYMAP[i].end) {
-                       pageTable[c] = pos | LOADER_MEMORYMAP[i].flags | 
smallType;
-
-                       c++;
-                       if (c > 255) { // we filled a pagetable => we need a 
new one
-                               // there is 1MB per pagetable so:
-                               sPageDirectory[VADDR_TO_PDENT(pos)]
-                                       = (uint32)pageTable | 
ARM_MMU_L1_TYPE_COARSE;
-                               pageTable = 
get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
-                               c = 0;
-                       }
 
-                       pos += B_PAGE_SIZE;
-               }
+               addr_t address = LOADER_MEMORYMAP[i].start;
+               ASSERT((address & ~ARM_PTE_ADDRESS_MASK) == 0);
 
-               if (c > 0) {
-                       sPageDirectory[VADDR_TO_PDENT(pos)]
-                               = (uint32)pageTable | ARM_MMU_L1_TYPE_COARSE;
+               uint32 *pageTable = NULL;
+               uint32 pageTableIndex = 0;
+
+               while (address < LOADER_MEMORYMAP[i].end) {
+                       if (pageTable == NULL
+                               || pageTableIndex >= 
ARM_MMU_L2_COARSE_ENTRY_COUNT) {
+                               pageTable = get_or_create_page_table(address,
+                                       ARM_MMU_L1_TYPE_COARSE);
+                               pageTableIndex = VADDR_TO_PTENT(address);
+                       }
+
+                       pageTable[pageTableIndex++]
+                               = address | LOADER_MEMORYMAP[i].flags | 
smallType;
+                       address += B_PAGE_SIZE;
                }
        }
 

############################################################################

Commit:      a438da7c8b553f2c23dc400083582e9a69ba43b7
URL:         http://cgit.haiku-os.org/haiku/commit/?id=a438da7
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 21:51:39 2012 UTC

Clear the page tables on creation, use macros for counts.

This makes it less likely that uninitialized entries cause troubles.
Also panic if we encounter an unknown entry type instead of defaulting
to 4K pages.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index c8ed8a4..7f84672 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -253,27 +253,38 @@ get_next_page_table(uint32 type)
                sNextPageTableAddress, kPageTableRegionEnd, type));
 
        size_t size = 0;
+       size_t entryCount = 0;
        switch (type) {
                case ARM_MMU_L1_TYPE_COARSE:
-               default:
                        size = ARM_MMU_L2_COARSE_TABLE_SIZE;
+                       entryCount = ARM_MMU_L2_COARSE_ENTRY_COUNT;
                        break;
                case ARM_MMU_L1_TYPE_FINE:
                        size = ARM_MMU_L2_FINE_TABLE_SIZE;
+                       entryCount = ARM_MMU_L2_FINE_ENTRY_COUNT;
                        break;
                case ARM_MMU_L1_TYPE_SECTION:
+                       // TODO: Figure out parameters for section types.
                        size = 16384;
                        break;
+               default:
+                       panic("asked for unknown page table type: %#" B_PRIx32 
"\n", type);
+                       return NULL;
        }
 
        addr_t address = sNextPageTableAddress;
-       if (address >= kPageTableRegionEnd) {
-               TRACE(("outside of pagetableregion!\n"));
-               return (uint32 *)get_next_physical_address_alligned(size, 
0xffffffc0);
+       if (address < kPageTableRegionEnd)
+               sNextPageTableAddress += size;
+       else {
+               TRACE(("page table allocation outside of pagetable region!\n"));
+               address = get_next_physical_address_alligned(size, 0xffffffc0);
        }
 
-       sNextPageTableAddress += size;
-       return (uint32 *)address;
+       uint32 *pageTable = (uint32 *)address;
+       for (size_t i = 0; i < entryCount; i++)
+               pageTable[i] = 0;
+
+       return pageTable;
 }
 
 

############################################################################

Commit:      83f7c22537add4bc57e28ed2dc34236ee725caea
URL:         http://cgit.haiku-os.org/haiku/commit/?id=83f7c22
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 21:55:42 2012 UTC

Reuse get_or_create_page_table() and remove similar add_page().

The former also does the initialization, simplifying the code and
reducing redundancy with the page directory init path.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 7f84672..8f0a7d3 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -381,29 +381,6 @@ init_page_directory()
 }
 
 
-/*!     Adds a new page table for the specified base address */
-static void
-add_page_table(addr_t base)
-{
-       TRACE(("add_page_table(base = %p)\n", (void *)base));
-
-       // Get new page table and clear it out
-       uint32 *pageTable = get_next_page_table(ARM_MMU_L1_TYPE_COARSE);
-/*
-       if (pageTable > (uint32 *)(8 * 1024 * 1024)) {
-               panic("tried to add page table beyond the indentity mapped 8 MB 
"
-                       "region\n");
-       }
-*/
-       for (int32 i = 0; i < 256; i++)
-               pageTable[i] = 0;
-
-       // put the new page table into the page directory
-       sPageDirectory[VADDR_TO_PDENT(base)]
-               = (uint32)pageTable | ARM_MMU_L1_TYPE_COARSE;
-}
-
-
 /*!    Creates an entry to map the specified virtualAddress to the given
        physicalAddress.
        If the mapping goes beyond the current page table, it will allocate
@@ -434,26 +411,15 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
        physicalAddress &= ~(B_PAGE_SIZE - 1);
 
        // map the page to the correct page table
-       uint32 *pageTable
-               = (uint32 *)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
-                       & ARM_PDE_ADDRESS_MASK);
-
-       TRACE(("map_page: pageTable 0x%lx\n",
-               sPageDirectory[VADDR_TO_PDENT(virtualAddress)] & 
ARM_PDE_ADDRESS_MASK));
-
-       if (pageTable == NULL) {
-               add_page_table(virtualAddress);
-               pageTable = (uint32 
*)(sPageDirectory[VADDR_TO_PDENT(virtualAddress)]
-                       & ARM_PDE_ADDRESS_MASK);
-       }
-
-       uint32 tableEntry = VADDR_TO_PTENT(virtualAddress);
+       uint32 *pageTable = get_or_create_page_table(virtualAddress,
+               ARM_MMU_L1_TYPE_COARSE);
 
+       uint32 pageTableIndex = VADDR_TO_PTENT(virtualAddress);
        TRACE(("map_page: inserting pageTable %p, tableEntry 0x%" B_PRIx32
-               ", physicalAddress 0x%" B_PRIxADDR "\n", pageTable, tableEntry,
+               ", physicalAddress 0x%" B_PRIxADDR "\n", pageTable, 
pageTableIndex,
                physicalAddress));
 
-       pageTable[tableEntry] = physicalAddress | flags;
+       pageTable[pageTableIndex] = physicalAddress | flags;
 
        mmu_flush_TLB();
 

############################################################################

Commit:      7c45cf715522a783d3d144998301ffb1d4335cca
URL:         http://cgit.haiku-os.org/haiku/commit/?id=7c45cf7
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 21:57:04 2012 UTC

Remove tracking of sMaxVirtualAddress as it's not used.

The value computed isn't actually used anywhere. It just ensured that
a panic would be triggered if we "skipped" to virtual addresses further
along. This shouldn't be problematic however.

----------------------------------------------------------------------------

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 8f0a7d3..c72b2c7 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -128,7 +128,6 @@ static const size_t kMaxKernelSize = 0x200000;              
// 2 MB for the kernel
 
 static addr_t sNextPhysicalAddress = 0; //will be set by mmu_init
 static addr_t sNextVirtualAddress = KERNEL_BASE + kMaxKernelSize;
-static addr_t sMaxVirtualAddress = KERNEL_BASE + kMaxKernelSize;
 
 static addr_t sNextPageTableAddress = 0;
 //the page directory is in front of the pagetable
@@ -397,17 +396,6 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
                        (void *)virtualAddress);
        }
 
-       if (virtualAddress >= sMaxVirtualAddress) {
-               // we need to add a new page table
-               add_page_table(sMaxVirtualAddress);
-               sMaxVirtualAddress += B_PAGE_SIZE * 256;
-
-               if (virtualAddress >= sMaxVirtualAddress) {
-                       panic("map_page: asked to map a page to %p\n",
-                               (void *)virtualAddress);
-               }
-       }
-
        physicalAddress &= ~(B_PAGE_SIZE - 1);
 
        // map the page to the correct page table

############################################################################

Commit:      fd6e3a11e2e39e8a3e72914996a4b0d79d64c9df
URL:         http://cgit.haiku-os.org/haiku/commit/?id=fd6e3a1
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 23:01:26 2012 UTC

Use the existing ARM MMU definitions and remove duplicates.

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/arch/arm/arm_mmu.h 
b/headers/private/kernel/arch/arm/arm_mmu.h
index 1ff3a97..9388c4a 100644
--- a/headers/private/kernel/arch/arm/arm_mmu.h
+++ b/headers/private/kernel/arch/arm/arm_mmu.h
@@ -52,6 +52,7 @@
  * I will use the old format...
  */
 
+#define ARM_MMU_L2_TYPE_LARGE                  0x1
 #define ARM_MMU_L2_TYPE_SMALLEXT               0x3
 
 /* for new format entries (cortex-a8) */
diff --git a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
index b95d399..eb3c42c 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
@@ -22,7 +22,6 @@
 #include <thread.h>
 #include <vm/vm.h>
 #include <vm/VMAddressSpace.h>
-#include <arm_mmu.h>
 
 #include "paging/32bit/ARMPagingStructures32Bit.h"
 #include "paging/32bit/ARMVMTranslationMap32Bit.h"
@@ -172,7 +171,7 @@ ARMPagingMethod32Bit::PhysicalPageSlotPool::Map(phys_addr_t 
physicalAddress,
        page_table_entry& pte = fPageTable[
                (virtualAddress - fVirtualBase) / B_PAGE_SIZE];
        pte = (physicalAddress & ARM_PTE_ADDRESS_MASK)
-               | ARM_PTE_TYPE_SMALL_PAGE;
+               | ARM_MMU_L2_TYPE_SMALLEXT;
 
        arch_cpu_invalidate_TLB_range(virtualAddress, virtualAddress + 
B_PAGE_SIZE);
 //     invalidate_TLB(virtualAddress);
@@ -462,8 +461,7 @@ ARMPagingMethod32Bit::IsKernelPageAccessible(addr_t 
virtualAddress,
 ARMPagingMethod32Bit::PutPageTableInPageDir(page_directory_entry* entry,
        phys_addr_t pgtablePhysical, uint32 attributes)
 {
-       *entry = (pgtablePhysical & ARM_PDE_ADDRESS_MASK)
-               | ARM_PDE_TYPE_COARSE_L2_PAGE_TABLE;
+       *entry = (pgtablePhysical & ARM_PDE_ADDRESS_MASK) | 
ARM_MMU_L1_TYPE_COARSE;
                // TODO: we ignore the attributes of the page table - for 
compatibility
                // with BeOS we allow having user accessible areas in the 
kernel address
                // space. This is currently being used by some drivers, mainly 
for the
@@ -480,7 +478,7 @@ 
ARMPagingMethod32Bit::PutPageTableEntryInTable(page_table_entry* entry,
        bool globalPage)
 {
        page_table_entry page = (physicalAddress & ARM_PTE_ADDRESS_MASK)
-               | ARM_PTE_TYPE_SMALL_PAGE;
+               | ARM_MMU_L2_TYPE_SMALLEXT;
 #if 0 //IRA
                | ARM_PTE_PRESENT | (globalPage ? ARM_PTE_GLOBAL : 0)
                | MemoryTypeToPageTableEntryFlags(memoryType);
diff --git a/src/system/kernel/arch/arm/paging/32bit/paging.h 
b/src/system/kernel/arch/arm/paging/32bit/paging.h
index 8bc0468..66bd2f3 100644
--- a/src/system/kernel/arch/arm/paging/32bit/paging.h
+++ b/src/system/kernel/arch/arm/paging/32bit/paging.h
@@ -16,25 +16,8 @@
 #include <int.h>
 #include <kernel.h>
 
-#define VADDR_TO_PDENT(va)                                     ((va) >> 20)
-#define VADDR_TO_PTENT(va)                                     (((va) & 
0xff000) >> 12)
-#define VADDR_TO_PGOFF(va)                                     ((va) & 0x0fff)
+#include <arm_mmu.h>
 
-// page directory entry bits
-#define ARM_PDE_TYPE_MASK                                      0x00000003
-#define ARM_PDE_TYPE_COARSE_L2_PAGE_TABLE      0x00000001
-#define ARM_PDE_TYPE_SECTION                           0x00000002
-#define ARM_PDE_TYPE_FINE_L2_PAGE_TABLE                0x00000003
-
-#define ARM_PDE_ADDRESS_MASK                           0xfffffc00
-
-// page table entry bits
-#define ARM_PTE_TYPE_MASK                                      0x00000003
-#define ARM_PTE_TYPE_LARGE_PAGE                                0x00000001
-#define ARM_PTE_TYPE_SMALL_PAGE                                0x00000002
-#define ARM_PTE_TYPE_EXT_SMALL_PAGE                    0x00000003
-
-#define ARM_PTE_ADDRESS_MASK                           0xfffff000
 
 #define FIRST_USER_PGDIR_ENT                           
(VADDR_TO_PDENT(USER_BASE))
 #define NUM_USER_PGDIR_ENTS                                    
(VADDR_TO_PDENT(ROUNDUP(USER_SIZE, \

############################################################################

Commit:      926d1024d0c75ee88107646f1c0ed819ff9fd6a9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=926d102
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 23:27:44 2012 UTC

Fix wrong address mask (page directory vs. page table).

----------------------------------------------------------------------------

diff --git 
a/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
index a1268c1..f48ec5c 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
@@ -574,8 +574,7 @@ ARMVMTranslationMap32Bit::Query(addr_t va, phys_addr_t 
*_physical,
                pd[index] & ARM_PDE_ADDRESS_MASK);
        page_table_entry entry = pt[VADDR_TO_PTENT(va)];
 
-       *_physical = (entry & ARM_PDE_ADDRESS_MASK)
-               | VADDR_TO_PGOFF(va);
+       *_physical = (entry & ARM_PTE_ADDRESS_MASK) | VADDR_TO_PGOFF(va);
 
 #if 0 //IRA
        // read in the page state flags
@@ -622,8 +621,8 @@ ARMVMTranslationMap32Bit::QueryInterrupt(addr_t va, 
phys_addr_t *_physical,
                        pd[index] & ARM_PDE_ADDRESS_MASK);
        page_table_entry entry = pt[VADDR_TO_PTENT(va)];
 
-       *_physical = (entry & ARM_PDE_ADDRESS_MASK)
-               | VADDR_TO_PGOFF(va);
+       *_physical = (entry & ARM_PTE_ADDRESS_MASK) | VADDR_TO_PGOFF(va);
+
 #if 0
        // read in the page state flags
        if ((entry & ARM_PTE_USER) != 0) {

############################################################################

Commit:      f0422c6f9f78f51b4400d63b6d0e5d1453b38583
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f0422c6
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 23:29:41 2012 UTC

Only set the physical address if the entry is mapped.

Otherwise, even when the address was 0, we would possibly set the
physical address to != 0 as we always applied the page offset.

----------------------------------------------------------------------------

diff --git 
a/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
index f48ec5c..d33bb20 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMVMTranslationMap32Bit.cpp
@@ -574,7 +574,8 @@ ARMVMTranslationMap32Bit::Query(addr_t va, phys_addr_t 
*_physical,
                pd[index] & ARM_PDE_ADDRESS_MASK);
        page_table_entry entry = pt[VADDR_TO_PTENT(va)];
 
-       *_physical = (entry & ARM_PTE_ADDRESS_MASK) | VADDR_TO_PGOFF(va);
+       if ((entry & ARM_PTE_TYPE_MASK) != 0)
+               *_physical = (entry & ARM_PTE_ADDRESS_MASK) | 
VADDR_TO_PGOFF(va);
 
 #if 0 //IRA
        // read in the page state flags
@@ -621,7 +622,8 @@ ARMVMTranslationMap32Bit::QueryInterrupt(addr_t va, 
phys_addr_t *_physical,
                        pd[index] & ARM_PDE_ADDRESS_MASK);
        page_table_entry entry = pt[VADDR_TO_PTENT(va)];
 
-       *_physical = (entry & ARM_PTE_ADDRESS_MASK) | VADDR_TO_PGOFF(va);
+       if ((entry & ARM_PTE_TYPE_MASK) != 0)
+               *_physical = (entry & ARM_PTE_ADDRESS_MASK) | 
VADDR_TO_PGOFF(va);
 
 #if 0
        // read in the page state flags
@@ -636,7 +638,9 @@ ARMVMTranslationMap32Bit::QueryInterrupt(addr_t va, 
phys_addr_t *_physical,
                | ((entry & ARM_PTE_ACCESSED) != 0 ? PAGE_ACCESSED : 0)
                | ((entry & ARM_PTE_PRESENT) != 0 ? PAGE_PRESENT : 0);
 #else
-       *_flags = B_KERNEL_WRITE_AREA | B_KERNEL_READ_AREA | PAGE_PRESENT;
+       *_flags = B_KERNEL_WRITE_AREA | B_KERNEL_READ_AREA;
+       if (*_physical != 0)
+               *_flags |= PAGE_PRESENT;
 #endif
        return B_OK;
 }

############################################################################

Commit:      2b5d52a1745eb9fb34887251b09f24aaf78d535b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=2b5d52a
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 23:46:17 2012 UTC

Whitespace cleanup only.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/arm/arch_exceptions.S 
b/src/system/kernel/arch/arm/arch_exceptions.S
index 41a88d9..83124ac 100644
--- a/src/system/kernel/arch/arm/arch_exceptions.S
+++ b/src/system/kernel/arch/arm/arch_exceptions.S
@@ -19,75 +19,84 @@
 
 /* The following two macros are taken from FreeBSD... */
 
-       .macro PUSHFRAMEINSVC
-       stmdb   sp, {r0-r3}             /* Save 4 registers */
-       mov     r0, lr                  /* Save xxx32 r14 */
-       mov     r1, sp                  /* Save xxx32 sp */
-       mrs     r3, spsr                /* Save xxx32 spsr */
-       mrs     r2, cpsr                /* Get the CPSR */
-       bic     r2, r2, #(CPSR_MODE_MASK)/* Fix for SVC mode */
-       orr     r2, r2, #(CPSR_MODE_SVC)
-       msr     cpsr_c, r2              /* Punch into SVC mode */
-       mov     r2, sp                  /* Save SVC sp */
-       str     r0, [sp, #-4]!          /* Push return address */
-       str     lr, [sp, #-4]!          /* Push SVC lr */
-       str     r2, [sp, #-4]!          /* Push SVC sp */
-       msr     spsr_all, r3            /* Restore correct spsr */
-       ldmdb   r1, {r0-r3}             /* Restore 4 regs from xxx mode */
-       sub     sp, sp, #(4*15)         /* Adjust the stack pointer */
-       stmia   sp, {r0-r12}            /* Push the user mode registers */
-       add     r0, sp, #(4*13)         /* Adjust the stack pointer */
-       stmia   r0, {r13-r14}^          /* Push the user mode registers */
-       mov     r0, r0                  /* NOP for previous instruction */
-       mrs     r0, spsr_all
-       str     r0, [sp, #-4]!          /* Save spsr */
-       .endm
-
-       .macro PULLFRAMEFROMSVCANDEXIT
-       ldr     r0, [sp], #0x0004       /* Get the SPSR from stack */
-       msr     spsr_all, r0            /* restore SPSR */
-       ldmia   sp, {r0-r14}^           /* Restore registers (usr mode) */
-       mov     r0, r0                  /* NOP for previous instruction */
-       add     sp, sp, #(4*15)         /* Adjust the stack pointer */
-       ldmia   sp, {sp, lr, pc}^       /* Restore lr and exit */
-       .endm
-
-       .text
+.macro PUSHFRAMEINSVC
+       stmdb   sp, {r0-r3}                                     /* Save 4 
registers */
+       mov             r0, lr                                          /* Save 
xxx32 r14 */
+       mov             r1, sp                                          /* Save 
xxx32 sp */
+       mrs             r3, spsr                                        /* Save 
xxx32 spsr */
+       mrs             r2, cpsr                                        /* Get 
the CPSR */
+       bic             r2, r2, #(CPSR_MODE_MASK)       /* Fix for SVC mode */
+       orr             r2, r2, #(CPSR_MODE_SVC)
+       msr             cpsr_c, r2                                      /* 
Punch into SVC mode */
+       mov             r2, sp                                          /* Save 
SVC sp */
+       str             r0, [sp, #-4]!                          /* Push return 
address */
+       str             lr, [sp, #-4]!                          /* Push SVC lr 
*/
+       str             r2, [sp, #-4]!                          /* Push SVC sp 
*/
+       msr             spsr_all, r3                            /* Restore 
correct spsr */
+       ldmdb   r1, {r0-r3}                                     /* Restore 4 
regs from xxx mode */
+       sub             sp, sp, #(4*15)                         /* Adjust the 
stack pointer */
+       stmia   sp, {r0-r12}                            /* Push the user mode 
registers */
+       add             r0, sp, #(4*13)                         /* Adjust the 
stack pointer */
+       stmia   r0, {r13-r14}^                          /* Push the user mode 
registers */
+       mov             r0, r0                                          /* NOP 
for previous instruction */
+       mrs             r0, spsr_all
+       str             r0, [sp, #-4]!                          /* Save spsr */
+.endm
+
+.macro PULLFRAMEFROMSVCANDEXIT
+       ldr             r0, [sp], #0x0004                       /* Get the SPSR 
from stack */
+       msr             spsr_all, r0                            /* restore SPSR 
*/
+       ldmia   sp, {r0-r14}^                           /* Restore registers 
(usr mode) */
+       mov             r0, r0                                          /* NOP 
for previous instruction */
+       add             sp, sp, #(4*15)                         /* Adjust the 
stack pointer */
+       ldmia   sp, {sp, lr, pc}^                       /* Restore lr and exit 
*/
+.endm
+
+.text
 
 .globl _vectors_start
 _vectors_start:
-        ldr            pc, _arm_reset  
-        ldr             pc, _arm_undefined
-        ldr             pc, _arm_syscall
-        ldr             pc, _arm_prefetch_abort
-        ldr             pc, _arm_data_abort
-        ldr             pc, _arm_reserved
-        ldr             pc, _arm_irq
-        ldr             pc, _arm_fiq
+       ldr             pc, _arm_reset
+       ldr             pc, _arm_undefined
+       ldr             pc, _arm_syscall
+       ldr             pc, _arm_prefetch_abort
+       ldr             pc, _arm_data_abort
+       ldr             pc, _arm_reserved
+       ldr             pc, _arm_irq
+       ldr             pc, _arm_fiq
+
 
 _arm_reset:
-       .word           arm_reserved // actually reset, but not used when mapped
-_arm_undefined: 
-       .word           arm_undefined
+       .word   arm_reserved // actually reset, but not used when mapped
+
+_arm_undefined:
+       .word   arm_undefined
+
 _arm_syscall:
-       .word           arm_syscall
+       .word   arm_syscall
+
 _arm_prefetch_abort:
-       .word           arm_prefetch_abort
+       .word   arm_prefetch_abort
+
 _arm_data_abort:
-       .word           arm_data_abort
+       .word   arm_data_abort
+
 _arm_reserved:
-       .word           arm_reserved
-_arm_irq:       
-       .word           arm_irq
-_arm_fiq:       
-       .word           arm_fiq 
-.globl _vectors_end
-_vectors_end:
+       .word   arm_reserved
+
+_arm_irq:
+       .word   arm_irq
 
+_arm_fiq:
+       .word   arm_fiq
 
+
+.globl _vectors_end
+_vectors_end:
        .rept   64
        .word   0xdeadbeef
        .endr
+
 abort_stack:
        .word   . - 4
        .word   0xdeadbeef
@@ -95,6 +104,7 @@ abort_stack:
        .rept   64
        .word   0xcafebabe
        .endr
+
 irq_stack:
        .word   . - 4
        .word   0xcafebabe
@@ -102,6 +112,7 @@ irq_stack:
        .rept   64
        .word   0xaaaabbbb
        .endr
+
 fiq_stack:
        .word   . - 4
        .word   0xaaaabbbb
@@ -109,6 +120,7 @@ fiq_stack:
        .rept   64
        .word   0xccccdddd
        .endr
+
 und_stack:
        .word   . - 4
        .word   0xccccdddd
@@ -136,8 +148,8 @@ FUNCTION_END(arm_syscall)
 
 FUNCTION(arm_prefetch_abort):
 #ifdef __XSCALE__
-       nop                             /* Make absolutely sure any pending */
-       nop                             /* imprecise aborts have occurred. */
+       nop                                     /* Make absolutely sure any 
pending */
+       nop                                     /* imprecise aborts have 
occurred. */
 #endif
        add     lr, lr, #4
        PUSHFRAMEINSVC
@@ -151,8 +163,8 @@ FUNCTION_END(arm_prefetch_abort)
 
 FUNCTION(arm_data_abort):
 #ifdef __XSCALE__
-       nop                             /* Make absolutely sure any pending */
-       nop                             /* imprecise aborts have occurred. */
+       nop                                     /* Make absolutely sure any 
pending */
+       nop                                     /* imprecise aborts have 
occurred. */
 #endif
        sub     lr, lr, #8              /* Adjust the lr */
        PUSHFRAMEINSVC
@@ -167,11 +179,12 @@ FUNCTION(arm_reserved):
        b       .
 FUNCTION_END(arm_reserved)
 
+
 FUNCTION(arm_irq):
        sub     lr, lr, #4
        PUSHFRAMEINSVC
 
-       mov     r0, sp /* iframe */
+       mov     r0, sp                  /* iframe */
        bl      arch_arm_irq
 
        PULLFRAMEFROMSVCANDEXIT
@@ -182,7 +195,7 @@ FUNCTION(arm_fiq):
        sub     lr, lr, #4
        PUSHFRAMEINSVC
 
-       mov     r0, sp /* iframe */
+       mov     r0, sp                  /* iframe */
        bl      arch_arm_fiq
        
        PULLFRAMEFROMSVCANDEXIT

############################################################################

Commit:      1ed5f66cd4e5abaa0d048d8b34bfbf293e90609a
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1ed5f66
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Mon Dec  3 23:46:38 2012 UTC

Add missing function end macro.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/arm/arch_exceptions.S 
b/src/system/kernel/arch/arm/arch_exceptions.S
index 83124ac..a67ff88 100644
--- a/src/system/kernel/arch/arm/arch_exceptions.S
+++ b/src/system/kernel/arch/arm/arch_exceptions.S
@@ -173,6 +173,7 @@ FUNCTION(arm_data_abort):
        bl      arch_arm_data_abort
 
        PULLFRAMEFROMSVCANDEXIT
+FUNCTION_END(arm_data_abort)
 
 
 FUNCTION(arm_reserved):

############################################################################

Commit:      85db22817795bddf17313dd977740bcaadc2f851
URL:         http://cgit.haiku-os.org/haiku/commit/?id=85db228
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Tue Dec  4 22:15:02 2012 UTC

Style cleanup only.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/arm/arch_int.cpp 
b/src/system/kernel/arch/arm/arch_int.cpp
index 5c37f36..b6f18d4 100644
--- a/src/system/kernel/arch/arm/arch_int.cpp
+++ b/src/system/kernel/arch/arm/arch_int.cpp
@@ -150,16 +150,16 @@ arch_int_init_post_vm(kernel_args *args)
        arm_vector_init();
 
        // see if high vectors are enabled
-       if (mmu_read_c1() & (1<<13))
+       if ((mmu_read_c1() & (1 << 13)) != 0)
                dprintf("High vectors already enabled\n");
        else {
-               mmu_write_c1(mmu_read_c1() | (1<<13));
+               mmu_write_c1(mmu_read_c1() | (1 << 13));
 
-               if (!(mmu_read_c1() & (1<<13)))
+               if ((mmu_read_c1() & (1 << 13)) == 0)
                        dprintf("Unable to enable high vectors!\n");
                else
                        dprintf("Enabled high vectors\n");
-       }
+       }
 
        sPxaInterruptArea = map_physical_memory("pxa_intc", 
PXA_INTERRUPT_PHYS_BASE,
                PXA_INTERRUPT_SIZE, 0, B_KERNEL_READ_AREA | 
B_KERNEL_WRITE_AREA, (void**)&sPxaInterruptBase);
@@ -188,18 +188,23 @@ arch_int_init_post_device_manager(struct kernel_args 
*args)
 }
 
 
-extern "C" void arch_arm_undefined(struct iframe *iframe)
+extern "C" void
+arch_arm_undefined(struct iframe *iframe)
 {
        print_iframe("Undefined Instruction", iframe);
        panic("not handled!");
 }
 
-extern "C" void arch_arm_syscall(struct iframe *iframe)
+
+extern "C" void
+arch_arm_syscall(struct iframe *iframe)
 {
        print_iframe("Software interrupt", iframe);
 }
 
-extern "C" void arch_arm_data_abort(struct iframe *frame)
+
+extern "C" void
+arch_arm_data_abort(struct iframe *frame)
 {
        Thread *thread = thread_get_current_thread();
        bool isUser = (frame->spsr & 0x1f) == 0x10;
@@ -281,22 +286,32 @@ extern "C" void arch_arm_data_abort(struct iframe *frame)
        }
 }
 
-extern "C" void arch_arm_prefetch_abort(struct iframe *iframe)
+
+extern "C" void
+arch_arm_prefetch_abort(struct iframe *iframe)
 {
        print_iframe("Prefetch Abort", iframe);
        panic("not handled!");
 }
 
-extern "C" void arch_arm_irq(struct iframe *iframe)
+
+extern "C" void
+arch_arm_irq(struct iframe *iframe)
 {
-       for (int i=0; i < 32; i++)
+       for (int i=0; i < 32; i++) {
                if (sPxaInterruptBase[PXA_ICIP] & (1 << i))
                        int_io_interrupt_handler(i, true);
+       }
 }
 
-extern "C" void arch_arm_fiq(struct iframe *iframe)
+
+extern "C" void
+arch_arm_fiq(struct iframe *iframe)
 {
-       for (int i=0; i < 32; i++)
-               if (sPxaInterruptBase[PXA_ICIP] & (1 << i))
-                       dprintf("arch_arm_fiq: help me, FIQ %d was triggered 
but no FIQ support!\n", i);
+       for (int i=0; i < 32; i++) {
+               if (sPxaInterruptBase[PXA_ICIP] & (1 << i)) {
+                       dprintf("arch_arm_fiq: help me, FIQ %d was triggered 
but no "
+                               "FIQ support!\n", i);
+               }
+       }
 }

############################################################################

Revision:    hrev44957
Commit:      760de9b200a5023e2f79e2ee04ba570869de7ae7
URL:         http://cgit.haiku-os.org/haiku/commit/?id=760de9b
Author:      Michael Lotz <mmlr@xxxxxxxx>
Date:        Tue Dec  4 01:04:38 2012 UTC

Tiny code style cleanup.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
index eb3c42c..fe033e0 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
@@ -117,7 +117,7 @@ 
ARMPagingMethod32Bit::PhysicalPageSlotPool::InitInitialPostArea(
        area_id area = create_area("physical page pool", &temp,
                B_EXACT_ADDRESS, areaSize, B_ALREADY_WIRED,
                B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
-       if (area < B_OK) {
+       if (area < 0) {
                panic("LargeMemoryPhysicalPageMapper::InitPostArea(): Failed to 
"
                        "create area for physical page pool.");
                return area;
@@ -372,7 +372,7 @@ ARMPagingMethod32Bit::MapEarly(kernel_args* args, addr_t 
virtualAddress,
                memset((void*)pgtable, 0, B_PAGE_SIZE);
        }
 
-       page_table_entry *ptEntry = (page_table_entry*)
+       page_table_entry* ptEntry = (page_table_entry*)
                (fKernelVirtualPageDirectory[index] & ARM_PDE_ADDRESS_MASK);
        ptEntry += VADDR_TO_PTENT(virtualAddress);
 


Other related posts: