Changeset 1affcdf3 in mainline for kernel/generic/src


Ignore:
Timestamp:
2011-06-10T19:33:41Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1878386
Parents:
13ecdac9 (diff), 79a141a (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:
32 edited

Legend:

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

    r13ecdac9 r1affcdf3  
    5252 *
    5353 */
    54 bool list_member(const link_t *link, const link_t *head)
     54int list_member(const link_t *link, const link_t *head)
    5555{
    5656        bool found = false;
  • kernel/generic/src/console/cmd.c

    r13ecdac9 r1affcdf3  
    11071107        release_console();
    11081108       
    1109         event_notify_0(EVENT_KCONSOLE);
     1109        event_notify_0(EVENT_KCONSOLE, false);
    11101110        indev_pop_character(stdin);
    11111111       
  • kernel/generic/src/console/console.c

    r13ecdac9 r1affcdf3  
    5353#include <str.h>
    5454
    55 #define KLOG_PAGES    4
     55#define KLOG_PAGES    8
    5656#define KLOG_LENGTH   (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))
    57 #define KLOG_LATENCY  8
    5857
    5958/** Kernel log cyclic buffer */
     
    6160
    6261/** Kernel log initialized */
    63 static bool klog_inited = false;
     62static atomic_t klog_inited = {false};
    6463
    6564/** First kernel log characters */
     
    7675
    7776/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "*klog_lock");
     77SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");
    7978
    8079/** Physical memory area used for klog buffer */
     
    166165        sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES);
    167166       
    168         spinlock_lock(&klog_lock);
    169         klog_inited = true;
    170         spinlock_unlock(&klog_lock);
     167        event_set_unmask_callback(EVENT_KLOG, klog_update);
     168        atomic_set(&klog_inited, true);
    171169}
    172170
     
    263261void klog_update(void)
    264262{
     263        if (!atomic_get(&klog_inited))
     264                return;
     265       
    265266        spinlock_lock(&klog_lock);
    266267       
    267         if ((klog_inited) && (event_is_subscribed(EVENT_KLOG)) && (klog_uspace > 0)) {
    268                 event_notify_3(EVENT_KLOG, klog_start, klog_len, klog_uspace);
    269                 klog_uspace = 0;
     268        if (klog_uspace > 0) {
     269                if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len,
     270                    klog_uspace) == EOK)
     271                        klog_uspace = 0;
    270272        }
    271273       
     
    275277void putchar(const wchar_t ch)
    276278{
     279        bool ordy = ((stdout) && (stdout->op->write));
     280       
    277281        spinlock_lock(&klog_lock);
    278282       
    279         if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
    280                 /* Print charaters stored in kernel log */
    281                 size_t i;
    282                 for (i = klog_len - klog_stored; i < klog_len; i++)
    283                         stdout->op->write(stdout, klog[(klog_start + i) % KLOG_LENGTH], silent);
    284                 klog_stored = 0;
     283        /* Print charaters stored in kernel log */
     284        if (ordy) {
     285                while (klog_stored > 0) {
     286                        wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH];
     287                        klog_stored--;
     288                       
     289                        /*
     290                         * We need to give up the spinlock for
     291                         * the physical operation of writting out
     292                         * the character.
     293                         */
     294                        spinlock_unlock(&klog_lock);
     295                        stdout->op->write(stdout, tmp, silent);
     296                        spinlock_lock(&klog_lock);
     297                }
    285298        }
    286299       
     
    292305                klog_start = (klog_start + 1) % KLOG_LENGTH;
    293306       
    294         if ((stdout) && (stdout->op->write))
     307        if (!ordy) {
     308                if (klog_stored < klog_len)
     309                        klog_stored++;
     310        }
     311       
     312        /* The character is stored for uspace */
     313        if (klog_uspace < klog_len)
     314                klog_uspace++;
     315       
     316        spinlock_unlock(&klog_lock);
     317       
     318        if (ordy) {
     319                /*
     320                 * Output the character. In this case
     321                 * it should be no longer buffered.
     322                 */
    295323                stdout->op->write(stdout, ch, silent);
    296         else {
     324        } else {
    297325                /*
    298326                 * No standard output routine defined yet.
     
    304332                 * Note that the early_putc() function might be
    305333                 * a no-op on certain hardware configurations.
    306                  *
    307334                 */
    308335                early_putchar(ch);
    309                
    310                 if (klog_stored < klog_len)
    311                         klog_stored++;
    312         }
    313        
    314         /* The character is stored for uspace */
    315         if (klog_uspace < klog_len)
    316                 klog_uspace++;
    317        
    318         /* Check notify uspace to update */
    319         bool update;
    320         if ((klog_uspace > KLOG_LATENCY) || (ch == '\n'))
    321                 update = true;
    322         else
    323                 update = false;
    324        
    325         spinlock_unlock(&klog_lock);
    326        
    327         if (update)
     336        }
     337       
     338        /* Force notification on newline */
     339        if (ch == '\n')
    328340                klog_update();
    329341}
  • kernel/generic/src/ddi/ddi.c

    r13ecdac9 r1affcdf3  
    224224        task_t *task = task_find_by_id(id);
    225225       
    226         if ((!task) || (!context_check(CONTEXT, task->context))) {
     226        if ((!task) || (!container_check(CONTAINER, task->container))) {
    227227                /*
    228228                 * There is no task with the specified ID
  • kernel/generic/src/debug/panic.c

    r13ecdac9 r1affcdf3  
    9595        printf("\n");
    9696       
     97        printf("THE=%p: ", THE);
     98        if (THE != NULL) {
     99                printf("pe=%" PRIun " thr=%p task=%p cpu=%p as=%p"
     100                    " magic=%#" PRIx32 "\n", THE->preemption_disabled,
     101                    THE->thread, THE->task, THE->cpu, THE->as, THE->magic);
     102        } else
     103                printf("invalid\n");
     104       
    97105        if (istate) {
    98106                istate_decode(istate);
  • kernel/generic/src/interrupt/interrupt.c

    r13ecdac9 r1affcdf3  
    177177            (void *) istate_get_pc(istate));
    178178       
     179        istate_decode(istate);
    179180        stack_trace_istate(istate);
    180181       
     
    205206         * stack.
    206207         */
    207         return (istate_t *) ((uint8_t *) thread->kstack + THREAD_STACK_SIZE -
    208             sizeof(istate_t));
     208        return (istate_t *) ((uint8_t *)
     209            thread->kstack + STACK_SIZE - sizeof(istate_t));
    209210}
    210211
  • kernel/generic/src/ipc/event.c

    r13ecdac9 r1affcdf3  
    4848static event_t events[EVENT_END];
    4949
    50 /** Initialize kernel events. */
     50/** Initialize kernel events.
     51 *
     52 */
    5153void event_init(void)
    5254{
    53         unsigned int i;
    54        
    55         for (i = 0; i < EVENT_END; i++) {
     55        for (unsigned int i = 0; i < EVENT_END; i++) {
    5656                spinlock_initialize(&events[i].lock, "event.lock");
    5757                events[i].answerbox = NULL;
    5858                events[i].counter = 0;
    5959                events[i].imethod = 0;
     60                events[i].masked = false;
     61                events[i].unmask_callback = NULL;
    6062        }
    6163}
    6264
     65/** Unsubscribe kernel events associated with an answerbox
     66 *
     67 * @param answerbox Answerbox to be unsubscribed.
     68 *
     69 */
     70void event_cleanup_answerbox(answerbox_t *answerbox)
     71{
     72        for (unsigned int i = 0; i < EVENT_END; i++) {
     73                spinlock_lock(&events[i].lock);
     74               
     75                if (events[i].answerbox == answerbox) {
     76                        events[i].answerbox = NULL;
     77                        events[i].counter = 0;
     78                        events[i].imethod = 0;
     79                        events[i].masked = false;
     80                }
     81               
     82                spinlock_unlock(&events[i].lock);
     83        }
     84}
     85
     86/** Define a callback function for the event unmask event.
     87 *
     88 * @param evno     Event type.
     89 * @param callback Callback function to be called when
     90 *                 the event is unmasked.
     91 *
     92 */
     93void event_set_unmask_callback(event_type_t evno, event_callback_t callback)
     94{
     95        ASSERT(evno < EVENT_END);
     96       
     97        spinlock_lock(&events[evno].lock);
     98        events[evno].unmask_callback = callback;
     99        spinlock_unlock(&events[evno].lock);
     100}
     101
     102/** Send kernel notification event
     103 *
     104 * @param evno Event type.
     105 * @param mask Mask further notifications after a successful
     106 *             sending.
     107 * @param a1   First argument.
     108 * @param a2   Second argument.
     109 * @param a3   Third argument.
     110 * @param a4   Fourth argument.
     111 * @param a5   Fifth argument.
     112 *
     113 * @return EOK if notification was successfully sent.
     114 * @return ENOMEM if the notification IPC message failed to allocate.
     115 * @return EBUSY if the notifications of the given type are
     116 *         currently masked.
     117 * @return ENOENT if the notifications of the given type are
     118 *         currently not subscribed.
     119 *
     120 */
     121int event_notify(event_type_t evno, bool mask, sysarg_t a1, sysarg_t a2,
     122    sysarg_t a3, sysarg_t a4, sysarg_t a5)
     123{
     124        ASSERT(evno < EVENT_END);
     125       
     126        spinlock_lock(&events[evno].lock);
     127       
     128        int ret;
     129       
     130        if (events[evno].answerbox != NULL) {
     131                if (!events[evno].masked) {
     132                        call_t *call = ipc_call_alloc(FRAME_ATOMIC);
     133                       
     134                        if (call) {
     135                                call->flags |= IPC_CALL_NOTIF;
     136                                call->priv = ++events[evno].counter;
     137                               
     138                                IPC_SET_IMETHOD(call->data, events[evno].imethod);
     139                                IPC_SET_ARG1(call->data, a1);
     140                                IPC_SET_ARG2(call->data, a2);
     141                                IPC_SET_ARG3(call->data, a3);
     142                                IPC_SET_ARG4(call->data, a4);
     143                                IPC_SET_ARG5(call->data, a5);
     144                               
     145                                irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
     146                                list_append(&call->link, &events[evno].answerbox->irq_notifs);
     147                                irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
     148                               
     149                                waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
     150                               
     151                                if (mask)
     152                                        events[evno].masked = true;
     153                               
     154                                ret = EOK;
     155                        } else
     156                                ret = ENOMEM;
     157                } else
     158                        ret = EBUSY;
     159        } else
     160                ret = ENOENT;
     161       
     162        spinlock_unlock(&events[evno].lock);
     163       
     164        return ret;
     165}
     166
     167/** Subscribe event notifications
     168 *
     169 * @param evno      Event type.
     170 * @param imethod   IPC interface and method to be used for
     171 *                  the notifications.
     172 * @param answerbox Answerbox to send the notifications to.
     173 *
     174 * @return EOK if the subscription was successful.
     175 * @return EEXISTS if the notifications of the given type are
     176 *         already subscribed.
     177 *
     178 */
    63179static int event_subscribe(event_type_t evno, sysarg_t imethod,
    64180    answerbox_t *answerbox)
    65181{
    66         if (evno >= EVENT_END)
    67                 return ELIMIT;
     182        ASSERT(evno < EVENT_END);
    68183       
    69184        spinlock_lock(&events[evno].lock);
     
    75190                events[evno].imethod = imethod;
    76191                events[evno].counter = 0;
     192                events[evno].masked = false;
    77193                res = EOK;
    78194        } else
     
    84200}
    85201
     202/** Unmask event notifications
     203 *
     204 * @param evno Event type to unmask.
     205 *
     206 */
     207static void event_unmask(event_type_t evno)
     208{
     209        ASSERT(evno < EVENT_END);
     210       
     211        spinlock_lock(&events[evno].lock);
     212        events[evno].masked = false;
     213        event_callback_t callback = events[evno].unmask_callback;
     214        spinlock_unlock(&events[evno].lock);
     215       
     216        /*
     217         * Check if there is an unmask callback
     218         * function defined for this event.
     219         */
     220        if (callback != NULL)
     221                callback();
     222}
     223
     224/** Event notification syscall wrapper
     225 *
     226 * @param evno    Event type to subscribe.
     227 * @param imethod IPC interface and method to be used for
     228 *                the notifications.
     229 *
     230 * @return EOK on success.
     231 * @return ELIMIT on unknown event type.
     232 * @return EEXISTS if the notifications of the given type are
     233 *         already subscribed.
     234 *
     235 */
    86236sysarg_t sys_event_subscribe(sysarg_t evno, sysarg_t imethod)
    87237{
     238        if (evno >= EVENT_END)
     239                return ELIMIT;
     240       
    88241        return (sysarg_t) event_subscribe((event_type_t) evno, (sysarg_t)
    89242            imethod, &TASK->answerbox);
    90243}
    91244
    92 bool event_is_subscribed(event_type_t evno)
    93 {
    94         bool res;
    95        
    96         ASSERT(evno < EVENT_END);
    97        
    98         spinlock_lock(&events[evno].lock);
    99         res = events[evno].answerbox != NULL;
    100         spinlock_unlock(&events[evno].lock);
    101        
    102         return res;
    103 }
    104 
    105 
    106 void event_cleanup_answerbox(answerbox_t *answerbox)
    107 {
    108         unsigned int i;
    109        
    110         for (i = 0; i < EVENT_END; i++) {
    111                 spinlock_lock(&events[i].lock);
    112                 if (events[i].answerbox == answerbox) {
    113                         events[i].answerbox = NULL;
    114                         events[i].counter = 0;
    115                         events[i].imethod = 0;
    116                 }
    117                 spinlock_unlock(&events[i].lock);
    118         }
    119 }
    120 
    121 void event_notify(event_type_t evno, sysarg_t a1, sysarg_t a2, sysarg_t a3,
    122     sysarg_t a4, sysarg_t a5)
    123 {
    124         ASSERT(evno < EVENT_END);
    125        
    126         spinlock_lock(&events[evno].lock);
    127         if (events[evno].answerbox != NULL) {
    128                 call_t *call = ipc_call_alloc(FRAME_ATOMIC);
    129                 if (call) {
    130                         call->flags |= IPC_CALL_NOTIF;
    131                         call->priv = ++events[evno].counter;
    132                         IPC_SET_IMETHOD(call->data, events[evno].imethod);
    133                         IPC_SET_ARG1(call->data, a1);
    134                         IPC_SET_ARG2(call->data, a2);
    135                         IPC_SET_ARG3(call->data, a3);
    136                         IPC_SET_ARG4(call->data, a4);
    137                         IPC_SET_ARG5(call->data, a5);
    138                        
    139                         irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
    140                         list_append(&call->link, &events[evno].answerbox->irq_notifs);
    141                         irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
    142                        
    143                         waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
    144                 }
    145         }
    146         spinlock_unlock(&events[evno].lock);
     245/** Event notification unmask syscall wrapper
     246 *
     247 * Note that currently no tests are performed whether the calling
     248 * task is entitled to unmask the notifications. However, thanks
     249 * to the fact that notification masking is only a performance
     250 * optimization, this has probably no security implications.
     251 *
     252 * @param evno Event type to unmask.
     253 *
     254 * @return EOK on success.
     255 * @return ELIMIT on unknown event type.
     256 *
     257 */
     258sysarg_t sys_event_unmask(sysarg_t evno)
     259{
     260        if (evno >= EVENT_END)
     261                return ELIMIT;
     262       
     263        event_unmask((event_type_t) evno);
     264        return EOK;
    147265}
    148266
  • kernel/generic/src/ipc/ipc.c

    r13ecdac9 r1affcdf3  
    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>
  • kernel/generic/src/ipc/irq.c

    r13ecdac9 r1affcdf3  
    174174        irq->notif_cfg.code = code;
    175175        irq->notif_cfg.counter = 0;
     176        irq->driver_as = AS;
    176177       
    177178        /*
     
    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

    r13ecdac9 r1affcdf3  
    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

    r13ecdac9 r1affcdf3  
    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/elf.c

    r13ecdac9 r1affcdf3  
    114114        }
    115115       
    116         /* Inspect all section headers and proccess them. */
     116        /* Inspect all section headers and process them. */
    117117        for (i = 0; i < header->e_shnum; i++) {
    118118                elf_section_header_t *sechdr =
  • kernel/generic/src/lib/memfnc.c

    r13ecdac9 r1affcdf3  
    5656void *memset(void *dst, int val, size_t cnt)
    5757{
    58         size_t i;
    59         uint8_t *ptr = (uint8_t *) dst;
     58        uint8_t *dp = (uint8_t *) dst;
    6059       
    61         for (i = 0; i < cnt; i++)
    62                 ptr[i] = val;
     60        while (cnt-- != 0)
     61                *dp++ = val;
    6362       
    6463        return dst;
     
    8382       
    8483        while (cnt-- != 0)
    85                         *dp++ = *sp++;
     84                *dp++ = *sp++;
    8685       
    8786        return dst;
  • kernel/generic/src/main/main.c

    r13ecdac9 r1affcdf3  
    7171#include <mm/as.h>
    7272#include <mm/slab.h>
     73#include <mm/reserve.h>
    7374#include <synch/waitq.h>
    7475#include <synch/futex.h>
     
    117118#endif
    118119
    119 #define CONFIG_STACK_SIZE  ((1 << STACK_FRAMES) * STACK_SIZE)
    120 
    121120/** Main kernel routine for bootstrap CPU.
    122121 *
     
    138137        config.kernel_size = ALIGN_UP(hardcoded_ktext_size +
    139138            hardcoded_kdata_size, PAGE_SIZE);
    140         config.stack_size = CONFIG_STACK_SIZE;
     139        config.stack_size = STACK_SIZE;
    141140       
    142141        /* Initialy the stack is placed just after the kernel */
     
    164163       
    165164        context_save(&ctx);
    166         context_set(&ctx, FADDR(main_bsp_separated_stack), config.stack_base,
    167             THREAD_STACK_SIZE);
     165        context_set(&ctx, FADDR(main_bsp_separated_stack),
     166            config.stack_base, STACK_SIZE);
    168167        context_restore(&ctx);
    169168        /* not reached */
     
    217216        ddi_init();
    218217        arch_post_mm_init();
     218        reserve_init();
    219219        arch_pre_smp_init();
    220220        smp_init();
     
    321321        context_save(&CPU->saved_context);
    322322        context_set(&CPU->saved_context, FADDR(main_ap_separated_stack),
    323             (uintptr_t) CPU->stack, CPU_STACK_SIZE);
     323            (uintptr_t) CPU->stack, STACK_SIZE);
    324324        context_restore(&CPU->saved_context);
    325325        /* not reached */
  • kernel/generic/src/main/uinit.c

    r13ecdac9 r1affcdf3  
    3333/**
    3434 * @file
    35  * @brief       Userspace bootstrap thread.
     35 * @brief Userspace bootstrap thread.
    3636 *
    3737 * This file contains uinit kernel thread wich is used to start every
     
    4040 * @see SYS_THREAD_CREATE
    4141 */
    42  
     42
    4343#include <main/uinit.h>
    4444#include <typedefs.h>
     
    4848#include <arch.h>
    4949#include <udebug/udebug.h>
    50 
    5150
    5251/** Thread used to bring up userspace thread.
     
    5857{
    5958        uspace_arg_t uarg;
    60 
     59       
    6160        /*
    6261         * So far, we don't have a use for joining userspace threads so we
     
    6867         */
    6968        thread_detach(THREAD);
    70 
     69       
    7170#ifdef CONFIG_UDEBUG
    7271        udebug_stoppable_end();
     
    7877        uarg.uspace_thread_function = NULL;
    7978        uarg.uspace_thread_arg = NULL;
    80 
     79       
    8180        free((uspace_arg_t *) arg);
    8281       
  • kernel/generic/src/main/version.c

    r13ecdac9 r1affcdf3  
    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

    r13ecdac9 r1affcdf3  
    302302         * We don't want any area to have conflicts with NULL page.
    303303         */
    304         if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
     304        if (overlaps(addr, P2SZ(count), (uintptr_t) NULL, PAGE_SIZE))
    305305                return false;
    306306       
     
    329329                        mutex_lock(&area->lock);
    330330                       
    331                         if (overlaps(addr, count << PAGE_WIDTH,
    332                             area->base, area->pages << PAGE_WIDTH)) {
     331                        if (overlaps(addr, P2SZ(count), area->base,
     332                            P2SZ(area->pages))) {
    333333                                mutex_unlock(&area->lock);
    334334                                return false;
     
    346346                        mutex_lock(&area->lock);
    347347                       
    348                         if (overlaps(addr, count << PAGE_WIDTH,
    349                             area->base, area->pages << PAGE_WIDTH)) {
     348                        if (overlaps(addr, P2SZ(count), area->base,
     349                            P2SZ(area->pages))) {
    350350                                mutex_unlock(&area->lock);
    351351                                return false;
     
    366366                mutex_lock(&area->lock);
    367367               
    368                 if (overlaps(addr, count << PAGE_WIDTH,
    369                     area->base, area->pages << PAGE_WIDTH)) {
     368                if (overlaps(addr, P2SZ(count), area->base,
     369                    P2SZ(area->pages))) {
    370370                        mutex_unlock(&area->lock);
    371371                        return false;
     
    380380         */
    381381        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    382                 return !overlaps(addr, count << PAGE_WIDTH,
    383                     KERNEL_ADDRESS_SPACE_START,
     382                return !overlaps(addr, P2SZ(count), KERNEL_ADDRESS_SPACE_START,
    384383                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
    385384        }
     
    474473       
    475474        btree_node_t *leaf;
    476         as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
     475        as_area_t *area = (as_area_t *) btree_search(&as->as_area_btree, va,
     476            &leaf);
    477477        if (area) {
    478478                /* va is the base address of an address space area */
     
    482482       
    483483        /*
    484          * Search the leaf node and the righmost record of its left neighbour
     484         * Search the leaf node and the rightmost record of its left neighbour
    485485         * to find out whether this is a miss or va belongs to an address
    486486         * space area found there.
     
    494494               
    495495                mutex_lock(&area->lock);
    496                
     496
    497497                if ((area->base <= va) &&
    498                     (va < area->base + (area->pages << PAGE_WIDTH)))
     498                    (va <= area->base + (P2SZ(area->pages) - 1)))
    499499                        return area;
    500500               
     
    506506         * Because of its position in the B+tree, it must have base < va.
    507507         */
    508         btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     508        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree,
     509            leaf);
    509510        if (lnode) {
    510511                area = (as_area_t *) lnode->value[lnode->keys - 1];
     
    512513                mutex_lock(&area->lock);
    513514               
    514                 if (va < area->base + (area->pages << PAGE_WIDTH))
     515                if (va <= area->base + (P2SZ(area->pages) - 1))
    515516                        return area;
    516517               
     
    577578       
    578579        if (pages < area->pages) {
    579                 uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
     580                uintptr_t start_free = area->base + P2SZ(pages);
    580581               
    581582                /*
     
    590591                 */
    591592                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    592                     area->base + (pages << PAGE_WIDTH), area->pages - pages);
     593                    area->base + P2SZ(pages), area->pages - pages);
    593594               
    594595                /*
     
    613614                                size_t i = 0;
    614615                               
    615                                 if (overlaps(ptr, size << PAGE_WIDTH, area->base,
    616                                     pages << PAGE_WIDTH)) {
     616                                if (overlaps(ptr, P2SZ(size), area->base,
     617                                    P2SZ(pages))) {
    617618                                       
    618                                         if (ptr + (size << PAGE_WIDTH) <= start_free) {
     619                                        if (ptr + P2SZ(size) <= start_free) {
    619620                                                /*
    620621                                                 * The whole interval fits
     
    647648                               
    648649                                for (; i < size; i++) {
    649                                         pte_t *pte = page_mapping_find(as, ptr +
    650                                             (i << PAGE_WIDTH));
     650                                        pte_t *pte = page_mapping_find(as,
     651                                            ptr + P2SZ(i), false);
    651652                                       
    652653                                        ASSERT(pte);
     
    657658                                            (area->backend->frame_free)) {
    658659                                                area->backend->frame_free(area,
    659                                                     ptr + (i << PAGE_WIDTH),
     660                                                    ptr + P2SZ(i),
    660661                                                    PTE_GET_FRAME(pte));
    661662                                        }
    662663                                       
    663                                         page_mapping_remove(as, ptr +
    664                                             (i << PAGE_WIDTH));
     664                                        page_mapping_remove(as, ptr + P2SZ(i));
    665665                                }
    666666                        }
     
    671671                 */
    672672               
    673                 tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
     673                tlb_invalidate_pages(as->asid, area->base + P2SZ(pages),
    674674                    area->pages - pages);
    675675               
    676676                /*
    677                  * Invalidate software translation caches (e.g. TSB on sparc64).
    678                  */
    679                 as_invalidate_translation_cache(as, area->base +
    680                     (pages << PAGE_WIDTH), area->pages - pages);
     677                 * Invalidate software translation caches
     678                 * (e.g. TSB on sparc64, PHT on ppc32).
     679                 */
     680                as_invalidate_translation_cache(as, area->base + P2SZ(pages),
     681                    area->pages - pages);
    681682                tlb_shootdown_finalize(ipl);
    682683               
     
    797798                       
    798799                        for (size = 0; size < (size_t) node->value[i]; size++) {
    799                                 pte_t *pte =
    800                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     800                                pte_t *pte = page_mapping_find(as,
     801                                     ptr + P2SZ(size), false);
    801802                               
    802803                                ASSERT(pte);
     
    807808                                    (area->backend->frame_free)) {
    808809                                        area->backend->frame_free(area,
    809                                             ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
     810                                            ptr + P2SZ(size),
     811                                            PTE_GET_FRAME(pte));
    810812                                }
    811813                               
    812                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     814                                page_mapping_remove(as, ptr + P2SZ(size));
    813815                        }
    814816                }
     
    822824       
    823825        /*
    824          * Invalidate potential software translation caches (e.g. TSB on
    825          * sparc64).
     826         * Invalidate potential software translation caches
     827         * (e.g. TSB on sparc64, PHT on ppc32).
    826828         */
    827829        as_invalidate_translation_cache(as, area->base, area->pages);
     
    897899        }
    898900       
    899         size_t src_size = src_area->pages << PAGE_WIDTH;
     901        size_t src_size = P2SZ(src_area->pages);
    900902        unsigned int src_flags = src_area->flags;
    901903        mem_backend_t *src_backend = src_area->backend;
     
    10941096        for (cur = area->used_space.leaf_head.next;
    10951097            cur != &area->used_space.leaf_head; cur = cur->next) {
    1096                 btree_node_t *node
    1097                     = list_get_instance(cur, btree_node_t, leaf_link);
     1098                btree_node_t *node = list_get_instance(cur, btree_node_t,
     1099                    leaf_link);
    10981100                btree_key_t i;
    10991101               
     
    11031105                       
    11041106                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1105                                 pte_t *pte =
    1106                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     1107                                pte_t *pte = page_mapping_find(as,
     1108                                    ptr + P2SZ(size), false);
    11071109                               
    11081110                                ASSERT(pte);
     
    11131115                               
    11141116                                /* Remove old mapping */
    1115                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     1117                                page_mapping_remove(as, ptr + P2SZ(size));
    11161118                        }
    11171119                }
     
    11251127       
    11261128        /*
    1127          * Invalidate potential software translation caches (e.g. TSB on
    1128          * sparc64).
     1129         * Invalidate potential software translation caches
     1130         * (e.g. TSB on sparc64, PHT on ppc32).
    11291131         */
    11301132        as_invalidate_translation_cache(as, area->base, area->pages);
     
    11591161                               
    11601162                                /* Insert the new mapping */
    1161                                 page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
     1163                                page_mapping_insert(as, ptr + P2SZ(size),
    11621164                                    old_frame[frame_idx++], page_flags);
    11631165                               
     
    12401242         */
    12411243        pte_t *pte;
    1242         if ((pte = page_mapping_find(AS, page))) {
     1244        if ((pte = page_mapping_find(AS, page, false))) {
    12431245                if (PTE_PRESENT(pte)) {
    12441246                        if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
     
    14811483       
    14821484        if (src_area) {
    1483                 size = src_area->pages << PAGE_WIDTH;
     1485                size = P2SZ(src_area->pages);
    14841486                mutex_unlock(&src_area->lock);
    14851487        } else
     
    15361538                if (page >= right_pg) {
    15371539                        /* Do nothing. */
    1538                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1539                     left_cnt << PAGE_WIDTH)) {
     1540                } else if (overlaps(page, P2SZ(count), left_pg,
     1541                    P2SZ(left_cnt))) {
    15401542                        /* The interval intersects with the left interval. */
    15411543                        return false;
    1542                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1543                     right_cnt << PAGE_WIDTH)) {
     1544                } else if (overlaps(page, P2SZ(count), right_pg,
     1545                    P2SZ(right_cnt))) {
    15441546                        /* The interval intersects with the right interval. */
    15451547                        return false;
    1546                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1547                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1548                } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1549                    (page + P2SZ(count) == right_pg)) {
    15481550                        /*
    15491551                         * The interval can be added by merging the two already
     
    15531555                        btree_remove(&area->used_space, right_pg, leaf);
    15541556                        goto success;
    1555                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1557                } else if (page == left_pg + P2SZ(left_cnt)) {
    15561558                        /*
    15571559                         * The interval can be added by simply growing the left
     
    15601562                        node->value[node->keys - 1] += count;
    15611563                        goto success;
    1562                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1564                } else if (page + P2SZ(count) == right_pg) {
    15631565                        /*
    15641566                         * The interval can be addded by simply moving base of
     
    15871589                 */
    15881590               
    1589                 if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1590                     right_cnt << PAGE_WIDTH)) {
     1591                if (overlaps(page, P2SZ(count), right_pg, P2SZ(right_cnt))) {
    15911592                        /* The interval intersects with the right interval. */
    15921593                        return false;
    1593                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1594                } else if (page + P2SZ(count) == right_pg) {
    15941595                        /*
    15951596                         * The interval can be added by moving the base of the
     
    16261627                if (page < left_pg) {
    16271628                        /* Do nothing. */
    1628                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1629                     left_cnt << PAGE_WIDTH)) {
     1629                } else if (overlaps(page, P2SZ(count), left_pg,
     1630                    P2SZ(left_cnt))) {
    16301631                        /* The interval intersects with the left interval. */
    16311632                        return false;
    1632                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1633                     right_cnt << PAGE_WIDTH)) {
     1633                } else if (overlaps(page, P2SZ(count), right_pg,
     1634                    P2SZ(right_cnt))) {
    16341635                        /* The interval intersects with the right interval. */
    16351636                        return false;
    1636                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1637                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1637                } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1638                    (page + P2SZ(count) == right_pg)) {
    16381639                        /*
    16391640                         * The interval can be added by merging the two already
     
    16431644                        btree_remove(&area->used_space, right_pg, node);
    16441645                        goto success;
    1645                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1646                } else if (page == left_pg + P2SZ(left_cnt)) {
    16461647                        /*
    16471648                         * The interval can be added by simply growing the left
     
    16501651                        leaf->value[leaf->keys - 1] += count;
    16511652                        goto success;
    1652                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1653                } else if (page + P2SZ(count) == right_pg) {
    16531654                        /*
    16541655                         * The interval can be addded by simply moving base of
     
    16771678                 */
    16781679               
    1679                 if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1680                     left_cnt << PAGE_WIDTH)) {
     1680                if (overlaps(page, P2SZ(count), left_pg, P2SZ(left_cnt))) {
    16811681                        /* The interval intersects with the left interval. */
    16821682                        return false;
    1683                 } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
     1683                } else if (left_pg + P2SZ(left_cnt) == page) {
    16841684                        /*
    16851685                         * The interval can be added by growing the left
     
    17161716                         */
    17171717                       
    1718                         if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1719                             left_cnt << PAGE_WIDTH)) {
     1718                        if (overlaps(page, P2SZ(count), left_pg,
     1719                            P2SZ(left_cnt))) {
    17201720                                /*
    17211721                                 * The interval intersects with the left
     
    17231723                                 */
    17241724                                return false;
    1725                         } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1726                             right_cnt << PAGE_WIDTH)) {
     1725                        } else if (overlaps(page, P2SZ(count), right_pg,
     1726                            P2SZ(right_cnt))) {
    17271727                                /*
    17281728                                 * The interval intersects with the right
     
    17301730                                 */
    17311731                                return false;
    1732                         } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1733                             (page + (count << PAGE_WIDTH) == right_pg)) {
     1732                        } else if ((page == left_pg + P2SZ(left_cnt)) &&
     1733                            (page + P2SZ(count) == right_pg)) {
    17341734                                /*
    17351735                                 * The interval can be added by merging the two
     
    17391739                                btree_remove(&area->used_space, right_pg, leaf);
    17401740                                goto success;
    1741                         } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1741                        } else if (page == left_pg + P2SZ(left_cnt)) {
    17421742                                /*
    17431743                                 * The interval can be added by simply growing
     
    17461746                                leaf->value[i - 1] += count;
    17471747                                goto success;
    1748                         } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1748                        } else if (page + P2SZ(count) == right_pg) {
    17491749                                /*
    17501750                                 * The interval can be addded by simply moving
     
    18121812                        for (i = 0; i < leaf->keys; i++) {
    18131813                                if (leaf->key[i] == page) {
    1814                                         leaf->key[i] += count << PAGE_WIDTH;
     1814                                        leaf->key[i] += P2SZ(count);
    18151815                                        leaf->value[i] -= count;
    18161816                                        goto success;
     
    18221822        }
    18231823       
    1824         btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space, leaf);
     1824        btree_node_t *node = btree_leaf_node_left_neighbour(&area->used_space,
     1825            leaf);
    18251826        if ((node) && (page < leaf->key[0])) {
    18261827                uintptr_t left_pg = node->key[node->keys - 1];
    18271828                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18281829               
    1829                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1830                     count << PAGE_WIDTH)) {
    1831                         if (page + (count << PAGE_WIDTH) ==
    1832                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1830                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
     1831                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
    18331832                                /*
    18341833                                 * The interval is contained in the rightmost
     
    18391838                                node->value[node->keys - 1] -= count;
    18401839                                goto success;
    1841                         } else if (page + (count << PAGE_WIDTH) <
    1842                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1840                        } else if (page + P2SZ(count) <
     1841                            left_pg + P2SZ(left_cnt)) {
     1842                                size_t new_cnt;
     1843
    18431844                                /*
    18441845                                 * The interval is contained in the rightmost
     
    18481849                                 * new interval.
    18491850                                 */
    1850                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1851                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1851                                new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1852                                    (page + P2SZ(count))) >> PAGE_WIDTH;
    18521853                                node->value[node->keys - 1] -= count + new_cnt;
    18531854                                btree_insert(&area->used_space, page +
    1854                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1855                                    P2SZ(count), (void *) new_cnt, leaf);
    18551856                                goto success;
    18561857                        }
     
    18651866                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    18661867               
    1867                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1868                     count << PAGE_WIDTH)) {
    1869                         if (page + (count << PAGE_WIDTH) ==
    1870                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1868                if (overlaps(left_pg, P2SZ(left_cnt), page, P2SZ(count))) {
     1869                        if (page + P2SZ(count) == left_pg + P2SZ(left_cnt)) {
    18711870                                /*
    18721871                                 * The interval is contained in the rightmost
     
    18761875                                leaf->value[leaf->keys - 1] -= count;
    18771876                                goto success;
    1878                         } else if (page + (count << PAGE_WIDTH) < left_pg +
    1879                             (left_cnt << PAGE_WIDTH)) {
     1877                        } else if (page + P2SZ(count) < left_pg +
     1878                            P2SZ(left_cnt)) {
     1879                                size_t new_cnt;
     1880
    18801881                                /*
    18811882                                 * The interval is contained in the rightmost
     
    18851886                                 * interval.
    18861887                                 */
    1887                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1888                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1888                                new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1889                                    (page + P2SZ(count))) >> PAGE_WIDTH;
    18891890                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    18901891                                btree_insert(&area->used_space, page +
    1891                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1892                                    P2SZ(count), (void *) new_cnt, leaf);
    18921893                                goto success;
    18931894                        }
     
    19111912                         * to (i - 1) and i.
    19121913                         */
    1913                         if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1914                             count << PAGE_WIDTH)) {
    1915                                 if (page + (count << PAGE_WIDTH) ==
    1916                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1914                        if (overlaps(left_pg, P2SZ(left_cnt), page,
     1915                            P2SZ(count))) {
     1916                                if (page + P2SZ(count) ==
     1917                                    left_pg + P2SZ(left_cnt)) {
    19171918                                        /*
    19181919                                         * The interval is contained in the
     
    19231924                                        leaf->value[i - 1] -= count;
    19241925                                        goto success;
    1925                                 } else if (page + (count << PAGE_WIDTH) <
    1926                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1926                                } else if (page + P2SZ(count) <
     1927                                    left_pg + P2SZ(left_cnt)) {
     1928                                        size_t new_cnt;
     1929
    19271930                                        /*
    19281931                                         * The interval is contained in the
     
    19321935                                         * also inserting a new interval.
    19331936                                         */
    1934                                         size_t new_cnt = ((left_pg +
    1935                                             (left_cnt << PAGE_WIDTH)) -
    1936                                             (page + (count << PAGE_WIDTH))) >>
     1937                                        new_cnt = ((left_pg + P2SZ(left_cnt)) -
     1938                                            (page + P2SZ(count))) >>
    19371939                                            PAGE_WIDTH;
    19381940                                        leaf->value[i - 1] -= count + new_cnt;
    19391941                                        btree_insert(&area->used_space, page +
    1940                                             (count << PAGE_WIDTH), (void *) new_cnt,
     1942                                            P2SZ(count), (void *) new_cnt,
    19411943                                            leaf);
    19421944                                        goto success;
     
    20342036                btree_key_t i;
    20352037                for (i = 0; (ret == 0) && (i < node->keys); i++) {
     2038                        uintptr_t addr;
     2039
    20362040                        as_area_t *area = (as_area_t *) node->value[i];
    20372041                       
    20382042                        mutex_lock(&area->lock);
    20392043                       
    2040                         uintptr_t addr =
    2041                             ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
     2044                        addr = ALIGN_UP(area->base + P2SZ(area->pages),
    20422045                            PAGE_SIZE);
    20432046                       
     
    20982101                       
    20992102                        info[area_idx].start_addr = area->base;
    2100                         info[area_idx].size = FRAMES2SIZE(area->pages);
     2103                        info[area_idx].size = P2SZ(area->pages);
    21012104                        info[area_idx].flags = area->flags;
    21022105                        ++area_idx;
     
    21362139                            " (%p - %p)\n", area, (void *) area->base,
    21372140                            area->pages, (void *) area->base,
    2138                             (void *) (area->base + FRAMES2SIZE(area->pages)));
     2141                            (void *) (area->base + P2SZ(area->pages)));
    21392142                        mutex_unlock(&area->lock);
    21402143                }
  • kernel/generic/src/mm/backend_anon.c

    r13ecdac9 r1affcdf3  
    5050#include <typedefs.h>
    5151#include <align.h>
     52#include <memstr.h>
    5253#include <arch.h>
    5354
     
    121122                                page_table_lock(area->as, false);
    122123                                pte = page_mapping_find(area->as,
    123                                     base + j * PAGE_SIZE);
     124                                    base + P2SZ(j), false);
    124125                                ASSERT(pte && PTE_VALID(pte) &&
    125126                                    PTE_PRESENT(pte));
    126127                                btree_insert(&area->sh_info->pagemap,
    127                                     (base + j * PAGE_SIZE) - area->base,
     128                                    (base + P2SZ(j)) - area->base,
    128129                                    (void *) PTE_GET_FRAME(pte), NULL);
    129130                                page_table_unlock(area->as, false);
  • kernel/generic/src/mm/backend_elf.c

    r13ecdac9 r1affcdf3  
    170170                        if (!(area->flags & AS_AREA_WRITE))
    171171                                if (base >= entry->p_vaddr &&
    172                                     base + count * PAGE_SIZE <= start_anon)
     172                                    base + P2SZ(count) <= start_anon)
    173173                                        continue;
    174174                       
     
    182182                                if (!(area->flags & AS_AREA_WRITE))
    183183                                        if (base >= entry->p_vaddr &&
    184                                             base + (j + 1) * PAGE_SIZE <=
    185                                             start_anon)
     184                                            base + P2SZ(j + 1) <= start_anon)
    186185                                                continue;
    187186                               
    188187                                page_table_lock(area->as, false);
    189188                                pte = page_mapping_find(area->as,
    190                                     base + j * PAGE_SIZE);
     189                                    base + P2SZ(j), false);
    191190                                ASSERT(pte && PTE_VALID(pte) &&
    192191                                    PTE_PRESENT(pte));
    193192                                btree_insert(&area->sh_info->pagemap,
    194                                     (base + j * PAGE_SIZE) - area->base,
     193                                    (base + P2SZ(j)) - area->base,
    195194                                    (void *) PTE_GET_FRAME(pte), NULL);
    196195                                page_table_unlock(area->as, false);
  • kernel/generic/src/mm/frame.c

    r13ecdac9 r1affcdf3  
    182182 *
    183183 */
    184 #ifdef CONFIG_DEBUG
    185 NO_TRACE static size_t total_frames_free(void)
     184NO_TRACE static size_t frame_total_free_get_internal(void)
    186185{
    187186        size_t total = 0;
    188187        size_t i;
     188
    189189        for (i = 0; i < zones.count; i++)
    190190                total += zones.info[i].free_count;
     
    192192        return total;
    193193}
    194 #endif /* CONFIG_DEBUG */
     194
     195NO_TRACE size_t frame_total_free_get(void)
     196{
     197        size_t total;
     198
     199        irq_spinlock_lock(&zones.lock, true);
     200        total = frame_total_free_get_internal();
     201        irq_spinlock_unlock(&zones.lock, true);
     202
     203        return total;
     204}
     205
    195206
    196207/** Find a zone with a given frames.
     
    840851                        buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
    841852                }
    842 
    843                 /* "Unreserve" new frames. */
    844                 reserve_free(count);
    845853        } else
    846854                zone->frames = NULL;
     
    10511059               
    10521060#ifdef CONFIG_DEBUG
    1053                 size_t avail = total_frames_free();
     1061                size_t avail = frame_total_free_get_internal();
    10541062#endif
    10551063               
  • kernel/generic/src/mm/page.c

    r13ecdac9 r1affcdf3  
    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. */
     
    108112 * using flags. Allocate and setup any missing page tables.
    109113 *
    110  * @param as    Address space to wich page belongs.
     114 * @param as    Address space to which page belongs.
    111115 * @param page  Virtual address of the page to be mapped.
    112116 * @param frame Physical address of memory frame to which the mapping is
     
    135139 * this call visible.
    136140 *
    137  * @param as   Address space to wich page belongs.
     141 * @param as   Address space to which page belongs.
    138142 * @param page Virtual address of the page to be demapped.
    139143 *
     
    152156}
    153157
    154 /** Find mapping for virtual page
    155  *
    156  * Find mapping for virtual page.
    157  *
    158  * @param as   Address space to wich page belongs.
    159  * @param page Virtual page.
     158/** Find mapping for virtual page.
     159 *
     160 * @param as     Address space to which page belongs.
     161 * @param page   Virtual page.
     162 * @param nolock True if the page tables need not be locked.
    160163 *
    161164 * @return NULL if there is no such mapping; requested mapping
     
    163166 *
    164167 */
    165 NO_TRACE pte_t *page_mapping_find(as_t *as, uintptr_t page)
    166 {
    167         ASSERT(page_table_locked(as));
     168NO_TRACE pte_t *page_mapping_find(as_t *as, uintptr_t page, bool nolock)
     169{
     170        ASSERT(nolock || page_table_locked(as));
    168171       
    169172        ASSERT(page_mapping_operations);
    170173        ASSERT(page_mapping_operations->mapping_find);
    171174       
    172         return page_mapping_operations->mapping_find(as, page);
     175        return page_mapping_operations->mapping_find(as, page, nolock);
     176}
     177
     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;
    173207}
    174208
  • kernel/generic/src/mm/reserve.c

    r13ecdac9 r1affcdf3  
    4545IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(reserve_lock, "reserve_lock");
    4646static ssize_t reserve = 0;
     47
     48/** Initialize memory reservations tracking.
     49 *
     50 * This function must be called after frame zones are created and merged
     51 * and before any address space area is created.
     52 */
     53void reserve_init(void)
     54{
     55        reserve = frame_total_free_get();
     56}
    4757
    4858/** Try to reserve memory.
  • kernel/generic/src/printf/vprintf.c

    r13ecdac9 r1affcdf3  
    4141#include <typedefs.h>
    4242#include <str.h>
    43 
    44 IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(printf_lock, "*printf_lock");
    4543
    4644static int vprintf_str_write(const char *str, size_t size, void *data)
     
    9391        };
    9492       
    95         irq_spinlock_lock(&printf_lock, true);
    96         int ret = printf_core(fmt, &ps, ap);
    97         irq_spinlock_unlock(&printf_lock, true);
    98        
    99         return ret;
     93        return printf_core(fmt, &ps, ap);
    10094}
    10195
  • kernel/generic/src/proc/program.c

    r13ecdac9 r1affcdf3  
    5454#include <proc/program.h>
    5555
    56 #ifndef LOADED_PROG_STACK_PAGES_NO
    57 #define LOADED_PROG_STACK_PAGES_NO 1
    58 #endif
    59 
    6056/**
    6157 * Points to the binary image used as the program loader. All non-initial
     
    9086       
    9187        /*
    92          * Create the data address space area.
     88         * Create the stack address space area.
    9389         */
    9490        as_area_t *area = as_area_create(as,
    9591            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
    96             LOADED_PROG_STACK_PAGES_NO * PAGE_SIZE, USTACK_ADDRESS,
    97             AS_AREA_ATTR_NONE, &anon_backend, NULL);
     92            STACK_SIZE, USTACK_ADDRESS, AS_AREA_ATTR_NONE,
     93            &anon_backend, NULL);
    9894        if (!area)
    9995                return ENOMEM;
  • kernel/generic/src/proc/scheduler.c

    r13ecdac9 r1affcdf3  
    376376        context_save(&CPU->saved_context);
    377377        context_set(&CPU->saved_context, FADDR(scheduler_separated_stack),
    378             (uintptr_t) CPU->stack, CPU_STACK_SIZE);
     378            (uintptr_t) CPU->stack, STACK_SIZE);
    379379        context_restore(&CPU->saved_context);
    380380       
  • kernel/generic/src/proc/task.c

    r13ecdac9 r1affcdf3  
    190190        str_cpy(task->name, TASK_NAME_BUFLEN, name);
    191191       
    192         task->context = CONTEXT;
     192        task->container = CONTAINER;
    193193        task->capabilities = 0;
    194194        task->ucycles = 0;
     
    211211       
    212212        if ((ipc_phone_0) &&
    213             (context_check(ipc_phone_0->task->context, task->context)))
     213            (container_check(ipc_phone_0->task->container, task->container)))
    214214                ipc_phone_connect(&task->phones[0], ipc_phone_0);
    215215       
     
    534534        */
    535535        if (notify) {
    536                 if (event_is_subscribed(EVENT_FAULT)) {
    537                         /* Notify the subscriber that a fault occurred. */
    538                         event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    539                             UPPER32(TASK->taskid), (sysarg_t) THREAD);
    540                
     536                /* Notify the subscriber that a fault occurred. */
     537                if (event_notify_3(EVENT_FAULT, false, LOWER32(TASK->taskid),
     538                    UPPER32(TASK->taskid), (sysarg_t) THREAD) == EOK) {
    541539#ifdef CONFIG_UDEBUG
    542540                        /* Wait for a debugging session. */
     
    586584                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %10p %10p"
    587585                    " %9" PRIu64 "%c %9" PRIu64 "%c\n", task->taskid,
    588                     task->name, task->context, task, task->as,
     586                    task->name, task->container, task, task->as,
    589587                    ucycles, usuffix, kcycles, ksuffix);
    590588#endif
     
    597595        else
    598596                printf("%-8" PRIu64 " %-14s %-5" PRIu32 " %18p %18p\n",
    599                     task->taskid, task->name, task->context, task, task->as);
     597                    task->taskid, task->name, task->container, task, task->as);
    600598#endif
    601599       
     
    627625                printf("[id    ] [threads] [calls] [callee\n");
    628626        else
    629                 printf("[id    ] [name        ] [ctx] [address ] [as      ]"
     627                printf("[id    ] [name        ] [ctn] [address ] [as      ]"
    630628                    " [ucycles ] [kcycles ]\n");
    631629#endif
     
    636634                    " [callee\n");
    637635        else
    638                 printf("[id    ] [name        ] [ctx] [address         ]"
     636                printf("[id    ] [name        ] [ctn] [address         ]"
    639637                    " [as              ]\n");
    640638#endif
  • kernel/generic/src/proc/the.c

    r13ecdac9 r1affcdf3  
    5858        the->task = NULL;
    5959        the->as = NULL;
     60        the->magic = MAGIC;
    6061}
    6162
     
    7071NO_TRACE void the_copy(the_t *src, the_t *dst)
    7172{
     73        ASSERT(src->magic == MAGIC);
    7274        *dst = *src;
    7375}
  • kernel/generic/src/proc/thread.c

    r13ecdac9 r1affcdf3  
    5555#include <time/clock.h>
    5656#include <time/timeout.h>
     57#include <time/delay.h>
    5758#include <config.h>
    5859#include <arch/interrupt.h>
     
    6768#include <syscall/copy.h>
    6869#include <errno.h>
    69 
    70 
    71 #ifndef LOADED_PROG_STACK_PAGES_NO
    72 #define LOADED_PROG_STACK_PAGES_NO 1
    73 #endif
    74 
    7570
    7671/** Thread states */
     
    300295       
    301296        /* Not needed, but good for debugging */
    302         memsetb(thread->kstack, THREAD_STACK_SIZE * 1 << STACK_FRAMES, 0);
     297        memsetb(thread->kstack, STACK_SIZE, 0);
    303298       
    304299        irq_spinlock_lock(&tidlock, true);
     
    308303        context_save(&thread->saved_context);
    309304        context_set(&thread->saved_context, FADDR(cushion),
    310             (uintptr_t) thread->kstack, THREAD_STACK_SIZE);
     305            (uintptr_t) thread->kstack, STACK_SIZE);
    311306       
    312307        the_initialize((the_t *) thread->kstack);
     
    605600                printf("%-8" PRIu64 " %-14s %10p %-8s %10p %-5" PRIu32 "\n",
    606601                    thread->tid, name, thread, thread_states[thread->state],
    607                     thread->task, thread->task->context);
     602                    thread->task, thread->task->container);
    608603#endif
    609604       
     
    617612                printf("%-8" PRIu64 " %-14s %18p %-8s %18p %-5" PRIu32 "\n",
    618613                    thread->tid, name, thread, thread_states[thread->state],
    619                     thread->task, thread->task->context);
     614                    thread->task, thread->task->container);
    620615#endif
    621616       
     
    658653        else
    659654                printf("[id    ] [name        ] [address ] [state ] [task    ]"
    660                     " [ctx]\n");
     655                    " [ctn]\n");
    661656#endif
    662657       
     
    667662        } else
    668663                printf("[id    ] [name        ] [address         ] [state ]"
    669                     " [task            ] [ctx]\n");
     664                    " [task            ] [ctn]\n");
    670665#endif
    671666       
     
    918913}
    919914
     915sysarg_t sys_thread_udelay(uint32_t usec)
     916{
     917        delay(usec);
     918        return 0;
     919}
     920
    920921/** @}
    921922 */
  • kernel/generic/src/security/cap.c

    r13ecdac9 r1affcdf3  
    9292        task_t *task = task_find_by_id(taskid);
    9393       
    94         if ((!task) || (!context_check(CONTEXT, task->context))) {
     94        if ((!task) || (!container_check(CONTAINER, task->container))) {
    9595                irq_spinlock_unlock(&tasks_lock, true);
    9696                return (sysarg_t) ENOENT;
     
    121121       
    122122        task_t *task = task_find_by_id(taskid);
    123         if ((!task) || (!context_check(CONTEXT, task->context))) {
     123        if ((!task) || (!container_check(CONTAINER, task->container))) {
    124124                irq_spinlock_unlock(&tasks_lock, true);
    125125                return (sysarg_t) ENOENT;
  • kernel/generic/src/synch/futex.c

    r13ecdac9 r1affcdf3  
    119119         */
    120120        page_table_lock(AS, true);
    121         t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE));
     121        t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), false);
    122122        if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
    123123                page_table_unlock(AS, true);
     
    155155         */
    156156        page_table_lock(AS, true);
    157         t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE));
     157        t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), false);
    158158        if (!t || !PTE_VALID(t) || !PTE_PRESENT(t)) {
    159159                page_table_unlock(AS, true);
  • kernel/generic/src/synch/spinlock.c

    r13ecdac9 r1affcdf3  
    9696                 * run in a simulator) that caused problems with both
    9797                 * printf_lock and the framebuffer lock.
    98                  *
    9998                 */
    10099                if (lock->name[0] == '*')
  • kernel/generic/src/syscall/syscall.c

    r13ecdac9 r1affcdf3  
    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,
     
    145148        (syshandler_t) sys_as_get_unmapped_area,
    146149       
     150        /* Page mapping related syscalls. */
     151        (syshandler_t) sys_page_find_mapping,
     152       
    147153        /* IPC related syscalls. */
    148154        (syshandler_t) sys_ipc_call_sync_fast,
     
    161167        /* Event notification syscalls. */
    162168        (syshandler_t) sys_event_subscribe,
     169        (syshandler_t) sys_event_unmask,
    163170       
    164171        /* Capabilities related syscalls. */
     
    173180        (syshandler_t) sys_unregister_irq,
    174181       
    175         /* Sysinfo syscalls */
     182        /* Sysinfo syscalls. */
    176183        (syshandler_t) sys_sysinfo_get_tag,
    177184        (syshandler_t) sys_sysinfo_get_value,
Note: See TracChangeset for help on using the changeset viewer.