Changeset b0b4592e in mainline for kernel/generic/src


Ignore:
Timestamp:
2014-03-15T19:21:53Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c773adc
Parents:
2034f98 (diff), 8cffdf5 (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:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/cmd.c

    r2034f98 rb0b4592e  
    4545#include <console/kconsole.h>
    4646#include <print.h>
     47#include <log.h>
    4748#include <panic.h>
    4849#include <typedefs.h>
     
    639640        for (i = 0; basic_commands[i]; i++) {
    640641                if (!cmd_register(basic_commands[i])) {
    641                         printf("Cannot register command %s\n",
     642                        log(LF_OTHER, LVL_ERROR,
     643                            "Cannot register command %s",
    642644                            basic_commands[i]->name);
    643645                }
     
    665667        unsigned int _len = (unsigned int) len;
    666668        if ((_len != len) || (((int) _len) < 0)) {
    667                 printf("Command length overflow\n");
     669                log(LF_OTHER, LVL_ERROR, "Command length overflow");
    668670                return 1;
    669671        }
  • kernel/generic/src/console/console.c

    r2034f98 rb0b4592e  
    5252#include <errno.h>
    5353#include <str.h>
    54 #include <abi/klog.h>
    55 
    56 #define KLOG_PAGES    8
    57 #define KLOG_LENGTH   (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))
     54#include <abi/kio.h>
     55
     56#define KIO_PAGES    8
     57#define KIO_LENGTH   (KIO_PAGES * PAGE_SIZE / sizeof(wchar_t))
    5858
    5959/** Kernel log cyclic buffer */
    60 wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE)));
     60wchar_t kio[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));
    6161
    6262/** Kernel log initialized */
    63 static atomic_t klog_inited = {false};
     63static atomic_t kio_inited = {false};
    6464
    6565/** First kernel log characters */
    66 static size_t klog_start = 0;
     66static size_t kio_start = 0;
    6767
    6868/** Number of valid kernel log characters */
    69 static size_t klog_len = 0;
     69static size_t kio_len = 0;
    7070
    7171/** Number of stored (not printed) kernel log characters */
    72 static size_t klog_stored = 0;
     72static size_t kio_stored = 0;
    7373
    7474/** Number of stored kernel log characters for uspace */
    75 static size_t klog_uspace = 0;
     75static size_t kio_uspace = 0;
    7676
    7777/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");
    79 
    80 /** Physical memory area used for klog buffer */
    81 static parea_t klog_parea;
     78SPINLOCK_INITIALIZE_NAME(kio_lock, "kio_lock");
     79
     80/** Physical memory area used for kio buffer */
     81static parea_t kio_parea;
    8282
    8383static indev_t stdin_sink;
     
    146146 *
    147147 */
    148 void klog_init(void)
    149 {
    150         void *faddr = (void *) KA2PA(klog);
     148void kio_init(void)
     149{
     150        void *faddr = (void *) KA2PA(kio);
    151151       
    152152        ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
    153153       
    154         klog_parea.pbase = (uintptr_t) faddr;
    155         klog_parea.frames = SIZE2FRAMES(sizeof(klog));
    156         klog_parea.unpriv = false;
    157         klog_parea.mapped = false;
    158         ddi_parea_register(&klog_parea);
    159        
    160         sysinfo_set_item_val("klog.faddr", NULL, (sysarg_t) faddr);
    161         sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES);
    162        
    163         event_set_unmask_callback(EVENT_KLOG, klog_update);
    164         atomic_set(&klog_inited, true);
     154        kio_parea.pbase = (uintptr_t) faddr;
     155        kio_parea.frames = SIZE2FRAMES(sizeof(kio));
     156        kio_parea.unpriv = false;
     157        kio_parea.mapped = false;
     158        ddi_parea_register(&kio_parea);
     159       
     160        sysinfo_set_item_val("kio.faddr", NULL, (sysarg_t) faddr);
     161        sysinfo_set_item_val("kio.pages", NULL, KIO_PAGES);
     162       
     163        event_set_unmask_callback(EVENT_KIO, kio_update);
     164        atomic_set(&kio_inited, true);
    165165}
    166166
     
    247247}
    248248
    249 void klog_update(void *event)
    250 {
    251         if (!atomic_get(&klog_inited))
     249void kio_update(void *event)
     250{
     251        if (!atomic_get(&kio_inited))
    252252                return;
    253253       
    254         spinlock_lock(&klog_lock);
    255        
    256         if (klog_uspace > 0) {
    257                 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len,
    258                     klog_uspace) == EOK)
    259                         klog_uspace = 0;
    260         }
    261        
    262         spinlock_unlock(&klog_lock);
     254        spinlock_lock(&kio_lock);
     255       
     256        if (kio_uspace > 0) {
     257                if (event_notify_3(EVENT_KIO, true, kio_start, kio_len,
     258                    kio_uspace) == EOK)
     259                        kio_uspace = 0;
     260        }
     261       
     262        spinlock_unlock(&kio_lock);
     263}
     264
     265/** Flush characters that are stored in the output buffer
     266 *
     267 */
     268void kio_flush(void)
     269{
     270        bool ordy = ((stdout) && (stdout->op->write));
     271       
     272        if (!ordy)
     273                return;
     274
     275        spinlock_lock(&kio_lock);
     276
     277        /* Print characters that weren't printed earlier */
     278        while (kio_stored > 0) {
     279                wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
     280                kio_stored--;
     281
     282                /*
     283                 * We need to give up the spinlock for
     284                 * the physical operation of writing out
     285                 * the character.
     286                 */
     287                spinlock_unlock(&kio_lock);
     288                stdout->op->write(stdout, tmp);
     289                spinlock_lock(&kio_lock);
     290        }
     291
     292        spinlock_unlock(&kio_lock);
     293}
     294
     295/** Put a character into the output buffer.
     296 *
     297 * The caller is required to hold kio_lock
     298 */
     299void kio_push_char(const wchar_t ch)
     300{
     301        kio[(kio_start + kio_len) % KIO_LENGTH] = ch;
     302        if (kio_len < KIO_LENGTH)
     303                kio_len++;
     304        else
     305                kio_start = (kio_start + 1) % KIO_LENGTH;
     306       
     307        if (kio_stored < kio_len)
     308                kio_stored++;
     309       
     310        /* The character is stored for uspace */
     311        if (kio_uspace < kio_len)
     312                kio_uspace++;
    263313}
    264314
     
    267317        bool ordy = ((stdout) && (stdout->op->write));
    268318       
    269         spinlock_lock(&klog_lock);
    270        
    271         /* Print charaters stored in kernel log */
    272         if (ordy) {
    273                 while (klog_stored > 0) {
    274                         wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH];
    275                         klog_stored--;
    276                        
    277                         /*
    278                          * We need to give up the spinlock for
    279                          * the physical operation of writting out
    280                          * the character.
    281                          */
    282                         spinlock_unlock(&klog_lock);
    283                         stdout->op->write(stdout, tmp);
    284                         spinlock_lock(&klog_lock);
    285                 }
    286         }
    287        
    288         /* Store character in the cyclic kernel log */
    289         klog[(klog_start + klog_len) % KLOG_LENGTH] = ch;
    290         if (klog_len < KLOG_LENGTH)
    291                 klog_len++;
    292         else
    293                 klog_start = (klog_start + 1) % KLOG_LENGTH;
     319        spinlock_lock(&kio_lock);
     320        kio_push_char(ch);
     321        spinlock_unlock(&kio_lock);
     322       
     323        /* Output stored characters */
     324        kio_flush();
    294325       
    295326        if (!ordy) {
    296                 if (klog_stored < klog_len)
    297                         klog_stored++;
    298         }
    299        
    300         /* The character is stored for uspace */
    301         if (klog_uspace < klog_len)
    302                 klog_uspace++;
    303        
    304         spinlock_unlock(&klog_lock);
    305        
    306         if (ordy) {
    307                 /*
    308                  * Output the character. In this case
    309                  * it should be no longer buffered.
    310                  */
    311                 stdout->op->write(stdout, ch);
    312         } else {
    313327                /*
    314328                 * No standard output routine defined yet.
     
    326340        /* Force notification on newline */
    327341        if (ch == '\n')
    328                 klog_update(NULL);
     342                kio_update(NULL);
    329343}
    330344
     
    334348 *
    335349 */
    336 sysarg_t sys_klog(int cmd, const void *buf, size_t size)
     350sysarg_t sys_kio(int cmd, const void *buf, size_t size)
    337351{
    338352        char *data;
     
    340354
    341355        switch (cmd) {
    342         case KLOG_UPDATE:
    343                 klog_update(NULL);
     356        case KIO_UPDATE:
     357                kio_update(NULL);
    344358                return EOK;
    345         case KLOG_WRITE:
    346         case KLOG_COMMAND:
     359        case KIO_WRITE:
     360        case KIO_COMMAND:
    347361                break;
    348362        default:
     
    366380               
    367381                switch (cmd) {
    368                 case KLOG_WRITE:
     382                case KIO_WRITE:
    369383                        printf("%s", data);
    370384                        break;
    371                 case KLOG_COMMAND:
     385                case KIO_COMMAND:
    372386                        if (!stdin)
    373387                                break;
  • kernel/generic/src/ddi/ddi.c

    r2034f98 rb0b4592e  
    121121        backend_data.base = phys;
    122122        backend_data.frames = pages;
     123        backend_data.anonymous = false;
    123124       
    124125        /*
     
    329330       
    330331        size_t frames = SIZE2FRAMES(size);
    331         *phys = frame_alloc(frames, FRAME_NO_RESERVE, constraint);
     332        *phys = frame_alloc(frames, FRAME_ATOMIC, constraint);
    332333        if (*phys == 0)
    333334                return ENOMEM;
     
    336337        backend_data.base = *phys;
    337338        backend_data.frames = frames;
     339        backend_data.anonymous = true;
    338340       
    339341        if (!as_area_create(TASK->as, map_flags, size,
    340342            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
    341                 frame_free_noreserve(*phys, frames);
     343                frame_free(*phys, frames);
    342344                return ENOMEM;
    343345        }
     
    354356NO_TRACE static int dmamem_unmap_anonymous(uintptr_t virt)
    355357{
    356         // TODO: implement unlocking & unmap
    357         return EOK;
     358        return as_area_destroy(TASK->as, virt);
    358359}
    359360
  • kernel/generic/src/lib/func.c

    r2034f98 rb0b4592e  
    3737
    3838#include <func.h>
    39 #include <print.h>
     39#include <log.h>
    4040#include <cpu.h>
    4141#include <arch/asm.h>
     
    7272       
    7373        if (CPU)
    74                 printf("cpu%u: halted\n", CPU->id);
     74                log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
    7575        else
    76                 printf("cpu: halted\n");
     76                log(LF_OTHER, LVL_NOTE, "cpu: halted");
    7777       
    7878        cpu_halt();
  • kernel/generic/src/lib/memfnc.c

    r2034f98 rb0b4592e  
    1         /*
     1/*
    22 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
  • kernel/generic/src/lib/rd.c

    r2034f98 rb0b4592e  
    3838 */
    3939
    40 #include <print.h>
     40#include <log.h>
    4141#include <lib/rd.h>
    4242#include <mm/frame.h>
     
    6868        sysinfo_set_item_val("rd.address.physical", NULL, (sysarg_t) base);
    6969       
    70         printf("RAM disk at %p (size %zu bytes)\n", (void *) base, size);
     70        log(LF_OTHER, LVL_NOTE, "RAM disk at %p (size %zu bytes)", (void *) base,
     71            size);
    7172}
    7273
  • kernel/generic/src/main/kinit.c

    r2034f98 rb0b4592e  
    5959#include <mm/km.h>
    6060#include <print.h>
     61#include <log.h>
    6162#include <memstr.h>
    6263#include <console/console.h>
     
    140141                                thread_ready(thread);
    141142                        } else
    142                                 printf("Unable to create kcpulb thread for cpu%u\n", i);
     143                                log(LF_OTHER, LVL_ERROR,
     144                                    "Unable to create kcpulb thread for cpu%u", i);
    143145                }
    144146        }
     
    156158                thread_ready(thread);
    157159        else
    158                 printf("Unable to create kload thread\n");
     160                log(LF_OTHER, LVL_ERROR, "Unable to create kload thread");
    159161       
    160162#ifdef CONFIG_KCONSOLE
     
    168170                        thread_ready(thread);
    169171                else
    170                         printf("Unable to create kconsole thread\n");
     172                        log(LF_OTHER, LVL_ERROR,
     173                            "Unable to create kconsole thread");
    171174        }
    172175#endif /* CONFIG_KCONSOLE */
     
    210213        for (i = 0; i < init.cnt; i++) {
    211214                if (init.tasks[i].paddr % FRAME_SIZE) {
    212                         printf("init[%zu]: Address is not frame aligned\n", i);
     215                        log(LF_OTHER, LVL_ERROR,
     216                            "init[%zu]: Address is not frame aligned", i);
    213217                        programs[i].task = NULL;
    214218                        continue;
     
    273277                        init_rd((void *) init.tasks[i].paddr, init.tasks[i].size);
    274278                } else
    275                         printf("init[%zu]: Init binary load failed "
    276                             "(error %d, loader status %u)\n", i, rc,
     279                        log(LF_OTHER, LVL_ERROR,
     280                            "init[%zu]: Init binary load failed "
     281                            "(error %d, loader status %u)", i, rc,
    277282                            programs[i].loader_status);
    278283        }
  • kernel/generic/src/main/main.c

    r2034f98 rb0b4592e  
    6262#include <console/kconsole.h>
    6363#include <console/console.h>
     64#include <log.h>
    6465#include <cpu.h>
    6566#include <align.h>
     
    281282        ipc_init();
    282283        event_init();
    283         klog_init();
     284        kio_init();
     285        log_init();
    284286        stats_init();
    285287       
  • kernel/generic/src/main/shutdown.c

    r2034f98 rb0b4592e  
    3939#include <func.h>
    4040#include <print.h>
     41#include <log.h>
    4142
    4243void reboot(void)
     
    4546       
    4647#ifdef CONFIG_DEBUG
    47         printf("Rebooting the system\n");
     48        log(LF_OTHER, LVL_DEBUG, "Rebooting the system");
    4849#endif
    4950       
  • kernel/generic/src/mm/as.c

    r2034f98 rb0b4592e  
    520520}
    521521
     522/** Remove reference to address space area share info.
     523 *
     524 * If the reference count drops to 0, the sh_info is deallocated.
     525 *
     526 * @param sh_info Pointer to address space area share info.
     527 *
     528 */
     529NO_TRACE static void sh_info_remove_reference(share_info_t *sh_info)
     530{
     531        bool dealloc = false;
     532       
     533        mutex_lock(&sh_info->lock);
     534        ASSERT(sh_info->refcount);
     535       
     536        if (--sh_info->refcount == 0) {
     537                dealloc = true;
     538               
     539                /*
     540                 * Now walk carefully the pagemap B+tree and free/remove
     541                 * reference from all frames found there.
     542                 */
     543                list_foreach(sh_info->pagemap.leaf_list, leaf_link,
     544                    btree_node_t, node) {
     545                        btree_key_t i;
     546                       
     547                        for (i = 0; i < node->keys; i++)
     548                                frame_free((uintptr_t) node->value[i], 1);
     549                }
     550               
     551        }
     552        mutex_unlock(&sh_info->lock);
     553       
     554        if (dealloc) {
     555                if (sh_info->backend && sh_info->backend->destroy_shared_data) {
     556                        sh_info->backend->destroy_shared_data(
     557                            sh_info->backend_shared_data);
     558                }
     559                btree_destroy(&sh_info->pagemap);
     560                free(sh_info);
     561        }
     562}
     563
     564
    522565/** Create address space area of common attributes.
    523566 *
     
    566609        }
    567610
    568         if (overflows_into_positive(*base, size))
     611        if (overflows_into_positive(*base, size)) {
     612                mutex_unlock(&as->lock);
    569613                return NULL;
     614        }
    570615
    571616        if (!check_area_conflicts(as, *base, pages, guarded, NULL)) {
     
    584629        area->resident = 0;
    585630        area->base = *base;
     631        area->backend = backend;
    586632        area->sh_info = NULL;
    587         area->backend = backend;
    588633       
    589634        if (backend_data)
     
    591636        else
    592637                memsetb(&area->backend_data, sizeof(area->backend_data), 0);
    593        
     638
     639        share_info_t *si = NULL;
     640
     641        /*
     642         * Create the sharing info structure.
     643         * We do this in advance for every new area, even if it is not going
     644         * to be shared.
     645         */
     646        if (!(attrs & AS_AREA_ATTR_PARTIAL)) {
     647                si = (share_info_t *) malloc(sizeof(share_info_t), 0);
     648                mutex_initialize(&si->lock, MUTEX_PASSIVE);
     649                si->refcount = 1;
     650                si->shared = false;
     651                si->backend_shared_data = NULL;
     652                si->backend = backend;
     653                btree_create(&si->pagemap);
     654
     655                area->sh_info = si;
     656       
     657                if (area->backend && area->backend->create_shared_data) {
     658                        if (!area->backend->create_shared_data(area)) {
     659                                free(area);
     660                                mutex_unlock(&as->lock);
     661                                sh_info_remove_reference(si);
     662                                return NULL;
     663                        }
     664                }
     665        }
     666
    594667        if (area->backend && area->backend->create) {
    595668                if (!area->backend->create(area)) {
    596669                        free(area);
    597670                        mutex_unlock(&as->lock);
     671                        if (!(attrs & AS_AREA_ATTR_PARTIAL))
     672                                sh_info_remove_reference(si);
    598673                        return NULL;
    599674                }
    600675        }
    601        
     676
    602677        btree_create(&area->used_space);
    603678        btree_insert(&as->as_area_btree, *base, (void *) area,
     
    709784        }
    710785       
    711         if (area->sh_info) {
     786        mutex_lock(&area->sh_info->lock);
     787        if (area->sh_info->shared) {
    712788                /*
    713789                 * Remapping of shared address space areas
    714790                 * is not supported.
    715791                 */
     792                mutex_unlock(&area->sh_info->lock);
    716793                mutex_unlock(&area->lock);
    717794                mutex_unlock(&as->lock);
    718795                return ENOTSUP;
    719796        }
     797        mutex_unlock(&area->sh_info->lock);
    720798       
    721799        size_t pages = SIZE2FRAMES((address - area->base) + size);
     
    881959}
    882960
    883 /** Remove reference to address space area share info.
    884  *
    885  * If the reference count drops to 0, the sh_info is deallocated.
    886  *
    887  * @param sh_info Pointer to address space area share info.
    888  *
    889  */
    890 NO_TRACE static void sh_info_remove_reference(share_info_t *sh_info)
    891 {
    892         bool dealloc = false;
    893        
    894         mutex_lock(&sh_info->lock);
    895         ASSERT(sh_info->refcount);
    896        
    897         if (--sh_info->refcount == 0) {
    898                 dealloc = true;
    899                
    900                 /*
    901                  * Now walk carefully the pagemap B+tree and free/remove
    902                  * reference from all frames found there.
    903                  */
    904                 list_foreach(sh_info->pagemap.leaf_list, leaf_link,
    905                     btree_node_t, node) {
    906                         btree_key_t i;
    907                        
    908                         for (i = 0; i < node->keys; i++)
    909                                 frame_free((uintptr_t) node->value[i], 1);
    910                 }
    911                
    912         }
    913         mutex_unlock(&sh_info->lock);
    914        
    915         if (dealloc) {
    916                 btree_destroy(&sh_info->pagemap);
    917                 free(sh_info);
    918         }
    919 }
    920 
    921961/** Destroy address space area.
    922962 *
     
    10001040        area->attributes |= AS_AREA_ATTR_PARTIAL;
    10011041       
    1002         if (area->sh_info)
    1003                 sh_info_remove_reference(area->sh_info);
     1042        sh_info_remove_reference(area->sh_info);
    10041043       
    10051044        mutex_unlock(&area->lock);
     
    10881127         */
    10891128        share_info_t *sh_info = src_area->sh_info;
    1090         if (!sh_info) {
    1091                 sh_info = (share_info_t *) malloc(sizeof(share_info_t), 0);
    1092                 mutex_initialize(&sh_info->lock, MUTEX_PASSIVE);
    1093                 sh_info->refcount = 2;
    1094                 btree_create(&sh_info->pagemap);
    1095                 src_area->sh_info = sh_info;
    1096                
     1129       
     1130        mutex_lock(&sh_info->lock);
     1131        sh_info->refcount++;
     1132        bool shared = sh_info->shared;
     1133        sh_info->shared = true;
     1134        mutex_unlock(&sh_info->lock);
     1135
     1136        if (!shared) {
    10971137                /*
    10981138                 * Call the backend to setup sharing.
     1139                 * This only happens once for each sh_info.
    10991140                 */
    11001141                src_area->backend->share(src_area);
    1101         } else {
    1102                 mutex_lock(&sh_info->lock);
    1103                 sh_info->refcount++;
    1104                 mutex_unlock(&sh_info->lock);
    11051142        }
    11061143       
     
    12211258        }
    12221259       
    1223         if ((area->sh_info) || (area->backend != &anon_backend)) {
    1224                 /* Copying shared areas not supported yet */
     1260        if (area->backend != &anon_backend) {
    12251261                /* Copying non-anonymous memory not supported yet */
    12261262                mutex_unlock(&area->lock);
     
    12281264                return ENOTSUP;
    12291265        }
     1266
     1267        mutex_lock(&area->sh_info->lock);
     1268        if (area->sh_info->shared) {
     1269                /* Copying shared areas not supported yet */
     1270                mutex_unlock(&area->sh_info->lock);
     1271                mutex_unlock(&area->lock);
     1272                mutex_unlock(&as->lock);
     1273                return ENOTSUP;
     1274        }
     1275        mutex_unlock(&area->sh_info->lock);
    12301276       
    12311277        /*
  • kernel/generic/src/mm/backend_anon.c

    r2034f98 rb0b4592e  
    7676        .page_fault = anon_page_fault,
    7777        .frame_free = anon_frame_free,
     78
     79        .create_shared_data = NULL,
     80        .destroy_shared_data = NULL
    7881};
    7982
     
    190193                return AS_PF_FAULT;
    191194
    192         if (area->sh_info) {
     195        mutex_lock(&area->sh_info->lock);
     196        if (area->sh_info->shared) {
    193197                btree_node_t *leaf;
    194198               
     
    200204                 * mapping, a new frame is allocated and the mapping is created.
    201205                 */
    202                 mutex_lock(&area->sh_info->lock);
    203206                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
    204207                    upage - area->base, &leaf);
     
    232235                }
    233236                frame_reference_add(ADDR2PFN(frame));
    234                 mutex_unlock(&area->sh_info->lock);
    235237        } else {
    236238
     
    254256                         * Reserve the memory for this page now.
    255257                         */
    256                         if (!reserve_try_alloc(1))
     258                        if (!reserve_try_alloc(1)) {
     259                                mutex_unlock(&area->sh_info->lock);
    257260                                return AS_PF_SILENT;
     261                        }
    258262                }
    259263
     
    262266                km_temporary_page_put(kpage);
    263267        }
     268        mutex_unlock(&area->sh_info->lock);
    264269       
    265270        /*
  • kernel/generic/src/mm/backend_elf.c

    r2034f98 rb0b4592e  
    7575        .page_fault = elf_page_fault,
    7676        .frame_free = elf_frame_free,
     77
     78        .create_shared_data = NULL,
     79        .destroy_shared_data = NULL
    7780};
    7881
     
    274277        start_anon = entry->p_vaddr + entry->p_filesz;
    275278
    276         if (area->sh_info) {
     279        mutex_lock(&area->sh_info->lock);
     280        if (area->sh_info->shared) {
    277281                bool found = false;
    278282
     
    281285                 */
    282286               
    283                 mutex_lock(&area->sh_info->lock);
    284287                frame = (uintptr_t) btree_search(&area->sh_info->pagemap,
    285288                    upage - area->base, &leaf);
     
    384387        }
    385388
    386         if (dirty && area->sh_info) {
     389        if (dirty && area->sh_info->shared) {
    387390                frame_reference_add(ADDR2PFN(frame));
    388391                btree_insert(&area->sh_info->pagemap, upage - area->base,
     
    390393        }
    391394
    392         if (area->sh_info)
    393                 mutex_unlock(&area->sh_info->lock);
     395        mutex_unlock(&area->sh_info->lock);
    394396
    395397        page_mapping_insert(AS, upage, frame, as_area_get_flags(area));
  • kernel/generic/src/mm/backend_phys.c

    r2034f98 rb0b4592e  
    5555static bool phys_is_shareable(as_area_t *);
    5656
     57static int phys_page_fault(as_area_t *, uintptr_t, pf_access_t);
    5758
    58 static int phys_page_fault(as_area_t *, uintptr_t, pf_access_t);
     59static bool phys_create_shared_data(as_area_t *);
     60static void phys_destroy_shared_data(void *);
     61
     62typedef struct {
     63        uintptr_t base;
     64        size_t frames; 
     65} phys_shared_data_t;
    5966
    6067mem_backend_t phys_backend = {
     
    6976        .page_fault = phys_page_fault,
    7077        .frame_free = NULL,
     78       
     79        .create_shared_data = phys_create_shared_data,
     80        .destroy_shared_data = phys_destroy_shared_data
    7181};
     82
    7283
    7384bool phys_create(as_area_t *area)
     
    92103void phys_destroy(as_area_t *area)
    93104{
    94         /* Nothing to do. */
     105        /*
     106         * Nothing to do.
     107         * The anonymous frames, if any, are released in
     108         * phys_destroy_shared_data().
     109         */
    95110}
    96111
     
    138153}
    139154
     155bool phys_create_shared_data(as_area_t *area)
     156{
     157        /*
     158         * For anonymous phys areas, create the shared data.
     159         */
     160        if (area->backend_data.anonymous) {
     161                phys_shared_data_t *data;
     162
     163                data = (phys_shared_data_t *) malloc(sizeof(*data), 0);
     164
     165                data->base = area->backend_data.base;
     166                data->frames = area->backend_data.frames;
     167                area->sh_info->backend_shared_data = data;
     168        }
     169
     170        return true;
     171}
     172
     173void phys_destroy_shared_data(void *opaque_data)
     174{
     175        phys_shared_data_t *data = (phys_shared_data_t *) opaque_data;
     176
     177        if (data) {
     178                frame_free(data->base, data->frames);
     179                free(data);
     180        }
     181}
     182
    140183/** @}
    141184 */
  • kernel/generic/src/mm/frame.c

    r2034f98 rb0b4592e  
    5454#include <arch.h>
    5555#include <print.h>
     56#include <log.h>
    5657#include <align.h>
    5758#include <mm/slab.h>
     
    121122{
    122123        if (zones.count + 1 == ZONES_MAX) {
    123                 printf("Maximum zone count %u exceeded!\n", ZONES_MAX);
     124                log(LF_OTHER, LVL_ERROR, "Maximum zone count %u exceeded!",
     125                    ZONES_MAX);
    124126                return (size_t) -1;
    125127        }
     
    141143                            (!iswithin(zones.info[i].base, zones.info[i].count,
    142144                            base, count))) {
    143                                 printf("Zone (%p, %p) overlaps "
    144                                     "with previous zone (%p %p)!\n",
     145                                log(LF_OTHER, LVL_WARN,
     146                                    "Zone (%p, %p) overlaps "
     147                                    "with previous zone (%p %p)!",
    145148                                    (void *) PFN2ADDR(base), (void *) PFN2ADDR(count),
    146149                                    (void *) PFN2ADDR(zones.info[i].base),
     
    913916               
    914917#ifdef CONFIG_DEBUG
    915                 printf("Thread %" PRIu64 " waiting for %zu frames "
    916                     "(%zu available).\n", THREAD->tid, count, avail);
     918                log(LF_OTHER, LVL_DEBUG,
     919                    "Thread %" PRIu64 " waiting for %zu frames "
     920                    "%zu available.", THREAD->tid, count, avail);
    917921#endif
    918922               
     
    938942               
    939943#ifdef CONFIG_DEBUG
    940                 printf("Thread %" PRIu64 " woken up.\n", THREAD->tid);
     944                log(LF_OTHER, LVL_DEBUG, "Thread %" PRIu64 " woken up.",
     945                    THREAD->tid);
    941946#endif
    942947               
  • kernel/generic/src/proc/program.c

    r2034f98 rb0b4592e  
    4949#include <lib/elf_load.h>
    5050#include <errno.h>
    51 #include <print.h>
     51#include <log.h>
    5252#include <syscall/copy.h>
    5353#include <proc/program.h>
     
    155155               
    156156                program_loader = image_addr;
    157                 printf("Program loader at %p\n", (void *) image_addr);
     157                log(LF_OTHER, LVL_NOTE, "Program loader at %p", (void *) image_addr);
    158158               
    159159                return EOK;
     
    181181        if (!loader) {
    182182                as_destroy(as);
    183                 printf("Cannot spawn loader as none was registered\n");
     183                log(LF_OTHER, LVL_ERROR,
     184                    "Cannot spawn loader as none was registered");
    184185                return ENOENT;
    185186        }
     
    189190        if (prg->loader_status != EE_OK) {
    190191                as_destroy(as);
    191                 printf("Cannot spawn loader (%s)\n",
     192                log(LF_OTHER, LVL_ERROR, "Cannot spawn loader (%s)",
    192193                    elf_error(prg->loader_status));
    193194                return ENOENT;
  • kernel/generic/src/proc/scheduler.c

    r2034f98 rb0b4592e  
    6161#include <cpu.h>
    6262#include <print.h>
     63#include <log.h>
    6364#include <debug.h>
    6465#include <stacktrace.h>
     
    517518       
    518519#ifdef SCHEDULER_VERBOSE
    519         printf("cpu%u: tid %" PRIu64 " (priority=%d, ticks=%" PRIu64
    520             ", nrdy=%ld)\n", CPU->id, THREAD->tid, THREAD->priority,
     520        log(LF_OTHER, LVL_DEBUG,
     521            "cpu%u: tid %" PRIu64 " (priority=%d, ticks=%" PRIu64
     522            ", nrdy=%" PRIua ")", CPU->id, THREAD->tid, THREAD->priority,
    521523            THREAD->ticks, atomic_get(&CPU->nrdy));
    522524#endif
     
    663665                               
    664666#ifdef KCPULB_VERBOSE
    665                                 printf("kcpulb%u: TID %" PRIu64 " -> cpu%u, "
    666                                     "nrdy=%ld, avg=%ld\n", CPU->id, t->tid,
     667                                log(LF_OTHER, LVL_DEBUG,
     668                                    "kcpulb%u: TID %" PRIu64 " -> cpu%u, "
     669                                    "nrdy=%ld, avg=%ld", CPU->id, t->tid,
    667670                                    CPU->id, atomic_get(&CPU->nrdy),
    668671                                    atomic_get(&nrdy) / config.cpu_active);
  • kernel/generic/src/syscall/syscall.c

    r2034f98 rb0b4592e  
    5656#include <console/console.h>
    5757#include <udebug/udebug.h>
     58#include <log.h>
    5859
    5960/** Dispatch system call */
     
    8687                rc = syscall_table[id](a1, a2, a3, a4, a5, a6);
    8788        } else {
    88                 printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
     89                log(LF_OTHER, LVL_ERROR,
     90                    "Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
    8991                task_kill_self(true);
    9092        }
     
    120122syshandler_t syscall_table[SYSCALL_END] = {
    121123        /* System management syscalls. */
    122         (syshandler_t) sys_klog,
     124        (syshandler_t) sys_kio,
    123125        (syshandler_t) sys_tls_set,
    124126       
     
    190192       
    191193        /* Kernel console syscalls. */
    192         (syshandler_t) sys_debug_activate_console
     194        (syshandler_t) sys_debug_activate_console,
     195       
     196        (syshandler_t) sys_klog,
    193197};
    194198
Note: See TracChangeset for help on using the changeset viewer.