Changeset 16 for trunk/kernel/kern


Ignore:
Timestamp:
May 10, 2017, 5:04:01 PM (7 years ago)
Author:
alain
Message:

mprove the HAL for interrupt, exception, syscall handling.

Location:
trunk/kernel/kern
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/chdev.c

    r14 r16  
    2525#include <hal_types.h>
    2626#include <hal_special.h>
     27#include <printk.h>
    2728#include <boot_info.h>
    2829#include <xlist.h>
     
    4748        else if( func_type == DEV_FUNC_ICU ) return "ICU";
    4849        else if( func_type == DEV_FUNC_PIC ) return "PIC";
    49     else                                 return "UNDEFINED";
     50    else                                 return "undefined";
    5051}
    5152
  • trunk/kernel/kern/chdev.h

    r14 r16  
    222222 ******************************************************************************************
    223223 * @ func_type  : functionnal type.
    224  * @ return a printable string.
     224 * @ return pointer on string.
    225225 *****************************************************************************************/
    226226char * chdev_func_str( uint32_t func_type );
  • trunk/kernel/kern/core.h

    r14 r16  
    148148
    149149/***************************************************************************************
    150  * This function and reset the usage statistics.
     150 * This function reset the usage statistics.
    151151 ***************************************************************************************
    152152 * @ core       : pointer on core descriptor.
  • trunk/kernel/kern/do_interrupt.c

    r5 r16  
    11/*
    2  * kern/do_interrupt.c - kernel unified interrupt entry-point
     2 * do_interrupt.c - architecture independant interrupt handler.
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     4 * Author        Alain Greiner (2016)
    65 *
    7  * This file is part of ALMOS-kernel.
     6 * Copyright (c) UPMC Sorbonne Universites
    87 *
    9  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     8 * This file is part of ALMOS-MKH.
     9 *
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * You should have received a copy of the GNU General Public License
    19  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
    2223
    23 #include <cpu.h>
    24 #include <task.h>
     24#include <hal_types.h>
     25#include <kernel_config.h>
    2526#include <thread.h>
    26 #include <cpu-trace.h>
    27 #include <chdev.h>
    28 #include <system.h>
    29 #include <signal.h>
     27#include <dev_icu.h>
    3028
    31 #define irq_cpu_dmsg(c,...)                             \
    32         do{                                             \
    33                 if(cpu_get_id() == (c))                 \
    34                         isr_dmsg(INFO, __VA_ARGS__);    \
    35         }while(0)
    3629
    37 void do_interrupt(struct thread_s *this, uint_t irq_num)
     30////////////////////////////////////
     31void do_interrupt( thread_t * this )
    3832{
    39         register thread_state_t old_state;
    40         struct irq_action_s *action;
    41         struct cpu_s *cpu;
    42         uint_t irq_state;
    43         error_t ret;
     33        // update user time     
     34        thread_user_time_update( this );
    4435
    45         cpu_trace_write(thread_current_cpu(this), do_interrupt);
     36    // access ICU device to call the relevant ISR
     37    dev_icu_irq_handler();
     38           
     39    // handle pending signals for interrupted thread
     40    thread_signals_handle( this );
    4641
    47         cpu = thread_current_cpu(this);
    48 
    49         cpu->irq_nr ++;
    50         old_state = this->state;
    51 
    52         if(old_state == S_USR)
    53         {
    54                 this->state = S_KERNEL;
    55                 tm_usr_compute(this);
    56         }
    57 
    58         arch_cpu_get_irq_entry(cpu, irq_num, &action);
    59         action->irq_handler(action);
    60            
    61         cpu_yield();
    62 
    63         if(old_state != S_USR)//and not a kernel thread ?
    64                 return;
    65 
    66         /* it is safe to migrate as we are going to user *
    67          * space.                                        */
    68         if(thread_migration_isActivated(this))
    69         {
    70                 thread_clear_cap_migrate(this);
    71                 cpu_enable_all_irq(&irq_state);
    72                 ret = thread_migrate(this,-1);
    73                 cpu_restore_irq(irq_state);
    74 
    75                 /* this pointer has expired */
    76                 this = CURRENT_THREAD;
    77                 cpu_wbflush();
    78 
    79                 if(ret == 0)   
    80                         thread_migration_deactivate(this);
    81                 else
    82                 {
    83                         isr_dmsg(INFO,
    84                         "%s: cpu %d, migration failed for victim pid %d, tid %d, err %d\n",
    85                          __FUNCTION__,
    86                          cpu_get_id(),
    87                          this->task->pid,
    88                          this->info.order,
    89                          ret);
    90                 }
    91         }
    92        
    93         tm_sys_compute(this);
    94         this->state = S_USR;
    95         signal_notify(this);
     42        // update kernel time
     43        thread_kernel_time_update( this );
    9644}
  • trunk/kernel/kern/printk.h

    r5 r16  
    213213#endif
    214214
     215#if CONFIG_SYSCALL_DEBUG
     216#define syscall_dmsg(...)   printk(__VA_ARGS__)
     217#else
     218#define syscall_dmsg(...)
     219#endif
     220
    215221#if CONFIG_THREAD_DEBUG
    216222#define thread_dmsg(...)   printk(__VA_ARGS__)
  • trunk/kernel/kern/rpc.c

    r14 r16  
    745745
    746746/////////////////////////////////////////////////////////////////////////////////////////
    747 //               Marshaling functions attached to RPC_VMM_GET_VSEG
     747//               Marshaling functions attached to RPC_VMM_GET_REF_VSEG
    748748/////////////////////////////////////////////////////////////////////////////////////////
    749749
     
    797797
    798798    // set output argument to client RPC descriptor
    799     vseg_xp = XPTR( local_cxy , vseg_ptr );
     799    if( vseg_ptr == NULL ) vseg_xp = XPTR_NULL;
     800    else                   vseg_xp = XPTR( local_cxy , vseg_ptr );
    800801    hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)vseg_xp );
    801802}
  • trunk/kernel/kern/rpc.h

    r14 r16  
    371371 * on the vseg containing a given virtual address in a given process.
    372372 * The server cluster is supposed to be the reference cluster.
    373  * It returns NULL if no vseg has been founded.
     373 * It returns XPTR_NULL if no vseg has been founded.
    374374 ***********************************************************************************
    375375 * @ cxy     : server cluster identifier.
    376376 * @ process : [in]   pointer on process descriptor in server cluster.
    377377 * @ vaddr   : [in]   virtual address to be searched.
    378  * @ vseg    : [out]  address of buffer for vseg pointer in client cluster.
     378 * @ vseg_xp : [out]  buffer for extended pointer on vseg in client cluster.
    379379 **********************************************************************************/
    380380void rpc_vmm_get_ref_vseg_client( cxy_t              cxy,
  • trunk/kernel/kern/signal.h

    r5 r16  
    9292        uid_t    si_uid;      /*! Real user ID of sending process */
    9393        int      si_status;   /*! Exit value or signal */
    94         clock_t  si_utime;    /*! User time consumed */
    95         clock_t  si_stime;    /*! System time consumed */
     94        cycle_t  si_utime;    /*! User time consumed */
     95        cycle_t  si_stime;    /*! System time consumed */
    9696        sigval_t si_value;    /*! Signal value */
    9797        int      si_int;      /*! POSIX.1b signal */
  • trunk/kernel/kern/thread.c

    r14 r16  
    5151
    5252//////////////////////////////////////////////////////////////////////////////////////
    53 //   global variables for display / must be consistant with enum in "thread.h"
    54 //////////////////////////////////////////////////////////////////////////////////////
    55 
    56 const char* thread_type_name[THREAD_TYPES_NR] =
    57 {
    58         "USER",
    59         "RPC"
    60         "KERNEL",
    61         "IDLE",
    62 };
    63 
    64 //////////////////////////////////////////////////////////////////////////////////////
    65 // This static function returns a printable string for the thread type.
     53// This function returns a printable string for the thread type.
    6654//////////////////////////////////////////////////////////////////////////////////////
    6755char * thread_type_str( uint32_t type )
    6856{
    69     if     ( type == THREAD_USER   ) return "THREAD_USER";
    70     else if( type == THREAD_RPC    ) return "THREAD_RPC";
    71     else if( type == THREAD_DEV    ) return "THREAD_DEV";
    72     else if( type == THREAD_KERNEL ) return "THREAD_KERNEL";
    73     else if( type == THREAD_IDLE   ) return "THREAD_IDLE";
     57    if     ( type == THREAD_USER   ) return "USER";
     58    else if( type == THREAD_RPC    ) return "RPC";
     59    else if( type == THREAD_DEV    ) return "DEV";
     60    else if( type == THREAD_KERNEL ) return "KERNEL";
     61    else if( type == THREAD_IDLE   ) return "IDLE";
    7462    else                             return "undefined";
    7563}
     
    703691}  // end thread_idle()
    704692
    705 
     693/////////////////////////////////////////////////
     694void thread_user_time_update( thread_t * thread )
     695{
     696    // TODO
     697    printk("\n[WARNING] function %s not implemented\n", __FUNCTION__ );
     698}
     699
     700///////////////////////////////////////////////////
     701void thread_kernel_time_update( thread_t * thread )
     702{
     703    // TODO
     704    printk("\n[WARNING] function %s not implemented\n", __FUNCTION__ );
     705}
     706
     707////////////////////////////////////////////////
     708void thread_signals_handler( thread_t * thread )
     709{
     710    // TODO
     711    printk("\n[WARNING] function %s not implemented\n", __FUNCTION__ );
     712}
     713
     714
  • trunk/kernel/kern/thread.h

    r14 r16  
    128128        uint32_t              tm_born;       /*! date of the thread loading               */
    129129        uint32_t              tm_dead;       /*! date of the death                        */
    130         clock_t               tm_sleep;      /*! TODO ???  [AG]                           */
    131         clock_t               tm_wait;       /*! TODO ???  [AG]                           */
    132         clock_t               tm_usr;        /*! user execution duration                  */
    133         clock_t               tm_sys;        /*! system execution duration                */
     130        cycle_t               tm_sleep;      /*! TODO ???  [AG]                           */
     131        cycle_t               tm_wait;       /*! TODO ???  [AG]                           */
     132        cycle_t               tm_usr;        /*! user execution duration                  */
     133        cycle_t               tm_sys;        /*! system execution duration                */
    134134}
    135135thread_info_t;
     
    151151typedef struct thread_s
    152152{
     153    void              * cpu_uzone;       /*! used for exception/interrupt/syscall     */
     154        void              * cpu_context;     /*! used for context switch                  */
     155        void              * fpu_context;     /*! used for dynamic FPU allocation          */
     156
    153157        uint32_t            trdid;           /*! thread index (in THTBL)                  */
    154158        thread_type_t       type;            /*! thread type                              */
     
    177181    uint32_t            signals;         /*! bit vector of signals                    */
    178182
    179         error_t             errno;           /*! errno value of last system call          */
     183        error_t             errno;           /*! errno value set by last system call      */
    180184
    181185    bool_t              fork_user;       /*! user defined placement for next fork()   */
     
    205209    xlist_entry_t       wait_list;       /*! member of threads blocked on same cond   */
    206210
    207         void              * fpu_context;     /*! pointer on FPU context                   */
    208         void              * cpu_context;     /*! pointer on CPU context                   */
    209 
    210211        thread_info_t       info;            /*! embedded thread_info_t                   */
    211212
     
    219220
    220221#define CURRENT_THREAD  (hal_get_current_thread())
     222
     223/***************************************************************************************
     224 * This function returns a printable string for a thread type.
     225 ***************************************************************************************
     226 * @ type    : thread type.
     227 * returns pointer on string.
     228 **************************************************************************************/
     229char * thread_type_str( uint32_t type );
    221230
    222231/***************************************************************************************
     
    438447void thread_kill( thread_t * thread );
    439448
     449/***************************************************************************************
     450 * This function updates the calling thread user_time counter, and reset the thread
     451 * cycles counter.
     452 * TODO This function is not implemented.
     453 ***************************************************************************************
     454 * @ thread   : local pointer on target thread.
     455 **************************************************************************************/
     456void thread_user_time_update( thread_t * thread );
     457
     458/**************************************************************************************n
     459 * This function updates the calling thread kernel_time counter, and reset the thread
     460 * cycles counter.
     461 * TODO This function is not implemented.
     462 ***************************************************************************************
     463 * @ thread   : local pointer on target thread.
     464 **************************************************************************************/
     465void thread_kernel_time_update( thread_t * thread );
     466
     467/***************************************************************************************
     468 * This function handle all pending signals for the thread identified by the <thread>
     469 * argument. It is called each time the core exit the kernel, after handling an
     470 * interrupt, exception or syscall.
     471 * TODO This function is not implemented.
     472 ***************************************************************************************
     473 * @ thread   : local pointer on target thread.
     474 **************************************************************************************/
     475void thread_signals_handle( thread_t * thread );
     476
     477
     478
    440479#endif  /* _THREAD_H_ */
Note: See TracChangeset for help on using the changeset viewer.