source: trunk/kernel/mm/vseg.c @ 595

Last change on this file since 595 was 595, checked in by alain, 5 years ago

Cosmetic: improve debug.

File size: 5.8 KB
Line 
1/*
2 * vseg.c - virtual segment (vseg) related operations
3 *
4 * Authors   Ghassan Almaless (2008,2009,2010,2011, 2012)
5 *           Mohamed Lamine Karaoui (2015)
6 *           Alain Greiner (2016,2018,2019)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <hal_kernel_types.h>
27#include <hal_special.h>
28#include <hal_remote.h>
29#include <list.h>
30#include <errno.h>
31#include <printk.h>
32#include <bits.h>
33#include <thread.h>
34#include <process.h>
35#include <ppm.h>
36#include <mapper.h>
37#include <vfs.h>
38#include <page.h>
39#include <vmm.h>
40#include <kmem.h>
41#include <vseg.h>
42
43////////////////////////////////////////////////////////////////////////////////////////
44//   global variables for display / must be consistent with enum in "vseg.h"
45////////////////////////////////////////////////////////////////////////////////////////
46
47
48//////////////////////////////////////////
49char * vseg_type_str( uint32_t vseg_type )
50{
51        if     ( vseg_type == VSEG_TYPE_CODE   ) return "CODE";
52        else if( vseg_type == VSEG_TYPE_DATA   ) return "DATA";
53        else if( vseg_type == VSEG_TYPE_STACK  ) return "STAK";
54        else if( vseg_type == VSEG_TYPE_ANON   ) return "ANON";
55        else if( vseg_type == VSEG_TYPE_FILE   ) return "FILE";
56        else if( vseg_type == VSEG_TYPE_REMOTE ) return "REMO";
57    else                                     return "undefined";
58}
59
60/////////////////////
61vseg_t * vseg_alloc( void )
62{
63    kmem_req_t   req;
64
65    req.type  = KMEM_VSEG;
66        req.size  = sizeof(vseg_t);
67        req.flags = AF_KERNEL;
68
69    return (vseg_t *)kmem_alloc( &req );
70}
71
72///////////////////////////////
73void vseg_free( vseg_t * vseg )
74{
75    kmem_req_t  req;
76
77        req.type = KMEM_VSEG;
78        req.ptr  = vseg;
79        kmem_free( &req );
80}
81
82///////////////////////////////////
83void vseg_init( vseg_t      * vseg,
84                vseg_type_t   type,
85                    intptr_t      base,
86                uint32_t      size,
87                vpn_t         vpn_base,
88                vpn_t         vpn_size,
89                        uint32_t      file_offset,
90                uint32_t      file_size,
91                xptr_t        mapper_xp,
92                cxy_t         cxy )
93{
94    vseg->type        = type;
95        vseg->min         = base;
96        vseg->max         = base + size;
97    vseg->vpn_base    = vpn_base;
98        vseg->vpn_size    = vpn_size;
99    vseg->file_offset = file_offset;
100    vseg->file_size   = file_size;
101        vseg->mapper_xp   = mapper_xp;
102    vseg->cxy         = cxy;
103
104    // set vseg flags depending on type
105        if     ( type == VSEG_TYPE_CODE )
106    {
107        vseg->flags = VSEG_USER    |
108                      VSEG_EXEC    |
109                      VSEG_CACHE   |
110                      VSEG_PRIVATE ;
111    }
112    else if( type == VSEG_TYPE_STACK )
113    {
114        vseg->flags = VSEG_USER    |
115                      VSEG_WRITE   |
116                      VSEG_CACHE   |
117                      VSEG_PRIVATE ;
118    }
119    else if( type == VSEG_TYPE_DATA )
120    {
121        vseg->flags = VSEG_USER    |
122                      VSEG_WRITE   |
123                      VSEG_CACHE   |
124                      VSEG_DISTRIB ;
125    }
126    else if( type == VSEG_TYPE_REMOTE )
127    {
128        vseg->flags = VSEG_USER    |
129                      VSEG_WRITE   |
130                      VSEG_CACHE   ;
131    }
132    else if( type == VSEG_TYPE_ANON )
133    {
134        vseg->flags = VSEG_USER    |
135                      VSEG_WRITE   |
136                      VSEG_CACHE; 
137    }
138    else if( type == VSEG_TYPE_FILE )
139    {
140        vseg->flags = VSEG_USER    |
141                      VSEG_WRITE   |
142                      VSEG_CACHE   ;
143    }
144    else
145    {
146            assert( false , "illegal vseg type\n" );
147    }
148
149}  // end vseg_init()
150
151//////////////////////////////////////////
152void vseg_init_from_ref( vseg_t    * vseg,
153                         xptr_t      ref_xp )
154{
155    // get remote vseg cluster and pointer
156    cxy_t    cxy = (cxy_t   )GET_CXY( ref_xp );
157    vseg_t * ptr = (vseg_t *)GET_PTR( ref_xp );
158
159    // initialize vseg with remote_read access
160    vseg->type        =           hal_remote_l32 ( XPTR( cxy , &ptr->type        ) );
161    vseg->min         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min         ) );
162    vseg->max         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max         ) );
163    vseg->vpn_base    =           hal_remote_l32 ( XPTR( cxy , &ptr->vpn_base    ) );
164    vseg->vpn_size    =           hal_remote_l32 ( XPTR( cxy , &ptr->vpn_size    ) );
165    vseg->flags       =           hal_remote_l32 ( XPTR( cxy , &ptr->flags       ) );
166    vseg->file_offset =           hal_remote_l32 ( XPTR( cxy , &ptr->file_offset ) );
167    vseg->file_size   =           hal_remote_l32 ( XPTR( cxy , &ptr->file_size   ) );
168        vseg->mapper_xp   = (xptr_t)  hal_remote_l64( XPTR( cxy , &ptr->mapper_xp   ) );
169
170    switch (vseg->type)
171    {
172        case VSEG_TYPE_DATA: 
173        {
174            vseg->cxy = 0xffff;
175            break;
176        }
177        case VSEG_TYPE_CODE:
178        case VSEG_TYPE_STACK: 
179        {
180            vseg->cxy = local_cxy;
181            break;
182        }
183        case VSEG_TYPE_ANON:
184        case VSEG_TYPE_FILE:
185        case VSEG_TYPE_REMOTE: 
186        {
187            vseg->cxy = (cxy_t) hal_remote_l32( XPTR(cxy, &ptr->cxy) );
188            break;
189        }
190        default: 
191        {
192            assert( false, "Illegal vseg type" );
193            break;
194        }
195    }
196}
197
198
Note: See TracBrowser for help on using the repository browser.