Changeset 390 for soft


Ignore:
Timestamp:
Aug 7, 2014, 4:57:07 PM (10 years ago)
Author:
alain
Message:

1) Introducing the new system call giet_get_xy() in stdio.h,

required for the free() funcyion in malloc.h

2) Fixing bugs in malloc.c

Location:
soft/giet_vm/giet_libs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_libs/malloc.c

    r382 r390  
    7878    }
    7979
    80     // compute alloc[] minimal array size
     80    // compute size of block containin alloc[] array
    8181    alloc_size = heap_size / MIN_BLOCK_SIZE;
     82    if ( alloc_size < MIN_BLOCK_SIZE) alloc_size = MIN_BLOCK_SIZE;
    8283
    8384    // get index for the corresponding block
     
    9899    unsigned int   base = heap_base;
    99100    unsigned int*  ptr;
    100     for ( index = heap_index-1 ; index > alloc_index ; index-- )
     101    for ( index = heap_index-1 ; index >= alloc_index ; index-- )
    101102    {
    102103        heap[x][y].free[index] = base;
     
    247248    }
    248249
     250    // normalize size
     251    if ( size < MIN_BLOCK_SIZE ) size = MIN_BLOCK_SIZE;
     252
    249253    // compute requested_index for the free[] array
    250254    unsigned int requested_index = GET_SIZE_INDEX( size );
     
    258262                                   requested_index );
    259263
    260     // update the alloc[] array
    261     unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE;
    262     unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset);
    263     *ptr = requested_index;
     264    // update the alloc[] array if block found
     265    if ( base != 0 )
     266    {
     267        unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE;
     268        unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset);
     269        *ptr = requested_index;
     270    }
    264271
    265272    // release the lock
     
    286293void free( void* ptr )
    287294{
    288     // To be done
    289     // - first : to compute the cluster coordinate
    290     // - second : retrieve the block length from the
    291     // - third : try to concatenate with another free block of same size
    292     // - fourth : update the free[] array
     295    unsigned int vaddr = (unsigned int)ptr;
     296
     297    // get the cluster coordinate
     298    unsigned int x;
     299    unsigned int y;
     300    giet_get_xy( ptr, &x, &y );
     301
     302    // compute index in alloc[] array
     303    unsigned index = ( (unsigned int)ptr - heap[x][y].heap_base ) / MAX_BLOCK_SIZE;
     304 
     305    // get the freed block size_index
     306    unsigned char* p i        = (unsigned char*)(heap[x][y].alloc_base + index);
     307    unsigned int   size_index = (unsigned int)*p;
     308
     309    // update the free[] array and NEXT pointer
     310    *(unsigned int*)ptr         = heap[x][y].free[size_index];
     311    heap[x][y].free[size_index] = (unsigned int)ptr;
     312   
     313    // TODO try to concatenate with another free block of same size
     314    // this require probably to replace this simple push by a recursive function
    293315}
    294316
  • soft/giet_vm/giet_libs/stdio.c

    r382 r390  
    55// Copyright (c) UPMC-LIP6
    66///////////////////////////////////////////////////////////////////////////////////
    7 // The stdio.c and stdio.h files are part of the GIET_VM nano-kernel.
    8 // This library contains all user-level functions that contain a system call
    9 // to access protected or shared ressources.
    10 ///////////////////////////////////////////////////////////////////////////////////
    117
    128#include <stdarg.h>
    139#include <stdio.h>
    1410#include <giet_config.h>
     11
     12////////////////////////////////////////////////////////////////////////////////////
     13/////////////////////  MIPS32     related system calls /////////////////////////////
     14////////////////////////////////////////////////////////////////////////////////////
     15
     16/////////////////
     17int giet_procid()
     18{
     19    return sys_call( SYSCALL_PROCID,
     20                     0, 0, 0, 0 );
     21}
     22
     23////////////////////
     24int giet_proctime()
     25{
     26    return sys_call( SYSCALL_PROCTIME,
     27                     0, 0, 0, 0 );
     28}
     29
     30///////////////
     31int giet_rand()
     32{
     33    unsigned int x = sys_call(SYSCALL_PROCTIME,
     34                              0, 0, 0, 0);
     35    if ((x & 0xF) > 7)
     36    {
     37        return (x*x & 0xFFFF);
     38    }
     39    else
     40    {
     41        return (x*x*x & 0xFFFF);
     42    }
     43}
    1544
    1645////////////////////////////////////////////////////////////////////////////////////
     
    498527                   (unsigned int)buffer,
    499528                   count,
    500                    offset ) != count ) giet_exit("in giet_fat_read()");
     529                   offset ) != count ) giet_exit("ERROR in giet_fat_read()");
    501530}
    502531
     
    511540                   (unsigned int)buffer,
    512541                   count,
    513                    offset ) != count ) giet_exit("in giet_fat_write()");
     542                   offset ) != count ) giet_exit("ERROR in giet_fat_write()");
    514543}
    515544
     
    541570                   offset,
    542571                   whence,
    543                    0 ) ) giet_exit("in giet_fat_lseek()");
     572                   0 ) ) giet_exit("ERROR in giet_fat_lseek()");
    544573}
    545574
     
    549578    if ( sys_call( SYSCALL_FAT_FSTAT,
    550579                   fd,
    551                    0, 0, 0 ) )  giet_exit("in giet_fat_lseek()");
     580                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_lseek()");
    552581}
    553582
     
    557586    if ( sys_call( SYSCALL_FAT_CLOSE,
    558587                   fd,
    559                    0, 0, 0 ) )  giet_exit("in giet_fat_close()");
    560 }
    561 
    562 
    563 //////////////////////////////////////////////////////////////////////////////////
    564 ///////////////////// Miscellaneous system calls /////////////////////////////////
    565 //////////////////////////////////////////////////////////////////////////////////
    566 
    567 /////////////////
    568 int giet_procid()
    569 {
    570     return sys_call( SYSCALL_PROCID,
    571                      0, 0, 0, 0 );
    572 }
    573 
    574 ////////////////////
    575 int giet_proctime()
    576 {
    577     return sys_call( SYSCALL_PROCTIME,
    578                      0, 0, 0, 0 );
    579 }
     588                   0, 0, 0 ) )  giet_exit("ERROR in giet_fat_close()");
     589}
     590
     591
     592//////////////////////////////////////////////////////////////////////////////////
     593///////////////////// Task context  system calls /////////////////////////////////
     594//////////////////////////////////////////////////////////////////////////////////
    580595
    581596///////////////////////
     
    600615}
    601616
    602 ///////////////
    603 int giet_rand()
    604 {
    605     unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0);
    606     if ((x & 0xF) > 7) {
    607         return (x*x & 0xFFFF);
    608     }
    609     else {
    610         return (x*x*x & 0xFFFF);
    611     }
    612 }
     617
     618//////////////////////////////////////////////////////////////////////////////////
     619///////////////////// Miscellaneous system calls /////////////////////////////////
     620//////////////////////////////////////////////////////////////////////////////////
    613621
    614622//////////////////////////////
     
    625633{
    626634    if ( condition == 0 ) giet_exit( string );
     635}
     636
     637//////////////////////////
     638void giet_context_switch()
     639{
     640    sys_call( SYSCALL_CTX_SWITCH,
     641              0, 0, 0, 0 );
    627642}
    628643
     
    636651                   (unsigned int) vobj_name,
    637652                   (unsigned int) vobj_vaddr,
    638                    0 ) )  giet_exit("in giet_vobj_get_vbase()");
     653                   0 ) )  giet_exit("ERROR in giet_vobj_get_vbase()");
    639654}
    640655
     
    646661                   cluster_id,
    647662                   (unsigned int) buffer,
    648                    0, 0) )  giet_exit("in giet_proc_number()");
    649 }
    650 
    651 //////////////////////////
    652 void giet_context_switch()
    653 {
    654     sys_call( SYSCALL_CTX_SWITCH,
    655               0, 0, 0, 0 );
     663                   0, 0) )  giet_exit("ERROR in giet_proc_number()");
    656664}
    657665
     
    666674                   (unsigned int)length,
    667675                   x,
    668                    y ) )  giet_exit("in giet_heap_info()");
     676                   y ) )  giet_exit("ERROR in giet_heap_info()");
     677}
     678
     679/////////////////////////////////////////
     680void giet_get_xy( void*         ptr,
     681                  unsigned int* px,
     682                  unsigned int* py )
     683{
     684    if ( sys_call( SYSCALL_GET_XY,
     685                   (unsigned int)ptr,
     686                   (unsigned int)px,
     687                   (unsigned int)py,
     688                   0 ) )  giet_exit("ERROR in giet_get_xy()");
    669689}
    670690
  • soft/giet_vm/giet_libs/stdio.h

    r389 r390  
    44// Author   : alain greiner & Joel Porquet
    55// Copyright (c) UPMC-LIP6
     6///////////////////////////////////////////////////////////////////////////////////
     7// The stdio.c and stdio.h files are part of the GIET_VM nano-kernel.
     8// This library contains all user-level functions that contain a system call
     9// to access protected or shared ressources.
    610///////////////////////////////////////////////////////////////////////////////////
    711
     
    4044#define SYSCALL_CTX_SWITCH        0x19
    4145#define SYSCALL_VOBJ_GET_VBASE    0x1A
    42 #define SYSCALL_FREE_1B           0x1B
     46#define SYSCALL_GET_XY            0x1B
    4347#define SYSCALL_NIC_CMA_START     0x1C
    4448#define SYSCALL_NIC_CMA_STOP      0x1D
     
    446450                            unsigned int  y );
    447451
     452//////////////////////////////////////////////////////////////////////////
     453// This function takes as input a virtual address (ptr argument),
     454// and returns through the (px,py) arguments the coordinates of
     455// the cluster containing the physical address associated to ptr.
     456// In case of error (unmapped virtual address), it makes a giet_exit().
     457//////////////////////////////////////////////////////////////////////////
     458extern void giet_get_xy( void*          ptr,
     459                         unsigned int*  px,
     460                         unsigned int*  py );
     461
    448462#endif
    449463
Note: See TracChangeset for help on using the changeset viewer.