Changeset da1bafb in mainline for kernel/arch/ia32/src


Ignore:
Timestamp:
2010-05-24T18:57:31Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
Location:
kernel/arch/ia32/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/ddi/ddi.c

    r666f492 rda1bafb  
    5050 * Interrupts are disabled and task is locked.
    5151 *
    52  * @param task Task.
     52 * @param task   Task.
    5353 * @param ioaddr Startign I/O space address.
    54  * @param size Size of the enabled I/O range.
     54 * @param size   Size of the enabled I/O range.
    5555 *
    5656 * @return 0 on success or an error code from errno.h.
     57 *
    5758 */
    5859int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    5960{
    60         size_t bits;
    61 
    62         bits = ioaddr + size;
     61        size_t bits = ioaddr + size;
    6362        if (bits > IO_PORTS)
    6463                return ENOENT;
    65 
     64       
    6665        if (task->arch.iomap.bits < bits) {
    67                 bitmap_t oldiomap;
    68                 uint8_t *newmap;
    69        
    7066                /*
    7167                 * The I/O permission bitmap is too small and needs to be grown.
    7268                 */
    7369               
    74                 newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     70                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    7571                if (!newmap)
    7672                        return ENOMEM;
    7773               
     74                bitmap_t oldiomap;
    7875                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7976                    task->arch.iomap.bits);
    8077                bitmap_initialize(&task->arch.iomap, newmap, bits);
    81 
     78               
    8279                /*
    8380                 * Mark the new range inaccessible.
     
    8582                bitmap_set_range(&task->arch.iomap, oldiomap.bits,
    8683                    bits - oldiomap.bits);
    87 
     84               
    8885                /*
    8986                 * In case there really existed smaller iomap,
    9087                 * copy its contents and deallocate it.
    91                  */             
     88                 */
    9289                if (oldiomap.bits) {
    9390                        bitmap_copy(&task->arch.iomap, &oldiomap,
     
    9693                }
    9794        }
    98 
     95       
    9996        /*
    10097         * Enable the range and we are done.
    10198         */
    10299        bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, (size_t) size);
    103 
     100       
    104101        /*
    105102         * Increment I/O Permission bitmap generation counter.
    106103         */
    107104        task->arch.iomapver++;
    108 
     105       
    109106        return 0;
    110107}
     
    116113 *
    117114 * Interrupts must be disabled prior this call.
     115 *
    118116 */
    119117void io_perm_bitmap_install(void)
    120118{
    121         size_t bits;
    122         ptr_16_32_t cpugdtr;
    123         descriptor_t *gdt_p;
    124         size_t ver;
    125 
    126119        /* First, copy the I/O Permission Bitmap. */
    127         spinlock_lock(&TASK->lock);
    128         ver = TASK->arch.iomapver;
    129         if ((bits = TASK->arch.iomap.bits)) {
     120        irq_spinlock_lock(&TASK->lock, false);
     121        size_t ver = TASK->arch.iomapver;
     122        size_t bits = TASK->arch.iomap.bits;
     123        if (bits) {
     124                ASSERT(TASK->arch.iomap.map);
     125               
    130126                bitmap_t iomap;
    131                 task_t *task = TASK;
    132        
    133                 ASSERT(TASK->arch.iomap.map);
    134127                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    135128                    TSS_IOMAP_SIZE * 8);
    136                 bitmap_copy(&iomap, &task->arch.iomap, task->arch.iomap.bits);
     129                bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     130               
    137131                /*
    138132                 * It is safe to set the trailing eight bits because of the
     
    141135                bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
    142136        }
    143         spinlock_unlock(&TASK->lock);
    144 
     137        irq_spinlock_unlock(&TASK->lock, false);
     138       
    145139        /*
    146140         * Second, adjust TSS segment limit.
    147141         * Take the extra ending byte with all bits set into account.
    148142         */
     143        ptr_16_32_t cpugdtr;
    149144        gdtr_store(&cpugdtr);
    150         gdt_p = (descriptor_t *) cpugdtr.base;
     145       
     146        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    151147        gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    152148        gdtr_load(&cpugdtr);
    153 
     149       
    154150        /*
    155151         * Before we load new TSS limit, the current TSS descriptor
  • kernel/arch/ia32/src/drivers/i8254.c

    r666f492 rda1bafb  
    5454#include <ddi/device.h>
    5555
    56 #define CLK_PORT1       ((ioport8_t *)0x40)
    57 #define CLK_PORT4       ((ioport8_t *)0x43)
     56#define CLK_PORT1  ((ioport8_t *) 0x40)
     57#define CLK_PORT4  ((ioport8_t *) 0x43)
    5858
    59 #define CLK_CONST       1193180
    60 #define MAGIC_NUMBER    1194
     59#define CLK_CONST     1193180
     60#define MAGIC_NUMBER  1194
     61
     62#define LOOPS  150000
     63#define SHIFT  11
    6164
    6265static irq_t i8254_irq;
     
    7578         * lock. We just release it, call clock() and then reacquire it again.
    7679         */
    77         spinlock_unlock(&irq->lock);
     80        irq_spinlock_unlock(&irq->lock, false);
    7881        clock();
    79         spinlock_lock(&irq->lock);
     82        irq_spinlock_lock(&irq->lock, false);
    8083}
    8184
     
    102105}
    103106
    104 #define LOOPS 150000
    105 #define SHIFT 11
    106107void i8254_calibrate_delay_loop(void)
    107108{
    108         uint64_t clk1, clk2;
    109         uint32_t t1, t2, o1, o2;
    110         uint8_t not_ok;
    111 
    112 
    113109        /*
    114110         * One-shot timer. Count-down from 0xffff at 1193180Hz
     
    118114        pio_write_8(CLK_PORT1, 0xff);
    119115        pio_write_8(CLK_PORT1, 0xff);
    120 
     116       
     117        uint8_t not_ok;
     118        uint32_t t1;
     119        uint32_t t2;
     120       
    121121        do {
    122122                /* will read both status and count */
     
    126126                t1 |= pio_read_8(CLK_PORT1) << 8;
    127127        } while (not_ok);
    128 
     128       
    129129        asm_delay_loop(LOOPS);
    130 
     130       
    131131        pio_write_8(CLK_PORT4, 0xd2);
    132132        t2 = pio_read_8(CLK_PORT1);
    133133        t2 |= pio_read_8(CLK_PORT1) << 8;
    134 
     134       
    135135        /*
    136136         * We want to determine the overhead of the calibrating mechanism.
    137137         */
    138138        pio_write_8(CLK_PORT4, 0xd2);
    139         o1 = pio_read_8(CLK_PORT1);
     139        uint32_t o1 = pio_read_8(CLK_PORT1);
    140140        o1 |= pio_read_8(CLK_PORT1) << 8;
    141 
     141       
    142142        asm_fake_loop(LOOPS);
    143 
     143       
    144144        pio_write_8(CLK_PORT4, 0xd2);
    145         o2 = pio_read_8(CLK_PORT1);
     145        uint32_t o2 = pio_read_8(CLK_PORT1);
    146146        o2 |= pio_read_8(CLK_PORT1) << 8;
    147 
     147       
    148148        CPU->delay_loop_const =
    149149            ((MAGIC_NUMBER * LOOPS) / 1000) / ((t1 - t2) - (o1 - o2)) +
    150150            (((MAGIC_NUMBER * LOOPS) / 1000) % ((t1 - t2) - (o1 - o2)) ? 1 : 0);
    151 
    152         clk1 = get_cycle();
     151       
     152        uint64_t clk1 = get_cycle();
    153153        delay(1 << SHIFT);
    154         clk2 = get_cycle();
     154        uint64_t clk2 = get_cycle();
    155155       
    156156        CPU->frequency_mhz = (clk2 - clk1) >> SHIFT;
    157 
     157       
    158158        return;
    159159}
  • kernel/arch/ia32/src/interrupt.c

    r666f492 rda1bafb  
    9494{
    9595        fault_if_from_uspace(istate, "Unserviced interrupt: %d.", n);
    96 
     96       
    9797        decode_istate(istate);
    9898        panic("Unserviced interrupt: %d.", n);
     
    102102{
    103103        fault_if_from_uspace(istate, "Divide error.");
    104 
     104       
    105105        decode_istate(istate);
    106106        panic("Divide error.");
     
    111111{
    112112        if (TASK) {
    113                 size_t ver;
     113                irq_spinlock_lock(&TASK->lock, false);
     114                size_t ver = TASK->arch.iomapver;
     115                irq_spinlock_unlock(&TASK->lock, false);
    114116               
    115                 spinlock_lock(&TASK->lock);
    116                 ver = TASK->arch.iomapver;
    117                 spinlock_unlock(&TASK->lock);
    118        
    119117                if (CPU->arch.iomapver_copy != ver) {
    120118                        /*
     
    130128                fault_if_from_uspace(istate, "General protection fault.");
    131129        }
    132 
     130       
    133131        decode_istate(istate);
    134132        panic("General protection fault.");
     
    138136{
    139137        fault_if_from_uspace(istate, "Stack fault.");
    140 
     138       
    141139        decode_istate(istate);
    142140        panic("Stack fault.");
     
    146144{
    147145        uint32_t mxcsr;
    148         asm (
     146        asm volatile (
    149147                "stmxcsr %[mxcsr]\n"
    150148                : [mxcsr] "=m" (mxcsr)
    151149        );
     150       
    152151        fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zx.",
    153152            (unative_t) mxcsr);
     
    158157}
    159158
    160 static void nm_fault(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
    161 {
    162 #ifdef CONFIG_FPU_LAZY     
     159static void nm_fault(int n __attribute__((unused)),
     160    istate_t *istate __attribute__((unused)))
     161{
     162#ifdef CONFIG_FPU_LAZY
    163163        scheduler_fpu_lazy_request();
    164164#else
     
    169169
    170170#ifdef CONFIG_SMP
    171 static void tlb_shootdown_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
     171static void tlb_shootdown_ipi(int n __attribute__((unused)),
     172    istate_t *istate __attribute__((unused)))
    172173{
    173174        trap_virtual_eoi();
     
    191192                 * The IRQ handler was found.
    192193                 */
    193                  
     194               
    194195                if (irq->preack) {
    195196                        /* Send EOI before processing the interrupt */
     
    198199                }
    199200                irq->handler(irq);
    200                 spinlock_unlock(&irq->lock);
     201                irq_spinlock_unlock(&irq->lock, false);
    201202        } else {
    202203                /*
  • kernel/arch/ia32/src/smp/apic.c

    r666f492 rda1bafb  
    5353 * Advanced Programmable Interrupt Controller for SMP systems.
    5454 * Tested on:
    55  *      Bochs 2.0.2 - Bochs 2.2.6 with 2-8 CPUs
    56  *      Simics 2.0.28 - Simics 2.2.19 2-15 CPUs
    57  *      VMware Workstation 5.5 with 2 CPUs
    58  *      QEMU 0.8.0 with 2-15 CPUs
    59  *      ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
    60  *      ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs
    61  *      MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs
     55 *    Bochs 2.0.2 - Bochs 2.2.6 with 2-8 CPUs
     56 *    Simics 2.0.28 - Simics 2.2.19 2-15 CPUs
     57 *    VMware Workstation 5.5 with 2 CPUs
     58 *    QEMU 0.8.0 with 2-15 CPUs
     59 *    ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
     60 *    ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs
     61 *    MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs
     62 *
    6263 */
    6364
     
    6970 * optimize the code too much and accesses to l_apic and io_apic, that must
    7071 * always be 32-bit, would use byte oriented instructions.
     72 *
    7173 */
    7274volatile uint32_t *l_apic = (uint32_t *) 0xfee00000;
     
    7981
    8082#ifdef LAPIC_VERBOSE
    81 static char *delmod_str[] = {
     83static const char *delmod_str[] = {
    8284        "Fixed",
    8385        "Lowest Priority",
     
    9092};
    9193
    92 static char *destmod_str[] = {
     94static const char *destmod_str[] = {
    9395        "Physical",
    9496        "Logical"
    9597};
    9698
    97 static char *trigmod_str[] = {
     99static const char *trigmod_str[] = {
    98100        "Edge",
    99101        "Level"
    100102};
    101103
    102 static char *mask_str[] = {
     104static const char *mask_str[] = {
    103105        "Unmasked",
    104106        "Masked"
    105107};
    106108
    107 static char *delivs_str[] = {
     109static const char *delivs_str[] = {
    108110        "Idle",
    109111        "Send Pending"
    110112};
    111113
    112 static char *tm_mode_str[] = {
     114static const char *tm_mode_str[] = {
    113115        "One-shot",
    114116        "Periodic"
    115117};
    116118
    117 static char *intpol_str[] = {
     119static const char *intpol_str[] = {
    118120        "Polarity High",
    119121        "Polarity Low"
     
    123125/** APIC spurious interrupt handler.
    124126 *
    125  * @param n Interrupt vector.
     127 * @param n      Interrupt vector.
    126128 * @param istate Interrupted state.
    127  */
    128 static void apic_spurious(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
     129 *
     130 */
     131static void apic_spurious(int n __attribute__((unused)),
     132    istate_t *istate __attribute__((unused)))
    129133{
    130134#ifdef CONFIG_DEBUG
     
    145149         * irq->lock so we just unlock it and then lock it again.
    146150         */
    147         spinlock_unlock(&irq->lock);
     151        irq_spinlock_unlock(&irq->lock, false);
    148152        clock();
    149         spinlock_lock(&irq->lock);
     153        irq_spinlock_lock(&irq->lock, false);
    150154}
    151155
     
    153157void apic_init(void)
    154158{
    155         io_apic_id_t idreg;
    156        
    157159        exc_register(VECTOR_APIC_SPUR, "apic_spurious", (iroutine) apic_spurious);
    158 
     160       
    159161        enable_irqs_function = io_apic_enable_irqs;
    160162        disable_irqs_function = io_apic_disable_irqs;
     
    179181        for (i = 0; i < IRQ_COUNT; i++) {
    180182                int pin;
    181        
     183               
    182184                if ((pin = smp_irq_to_pin(i)) != -1)
    183185                        io_apic_change_ioredtbl((uint8_t) pin, DEST_ALL, (uint8_t) (IVT_IRQBASE + i), LOPRI);
     
    187189         * Ensure that io_apic has unique ID.
    188190         */
     191        io_apic_id_t idreg;
     192       
    189193        idreg.value = io_apic_read(IOAPICID);
    190         if ((1 << idreg.apic_id) & apic_id_mask) {      /* see if IO APIC ID is used already */
     194        if ((1 << idreg.apic_id) & apic_id_mask) {  /* See if IO APIC ID is used already */
    191195                for (i = 0; i < APIC_ID_COUNT; i++) {
    192196                        if (!((1 << i) & apic_id_mask)) {
     
    197201                }
    198202        }
    199 
     203       
    200204        /*
    201205         * Configure the BSP's lapic.
    202206         */
    203207        l_apic_init();
    204 
    205         l_apic_debug();
     208        l_apic_debug();
    206209}
    207210
     
    211214 *
    212215 * @return 0 on error, 1 on success.
     216 *
    213217 */
    214218int apic_poll_errors(void)
     
    232236        if (esr.illegal_register_address)
    233237                printf("Illegal Register Address\n");
    234 
     238       
    235239        return !esr.err_bitmap;
    236240}
     
    241245 *
    242246 * @return 0 on failure, 1 on success.
     247 *
    243248 */
    244249int l_apic_broadcast_custom_ipi(uint8_t vector)
    245250{
    246251        icr_t icr;
    247 
     252       
    248253        icr.lo = l_apic[ICRlo];
    249254        icr.delmod = DELMOD_FIXED;
     
    253258        icr.trigger_mode = TRIGMOD_LEVEL;
    254259        icr.vector = vector;
    255 
     260       
    256261        l_apic[ICRlo] = icr.lo;
    257 
     262       
    258263        icr.lo = l_apic[ICRlo];
    259264        if (icr.delivs == DELIVS_PENDING) {
     
    262267#endif
    263268        }
    264 
     269       
    265270        return apic_poll_errors();
    266271}
     
    271276 *
    272277 * @return 0 on failure, 1 on success.
     278 *
    273279 */
    274280int l_apic_send_init_ipi(uint8_t apicid)
    275281{
     282        /*
     283         * Read the ICR register in and zero all non-reserved fields.
     284         */
    276285        icr_t icr;
    277         int i;
    278 
    279         /*
    280          * Read the ICR register in and zero all non-reserved fields.
    281          */
     286       
    282287        icr.lo = l_apic[ICRlo];
    283288        icr.hi = l_apic[ICRhi];
     
    293298        l_apic[ICRhi] = icr.hi;
    294299        l_apic[ICRlo] = icr.lo;
    295 
     300       
    296301        /*
    297302         * According to MP Specification, 20us should be enough to
     
    299304         */
    300305        delay(20);
    301 
     306       
    302307        if (!apic_poll_errors())
    303308                return 0;
    304 
     309       
    305310        icr.lo = l_apic[ICRlo];
    306311        if (icr.delivs == DELIVS_PENDING) {
     
    309314#endif
    310315        }
    311 
     316       
    312317        icr.delmod = DELMOD_INIT;
    313318        icr.destmod = DESTMOD_PHYS;
     
    317322        icr.vector = 0;
    318323        l_apic[ICRlo] = icr.lo;
    319 
     324       
    320325        /*
    321326         * Wait 10ms as MP Specification specifies.
    322327         */
    323328        delay(10000);
    324 
     329       
    325330        if (!is_82489DX_apic(l_apic[LAVR])) {
    326331                /*
    327332                 * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
    328333                 */
    329                 for (i = 0; i<2; i++) {
     334                unsigned int i;
     335                for (i = 0; i < 2; i++) {
    330336                        icr.lo = l_apic[ICRlo];
    331337                        icr.vector = (uint8_t) (((uintptr_t) ap_boot) >> 12); /* calculate the reset vector */
     
    346352void l_apic_init(void)
    347353{
     354        /* Initialize LVT Error register. */
    348355        lvt_error_t error;
    349         lvt_lint_t lint;
    350         tpr_t tpr;
    351         svr_t svr;
    352         icr_t icr;
    353         tdcr_t tdcr;
    354         lvt_tm_t tm;
    355         ldr_t ldr;
    356         dfr_t dfr;
    357         uint32_t t1, t2;
    358 
    359         /* Initialize LVT Error register. */
     356       
    360357        error.value = l_apic[LVT_Err];
    361358        error.masked = true;
    362359        l_apic[LVT_Err] = error.value;
    363 
     360       
    364361        /* Initialize LVT LINT0 register. */
     362        lvt_lint_t lint;
     363       
    365364        lint.value = l_apic[LVT_LINT0];
    366365        lint.masked = true;
    367366        l_apic[LVT_LINT0] = lint.value;
    368 
     367       
    369368        /* Initialize LVT LINT1 register. */
    370369        lint.value = l_apic[LVT_LINT1];
    371370        lint.masked = true;
    372371        l_apic[LVT_LINT1] = lint.value;
    373 
     372       
    374373        /* Task Priority Register initialization. */
     374        tpr_t tpr;
     375       
    375376        tpr.value = l_apic[TPR];
    376377        tpr.pri_sc = 0;
     
    379380       
    380381        /* Spurious-Interrupt Vector Register initialization. */
     382        svr_t svr;
     383       
    381384        svr.value = l_apic[SVR];
    382385        svr.vector = VECTOR_APIC_SPUR;
     
    384387        svr.focus_checking = true;
    385388        l_apic[SVR] = svr.value;
    386 
     389       
    387390        if (CPU->arch.family >= 6)
    388391                enable_l_apic_in_msr();
    389392       
    390393        /* Interrupt Command Register initialization. */
     394        icr_t icr;
     395       
    391396        icr.lo = l_apic[ICRlo];
    392397        icr.delmod = DELMOD_INIT;
     
    398403       
    399404        /* Timer Divide Configuration Register initialization. */
     405        tdcr_t tdcr;
     406       
    400407        tdcr.value = l_apic[TDCR];
    401408        tdcr.div_value = DIVIDE_1;
    402409        l_apic[TDCR] = tdcr.value;
    403 
     410       
    404411        /* Program local timer. */
     412        lvt_tm_t tm;
     413       
    405414        tm.value = l_apic[LVT_Tm];
    406415        tm.vector = VECTOR_CLK;
     
    408417        tm.masked = false;
    409418        l_apic[LVT_Tm] = tm.value;
    410 
     419       
    411420        /*
    412421         * Measure and configure the timer to generate timer
    413422         * interrupt with period 1s/HZ seconds.
    414423         */
     424        uint32_t t1 = l_apic[CCRT];
     425        l_apic[ICRT] = 0xffffffff;
     426       
     427        while (l_apic[CCRT] == t1);
     428       
    415429        t1 = l_apic[CCRT];
    416         l_apic[ICRT] = 0xffffffff;
    417 
    418         while (l_apic[CCRT] == t1)
    419                 ;
    420                
    421         t1 = l_apic[CCRT];
    422         delay(1000000/HZ);
    423         t2 = l_apic[CCRT];
    424        
    425         l_apic[ICRT] = t1-t2;
     430        delay(1000000 / HZ);
     431        uint32_t t2 = l_apic[CCRT];
     432       
     433        l_apic[ICRT] = t1 - t2;
    426434       
    427435        /* Program Logical Destination Register. */
    428436        ASSERT(CPU->id < 8);
     437        ldr_t ldr;
     438       
    429439        ldr.value = l_apic[LDR];
    430440        ldr.id = (uint8_t) (1 << CPU->id);
     
    432442       
    433443        /* Program Destination Format Register for Flat mode. */
     444        dfr_t dfr;
     445       
    434446        dfr.value = l_apic[DFR];
    435447        dfr.model = MODEL_FLAT;
     
    447459{
    448460#ifdef LAPIC_VERBOSE
     461        printf("LVT on cpu%" PRIs ", LAPIC ID: %" PRIu8 "\n", CPU->id, l_apic_id());
     462       
    449463        lvt_tm_t tm;
    450         lvt_lint_t lint;
    451         lvt_error_t error;     
    452        
    453         printf("LVT on cpu%d, LAPIC ID: %d\n", CPU->id, l_apic_id());
    454 
    455464        tm.value = l_apic[LVT_Tm];
    456465        printf("LVT Tm: vector=%hhd, %s, %s, %s\n", tm.vector, delivs_str[tm.delivs], mask_str[tm.masked], tm_mode_str[tm.mode]);
     466       
     467        lvt_lint_t lint;
    457468        lint.value = l_apic[LVT_LINT0];
    458469        printf("LVT LINT0: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]);
    459470        lint.value = l_apic[LVT_LINT1];
    460471        printf("LVT LINT1: vector=%hhd, %s, %s, %s, irr=%d, %s, %s\n", tm.vector, delmod_str[lint.delmod], delivs_str[lint.delivs], intpol_str[lint.intpol], lint.irr, trigmod_str[lint.trigger_mode], mask_str[lint.masked]); 
     472       
     473        lvt_error_t error;
    461474        error.value = l_apic[LVT_Err];
    462475        printf("LVT Err: vector=%hhd, %s, %s\n", error.vector, delivs_str[error.delivs], mask_str[error.masked]);
     
    467480 *
    468481 * @return Local APIC ID.
     482 *
    469483 */
    470484uint8_t l_apic_id(void)
     
    481495 *
    482496 * @return Content of the addressed IO APIC register.
     497 *
    483498 */
    484499uint32_t io_apic_read(uint8_t address)
     
    495510 *
    496511 * @param address IO APIC register address.
    497  * @param x Content to be written to the addressed IO APIC register.
    498  */
    499 void io_apic_write(uint8_t address, uint32_t x)
     512 * @param val     Content to be written to the addressed IO APIC register.
     513 *
     514 */
     515void io_apic_write(uint8_t address, uint32_t val)
    500516{
    501517        io_regsel_t regsel;
     
    504520        regsel.reg_addr = address;
    505521        io_apic[IOREGSEL] = regsel.value;
    506         io_apic[IOWIN] = x;
     522        io_apic[IOWIN] = val;
    507523}
    508524
    509525/** Change some attributes of one item in I/O Redirection Table.
    510526 *
    511  * @param pin IO APIC pin number.
    512  * @param dest Interrupt destination address.
    513  * @param v Interrupt vector to trigger.
     527 * @param pin   IO APIC pin number.
     528 * @param dest  Interrupt destination address.
     529 * @param vec  Interrupt vector to trigger.
    514530 * @param flags Flags.
    515  */
    516 void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t v, int flags)
    517 {
    518         io_redirection_reg_t reg;
    519         int dlvr = DELMOD_FIXED;
     531 *
     532 */
     533void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t vec,
     534    unsigned int flags)
     535{
     536        unsigned int dlvr;
    520537       
    521538        if (flags & LOPRI)
    522539                dlvr = DELMOD_LOWPRI;
    523 
     540        else
     541                dlvr = DELMOD_FIXED;
     542       
     543        io_redirection_reg_t reg;
    524544        reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
    525545        reg.hi = io_apic_read((uint8_t) (IOREDTBL + pin * 2 + 1));
     
    530550        reg.intpol = POLARITY_HIGH;
    531551        reg.delmod = dlvr;
    532         reg.intvec = v;
    533 
     552        reg.intvec = vec;
     553       
    534554        io_apic_write((uint8_t) (IOREDTBL + pin * 2), reg.lo);
    535555        io_apic_write((uint8_t) (IOREDTBL + pin * 2 + 1), reg.hi);
     
    539559 *
    540560 * @param irqmask Bitmask of IRQs to be masked (0 = do not mask, 1 = mask).
     561 *
    541562 */
    542563void io_apic_disable_irqs(uint16_t irqmask)
    543564{
    544         io_redirection_reg_t reg;
    545565        unsigned int i;
    546         int pin;
    547        
    548566        for (i = 0; i < 16; i++) {
    549567                if (irqmask & (1 << i)) {
     
    552570                         * mapping for the respective IRQ number.
    553571                         */
    554                         pin = smp_irq_to_pin(i);
     572                        int pin = smp_irq_to_pin(i);
    555573                        if (pin != -1) {
     574                                io_redirection_reg_t reg;
     575                               
    556576                                reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
    557577                                reg.masked = true;
     
    566586 *
    567587 * @param irqmask Bitmask of IRQs to be unmasked (0 = do not unmask, 1 = unmask).
     588 *
    568589 */
    569590void io_apic_enable_irqs(uint16_t irqmask)
    570591{
    571592        unsigned int i;
    572         int pin;
    573         io_redirection_reg_t reg;       
    574        
    575593        for (i = 0; i < 16; i++) {
    576594                if (irqmask & (1 << i)) {
     
    579597                         * mapping for the respective IRQ number.
    580598                         */
    581                         pin = smp_irq_to_pin(i);
     599                        int pin = smp_irq_to_pin(i);
    582600                        if (pin != -1) {
     601                                io_redirection_reg_t reg;
     602                               
    583603                                reg.lo = io_apic_read((uint8_t) (IOREDTBL + pin * 2));
    584604                                reg.masked = false;
Note: See TracChangeset for help on using the changeset viewer.