source: trunk/hal/tsar_mips32/core/hal_vmm.c @ 579

Last change on this file since 579 was 579, checked in by alain, 6 years ago

restore value of CONFIG_VMM_KENTRY_BASE to 0x000004

File size: 3.2 KB
Line 
1/*
2 * hal_vmm.c - Generic Virtual Memory Manager Initialisation for TSAR
3 *
4 * Authors  Alain Greiner (2016,2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <kernel_config.h>
25#include <hal_kernel_types.h>
26#include <hal_vmm.h>
27#include <hal_gpt.h>
28#include <vseg.h>
29#include <xlist.h>
30#include <vmm.h>
31#include <remote_rwlock.h>
32
33//////////////////////////////////////////////////////////////////////////////////////////
34// This file contains the TSAR specific code to initialize the Virtual Memory Manager.
35// The "kentry" vseg contains the kernel code executed when a core enter/exit the kernel,
36// in case of Interrupt, Exception, or Syscall.
37// For the TSAR architecture, the kernel uses physical addresses, and this code must be
38// identity mapped. The following function is called by the generic vmm_init() function
39// and identity map all pages of the "kentry" vseg.
40//////////////////////////////////////////////////////////////////////////////////////////
41
42////////////////////////////////////
43error_t  hal_vmm_init( vmm_t * vmm )
44{
45    error_t error;
46
47    // get pointer on GPT
48    gpt_t * gpt = &vmm->gpt;
49
50    // map all pages of "kentry" vseg
51    uint32_t vpn;
52    uint32_t attr;
53    attr = GPT_MAPPED | GPT_SMALL | GPT_EXECUTABLE | GPT_CACHABLE | GPT_GLOBAL;
54    for( vpn = CONFIG_VMM_KENTRY_BASE;
55         vpn < (CONFIG_VMM_KENTRY_BASE + CONFIG_VMM_KENTRY_SIZE); vpn++ )
56    {
57        error = hal_gpt_set_pte( gpt,
58                                 vpn,
59                                 attr,
60                                 (local_cxy<<20) | (vpn & 0xFFFFF) );
61
62        if( error ) return error;
63    }
64
65    // get extended pointer on lock protecting the VSL
66    xptr_t lock_xp = XPTR( local_cxy , &vmm->vsegs_lock );
67
68    // get VSL lock
69    remote_rwlock_wr_acquire( lock_xp );
70
71    // scan the VSL to found the "kentry" vseg
72    xptr_t         root_xp = XPTR( local_cxy , &vmm->vsegs_root );
73    xptr_t         iter_xp;
74    xptr_t         vseg_xp;
75    vseg_t       * vseg;
76    bool_t         found = false;
77 
78    XLIST_FOREACH( root_xp , iter_xp )
79    {
80        vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist );
81        vseg    = (vseg_t *)GET_PTR( vseg_xp );
82
83        // set the IDENT flag in "kentry" vseg descriptor
84        if( vseg->vpn_base == CONFIG_VMM_KENTRY_BASE )
85        {
86            vseg->flags |= VSEG_IDENT;
87            found = true;
88            break;
89        }
90    }
91
92    // release the VSL lock
93    remote_rwlock_wr_release( lock_xp );
94
95    if( found == false ) return error;
96
97    return 0;
98
99}  // end hal_vmm_init()
100
101
Note: See TracBrowser for help on using the repository browser.