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

mprove the HAL for interrupt, exception, syscall handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.