Changeset 122 for trunk/hal/x86_64


Ignore:
Timestamp:
Jul 3, 2017, 2:20:52 PM (7 years ago)
Author:
max@…
Message:

we will fix nested interrupt contexts later

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/core/hal_irqmask.c

    r118 r122  
    2323#include <hal_internal.h>
    2424
    25 static int interrupts_enabled __in_kdata = 0;
     25#define INTRS_ENABLED   0xFFEFAAAA
     26#define INTRS_DISABLED  0xD0CCCCC0
     27
     28static uint32_t intrs_state __in_kdata = INTRS_DISABLED;
    2629
    2730inline void hal_disable_irq(uint32_t *old)
    2831{
    29         if (!interrupts_enabled) {
    30                 x86_panic("nested critical sections forbidden");
    31         }
    32         interrupts_enabled = 0;
     32        *old = intrs_state;
     33        intrs_state = INTRS_DISABLED;
    3334        cli();
    3435}
     
    3637inline void hal_enable_irq(uint32_t *old)
    3738{
    38         if (interrupts_enabled) {
    39                 x86_panic("nested critical sections forbidden");
    40         }
    41         interrupts_enabled = 1;
     39        *old = intrs_state;
     40        intrs_state = INTRS_ENABLED;
    4241        sti();
    4342}
     
    4544inline void hal_restore_irq(uint32_t old)
    4645{
    47         if (interrupts_enabled)
    48                 hal_disable_irq(&old);
     46        intrs_state = old;
     47
     48        if (intrs_state == INTRS_ENABLED)
     49                sti();
     50        else if(intrs_state == INTRS_DISABLED)
     51                cli();
    4952        else
    50                 hal_enable_irq(&old);
     53                x86_panic("hal_restore_irq: not reachable");
    5154}
    5255
Note: See TracChangeset for help on using the changeset viewer.