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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 36df4109 was 36df4109, checked in by Jakub Jermar <jakub@…>, 9 years ago

Introduce architecure-specific operations

This replaces the arch_*_init() functions with an arch_ops_t structure
defined for each architecture. Undefined operations are treated as NOPs.

  • Property mode set to 100644
File size: 3.6 KB
Line 
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 sparc32mm
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/mm/page.h>
36#include <arch/mm/page_fault.h>
37#include <arch/mm/tlb.h>
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/arch.h>
49#include <arch/asm.h>
50#include <debug.h>
51#include <memstr.h>
52#include <print.h>
53#include <interrupt.h>
54#include <macros.h>
55
56void page_arch_init(void)
57{
58 int flags = PAGE_CACHEABLE | PAGE_EXEC;
59 page_mapping_operations = &pt_mapping_operations;
60
61 page_table_lock(AS_KERNEL, true);
62
63 /* Kernel identity mapping */
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.
68 for (uintptr_t cur = PHYSMEM_START_ADDR;
69 cur < min(KA2PA(config.identity_base) +
70 config.identity_size, config.physmem_end);
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);
76
77 /* Switch MMU to new context table */
78 asi_u32_write(ASI_MMUREGS, MMU_CONTEXT_TABLE, KA2PA(as_context_table) >> 4);
79}
80
81void page_fault(unsigned int n __attribute__((unused)), istate_t *istate)
82{
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);
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))
90 as_page_fault(fault_address, PF_ACCESS_READ, istate);
91
92 if ((type == FAULT_TYPE_EXECUTE_USER) ||
93 (type == FAULT_TYPE_EXECUTE_SUPERVISOR))
94 as_page_fault(fault_address, PF_ACCESS_EXEC, istate);
95
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))
100 as_page_fault(fault_address, PF_ACCESS_WRITE, istate);
101}
102
103/** @}
104 */
Note: See TracBrowser for help on using the repository browser.