Ignore:
File:
1 edited

Legend:

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

    r9d58539 r7de18418  
    5959int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    6060{
    61         size_t bits = ioaddr + size;
    62         if (bits > IO_PORTS)
     61        size_t elements = ioaddr + size;
     62        if (elements > IO_PORTS)
    6363                return ENOENT;
    6464       
    65         if (task->arch.iomap.bits < bits) {
     65        if (task->arch.iomap.elements < elements) {
    6666                /*
    6767                 * The I/O permission bitmap is too small and needs to be grown.
    6868                 */
    6969               
    70                 uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    71                 if (!newmap)
     70                void *store = malloc(bitmap_size(elements, 0), FRAME_ATOMIC);
     71                if (!store)
    7272                        return ENOMEM;
    7373               
    7474                bitmap_t oldiomap;
    75                 bitmap_initialize(&oldiomap, task->arch.iomap.map,
     75                bitmap_initialize(&oldiomap, task->arch.iomap.elements, 0,
    7676                    task->arch.iomap.bits);
    77                 bitmap_initialize(&task->arch.iomap, newmap, bits);
     77               
     78                bitmap_initialize(&task->arch.iomap, elements, 0, store);
    7879               
    7980                /*
    8081                 * Mark the new range inaccessible.
    8182                 */
    82                 bitmap_set_range(&task->arch.iomap, oldiomap.bits,
    83                     bits - oldiomap.bits);
     83                bitmap_set_range(&task->arch.iomap, oldiomap.elements,
     84                    elements - oldiomap.elements);
    8485               
    8586                /*
     
    8990                if (oldiomap.bits) {
    9091                        bitmap_copy(&task->arch.iomap, &oldiomap,
    91                             oldiomap.bits);
    92                         free(oldiomap.map);
     92                            oldiomap.elements);
     93                       
     94                        free(oldiomap.bits);
    9395                }
    9496        }
     
    9799         * Enable the range and we are done.
    98100         */
    99         bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, (size_t) size);
     101        bitmap_clear_range(&task->arch.iomap, (size_t) ioaddr, size);
    100102       
    101103        /*
     
    119121        /* First, copy the I/O Permission Bitmap. */
    120122        irq_spinlock_lock(&TASK->lock, false);
     123       
    121124        size_t ver = TASK->arch.iomapver;
    122         size_t bits = TASK->arch.iomap.bits;
    123         if (bits) {
    124                 ASSERT(TASK->arch.iomap.map);
     125        size_t elements = TASK->arch.iomap.elements;
     126       
     127        if (elements > 0) {
     128                ASSERT(TASK->arch.iomap.bits);
    125129               
    126130                bitmap_t iomap;
    127                 bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    128                     TSS_IOMAP_SIZE * 8);
    129                 bitmap_copy(&iomap, &TASK->arch.iomap, bits);
     131                bitmap_initialize(&iomap, TSS_IOMAP_SIZE * 8, 0,
     132                    CPU->arch.tss->iomap);
     133                bitmap_copy(&iomap, &TASK->arch.iomap, elements);
    130134               
    131135                /*
     
    133137                 * I/O access.
    134138                 */
    135                 bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
     139                bitmap_set_range(&iomap, elements,
     140                    ALIGN_UP(elements, 8) - elements);
     141               
    136142                /*
    137143                 * It is safe to set the trailing eight bits because of the
    138144                 * extra convenience byte in TSS_IOMAP_SIZE.
    139145                 */
    140                 bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
     146                bitmap_set_range(&iomap, ALIGN_UP(elements, 8), 8);
    141147        }
     148       
    142149        irq_spinlock_unlock(&TASK->lock, false);
    143150       
     
    150157       
    151158        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    152         gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
     159        size_t size = bitmap_size(elements, 0);
     160        gdt_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + size);
    153161        gdtr_load(&cpugdtr);
    154162       
Note: See TracChangeset for help on using the changeset viewer.