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

Last change on this file since 690 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
Line 
1/*
2 * vseg.c - virtual segment (vseg) related operations
3 *
4 * Authors   Alain Greiner (2016,2017,2018,2019,2020)
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 <hal_kernel_types.h>
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////////////////////////////////////////////////////////////////////////////////////////
42//   global variables for display / must be consistent with enum in "vseg.h"
43////////////////////////////////////////////////////////////////////////////////////////
44
45
46//////////////////////////////////////////
47char * vseg_type_str( uint32_t vseg_type )
48{
49        if     ( vseg_type == VSEG_TYPE_CODE   ) return "CODE";
50        else if( vseg_type == VSEG_TYPE_DATA   ) return "DATA";
51        else if( vseg_type == VSEG_TYPE_STACK  ) return "STAK";
52        else if( vseg_type == VSEG_TYPE_ANON   ) return "ANON";
53        else if( vseg_type == VSEG_TYPE_FILE   ) return "FILE";
54        else if( vseg_type == VSEG_TYPE_REMOTE ) return "REMO";
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";
58    else                                     return "undefined";
59}
60
61///////////////////////////
62vseg_t * vseg_alloc( void )
63{
64    return (vseg_t*)kmem_alloc( bits_log2( sizeof(vseg_t)) , AF_ZERO );
65}
66
67///////////////////////////////
68void vseg_free( vseg_t * vseg )
69{
70        kmem_free( vseg , bits_log2( sizeof(vseg_t)) );
71}
72
73/////////////////////////////////////////
74void vseg_init_flags( vseg_t      * vseg,
75                      vseg_type_t   type )
76{
77    // set vseg flags depending on type
78        if( type == VSEG_TYPE_CODE )
79    {
80        vseg->flags = VSEG_USER    |
81                      VSEG_EXEC    |
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   |
90                      VSEG_PRIVATE ;
91    }
92    else if( type == VSEG_TYPE_DATA )
93    {
94        vseg->flags = VSEG_USER    |
95                      VSEG_WRITE   |
96                      VSEG_CACHE   |
97                      VSEG_DISTRIB ;
98    }
99    else if( type == VSEG_TYPE_REMOTE )
100    {
101        vseg->flags = VSEG_USER    |
102                      VSEG_WRITE   |
103                      VSEG_CACHE   ;
104    }
105    else if( type == VSEG_TYPE_ANON )
106    {
107        vseg->flags = VSEG_USER    |
108                      VSEG_WRITE   |
109                      VSEG_CACHE; 
110    }
111    else if( type == VSEG_TYPE_FILE )
112    {
113        vseg->flags = VSEG_USER    |
114                      VSEG_WRITE   |
115                      VSEG_CACHE   ;
116    }
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    }
132    else
133    {
134            assert( __FUNCTION__, false , "illegal vseg type\n" );
135    }
136
137}  // end vseg_init()
138
139//////////////////////////////////////////
140void vseg_init_from_ref( vseg_t    * vseg,
141                         xptr_t      ref_xp )
142{
143    // get remote vseg cluster and pointer
144    cxy_t    cxy = (cxy_t   )GET_CXY( ref_xp );
145    vseg_t * ptr = (vseg_t *)GET_PTR( ref_xp );
146
147    // initialize vseg with remote_read access
148    vseg->type        =           hal_remote_l32( XPTR( cxy , &ptr->type        ) );
149    vseg->min         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min         ) );
150    vseg->max         = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max         ) );
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   ) );
156        vseg->mapper_xp   = (xptr_t)  hal_remote_l64( XPTR( cxy , &ptr->mapper_xp   ) );
157
158    switch (vseg->type)
159    {
160        case VSEG_TYPE_DATA:      // unused
161        {
162            vseg->cxy = 0xffff;
163            break;
164        }
165        case VSEG_TYPE_CODE:      // always local
166        case VSEG_TYPE_STACK: 
167        case VSEG_TYPE_KCODE:
168        {
169            vseg->cxy = local_cxy;
170            break;
171        }
172        case VSEG_TYPE_ANON:      // intrinsic
173        case VSEG_TYPE_FILE:
174        case VSEG_TYPE_REMOTE: 
175        case VSEG_TYPE_KDEV:
176        case VSEG_TYPE_KDATA:
177        {
178            vseg->cxy = (cxy_t) hal_remote_l32( XPTR(cxy, &ptr->cxy) );
179            break;
180        }
181        default: 
182        {
183            assert( __FUNCTION__, false, "Illegal vseg type" );
184            break;
185        }
186    }
187}
188
189
Note: See TracBrowser for help on using the repository browser.