[b6b02c0] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Martin Decky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup abs32lemm
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <arch/mm/page.h>
|
---|
[1f12fab] | 36 | #include <arch/mm/page_fault.h>
|
---|
| 37 | #include <arch/mm/tlb.h>
|
---|
[b6b02c0] | 38 | #include <genarch/mm/page_pt.h>
|
---|
| 39 | #include <arch/mm/frame.h>
|
---|
| 40 | #include <mm/frame.h>
|
---|
| 41 | #include <mm/page.h>
|
---|
| 42 | #include <mm/as.h>
|
---|
| 43 | #include <typedefs.h>
|
---|
| 44 | #include <align.h>
|
---|
| 45 | #include <config.h>
|
---|
| 46 | #include <func.h>
|
---|
| 47 | #include <arch/interrupt.h>
|
---|
| 48 | #include <arch/asm.h>
|
---|
| 49 | #include <debug.h>
|
---|
| 50 | #include <memstr.h>
|
---|
| 51 | #include <print.h>
|
---|
| 52 | #include <interrupt.h>
|
---|
[ef9a2a8] | 53 | #include <macros.h>
|
---|
[b6b02c0] | 54 |
|
---|
| 55 | void page_arch_init(void)
|
---|
| 56 | {
|
---|
[ef9a2a8] | 57 | int flags = PAGE_CACHEABLE | PAGE_EXEC;
|
---|
| 58 | page_mapping_operations = &pt_mapping_operations;
|
---|
| 59 |
|
---|
| 60 | page_table_lock(AS_KERNEL, true);
|
---|
| 61 |
|
---|
| 62 | /* Kernel identity mapping */
|
---|
| 63 | //FIXME: We need to consider the possibility that
|
---|
| 64 | //identity_base > identity_size and physmem_end.
|
---|
| 65 | //This might lead to overflow if identity_size is too big.
|
---|
| 66 | for (uintptr_t cur = PHYSMEM_START_ADDR;
|
---|
| 67 | cur < min(KA2PA(config.identity_base) +
|
---|
| 68 | config.identity_size, config.physmem_end);
|
---|
| 69 | cur += FRAME_SIZE)
|
---|
| 70 | page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | page_table_unlock(AS_KERNEL, true);
|
---|
| 74 | as_switch(NULL, AS_KERNEL);
|
---|
| 75 |
|
---|
[382fb4ba] | 76 | // printf("as_context_table=0x%08x\n", as_context_table);
|
---|
[ef9a2a8] | 77 |
|
---|
| 78 | /* Switch MMU to new context table */
|
---|
[1f12fab] | 79 | asi_u32_write(ASI_MMUREGS, MMU_CONTEXT_TABLE, KA2PA(as_context_table) >> 4);
|
---|
[ef9a2a8] | 80 |
|
---|
| 81 | //boot_page_table_free();
|
---|
[b6b02c0] | 82 | }
|
---|
| 83 |
|
---|
| 84 | void page_fault(unsigned int n __attribute__((unused)), istate_t *istate)
|
---|
| 85 | {
|
---|
[1f12fab] | 86 | uint32_t fault_status = asi_u32_read(ASI_MMUREGS, MMU_FAULT_STATUS);
|
---|
| 87 | uintptr_t fault_address = asi_u32_read(ASI_MMUREGS, MMU_FAULT_ADDRESS);
|
---|
| 88 | mmu_fault_status_t *fault = (mmu_fault_status_t *)&fault_status;
|
---|
[13c94f7] | 89 | mmu_fault_type_t type = (mmu_fault_type_t)fault->at;
|
---|
[1f12fab] | 90 |
|
---|
[382fb4ba] | 91 | // printf("page fault on address 0x%08x, status 0x%08x, type %d\n", fault_address, fault_status, type);
|
---|
[1f12fab] | 92 |
|
---|
[817d939] | 93 | if (type == FAULT_TYPE_LOAD_USER_DATA ||
|
---|
| 94 | type == FAULT_TYPE_LOAD_SUPERVISOR_DATA)
|
---|
[1f12fab] | 95 | as_page_fault(fault_address, PF_ACCESS_READ, istate);
|
---|
| 96 |
|
---|
[817d939] | 97 | if (type == FAULT_TYPE_EXECUTE_USER ||
|
---|
| 98 | type == FAULT_TYPE_EXECUTE_SUPERVISOR)
|
---|
[1f12fab] | 99 | as_page_fault(fault_address, PF_ACCESS_EXEC, istate);
|
---|
| 100 |
|
---|
[817d939] | 101 | if (type == FAULT_TYPE_STORE_USER_DATA ||
|
---|
| 102 | type == FAULT_TYPE_STORE_USER_INSTRUCTION ||
|
---|
[382fb4ba] | 103 | type == FAULT_TYPE_STORE_SUPERVISOR_INSTRUCTION ||
|
---|
| 104 | type == FAULT_TYPE_STORE_SUPERVISOR_DATA)
|
---|
[1f12fab] | 105 | as_page_fault(fault_address, PF_ACCESS_WRITE, istate);
|
---|
[b6b02c0] | 106 | }
|
---|
| 107 |
|
---|
| 108 | /** @}
|
---|
| 109 | */
|
---|