source: trunk/kernel/mm/vseg.c

Last change on this file was 683, checked in by alain, 3 years ago

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File size: 5.8 KB
RevLine 
[1]1/*
2 * vseg.c - virtual segment (vseg) related operations
3 *
[657]4 * Authors   Alain Greiner (2016,2017,2018,2019,2020)
[1]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
[184]10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[1]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 *
[184]14 * ALMOS-MKH is distributed in the hope that it will be useful, but
[1]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
[184]20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[1]21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[457]24#include <hal_kernel_types.h>
[1]25#include <hal_special.h>
26#include <hal_remote.h>
27#include <list.h>
28#include <errno.h>
29#include <printk.h>
30#include <bits.h>
31#include <thread.h>
32#include <process.h>
33#include <ppm.h>
34#include <mapper.h>
35#include <vfs.h>
36#include <page.h>
37#include <vmm.h>
38#include <kmem.h>
39#include <vseg.h>
40
41////////////////////////////////////////////////////////////////////////////////////////
[18]42//   global variables for display / must be consistent with enum in "vseg.h"
[1]43////////////////////////////////////////////////////////////////////////////////////////
44
[101]45
46//////////////////////////////////////////
[184]47char * vseg_type_str( uint32_t vseg_type )
[1]48{
[101]49        if     ( vseg_type == VSEG_TYPE_CODE   ) return "CODE";
50        else if( vseg_type == VSEG_TYPE_DATA   ) return "DATA";
[407]51        else if( vseg_type == VSEG_TYPE_STACK  ) return "STAK";
[101]52        else if( vseg_type == VSEG_TYPE_ANON   ) return "ANON";
53        else if( vseg_type == VSEG_TYPE_FILE   ) return "FILE";
[407]54        else if( vseg_type == VSEG_TYPE_REMOTE ) return "REMO";
[623]55        else if( vseg_type == VSEG_TYPE_KCODE  ) return "KCOD";
56        else if( vseg_type == VSEG_TYPE_KDATA  ) return "KDAT";
57        else if( vseg_type == VSEG_TYPE_KDEV   ) return "KDEV";
[101]58    else                                     return "undefined";
59}
[1]60
[625]61///////////////////////////
[503]62vseg_t * vseg_alloc( void )
[1]63{
[683]64    return (vseg_t*)kmem_alloc( bits_log2( sizeof(vseg_t)) , AF_ZERO );
[1]65}
66
67///////////////////////////////
68void vseg_free( vseg_t * vseg )
69{
[683]70        kmem_free( vseg , bits_log2( sizeof(vseg_t)) );
[1]71}
72
[651]73/////////////////////////////////////////
74void vseg_init_flags( vseg_t      * vseg,
75                      vseg_type_t   type )
[1]76{
77    // set vseg flags depending on type
[651]78        if( type == VSEG_TYPE_CODE )
[1]79    {
80        vseg->flags = VSEG_USER    |
[18]81                      VSEG_EXEC    |
[1]82                      VSEG_CACHE   |
83                      VSEG_PRIVATE ;
84    }
85    else if( type == VSEG_TYPE_STACK )
86    {
87        vseg->flags = VSEG_USER    |
88                      VSEG_WRITE   |
89                      VSEG_CACHE   |
[18]90                      VSEG_PRIVATE ;
[1]91    }
[18]92    else if( type == VSEG_TYPE_DATA )
[1]93    {
94        vseg->flags = VSEG_USER    |
95                      VSEG_WRITE   |
[18]96                      VSEG_CACHE   |
[1]97                      VSEG_DISTRIB ;
98    }
[18]99    else if( type == VSEG_TYPE_REMOTE )
[1]100    {
101        vseg->flags = VSEG_USER    |
[18]102                      VSEG_WRITE   |
103                      VSEG_CACHE   ;
[1]104    }
[18]105    else if( type == VSEG_TYPE_ANON )
[1]106    {
107        vseg->flags = VSEG_USER    |
108                      VSEG_WRITE   |
[407]109                      VSEG_CACHE; 
[1]110    }
[18]111    else if( type == VSEG_TYPE_FILE )
[1]112    {
113        vseg->flags = VSEG_USER    |
114                      VSEG_WRITE   |
115                      VSEG_CACHE   ;
116    }
[623]117    else if( type == VSEG_TYPE_KCODE )
118    {
119        vseg->flags = VSEG_EXEC    |
120                      VSEG_CACHE   |
121                      VSEG_PRIVATE ;
122    }
123    else if( type == VSEG_TYPE_KDATA )
124    {
125        vseg->flags = VSEG_CACHE   |
126                      VSEG_WRITE   ;
127    }
128    else if( type == VSEG_TYPE_KDEV )
129    {
130        vseg->flags = VSEG_WRITE   ;
131    }
[18]132    else
[1]133    {
[672]134            assert( __FUNCTION__, false , "illegal vseg type\n" );
[18]135    }
[1]136
[315]137}  // end vseg_init()
138
[1]139//////////////////////////////////////////
140void vseg_init_from_ref( vseg_t    * vseg,
[407]141                         xptr_t      ref_xp )
[1]142{
143    // get remote vseg cluster and pointer
[407]144    cxy_t    cxy = (cxy_t   )GET_CXY( ref_xp );
145    vseg_t * ptr = (vseg_t *)GET_PTR( ref_xp );
[1]146
147    // initialize vseg with remote_read access
[623]148    vseg->type        =           hal_remote_l32( XPTR( cxy , &ptr->type        ) );
[407]149    vseg->min         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min         ) );
150    vseg->max         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max         ) );
[623]151    vseg->vpn_base    =           hal_remote_l32( XPTR( cxy , &ptr->vpn_base    ) );
152    vseg->vpn_size    =           hal_remote_l32( XPTR( cxy , &ptr->vpn_size    ) );
153    vseg->flags       =           hal_remote_l32( XPTR( cxy , &ptr->flags       ) );
154    vseg->file_offset =           hal_remote_l32( XPTR( cxy , &ptr->file_offset ) );
155    vseg->file_size   =           hal_remote_l32( XPTR( cxy , &ptr->file_size   ) );
[567]156        vseg->mapper_xp   = (xptr_t)  hal_remote_l64( XPTR( cxy , &ptr->mapper_xp   ) );
[453]157
158    switch (vseg->type)
159    {
[623]160        case VSEG_TYPE_DATA:      // unused
[457]161        {
[453]162            vseg->cxy = 0xffff;
163            break;
164        }
[623]165        case VSEG_TYPE_CODE:      // always local
[457]166        case VSEG_TYPE_STACK: 
[623]167        case VSEG_TYPE_KCODE:
[457]168        {
[453]169            vseg->cxy = local_cxy;
170            break;
171        }
[623]172        case VSEG_TYPE_ANON:      // intrinsic
[453]173        case VSEG_TYPE_FILE:
[457]174        case VSEG_TYPE_REMOTE: 
[623]175        case VSEG_TYPE_KDEV:
176        case VSEG_TYPE_KDATA:
[457]177        {
[567]178            vseg->cxy = (cxy_t) hal_remote_l32( XPTR(cxy, &ptr->cxy) );
[453]179            break;
180        }
[457]181        default: 
182        {
[672]183            assert( __FUNCTION__, false, "Illegal vseg type" );
[453]184            break;
185        }
186    }
[184]187}
[1]188
189
Note: See TracBrowser for help on using the repository browser.