source: mainline/kernel/arch/sparc32/src/mm/page.c@ df7f5cea

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since df7f5cea was 32e8cd1, checked in by Martin Decky <martin@…>, 12 years ago

code revision
coding style fixes
removal of debugging printouts and other temporary stuff

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