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

Last change on this file since 534 was 503, checked in by viala@…, 6 years ago

Add void type on function that takes no parameters, fix invalid call.

Fix invalid calls to thread_can_yield.

In file included from kern/chdev.c:29:
kern/chdev.c: In function 'chdev_sequencial_server':
kern/chdev.c:329:21: error: too many arguments to function 'thread_can_yield'

assert( thread_can_yield( server ) , "illegal sched_yield\n" );

~

Also fixed signature of mapper_create.

File size: 6.3 KB
RevLine 
[1]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)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
[184]12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[1]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 *
[184]16 * ALMOS-MKH is distributed in the hope that it will be useful, but
[1]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
[184]22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[1]23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
[457]26#include <hal_kernel_types.h>
[1]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 <spinlock.h>
38#include <vfs.h>
39#include <page.h>
40#include <vmm.h>
41#include <kmem.h>
42#include <vseg.h>
43
44////////////////////////////////////////////////////////////////////////////////////////
[18]45//   global variables for display / must be consistent with enum in "vseg.h"
[1]46////////////////////////////////////////////////////////////////////////////////////////
47
[101]48
49//////////////////////////////////////////
[184]50char * vseg_type_str( uint32_t vseg_type )
[1]51{
[101]52        if     ( vseg_type == VSEG_TYPE_CODE   ) return "CODE";
53        else if( vseg_type == VSEG_TYPE_DATA   ) return "DATA";
[407]54        else if( vseg_type == VSEG_TYPE_STACK  ) return "STAK";
[101]55        else if( vseg_type == VSEG_TYPE_ANON   ) return "ANON";
56        else if( vseg_type == VSEG_TYPE_FILE   ) return "FILE";
[407]57        else if( vseg_type == VSEG_TYPE_REMOTE ) return "REMO";
[101]58    else                                     return "undefined";
59}
[1]60
61/////////////////////
[503]62vseg_t * vseg_alloc( void )
[1]63{
64    kmem_req_t   req;
65
66    req.type  = KMEM_VSEG;
67        req.size  = sizeof(vseg_t);
68        req.flags = AF_KERNEL;
69
70    return (vseg_t *)kmem_alloc( &req );
71}
72
73///////////////////////////////
74void vseg_free( vseg_t * vseg )
75{
76    kmem_req_t  req;
77
78        req.type = KMEM_VSEG;
79        req.ptr  = vseg;
80        kmem_free( &req );
81}
82
83///////////////////////////////////
84void vseg_init( vseg_t      * vseg,
[407]85                vseg_type_t   type,
[18]86                    intptr_t      base,
[407]87                uint32_t      size,
[1]88                vpn_t         vpn_base,
89                vpn_t         vpn_size,
[407]90                        uint32_t      file_offset,
91                uint32_t      file_size,
92                xptr_t        mapper_xp,
[315]93                cxy_t         cxy )
[1]94{
[407]95    vseg->type        = type;
96        vseg->min         = base;
97        vseg->max         = base + size;
98    vseg->vpn_base    = vpn_base;
99        vseg->vpn_size    = vpn_size;
100    vseg->file_offset = file_offset;
101    vseg->file_size   = file_size;
102        vseg->mapper_xp   = mapper_xp;
103    vseg->cxy         = cxy;
[1]104
105    // set vseg flags depending on type
[18]106        if     ( type == VSEG_TYPE_CODE )
[1]107    {
108        vseg->flags = VSEG_USER    |
[18]109                      VSEG_EXEC    |
[1]110                      VSEG_CACHE   |
111                      VSEG_PRIVATE ;
112    }
113    else if( type == VSEG_TYPE_STACK )
114    {
115        vseg->flags = VSEG_USER    |
116                      VSEG_WRITE   |
117                      VSEG_CACHE   |
[18]118                      VSEG_PRIVATE ;
[1]119    }
[18]120    else if( type == VSEG_TYPE_DATA )
[1]121    {
122        vseg->flags = VSEG_USER    |
123                      VSEG_WRITE   |
[18]124                      VSEG_CACHE   |
[1]125                      VSEG_DISTRIB ;
126    }
[18]127    else if( type == VSEG_TYPE_REMOTE )
[1]128    {
129        vseg->flags = VSEG_USER    |
[18]130                      VSEG_WRITE   |
131                      VSEG_CACHE   ;
[1]132    }
[18]133    else if( type == VSEG_TYPE_ANON )
[1]134    {
135        vseg->flags = VSEG_USER    |
136                      VSEG_WRITE   |
[407]137                      VSEG_CACHE; 
[1]138    }
[18]139    else if( type == VSEG_TYPE_FILE )
[1]140    {
141        vseg->flags = VSEG_USER    |
142                      VSEG_WRITE   |
143                      VSEG_CACHE   ;
144    }
[18]145    else
[1]146    {
[492]147            assert( false , "illegal vseg type\n" );
[18]148    }
[1]149
[315]150}  // end vseg_init()
151
[1]152//////////////////////////////////////////
153void vseg_init_from_ref( vseg_t    * vseg,
[407]154                         xptr_t      ref_xp )
[1]155{
156    // get remote vseg cluster and pointer
[407]157    cxy_t    cxy = (cxy_t   )GET_CXY( ref_xp );
158    vseg_t * ptr = (vseg_t *)GET_PTR( ref_xp );
[1]159
160    // initialize vseg with remote_read access
[407]161    vseg->type        =           hal_remote_lw ( XPTR( cxy , &ptr->type        ) );
162    vseg->min         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min         ) );
163    vseg->max         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max         ) );
164    vseg->vpn_base    =           hal_remote_lw ( XPTR( cxy , &ptr->vpn_base    ) );
165    vseg->vpn_size    =           hal_remote_lw ( XPTR( cxy , &ptr->vpn_size    ) );
166    vseg->flags       =           hal_remote_lw ( XPTR( cxy , &ptr->flags       ) );
167    vseg->file_offset =           hal_remote_lw ( XPTR( cxy , &ptr->file_offset ) );
168    vseg->file_size   =           hal_remote_lw ( XPTR( cxy , &ptr->file_size   ) );
169        vseg->mapper_xp   = (xptr_t)  hal_remote_lwd( XPTR( cxy , &ptr->mapper_xp   ) );
[453]170
171    switch (vseg->type)
172    {
[457]173        case VSEG_TYPE_DATA: 
174        {
[453]175            vseg->cxy = 0xffff;
176            break;
177        }
178        case VSEG_TYPE_CODE:
[457]179        case VSEG_TYPE_STACK: 
180        {
[453]181            vseg->cxy = local_cxy;
182            break;
183        }
184        case VSEG_TYPE_ANON:
185        case VSEG_TYPE_FILE:
[457]186        case VSEG_TYPE_REMOTE: 
187        {
[453]188            vseg->cxy = (cxy_t) hal_remote_lw( XPTR(cxy, &ptr->cxy) );
189            break;
190        }
[457]191        default: 
192        {
[492]193            assert( false, "Illegal vseg type" );
[453]194            break;
195        }
196    }
[184]197}
[1]198
199///////////////////////////////
[406]200void vseg_attach( vmm_t  * vmm,
201                  vseg_t * vseg )
[1]202{
203    // update vseg descriptor
204    vseg->vmm = vmm;
205
206    // add vseg in vmm list
[408]207    xlist_add_last( XPTR( local_cxy , &vmm->vsegs_root ),
208                    XPTR( local_cxy , &vseg->xlist ) );
[1]209}
210
[473]211/////////////////////////////////
212void vseg_detach( vseg_t * vseg )
[1]213{
214    // update vseg descriptor
215    vseg->vmm = NULL;
216
217    // remove vseg from vmm list
[408]218    xlist_unlink( XPTR( local_cxy , &vseg->xlist ) );
[1]219}
220
Note: See TracBrowser for help on using the repository browser.