Changeset 6a44ee4 in mainline for kernel/generic/src


Ignore:
Timestamp:
2011-07-20T15:26:21Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/generic/src
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/btree.c

    r25bef0ff r6a44ee4  
    108108void btree_create(btree_t *t)
    109109{
    110         list_initialize(&t->leaf_head);
     110        list_initialize(&t->leaf_list);
    111111        t->root = (btree_node_t *) slab_alloc(btree_node_slab, 0);
    112112        node_initialize(t->root);
    113         list_append(&t->root->leaf_link, &t->leaf_head);
     113        list_append(&t->root->leaf_link, &t->leaf_list);
    114114}
    115115
     
    588588               
    589589                if (LEAF_NODE(node)) {
    590                         list_prepend(&rnode->leaf_link, &node->leaf_link);
     590                        list_insert_after(&rnode->leaf_link, &node->leaf_link);
    591591                }
    592592               
     
    953953        ASSERT(LEAF_NODE(node));
    954954       
    955         if (node->leaf_link.prev != &t->leaf_head)
     955        if (node->leaf_link.prev != &t->leaf_list.head)
    956956                return list_get_instance(node->leaf_link.prev, btree_node_t, leaf_link);
    957957        else
     
    972972        ASSERT(LEAF_NODE(node));
    973973       
    974         if (node->leaf_link.next != &t->leaf_head)
     974        if (node->leaf_link.next != &t->leaf_list.head)
    975975                return list_get_instance(node->leaf_link.next, btree_node_t, leaf_link);
    976976        else
     
    987987        size_t i;
    988988        int depth = t->root->depth;
    989         link_t head, *cur;
     989        list_t list;
    990990       
    991991        printf("Printing B-tree:\n");
    992         list_initialize(&head);
    993         list_append(&t->root->bfs_link, &head);
     992        list_initialize(&list);
     993        list_append(&t->root->bfs_link, &list);
    994994       
    995995        /*
     
    997997         * Levels are distinguished from one another by node->depth.
    998998         */
    999         while (!list_empty(&head)) {
     999        while (!list_empty(&list)) {
    10001000                link_t *hlp;
    10011001                btree_node_t *node;
    10021002               
    1003                 hlp = head.next;
    1004                 ASSERT(hlp != &head);
     1003                hlp = list_first(&list);
     1004                ASSERT(hlp != NULL);
    10051005                node = list_get_instance(hlp, btree_node_t, bfs_link);
    10061006                list_remove(hlp);
     
    10181018                        printf("%" PRIu64 "%s", node->key[i], i < node->keys - 1 ? "," : "");
    10191019                        if (node->depth && node->subtree[i]) {
    1020                                 list_append(&node->subtree[i]->bfs_link, &head);
     1020                                list_append(&node->subtree[i]->bfs_link, &list);
    10211021                        }
    10221022                }
    10231023               
    10241024                if (node->depth && node->subtree[i])
    1025                         list_append(&node->subtree[i]->bfs_link, &head);
     1025                        list_append(&node->subtree[i]->bfs_link, &list);
    10261026               
    10271027                printf(")");
     
    10311031       
    10321032        printf("Printing list of leaves:\n");
    1033         for (cur = t->leaf_head.next; cur != &t->leaf_head; cur = cur->next) {
     1033        list_foreach(t->leaf_list, cur) {
    10341034                btree_node_t *node;
    10351035               
  • kernel/generic/src/adt/hash_table.c

    r25bef0ff r6a44ee4  
    6262        ASSERT(max_keys > 0);
    6363       
    64         h->entry = (link_t *) malloc(m * sizeof(link_t), 0);
     64        h->entry = (list_t *) malloc(m * sizeof(list_t), 0);
    6565        if (!h->entry)
    6666                panic("Cannot allocate memory for hash table.");
    6767       
    68         memsetb(h->entry, m * sizeof(link_t), 0);
     68        memsetb(h->entry, m * sizeof(list_t), 0);
    6969       
    7070        for (i = 0; i < m; i++)
     
    107107link_t *hash_table_find(hash_table_t *h, sysarg_t key[])
    108108{
    109         link_t *cur;
    110109        size_t chain;
    111110       
     
    118117        ASSERT(chain < h->entries);
    119118       
    120         for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) {
     119        list_foreach(h->entry[chain], cur) {
    121120                if (h->op->compare(key, h->max_keys, cur)) {
    122121                        /*
     
    141140{
    142141        size_t chain;
    143         link_t *cur;
    144142       
    145143        ASSERT(h);
     
    149147        ASSERT(keys <= h->max_keys);
    150148       
     149       
    151150        if (keys == h->max_keys) {
    152        
     151                link_t *cur;
     152               
    153153                /*
    154154                 * All keys are known, hash_table_find() can be used to find the entry.
     
    169169         */
    170170        for (chain = 0; chain < h->entries; chain++) {
    171                 for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) {
     171                link_t *cur;
     172                for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head;
     173                    cur = cur->next) {
    172174                        if (h->op->compare(key, keys, cur)) {
    173175                                link_t *hlp;
  • kernel/generic/src/adt/list.c

    r25bef0ff r6a44ee4  
    4343/** Check for membership
    4444 *
    45  * Check whether link is contained in the list head.
    46  * The membership is defined as pointer equivalence.
     45 * Check whether link is contained in a list.
     46 * Membership is defined as pointer equivalence.
    4747 *
    48  * @param link Item to look for.
    49  * @param head List to look in.
     48 * @param link  Item to look for.
     49 * @param list  List to look in.
    5050 *
    5151 * @return true if link is contained in head, false otherwise.
    5252 *
    5353 */
    54 int list_member(const link_t *link, const link_t *head)
     54int list_member(const link_t *link, const list_t *list)
    5555{
    5656        bool found = false;
    57         link_t *hlp = head->next;
     57        link_t *hlp = list->head.next;
    5858       
    59         while (hlp != head) {
     59        while (hlp != &list->head) {
    6060                if (hlp == link) {
    6161                        found = true;
     
    6868}
    6969
    70 
    7170/** Concatenate two lists
    7271 *
    73  * Concatenate lists head1 and head2, producing a single
    74  * list head1 containing items from both (in head1, head2
    75  * order) and empty list head2.
     72 * Concatenate lists @a list1 and @a list2, producing a single
     73 * list @a list1 containing items from both (in @a list1, @a list2
     74 * order) and empty list @a list2.
    7675 *
    77  * @param head1 First list and concatenated output
    78  * @param head2 Second list and empty output.
     76 * @param list1         First list and concatenated output
     77 * @param list2         Second list and empty output.
    7978 *
    8079 */
    81 void list_concat(link_t *head1, link_t *head2)
     80void list_concat(list_t *list1, list_t *list2)
    8281{
    83         if (list_empty(head2))
     82        if (list_empty(list2))
    8483                return;
    8584
    86         head2->next->prev = head1->prev;
    87         head2->prev->next = head1;     
    88         head1->prev->next = head2->next;
    89         head1->prev = head2->prev;
    90         list_initialize(head2);
     85        list2->head.next->prev = list1->head.prev;
     86        list2->head.prev->next = &list1->head;
     87        list1->head.prev->next = list2->head.next;
     88        list1->head.prev = list2->head.prev;
     89        list_initialize(list2);
     90}
     91
     92/** Count list items
     93 *
     94 * Return the number of items in the list.
     95 *
     96 * @param list          List to count.
     97 * @return              Number of items in the list.
     98 */
     99unsigned int list_count(const list_t *list)
     100{
     101        unsigned int count = 0;
     102       
     103        list_foreach(*list, link) {
     104                count++;
     105        }
     106       
     107        return count;
    91108}
    92109
  • kernel/generic/src/console/cmd.c

    r25bef0ff r6a44ee4  
    573573        spinlock_lock(&cmd_lock);
    574574       
    575         link_t *cur;
    576575        size_t len = 0;
    577         for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
     576        list_foreach(cmd_list, cur) {
    578577                cmd_info_t *hlp;
    579578                hlp = list_get_instance(cur, cmd_info_t, link);
     
    591590        }
    592591       
    593         for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
     592        list_foreach(cmd_list, cur) {
    594593                cmd_info_t *hlp;
    595594                hlp = list_get_instance(cur, cmd_info_t, link);
     
    646645int cmd_desc(cmd_arg_t *argv)
    647646{
    648         link_t *cur;
    649        
    650647        spinlock_lock(&cmd_lock);
    651648       
    652         for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
     649        list_foreach(cmd_list, cur) {
    653650                cmd_info_t *hlp;
    654651               
  • kernel/generic/src/console/console.c

    r25bef0ff r6a44ee4  
    8787};
    8888
    89 static void stdout_write(outdev_t *, wchar_t, bool);
     89static void stdout_write(outdev_t *, wchar_t);
    9090static void stdout_redraw(outdev_t *);
    9191
     
    9595};
    9696
    97 /** Silence output */
    98 bool silent = false;
     97/** Override kernel console lockout */
     98bool console_override = false;
    9999
    100100/** Standard input and output character devices */
     
    122122}
    123123
    124 static void stdout_write(outdev_t *dev, wchar_t ch, bool silent)
    125 {
    126         link_t *cur;
    127        
    128         for (cur = dev->list.next; cur != &dev->list; cur = cur->next) {
     124static void stdout_write(outdev_t *dev, wchar_t ch)
     125{
     126        list_foreach(dev->list, cur) {
    129127                outdev_t *sink = list_get_instance(cur, outdev_t, link);
    130128                if ((sink) && (sink->op->write))
    131                         sink->op->write(sink, ch, silent);
     129                        sink->op->write(sink, ch);
    132130        }
    133131}
     
    135133static void stdout_redraw(outdev_t *dev)
    136134{
    137         link_t *cur;
    138        
    139         for (cur = dev->list.next; cur != &dev->list; cur = cur->next) {
     135        list_foreach(dev->list, cur) {
    140136                outdev_t *sink = list_get_instance(cur, outdev_t, link);
    141137                if ((sink) && (sink->op->redraw))
     
    160156        klog_parea.frames = SIZE2FRAMES(sizeof(klog));
    161157        klog_parea.unpriv = false;
     158        klog_parea.mapped = false;
    162159        ddi_parea_register(&klog_parea);
    163160       
     
    171168void grab_console(void)
    172169{
    173         bool prev = silent;
    174        
    175         silent = false;
     170        bool prev = console_override;
     171       
     172        console_override = true;
    176173        if ((stdout) && (stdout->op->redraw))
    177174                stdout->op->redraw(stdout);
    178175       
    179         if ((stdin) && (prev)) {
     176        if ((stdin) && (!prev)) {
    180177                /*
    181178                 * Force the console to print the prompt.
     
    187184void release_console(void)
    188185{
    189         // FIXME arch_release_console
    190         silent = true;
    191 }
    192 
    193 /** Tell kernel to get keyboard/console access again */
    194 sysarg_t sys_debug_enable_console(void)
     186        console_override = false;
     187}
     188
     189/** Activate kernel console override */
     190sysarg_t sys_debug_activate_console(void)
    195191{
    196192#ifdef CONFIG_KCONSOLE
     
    200196        return false;
    201197#endif
    202 }
    203 
    204 /** Tell kernel to relinquish keyboard/console access */
    205 sysarg_t sys_debug_disable_console(void)
    206 {
    207         release_console();
    208         return true;
    209198}
    210199
     
    293282                         */
    294283                        spinlock_unlock(&klog_lock);
    295                         stdout->op->write(stdout, tmp, silent);
     284                        stdout->op->write(stdout, tmp);
    296285                        spinlock_lock(&klog_lock);
    297286                }
     
    321310                 * it should be no longer buffered.
    322311                 */
    323                 stdout->op->write(stdout, ch, silent);
     312                stdout->op->write(stdout, ch);
    324313        } else {
    325314                /*
  • kernel/generic/src/console/kconsole.c

    r25bef0ff r6a44ee4  
    8484
    8585SPINLOCK_INITIALIZE(cmd_lock);  /**< Lock protecting command list. */
    86 LIST_INITIALIZE(cmd_head);      /**< Command list. */
     86LIST_INITIALIZE(cmd_list);      /**< Command list. */
    8787
    8888static wchar_t history[KCONSOLE_HISTORY][MAX_CMDLINE] = {};
     
    113113bool cmd_register(cmd_info_t *cmd)
    114114{
    115         link_t *cur;
    116        
    117115        spinlock_lock(&cmd_lock);
    118116       
     
    120118         * Make sure the command is not already listed.
    121119         */
    122         for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
     120        list_foreach(cmd_list, cur) {
    123121                cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link);
    124122               
     
    153151         * Now the command can be added.
    154152         */
    155         list_append(&cmd->link, &cmd_head);
     153        list_append(&cmd->link, &cmd_list);
    156154       
    157155        spinlock_unlock(&cmd_lock);
     
    176174       
    177175        if (*startpos == NULL)
    178                 *startpos = cmd_head.next;
    179        
    180         for (; *startpos != &cmd_head; *startpos = (*startpos)->next) {
     176                *startpos = cmd_list.head.next;
     177       
     178        for (; *startpos != &cmd_list.head; *startpos = (*startpos)->next) {
    181179                cmd_info_t *hlp = list_get_instance(*startpos, cmd_info_t, link);
    182180               
     
    559557       
    560558        cmd_info_t *cmd = NULL;
    561         link_t *cur;
    562        
    563         for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
     559       
     560        list_foreach(cmd_list, cur) {
    564561                cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link);
    565562                spinlock_lock(&hlp->lock);
  • kernel/generic/src/cpu/cpu.c

    r25bef0ff r6a44ee4  
    8282                        for (j = 0; j < RQ_COUNT; j++) {
    8383                                irq_spinlock_initialize(&cpus[i].rq[j].lock, "cpus[].rq[].lock");
    84                                 list_initialize(&cpus[i].rq[j].rq_head);
     84                                list_initialize(&cpus[i].rq[j].rq);
    8585                        }
    8686                }
  • kernel/generic/src/ddi/ddi.c

    r25bef0ff r6a44ee4  
    122122        backend_data.frames = pages;
    123123       
    124         /* Find the zone of the physical memory */
     124        /*
     125         * Check if the memory region is explicitly enabled
     126         * for mapping by any parea structure.
     127         */
     128       
     129        mutex_lock(&parea_lock);
     130        btree_node_t *nodep;
     131        parea_t *parea = (parea_t *) btree_search(&parea_btree,
     132            (btree_key_t) pf, &nodep);
     133       
     134        if ((parea != NULL) && (parea->frames >= pages)) {
     135                if ((!priv) && (!parea->unpriv)) {
     136                        mutex_unlock(&parea_lock);
     137                        return EPERM;
     138                }
     139               
     140                goto map;
     141        }
     142       
     143        parea = NULL;
     144        mutex_unlock(&parea_lock);
     145       
     146        /*
     147         * Check if the memory region is part of physical
     148         * memory generally enabled for mapping.
     149         */
     150       
    125151        irq_spinlock_lock(&zones.lock, true);
    126152        size_t znum = find_zone(ADDR2PFN(pf), pages, 0);
     
    153179        }
    154180       
    155         if (zone_flags_available(zones.info[znum].flags)) {
    156                 /*
    157                  * Frames are part of physical memory, check
    158                  * if the memory region is enabled for mapping.
    159                  */
    160                 irq_spinlock_unlock(&zones.lock, true);
    161                
    162                 mutex_lock(&parea_lock);
    163                 btree_node_t *nodep;
    164                 parea_t *parea = (parea_t *) btree_search(&parea_btree,
    165                     (btree_key_t) pf, &nodep);
    166                
    167                 if ((!parea) || (parea->frames < pages)) {
    168                         mutex_unlock(&parea_lock);
    169                         return ENOENT;
    170                 }
    171                
    172                 if (!priv) {
    173                         if (!parea->unpriv) {
    174                                 mutex_unlock(&parea_lock);
    175                                 return EPERM;
    176                         }
    177                 }
    178                
    179                 mutex_unlock(&parea_lock);
    180                 goto map;
    181         }
    182        
    183181        irq_spinlock_unlock(&zones.lock, true);
    184182        return ENOENT;
     
    188186            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
    189187                /*
    190                  * The address space area could not have been created.
     188                 * The address space area was not created.
    191189                 * We report it using ENOMEM.
    192190                 */
     191               
     192                if (parea != NULL)
     193                        mutex_unlock(&parea_lock);
     194               
    193195                return ENOMEM;
    194196        }
     
    197199         * Mapping is created on-demand during page fault.
    198200         */
    199         return 0;
     201       
     202        if (parea != NULL) {
     203                parea->mapped = true;
     204                mutex_unlock(&parea_lock);
     205        }
     206       
     207        return EOK;
    200208}
    201209
  • kernel/generic/src/ddi/irq.c

    r25bef0ff r6a44ee4  
    275275{
    276276        /*
    277          * If the kernel console is silenced,
    278          * then try first the uspace handlers,
    279          * eventually fall back to kernel handlers.
     277         * If the kernel console override is on,
     278         * then try first the kernel handlers
     279         * and eventually fall back to uspace
     280         * handlers.
    280281         *
    281          * If the kernel console is active,
    282          * then do it the other way around.
     282         * In the usual case the uspace handlers
     283         * have precedence.
    283284         */
    284         if (silent) {
    285                 irq_t *irq = irq_dispatch_and_lock_uspace(inr);
     285       
     286        if (console_override) {
     287                irq_t *irq = irq_dispatch_and_lock_kernel(inr);
    286288                if (irq)
    287289                        return irq;
    288290               
    289                 return irq_dispatch_and_lock_kernel(inr);
    290         }
    291        
    292         irq_t *irq = irq_dispatch_and_lock_kernel(inr);
     291                return irq_dispatch_and_lock_uspace(inr);
     292        }
     293       
     294        irq_t *irq = irq_dispatch_and_lock_uspace(inr);
    293295        if (irq)
    294296                return irq;
    295297       
    296         return irq_dispatch_and_lock_uspace(inr);
     298        return irq_dispatch_and_lock_kernel(inr);
    297299}
    298300
  • kernel/generic/src/debug/panic.c

    r25bef0ff r6a44ee4  
    4848    uintptr_t address, const char *fmt, ...)
    4949{
    50         va_list args;
    51        
    52         silent = false;
     50        console_override = true;
    5351       
    5452        printf("\n%s Kernel panic ", BANNER_LEFT);
     
    5755        printf("due to ");
    5856       
     57        va_list args;
    5958        va_start(args, fmt);
    6059        if (cat == PANIC_ASSERT) {
  • kernel/generic/src/interrupt/interrupt.c

    r25bef0ff r6a44ee4  
    177177            (void *) istate_get_pc(istate));
    178178       
     179        istate_decode(istate);
    179180        stack_trace_istate(istate);
    180181       
  • kernel/generic/src/ipc/ipc.c

    r25bef0ff r6a44ee4  
    4444#include <synch/synch.h>
    4545#include <ipc/ipc.h>
     46#include <ipc/ipc_methods.h>
    4647#include <ipc/kbox.h>
    4748#include <ipc/event.h>
     
    127128        list_initialize(&box->answers);
    128129        list_initialize(&box->irq_notifs);
    129         list_initialize(&box->irq_head);
     130        list_initialize(&box->irq_list);
    130131        box->task = task;
    131132}
     
    182183         */
    183184        irq_spinlock_lock(&TASK->lock, true);
    184         list_append(&sync_box->sync_box_link, &TASK->sync_box_head);
     185        list_append(&sync_box->sync_box_link, &TASK->sync_boxes);
    185186        irq_spinlock_unlock(&TASK->lock, true);
    186187       
     
    449450                irq_spinlock_lock(&box->irq_lock, false);
    450451               
    451                 request = list_get_instance(box->irq_notifs.next, call_t, link);
     452                request = list_get_instance(list_first(&box->irq_notifs),
     453                    call_t, link);
    452454                list_remove(&request->link);
    453455               
     
    458460               
    459461                /* Handle asynchronous answers */
    460                 request = list_get_instance(box->answers.next, call_t, link);
     462                request = list_get_instance(list_first(&box->answers),
     463                    call_t, link);
    461464                list_remove(&request->link);
    462465                atomic_dec(&request->data.phone->active_calls);
     
    466469               
    467470                /* Handle requests */
    468                 request = list_get_instance(box->calls.next, call_t, link);
     471                request = list_get_instance(list_first(&box->calls),
     472                    call_t, link);
    469473                list_remove(&request->link);
    470474               
     
    493497 *
    494498 */
    495 void ipc_cleanup_call_list(link_t *lst)
     499void ipc_cleanup_call_list(list_t *lst)
    496500{
    497501        while (!list_empty(lst)) {
    498                 call_t *call = list_get_instance(lst->next, call_t, link);
     502                call_t *call = list_get_instance(list_first(lst), call_t, link);
    499503                if (call->buffer)
    500504                        free(call->buffer);
     
    525529        irq_spinlock_lock(&box->lock, true);
    526530        while (!list_empty(&box->connected_phones)) {
    527                 phone = list_get_instance(box->connected_phones.next,
     531                phone = list_get_instance(list_first(&box->connected_phones),
    528532                    phone_t, link);
    529533                if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
     
    605609        /* Wait for all answers to interrupted synchronous calls to arrive */
    606610        ipl_t ipl = interrupts_disable();
    607         while (!list_empty(&TASK->sync_box_head)) {
    608                 answerbox_t *box = list_get_instance(TASK->sync_box_head.next,
    609                     answerbox_t, sync_box_link);
     611        while (!list_empty(&TASK->sync_boxes)) {
     612                answerbox_t *box = list_get_instance(
     613                    list_first(&TASK->sync_boxes), answerbox_t, sync_box_link);
    610614               
    611615                list_remove(&box->sync_box_link);
     
    742746#endif
    743747       
    744         link_t *cur;
    745        
    746748        printf(" --- incomming calls ---\n");
    747         for (cur = task->answerbox.calls.next; cur != &task->answerbox.calls;
    748             cur = cur->next) {
     749        list_foreach(task->answerbox.calls, cur) {
    749750                call_t *call = list_get_instance(cur, call_t, link);
    750751               
     
    766767       
    767768        printf(" --- dispatched calls ---\n");
    768         for (cur = task->answerbox.dispatched_calls.next;
    769             cur != &task->answerbox.dispatched_calls;
    770             cur = cur->next) {
     769        list_foreach(task->answerbox.dispatched_calls, cur) {
    771770                call_t *call = list_get_instance(cur, call_t, link);
    772771               
     
    788787       
    789788        printf(" --- incoming answers ---\n");
    790         for (cur = task->answerbox.answers.next;
    791             cur != &task->answerbox.answers;
    792             cur = cur->next) {
     789        list_foreach(task->answerbox.answers, cur) {
    793790                call_t *call = list_get_instance(cur, call_t, link);
    794791               
  • kernel/generic/src/ipc/ipcrsc.c

    r25bef0ff r6a44ee4  
    146146call_t *get_call(sysarg_t callid)
    147147{
    148         link_t *lst;
    149148        call_t *result = NULL;
    150149       
    151150        irq_spinlock_lock(&TASK->answerbox.lock, true);
    152         for (lst = TASK->answerbox.dispatched_calls.next;
    153             lst != &TASK->answerbox.dispatched_calls; lst = lst->next) {
     151       
     152        list_foreach(TASK->answerbox.dispatched_calls, lst) {
    154153                call_t *call = list_get_instance(lst, call_t, link);
    155154                if ((sysarg_t) call == callid) {
  • kernel/generic/src/ipc/irq.c

    r25bef0ff r6a44ee4  
    174174        irq->notif_cfg.code = code;
    175175        irq->notif_cfg.counter = 0;
     176        irq->driver_as = AS;
    176177       
    177178        /*
     
    199200       
    200201        hash_table_insert(&irq_uspace_hash_table, key, &irq->link);
    201         list_append(&irq->notif_cfg.link, &box->irq_head);
     202        list_append(&irq->notif_cfg.link, &box->irq_list);
    202203       
    203204        irq_spinlock_unlock(&box->irq_lock, false);
     
    281282        irq_spinlock_lock(&box->irq_lock, false);
    282283       
    283         while (box->irq_head.next != &box->irq_head) {
     284        while (!list_empty(&box->irq_list)) {
    284285                DEADLOCK_PROBE_INIT(p_irqlock);
    285286               
    286                 irq_t *irq = list_get_instance(box->irq_head.next, irq_t,
     287                irq_t *irq = list_get_instance(list_first(&box->irq_list), irq_t,
    287288                    notif_cfg.link);
    288289               
     
    364365                return IRQ_DECLINE;
    365366       
     367#define CMD_MEM_READ(target) \
     368do { \
     369        void *va = code->cmds[i].addr; \
     370        if (AS != irq->driver_as) \
     371                as_switch(AS, irq->driver_as); \
     372        memcpy_from_uspace(&target, va, (sizeof(target))); \
     373        if (dstarg) \
     374                scratch[dstarg] = target; \
     375} while(0)
     376
     377#define CMD_MEM_WRITE(val) \
     378do { \
     379        void *va = code->cmds[i].addr; \
     380        if (AS != irq->driver_as) \
     381                as_switch(AS, irq->driver_as); \
     382        memcpy_to_uspace(va, &val, sizeof(val)); \
     383} while (0)
     384
     385        as_t *current_as = AS;
    366386        size_t i;
    367387        for (i = 0; i < code->cmdcount; i++) {
     
    422442                        }
    423443                        break;
     444                case CMD_MEM_READ_8: {
     445                        uint8_t val;
     446                        CMD_MEM_READ(val);
     447                        break;
     448                        }
     449                case CMD_MEM_READ_16: {
     450                        uint16_t val;
     451                        CMD_MEM_READ(val);
     452                        break;
     453                        }
     454                case CMD_MEM_READ_32: {
     455                        uint32_t val;
     456                        CMD_MEM_READ(val);
     457                        break;
     458                        }
     459                case CMD_MEM_WRITE_8: {
     460                        uint8_t val = code->cmds[i].value;
     461                        CMD_MEM_WRITE(val);
     462                        break;
     463                        }
     464                case CMD_MEM_WRITE_16: {
     465                        uint16_t val = code->cmds[i].value;
     466                        CMD_MEM_WRITE(val);
     467                        break;
     468                        }
     469                case CMD_MEM_WRITE_32: {
     470                        uint32_t val = code->cmds[i].value;
     471                        CMD_MEM_WRITE(val);
     472                        break;
     473                        }
     474                case CMD_MEM_WRITE_A_8:
     475                        if (srcarg) {
     476                                uint8_t val = scratch[srcarg];
     477                                CMD_MEM_WRITE(val);
     478                        }
     479                        break;
     480                case CMD_MEM_WRITE_A_16:
     481                        if (srcarg) {
     482                                uint16_t val = scratch[srcarg];
     483                                CMD_MEM_WRITE(val);
     484                        }
     485                        break;
     486                case CMD_MEM_WRITE_A_32:
     487                        if (srcarg) {
     488                                uint32_t val = scratch[srcarg];
     489                                CMD_MEM_WRITE(val);
     490                        }
     491                        break;
    424492                case CMD_BTEST:
    425493                        if ((srcarg) && (dstarg)) {
     
    435503                        break;
    436504                case CMD_ACCEPT:
     505                        if (AS != current_as)
     506                                as_switch(AS, current_as);
    437507                        return IRQ_ACCEPT;
    438508                case CMD_DECLINE:
    439509                default:
     510                        if (AS != current_as)
     511                                as_switch(AS, current_as);
    440512                        return IRQ_DECLINE;
    441513                }
    442514        }
     515        if (AS != current_as)
     516                as_switch(AS, current_as);
    443517       
    444518        return IRQ_DECLINE;
  • kernel/generic/src/ipc/kbox.c

    r25bef0ff r6a44ee4  
    3737#include <synch/mutex.h>
    3838#include <ipc/ipc.h>
     39#include <ipc/ipc_methods.h>
    3940#include <ipc/ipcrsc.h>
    4041#include <arch.h>
     
    169170                switch (IPC_GET_IMETHOD(call->data)) {
    170171               
    171                 case IPC_M_DEBUG_ALL:
     172                case IPC_M_DEBUG:
    172173                        /* Handle debug call. */
    173174                        udebug_call_receive(call);
  • kernel/generic/src/ipc/sysipc.c

    r25bef0ff r6a44ee4  
    4040#include <debug.h>
    4141#include <ipc/ipc.h>
     42#include <ipc/ipc_methods.h>
    4243#include <ipc/sysipc.h>
    4344#include <ipc/irq.h>
     
    460461        }
    461462#ifdef CONFIG_UDEBUG
    462         case IPC_M_DEBUG_ALL:
     463        case IPC_M_DEBUG:
    463464                return udebug_request_preprocess(call, phone);
    464465#endif
     
    495496                /*
    496497                 * This must be an affirmative answer to IPC_M_DATA_READ
    497                  * or IPC_M_DEBUG_ALL/UDEBUG_M_MEM_READ...
     498                 * or IPC_M_DEBUG/UDEBUG_M_MEM_READ...
    498499                 *
    499500                 */
     
    531532       
    532533        switch (IPC_GET_IMETHOD(call->data)) {
    533         case IPC_M_DEBUG_ALL:
     534        case IPC_M_DEBUG:
    534535                return -1;
    535536        default:
  • kernel/generic/src/lib/rd.c

    r25bef0ff r6a44ee4  
    9191        rd_parea.frames = SIZE2FRAMES(dsize);
    9292        rd_parea.unpriv = false;
     93        rd_parea.mapped = false;
    9394        ddi_parea_register(&rd_parea);
    9495
  • kernel/generic/src/main/version.c

    r25bef0ff r6a44ee4  
    3838
    3939static const char *project = "SPARTAN kernel";
    40 static const char *copyright = "Copyright (c) 2001-2010 HelenOS project";
     40static const char *copyright = "Copyright (c) 2001-2011 HelenOS project";
    4141static const char *release = STRING(RELEASE);
    4242static const char *name = STRING(NAME);
  • kernel/generic/src/mm/as.c

    r25bef0ff r6a44ee4  
    9494 *
    9595 * This lock protects:
    96  * - inactive_as_with_asid_head list
     96 * - inactive_as_with_asid_list
    9797 * - as->asid for each as of the as_t type
    9898 * - asids_allocated counter
     
    105105 * that have valid ASID.
    106106 */
    107 LIST_INITIALIZE(inactive_as_with_asid_head);
     107LIST_INITIALIZE(inactive_as_with_asid_list);
    108108
    109109/** Kernel address space. */
     
    235235        bool cond = true;
    236236        while (cond) {
    237                 ASSERT(!list_empty(&as->as_area_btree.leaf_head));
     237                ASSERT(!list_empty(&as->as_area_btree.leaf_list));
    238238               
    239239                btree_node_t *node =
    240                     list_get_instance(as->as_area_btree.leaf_head.next,
     240                    list_get_instance(list_first(&as->as_area_btree.leaf_list),
    241241                    btree_node_t, leaf_link);
    242242               
     
    602602                bool cond = true;
    603603                while (cond) {
    604                         ASSERT(!list_empty(&area->used_space.leaf_head));
     604                        ASSERT(!list_empty(&area->used_space.leaf_list));
    605605                       
    606606                        btree_node_t *node =
    607                             list_get_instance(area->used_space.leaf_head.prev,
     607                            list_get_instance(list_last(&area->used_space.leaf_list),
    608608                            btree_node_t, leaf_link);
    609609                       
     
    727727        if (--sh_info->refcount == 0) {
    728728                dealloc = true;
    729                 link_t *cur;
    730729               
    731730                /*
     
    733732                 * reference from all frames found there.
    734733                 */
    735                 for (cur = sh_info->pagemap.leaf_head.next;
    736                     cur != &sh_info->pagemap.leaf_head; cur = cur->next) {
     734                list_foreach(sh_info->pagemap.leaf_list, cur) {
    737735                        btree_node_t *node
    738736                            = list_get_instance(cur, btree_node_t, leaf_link);
     
    786784         * Visit only the pages mapped by used_space B+tree.
    787785         */
    788         link_t *cur;
    789         for (cur = area->used_space.leaf_head.next;
    790             cur != &area->used_space.leaf_head; cur = cur->next) {
     786        list_foreach(area->used_space.leaf_list, cur) {
    791787                btree_node_t *node;
    792788                btree_key_t i;
     
    10651061         */
    10661062        size_t used_pages = 0;
    1067         link_t *cur;
    1068        
    1069         for (cur = area->used_space.leaf_head.next;
    1070             cur != &area->used_space.leaf_head; cur = cur->next) {
     1063       
     1064        list_foreach(area->used_space.leaf_list, cur) {
    10711065                btree_node_t *node
    10721066                    = list_get_instance(cur, btree_node_t, leaf_link);
     
    10941088        size_t frame_idx = 0;
    10951089       
    1096         for (cur = area->used_space.leaf_head.next;
    1097             cur != &area->used_space.leaf_head; cur = cur->next) {
     1090        list_foreach(area->used_space.leaf_list, cur) {
    10981091                btree_node_t *node = list_get_instance(cur, btree_node_t,
    10991092                    leaf_link);
     
    11471140        frame_idx = 0;
    11481141       
    1149         for (cur = area->used_space.leaf_head.next;
    1150             cur != &area->used_space.leaf_head; cur = cur->next) {
     1142        list_foreach(area->used_space.leaf_list, cur) {
    11511143                btree_node_t *node
    11521144                    = list_get_instance(cur, btree_node_t, leaf_link);
     
    12921284 * thing which is forbidden in this context is locking the address space.
    12931285 *
    1294  * When this function is enetered, no spinlocks may be held.
     1286 * When this function is entered, no spinlocks may be held.
    12951287 *
    12961288 * @param old Old address space or NULL.
     
    13341326                       
    13351327                        list_append(&old_as->inactive_as_with_asid_link,
    1336                             &inactive_as_with_asid_head);
     1328                            &inactive_as_with_asid_list);
    13371329                }
    13381330               
     
    20272019       
    20282020        /* Eventually check the addresses behind each area */
    2029         link_t *cur;
    2030         for (cur = AS->as_area_btree.leaf_head.next;
    2031             (ret == 0) && (cur != &AS->as_area_btree.leaf_head);
    2032             cur = cur->next) {
     2021        list_foreach(AS->as_area_btree.leaf_list, cur) {
     2022                if (ret != 0)
     2023                        break;
     2024
    20332025                btree_node_t *node =
    20342026                    list_get_instance(cur, btree_node_t, leaf_link);
     
    20722064       
    20732065        size_t area_cnt = 0;
    2074         link_t *cur;
    2075        
    2076         for (cur = as->as_area_btree.leaf_head.next;
    2077             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     2066       
     2067        list_foreach(as->as_area_btree.leaf_list, cur) {
    20782068                btree_node_t *node =
    20792069                    list_get_instance(cur, btree_node_t, leaf_link);
     
    20882078        size_t area_idx = 0;
    20892079       
    2090         for (cur = as->as_area_btree.leaf_head.next;
    2091             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     2080        list_foreach(as->as_area_btree.leaf_list, cur) {
    20922081                btree_node_t *node =
    20932082                    list_get_instance(cur, btree_node_t, leaf_link);
     
    21252114       
    21262115        /* Print out info about address space areas */
    2127         link_t *cur;
    2128         for (cur = as->as_area_btree.leaf_head.next;
    2129             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     2116        list_foreach(as->as_area_btree.leaf_list, cur) {
    21302117                btree_node_t *node
    21312118                    = list_get_instance(cur, btree_node_t, leaf_link);
  • kernel/generic/src/mm/backend_anon.c

    r25bef0ff r6a44ee4  
    9797void anon_share(as_area_t *area)
    9898{
    99         link_t *cur;
    100 
    10199        ASSERT(mutex_locked(&area->as->lock));
    102100        ASSERT(mutex_locked(&area->lock));
     
    106104         */
    107105        mutex_lock(&area->sh_info->lock);
    108         for (cur = area->used_space.leaf_head.next;
    109             cur != &area->used_space.leaf_head; cur = cur->next) {
     106        list_foreach(area->used_space.leaf_list, cur) {
    110107                btree_node_t *node;
    111108                unsigned int i;
  • kernel/generic/src/mm/backend_elf.c

    r25bef0ff r6a44ee4  
    139139         */
    140140        if (area->flags & AS_AREA_WRITE) {
    141                 node = list_get_instance(area->used_space.leaf_head.next,
     141                node = list_get_instance(list_first(&area->used_space.leaf_list),
    142142                    btree_node_t, leaf_link);
    143143        } else {
     
    153153         */
    154154        mutex_lock(&area->sh_info->lock);
    155         for (cur = &node->leaf_link; cur != &area->used_space.leaf_head;
     155        for (cur = &node->leaf_link; cur != &area->used_space.leaf_list.head;
    156156            cur = cur->next) {
    157157                unsigned int i;
  • kernel/generic/src/mm/buddy.c

    r25bef0ff r6a44ee4  
    8282         * Use memory after our own structure.
    8383         */
    84         b->order = (link_t *) (&b[1]);
     84        b->order = (list_t *) (&b[1]);
    8585       
    8686        for (i = 0; i <= max_order; i++)
     
    176176         * the request can be immediatelly satisfied.
    177177         */
    178         if (!list_empty(&b->order[i])) {
    179                 res = b->order[i].next;
     178        res = list_first(&b->order[i]);
     179        if (res != NULL) {
    180180                list_remove(res);
    181181                b->op->mark_busy(b, res);
  • kernel/generic/src/mm/page.c

    r25bef0ff r6a44ee4  
    6060
    6161#include <mm/page.h>
     62#include <genarch/mm/page_ht.h>
     63#include <genarch/mm/page_pt.h>
    6264#include <arch/mm/page.h>
    6365#include <arch/mm/asid.h>
     
    7072#include <debug.h>
    7173#include <arch.h>
     74#include <syscall/copy.h>
     75#include <errno.h>
    7276
    7377/** Virtual operations for page subsystem. */
     
    172176}
    173177
     178/** Syscall wrapper for getting mapping of a virtual page.
     179 *
     180 * @retval EOK Everything went find, @p uspace_frame and @p uspace_node
     181 *             contains correct values.
     182 * @retval ENOENT Virtual address has no mapping.
     183 */
     184sysarg_t sys_page_find_mapping(uintptr_t virt_address,
     185    uintptr_t *uspace_frame)
     186{
     187        mutex_lock(&AS->lock);
     188       
     189        pte_t *pte = page_mapping_find(AS, virt_address, false);
     190        if (!PTE_VALID(pte) || !PTE_PRESENT(pte)) {
     191                mutex_unlock(&AS->lock);
     192               
     193                return (sysarg_t) ENOENT;
     194        }
     195       
     196        uintptr_t phys_address = PTE_GET_FRAME(pte);
     197       
     198        mutex_unlock(&AS->lock);
     199       
     200        int rc = copy_to_uspace(uspace_frame,
     201            &phys_address, sizeof(phys_address));
     202        if (rc != EOK) {
     203                return (sysarg_t) rc;
     204        }
     205       
     206        return EOK;
     207}
     208
    174209/** @}
    175210 */
  • kernel/generic/src/mm/slab.c

    r25bef0ff r6a44ee4  
    317317                spinlock_lock(&cache->slablock);
    318318        } else {
    319                 slab = list_get_instance(cache->partial_slabs.next, slab_t,
    320                     link);
     319                slab = list_get_instance(list_first(&cache->partial_slabs),
     320                    slab_t, link);
    321321                list_remove(&slab->link);
    322322        }
     
    360360        if (!list_empty(&cache->magazines)) {
    361361                if (first)
    362                         cur = cache->magazines.next;
     362                        cur = list_first(&cache->magazines);
    363363                else
    364                         cur = cache->magazines.prev;
     364                        cur = list_last(&cache->magazines);
    365365               
    366366                mag = list_get_instance(cur, slab_magazine_t, link);
     
    812812       
    813813        size_t frames = 0;
    814         link_t *cur;
    815         for (cur = slab_cache_list.next; cur != &slab_cache_list;
    816             cur = cur->next) {
     814        list_foreach(slab_cache_list, cur) {
    817815                slab_cache_t *cache = list_get_instance(cur, slab_cache_t, link);
    818816                frames += _slab_reclaim(cache, flags);
     
    861859                link_t *cur;
    862860                size_t i;
    863                 for (i = 0, cur = slab_cache_list.next;
    864                     (i < skip) && (cur != &slab_cache_list);
     861                for (i = 0, cur = slab_cache_list.head.next;
     862                    (i < skip) && (cur != &slab_cache_list.head);
    865863                    i++, cur = cur->next);
    866864               
    867                 if (cur == &slab_cache_list) {
     865                if (cur == &slab_cache_list.head) {
    868866                        irq_spinlock_unlock(&slab_cache_lock, true);
    869867                        break;
     
    940938        irq_spinlock_lock(&slab_cache_lock, false);
    941939       
    942         link_t *cur;
    943         for (cur = slab_cache_list.next; cur != &slab_cache_list;
    944             cur = cur->next) {
     940        list_foreach(slab_cache_list, cur) {
    945941                slab_cache_t *slab = list_get_instance(cur, slab_cache_t, link);
    946942                if ((slab->flags & SLAB_CACHE_MAGDEFERRED) !=
  • kernel/generic/src/proc/scheduler.c

    r25bef0ff r6a44ee4  
    237237                 * Take the first thread from the queue.
    238238                 */
    239                 thread_t *thread =
    240                     list_get_instance(CPU->rq[i].rq_head.next, thread_t, rq_link);
     239                thread_t *thread = list_get_instance(
     240                    list_first(&CPU->rq[i].rq), thread_t, rq_link);
    241241                list_remove(&thread->rq_link);
    242242               
     
    273273static void relink_rq(int start)
    274274{
    275         link_t head;
    276        
    277         list_initialize(&head);
     275        list_t list;
     276       
     277        list_initialize(&list);
    278278        irq_spinlock_lock(&CPU->lock, false);
    279279       
     
    284284                       
    285285                        irq_spinlock_lock(&CPU->rq[i + 1].lock, false);
    286                         list_concat(&head, &CPU->rq[i + 1].rq_head);
     286                        list_concat(&list, &CPU->rq[i + 1].rq);
    287287                        size_t n = CPU->rq[i + 1].n;
    288288                        CPU->rq[i + 1].n = 0;
     
    292292                       
    293293                        irq_spinlock_lock(&CPU->rq[i].lock, false);
    294                         list_concat(&CPU->rq[i].rq_head, &head);
     294                        list_concat(&CPU->rq[i].rq, &list);
    295295                        CPU->rq[i].n += n;
    296296                        irq_spinlock_unlock(&CPU->rq[i].lock, false);
     
    586586         * Searching least priority queues on all CPU's first and most priority
    587587         * queues on all CPU's last.
    588          *
    589588         */
    590589        size_t acpu;
     
    617616                       
    618617                        /* Search rq from the back */
    619                         link_t *link = cpu->rq[rq].rq_head.prev;
    620                        
    621                         while (link != &(cpu->rq[rq].rq_head)) {
    622                                 thread = (thread_t *) list_get_instance(link, thread_t, rq_link);
     618                        link_t *link = cpu->rq[rq].rq.head.prev;
     619                       
     620                        while (link != &(cpu->rq[rq].rq.head)) {
     621                                thread = (thread_t *) list_get_instance(link,
     622                                    thread_t, rq_link);
    623623                               
    624624                                /*
    625                                  * We don't want to steal CPU-wired threads
    626                                  * neither threads already stolen. The latter
    627                                  * prevents threads from migrating between CPU's
    628                                  * without ever being run. We don't want to
    629                                  * steal threads whose FPU context is still in
    630                                  * CPU.
    631                                  *
     625                                 * Do not steal CPU-wired threads, threads
     626                                 * already stolen, threads for which migration
     627                                 * was temporarily disabled or threads whose
     628                                 * FPU context is still in the CPU.
    632629                                 */
    633630                                irq_spinlock_lock(&thread->lock, false);
    634631                               
    635                                 if ((!(thread->flags & (THREAD_FLAG_WIRED | THREAD_FLAG_STOLEN)))
    636                                     && (!(thread->fpu_context_engaged))) {
     632                                if (!(thread->flags & THREAD_FLAG_WIRED) &&
     633                                    !(thread->flags & THREAD_FLAG_STOLEN) &&
     634                                    !thread->nomigrate &&
     635                                    !thread->fpu_context_engaged) {
    637636                                        /*
    638637                                         * Remove thread from ready queue.
    639638                                         */
    640                                         irq_spinlock_unlock(&thread->lock, false);
     639                                        irq_spinlock_unlock(&thread->lock,
     640                                            false);
    641641                                       
    642642                                        atomic_dec(&cpu->nrdy);
     
    660660                                 */
    661661                               
    662                                 irq_spinlock_pass(&(cpu->rq[rq].lock), &thread->lock);
     662                                irq_spinlock_pass(&(cpu->rq[rq].lock),
     663                                    &thread->lock);
    663664                               
    664665#ifdef KCPULB_VERBOSE
     
    739740                       
    740741                        printf("\trq[%u]: ", i);
    741                         link_t *cur;
    742                         for (cur = cpus[cpu].rq[i].rq_head.next;
    743                             cur != &(cpus[cpu].rq[i].rq_head);
    744                             cur = cur->next) {
    745                                 thread_t *thread = list_get_instance(cur, thread_t, rq_link);
     742                        list_foreach(cpus[cpu].rq[i].rq, cur) {
     743                                thread_t *thread = list_get_instance(cur,
     744                                    thread_t, rq_link);
    746745                                printf("%" PRIu64 "(%s) ", thread->tid,
    747746                                    thread_states[thread->state]);
  • kernel/generic/src/proc/task.c

    r25bef0ff r6a44ee4  
    155155        mutex_initialize(&task->futexes_lock, MUTEX_PASSIVE);
    156156       
    157         list_initialize(&task->th_head);
    158         list_initialize(&task->sync_box_head);
     157        list_initialize(&task->threads);
     158        list_initialize(&task->sync_boxes);
    159159       
    160160        ipc_answerbox_init(&task->answerbox, task);
     
    435435       
    436436        /* Current values of threads */
    437         link_t *cur;
    438         for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
     437        list_foreach(task->threads, cur) {
    439438                thread_t *thread = list_get_instance(cur, thread_t, th_link);
    440439               
     
    468467         */
    469468       
    470         link_t *cur;
    471         for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
     469        list_foreach(task->threads, cur) {
    472470                thread_t *thread = list_get_instance(cur, thread_t, th_link);
    473471                bool sleeping = false;
  • kernel/generic/src/proc/thread.c

    r25bef0ff r6a44ee4  
    5555#include <time/clock.h>
    5656#include <time/timeout.h>
     57#include <time/delay.h>
    5758#include <config.h>
    5859#include <arch/interrupt.h>
     
    259260         */
    260261       
    261         list_append(&thread->rq_link, &cpu->rq[i].rq_head);
     262        list_append(&thread->rq_link, &cpu->rq[i].rq);
    262263        cpu->rq[i].n++;
    263264        irq_spinlock_unlock(&(cpu->rq[i].lock), true);
     
    321322        thread->cpu = NULL;
    322323        thread->flags = flags;
     324        thread->nomigrate = 0;
    323325        thread->state = Entering;
    324326       
     
    421423                atomic_inc(&task->lifecount);
    422424       
    423         list_append(&thread->th_link, &task->th_head);
     425        list_append(&thread->th_link, &task->threads);
    424426       
    425427        irq_spinlock_pass(&task->lock, &threads_lock);
     
    481483        /* Not reached */
    482484        while (true);
     485}
     486
     487/** Prevent the current thread from being migrated to another processor. */
     488void thread_migration_disable(void)
     489{
     490        ASSERT(THREAD);
     491
     492        THREAD->nomigrate++;
     493}
     494
     495/** Allow the current thread to be migrated to another processor. */
     496void thread_migration_enable(void)
     497{
     498        ASSERT(THREAD);
     499        ASSERT(THREAD->nomigrate > 0);
     500
     501        THREAD->nomigrate--;
    483502}
    484503
     
    912931}
    913932
     933sysarg_t sys_thread_udelay(uint32_t usec)
     934{
     935        delay(usec);
     936        return 0;
     937}
     938
    914939/** @}
    915940 */
  • kernel/generic/src/synch/futex.c

    r25bef0ff r6a44ee4  
    272272void futex_cleanup(void)
    273273{
    274         link_t *cur;
    275        
    276274        mutex_lock(&futex_ht_lock);
    277275        mutex_lock(&TASK->futexes_lock);
    278276
    279         for (cur = TASK->futexes.leaf_head.next;
    280             cur != &TASK->futexes.leaf_head; cur = cur->next) {
     277        list_foreach(TASK->futexes.leaf_list, cur) {
    281278                btree_node_t *node;
    282279                unsigned int i;
  • kernel/generic/src/synch/waitq.c

    r25bef0ff r6a44ee4  
    6969{
    7070        irq_spinlock_initialize(&wq->lock, "wq.lock");
    71         list_initialize(&wq->head);
     71        list_initialize(&wq->sleepers);
    7272        wq->missed_wakeups = 0;
    7373}
     
    196196        irq_spinlock_lock(&wq->lock, true);
    197197       
    198         if (!list_empty(&wq->head)) {
    199                 thread_t *thread = list_get_instance(wq->head.next, thread_t, wq_link);
     198        if (!list_empty(&wq->sleepers)) {
     199                thread_t *thread = list_get_instance(list_first(&wq->sleepers),
     200                    thread_t, wq_link);
    200201               
    201202                irq_spinlock_lock(&thread->lock, false);
     
    407408        }
    408409       
    409         list_append(&THREAD->wq_link, &wq->head);
     410        list_append(&THREAD->wq_link, &wq->sleepers);
    410411       
    411412        /*
     
    464465       
    465466loop:
    466         if (list_empty(&wq->head)) {
     467        if (list_empty(&wq->sleepers)) {
    467468                wq->missed_wakeups++;
    468469                if ((count) && (mode == WAKEUP_ALL))
     
    473474       
    474475        count++;
    475         thread_t *thread = list_get_instance(wq->head.next, thread_t, wq_link);
     476        thread_t *thread = list_get_instance(list_first(&wq->sleepers),
     477            thread_t, wq_link);
    476478       
    477479        /*
  • kernel/generic/src/syscall/syscall.c

    r25bef0ff r6a44ee4  
    4141#include <proc/program.h>
    4242#include <mm/as.h>
     43#include <mm/page.h>
    4344#include <print.h>
    4445#include <arch.h>
     
    118119
    119120syshandler_t syscall_table[SYSCALL_END] = {
     121        /* System management syscalls. */
    120122        (syshandler_t) sys_klog,
    121123        (syshandler_t) sys_tls_set,
     
    126128        (syshandler_t) sys_thread_get_id,
    127129        (syshandler_t) sys_thread_usleep,
     130        (syshandler_t) sys_thread_udelay,
    128131       
    129132        (syshandler_t) sys_task_get_id,
     
    144147        (syshandler_t) sys_as_area_destroy,
    145148        (syshandler_t) sys_as_get_unmapped_area,
     149       
     150        /* Page mapping related syscalls. */
     151        (syshandler_t) sys_page_find_mapping,
    146152       
    147153        /* IPC related syscalls. */
     
    174180        (syshandler_t) sys_unregister_irq,
    175181       
    176         /* Sysinfo syscalls */
     182        /* Sysinfo syscalls. */
    177183        (syshandler_t) sys_sysinfo_get_tag,
    178184        (syshandler_t) sys_sysinfo_get_value,
     
    180186        (syshandler_t) sys_sysinfo_get_data,
    181187       
    182         /* Debug calls */
    183         (syshandler_t) sys_debug_enable_console,
    184         (syshandler_t) sys_debug_disable_console
     188        /* Kernel console syscalls. */
     189        (syshandler_t) sys_debug_activate_console
    185190};
    186191
  • kernel/generic/src/sysinfo/stats.c

    r25bef0ff r6a44ee4  
    173173       
    174174        /* Walk the B+ tree and count pages */
    175         link_t *cur;
    176         for (cur = as->as_area_btree.leaf_head.next;
    177             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     175        list_foreach(as->as_area_btree.leaf_list, cur) {
    178176                btree_node_t *node =
    179177                    list_get_instance(cur, btree_node_t, leaf_link);
     
    218216       
    219217        /* Walk the B+ tree and count pages */
    220         link_t *cur;
    221         for (cur = as->as_area_btree.leaf_head.next;
    222             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     218        list_foreach(as->as_area_btree.leaf_list, cur) {
    223219                btree_node_t *node =
    224220                    list_get_instance(cur, btree_node_t, leaf_link);
  • kernel/generic/src/time/clock.c

    r25bef0ff r6a44ee4  
    9494        clock_parea.frames = 1;
    9595        clock_parea.unpriv = true;
     96        clock_parea.mapped = false;
    9697        ddi_parea_register(&clock_parea);
    9798       
     
    163164               
    164165                link_t *cur;
    165                 while ((cur = CPU->timeout_active_head.next) != &CPU->timeout_active_head) {
    166                         timeout_t *timeout = list_get_instance(cur, timeout_t, link);
     166                while ((cur = list_first(&CPU->timeout_active_list)) != NULL) {
     167                        timeout_t *timeout = list_get_instance(cur, timeout_t,
     168                            link);
    167169                       
    168170                        irq_spinlock_lock(&timeout->lock, false);
  • kernel/generic/src/time/delay.c

    r25bef0ff r6a44ee4  
    3737 
    3838#include <time/delay.h>
     39#include <proc/thread.h>
    3940#include <typedefs.h>
    4041#include <cpu.h>
     
    4243#include <arch.h>
    4344
    44 /** Active delay
     45/** Delay the execution for the given number of microseconds (or slightly more).
    4546 *
    46  * Delay the execution for the given number
    47  * of microseconds (or slightly more). The delay
    48  * is implemented as CPU calibrated active loop.
     47 * The delay is implemented as active delay loop.
    4948 *
    5049 * @param usec Number of microseconds to sleep.
     
    5251void delay(uint32_t usec)
    5352{
    54         ipl_t ipl;
    55        
    5653        /*
    57          * The delay loop is calibrated for each and every
    58          * CPU in the system. Therefore it is necessary to
    59          * call interrupts_disable() before calling the
    60          * asm_delay_loop().
     54         * The delay loop is calibrated for each and every CPU in the system.
     55         * If running in a thread context, it is therefore necessary to disable
     56         * thread migration. We want to do this in a lightweight manner.
    6157         */
    62         ipl = interrupts_disable();
     58        if (THREAD)
     59                thread_migration_disable();
    6360        asm_delay_loop(usec * CPU->delay_loop_const);
    64         interrupts_restore(ipl);
     61        if (THREAD)
     62                thread_migration_enable();
    6563}
    6664
  • kernel/generic/src/time/timeout.c

    r25bef0ff r6a44ee4  
    5454{
    5555        irq_spinlock_initialize(&CPU->timeoutlock, "cpu.timeoutlock");
    56         list_initialize(&CPU->timeout_active_head);
     56        list_initialize(&CPU->timeout_active_list);
    5757}
    5858
     
    119119        timeout_t *target = NULL;
    120120        link_t *cur;
    121         for (cur = CPU->timeout_active_head.next;
    122             cur != &CPU->timeout_active_head; cur = cur->next) {
     121        for (cur = CPU->timeout_active_list.head.next;
     122            cur != &CPU->timeout_active_list.head; cur = cur->next) {
    123123                target = list_get_instance(cur, timeout_t, link);
    124124                irq_spinlock_lock(&target->lock, false);
     
    135135        /* Avoid using cur->prev directly */
    136136        link_t *prev = cur->prev;
    137         list_prepend(&timeout->link, prev);
     137        list_insert_after(&timeout->link, prev);
    138138       
    139139        /*
     
    146146         * Decrease ticks of timeout's immediate succesor by timeout->ticks.
    147147         */
    148         if (cur != &CPU->timeout_active_head) {
     148        if (cur != &CPU->timeout_active_list.head) {
    149149                irq_spinlock_lock(&target->lock, false);
    150150                target->ticks -= timeout->ticks;
     
    184184        /*
    185185         * Now we know for sure that timeout hasn't been activated yet
    186          * and is lurking in timeout->cpu->timeout_active_head queue.
     186         * and is lurking in timeout->cpu->timeout_active_list.
    187187         */
    188188       
    189189        link_t *cur = timeout->link.next;
    190         if (cur != &timeout->cpu->timeout_active_head) {
     190        if (cur != &timeout->cpu->timeout_active_list.head) {
    191191                timeout_t *tmp = list_get_instance(cur, timeout_t, link);
    192192                irq_spinlock_lock(&tmp->lock, false);
  • kernel/generic/src/udebug/udebug.c

    r25bef0ff r6a44ee4  
    406406       
    407407        /* Finish debugging of all userspace threads */
    408         link_t *cur;
    409         for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
     408        list_foreach(task->threads, cur) {
    410409                thread_t *thread = list_get_instance(cur, thread_t, th_link);
    411410               
  • kernel/generic/src/udebug/udebug_ops.c

    r25bef0ff r6a44ee4  
    196196        /* Set udebug.active on all of the task's userspace threads. */
    197197       
    198         link_t *cur;
    199         for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
     198        list_foreach(TASK->threads, cur) {
    200199                thread_t *thread = list_get_instance(cur, thread_t, th_link);
    201200               
     
    390389       
    391390        /* FIXME: make sure the thread isn't past debug shutdown... */
    392         link_t *cur;
    393         for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) {
     391        list_foreach(TASK->threads, cur) {
    394392                thread_t *thread = list_get_instance(cur, thread_t, th_link);
    395393               
Note: See TracChangeset for help on using the changeset viewer.