[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 |
|
---|
[32e8cd1] | 29 | /** @addtogroup sparc32mm
|
---|
[b6b02c0] | 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>
|
---|
[36df4109] | 48 | #include <arch/arch.h>
|
---|
[b6b02c0] | 49 | #include <arch/asm.h>
|
---|
| 50 | #include <debug.h>
|
---|
| 51 | #include <memstr.h>
|
---|
| 52 | #include <print.h>
|
---|
| 53 | #include <interrupt.h>
|
---|
[ef9a2a8] | 54 | #include <macros.h>
|
---|
[b6b02c0] | 55 |
|
---|
| 56 | void page_arch_init(void)
|
---|
| 57 | {
|
---|
[ef9a2a8] | 58 | int flags = PAGE_CACHEABLE | PAGE_EXEC;
|
---|
| 59 | page_mapping_operations = &pt_mapping_operations;
|
---|
[32e8cd1] | 60 |
|
---|
[ef9a2a8] | 61 | page_table_lock(AS_KERNEL, true);
|
---|
| 62 |
|
---|
| 63 | /* Kernel identity mapping */
|
---|
[32e8cd1] | 64 | // FIXME:
|
---|
| 65 | // We need to consider the possibility that
|
---|
| 66 | // identity_base > identity_size and physmem_end.
|
---|
| 67 | // This might lead to overflow if identity_size is too big.
|
---|
[ef9a2a8] | 68 | for (uintptr_t cur = PHYSMEM_START_ADDR;
|
---|
| 69 | cur < min(KA2PA(config.identity_base) +
|
---|
[32e8cd1] | 70 | config.identity_size, config.physmem_end);
|
---|
[ef9a2a8] | 71 | cur += FRAME_SIZE)
|
---|
| 72 | page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
|
---|
| 73 |
|
---|
| 74 | page_table_unlock(AS_KERNEL, true);
|
---|
| 75 | as_switch(NULL, AS_KERNEL);
|
---|
[32e8cd1] | 76 |
|
---|
[ef9a2a8] | 77 | /* Switch MMU to new context table */
|
---|
[1f12fab] | 78 | asi_u32_write(ASI_MMUREGS, MMU_CONTEXT_TABLE, KA2PA(as_context_table) >> 4);
|
---|
[b6b02c0] | 79 | }
|
---|
| 80 |
|
---|
| 81 | void page_fault(unsigned int n __attribute__((unused)), istate_t *istate)
|
---|
| 82 | {
|
---|
[1f12fab] | 83 | uint32_t fault_status = asi_u32_read(ASI_MMUREGS, MMU_FAULT_STATUS);
|
---|
| 84 | uintptr_t fault_address = asi_u32_read(ASI_MMUREGS, MMU_FAULT_ADDRESS);
|
---|
[32e8cd1] | 85 | mmu_fault_status_t *fault = (mmu_fault_status_t *) &fault_status;
|
---|
| 86 | mmu_fault_type_t type = (mmu_fault_type_t) fault->at;
|
---|
| 87 |
|
---|
| 88 | if ((type == FAULT_TYPE_LOAD_USER_DATA) ||
|
---|
| 89 | (type == FAULT_TYPE_LOAD_SUPERVISOR_DATA))
|
---|
[1f12fab] | 90 | as_page_fault(fault_address, PF_ACCESS_READ, istate);
|
---|
| 91 |
|
---|
[32e8cd1] | 92 | if ((type == FAULT_TYPE_EXECUTE_USER) ||
|
---|
| 93 | (type == FAULT_TYPE_EXECUTE_SUPERVISOR))
|
---|
[1f12fab] | 94 | as_page_fault(fault_address, PF_ACCESS_EXEC, istate);
|
---|
| 95 |
|
---|
[32e8cd1] | 96 | if ((type == FAULT_TYPE_STORE_USER_DATA) ||
|
---|
| 97 | (type == FAULT_TYPE_STORE_USER_INSTRUCTION) ||
|
---|
| 98 | (type == FAULT_TYPE_STORE_SUPERVISOR_INSTRUCTION) ||
|
---|
| 99 | (type == FAULT_TYPE_STORE_SUPERVISOR_DATA))
|
---|
[1f12fab] | 100 | as_page_fault(fault_address, PF_ACCESS_WRITE, istate);
|
---|
[b6b02c0] | 101 | }
|
---|
| 102 |
|
---|
| 103 | /** @}
|
---|
| 104 | */
|
---|