Changeset 204 for trunk/kernel/mm/vmm.c


Ignore:
Timestamp:
Jul 17, 2017, 8:42:59 AM (7 years ago)
Author:
alain
Message:

Bug fix in kernel_init
-This line, and those below, will be ignored--

M params.mk
M kernel_config.h
M Makefile
M hdd/virt_hdd.dmg
M tools/bootloader_tsar/boot.c
M kernel/libk/bits.h
M kernel/libk/elf.c
M kernel/libk/xhtab.c
M kernel/libk/elf.h
M kernel/libk/xhtab.h
M kernel/devices/dev_pic.c
M kernel/mm/vmm.c
M kernel/mm/mapper.c
M kernel/mm/mapper.h
M kernel/vfs/devfs.h
M kernel/vfs/vfs.c
M kernel/vfs/vfs.h
M kernel/vfs/devfs.c
M kernel/kern/chdev.h
M kernel/kern/kernel_init.c
M kernel/kern/process.c
M kernel/kern/process.h
M hal/tsar_mips32/core/hal_remote.c
M hal/tsar_mips32/drivers/soclib_pic.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/vmm.c

    r179 r204  
    6262    intptr_t  size;
    6363
     64    vmm_dmsg("\n[INFO] %s : enter for process %x\n", __FUNCTION__ , process->pid );
     65
    6466    // get pointer on VMM
    6567    vmm_t   * vmm = &process->vmm;
    6668
    67     // check UTILS zone size
    68     if( (CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE ) >
    69         CONFIG_VMM_ELF_BASE )
    70     {
    71         printk("\n[PANIC] in %s : UTILS zone too small for process %x\n",
    72                __FUNCTION__ , process->pid );
    73         hal_core_sleep();
    74     }
    75 
    76     // check max number of stacks slots
    77     if( CONFIG_THREAD_MAX_PER_CLUSTER > 32 )
    78     {
    79         printk("\n[PANIC] in %s : max number of threads per cluster for a single process"
    80                " cannot be larger than 32\n", __FUNCTION__ );
    81         hal_core_sleep();
    82     }
    83 
    84     // check STACK zone size
    85     if( (CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) >
    86         (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE) )
    87     {
    88         printk("\n[PANIC] in %s : STACK zone too small for process %x\n",
    89                __FUNCTION__ , process->pid );
    90         hal_core_sleep();
    91     }
     69    assert( ((CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE)
     70            <= CONFIG_VMM_ELF_BASE) , __FUNCTION__ , "UTILS zone too small\n" );
     71
     72    assert( (CONFIG_THREAD_MAX_PER_CLUSTER <= 32) , __FUNCTION__ ,
     73            "no more than 32 threads per cluster for a single process\n");
     74
     75    assert( ((CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) <=
     76             (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE)) , __FUNCTION__ ,
     77             "STACK zone too small\n");
    9278
    9379    // initialize the rwlock protecting the vsegs list
     
    10187                        CONFIG_VMM_GRDXT_W2,
    10288                        CONFIG_VMM_GRDXT_W3 );
    103     if( error )
    104     {
    105         printk("\n[PANIC] in %s : cannot initialize radix tree for process %x\n",
    106                __FUNCTION__ , process->pid );
    107         hal_core_sleep();
    108     }
     89 
     90    assert( (error == 0) , __FUNCTION__ , "cannot initialize radix tree\n" );
    10991
    11092    // register kentry vseg in VMM
     
    11294    size = CONFIG_VMM_KENTRY_SIZE << CONFIG_PPM_PAGE_SHIFT;
    11395    vseg_kentry = vmm_create_vseg( process , base , size , VSEG_TYPE_CODE );
    114     if( vseg_kentry == NULL )
    115     {
    116         printk("\n[PANIC] in %s : cannot register kent vseg for process %x\n",
    117                __FUNCTION__ , process->pid );
    118         hal_core_sleep();
    119     }
     96
     97    assert( (vseg_kentry != NULL) , __FUNCTION__ , "cannot register kentry vseg\n" );
     98
    12099    vmm->kent_vpn_base = 1;
    121100
     
    124103    size = CONFIG_VMM_ARGS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    125104    vseg_args = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    126     if( vseg_args == NULL )
    127     {
    128         printk("\n[PANIC] in %s : cannot register args vseg for process %x\n",
    129                __FUNCTION__ , process->pid );
    130         hal_core_sleep();
    131     }
     105
     106    assert( (vseg_args != NULL) , __FUNCTION__ , "cannot register args vseg\n" );
     107
    132108    vmm->args_vpn_base = CONFIG_VMM_KENTRY_SIZE + 1;
    133109
     
    136112    size = CONFIG_VMM_ENVS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    137113    vseg_envs = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    138     if( vseg_envs == NULL )
    139     {
    140         printk("\n[PANIC] in %s : cannot register envs vseg for process %x\n",
    141                __FUNCTION__ , process->pid );
    142         hal_core_sleep();
    143     }
     114
     115    assert( (vseg_envs != NULL) , __FUNCTION__ , "cannot register envs vseg\n" );
     116
    144117    vmm->envs_vpn_base = CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + 1;
    145118
     
    148121    size = (CONFIG_VMM_MMAP_BASE-CONFIG_VMM_HEAP_BASE) << CONFIG_PPM_PAGE_SHIFT;
    149122    vseg_heap = vmm_create_vseg( process , base , size , VSEG_TYPE_HEAP );
    150     if( vseg_heap == NULL )
    151     {
    152         printk("\n[PANIC] in %s : cannot register heap vseg in for process %x\n",
    153                __FUNCTION__ , process->pid );
    154         hal_core_sleep();
    155     }
     123
     124    assert( (vseg_heap != NULL) , __FUNCTION__ , "cannot register heap vseg\n" );
     125
    156126    vmm->heap_vpn_base = CONFIG_VMM_HEAP_BASE;
    157127
    158128    // initialize generic page table
    159129    error = hal_gpt_create( &vmm->gpt );
    160     if( error )
    161     {
    162         printk("PANIC in %s : cannot initialize page table\n", __FUNCTION__ );
    163         hal_core_sleep();
    164     }
     130
     131    assert( (error == 0) , __FUNCTION__ , "cannot initialize page table\n");
    165132
    166133    // initialize STACK allocator
     
    181148
    182149    hal_fence();
    183 }
     150
     151    vmm_dmsg("\n[INFO] %s : exit for process %x\n", __FUNCTION__ , process->pid );
     152
     153}  // end vmm_init()
    184154
    185155//////////////////////////////////////////
     
    301271
    302272    return 0;
    303 }
     273
     274}  // vmm_copy()
    304275
    305276///////////////////////////////////////
     
    342313    // release memory allocated to the local page table
    343314    hal_gpt_destroy( &vmm->gpt );
    344 }
     315
     316}  // end vmm_destroy()
    345317
    346318/////////////////////////////////////////////////
     
    357329        {
    358330                vseg = LIST_ELEMENT( iter , vseg_t , list );
     331
    359332                if( ((vpn_base + vpn_size) > vseg->vpn_base) &&
    360333             (vpn_base < (vseg->vpn_base + vseg->vpn_size)) ) return vseg;
    361334        }
    362335    return NULL;
    363 }
     336
     337}  // end vmm_check_conflict()
    364338
    365339////////////////////////////////////////////////////////////////////////////////////////////
     
    399373    *vpn_size = CONFIG_VMM_STACK_SIZE - 1;
    400374    return 0;
    401 }
     375
     376} // end vmm_stack_alloc()
    402377
    403378////////////////////////////////////////////////////////////////////////////////////////////
     
    464439    *vpn_size = size;
    465440    return 0;
    466 }
     441
     442}  // end vmm_mmap_alloc()
    467443
    468444//////////////////////////////////////////////
     
    473449{
    474450    vseg_t     * vseg;          // created vseg pointer
    475     vpn_t        vpn_base;      // vseg first page
     451    vpn_t        vpn_base;      // first page index
    476452    vpn_t        vpn_size;      // number of pages
    477453        error_t      error;
     
    480456        vmm_t * vmm = &process->vmm;
    481457
    482         vmm_dmsg("\n[INFO] %s enter for process %x / base = %x / size = %x / type = %s\n",
     458        vmm_dmsg("\n[INFO] %s : enter for process %x / base = %x / size = %x / type = %s\n",
    483459                     __FUNCTION__ , process->pid , base , size , vseg_type_str(type) );
    484460
    485     // compute base, size, vpn_base, vpn_size, depending on type
     461    // compute base, size, vpn_base, vpn_size, depending on vseg type
    486462    // we use the VMM specific allocators for STACK and MMAP vsegs
    487463    if( type == VSEG_TYPE_STACK )
     
    520496    else
    521497    {
    522         vpn_base = ARROUND_DOWN( base , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
    523             vpn_size = ARROUND_UP( base + size , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
     498        uint32_t vpn_min = base >> CONFIG_PPM_PAGE_SHIFT;
     499        uint32_t vpn_max = (base + size - 1) >> CONFIG_PPM_PAGE_SHIFT;
     500
     501        vpn_base = vpn_min;
     502            vpn_size = vpn_max - vpn_min + 1;
    524503    }
    525504
     
    555534        rwlock_wr_unlock( &vmm->vsegs_lock );
    556535
    557         vmm_dmsg("\n[INFO] : %s exit for process %x, vseg [%x, %x] has been mapped\n",
     536        vmm_dmsg("\n[INFO] %s : exit for process %x / vseg [%x, %x] has been mapped\n",
    558537                     __FUNCTION__ , process->pid , vseg->min , vseg->max );
    559538
Note: See TracChangeset for help on using the changeset viewer.