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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 382fb4ba was 382fb4ba, checked in by Jakub Klama <jakub.klama@…>, 12 years ago

Fixes as follows:

  • memcpy_from/to_uspace - fixed return value when size is 0
  • saving UWB pointer after thead runs
  • preemptible trap/syscall fixes
  • support for missing page fault types in page_fault()
  • Property mode set to 100644
File size: 3.7 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 abs32lemm
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/asm.h>
49#include <debug.h>
50#include <memstr.h>
51#include <print.h>
52#include <interrupt.h>
53#include <macros.h>
54
55void page_arch_init(void)
56{
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
76// printf("as_context_table=0x%08x\n", as_context_table);
77
78 /* Switch MMU to new context table */
79 asi_u32_write(ASI_MMUREGS, MMU_CONTEXT_TABLE, KA2PA(as_context_table) >> 4);
80
81 //boot_page_table_free();
82}
83
84void page_fault(unsigned int n __attribute__((unused)), istate_t *istate)
85{
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;
89 mmu_fault_type_t type = (mmu_fault_type_t)fault->at;
90
91// printf("page fault on address 0x%08x, status 0x%08x, type %d\n", fault_address, fault_status, type);
92
93 if (type == FAULT_TYPE_LOAD_USER_DATA ||
94 type == FAULT_TYPE_LOAD_SUPERVISOR_DATA)
95 as_page_fault(fault_address, PF_ACCESS_READ, istate);
96
97 if (type == FAULT_TYPE_EXECUTE_USER ||
98 type == FAULT_TYPE_EXECUTE_SUPERVISOR)
99 as_page_fault(fault_address, PF_ACCESS_EXEC, istate);
100
101 if (type == FAULT_TYPE_STORE_USER_DATA ||
102 type == FAULT_TYPE_STORE_USER_INSTRUCTION ||
103 type == FAULT_TYPE_STORE_SUPERVISOR_INSTRUCTION ||
104 type == FAULT_TYPE_STORE_SUPERVISOR_DATA)
105 as_page_fault(fault_address, PF_ACCESS_WRITE, istate);
106}
107
108/** @}
109 */
Note: See TracBrowser for help on using the repository browser.