Changeset da1bafb in mainline for kernel/arch


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
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/debugger.h

    r666f492 rda1bafb  
    3838#include <typedefs.h>
    3939
    40 #define BKPOINTS_MAX 4
     40#define BKPOINTS_MAX  4
    4141
    4242/* Flags that are passed to breakpoint_add function */
    43 #define BKPOINT_INSTR        0x1
    44 #define BKPOINT_WRITE        0x2
    45 #define BKPOINT_READ_WRITE   0x4
     43#define BKPOINT_INSTR       0x1
     44#define BKPOINT_WRITE       0x2
     45#define BKPOINT_READ_WRITE  0x4
    4646
    47 #define BKPOINT_CHECK_ZERO   0x8
     47#define BKPOINT_CHECK_ZERO  0x8
    4848
    4949
    5050extern void debugger_init(void);
    51 extern int breakpoint_add(const void *where, const int flags, int curidx);
    52 extern void breakpoint_del(int slot);
     51extern int breakpoint_add(const void *, const unsigned int, int);
     52extern void breakpoint_del(int);
    5353
    5454#endif
  • kernel/arch/amd64/src/ddi/ddi.c

    r666f492 rda1bafb  
    4949 * Interrupts are disabled and task is locked.
    5050 *
    51  * @param task Task.
     51 * @param task   Task.
    5252 * @param ioaddr Startign I/O space address.
    53  * @param size Size of the enabled I/O range.
     53 * @param size   Size of the enabled I/O range.
    5454 *
    5555 * @return 0 on success or an error code from errno.h.
     56 *
    5657 */
    5758int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    5859{
    59         size_t bits;
    60        
    61         bits = ioaddr + size;
     60        size_t bits = ioaddr + size;
    6261        if (bits > IO_PORTS)
    6362                return ENOENT;
    6463       
    6564        if (task->arch.iomap.bits < bits) {
    66                 bitmap_t oldiomap;
    67                 uint8_t *newmap;
    68                
    6965                /*
    7066                 * The I/O permission bitmap is too small and needs to be grown.
    7167                 */
    7268               
    73                 newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     69                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    7470                if (!newmap)
    7571                        return ENOMEM;
    7672               
     73                bitmap_t oldiomap;
    7774                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7875                    task->arch.iomap.bits);
     
    115112 *
    116113 * Interrupts must be disabled prior this call.
     114 *
    117115 */
    118116void io_perm_bitmap_install(void)
    119117{
    120         size_t bits;
    121         ptr_16_64_t cpugdtr;
    122         descriptor_t *gdt_p;
    123         tss_descriptor_t *tss_desc;
    124         size_t ver;
    125        
    126118        /* First, copy the I/O Permission Bitmap. */
    127         spinlock_lock(&TASK->lock);
    128         ver = TASK->arch.iomapver;
    129         if ((bits = TASK->arch.iomap.bits)) {
     119        irq_spinlock_lock(&TASK->lock, false);
     120        size_t ver = TASK->arch.iomapver;
     121        size_t bits = TASK->arch.iomap.bits;
     122        if (bits) {
     123                ASSERT(TASK->arch.iomap.map);
     124               
    130125                bitmap_t iomap;
    131        
    132                 ASSERT(TASK->arch.iomap.map);
    133126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    134127                    TSS_IOMAP_SIZE * 8);
    135128                bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     129               
    136130                /*
    137131                 * It is safe to set the trailing eight bits because of the
     
    140134                bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
    141135        }
    142         spinlock_unlock(&TASK->lock);
     136        irq_spinlock_unlock(&TASK->lock, false);
    143137       
    144138        /*
     
    146140         * Take the extra ending byte will all bits set into account.
    147141         */
     142        ptr_16_64_t cpugdtr;
    148143        gdtr_store(&cpugdtr);
    149         gdt_p = (descriptor_t *) cpugdtr.base;
     144       
     145        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    150146        gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    151147        gdtr_load(&cpugdtr);
     
    155151         * type must be changed to describe inactive TSS.
    156152         */
    157         tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
     153        tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
    158154        tss_desc->type = AR_TSS;
    159155        tr_load(gdtselector(TSS_DES));
  • kernel/arch/amd64/src/debugger.c

    r666f492 rda1bafb  
    4646#include <symtab.h>
    4747
     48#ifdef __64_BITS__
     49        #define getip(x)  ((x)->rip)
     50#endif
     51
     52#ifdef __32_BITS__
     53        #define getip(x)  ((x)->eip)
     54#endif
     55
    4856typedef struct  {
    49         uintptr_t address;      /**< Breakpoint address */
    50         int flags;              /**< Flags regarding breakpoint */
    51         int counter;            /**< How many times the exception occured */
     57        uintptr_t address;   /**< Breakpoint address */
     58        unsigned int flags;  /**< Flags regarding breakpoint */
     59        size_t counter;      /**< How many times the exception occured */
    5260} bpinfo_t;
    5361
    5462static bpinfo_t breakpoints[BKPOINTS_MAX];
    55 SPINLOCK_INITIALIZE(bkpoint_lock);
     63IRQ_SPINLOCK_STATIC_INITIALIZE(bkpoint_lock);
    5664
    5765#ifdef CONFIG_KCONSOLE
    5866
    59 static int cmd_print_breakpoints(cmd_arg_t *argv);
     67static int cmd_print_breakpoints(cmd_arg_t *);
     68static int cmd_del_breakpoint(cmd_arg_t *);
     69static int cmd_add_breakpoint(cmd_arg_t *);
     70
    6071static cmd_info_t bkpts_info = {
    6172        .name = "bkpts",
     
    6576};
    6677
    67 static int cmd_del_breakpoint(cmd_arg_t *argv);
    6878static cmd_arg_t del_argv = {
    6979        .type = ARG_TYPE_INT
    7080};
     81
    7182static cmd_info_t delbkpt_info = {
    7283        .name = "delbkpt",
    73         .description = "delbkpt <number> - Delete breakpoint.",
     84        .description = "Delete breakpoint.",
    7485        .func = cmd_del_breakpoint,
    7586        .argc = 1,
     
    7788};
    7889
    79 static int cmd_add_breakpoint(cmd_arg_t *argv);
    8090static cmd_arg_t add_argv = {
    8191        .type = ARG_TYPE_INT
    8292};
     93
    8394static cmd_info_t addbkpt_info = {
    8495        .name = "addbkpt",
    85         .description = "addbkpt <&symbol> - new breakpoint.",
     96        .description = "Add breakpoint.",
    8697        .func = cmd_add_breakpoint,
    8798        .argc = 1,
     
    92103        .type = ARG_TYPE_INT
    93104};
     105
    94106static cmd_info_t addwatchp_info = {
    95107        .name = "addwatchp",
    96         .description = "addbwatchp <&symbol> - new write watchpoint.",
     108        .description = "Add write watchpoint.",
    97109        .func = cmd_add_breakpoint,
    98110        .argc = 1,
     
    102114#endif /* CONFIG_KCONSOLE */
    103115
    104 /* Setup DR register according to table */
     116/** Setup DR register according to table
     117 *
     118 */
    105119static void setup_dr(int curidx)
    106120{
    107         unative_t dr7;
     121        ASSERT(curidx >= 0);
     122       
    108123        bpinfo_t *cur = &breakpoints[curidx];
    109         int flags = breakpoints[curidx].flags;
    110 
     124        unsigned int flags = breakpoints[curidx].flags;
     125       
    111126        /* Disable breakpoint in DR7 */
    112         dr7 = read_dr7();
    113         dr7 &= ~(0x2 << (curidx*2));
    114 
    115         if (cur->address) { /* Setup DR register */
     127        unative_t dr7 = read_dr7();
     128        dr7 &= ~(0x2 << (curidx * 2));
     129       
     130        /* Setup DR register */
     131        if (cur->address) {
    116132                /* Set breakpoint to debug registers */
    117133                switch (curidx) {
     
    129145                        break;
    130146                }
     147               
    131148                /* Set type to requested breakpoint & length*/
    132                 dr7 &= ~ (0x3 << (16 + 4*curidx));
    133                 dr7 &= ~ (0x3 << (18 + 4*curidx));
    134                 if ((flags & BKPOINT_INSTR)) {
    135                         ;
    136                 } else {
     149                dr7 &= ~(0x3 << (16 + 4 * curidx));
     150                dr7 &= ~(0x3 << (18 + 4 * curidx));
    137151               
     152                if (!(flags & BKPOINT_INSTR)) {
    138153#ifdef __32_BITS__
    139154                        dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
    140155#endif
    141 
     156                       
    142157#ifdef __64_BITS__
    143158                        dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
     
    149164                                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
    150165                }
    151 
     166               
    152167                /* Enable global breakpoint */
    153168                dr7 |= 0x2 << (curidx * 2);
    154 
     169               
    155170                write_dr7(dr7);
    156                
    157         }
    158 }
    159        
     171        }
     172}
     173
    160174/** Enable hardware breakpoint
    161175 *
    162176 * @param where Address of HW breakpoint
    163177 * @param flags Type of breakpoint (EXECUTE, WRITE)
     178 *
    164179 * @return Debug slot on success, -1 - no available HW breakpoint
    165  */
    166 int breakpoint_add(const void *where, const int flags, int curidx)
    167 {
    168         ipl_t ipl;
    169         int i;
    170         bpinfo_t *cur;
    171 
     180 *
     181 */
     182int breakpoint_add(const void *where, const unsigned int flags, int curidx)
     183{
    172184        ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
    173 
    174         ipl = interrupts_disable();
    175         spinlock_lock(&bkpoint_lock);
     185       
     186        irq_spinlock_lock(&bkpoint_lock, true);
    176187       
    177188        if (curidx == -1) {
    178189                /* Find free space in slots */
    179                 for (i = 0; i < BKPOINTS_MAX; i++)
     190                unsigned int i;
     191                for (i = 0; i < BKPOINTS_MAX; i++) {
    180192                        if (!breakpoints[i].address) {
    181193                                curidx = i;
    182194                                break;
    183195                        }
     196                }
     197               
    184198                if (curidx == -1) {
    185199                        /* Too many breakpoints */
    186                         spinlock_unlock(&bkpoint_lock);
    187                         interrupts_restore(ipl);
     200                        irq_spinlock_unlock(&bkpoint_lock, true);
    188201                        return -1;
    189202                }
    190203        }
    191         cur = &breakpoints[curidx];
    192 
     204       
     205        bpinfo_t *cur = &breakpoints[curidx];
     206       
    193207        cur->address = (uintptr_t) where;
    194208        cur->flags = flags;
    195209        cur->counter = 0;
    196 
     210       
    197211        setup_dr(curidx);
    198 
    199         spinlock_unlock(&bkpoint_lock);
    200         interrupts_restore(ipl);
    201 
     212       
     213        irq_spinlock_unlock(&bkpoint_lock, true);
     214       
    202215        /* Send IPI */
    203216//      ipi_broadcast(VECTOR_DEBUG_IPI);
    204 
     217       
    205218        return curidx;
    206219}
    207220
    208 #ifdef __64_BITS__
    209         #define getip(x)  ((x)->rip)
    210 #else
    211         #define getip(x)  ((x)->eip)
    212 #endif
    213 
    214221static void handle_exception(int slot, istate_t *istate)
    215222{
     223        ASSERT(slot >= 0);
    216224        ASSERT(breakpoints[slot].address);
    217 
     225       
    218226        /* Handle zero checker */
    219         if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
     227        if (!(breakpoints[slot].flags & BKPOINT_INSTR)) {
    220228                if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
    221229                        if (*((unative_t *) breakpoints[slot].address) != 0)
    222230                                return;
     231                       
    223232                        printf("*** Found ZERO on address %lx (slot %d) ***\n",
    224233                            breakpoints[slot].address, slot);
     
    228237                }
    229238        }
    230 
     239       
    231240        printf("Reached breakpoint %d:%lx (%s)\n", slot, getip(istate),
    232241            symtab_fmt_name_lookup(getip(istate)));
    233 
     242       
    234243#ifdef CONFIG_KCONSOLE
    235244        atomic_set(&haltstate, 1);
     
    241250void breakpoint_del(int slot)
    242251{
    243         bpinfo_t *cur;
    244         ipl_t ipl;
    245 
    246         ipl = interrupts_disable();
    247         spinlock_lock(&bkpoint_lock);
    248 
    249         cur = &breakpoints[slot];
     252        ASSERT(slot >= 0);
     253       
     254        irq_spinlock_lock(&bkpoint_lock, true);
     255       
     256        bpinfo_t *cur = &breakpoints[slot];
    250257        if (!cur->address) {
    251                 spinlock_unlock(&bkpoint_lock);
    252                 interrupts_restore(ipl);
     258                irq_spinlock_unlock(&bkpoint_lock, true);
    253259                return;
    254260        }
    255 
     261       
    256262        cur->address = NULL;
    257 
     263       
    258264        setup_dr(slot);
    259 
    260         spinlock_unlock(&bkpoint_lock);
    261         interrupts_restore(ipl);
     265       
     266        irq_spinlock_unlock(&bkpoint_lock, true);
    262267//      ipi_broadcast(VECTOR_DEBUG_IPI);
    263268}
    264269
    265 
    266 
    267270static void debug_exception(int n __attribute__((unused)), istate_t *istate)
    268271{
    269         unative_t dr6;
    270         int i;
    271        
    272272        /* Set RF to restart the instruction  */
    273273#ifdef __64_BITS__
    274274        istate->rflags |= RFLAGS_RF;
    275 #else
     275#endif
     276       
     277#ifdef __32_BITS__
    276278        istate->eflags |= EFLAGS_RF;
    277279#endif
    278 
    279         dr6 = read_dr6();
    280         for (i=0; i < BKPOINTS_MAX; i++) {
     280       
     281        unative_t dr6 = read_dr6();
     282       
     283        unsigned int i;
     284        for (i = 0; i < BKPOINTS_MAX; i++) {
    281285                if (dr6 & (1 << i)) {
    282286                        dr6 &= ~ (1 << i);
     
    289293
    290294#ifdef CONFIG_SMP
    291 static void
    292 debug_ipi(int n __attribute__((unused)),
     295static void debug_ipi(int n __attribute__((unused)),
    293296    istate_t *istate __attribute__((unused)))
    294297{
    295         int i;
    296 
    297         spinlock_lock(&bkpoint_lock);
     298        irq_spinlock_lock(&bkpoint_lock, false);
     299       
     300        unsigned int i;
    298301        for (i = 0; i < BKPOINTS_MAX; i++)
    299302                setup_dr(i);
    300         spinlock_unlock(&bkpoint_lock);
    301 }
    302 #endif
    303 
    304 /** Initialize debugger */
     303       
     304        irq_spinlock_unlock(&bkpoint_lock, false);
     305}
     306#endif /* CONFIG_SMP */
     307
     308/** Initialize debugger
     309 *
     310 */
    305311void debugger_init()
    306312{
    307         int i;
    308 
     313        unsigned int i;
    309314        for (i = 0; i < BKPOINTS_MAX; i++)
    310315                breakpoints[i].address = NULL;
    311 
     316       
    312317#ifdef CONFIG_KCONSOLE
    313318        cmd_initialize(&bkpts_info);
    314319        if (!cmd_register(&bkpts_info))
    315320                printf("Cannot register command %s\n", bkpts_info.name);
    316 
     321       
    317322        cmd_initialize(&delbkpt_info);
    318323        if (!cmd_register(&delbkpt_info))
    319324                printf("Cannot register command %s\n", delbkpt_info.name);
    320 
     325       
    321326        cmd_initialize(&addbkpt_info);
    322327        if (!cmd_register(&addbkpt_info))
    323328                printf("Cannot register command %s\n", addbkpt_info.name);
    324 
     329       
    325330        cmd_initialize(&addwatchp_info);
    326331        if (!cmd_register(&addwatchp_info))
     
    331336#ifdef CONFIG_SMP
    332337        exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
    333 #endif
     338#endif /* CONFIG_SMP */
    334339}
    335340
    336341#ifdef CONFIG_KCONSOLE
    337 /** Print table of active breakpoints */
     342/** Print table of active breakpoints
     343 *
     344 */
    338345int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
    339346{
    340         unsigned int i;
    341 
    342347#ifdef __32_BITS__
    343348        printf("#  Count Address    In symbol\n");
    344349        printf("-- ----- ---------- ---------\n");
    345350#endif
    346 
     351       
    347352#ifdef __64_BITS__
    348353        printf("#  Count Address            In symbol\n");
     
    350355#endif
    351356       
    352         for (i = 0; i < BKPOINTS_MAX; i++)
     357        unsigned int i;
     358        for (i = 0; i < BKPOINTS_MAX; i++) {
    353359                if (breakpoints[i].address) {
    354360                        const char *symbol = symtab_fmt_name_lookup(
    355361                            breakpoints[i].address);
    356 
     362                       
    357363#ifdef __32_BITS__
    358                         printf("%-2u %-5d %#10zx %s\n", i,
     364                        printf("%-2u %-5" PRIs " %p %s\n", i,
    359365                            breakpoints[i].counter, breakpoints[i].address,
    360366                            symbol);
    361367#endif
    362 
     368                       
    363369#ifdef __64_BITS__
    364                         printf("%-2u %-5d %#18zx %s\n", i,
     370                        printf("%-2u %-5" PRIs " %p %s\n", i,
    365371                            breakpoints[i].counter, breakpoints[i].address,
    366372                            symbol);
    367373#endif
    368 
    369                 }
     374                }
     375        }
     376       
    370377        return 1;
    371378}
    372379
    373 /** Remove breakpoint from table */
     380/** Remove breakpoint from table
     381 *
     382 */
    374383int cmd_del_breakpoint(cmd_arg_t *argv)
    375384{
     
    379388                return 0;
    380389        }
     390       
    381391        breakpoint_del(argv->intval);
    382392        return 1;
    383393}
    384394
    385 /** Add new breakpoint to table */
     395/** Add new breakpoint to table
     396 *
     397 */
    386398static int cmd_add_breakpoint(cmd_arg_t *argv)
    387399{
    388         int flags;
    389         int id;
    390 
    391         if (argv == &add_argv) {
     400        unsigned int flags;
     401        if (argv == &add_argv)
    392402                flags = BKPOINT_INSTR;
    393         } else { /* addwatchp */
     403        else
    394404                flags = BKPOINT_WRITE;
    395         }
     405       
    396406        printf("Adding breakpoint on address: %p\n", argv->intval);
    397         id = breakpoint_add((void *)argv->intval, flags, -1);
     407       
     408        int id = breakpoint_add((void *)argv->intval, flags, -1);
    398409        if (id < 0)
    399410                printf("Add breakpoint failed.\n");
  • kernel/arch/amd64/src/interrupt.c

    r666f492 rda1bafb  
    106106}
    107107
    108 /** General Protection Fault. */
     108/** General Protection Fault.
     109 *
     110 */
    109111static void gp_fault(int n, istate_t *istate)
    110112{
    111113        if (TASK) {
    112                 size_t ver;
    113 
    114                 spinlock_lock(&TASK->lock);
    115                 ver = TASK->arch.iomapver;
    116                 spinlock_unlock(&TASK->lock);
    117 
     114                irq_spinlock_lock(&TASK->lock, false);
     115                size_t ver = TASK->arch.iomapver;
     116                irq_spinlock_unlock(&TASK->lock, false);
     117               
    118118                if (CPU->arch.iomapver_copy != ver) {
    119119                        /*
     
    129129                fault_if_from_uspace(istate, "General protection fault.");
    130130        }
    131 
     131       
    132132        decode_istate(n, istate);
    133133        panic("General protection fault.");
     
    159159#endif
    160160
    161 /** Handler of IRQ exceptions */
     161/** Handler of IRQ exceptions.
     162 *
     163 */
    162164static void irq_interrupt(int n, istate_t *istate)
    163165{
     
    174176                 * The IRQ handler was found.
    175177                 */
    176                  
     178               
    177179                if (irq->preack) {
    178180                        /* Send EOI before processing the interrupt */
     
    181183                }
    182184                irq->handler(irq);
    183                 spinlock_unlock(&irq->lock);
     185                irq_spinlock_unlock(&irq->lock, false);
    184186        } else {
    185187                /*
  • kernel/arch/ia32/include/smp/apic.h

    r666f492 rda1bafb  
    2727 */
    2828
    29 /** @addtogroup ia32   
     29/** @addtogroup ia32
    3030 * @{
    3131 */
     
    3939#include <cpu.h>
    4040
    41 #define FIXED           (0<<0)
    42 #define LOPRI           (1<<0)
    43 
    44 #define APIC_ID_COUNT   16
     41#define FIXED  (0 << 0)
     42#define LOPRI  (1 << 0)
     43
     44#define APIC_ID_COUNT  16
    4545
    4646/* local APIC macros */
    47 #define IPI_INIT        0
    48 #define IPI_STARTUP     0
     47#define IPI_INIT     0
     48#define IPI_STARTUP  0
    4949
    5050/** Delivery modes. */
    51 #define DELMOD_FIXED    0x0
    52 #define DELMOD_LOWPRI   0x1
    53 #define DELMOD_SMI      0x2
     51#define DELMOD_FIXED    0x0
     52#define DELMOD_LOWPRI   0x1
     53#define DELMOD_SMI      0x2
    5454/* 0x3 reserved */
    55 #define DELMOD_NMI      0x4
    56 #define DELMOD_INIT     0x5
    57 #define DELMOD_STARTUP  0x6
    58 #define DELMOD_EXTINT   0x7
     55#define DELMOD_NMI      0x4
     56#define DELMOD_INIT     0x5
     57#define DELMOD_STARTUP  0x6
     58#define DELMOD_EXTINT   0x7
    5959
    6060/** Destination modes. */
    61 #define DESTMOD_PHYS    0x0
    62 #define DESTMOD_LOGIC   0x1
     61#define DESTMOD_PHYS   0x0
     62#define DESTMOD_LOGIC  0x1
    6363
    6464/** Trigger Modes. */
    65 #define TRIGMOD_EDGE    0x0
    66 #define TRIGMOD_LEVEL   0x1
     65#define TRIGMOD_EDGE   0x0
     66#define TRIGMOD_LEVEL  0x1
    6767
    6868/** Levels. */
    69 #define LEVEL_DEASSERT  0x0
    70 #define LEVEL_ASSERT    0x1
     69#define LEVEL_DEASSERT  0x0
     70#define LEVEL_ASSERT    0x1
    7171
    7272/** Destination Shorthands. */
    73 #define SHORTHAND_NONE          0x0
    74 #define SHORTHAND_SELF          0x1
    75 #define SHORTHAND_ALL_INCL      0x2
    76 #define SHORTHAND_ALL_EXCL      0x3
     73#define SHORTHAND_NONE      0x0
     74#define SHORTHAND_SELF      0x1
     75#define SHORTHAND_ALL_INCL  0x2
     76#define SHORTHAND_ALL_EXCL  0x3
    7777
    7878/** Interrupt Input Pin Polarities. */
    79 #define POLARITY_HIGH   0x0
    80 #define POLARITY_LOW    0x1
     79#define POLARITY_HIGH  0x0
     80#define POLARITY_LOW   0x1
    8181
    8282/** Divide Values. (Bit 2 is always 0) */
    83 #define DIVIDE_2        0x0
    84 #define DIVIDE_4        0x1
    85 #define DIVIDE_8        0x2
    86 #define DIVIDE_16       0x3
    87 #define DIVIDE_32       0x8
    88 #define DIVIDE_64       0x9
    89 #define DIVIDE_128      0xa
    90 #define DIVIDE_1        0xb
     83#define DIVIDE_2    0x0
     84#define DIVIDE_4    0x1
     85#define DIVIDE_8    0x2
     86#define DIVIDE_16   0x3
     87#define DIVIDE_32   0x8
     88#define DIVIDE_64   0x9
     89#define DIVIDE_128  0xa
     90#define DIVIDE_1    0xb
    9191
    9292/** Timer Modes. */
    93 #define TIMER_ONESHOT   0x0
    94 #define TIMER_PERIODIC  0x1
     93#define TIMER_ONESHOT   0x0
     94#define TIMER_PERIODIC  0x1
    9595
    9696/** Delivery status. */
    97 #define DELIVS_IDLE     0x0
    98 #define DELIVS_PENDING  0x1
     97#define DELIVS_IDLE     0x0
     98#define DELIVS_PENDING  0x1
    9999
    100100/** Destination masks. */
    101 #define DEST_ALL        0xff
     101#define DEST_ALL  0xff
    102102
    103103/** Dest format models. */
    104 #define MODEL_FLAT      0xf
    105 #define MODEL_CLUSTER   0x0
     104#define MODEL_FLAT     0xf
     105#define MODEL_CLUSTER  0x0
    106106
    107107/** Interrupt Command Register. */
    108 #define ICRlo           (0x300 / sizeof(uint32_t))
    109 #define ICRhi           (0x310 / sizeof(uint32_t))
     108#define ICRlo  (0x300 / sizeof(uint32_t))
     109#define ICRhi  (0x310 / sizeof(uint32_t))
     110
    110111typedef struct {
    111112        union {
    112113                uint32_t lo;
    113114                struct {
    114                         uint8_t vector;                 /**< Interrupt Vector. */
    115                         unsigned delmod : 3;            /**< Delivery Mode. */
    116                         unsigned destmod : 1;           /**< Destination Mode. */
    117                         unsigned delivs : 1;            /**< Delivery status (RO). */
    118                         unsigned : 1;                   /**< Reserved. */
    119                         unsigned level : 1;             /**< Level. */
    120                         unsigned trigger_mode : 1;      /**< Trigger Mode. */
    121                         unsigned : 2;                   /**< Reserved. */
    122                         unsigned shorthand : 2;         /**< Destination Shorthand. */
    123                         unsigned : 12;                  /**< Reserved. */
     115                        uint8_t vector;                 /**< Interrupt Vector. */
     116                        unsigned int delmod : 3;        /**< Delivery Mode. */
     117                        unsigned int destmod : 1;       /**< Destination Mode. */
     118                        unsigned int delivs : 1;        /**< Delivery status (RO). */
     119                        unsigned int : 1;               /**< Reserved. */
     120                        unsigned int level : 1;         /**< Level. */
     121                        unsigned int trigger_mode : 1;  /**< Trigger Mode. */
     122                        unsigned int : 2;               /**< Reserved. */
     123                        unsigned int shorthand : 2;     /**< Destination Shorthand. */
     124                        unsigned int : 12;              /**< Reserved. */
    124125                } __attribute__ ((packed));
    125126        };
     
    127128                uint32_t hi;
    128129                struct {
    129                         unsigned : 24;                  /**< Reserved. */
    130                         uint8_t dest;                   /**< Destination field. */
     130                        unsigned int : 24;  /**< Reserved. */
     131                        uint8_t dest;       /**< Destination field. */
    131132                } __attribute__ ((packed));
    132133        };
     
    134135
    135136/* End Of Interrupt. */
    136 #define EOI             (0x0b0 / sizeof(uint32_t))
     137#define EOI  (0x0b0 / sizeof(uint32_t))
    137138
    138139/** Error Status Register. */
    139 #define ESR             (0x280 / sizeof(uint32_t))
     140#define ESR  (0x280 / sizeof(uint32_t))
     141
    140142typedef union {
    141143        uint32_t value;
    142144        uint8_t err_bitmap;
    143145        struct {
    144                 unsigned send_checksum_error : 1;
    145                 unsigned receive_checksum_error : 1;
    146                 unsigned send_accept_error : 1;
    147                 unsigned receive_accept_error : 1;
    148                 unsigned : 1;
    149                 unsigned send_illegal_vector : 1;
    150                 unsigned received_illegal_vector : 1;
    151                 unsigned illegal_register_address : 1;
    152                 unsigned : 24;
     146                unsigned int send_checksum_error : 1;
     147                unsigned int receive_checksum_error : 1;
     148                unsigned int send_accept_error : 1;
     149                unsigned int receive_accept_error : 1;
     150                unsigned int : 1;
     151                unsigned int send_illegal_vector : 1;
     152                unsigned int received_illegal_vector : 1;
     153                unsigned int illegal_register_address : 1;
     154                unsigned int : 24;
    153155        } __attribute__ ((packed));
    154156} esr_t;
    155157
    156158/* Task Priority Register */
    157 #define TPR             (0x080 / sizeof(uint32_t))
    158 typedef union {
    159         uint32_t value;
    160         struct {
    161                 unsigned pri_sc : 4;            /**< Task Priority Sub-Class. */
    162                 unsigned pri : 4;               /**< Task Priority. */
     159#define TPR  (0x080 / sizeof(uint32_t))
     160
     161typedef union {
     162        uint32_t value;
     163        struct {
     164                unsigned int pri_sc : 4;  /**< Task Priority Sub-Class. */
     165                unsigned int pri : 4;     /**< Task Priority. */
    163166        } __attribute__ ((packed));
    164167} tpr_t;
    165168
    166169/** Spurious-Interrupt Vector Register. */
    167 #define SVR             (0x0f0 / sizeof(uint32_t))
    168 typedef union {
    169         uint32_t value;
    170         struct {
    171                 uint8_t vector;                 /**< Spurious Vector. */
    172                 unsigned lapic_enabled : 1;     /**< APIC Software Enable/Disable. */
    173                 unsigned focus_checking : 1;    /**< Focus Processor Checking. */
    174                 unsigned : 22;                  /**< Reserved. */
     170#define SVR  (0x0f0 / sizeof(uint32_t))
     171
     172typedef union {
     173        uint32_t value;
     174        struct {
     175                uint8_t vector;                   /**< Spurious Vector. */
     176                unsigned int lapic_enabled : 1;   /**< APIC Software Enable/Disable. */
     177                unsigned int focus_checking : 1;  /**< Focus Processor Checking. */
     178                unsigned int : 22;                /**< Reserved. */
    175179        } __attribute__ ((packed));
    176180} svr_t;
    177181
    178182/** Time Divide Configuration Register. */
    179 #define TDCR            (0x3e0 / sizeof(uint32_t))
    180 typedef union {
    181         uint32_t value;
    182         struct {
    183                 unsigned div_value : 4;         /**< Divide Value, bit 2 is always 0. */
    184                 unsigned : 28;                  /**< Reserved. */
     183#define TDCR  (0x3e0 / sizeof(uint32_t))
     184
     185typedef union {
     186        uint32_t value;
     187        struct {
     188                unsigned int div_value : 4;  /**< Divide Value, bit 2 is always 0. */
     189                unsigned int : 28;           /**< Reserved. */
    185190        } __attribute__ ((packed));
    186191} tdcr_t;
    187192
    188193/* Initial Count Register for Timer */
    189 #define ICRT            (0x380 / sizeof(uint32_t))
     194#define ICRT  (0x380 / sizeof(uint32_t))
    190195
    191196/* Current Count Register for Timer */
    192 #define CCRT            (0x390 / sizeof(uint32_t))
     197#define CCRT  (0x390 / sizeof(uint32_t))
    193198
    194199/** LVT Timer register. */
    195 #define LVT_Tm          (0x320 / sizeof(uint32_t))
    196 typedef union {
    197         uint32_t value;
    198         struct {
    199                 uint8_t vector;         /**< Local Timer Interrupt vector. */
    200                 unsigned : 4;           /**< Reserved. */
    201                 unsigned delivs : 1;    /**< Delivery status (RO). */
    202                 unsigned : 3;           /**< Reserved. */
    203                 unsigned masked : 1;    /**< Interrupt Mask. */
    204                 unsigned mode : 1;      /**< Timer Mode. */
    205                 unsigned : 14;          /**< Reserved. */
     200#define LVT_Tm  (0x320 / sizeof(uint32_t))
     201
     202typedef union {
     203        uint32_t value;
     204        struct {
     205                uint8_t vector;           /**< Local Timer Interrupt vector. */
     206                unsigned int : 4;         /**< Reserved. */
     207                unsigned int delivs : 1;  /**< Delivery status (RO). */
     208                unsigned int : 3;         /**< Reserved. */
     209                unsigned int masked : 1;  /**< Interrupt Mask. */
     210                unsigned int mode : 1;    /**< Timer Mode. */
     211                unsigned int : 14;        /**< Reserved. */
    206212        } __attribute__ ((packed));
    207213} lvt_tm_t;
    208214
    209215/** LVT LINT registers. */
    210 #define LVT_LINT0       (0x350 / sizeof(uint32_t))
    211 #define LVT_LINT1       (0x360 / sizeof(uint32_t))
    212 typedef union {
    213         uint32_t value;
    214         struct {
    215                 uint8_t vector;                 /**< LINT Interrupt vector. */
    216                 unsigned delmod : 3;            /**< Delivery Mode. */
    217                 unsigned : 1;                   /**< Reserved. */
    218                 unsigned delivs : 1;            /**< Delivery status (RO). */
    219                 unsigned intpol : 1;            /**< Interrupt Input Pin Polarity. */
    220                 unsigned irr : 1;               /**< Remote IRR (RO). */
    221                 unsigned trigger_mode : 1;      /**< Trigger Mode. */
    222                 unsigned masked : 1;            /**< Interrupt Mask. */
    223                 unsigned : 15;                  /**< Reserved. */
     216#define LVT_LINT0  (0x350 / sizeof(uint32_t))
     217#define LVT_LINT1  (0x360 / sizeof(uint32_t))
     218
     219typedef union {
     220        uint32_t value;
     221        struct {
     222                uint8_t vector;                 /**< LINT Interrupt vector. */
     223                unsigned int delmod : 3;        /**< Delivery Mode. */
     224                unsigned int : 1;               /**< Reserved. */
     225                unsigned int delivs : 1;        /**< Delivery status (RO). */
     226                unsigned int intpol : 1;        /**< Interrupt Input Pin Polarity. */
     227                unsigned int irr : 1;           /**< Remote IRR (RO). */
     228                unsigned int trigger_mode : 1;  /**< Trigger Mode. */
     229                unsigned int masked : 1;        /**< Interrupt Mask. */
     230                unsigned int : 15;              /**< Reserved. */
    224231        } __attribute__ ((packed));
    225232} lvt_lint_t;
    226233
    227234/** LVT Error register. */
    228 #define LVT_Err         (0x370 / sizeof(uint32_t))
    229 typedef union {
    230         uint32_t value;
    231         struct {
    232                 uint8_t vector;         /**< Local Timer Interrupt vector. */
    233                 unsigned : 4;           /**< Reserved. */
    234                 unsigned delivs : 1;    /**< Delivery status (RO). */
    235                 unsigned : 3;           /**< Reserved. */
    236                 unsigned masked : 1;    /**< Interrupt Mask. */
    237                 unsigned : 15;          /**< Reserved. */
     235#define LVT_Err  (0x370 / sizeof(uint32_t))
     236
     237typedef union {
     238        uint32_t value;
     239        struct {
     240                uint8_t vector;           /**< Local Timer Interrupt vector. */
     241                unsigned int : 4;         /**< Reserved. */
     242                unsigned int delivs : 1;  /**< Delivery status (RO). */
     243                unsigned int : 3;         /**< Reserved. */
     244                unsigned int masked : 1;  /**< Interrupt Mask. */
     245                unsigned int : 15;        /**< Reserved. */
    238246        } __attribute__ ((packed));
    239247} lvt_error_t;
    240248
    241249/** Local APIC ID Register. */
    242 #define L_APIC_ID       (0x020 / sizeof(uint32_t))
    243 typedef union {
    244         uint32_t value;
    245         struct {
    246                 unsigned : 24;          /**< Reserved. */
    247                 uint8_t apic_id;                /**< Local APIC ID. */
     250#define L_APIC_ID  (0x020 / sizeof(uint32_t))
     251
     252typedef union {
     253        uint32_t value;
     254        struct {
     255                unsigned int : 24;  /**< Reserved. */
     256                uint8_t apic_id;    /**< Local APIC ID. */
    248257        } __attribute__ ((packed));
    249258} l_apic_id_t;
    250259
    251260/** Local APIC Version Register */
    252 #define LAVR            (0x030 / sizeof(uint32_t))
    253 #define LAVR_Mask       0xff
    254 #define is_local_apic(x)        (((x) & LAVR_Mask & 0xf0) == 0x1)
    255 #define is_82489DX_apic(x)      ((((x) & LAVR_Mask & 0xf0) == 0x0))
    256 #define is_local_xapic(x)       (((x) & LAVR_Mask) == 0x14)
     261#define LAVR       (0x030 / sizeof(uint32_t))
     262#define LAVR_Mask  0xff
     263
     264#define is_local_apic(x)    (((x) & LAVR_Mask & 0xf0) == 0x1)
     265#define is_82489DX_apic(x)  ((((x) & LAVR_Mask & 0xf0) == 0x0))
     266#define is_local_xapic(x)   (((x) & LAVR_Mask) == 0x14)
    257267
    258268/** Logical Destination Register. */
    259 #define  LDR            (0x0d0 / sizeof(uint32_t))
    260 typedef union {
    261         uint32_t value;
    262         struct {
    263                 unsigned : 24;          /**< Reserved. */
    264                 uint8_t id;             /**< Logical APIC ID. */
     269#define  LDR  (0x0d0 / sizeof(uint32_t))
     270
     271typedef union {
     272        uint32_t value;
     273        struct {
     274                unsigned int : 24;  /**< Reserved. */
     275                uint8_t id;         /**< Logical APIC ID. */
    265276        } __attribute__ ((packed));
    266277} ldr_t;
    267278
    268279/** Destination Format Register. */
    269 #define DFR             (0x0e0 / sizeof(uint32_t))
    270 typedef union {
    271         uint32_t value;
    272         struct {
    273                 unsigned : 28;          /**< Reserved, all ones. */
    274                 unsigned model : 4;     /**< Model. */
     280#define DFR  (0x0e0 / sizeof(uint32_t))
     281
     282typedef union {
     283        uint32_t value;
     284        struct {
     285                unsigned int : 28;       /**< Reserved, all ones. */
     286                unsigned int model : 4;  /**< Model. */
    275287        } __attribute__ ((packed));
    276288} dfr_t;
    277289
    278290/* IO APIC */
    279 #define IOREGSEL        (0x00 / sizeof(uint32_t))
    280 #define IOWIN           (0x10 / sizeof(uint32_t))
    281 
    282 #define IOAPICID        0x00
    283 #define IOAPICVER       0x01
    284 #define IOAPICARB       0x02
    285 #define IOREDTBL        0x10
     291#define IOREGSEL  (0x00 / sizeof(uint32_t))
     292#define IOWIN     (0x10 / sizeof(uint32_t))
     293
     294#define IOAPICID   0x00
     295#define IOAPICVER  0x01
     296#define IOAPICARB  0x02
     297#define IOREDTBL   0x10
    286298
    287299/** I/O Register Select Register. */
     
    289301        uint32_t value;
    290302        struct {
    291                 uint8_t reg_addr;               /**< APIC Register Address. */
    292                 unsigned : 24;          /**< Reserved. */
     303                uint8_t reg_addr;   /**< APIC Register Address. */
     304                unsigned int : 24;  /**< Reserved. */
    293305        } __attribute__ ((packed));
    294306} io_regsel_t;
     
    299311                uint32_t lo;
    300312                struct {
    301                         uint8_t intvec;                 /**< Interrupt Vector. */
    302                         unsigned delmod : 3;            /**< Delivery Mode. */
    303                         unsigned destmod : 1;           /**< Destination mode. */
    304                         unsigned delivs : 1;            /**< Delivery status (RO). */
    305                         unsigned intpol : 1;            /**< Interrupt Input Pin Polarity. */
    306                         unsigned irr : 1;               /**< Remote IRR (RO). */
    307                         unsigned trigger_mode : 1;      /**< Trigger Mode. */
    308                         unsigned masked : 1;            /**< Interrupt Mask. */
    309                         unsigned : 15;                  /**< Reserved. */
     313                        uint8_t intvec;                 /**< Interrupt Vector. */
     314                        unsigned int delmod : 3;        /**< Delivery Mode. */
     315                        unsigned int destmod : 1;       /**< Destination mode. */
     316                        unsigned int delivs : 1;        /**< Delivery status (RO). */
     317                        unsigned int intpol : 1;        /**< Interrupt Input Pin Polarity. */
     318                        unsigned int irr : 1;           /**< Remote IRR (RO). */
     319                        unsigned int trigger_mode : 1;  /**< Trigger Mode. */
     320                        unsigned int masked : 1;        /**< Interrupt Mask. */
     321                        unsigned int : 15;              /**< Reserved. */
    310322                } __attribute__ ((packed));
    311323        };
     
    313325                uint32_t hi;
    314326                struct {
    315                         unsigned : 24;                  /**< Reserved. */
    316                         uint8_t dest : 8;                       /**< Destination Field. */
     327                        unsigned int : 24;  /**< Reserved. */
     328                        uint8_t dest : 8;   /**< Destination Field. */
    317329                } __attribute__ ((packed));
    318330        };
     
    325337        uint32_t value;
    326338        struct {
    327                 unsigned : 24;          /**< Reserved. */
    328                 unsigned apic_id : 4;   /**< IO APIC ID. */
    329                 unsigned : 4;           /**< Reserved. */
     339                unsigned int : 24;         /**< Reserved. */
     340                unsigned int apic_id : 4;  /**< IO APIC ID. */
     341                unsigned int : 4;          /**< Reserved. */
    330342        } __attribute__ ((packed));
    331343} io_apic_id_t;
     
    340352extern void l_apic_init(void);
    341353extern void l_apic_eoi(void);
    342 extern int l_apic_broadcast_custom_ipi(uint8_t vector);
    343 extern int l_apic_send_init_ipi(uint8_t apicid);
     354extern int l_apic_broadcast_custom_ipi(uint8_t);
     355extern int l_apic_send_init_ipi(uint8_t);
    344356extern void l_apic_debug(void);
    345357extern uint8_t l_apic_id(void);
    346358
    347 extern uint32_t io_apic_read(uint8_t address);
    348 extern void io_apic_write(uint8_t address , uint32_t x);
    349 extern void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t v, int flags);
    350 extern void io_apic_disable_irqs(uint16_t irqmask);
    351 extern void io_apic_enable_irqs(uint16_t irqmask);
     359extern uint32_t io_apic_read(uint8_t);
     360extern void io_apic_write(uint8_t, uint32_t);
     361extern void io_apic_change_ioredtbl(uint8_t pin, uint8_t dest, uint8_t v, unsigned int);
     362extern void io_apic_disable_irqs(uint16_t);
     363extern void io_apic_enable_irqs(uint16_t);
    352364
    353365#endif
  • 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;
  • kernel/arch/ia64/src/drivers/it.c

    r666f492 rda1bafb  
    3434
    3535/** Interval Timer driver. */
    36  
     36
    3737#include <arch/drivers/it.h>
    3838#include <arch/interrupt.h>
     
    4545#include <arch.h>
    4646
    47 #define IT_SERVICE_CLOCKS       64
     47#define IT_SERVICE_CLOCKS  64
    4848
    49 #define FREQ_NUMERATOR_SHIFT    32
    50 #define FREQ_NUMERATOR_MASK     0xffffffff00000000ULL
     49#define FREQ_NUMERATOR_SHIFT  32
     50#define FREQ_NUMERATOR_MASK   0xffffffff00000000ULL
    5151
    52 #define FREQ_DENOMINATOR_SHIFT  0
    53 #define FREQ_DENOMINATOR_MASK   0xffffffffULL
     52#define FREQ_DENOMINATOR_SHIFT  0
     53#define FREQ_DENOMINATOR_MASK   0xffffffffULL
    5454
    5555uint64_t it_delta;
     
    6363void it_init(void)
    6464{
    65         cr_itv_t itv;
    66        
    6765        if (config.cpu_active == 1) {
    6866                irq_initialize(&it_irq);
     
    8381        }
    8482       
    85         /* initialize Interval Timer external interrupt vector */
     83        /* Initialize Interval Timer external interrupt vector */
     84        cr_itv_t itv;
     85       
    8686        itv.value = itv_read();
    8787        itv.vector = INTERRUPT_TIMER;
    8888        itv.m = 0;
    8989        itv_write(itv.value);
    90 
    91         /* set Interval Timer Counter to zero */
     90       
     91        /* Set Interval Timer Counter to zero */
    9292        itc_write(0);
    9393       
    94         /* generate first Interval Timer interrupt in IT_DELTA ticks */
     94        /* Generate first Interval Timer interrupt in IT_DELTA ticks */
    9595        itm_write(IT_DELTA);
    96 
    97         /* propagate changes */
     96       
     97        /* Propagate changes */
    9898        srlz_d();
    9999}
     
    104104 *
    105105 * @return Always IRQ_ACCEPT.
     106 *
    106107 */
    107108irq_ownership_t it_claim(irq_t *irq)
     
    113114void it_interrupt(irq_t *irq)
    114115{
    115         int64_t c;
    116         int64_t m;
    117        
    118116        eoi_write(EOI);
    119117       
    120         m = itm_read();
     118        int64_t itm = itm_read();
    121119       
    122         while (1) {
    123                 c = itc_read();
    124                 c += IT_SERVICE_CLOCKS;
    125 
    126                 m += IT_DELTA;
    127                 if (m - c < 0)
     120        while (true) {
     121                int64_t itc = itc_read();
     122                itc += IT_SERVICE_CLOCKS;
     123               
     124                itm += IT_DELTA;
     125                if (itm - itc < 0)
    128126                        CPU->missed_clock_ticks++;
    129127                else
     
    131129        }
    132130       
    133         itm_write(m);
    134         srlz_d();                               /* propagate changes */
    135 
     131        itm_write(itm);
     132        srlz_d();  /* Propagate changes */
     133       
    136134        /*
    137135         * We are holding a lock which prevents preemption.
    138136         * Release the lock, call clock() and reacquire the lock again.
    139137         */
    140         spinlock_unlock(&irq->lock);   
     138        irq_spinlock_unlock(&irq->lock, false);
    141139        clock();
    142         spinlock_lock(&irq->lock);
     140        irq_spinlock_lock(&irq->lock, false);
    143141}
    144142
  • kernel/arch/ia64/src/interrupt.c

    r666f492 rda1bafb  
    5757#include <putchar.h>
    5858
    59 #define VECTORS_64_BUNDLE       20
    60 #define VECTORS_16_BUNDLE       48
    61 #define VECTORS_16_BUNDLE_START 0x5000
    62 #define VECTOR_MAX              0x7f00
    63 
    64 #define BUNDLE_SIZE             16
     59#define VECTORS_64_BUNDLE        20
     60#define VECTORS_16_BUNDLE        48
     61#define VECTORS_16_BUNDLE_START  0x5000
     62
     63#define VECTOR_MAX  0x7f00
     64
     65#define BUNDLE_SIZE  16
    6566
    6667static const char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
     
    134135static void dump_interrupted_context(istate_t *istate)
    135136{
    136         const char *ifa = symtab_fmt_name_lookup(istate->cr_ifa);
    137         const char *iipa = symtab_fmt_name_lookup(istate->cr_iipa);
    138         const char *iip = symtab_fmt_name_lookup(istate->cr_iip);
    139        
    140137        putchar('\n');
    141138        printf("Interrupted context dump:\n");
     
    149146            istate->cr_ipsr);
    150147       
    151         printf("cr.iip=%#018llx, #%d\t(%s)\n", istate->cr_iip,
    152             istate->cr_isr.ei, iip);
    153         printf("cr.iipa=%#018llx\t(%s)\n", istate->cr_iipa, iipa);
    154         printf("cr.ifa=%#018llx\t(%s)\n", istate->cr_ifa, ifa);
     148        printf("cr.iip=%#018llx, #%d\t(%s)\n", istate->cr_iip, istate->cr_isr.ei,
     149            symtab_fmt_name_lookup(istate->cr_iip));
     150        printf("cr.iipa=%#018llx\t(%s)\n", istate->cr_iipa,
     151            symtab_fmt_name_lookup(istate->cr_iipa));
     152        printf("cr.ifa=%#018llx\t(%s)\n", istate->cr_ifa,
     153            symtab_fmt_name_lookup(istate->cr_ifa));
    155154}
    156155
     
    218217                istate->cr_ipsr.ri++;
    219218        }
    220 
     219       
    221220        return syscall_handler(istate->in0, istate->in1, istate->in2,
    222221            istate->in3, istate->in4, istate->in5, istate->in6);
     
    234233static void end_of_local_irq(void)
    235234{
    236         asm volatile ("mov cr.eoi=r0;;");
    237 }
    238 
     235        asm volatile (
     236                "mov cr.eoi=r0;;"
     237        );
     238}
    239239
    240240void external_interrupt(uint64_t vector, istate_t *istate)
    241241{
    242242        cr_ivr_t ivr;
    243         irq_t *irq;
    244243       
    245244        ivr.value = ivr_read();
    246245        srlz_d();
    247 
     246       
     247        irq_t *irq;
     248       
    248249        switch (ivr.vector) {
    249250        case INTERRUPT_SPURIOUS:
     
    252253#endif
    253254                break;
    254 
     255       
    255256#ifdef CONFIG_SMP
    256257        case VECTOR_TLB_SHOOTDOWN_IPI:
     
    259260                break;
    260261#endif
    261 
     262       
    262263        case INTERRUPT_TIMER:
    263264                irq = irq_dispatch_and_lock(ivr.vector);
    264265                if (irq) {
    265266                        irq->handler(irq);
    266                         spinlock_unlock(&irq->lock);
     267                        irq_spinlock_unlock(&irq->lock, false);
    267268                } else {
    268269                        panic("Unhandled Internal Timer Interrupt (%d).",
     
    283284                        if (!irq->preack)
    284285                                end_of_local_irq();
    285                         spinlock_unlock(&irq->lock);
     286                        irq_spinlock_unlock(&irq->lock, false);
    286287                } else {
    287288                        /*
  • kernel/arch/mips32/include/asm.h

    r666f492 rda1bafb  
    3939#include <config.h>
    4040
    41 
    4241static inline void cpu_sleep(void)
    4342{
     
    4746
    4847/** Return base address of current stack
    49  * 
     48 *
    5049 * Return the base address of the current stack.
    5150 * The stack is assumed to be STACK_SIZE bytes long.
    5251 * The stack must start on page boundary.
     52 *
    5353 */
    5454static inline uintptr_t get_stack_base(void)
    5555{
    56         uintptr_t v;
     56        uintptr_t base;
    5757       
    5858        asm volatile (
    59                 "and %0, $29, %1\n"
    60                 : "=r" (v)
    61                 : "r" (~(STACK_SIZE-1))
     59                "and %[base], $29, %[mask]\n"
     60                : [base] "=r" (base)
     61                : [mask] "r" (~(STACK_SIZE - 1))
    6262        );
    6363       
    64         return v;
     64        return base;
    6565}
    6666
     
    7878static inline void pio_write_8(ioport8_t *port, uint8_t v)
    7979{
    80         *port = v;     
     80        *port = v;
    8181}
    8282
    8383static inline void pio_write_16(ioport16_t *port, uint16_t v)
    8484{
    85         *port = v;     
     85        *port = v;
    8686}
    8787
    8888static inline void pio_write_32(ioport32_t *port, uint32_t v)
    8989{
    90         *port = v;     
     90        *port = v;
    9191}
    9292
  • kernel/arch/mips32/include/debugger.h

    r666f492 rda1bafb  
    4141#define BKPOINTS_MAX 10
    4242
    43 #define BKPOINT_INPROG   (1 << 0)   /**< Breakpoint was shot */
    44 #define BKPOINT_ONESHOT  (1 << 1)   /**< One-time breakpoint,mandatory for j/b
    45                                          instructions */
    46 #define BKPOINT_REINST   (1 << 2)   /**< Breakpoint is set on the next
    47                                          instruction, so that it could be
    48                                          reinstalled on the previous one */
    49 #define BKPOINT_FUNCCALL (1 << 3)   /**< Call a predefined function */
     43/** Breakpoint was shot */
     44#define BKPOINT_INPROG  (1 << 0)
     45
     46/** One-time breakpoint, mandatory for j/b instructions */
     47#define BKPOINT_ONESHOT  (1 << 1)
     48
     49/**
     50 * Breakpoint is set on the next instruction, so that it
     51 * could be reinstalled on the previous one
     52 */
     53#define BKPOINT_REINST  (1 << 2)
     54
     55/** Call a predefined function */
     56#define BKPOINT_FUNCCALL  (1 << 3)
     57
    5058
    5159typedef struct  {
    52         uintptr_t address;      /**< Breakpoint address */
    53         unative_t instruction; /**< Original instruction */
     60        uintptr_t address;          /**< Breakpoint address */
     61        unative_t instruction;      /**< Original instruction */
    5462        unative_t nextinstruction;  /**< Original instruction following break */
    55         int flags;        /**< Flags regarding breakpoint */
     63        unsigned int flags;         /**< Flags regarding breakpoint */
    5664        size_t counter;
    57         void (*bkfunc)(void *b, istate_t *istate);
     65        void (*bkfunc)(void *, istate_t *);
    5866} bpinfo_t;
    5967
     68extern bpinfo_t breakpoints[BKPOINTS_MAX];
     69
    6070extern void debugger_init(void);
    61 void debugger_bpoint(istate_t *istate);
    62 
    63 extern bpinfo_t breakpoints[BKPOINTS_MAX];
     71extern void debugger_bpoint(istate_t *);
    6472
    6573#endif
  • kernel/arch/mips32/include/mm/as.h

    r666f492 rda1bafb  
    2727 */
    2828
    29 /** @addtogroup mips32mm       
     29/** @addtogroup mips32mm
    3030 * @{
    3131 */
     
    3636#define KERN_mips32_AS_H_
    3737
    38 #define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH      0
     38#define KERNEL_ADDRESS_SPACE_SHADOWED_ARCH  0
    3939
    4040#define KERNEL_ADDRESS_SPACE_START_ARCH         (unsigned long) 0x80000000
  • kernel/arch/mips32/src/debugger.c

    r666f492 rda1bafb  
    4646
    4747bpinfo_t breakpoints[BKPOINTS_MAX];
    48 SPINLOCK_INITIALIZE(bkpoint_lock);
     48IRQ_SPINLOCK_STATIC_INITIALIZE(bkpoint_lock);
    4949
    5050#ifdef CONFIG_KCONSOLE
    5151
    52 static int cmd_print_breakpoints(cmd_arg_t *argv);
     52static int cmd_print_breakpoints(cmd_arg_t *);
     53static int cmd_del_breakpoint(cmd_arg_t *);
     54static int cmd_add_breakpoint(cmd_arg_t *);
     55
    5356static cmd_info_t bkpts_info = {
    5457        .name = "bkpts",
     
    5861};
    5962
    60 static int cmd_del_breakpoint(cmd_arg_t *argv);
    6163static cmd_arg_t del_argv = {
    6264        .type = ARG_TYPE_INT
    6365};
     66
    6467static cmd_info_t delbkpt_info = {
    6568        .name = "delbkpt",
    66         .description = "delbkpt <number> - Delete breakpoint.",
     69        .description = "Delete breakpoint.",
    6770        .func = cmd_del_breakpoint,
    6871        .argc = 1,
     
    7073};
    7174
    72 static int cmd_add_breakpoint(cmd_arg_t *argv);
    7375static cmd_arg_t add_argv = {
    7476        .type = ARG_TYPE_INT
    7577};
     78
    7679static cmd_info_t addbkpt_info = {
    7780        .name = "addbkpt",
    78         .description = "addbkpt <&symbol> - new bkpoint. Break on J/Branch "
    79             "insts unsupported.",
     81        .description = "Add bkpoint (break on J/Branch insts unsupported).",
    8082        .func = cmd_add_breakpoint,
    8183        .argc = 1,
     
    8991static cmd_info_t addbkpte_info = {
    9092        .name = "addbkpte",
    91         .description = "addebkpte <&symbol> <&func> - new bkpoint. Call "
    92             "func(or Nothing if 0).",
     93        .description = "Add bkpoint with a trigger function.",
    9394        .func = cmd_add_breakpoint,
    9495        .argc = 2,
     
    100101        uint32_t value;
    101102} jmpinstr[] = {
    102         {0xf3ff0000, 0x41000000}, /* BCzF */
    103         {0xf3ff0000, 0x41020000}, /* BCzFL */
    104         {0xf3ff0000, 0x41010000}, /* BCzT */
    105         {0xf3ff0000, 0x41030000}, /* BCzTL */
    106         {0xfc000000, 0x10000000}, /* BEQ */
    107         {0xfc000000, 0x50000000}, /* BEQL */
    108         {0xfc1f0000, 0x04010000}, /* BEQL */
    109         {0xfc1f0000, 0x04110000}, /* BGEZAL */
    110         {0xfc1f0000, 0x04130000}, /* BGEZALL */
    111         {0xfc1f0000, 0x04030000}, /* BGEZL */
    112         {0xfc1f0000, 0x1c000000}, /* BGTZ */
    113         {0xfc1f0000, 0x5c000000}, /* BGTZL */
    114         {0xfc1f0000, 0x18000000}, /* BLEZ */
    115         {0xfc1f0000, 0x58000000}, /* BLEZL */
    116         {0xfc1f0000, 0x04000000}, /* BLTZ */
    117         {0xfc1f0000, 0x04100000}, /* BLTZAL */
    118         {0xfc1f0000, 0x04120000}, /* BLTZALL */
    119         {0xfc1f0000, 0x04020000}, /* BLTZL */
    120         {0xfc000000, 0x14000000}, /* BNE */
    121         {0xfc000000, 0x54000000}, /* BNEL */
    122         {0xfc000000, 0x08000000}, /* J */
    123         {0xfc000000, 0x0c000000}, /* JAL */
    124         {0xfc1f07ff, 0x00000009}, /* JALR */
    125         {0, 0} /* EndOfTable */
    126 };
    127 
     103        {0xf3ff0000, 0x41000000},  /* BCzF */
     104        {0xf3ff0000, 0x41020000},  /* BCzFL */
     105        {0xf3ff0000, 0x41010000},  /* BCzT */
     106        {0xf3ff0000, 0x41030000},  /* BCzTL */
     107        {0xfc000000, 0x10000000},  /* BEQ */
     108        {0xfc000000, 0x50000000},  /* BEQL */
     109        {0xfc1f0000, 0x04010000},  /* BEQL */
     110        {0xfc1f0000, 0x04110000},  /* BGEZAL */
     111        {0xfc1f0000, 0x04130000},  /* BGEZALL */
     112        {0xfc1f0000, 0x04030000},  /* BGEZL */
     113        {0xfc1f0000, 0x1c000000},  /* BGTZ */
     114        {0xfc1f0000, 0x5c000000},  /* BGTZL */
     115        {0xfc1f0000, 0x18000000},  /* BLEZ */
     116        {0xfc1f0000, 0x58000000},  /* BLEZL */
     117        {0xfc1f0000, 0x04000000},  /* BLTZ */
     118        {0xfc1f0000, 0x04100000},  /* BLTZAL */
     119        {0xfc1f0000, 0x04120000},  /* BLTZALL */
     120        {0xfc1f0000, 0x04020000},  /* BLTZL */
     121        {0xfc000000, 0x14000000},  /* BNE */
     122        {0xfc000000, 0x54000000},  /* BNEL */
     123        {0xfc000000, 0x08000000},  /* J */
     124        {0xfc000000, 0x0c000000},  /* JAL */
     125        {0xfc1f07ff, 0x00000009},  /* JALR */
     126        {0, 0}                     /* end of table */
     127};
    128128
    129129/** Test, if the given instruction is a jump or branch instruction
    130130 *
    131131 * @param instr Instruction code
    132  * @return true - it is jump instruction, false otherwise
     132 *
     133 * @return true if it is jump instruction, false otherwise
    133134 *
    134135 */
    135136static bool is_jump(unative_t instr)
    136137{
    137         int i;
    138 
     138        unsigned int i;
     139       
    139140        for (i = 0; jmpinstr[i].andmask; i++) {
    140141                if ((instr & jmpinstr[i].andmask) == jmpinstr[i].value)
    141142                        return true;
    142143        }
    143 
     144       
    144145        return false;
    145146}
    146147
    147 /** Add new breakpoint to table */
     148/** Add new breakpoint to table
     149 *
     150 */
    148151int cmd_add_breakpoint(cmd_arg_t *argv)
    149152{
    150         bpinfo_t *cur = NULL;
    151         ipl_t ipl;
    152         int i;
    153 
    154153        if (argv->intval & 0x3) {
    155154                printf("Not aligned instruction, forgot to use &symbol?\n");
    156155                return 1;
    157156        }
    158         ipl = interrupts_disable();
    159         spinlock_lock(&bkpoint_lock);
    160 
     157       
     158        irq_spinlock_lock(&bkpoint_lock, true);
     159       
    161160        /* Check, that the breakpoints do not conflict */
     161        unsigned int i;
    162162        for (i = 0; i < BKPOINTS_MAX; i++) {
    163                 if (breakpoints[i].address == (uintptr_t)argv->intval) {
     163                if (breakpoints[i].address == (uintptr_t) argv->intval) {
    164164                        printf("Duplicate breakpoint %d.\n", i);
    165                         spinlock_unlock(&bkpoint_lock);
    166                         interrupts_restore(ipl);
     165                        irq_spinlock_unlock(&bkpoint_lock, true);
    167166                        return 0;
    168                 } else if (breakpoints[i].address == (uintptr_t)argv->intval +
    169                     sizeof(unative_t) || breakpoints[i].address ==
    170                     (uintptr_t)argv->intval - sizeof(unative_t)) {
     167                } else if ((breakpoints[i].address == (uintptr_t) argv->intval +
     168                    sizeof(unative_t)) || (breakpoints[i].address ==
     169                    (uintptr_t) argv->intval - sizeof(unative_t))) {
    171170                        printf("Adjacent breakpoints not supported, conflict "
    172171                            "with %d.\n", i);
    173                         spinlock_unlock(&bkpoint_lock);
    174                         interrupts_restore(ipl);
     172                        irq_spinlock_unlock(&bkpoint_lock, true);
    175173                        return 0;
    176174                }
    177175               
    178176        }
    179 
    180         for (i = 0; i < BKPOINTS_MAX; i++)
     177       
     178        bpinfo_t *cur = NULL;
     179       
     180        for (i = 0; i < BKPOINTS_MAX; i++) {
    181181                if (!breakpoints[i].address) {
    182182                        cur = &breakpoints[i];
    183183                        break;
    184184                }
     185        }
     186       
    185187        if (!cur) {
    186188                printf("Too many breakpoints.\n");
    187                 spinlock_unlock(&bkpoint_lock);
    188                 interrupts_restore(ipl);
     189                irq_spinlock_unlock(&bkpoint_lock, true);
    189190                return 0;
    190191        }
     192       
     193        printf("Adding breakpoint on address %p\n", argv->intval);
     194       
    191195        cur->address = (uintptr_t) argv->intval;
    192         printf("Adding breakpoint on address: %p\n", argv->intval);
    193         cur->instruction = ((unative_t *)cur->address)[0];
    194         cur->nextinstruction = ((unative_t *)cur->address)[1];
     196        cur->instruction = ((unative_t *) cur->address)[0];
     197        cur->nextinstruction = ((unative_t *) cur->address)[1];
    195198        if (argv == &add_argv) {
    196199                cur->flags = 0;
    197         } else { /* We are add extended */
     200        } else {  /* We are add extended */
    198201                cur->flags = BKPOINT_FUNCCALL;
    199202                cur->bkfunc = (void (*)(void *, istate_t *)) argv[1].intval;
    200203        }
     204       
    201205        if (is_jump(cur->instruction))
    202206                cur->flags |= BKPOINT_ONESHOT;
     207       
    203208        cur->counter = 0;
    204 
     209       
    205210        /* Set breakpoint */
    206         *((unative_t *)cur->address) = 0x0d;
     211        *((unative_t *) cur->address) = 0x0d;
    207212        smc_coherence(cur->address);
    208 
    209         spinlock_unlock(&bkpoint_lock);
    210         interrupts_restore(ipl);
    211 
     213       
     214        irq_spinlock_unlock(&bkpoint_lock, true);
     215       
    212216        return 1;
    213217}
    214218
    215 /** Remove breakpoint from table */
     219/** Remove breakpoint from table
     220 *
     221 */
    216222int cmd_del_breakpoint(cmd_arg_t *argv)
    217223{
    218         bpinfo_t *cur;
    219         ipl_t ipl;
    220 
    221224        if (argv->intval > BKPOINTS_MAX) {
    222225                printf("Invalid breakpoint number.\n");
    223226                return 0;
    224227        }
    225         ipl = interrupts_disable();
    226         spinlock_lock(&bkpoint_lock);
    227 
    228         cur = &breakpoints[argv->intval];
     228       
     229        irq_spinlock_lock(&bkpoint_lock, true);
     230       
     231        bpinfo_t *cur = &breakpoints[argv->intval];
    229232        if (!cur->address) {
    230233                printf("Breakpoint does not exist.\n");
    231                 spinlock_unlock(&bkpoint_lock);
    232                 interrupts_restore(ipl);
     234                irq_spinlock_unlock(&bkpoint_lock, true);
    233235                return 0;
    234236        }
     237       
    235238        if ((cur->flags & BKPOINT_INPROG) && (cur->flags & BKPOINT_ONESHOT)) {
    236239                printf("Cannot remove one-shot breakpoint in-progress\n");
    237                 spinlock_unlock(&bkpoint_lock);
    238                 interrupts_restore(ipl);
     240                irq_spinlock_unlock(&bkpoint_lock, true);
    239241                return 0;
    240242        }
    241         ((uint32_t *)cur->address)[0] = cur->instruction;
    242         smc_coherence(((uint32_t *)cur->address)[0]);
    243         ((uint32_t *)cur->address)[1] = cur->nextinstruction;
    244         smc_coherence(((uint32_t *)cur->address)[1]);
    245 
     243       
     244        ((uint32_t *) cur->address)[0] = cur->instruction;
     245        smc_coherence(((uint32_t *) cur->address)[0]);
     246        ((uint32_t *) cur->address)[1] = cur->nextinstruction;
     247        smc_coherence(((uint32_t *) cur->address)[1]);
     248       
    246249        cur->address = NULL;
    247 
    248         spinlock_unlock(&bkpoint_lock);
    249         interrupts_restore(ipl);
     250       
     251        irq_spinlock_unlock(&bkpoint_lock, true);
    250252        return 1;
    251253}
    252254
    253 /** Print table of active breakpoints */
     255/** Print table of active breakpoints
     256 *
     257 */
    254258int cmd_print_breakpoints(cmd_arg_t *argv)
    255259{
     
    276280}
    277281
    278 #endif
    279 
    280 /** Initialize debugger */
     282#endif /* CONFIG_KCONSOLE */
     283
     284/** Initialize debugger
     285 *
     286 */
    281287void debugger_init()
    282288{
    283         int i;
    284 
     289        unsigned int i;
     290       
    285291        for (i = 0; i < BKPOINTS_MAX; i++)
    286292                breakpoints[i].address = NULL;
    287 
     293       
    288294#ifdef CONFIG_KCONSOLE
    289295        cmd_initialize(&bkpts_info);
    290296        if (!cmd_register(&bkpts_info))
    291297                printf("Cannot register command %s\n", bkpts_info.name);
    292 
     298       
    293299        cmd_initialize(&delbkpt_info);
    294300        if (!cmd_register(&delbkpt_info))
    295301                printf("Cannot register command %s\n", delbkpt_info.name);
    296 
     302       
    297303        cmd_initialize(&addbkpt_info);
    298304        if (!cmd_register(&addbkpt_info))
    299305                printf("Cannot register command %s\n", addbkpt_info.name);
    300 
     306       
    301307        cmd_initialize(&addbkpte_info);
    302308        if (!cmd_register(&addbkpte_info))
    303309                printf("Cannot register command %s\n", addbkpte_info.name);
    304 #endif
     310#endif /* CONFIG_KCONSOLE */
    305311}
    306312
    307313/** Handle breakpoint
    308314 *
    309  * Find breakpoint in breakpoint table. 
     315 * Find breakpoint in breakpoint table.
    310316 * If found, call kconsole, set break on next instruction and reexecute.
    311317 * If we are on "next instruction", set it back on the first and reexecute.
    312318 * If breakpoint not found in breakpoint table, call kconsole and start
    313319 * next instruction.
     320 *
    314321 */
    315322void debugger_bpoint(istate_t *istate)
    316323{
    317         bpinfo_t *cur = NULL;
    318         uintptr_t fireaddr = istate->epc;
    319         int i;
    320 
    321324        /* test branch delay slot */
    322325        if (cp0_cause_read() & 0x80000000)
    323326                panic("Breakpoint in branch delay slot not supported.");
    324 
    325         spinlock_lock(&bkpoint_lock);
     327       
     328        irq_spinlock_lock(&bkpoint_lock, false);
     329       
     330        bpinfo_t *cur = NULL;
     331        uintptr_t fireaddr = istate->epc;
     332        unsigned int i;
     333       
    326334        for (i = 0; i < BKPOINTS_MAX; i++) {
    327335                /* Normal breakpoint */
    328                 if (fireaddr == breakpoints[i].address &&
    329                     !(breakpoints[i].flags & BKPOINT_REINST)) {
     336                if ((fireaddr == breakpoints[i].address) &&
     337                    (!(breakpoints[i].flags & BKPOINT_REINST))) {
    330338                        cur = &breakpoints[i];
    331339                        break;
    332340                }
     341               
    333342                /* Reinst only breakpoint */
    334343                if ((breakpoints[i].flags & BKPOINT_REINST) &&
     
    338347                }
    339348        }
     349       
    340350        if (cur) {
    341351                if (cur->flags & BKPOINT_REINST) {
    342352                        /* Set breakpoint on first instruction */
    343                         ((uint32_t *)cur->address)[0] = 0x0d;
     353                        ((uint32_t *) cur->address)[0] = 0x0d;
    344354                        smc_coherence(((uint32_t *)cur->address)[0]);
     355                       
    345356                        /* Return back the second */
    346                         ((uint32_t *)cur->address)[1] = cur->nextinstruction;
    347                         smc_coherence(((uint32_t *)cur->address)[1]);
     357                        ((uint32_t *) cur->address)[1] = cur->nextinstruction;
     358                        smc_coherence(((uint32_t *) cur->address)[1]);
     359                       
    348360                        cur->flags &= ~BKPOINT_REINST;
    349                         spinlock_unlock(&bkpoint_lock);
     361                        irq_spinlock_unlock(&bkpoint_lock, false);
    350362                        return;
    351                 }
     363                }
     364               
    352365                if (cur->flags & BKPOINT_INPROG)
    353366                        printf("Warning: breakpoint recursion\n");
    354367               
    355368                if (!(cur->flags & BKPOINT_FUNCCALL)) {
    356                         printf("***Breakpoint %d: %p in %s.\n", i, fireaddr,
    357                             symtab_fmt_name_lookup(istate->epc));
    358                 }
    359 
     369                        printf("***Breakpoint %u: %p in %s.\n", i, fireaddr,
     370                            symtab_fmt_name_lookup(fireaddr));
     371                }
     372               
    360373                /* Return first instruction back */
    361374                ((uint32_t *)cur->address)[0] = cur->instruction;
     
    371384                printf("***Breakpoint %d: %p in %s.\n", i, fireaddr,
    372385                    symtab_fmt_name_lookup(fireaddr));
    373 
     386               
    374387                /* Move on to next instruction */
    375388                istate->epc += 4;
    376389        }
     390       
    377391        if (cur)
    378392                cur->counter++;
     393       
    379394        if (cur && (cur->flags & BKPOINT_FUNCCALL)) {
    380395                /* Allow zero bkfunc, just for counting */
     
    383398        } else {
    384399#ifdef CONFIG_KCONSOLE
    385                 /* This disables all other processors - we are not SMP,
     400                /*
     401                 * This disables all other processors - we are not SMP,
    386402                 * actually this gets us to cpu_halt, if scheduler() is run
    387403                 * - we generally do not want scheduler to be run from debug,
    388404                 *   so this is a good idea
    389                  */     
     405                 */
    390406                atomic_set(&haltstate, 1);
    391                 spinlock_unlock(&bkpoint_lock);
     407                irq_spinlock_unlock(&bkpoint_lock, false);
    392408               
    393409                kconsole("debug", "Debug console ready.\n", false);
    394410               
    395                 spinlock_lock(&bkpoint_lock);
     411                irq_spinlock_lock(&bkpoint_lock, false);
    396412                atomic_set(&haltstate, 0);
    397413#endif
    398414        }
    399         if (cur && cur->address == fireaddr && (cur->flags & BKPOINT_INPROG)) {
     415       
     416        if ((cur) && (cur->address == fireaddr)
     417            && ((cur->flags & BKPOINT_INPROG))) {
    400418                /* Remove one-shot breakpoint */
    401419                if ((cur->flags & BKPOINT_ONESHOT))
    402420                        cur->address = NULL;
     421               
    403422                /* Remove in-progress flag */
    404423                cur->flags &= ~BKPOINT_INPROG;
    405         }
    406         spinlock_unlock(&bkpoint_lock);
     424        }
     425       
     426        irq_spinlock_unlock(&bkpoint_lock, false);
    407427}
    408428
  • kernel/arch/mips32/src/exception.c

    r666f492 rda1bafb  
    2727 */
    2828
    29 /** @addtogroup mips32 
     29/** @addtogroup mips32
    3030 * @{
    3131 */
     
    6767        "Floating Point",
    6868        NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    69         "WatchHi/WatchLo", /* 23 */
     69        "WatchHi/WatchLo",  /* 23 */
    7070        NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    7171        "Virtual Coherency - data",
     
    7474static void print_regdump(istate_t *istate)
    7575{
    76         const char *pcsymbol = symtab_fmt_name_lookup(istate->epc);
    77         const char *rasymbol = symtab_fmt_name_lookup(istate->ra);
    78        
    79         printf("PC: %#x(%s) RA: %#x(%s), SP(%p)\n", istate->epc, pcsymbol,
    80             istate->ra, rasymbol, istate->sp);
     76        printf("PC: %#x(%s) RA: %#x(%s), SP(%p)\n", istate->epc,
     77            symtab_fmt_name_lookup(istate->epc), istate->ra,
     78            symtab_fmt_name_lookup(istate->ra), istate->sp);
    8179}
    8280
     
    135133static void interrupt_exception(int n, istate_t *istate)
    136134{
    137         uint32_t cause;
    138         int i;
     135        /* Decode interrupt number and process the interrupt */
     136        uint32_t cause = (cp0_cause_read() >> 8) & 0xff;
    139137       
    140         /* decode interrupt number and process the interrupt */
    141         cause = (cp0_cause_read() >> 8) & 0xff;
    142        
     138        unsigned int i;
    143139        for (i = 0; i < 8; i++) {
    144140                if (cause & (1 << i)) {
     
    149145                                 */
    150146                                irq->handler(irq);
    151                                 spinlock_unlock(&irq->lock);
     147                                irq_spinlock_unlock(&irq->lock, false);
    152148                        } else {
    153149                                /*
     
    172168{
    173169        int i;
    174 
     170       
    175171        /* Clear exception table */
    176172        for (i = 0; i < IVT_ITEMS; i++)
  • kernel/arch/mips32/src/interrupt.c

    r666f492 rda1bafb  
    4848function virtual_timer_fnc = NULL;
    4949static irq_t timer_irq;
     50
     51// TODO: This is SMP unsafe!!!
     52
     53uint32_t count_hi = 0;
     54static unsigned long nextcount;
     55static unsigned long lastcount;
    5056
    5157/** Disable interrupts.
     
    99105}
    100106
    101 /* TODO: This is SMP unsafe!!! */
    102 uint32_t count_hi = 0;
    103 static unsigned long nextcount;
    104 static unsigned long lastcount;
    105 
    106 /** Start hardware clock */
     107/** Start hardware clock
     108 *
     109 */
    107110static void timer_start(void)
    108111{
     
    119122static void timer_irq_handler(irq_t *irq)
    120123{
    121         unsigned long drift;
    122        
    123124        if (cp0_count_read() < lastcount)
    124125                /* Count overflow detected */
    125126                count_hi++;
     127       
    126128        lastcount = cp0_count_read();
    127129       
    128         drift = cp0_count_read() - nextcount;
     130        unsigned long drift = cp0_count_read() - nextcount;
    129131        while (drift > cp0_compare_value) {
    130132                drift -= cp0_compare_value;
    131133                CPU->missed_clock_ticks++;
    132134        }
     135       
    133136        nextcount = cp0_count_read() + cp0_compare_value - drift;
    134137        cp0_compare_write(nextcount);
     
    138141         * Release the lock, call clock() and reacquire the lock again.
    139142         */
    140         spinlock_unlock(&irq->lock);
     143        irq_spinlock_unlock(&irq->lock, false);
    141144        clock();
    142         spinlock_lock(&irq->lock);
     145        irq_spinlock_lock(&irq->lock, false);
    143146       
    144147        if (virtual_timer_fnc != NULL)
  • kernel/arch/ppc32/include/asm.h

    r666f492 rda1bafb  
    3939#include <config.h>
    4040#include <arch/cpu.h>
     41#include <arch/mm/asid.h>
    4142
    4243static inline uint32_t msr_read(void)
     
    5859                :: [msr] "r" (msr)
    5960        );
     61}
     62
     63static inline void sr_set(uint32_t flags, asid_t asid, uint32_t sr)
     64{
     65        asm volatile (
     66                "mtsrin %[value], %[sr]\n"
     67                :: [value] "r" ((flags << 16) + (asid << 4) + sr),
     68                   [sr] "r" (sr << 28)
     69        );
     70}
     71
     72static inline uint32_t sr_get(uint32_t vaddr)
     73{
     74        uint32_t vsid;
     75       
     76        asm volatile (
     77                "mfsrin %[vsid], %[vaddr]\n"
     78                : [vsid] "=r" (vsid)
     79                : [vaddr] "r" (vaddr)
     80        );
     81       
     82        return vsid;
     83}
     84
     85static inline uint32_t sdr1_get(void)
     86{
     87        uint32_t sdr1;
     88       
     89        asm volatile (
     90                "mfsdr1 %[sdr1]\n"
     91                : [sdr1] "=r" (sdr1)
     92        );
     93       
     94        return sdr1;
    6095}
    6196
  • kernel/arch/ppc32/include/mm/frame.h

    r666f492 rda1bafb  
    4646extern uintptr_t last_frame;
    4747
     48static inline uint32_t physmem_top(void)
     49{
     50        uint32_t physmem;
     51       
     52        asm volatile (
     53                "mfsprg3 %[physmem]\n"
     54                : [physmem] "=r" (physmem)
     55        );
     56       
     57        return physmem;
     58}
     59
    4860extern void frame_arch_init(void);
    4961extern void physmem_print(void);
  • kernel/arch/ppc32/src/debug/stacktrace.c

    r666f492 rda1bafb  
    6666bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
    6767{
    68         return false;
     68        return !copy_from_uspace((void *) prev,
     69            (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
    6970}
    7071
    7172bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
    7273{
    73         return false;
     74        return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,
     75            sizeof(*ra));
    7476}
    7577
  • kernel/arch/ppc32/src/mm/as.c

    r666f492 rda1bafb  
    5555void as_install_arch(as_t *as)
    5656{
    57         asid_t asid;
    5857        uint32_t sr;
    59 
    60         asid = as->asid;
    6158       
    6259        /* Lower 2 GB, user and supervisor access */
    63         for (sr = 0; sr < 8; sr++) {
    64                 asm volatile (
    65                         "mtsrin %0, %1\n"
    66                         :
    67                         : "r" ((0x6000 << 16) + (asid << 4) + sr), "r" (sr << 28)
    68                 );
    69         }
     60        for (sr = 0; sr < 8; sr++)
     61                sr_set(0x6000, as->asid, sr);
    7062       
    7163        /* Upper 2 GB, only supervisor access */
    72         for (sr = 8; sr < 16; sr++) {
    73                 asm volatile (
    74                         "mtsrin %0, %1\n"
    75                         :
    76                         : "r" ((0x4000 << 16) + (asid << 4) + sr), "r" (sr << 28)
    77                 );
    78         }
     64        for (sr = 8; sr < 16; sr++)
     65                sr_set(0x4000, as->asid, sr);
    7966}
    8067
  • kernel/arch/ppc32/src/mm/frame.c

    r666f492 rda1bafb  
    4545void physmem_print(void)
    4646{
    47         unsigned int i;
    48        
    4947        printf("Base       Size\n");
    5048        printf("---------- ----------\n");
    51                
     49       
     50        size_t i;
    5251        for (i = 0; i < memmap.cnt; i++) {
    5352                printf("%#10x %#10x\n", memmap.zones[i].start,
    54                         memmap.zones[i].size);
     53                    memmap.zones[i].size);
    5554        }
    5655}
     
    6059        pfn_t minconf = 2;
    6160        size_t i;
    62         pfn_t start, conf;
    63         size_t size;
    6461       
    6562        for (i = 0; i < memmap.cnt; i++) {
    66                 start = ADDR2PFN(ALIGN_UP((uintptr_t) memmap.zones[i].start, FRAME_SIZE));
    67                 size = SIZE2FRAMES(ALIGN_DOWN(memmap.zones[i].size, FRAME_SIZE));
     63                pfn_t start = ADDR2PFN(ALIGN_UP((uintptr_t) memmap.zones[i].start,
     64                    FRAME_SIZE));
     65                size_t size = SIZE2FRAMES(ALIGN_DOWN(memmap.zones[i].size, FRAME_SIZE));
    6866               
     67                pfn_t conf;
    6968                if ((minconf < start) || (minconf >= start + size))
    7069                        conf = start;
     
    7372               
    7473                zone_create(start, size, conf, 0);
    75                 if (last_frame < ALIGN_UP((uintptr_t) memmap.zones[i].start + memmap.zones[i].size, FRAME_SIZE))
    76                         last_frame = ALIGN_UP((uintptr_t) memmap.zones[i].start + memmap.zones[i].size, FRAME_SIZE);
     74                if (last_frame < ALIGN_UP((uintptr_t) memmap.zones[i].start
     75                    + memmap.zones[i].size, FRAME_SIZE))
     76                        last_frame = ALIGN_UP((uintptr_t) memmap.zones[i].start
     77                            + memmap.zones[i].size, FRAME_SIZE);
    7778        }
    7879       
     
    8283       
    8384        /* Mark the Page Hash Table frames as unavailable */
    84         uint32_t sdr1;
    85         asm volatile (
    86                 "mfsdr1 %0\n"
    87                 : "=r" (sdr1)
    88         );
    89         frame_mark_unavailable(ADDR2PFN(sdr1 & 0xffff000), 16); // FIXME
     85        uint32_t sdr1 = sdr1_get();
     86       
     87        // FIXME: compute size of PHT exactly
     88        frame_mark_unavailable(ADDR2PFN(sdr1 & 0xffff000), 16);
    9089}
    9190
  • kernel/arch/ppc32/src/mm/tlb.c

    r666f492 rda1bafb  
    4545
    4646static unsigned int seed = 10;
    47 static unsigned int seed_real __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    48 
     47static unsigned int seed_real
     48    __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    4949
    5050/** Try to find PTE for faulting address
     
    5454 * if lock is true.
    5555 *
    56  * @param as            Address space.
    57  * @param lock          Lock/unlock the address space.
    58  * @param badvaddr      Faulting virtual address.
    59  * @param access        Access mode that caused the fault.
    60  * @param istate        Pointer to interrupted state.
    61  * @param pfrc          Pointer to variable where as_page_fault() return code
    62  *                      will be stored.
    63  * @return              PTE on success, NULL otherwise.
    64  *
    65  */
    66 static pte_t *
    67 find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr, int access,
    68     istate_t *istate, int *pfrc)
     56 * @param as       Address space.
     57 * @param lock     Lock/unlock the address space.
     58 * @param badvaddr Faulting virtual address.
     59 * @param access   Access mode that caused the fault.
     60 * @param istate   Pointer to interrupted state.
     61 * @param pfrc     Pointer to variable where as_page_fault() return code
     62 *                 will be stored.
     63 *
     64 * @return PTE on success, NULL otherwise.
     65 *
     66 */
     67static pte_t *find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr,
     68    int access, istate_t *istate, int *pfrc)
    6969{
    7070        /*
    7171         * Check if the mapping exists in page tables.
    72          */     
     72         */
    7373        pte_t *pte = page_mapping_find(as, badvaddr);
    7474        if ((pte) && (pte->present)) {
     
    7979                return pte;
    8080        } else {
    81                 int rc;
    82        
    8381                /*
    8482                 * Mapping not found in page tables.
     
    8684                 */
    8785                page_table_unlock(as, lock);
    88                 switch (rc = as_page_fault(badvaddr, access, istate)) {
     86               
     87                int rc = as_page_fault(badvaddr, access, istate);
     88                switch (rc) {
    8989                case AS_PF_OK:
    9090                        /*
     
    107107                default:
    108108                        panic("Unexpected rc (%d).", rc);
    109                 }       
    110         }
    111 }
    112 
     109                }
     110        }
     111}
    113112
    114113static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
     
    123122}
    124123
    125 
    126124static void pht_insert(const uintptr_t vaddr, const pte_t *pte)
    127125{
     
    129127        uint32_t api = (vaddr >> 22) & 0x3f;
    130128       
    131         uint32_t vsid;
    132         asm volatile (
    133                 "mfsrin %0, %1\n"
    134                 : "=r" (vsid)
    135                 : "r" (vaddr)
    136         );
    137        
    138         uint32_t sdr1;
    139         asm volatile (
    140                 "mfsdr1 %0\n"
    141                 : "=r" (sdr1)
    142         );
     129        uint32_t vsid = sr_get(vaddr);
     130        uint32_t sdr1 = sdr1_get();
     131       
     132        // FIXME: compute size of PHT exactly
    143133        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    144134       
     
    215205}
    216206
    217 
    218207/** Process Instruction/Data Storage Exception
    219208 *
     
    224213void pht_refill(int n, istate_t *istate)
    225214{
    226         uintptr_t badvaddr;
    227         pte_t *pte;
    228         int pfrc;
    229215        as_t *as;
    230216        bool lock;
     
    238224        }
    239225       
     226        uintptr_t badvaddr;
     227       
    240228        if (n == VECTOR_DATA_STORAGE)
    241229                badvaddr = istate->dar;
    242230        else
    243231                badvaddr = istate->pc;
    244                
     232       
    245233        page_table_lock(as, lock);
    246234       
    247         pte = find_mapping_and_check(as, lock, badvaddr,
     235        int pfrc;
     236        pte_t *pte = find_mapping_and_check(as, lock, badvaddr,
    248237            PF_ACCESS_READ /* FIXME */, istate, &pfrc);
     238       
    249239        if (!pte) {
    250240                switch (pfrc) {
     
    264254        }
    265255       
    266         pte->accessed = 1; /* Record access to PTE */
     256        /* Record access to PTE */
     257        pte->accessed = 1;
    267258        pht_insert(badvaddr, pte);
    268259       
     
    274265        pht_refill_fail(badvaddr, istate);
    275266}
    276 
    277267
    278268/** Process Instruction/Data Storage Exception in Real Mode
     
    291281                badvaddr = istate->pc;
    292282       
    293         uint32_t physmem;
    294         asm volatile (
    295                 "mfsprg3 %0\n"
    296                 : "=r" (physmem)
    297         );
     283        uint32_t physmem = physmem_top();
    298284       
    299285        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    303289        uint32_t api = (badvaddr >> 22) & 0x3f;
    304290       
    305         uint32_t vsid;
    306         asm volatile (
    307                 "mfsrin %0, %1\n"
    308                 : "=r" (vsid)
    309                 : "r" (badvaddr)
    310         );
    311        
    312         uint32_t sdr1;
    313         asm volatile (
    314                 "mfsdr1 %0\n"
    315                 : "=r" (sdr1)
    316         );
     291        uint32_t vsid = sr_get(badvaddr);
     292        uint32_t sdr1 = sdr1_get();
     293       
     294        // FIXME: compute size of PHT exactly
    317295        phte_t *phte_real = (phte_t *) (sdr1 & 0xffff0000);
    318296       
     
    396374}
    397375
    398 
    399376/** Process ITLB/DTLB Miss Exception in Real Mode
    400377 *
     
    404381{
    405382        uint32_t badvaddr = tlbmiss & 0xfffffffc;
    406        
    407         uint32_t physmem;
    408         asm volatile (
    409                 "mfsprg3 %0\n"
    410                 : "=r" (physmem)
    411         );
     383        uint32_t physmem = physmem_top();
    412384       
    413385        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    420392        uint32_t index = 0;
    421393        asm volatile (
    422                 "mtspr 981, %0\n"
    423                 "mtspr 982, %1\n"
    424                 "tlbld %2\n"
    425                 "tlbli %2\n"
    426                 : "=r" (index)
    427                 : "r" (ptehi),
    428                   "r" (ptelo)
     394                "mtspr 981, %[ptehi]\n"
     395                "mtspr 982, %[ptelo]\n"
     396                "tlbld %[index]\n"
     397                "tlbli %[index]\n"
     398                : [index] "=r" (index)
     399                : [ptehi] "r" (ptehi),
     400                  [ptelo] "r" (ptelo)
    429401        );
    430402}
    431403
    432 
    433404void tlb_arch_init(void)
    434405{
     
    436407}
    437408
    438 
    439409void tlb_invalidate_all(void)
    440410{
    441411        uint32_t index;
     412       
    442413        asm volatile (
    443                 "li %0, 0\n"
     414                "li %[index], 0\n"
    444415                "sync\n"
    445416               
    446417                ".rept 64\n"
    447                 "tlbie %0\n"
    448                 "addi %0, %0, 0x1000\n"
     418                "       tlbie %[index]\n"
     419                "       addi %[index], %[index], 0x1000\n"
    449420                ".endr\n"
    450421               
     
    452423                "tlbsync\n"
    453424                "sync\n"
    454                 : "=r" (index)
     425                : [index] "=r" (index)
    455426        );
    456427}
    457428
    458 
    459429void tlb_invalidate_asid(asid_t asid)
    460430{
    461         uint32_t sdr1;
    462         asm volatile (
    463                 "mfsdr1 %0\n"
    464                 : "=r" (sdr1)
    465         );
     431        uint32_t sdr1 = sdr1_get();
     432       
     433        // FIXME: compute size of PHT exactly
    466434        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    467435       
    468         uint32_t i;
     436        size_t i;
    469437        for (i = 0; i < 8192; i++) {
    470438                if ((phte[i].v) && (phte[i].vsid >= (asid << 4)) &&
     
    472440                        phte[i].v = 0;
    473441        }
     442       
    474443        tlb_invalidate_all();
    475444}
    476 
    477445
    478446void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
     
    482450}
    483451
    484 
    485452#define PRINT_BAT(name, ureg, lreg) \
    486453        asm volatile ( \
    487                 "mfspr %0," #ureg "\n" \
    488                 "mfspr %1," #lreg "\n" \
    489                 : "=r" (upper), "=r" (lower) \
     454                "mfspr %[upper], " #ureg "\n" \
     455                "mfspr %[lower], " #lreg "\n" \
     456                : [upper] "=r" (upper), \
     457                  [lower] "=r" (lower) \
    490458        ); \
     459        \
    491460        mask = (upper & 0x1ffc) >> 2; \
    492461        if (upper & 3) { \
    493462                uint32_t tmp = mask; \
    494463                length = 128; \
     464                \
    495465                while (tmp) { \
    496466                        if ((tmp & 1) == 0) { \
     
    503473        } else \
    504474                length = 0; \
     475        \
    505476        printf(name ": page=%.*p frame=%.*p length=%d KB (mask=%#x)%s%s\n", \
    506477            sizeof(upper) * 2, upper & 0xffff0000, sizeof(lower) * 2, \
     
    515486       
    516487        for (sr = 0; sr < 16; sr++) {
    517                 uint32_t vsid;
    518                 asm volatile (
    519                         "mfsrin %0, %1\n"
    520                         : "=r" (vsid)
    521                         : "r" (sr << 28)
    522                 );
     488                uint32_t vsid = sr_get(sr << 28);
     489               
    523490                printf("sr[%02u]: vsid=%.*p (asid=%u)%s%s\n", sr,
    524491                    sizeof(vsid) * 2, vsid & 0xffffff, (vsid & 0xffffff) >> 4,
  • kernel/arch/sparc64/src/mm/sun4u/as.c

    r666f492 rda1bafb  
    4141
    4242#ifdef CONFIG_TSB
     43
    4344#include <arch/mm/tsb.h>
    4445#include <arch/memstr.h>
     
    4748#include <bitops.h>
    4849#include <macros.h>
     50
    4951#endif /* CONFIG_TSB */
    5052
     
    5860}
    5961
    60 int as_constructor_arch(as_t *as, int flags)
     62int as_constructor_arch(as_t *as, unsigned int flags)
    6163{
    6264#ifdef CONFIG_TSB
     
    6466         * The order must be calculated with respect to the emulated
    6567         * 16K page size.
    66          */
    67         int order = fnzb32(((ITSB_ENTRY_COUNT + DTSB_ENTRY_COUNT) *
     68         *
     69         */
     70        uint8_t order = fnzb32(((ITSB_ENTRY_COUNT + DTSB_ENTRY_COUNT) *
    6871            sizeof(tsb_entry_t)) >> FRAME_WIDTH);
    69 
     72       
    7073        uintptr_t tsb = (uintptr_t) frame_alloc(order, flags | FRAME_KA);
    71 
     74       
    7275        if (!tsb)
    7376                return -1;
    74 
     77       
    7578        as->arch.itsb = (tsb_entry_t *) tsb;
    7679        as->arch.dtsb = (tsb_entry_t *) (tsb + ITSB_ENTRY_COUNT *
    7780            sizeof(tsb_entry_t));
    78 
     81       
    7982        memsetb(as->arch.itsb,
    8083            (ITSB_ENTRY_COUNT + DTSB_ENTRY_COUNT) * sizeof(tsb_entry_t), 0);
    8184#endif
     85       
    8286        return 0;
    8387}
     
    9397            sizeof(tsb_entry_t)) >> FRAME_WIDTH;
    9498        frame_free(KA2PA((uintptr_t) as->arch.itsb));
     99       
    95100        return cnt;
    96101#else
     
    99104}
    100105
    101 int as_create_arch(as_t *as, int flags)
     106int as_create_arch(as_t *as, unsigned int flags)
    102107{
    103108#ifdef CONFIG_TSB
    104109        tsb_invalidate(as, 0, (size_t) -1);
    105110#endif
     111       
    106112        return 0;
    107113}
     
    123129         *
    124130         * Moreover, the as->asid is protected by asidlock, which is being held.
     131         *
    125132         */
    126133       
     
    130137         * secondary context register from the TL=1 code just before switch to
    131138         * userspace.
     139         *
    132140         */
    133141        ctx.v = 0;
    134142        ctx.context = as->asid;
    135143        mmu_secondary_context_write(ctx.v);
    136 
    137 #ifdef CONFIG_TSB       
     144       
     145#ifdef CONFIG_TSB
    138146        uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
    139 
     147       
    140148        ASSERT(as->arch.itsb && as->arch.dtsb);
    141 
     149       
    142150        uintptr_t tsb = (uintptr_t) as->arch.itsb;
    143                
     151       
    144152        if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
    145153                /*
     
    147155                 * by the locked 4M kernel DTLB entry. We need
    148156                 * to map both TSBs explicitly.
     157                 *
    149158                 */
    150159                dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, tsb);
    151160                dtlb_insert_mapping(tsb, KA2PA(tsb), PAGESIZE_64K, true, true);
    152161        }
    153                
     162       
    154163        /*
    155164         * Setup TSB Base registers.
     165         *
    156166         */
    157167        tsb_base_reg_t tsb_base;
    158                
     168       
    159169        tsb_base.value = 0;
    160170        tsb_base.size = TSB_SIZE;
    161171        tsb_base.split = 0;
    162 
     172       
    163173        tsb_base.base = ((uintptr_t) as->arch.itsb) >> MMU_PAGE_WIDTH;
    164174        itsb_base_write(tsb_base.value);
     
    175185         * Clearing the extension registers will ensure that the value of the
    176186         * TSB Base register will be used as an address of TSB, making the code
    177          * compatible with the US port.
     187         * compatible with the US port.
     188         *
    178189         */
    179190        itsb_primary_extension_write(0);
     
    195206void as_deinstall_arch(as_t *as)
    196207{
    197 
    198208        /*
    199209         * Note that we don't and may not lock the address space. That's ok
     
    201211         *
    202212         * Moreover, the as->asid is protected by asidlock, which is being held.
    203          */
    204 
     213         *
     214         */
     215       
    205216#ifdef CONFIG_TSB
    206217        uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
    207 
     218       
    208219        ASSERT(as->arch.itsb && as->arch.dtsb);
    209 
     220       
    210221        uintptr_t tsb = (uintptr_t) as->arch.itsb;
    211                
     222       
    212223        if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
    213224                /*
  • kernel/arch/sparc64/src/mm/sun4v/as.c

    r666f492 rda1bafb  
    4444
    4545#ifdef CONFIG_TSB
     46
    4647#include <arch/mm/tsb.h>
    4748#include <arch/memstr.h>
     
    5051#include <bitops.h>
    5152#include <macros.h>
     53
    5254#endif /* CONFIG_TSB */
    5355
     
    6163}
    6264
    63 int as_constructor_arch(as_t *as, int flags)
     65int as_constructor_arch(as_t *as, unsigned int flags)
    6466{
    6567#ifdef CONFIG_TSB
    66         int order = fnzb32(
     68        uint8_t order = fnzb32(
    6769                (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH);
    68 
     70       
    6971        uintptr_t tsb = (uintptr_t) frame_alloc(order, flags);
    70 
     72       
    7173        if (!tsb)
    7274                return -1;
    73 
     75       
    7476        as->arch.tsb_description.page_size = PAGESIZE_8K;
    7577        as->arch.tsb_description.associativity = 1;
     
    7981        as->arch.tsb_description.reserved = 0;
    8082        as->arch.tsb_description.context = 0;
    81 
     83       
    8284        memsetb((void *) PA2KA(as->arch.tsb_description.tsb_base),
    8385                TSB_ENTRY_COUNT * sizeof(tsb_entry_t), 0);
    8486#endif
     87       
    8588        return 0;
    8689}
     
    9194        size_t cnt = (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH;
    9295        frame_free((uintptr_t) as->arch.tsb_description.tsb_base);
     96       
    9397        return cnt;
    9498#else
     
    97101}
    98102
    99 int as_create_arch(as_t *as, int flags)
     103int as_create_arch(as_t *as, unsigned int flags)
    100104{
    101105#ifdef CONFIG_TSB
    102106        tsb_invalidate(as, 0, (size_t) -1);
    103107#endif
     108       
    104109        return 0;
    105110}
     
    111116 *
    112117 * @param as Address space.
     118 *
    113119 */
    114120void as_install_arch(as_t *as)
    115121{
    116122        mmu_secondary_context_write(as->asid);
    117 #ifdef CONFIG_TSB       
     123       
     124#ifdef CONFIG_TSB
    118125        uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
    119 
     126       
    120127        ASSERT(as->arch.tsb_description.tsb_base);
    121128        uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
    122                
     129       
    123130        if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
    124131                /*
     
    126133                 * by the locked 4M kernel DTLB entry. We need
    127134                 * to map both TSBs explicitly.
     135                 *
    128136                 */
    129137                mmu_demap_page(tsb, 0, MMU_FLAG_DTLB);
    130138                dtlb_insert_mapping(tsb, KA2PA(tsb), PAGESIZE_64K, true, true);
    131139        }
    132 
     140       
    133141        __hypercall_fast2(MMU_TSB_CTXNON0, 1, KA2PA(&(as->arch.tsb_description)));
    134        
    135142#endif
    136143}
     
    142149 *
    143150 * @param as Address space.
     151 *
    144152 */
    145153void as_deinstall_arch(as_t *as)
    146154{
    147 
    148155        /*
    149156         * Note that we don't and may not lock the address space. That's ok
     
    151158         *
    152159         * Moreover, the as->asid is protected by asidlock, which is being held.
     160         *
    153161         */
    154 
     162       
    155163#ifdef CONFIG_TSB
    156164        uintptr_t base = ALIGN_DOWN(config.base, 1 << KERNEL_PAGE_WIDTH);
    157 
     165       
    158166        ASSERT(as->arch.tsb_description.tsb_base);
    159 
     167       
    160168        uintptr_t tsb = PA2KA(as->arch.tsb_description.tsb_base);
    161                
     169       
    162170        if (!overlaps(tsb, 8 * MMU_PAGE_SIZE, base, 1 << KERNEL_PAGE_WIDTH)) {
    163171                /*
     
    165173                 * by the locked 4M kernel DTLB entry. We need
    166174                 * to demap the entry installed by as_install_arch().
     175                 *
    167176                 */
    168177                __hypercall_fast3(MMU_UNMAP_PERM_ADDR, tsb, 0, MMU_FLAG_DTLB);
  • kernel/arch/sparc64/src/trap/sun4u/interrupt.c

    r666f492 rda1bafb  
    5555void interrupt(int n, istate_t *istate)
    5656{
    57         uint64_t status;
    58         uint64_t intrcv;
    59         uint64_t data0;
    60         status = asi_u64_read(ASI_INTR_DISPATCH_STATUS, 0);
     57        uint64_t status = asi_u64_read(ASI_INTR_DISPATCH_STATUS, 0);
    6158        if (status & (!INTR_DISPATCH_STATUS_BUSY))
    6259                panic("Interrupt Dispatch Status busy bit not set\n");
    63 
    64         intrcv = asi_u64_read(ASI_INTR_RECEIVE, 0);
     60       
     61        uint64_t intrcv = asi_u64_read(ASI_INTR_RECEIVE, 0);
    6562#if defined (US)
    66         data0 = asi_u64_read(ASI_INTR_R, ASI_UDB_INTR_R_DATA_0);
     63        uint64_t data0 = asi_u64_read(ASI_INTR_R, ASI_UDB_INTR_R_DATA_0);
    6764#elif defined (US3)
    68         data0 = asi_u64_read(ASI_INTR_R, VA_INTR_R_DATA_0);
     65        uint64_t data0 = asi_u64_read(ASI_INTR_R, VA_INTR_R_DATA_0);
    6966#endif
    70 
     67       
    7168        irq_t *irq = irq_dispatch_and_lock(data0);
    7269        if (irq) {
     
    7572                 */
    7673                irq->handler(irq);
     74               
    7775                /*
    7876                 * See if there is a clear-interrupt-routine and call it.
    7977                 */
    80                 if (irq->cir) {
     78                if (irq->cir)
    8179                        irq->cir(irq->cir_arg, irq->inr);
    82                 }
    83                 spinlock_unlock(&irq->lock);
     80               
     81                irq_spinlock_unlock(&irq->lock, false);
    8482        } else if (data0 > config.base) {
    8583                /*
     
    9088                 */
    9189#ifdef CONFIG_SMP
    92                 if (data0 == (uintptr_t) tlb_shootdown_ipi_recv) {
     90                if (data0 == (uintptr_t) tlb_shootdown_ipi_recv)
    9391                        tlb_shootdown_ipi_recv();
    94                 }
    9592#endif
    9693        } else {
     
    10198                printf("cpu%u: spurious interrupt (intrcv=%#" PRIx64
    10299                    ", data0=%#" PRIx64 ")\n", CPU->id, intrcv, data0);
     100#else
     101                (void) intrcv;
    103102#endif
    104103        }
    105 
     104       
    106105        membar();
    107106        asi_u64_write(ASI_INTR_RECEIVE, 0, 0);
Note: See TracChangeset for help on using the changeset viewer.