Ignore:
Timestamp:
Jul 4, 2017, 10:17:44 AM (7 years ago)
Author:
max@…
Message:

improve the APIC implementation

File:
1 edited

Legend:

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

    r135 r137  
    132132#define IOAPICVER       0x01
    133133#define IOAPICARB       0x02
     134
    134135#define IOREDTBL        0x10
     136#       define IOREDTBL_DEL_FIXED       0x000
     137#       define IOREDTBL_DEL_LOPRI       0x100
     138#       define IOREDTBL_DEL_SMI         0x200
     139#       define IOREDTBL_DEL_NMI         0x400
     140#       define IOREDTBL_DEL_INIT        0x500
     141#       define IOREDTBL_DEL_EXTINT      0x700
     142#       define IOREDTBL_DEM_PHYS        0x000
     143#       define IOREDTBL_DEM_LOGIC       0x800
     144#       define IOREDTBL_DES_SHIFT       56
     145#       define IOREDTBL_MSK             0x10000
    135146
    136147void hal_ioapic_write(uint8_t reg, uint32_t val)
     
    146157}
    147158
    148 void hal_ioapic_set_entry(uint8_t index, uint64_t data)
    149 {
     159void hal_ioapic_disable_entry(uint8_t index)
     160{
     161        const uint64_t data = IOREDTBL_MSK;
     162
    150163        hal_ioapic_write(IOREDTBL + index * 2, (uint32_t)(data & 0xFFFFFFFF));
    151164        hal_ioapic_write(IOREDTBL + index * 2 + 1, (uint32_t)(data >> 32));
    152165}
    153166
     167void hal_ioapic_set_entry(uint8_t index, uint8_t vec, uint8_t dest)
     168{
     169        const uint64_t data = ((uint64_t)dest << IOREDTBL_DES_SHIFT) |
     170            IOREDTBL_DEM_PHYS | IOREDTBL_DEL_FIXED | vec;
     171
     172        hal_ioapic_write(IOREDTBL + index * 2, (uint32_t)(data & 0xFFFFFFFF));
     173        hal_ioapic_write(IOREDTBL + index * 2 + 1, (uint32_t)(data >> 32));
     174}
     175
    154176static void hal_ioapic_init()
    155177{
     
    166188        /* Explicitly disable (mask) each vector */
    167189        for (i = 0; i < ioapic_pins; i++) {
    168                 hal_ioapic_set_entry(i, IOENTRY_DISABLE);
     190                hal_ioapic_disable_entry(i);
    169191        }
    170192
     
    172194
    173195        /* Now, enable the keyboard */
    174         hal_ioapic_set_entry(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR);
     196        hal_ioapic_set_entry(IRQ_KEYBOARD, IOAPIC_KEYBOARD_VECTOR, 0);
    175197}
    176198
Note: See TracChangeset for help on using the changeset viewer.