Changeset 167 for soft


Ignore:
Timestamp:
Jul 16, 2012, 10:26:27 AM (12 years ago)
Author:
alain
Message:

Fix several bugs to use the vci_block_device with MMU activated

Location:
soft/giet_vm
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/boot/boot.ld

    r160 r167  
    1212seg_mapping_base        = 0xBFC0C000;   /* boot mapping_info */
    1313
    14 seg_kernel_init_base    = 0x80030000;   /* system init entry */
     14seg_kernel_init_base    = 0x80090000;   /* system init entry */
     15
    1516seg_tty_base            = 0x90000000;   /* TTY device: for debug purpose! */
    1617
  • soft/giet_vm/boot/boot_handler.c

    r165 r167  
    3131// As most applications use only a limited number of segments, the number of PT2s
    3232// actually used by a given virtual space is generally smaller than 2048, and is
    33 // defined in the MAPPING_INFO_BINARY data structure (using the length field).
    34 // The value is calculated and put in _max_pt2 indexed by the vspace_id.
    35 // The physical alignment constraints, is ensured by the align flag in the MAPPING_INFO
    36 // structure.
     33// defined by the (GIET_NB_PT2_MAX) configuration parameter.
    3734// The max number of virtual spaces (GIET_NB_VSPACE_MAX) is a configuration parameter.
    3835//
    39 // Each page table (one page table per virtual space) is monolithic:
    40 // - a first 8K aligned PT1[2148] array, indexed by the (ix1) field of VPN.
     36// Each page table (one page table per virtual space) is monolithic, and
     37// contains one PT1 and (GIET_NB_PT2_MAX) PT2s. The PT1 is addressed using the ix1 field
     38// (11 bits) of the VPN, and the selected PT2 is addressed using the ix2 field (9 bits).
     39// - PT1[2048] : a first 8K aligned array of unsigned int, indexed by the (ix1) field of VPN.
     40//   Each entry in the PT1 contains a 32 bits PTD. The MSB bit PTD[31] is
     41//   the PTD valid bit, and LSB bits PTD[19:0] are the 20 MSB bits of the physical base
     42//   address of the selected PT2.
    4143//   The PT1 contains 2048 PTD of 4 bytes => 8K bytes.
    42 // - an aray of array PT2[1024][_max_pt2[vspace_id]], indexed by
    43 //   the (ix2) field of the VPN, and by the PT2 index (pt2_id).
    44 //   Each PT2 contains 512 PTE2 of 8bytes => 4Kbytes * _max_pt2[vspace_id]
    45 // The size of each page table is 8K + (_max_pt2[vspace_id])*4K bytes.
    46 // All page tables must be stored in the seg_kernel_pt segment (at address
    47 // seg_kernel_pt_base)
     44// - PT2[1024][GIET_NB_PT2_MAX] : an array of array of unsigned int.
     45//   Each PT2[1024] must be 4K aligned,  and each entry in a PT2 contains two unsigned int:
     46//   the first word contains the protection flags, and the second word contains the PPN.
     47//   Each PT2 contains 512 PTE2 of 8bytes => 4K bytes.
     48// The total size of a page table is finally = 8K + (GIET_NB_PT2_MAX)*4K bytes.
    4849////////////////////////////////////////////////////////////////////////////////////
    4950
     
    5556#include <stdarg.h>
    5657
    57 
    5858#if !defined(GIET_NB_VSPACE_MAX)
    5959# error The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file !
    6060#endif
    6161
     62#if !defined(GIET_NB_PT2_MAX)
     63# error The GIET_NB_PT2_MAX value must be defined in the 'giet_config.h' file !
     64#endif
     65
    6266////////////////////////////////////////////////////////////////////////////
    6367//  Page Tables global variables
     
    6670// Next free PT2 index array
    6771unsigned int  _next_free_pt2[GIET_NB_VSPACE_MAX] =
    68                          { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };
    69 
    70 // Max number of PT2 array
    71 unsigned int  _max_pt2[GIET_NB_VSPACE_MAX] =
    7272                         { [0 ... GIET_NB_VSPACE_MAX-1] = 0 };
    7373
     
    439439// allocation), this function checks a possible overflow of the PT2 array.
    440440//
    441 // The parametre global is a boolean taht indicate wether a global vseg is
     441// The global parameter is a boolean indicating wether a global vseg is
    442442// being mapped.
    443443//////////////////////////////////////////////////////////////////////////////
     
    445445                   unsigned int    vpn,           
    446446                   unsigned int    flags,
    447                    unsigned int    ppn,
    448                    unsigned char   global )
     447                   unsigned int    ppn )
    449448{
    450449    unsigned int    ix1;
     
    458457    ix2 = vpn  & 0x1FF;         //  9 bits
    459458
    460        
    461     unsigned int max_pt2   = _max_pt2[vspace_id];
    462     if(max_pt2 == 0)
    463     {
    464         boot_puts("Unfound page table for vspace ");
    465         boot_putw(vspace_id);
    466         boot_puts("\n");
    467         boot_exit();
    468     }
    469 
    470     page_table_t* pt    = (page_table_t *)_ptabs[vspace_id];
     459    page_table_t* pt = (page_table_t *)_ptabs[vspace_id];
    471460    if ( (pt->pt1[ix1] & PTE_V) == 0 )   // set a new PTD in PT1
    472461    {
    473462        pt2_id = _next_free_pt2[vspace_id];
    474         if ( pt2_id == max_pt2 )
     463        if ( pt2_id == GIET_NB_PT2_MAX )
    475464        {
    476465            boot_puts("\n[BOOT ERROR] in boot_add_pte() function\n");
     
    557546                          vpn,
    558547                          flags,
    559                           ppn,
    560                           0 );
     548                          ppn );
    561549            vpn++;
    562550            ppn++;
     
    593581                          vpn,
    594582                          flags,
    595                           ppn,
    596                           1 );
     583                          ppn );
    597584            vpn++;
    598585            ppn++;
     
    616603// This function compute the physical base address for a vseg
    617604// as specified in the mapping info data structure.
    618 // It updates the pbase field of the vseg.
    619 // It updates the page allocator (nextfreepage field of the pseg),
    620 // and checks a possible pseg overflow.
     605// It updates the pbase and the length fields of the vseg.
     606// It updates the pbase and vbase fields of all vobjs in the vseg.
     607// It updates the next_base field of the pseg.
     608// It checks a possible pseg overflow.
    621609// It is a global vseg if vspace_id = (-1)
    622610///////////////////////////////////////////////////////////////////////////
     
    641629    else                                // unconstrained mapping
    642630    {
    643         vseg->pbase = pseg->base + (pseg->next_free_page<<12);
     631        vseg->pbase = pseg->next_base;
     632
     633        // test alignment constraint
     634        if ( vobj[vseg->vobj_offset].align )
     635        {
     636            vseg->pbase = align_to( vseg->pbase, vobj[vseg->vobj_offset].align );
     637        }
    644638    }
    645639   
    646     // loop on vobjs to computes the length of the vseg,
    647     // initialise the vaddr and paddr fields of all vobjs,
    648     // and initialise the page table pointers array
     640    // loop on vobjs to (1) computes the length of the vseg,
     641    // (2) initialise the vaddr and paddr fields of all vobjs,
     642    // (3) initialise the page table pointers array
     643
    649644    cur_vaddr = vseg->vbase;
    650645    cur_paddr = vseg->pbase;
     
    659654        }
    660655
    661         // set vaddr/paddr
     656        // set vaddr/paddr for current vobj
    662657        vobj[vobj_id].vaddr = cur_vaddr;       
    663658        vobj[vobj_id].paddr = cur_paddr; 
     
    667662        cur_paddr += vobj[vobj_id].length;
    668663
    669         // initialise _ptabs[] and _max_pt2[]
     664        // initialise _ptabs[] if current vobj is a PTAB
    670665        if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB )
    671666        {
    672             if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE) ) // max_pt2 >= 1
     667            if(vobj[vobj_id].length < (PT1_SIZE + PT2_SIZE*GIET_NB_PT2_MAX) )
    673668            {
    674669                boot_puts( "\n[BOOT ERROR] in boot_vseg_map() function: " );
     
    684679                boot_exit();
    685680            }
    686             _ptabs[vspace_id]   = (page_table_t*)vobj[vobj_id].paddr;
    687             _max_pt2[vspace_id] = (vobj[vobj_id].length - PT1_SIZE) / PT2_SIZE;
    688         }
    689     }
     681            _ptabs[vspace_id] = (page_table_t*)vobj[vobj_id].paddr;
     682        }
     683    } // end for vobjs
    690684   
    691685    //set the vseg length
    692     unsigned int plength = pseg->length;
    693     unsigned int vlength = cur_paddr - vseg->pbase;
    694     vseg->length = align_to(vlength, 12);
     686    vseg->length = align_to( (cur_paddr - vseg->pbase), 12);
    695687
    696688    // checking pseg overflow
    697689    if ( (vseg->pbase < pseg->base) ||
    698          ((vseg->pbase + vlength) > (pseg->base + plength)) )
     690         ((vseg->pbase + vseg->length) > (pseg->base + pseg->length)) )
    699691    {
    700692        boot_puts("\n[BOOT ERROR] in boot_vseg_map() function\n");
    701         boot_puts("impossible identity mapping for virtual segment: ");
     693        boot_puts("impossible mapping for virtual segment: ");
    702694        boot_puts( vseg->name );
    703695        boot_puts("\n");
     
    717709    }
    718710
    719     // computes number of pages
    720     pages = vseg->length >> 12;
    721     if ( (vseg->length & 0xFFF) != 0 ) pages++;
    722 
    723     // set the next free physical address
    724     if ( vseg->ident != 0 )
    725             ;            // nothing to do
    726     else                               
    727         pseg->next_free_page = pseg->next_free_page + pages;
     711    // set the next_base field in vseg
     712    if ( vseg->ident == 0 )
     713        pseg->next_base = vseg->pbase + vseg->length;
    728714
    729715#if BOOT_DEBUG_PT
    730 boot_puts("- vseg ");
    731716boot_puts( vseg->name );
    732 boot_puts(" : vbase = ");
     717boot_puts(" : len = ");
     718boot_putw( vseg->length );
     719boot_puts(" / vbase = ");
    733720boot_putw( vseg->vbase );
    734721boot_puts(" / pbase = ");
     
    816803    for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ )
    817804    {
    818         pseg[pseg_id].next_free_page = 0;
     805        pseg[pseg_id].next_base = pseg[pseg_id].base;
    819806    }
    820807
     
    860847
    861848#if BOOT_DEBUG_PT
    862 boot_puts(">>> page table physical address = ");
    863 boot_putw((unsigned)_ptabs[vspace_id]);
     849boot_puts("\n>>> page table physical address = ");
     850boot_putw((unsigned int)_ptabs[vspace_id]);
    864851boot_puts("\n");
    865852#endif
  • soft/giet_vm/boot/boot_handler.h

    r160 r167  
    5353typedef struct PageTable
    5454{
    55         unsigned int    pt1[2048];                    // PT1 (index is ix1)
    56         unsigned int    pt2[GIET_NB_PT2_MAX][1024];   // PT2s (index is ix2)
     55        unsigned int    pt1[PT1_SIZE];                    // PT1 (index is ix1)
     56        unsigned int    pt2[GIET_NB_PT2_MAX][PT2_SIZE];   // PT2s (index is 2*ix2)
    5757} page_table_t;
    5858
  • soft/giet_vm/giet_config.h

    r166 r167  
    1414#define BOOT_DEBUG_VIEW         0           /* display the mapping_info on system TTY */
    1515#define BOOT_DEBUG_PT           0           /* display the page tables after mapping */
    16 #define INIT_DEBUG                      0           /* display the task contexts after mapping */
     16#define INIT_DEBUG_CTX          0           /* display the task contexts after mapping */
    1717#define GIET_DEBUG_SWITCH       0           /* Trace context switchs */
    1818
     
    2727#define NB_TIMERS                   4       /* number of timers per cluster */
    2828#define NB_DMAS                     1       /* total number of DMA channels */
    29 #define NB_TTYS                     7       /* total number of TTY terminals */
     29#define NB_TTYS                     8       /* total number of TTY terminals */
    3030
    3131/* software parameters */
    3232
    3333#define GIET_NB_TASKS_MAX       4           /* max number of tasks per processor */
    34 #define GIET_NB_VSPACE_MAX      3           /* max number of virtual spaces */
     34#define GIET_NB_VSPACE_MAX      4           /* max number of virtual spaces */
    3535#define GIET_NB_PT2_MAX         16          /* max number of level 2 page tables per vspace */
    36 #define GIET_TICK_VALUE     65536   /* context switch period (number of cycles) */
     36#define GIET_TICK_VALUE     16384   /* context switch period (number of cycles) */
    3737#define GIET_IOMMU_ACTIVE   0           /* The IOMMU vspace is defined */
    38 #define GIET_IOMMU_CHANNELS 1           /* number of 2Mbytes segments in IOMMU vspace */
     38
    3939#endif
    4040
  • soft/giet_vm/map.xml

    r165 r167  
    55                clusters = "1"
    66                psegs    = "9"
    7                 ttys     = "7"
     7                ttys     = "8"
    88                fbs      = "0"
    9                 vspaces  = "3"
     9                vspaces  = "4"
    1010                globals  = "13" >
    1111
     
    3030                <pseg    name   = "PSEG_TTY"
    3131                         base   = "0x90000000"
    32                          length = "0x00000200" />
     32                         length = "0x00001000" />
    3333
    3434                <pseg    name   = "PSEG_TIM"
    3535                         base   = "0x91000000"
    36                          length = "0x00000080" />
     36                         length = "0x00001000" />
    3737
    3838                <pseg    name   = "PSEG_IOC"
    3939                         base   = "0x92000000"
    40                          length = "0x00000020" />
     40                         length = "0x00001000" />
    4141
    4242                <pseg    name   = "PSEG_DMA"
    4343                         base   = "0x93000000"
    44                          length = "0x00000100" />
     44                         length = "0x00001000" />
    4545
    4646                <pseg    name   = "PSEG_FBF"
     
    5050                <pseg    name   = "PSEG_ICU"
    5151                         base   = "0x9F000000"
    52                          length = "0x00000100" />
     52                         length = "0x00001000" />
    5353        </psegset>
    5454
     
    105105                                        <vobj   name    = "seg_kernel_data"
    106106                                                        type    = "ELF"
    107                                                         length  = "0x00010000"
     107                                                        length  = "0x00040000"
    108108                                                        binpath = "build/sys.elf" />
    109109                                </vseg>
    110110
    111111                <vseg   name      = "seg_kernel_uncdata"
    112                         vbase     = "0x80020000"
     112                        vbase     = "0x80080000"
    113113                        mode      = "__W_"
    114114                        psegname  = "PSEG_RAK"
     
    121121
    122122                <vseg   name      = "seg_kernel_init"
    123                         vbase     = "0x80030000"
     123                        vbase     = "0x80090000"
    124124                        mode      = "CX__"
    125125                        psegname  = "PSEG_RAK"
     
    139139                                        <vobj   name    = "tty"
    140140                                                        type    = "PERI"
    141                                                         length  = "0x00000100" />
     141                                                        length  = "0x00001000" />
    142142                                </vseg>
    143143
     
    149149                                        <vobj   name    = "timer"
    150150                                                        type    = "PERI"
    151                                                         length  = "0x00000080" />
     151                                                        length  = "0x00001000" />
    152152                                </vseg>
    153153
     
    169169                                        <vobj   name    = "dma"
    170170                                                        type    = "PERI"
    171                                                         length  = "0x00000100" />
     171                                                        length  = "0x00001000" />
    172172                                </vseg>
    173173
     
    223223                                <vobj   name    = "ptab_router"
    224224                                        type    = "PTAB"
    225                                         length  = "0x00010000"
     225                                        length  = "0x00012000"
    226226                                        align   = "13" />
    227227                        </vseg>
     
    333333                                <vobj   name    = "ptab"
    334334                                        type    = "PTAB"
    335                                         length  = "0x00010000"
     335                                        length  = "0x00012000"
    336336                                        align   = "13" />
    337337                        </vseg>
     
    374374                                <vobj   name    = "ptab"
    375375                                        type    = "PTAB"
    376                                         length  = "0x00010000"
     376                                        length  = "0x00012000"
    377377                                        align   = "13" />
    378378                        </vseg>
     
    404404                                usetty    = "1" />
    405405                </vspace>
     406
     407                <vspace name      = "display"
     408                        startname = "seg_data_display" >
     409
     410                        <vseg   name      = "seg_data_display"
     411                                vbase     = "0x00800000"
     412                                mode      = "C_WU"
     413                                psegname  = "PSEG_RAU" >
     414                                                            <vobj   name        = "seg_data_display"
     415                                                                        type    = "ELF"
     416                                                                            length  = "0x00010000"
     417                                        binpath = "build/display.elf" />
     418                                                </vseg>
     419
     420                        <vseg   name      = "seg_ptab_display"
     421                                vbase     = "0x00300000"
     422                                mode      = "C___"
     423                                psegname  = "PSEG_RAU" >
     424                                <vobj   name    = "ptab"
     425                                        type    = "PTAB"
     426                                        length  = "0x00012000"
     427                                        align   = "13" />
     428                        </vseg>
     429
     430                        <vseg   name      = "seg_code_display"
     431                                vbase     = "0x00400000"
     432                                mode      = "CX_U"
     433                                psegname  = "PSEG_RAU" >
     434                                                            <vobj   name        = "seg_code_display"
     435                                                                        type    = "ELF"
     436                                                                            length  = "0x00010000"
     437                                        binpath = "build/display.elf" />
     438                                                </vseg>
     439
     440                        <vseg   name      = "seg_stack_display"
     441                                vbase     = "0x00000000"
     442                                mode      = "C_WU"
     443                                psegname  = "PSEG_RAU" >
     444                                                            <vobj   name        = "stack_display"
     445                                                                        type    = "BUFFER"
     446                                                                            length  = "0x00010000" />
     447                                                </vseg>
     448
     449                        <task   name      = "main_display"
     450                                clusterid = "0"
     451                                proclocid = "3"
     452                                stackname = "stack_display"
     453                                startid   = "0"
     454                                usetty    = "1" />
     455                </vspace>
     456
    406457          </vspaceset>
    407458</mapping_info>
  • soft/giet_vm/sys/ctx_handler.c

    r165 r167  
    1515// It contains copies of processor registers, when the task is not running,
    1616// and some general informations associated to the task.
     17//
    1718// - It contains GPR[i], generally stored in slot (i). $0, *26 & $27 are not saved.
    1819// - It contains HI & LO registers.
    1920// - It contains CP0 registers: EPC, SR, CR.
    2021// - It contains CP2 registers : PTPR and MODE.
    21 // - It contains the TTY index for the terminal allocated to the task.
    22 // ctx[0] <- SR   ctx[8] <- $8    ctx[16]<- $16   ctx[24]<- $24   ctx[32]<- EPC
    23 // ctx[1] <- $1   ctx[9] <- $9    ctx[17]<- $17   ctx[25]<- $25   ctx[33]<- CR
    24 // ctx[2] <- $2   ctx[10]<- $10   ctx[18]<- $18   ctx[26]<- LO    ctx[34]<- TTY
    25 // ctx[3] <- $3   ctx[11]<- $11   ctx[19]<- $19   ctx[27]<- HI    ctx[35]<- PTPR
    26 // ctx[4] <- $4   ctx[12]<- $12   ctx[20]<- $20   ctx[28]<- $28   ctx[36]<- MODE
    27 // ctx[5] <- $5   ctx[13]<- $13   ctx[21]<- $21   ctx[29]<- $29   ctx[37]<- FBDMA
    28 // ctx[6] <- $6   ctx[14]<- $14   ctx[22]<- $22   ctx[30]<- $30   ctx[38]<- reserved
    29 // ctx[7] <- $7   ctx[15]<- $15   ctx[23]<- $23   ctx[31]<- $31   ctx[39]<- reserved
     22// - It contains the TTY global index, the FBDMA global index, the virtual base
     23//   address of the page table (PTAB), and the task global index (TASK).
     24//
     25// ctx[0]<- SR|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC |ctx[40]<- TTY
     26// ctx[1]<- $1|ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR  |ctx[41]<- FBDMA
     27// ctx[2]<- $2|ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- *** |ctx[42]<- PTAB
     28// ctx[3]<- $3|ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- PTPR|ctx[43]<- TASK
     29// ctx[4]<- $4|ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- MODE|ctx[44]<- ***
     30// ctx[5]<- $5|ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- *** |ctx[45]<- ***
     31// ctx[6]<- $6|ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- *** |ctx[46]<- ***
     32// ctx[7]<- $7|ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- *** |ctx[47]<- ***
    3033/////////////////////////////////////////////////////////////////////////////////////
    3134
     
    4043
    4144/////////////////////////////////////////////////////////////////////////////////
    42 //      Global variables
     45//      Global variables : array of schedulers (one scheduler per processor)
    4346/////////////////////////////////////////////////////////////////////////////////
    4447
    45 static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS];
     48__attribute__((section (".kdata"))) static_scheduler_t _scheduler[NB_CLUSTERS * NB_PROCS];
    4649
    4750/////////////////////////////////////////////////////////////////////////////////
     
    6467    unsigned int *next_context;
    6568
    66     unsigned int pid   = _procid();
    67     unsigned int time  = _proctime();
    68     unsigned int tasks = _scheduler[pid].tasks;
     69    unsigned int proc_id   = _procid();
     70    unsigned int tasks     = _scheduler[proc_id].tasks;
    6971
    7072    // return if only one task  */
     
    7274 
    7375    // compute the task context base address for the current task
    74     curr_task_id = _scheduler[pid].current;
    75     curr_context = &(_scheduler[pid].context[curr_task_id][0]);
     76    curr_task_id = _scheduler[proc_id].current;
     77    curr_context = &(_scheduler[proc_id].context[curr_task_id][0]);
    7678   
    7779    // select the next task using a round-robin scheduling policy
     
    7981   
    8082    // compute the task context base address for the next task
    81     next_context = &(_scheduler[pid].context[next_task_id][0]);
     83    next_context = &(_scheduler[proc_id].context[next_task_id][0]);
    8284
    8385#if GIET_DEBUG_SWITCH
    8486_get_lock( &_tty_put_lock );
    8587_puts( "\n[GIET] Context switch for processor ");
    86 _putw( pid );
     88_putw( proc_id );
    8789_puts( " at cycle ");
    88 _putw( time );
     90_putw( _proctime() );
    8991_puts("\n");
    9092_puts( " - tasks        = ");
     
    101103
    102104    //  update the scheduler state, and makes the task switch
    103     _scheduler[pid].current = next_task_id;
     105    _scheduler[proc_id].current = next_task_id;
    104106    _task_switch( curr_context, next_context );
    105107
  • soft/giet_vm/sys/ctx_handler.h

    r165 r167  
    1515} static_scheduler_t;
    1616
     17/////////////////////////////////////////////////////////////////////////////////
     18//      Definition of the task context slots indexes
     19/////////////////////////////////////////////////////////////////////////////////
     20
     21#define CTX_SR_ID               0
     22#define CTX_SP_ID               29
     23#define CTX_RA_ID               31
     24
     25#define CTX_EPC_ID              32
     26#define CTX_CR_ID               33
     27#define CTX_PTPR_ID             35
     28#define CTX_MODE_ID             36
     29
     30#define CTX_TTY_ID              40
     31#define CTX_FBDMA_ID    41
     32#define CTX_PTAB_ID             42
     33#define CTX_TASK_ID             43
     34
     35
    1736//////////////////////////////////////////////////////////////////////////////////
    1837//      Prototype of the context switch function
  • soft/giet_vm/sys/drivers.c

    r166 r167  
    491491                          unsigned int  count )
    492492{
    493     unsigned int        user_vpn_min;
    494     unsigned int        user_vpn_max;
    495     unsigned int        vpn;                    // virtual page number in user space
    496     unsigned int        ppn;                    // physical page number
    497     unsigned int        flags;                  // page protection flags
    498     unsigned int        ix2;                    // Page index (for IOMMU page table)
    499     unsigned int        addr;                   // buffer address for IOC
    500     page_table_t*       user_ptp;               // user page table pointer
    501     unsigned int        ko;                             // bool returned by _v2p_translate()
    502     unsigned int        ppn_first;              // first physical page number for user buffer
     493    unsigned int                user_vpn_min;   // first virtuel page index in user space
     494    unsigned int                user_vpn_max;   // last virtual page index in user space
     495    unsigned int                vpn;                    // current virtual page index in user space
     496    unsigned int                ppn;                    // physical page number
     497    unsigned int                flags;                  // page protection flags
     498    unsigned int                ix2;                    // page index in IOMMU PT1 page table
     499    unsigned int                addr;                   // buffer address for IOC peripheral
     500    unsigned int                user_ptp;               // page table pointer in user space
     501    unsigned int                ko;                             // bool returned by _v2p_translate()
     502    unsigned int                ppn_first;              // first physical page number for user buffer
     503    unsigned int                ltid;                   // current task local index
     504    static_scheduler_t* psched;                 // pointer on the current task scheduler
    503505       
    504506    // check buffer alignment
     
    509511    unsigned int        length       = count*block_size;
    510512
    511     // get user space page table base address
    512     user_ptp     = (page_table_t*)(_get_ptpr() << 13);
     513    // get user space page table virtual address
     514    psched   = &_scheduler[_procid()];
     515    ltid     = psched->current;
     516    user_ptp = psched->context[ltid][CTX_PTAB_ID];
    513517   
    514518    user_vpn_min = user_vaddr >> 12;
     
    520524    {
    521525        // get ppn and flags for each vpn
    522         ko = _v2p_translate( user_ptp,  // user page table pointer
    523                              vpn,               // virtual page number
    524                              &ppn,              // physical page number
    525                              &flags );  // protection flags
     526        ko = _v2p_translate( (page_table_t*)user_ptp,
     527                             vpn,
     528                             &ppn,
     529                             &flags );
    526530
    527531        // check access rights
     
    543547                                                 ppn,                           // Physical page number
    544548                             flags );                   // Protection flags
    545 
    546             // buffer base address for IOC with IOMMU
    547549        }
    548550        else                    // no IOMMU : check that physical pages are contiguous
     
    563565    // compute buffer base address for IOC depending on IOMMU activation
    564566    if ( GIET_IOMMU_ACTIVE ) addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF);
    565     else                     addr = ppn_first | (user_vaddr & 0xFFF);
     567    else                     addr = (ppn_first << 12) | (user_vaddr & 0xFFF);
    566568
    567569    // get the lock on ioc device
  • soft/giet_vm/sys/irq_handler.c

    r165 r167  
    2323///////////////////////////////////////////////////////////////////////////////////
    2424
    25 _isr_func_t _interrupt_vector[32] = { [0 ... 31] = &_isr_default };
     25__attribute__((section (".kdata"))) _isr_func_t _interrupt_vector[32] =
     26                                                  { [0 ... 31] = &_isr_default };
    2627
    2728///////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/sys/kernel_init.c

    r166 r167  
    3131 
    3232///////////////////////////////////////////////////////////////////////////////////
     33// array of pointers on the page tables
     34// (both physical and virtual addresses)
     35///////////////////////////////////////////////////////////////////////////////////
     36
     37__attribute__((section (".kdata"))) unsigned int _kernel_ptabs_paddr[GIET_NB_VSPACE_MAX];
     38__attribute__((section (".kdata"))) unsigned int _kernel_ptabs_vaddr[GIET_NB_VSPACE_MAX];
     39
     40///////////////////////////////////////////////////////////////////////////////////
    3341// declarations required to avoid forward references
    3442///////////////////////////////////////////////////////////////////////////////////
    3543
    36 void    _kernel_vobjs_init(unsigned int*);
    37 void    _kernel_tasks_init(unsigned int*);
     44void    _kernel_vobjs_init(void);
     45void    _kernel_tasks_init(void);
    3846void    _kernel_peripherals_init(void);
    3947void    _kernel_interrupt_vector_init(void);
     
    4553in_kinit void _kernel_init()
    4654{
    47     // array of pointers on the page tables (used for task context initialisation)
    48     unsigned int        kernel_ptabs[GIET_NB_VSPACE_MAX];
    49 
    5055    // values to be written in registers
    5156    unsigned int        sp_value;
     
    5964    if ( pid == 0 )
    6065    {
    61         _kernel_vobjs_init(kernel_ptabs);
    62         _kernel_tasks_init(kernel_ptabs);
     66        _kernel_vobjs_init();
     67        _kernel_tasks_init();
    6368        _kernel_interrupt_vector_init();
    6469        _kernel_peripherals_init();
     
    163168// - ptpr   page table base address / 8K
    164169// - mode   mmu_mode = 0xF (TLBs and caches activated)
     170// - ptab   page table virtual address
    165171////////////////////////////////////////////////////////////////////////////////
    166172in_kinit void _task_map( unsigned int   task_id,    // global index
    167173                                         unsigned int   vspace_id,  // global index
    168174                         unsigned int   tty_id,         // TTY index
    169                          unsigned int   fb_id,          // FB index
    170                          unsigned int   pt_base )   // page table base adddress
     175                         unsigned int   fbdma_id )  // FBDMA index
    171176{
    172177    mapping_header_t*   header = (mapping_header_t*)&seg_mapping_base; 
     
    176181    mapping_vobj_t*     vobj   = _get_vobj_base( header );
    177182
     183   
    178184    // values to be initialised in task context
    179     unsigned int                ra = (unsigned int)&_eret;
     185    unsigned int                ra   = (unsigned int)&_eret;
    180186    unsigned int                sr   = 0x0000FF13;
    181187    unsigned int                tty  = tty_id;
    182     unsigned int                fb   = fb_id;   
    183     unsigned int                ptpr = pt_base >> 13;
     188    unsigned int                fb   = fbdma_id;         
     189    unsigned int                ptpr = _kernel_ptabs_paddr[vspace_id] >> 13;
     190    unsigned int                ptab = _kernel_ptabs_vaddr[vspace_id];
    184191    unsigned int                mode = 0xF;
    185192    unsigned int                sp;
    186193    unsigned int                epc;     
    187194
    188     // compute epc value
    189     // Get the (virtual) base address of the start_vector that
    190     // contains the start addresses for all tasks defined in a vspace.
     195    // EPC : Get the (virtual) base address of the start_vector containing
     196    // the start addresses for all tasks defined in a vspace.
    191197    mapping_vobj_t* vobj_data = &vobj[vspace[vspace_id].vobj_offset +
    192198                                      vspace[vspace_id].start_offset];
     
    194200    epc  = start_vector[task[task_id].startid];
    195201
    196     // compute sp value
    197     // Get the vobj containing the stack
     202    // SP :  Get the vobj containing the stack
    198203    unsigned int vobj_id = task[task_id].vobjlocid + vspace[vspace_id].vobj_offset;
    199204    sp = vobj[vobj_id].vaddr + vobj[vobj_id].length;
     
    220225    _scheduler[proc_id].context[ltid][CTX_RA_ID]    = ra;
    221226    _scheduler[proc_id].context[ltid][CTX_EPC_ID]   = epc;
     227    _scheduler[proc_id].context[ltid][CTX_PTPR_ID]  = ptpr;
     228    _scheduler[proc_id].context[ltid][CTX_MODE_ID]  = mode;
    222229    _scheduler[proc_id].context[ltid][CTX_TTY_ID]   = tty;
    223230        _scheduler[proc_id].context[ltid][CTX_FBDMA_ID] = fb;
    224     _scheduler[proc_id].context[ltid][CTX_PTPR_ID]  = ptpr;
    225     _scheduler[proc_id].context[ltid][CTX_MODE_ID]  = mode;
     231    _scheduler[proc_id].context[ltid][CTX_PTAB_ID]  = ptab;
    226232    _scheduler[proc_id].context[ltid][CTX_TASK_ID]  = task_id;
    227233   
    228 #if INIT_DEBUG
     234#if INIT_DEBUG_CTX
    229235_puts("Task ");
    230236_puts( task[task_id].name );
     
    259265_puts("\n");
    260266
     267_puts("  - PTPR        = ");
     268_putw( ptpr<<13 );
     269_puts("  saved at ");
     270_putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTPR_ID] );
     271_puts("\n");
     272
    261273_puts("  - TTY         = ");
    262274_putw( tty );
     
    271283_puts("\n");
    272284
    273 _puts("  - PTPR        = ");
    274 _putw( ptpr<<13 );
    275 _puts("  saved at ");
    276 _putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTPR_ID] );
     285_puts("  - PTAB        = ");
     286_putw( ptab );
     287_puts("  saved at ");
     288_putw( (unsigned int)&_scheduler[proc_id].context[ltid][CTX_PTAB_ID] );
    277289_puts("\n");
    278290#endif
     
    284296// such as mwmr channels, barriers and locks, depending on the vobj type.
    285297// (Most of the vobjs are not known, and not initialised by the compiler).
    286 // This function initialises the kernel_ptabs[] array indexed by the vspace_id,
    287 // and containint the base addresses of all page tables.
    288 // This kernel_ptabs[] array is used to initialise the task contexts.
     298// This function initialises the _kernel_ptabs_paddr[] array indexed by the vspace_id,
     299// and containing the base addresses of all page tables.
     300// This _kernel_ptabs_paddr[] array is used to initialise the task contexts.
    289301///////////////////////////////////////////////////////////////////////////////
    290 in_kinit void _kernel_vobjs_init( unsigned int* kernel_ptabs )
     302in_kinit void _kernel_vobjs_init()
    291303{
    292304    mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base; 
     
    302314        char ptab_found = 0;
    303315
    304 #if INIT_DEBUG
     316#if INIT_DEBUG_CTX
    305317_puts("[INIT] --- vobjs initialisation in vspace ");
    306318_puts(vspace[vspace_id].name);
     
    317329                {
    318330                    ptab_found = 1;
    319                     kernel_ptabs[vspace_id] = vobj[vobj_id].paddr;
    320 
    321 #if INIT_DEBUG
     331                    _kernel_ptabs_paddr[vspace_id] = vobj[vobj_id].paddr;
     332                    _kernel_ptabs_vaddr[vspace_id] = vobj[vobj_id].vaddr;
     333
     334#if INIT_DEBUG_CTX
    322335_puts("[INIT]   PTAB address = ");
    323 _putw(kernel_ptabs[vspace_id]);
     336_putw(_kernel_ptabs_paddr[vspace_id]);
    324337_puts("\n");
    325338#endif
     
    334347                    mwmr->depth = (vobj[vobj_id].length>>2) - 5;
    335348                    mwmr->lock  = 0;
    336 #if INIT_DEBUG
     349#if INIT_DEBUG_CTX
    337350_puts("[INIT]   MWMR channel ");
    338351_puts( vobj->name);
     
    346359                {
    347360
    348 #if INIT_DEBUG
     361#if INIT_DEBUG_CTX
    349362_puts("[INIT]   ELF section ");
    350363_puts( vobj->name);
     
    360373                    barrier->count = 0;
    361374                    barrier->init  = vobj[vobj_id].init;
    362 #if INIT_DEBUG
     375#if INIT_DEBUG_CTX
    363376_puts("   BARRIER ");
    364377_puts( vobj->name);
     
    373386                    unsigned int* lock = (unsigned int*)(vobj[vobj_id].vaddr);
    374387                    *lock = 0;
    375 #if INIT_DEBUG
     388#if INIT_DEBUG_CTX
    376389_puts("   LOCK ");
    377390_puts( vobj->name);
     
    383396                {
    384397
    385 #if INIT_DEBUG
     398#if INIT_DEBUG_CTX
    386399_puts("   BUFFER ");
    387400_puts( vobj->name);
     
    425438// TTY[0] is reserved for the kernel.
    426439///////////////////////////////////////////////////////////////////////////////
    427 in_kinit void _kernel_tasks_init(unsigned int* ptabs)
     440in_kinit void _kernel_tasks_init()
    428441{
    429442    mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base; 
     
    461474    {
    462475
    463 #if INIT_DEBUG
     476#if INIT_DEBUG_CTX
    464477_puts("\n[INIT] mapping tasks in vspace ");
    465478_puts(vspace[vspace_id].name);
     
    486499                       vspace_id,                       // vspace index
    487500                       tty_id,                          // global tty index
    488                        fb_id,                           // global fbdma index
    489                        ptabs[vspace_id] );      // page table pointer
     501                       fb_id );                         // global fbdma index
    490502        } // end loop on tasks
    491503    } // end oop on vspaces
     
    495507    _puts("\n");
    496508
    497 #if INIT_DEBUG
     509#if INIT_DEBUG_CTX
    498510for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ )
    499511{
     
    540552    {
    541553        unsigned int*   iob_address = (unsigned int*)&seg_iob_base;
    542         unsigned int    icu_address = (unsigned int)&seg_icu_base;
    543554
    544555        // define IPI address mapping the IOC interrupt ...TODO...
  • soft/giet_vm/sys/mips32_registers.h

    r165 r167  
    7878#define CP2_DCACHE_INVAL_PA     $20
    7979
    80 /* Context index */
    81 
    82 #define CTX_SR_ID               0
    83 #define CTX_SP_ID               29
    84 #define CTX_RA_ID               31
    85 #define CTX_EPC_ID              32
    86 #define CTX_TTY_ID              34
    87 #define CTX_PTPR_ID             35
    88 #define CTX_MODE_ID             36
    89 #define CTX_FBDMA_ID    37
    90 #define CTX_TASK_ID             63
    91 
    92 
    9380#endif
  • soft/giet_vm/sys/sys.ld

    r166 r167  
    33*****************************************************************************/
    44
    5 /* The vsegs used by the system are replicated in all virtual spaces
     5/* The vsegs used by the system are mapped in all virtual spaces
    66   They can be identity mapping... or not */
    77
    88seg_kernel_code_base    = 0x80000000;   /* system code */
    99seg_kernel_data_base    = 0x80010000;   /* system cacheable data */
    10 seg_kernel_uncdata_base = 0x80020000;   /* system uncacheable data */
    11 seg_kernel_init_base    = 0x80030000;   /* system page table */
     10seg_kernel_uncdata_base = 0x80080000;   /* system uncacheable data */
     11seg_kernel_init_base    = 0x80090000;   /* system page table */
    1212seg_mapping_base            = 0xBFC0C000;       /* boot mapping_info */
    1313
     
    1616   must be defined, even if the peripherals are not used in the architecture */
    1717
    18 seg_tty_base            = 0x90000000;   /* TTY device */
    19 seg_timer_base          = 0x91000000;   /* Timer device */
    20 seg_ioc_base            = 0x92000000;   /* Block device */
    21 seg_dma_base            = 0x93000000;   /* DMA device */
    22 seg_gcd_base            = 0x95000000;   /* GCD device */
    23 seg_fb_base             = 0x96000000;   /* FrameBuffer device */
    24 seg_icu_base            = 0x9F000000;   /* ICU or XICU device */
    25 seg_iob_base            = 0x9E000000;   /* IOB device */
     18seg_tty_base                = 0x90000000;   /* TTY device */
     19seg_timer_base              = 0x91000000;   /* Timer device */
     20seg_ioc_base                = 0x92000000;   /* Block device */
     21seg_dma_base                = 0x93000000;   /* DMA device */
     22seg_gcd_base                = 0x95000000;   /* GCD device */
     23seg_fb_base                 = 0x96000000;   /* FrameBuffer device */
     24seg_iob_base                = 0x9E000000;   /* IOB device */
     25seg_icu_base                = 0x9F000000;   /* ICU or XICU device */
    2626
    2727/*
     
    4040    seg_kernel_data :
    4141    {
     42        *(.iommu)
     43        *(.kdata)
    4244        *(.rodata)
    43         /* . = ALIGN(4); */
    4445        *(.rodata.*)
    45         /* . = ALIGN(4); */
    4646        *(.data)
    47         /* . = ALIGN(4); */
    4847        *(.lit8)
    4948        *(.lit4)
    5049        *(.sdata)
    51         /* . = ALIGN(4); */
    5250        *(.bss)
    5351        *(COMMON)
  • soft/giet_vm/sys/sys_handler.c

    r165 r167  
    7575void _exit()
    7676{
     77    unsigned int date    = _proctime();
    7778    unsigned int proc_id = _procid();
    7879    unsigned int task_id = _scheduler[proc_id].current;
     
    8384    _puts(" on processor ");
    8485    _putw( proc_id );
     86    _puts(" at cycle ");
     87    _putw( date );
    8588    _puts("\n\n");
    8689
  • soft/giet_vm/xml/mapping_info.h

    r165 r167  
    9595        unsigned int    base;           // base address in physical space
    9696        unsigned int    length;         // size (bytes)
    97     unsigned int    next_free_page; // physical page allocator
     97    unsigned int    next_base;      // first free page base address
    9898} mapping_pseg_t;
    9999
  • soft/giet_vm/xml/xml_parser.c

    r165 r167  
    802802    }
    803803
    804     pseg[pseg_index]->next_free_page = 0;
    805804    pseg_index++;
    806805} // end psegNode()
Note: See TracChangeset for help on using the changeset viewer.