Changeset 25a76ab8 in mainline for kernel


Ignore:
Timestamp:
2010-05-08T07:53:23Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
051bc69a
Parents:
6c39a907 (diff), 1317380 (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
Files:
49 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/_link.ld.in

    r6c39a907 r25a76ab8  
    77 */
    88
    9 #define KERNEL_LOAD_ADDRESS 0x80800000
     9#define KERNEL_LOAD_ADDRESS 0x80a00000
    1010
    1111OUTPUT_ARCH(arm)
  • kernel/arch/arm32/include/arch.h

    r6c39a907 r25a76ab8  
    4545
    4646typedef struct {
    47         uintptr_t addr;
    48         uint32_t size;
     47        void *addr;
     48        size_t size;
    4949        char name[BOOTINFO_TASK_NAME_BUFLEN];
    5050} utask_t;
    5151
    5252typedef struct {
    53         uint32_t cnt;
     53        size_t cnt;
    5454        utask_t tasks[TASKMAP_MAX_RECORDS];
    5555} bootinfo_t;
  • kernel/arch/arm32/include/mm/frame.h

    r6c39a907 r25a76ab8  
    4646
    4747#define BOOT_PAGE_TABLE_SIZE     0x4000
    48 #define BOOT_PAGE_TABLE_ADDRESS  0x4000
     48#define BOOT_PAGE_TABLE_ADDRESS  0x8000
    4949
    5050#define BOOT_PAGE_TABLE_START_FRAME     (BOOT_PAGE_TABLE_ADDRESS >> FRAME_WIDTH)
  • kernel/arch/arm32/src/arm32.c

    r6c39a907 r25a76ab8  
    6262void arch_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
    6363{
    64         unsigned int i;
     64        init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
    6565       
    66         init.cnt = bootinfo->cnt;
    67        
    68         for (i = 0; i < min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); ++i) {
    69                 init.tasks[i].addr = bootinfo->tasks[i].addr;
     66        size_t i;
     67        for (i = 0; i < init.cnt; i++) {
     68                init.tasks[i].addr = (uintptr_t) bootinfo->tasks[i].addr;
    7069                init.tasks[i].size = bootinfo->tasks[i].size;
    7170                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
  • kernel/arch/ia64/include/bootinfo.h

    r6c39a907 r25a76ab8  
    3232#define BOOTINFO_ADDRESS 0x4401000
    3333
    34 #define CONFIG_INIT_TASKS       32
     34#define TASKMAP_MAX_RECORDS  32
    3535
    3636#define MEMMAP_ITEMS 128
     
    4444
    4545typedef struct {
    46         void *addr; 
    47         unsigned long size;
     46        void *addr;
     47        size_t size;
    4848        char name[BOOTINFO_TASK_NAME_BUFLEN];
    4949} binit_task_t;
    5050       
    5151typedef struct {
    52         unsigned long count;
    53         binit_task_t tasks[CONFIG_INIT_TASKS];
     52        size_t cnt;
     53        binit_task_t tasks[TASKMAP_MAX_RECORDS];
    5454} binit_t;
    5555
     
    5858        unsigned long base;
    5959        unsigned long size;
    60 }efi_memmap_item_t;
    61 
     60} efi_memmap_item_t;
    6261
    6362typedef struct {
    6463        binit_t taskmap;
    65 
     64       
    6665        efi_memmap_item_t memmap[MEMMAP_ITEMS];
    6766        unsigned int memmap_items;
    68 
     67       
    6968        unative_t *sapic;
    7069        unsigned long sys_freq;
  • kernel/arch/ia64/src/ia64.c

    r6c39a907 r25a76ab8  
    4747#include <mm/as.h>
    4848#include <config.h>
     49#include <macros.h>
    4950#include <userspace.h>
    5051#include <console/console.h>
     
    7879void arch_pre_main(void)
    7980{
    80         /* Setup usermode init tasks. */
    81 
    82         unsigned int i;
    83        
    84         init.cnt = bootinfo->taskmap.count;
    85        
     81        init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
     82        size_t i;
    8683        for (i = 0; i < init.cnt; i++) {
    8784                init.tasks[i].addr =
  • kernel/arch/mips32/include/arch.h

    r6c39a907 r25a76ab8  
    4545
    4646typedef struct {
    47         uintptr_t addr;
     47        void *addr;
    4848        size_t size;
    4949        char name[BOOTINFO_TASK_NAME_BUFLEN];
  • kernel/arch/mips32/src/debugger.c

    r6c39a907 r25a76ab8  
    164164                        printf("Duplicate breakpoint %d.\n", i);
    165165                        spinlock_unlock(&bkpoint_lock);
     166                        interrupts_restore(ipl);
    166167                        return 0;
    167168                } else if (breakpoints[i].address == (uintptr_t)argv->intval +
     
    171172                            "with %d.\n", i);
    172173                        spinlock_unlock(&bkpoint_lock);
     174                        interrupts_restore(ipl);
    173175                        return 0;
    174176                }
  • kernel/arch/mips32/src/mips32.c

    r6c39a907 r25a76ab8  
    8383void arch_pre_main(void *entry __attribute__((unused)), bootinfo_t *bootinfo)
    8484{
    85         /* Setup usermode */
    86         init.cnt = bootinfo->cnt;
     85        init.cnt = min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
    8786       
    8887        size_t i;
    89         for (i = 0; i < min3(bootinfo->cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
    90                 init.tasks[i].addr = bootinfo->tasks[i].addr;
     88        for (i = 0; i < init.cnt; i++) {
     89                init.tasks[i].addr = (uintptr_t) bootinfo->tasks[i].addr;
    9190                init.tasks[i].size = bootinfo->tasks[i].size;
    9291                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
  • kernel/arch/ppc32/include/arch.h

    r6c39a907 r25a76ab8  
    3636#define KERN_ppc32_ARCH_H_
    3737
    38 extern void arch_pre_main(void);
     38#include <arch/boot/boot.h>
     39
     40extern void arch_pre_main(bootinfo_t *);
    3941
    4042#endif
  • kernel/arch/ppc32/include/boot/boot.h

    r6c39a907 r25a76ab8  
    5252
    5353typedef struct {
    54         uintptr_t addr;
    55         uint32_t size;
     54        void *addr;
     55        size_t size;
    5656        char name[BOOTINFO_TASK_NAME_BUFLEN];
    5757} utask_t;
    5858
    5959typedef struct {
    60         uint32_t count;
     60        size_t cnt;
    6161        utask_t tasks[TASKMAP_MAX_RECORDS];
    6262} taskmap_t;
    6363
    6464typedef struct {
    65         uintptr_t start;
    66         uint32_t size;
     65        void *start;
     66        size_t size;
    6767} memzone_t;
    6868
    6969typedef struct {
    70         uint32_t total;
    71         uint32_t count;
     70        uint64_t total;
     71        size_t cnt;
    7272        memzone_t zones[MEMMAP_MAX_RECORDS];
    7373} memmap_t;
     
    8080} bootinfo_t;
    8181
    82 extern bootinfo_t bootinfo;
     82extern memmap_t memmap;
    8383
    8484#endif
  • kernel/arch/ppc32/src/boot/boot.S

    r6c39a907 r25a76ab8  
    4747       
    4848        # r3 contains physical address of bootinfo_t
    49         # r4 contains size of bootinfo_t
    50        
    51         cmpwi r4, 0
    52         beq bootinfo_end
    5349       
    5450        addis r3, r3, 0x8000
    55        
    56         lis r31, bootinfo@ha
    57         addi r31, r31, bootinfo@l  # r31 = bootinfo
    58        
    59         bootinfo_loop:
    60                
    61                 lwz r30, 0(r3)
    62                 stw r30, 0(r31)
    63                
    64                 addi r3, r3, 4
    65                 addi r31, r31, 4
    66                 subi r4, r4, 4
    67                
    68                 cmpwi r4, 0
    69                 bgt bootinfo_loop
    70                
    71         bootinfo_end:
    72        
    7351        bl arch_pre_main
    7452        b main_bsp
  • kernel/arch/ppc32/src/mm/frame.c

    r6c39a907 r25a76ab8  
    2727 */
    2828
    29 /** @addtogroup ppc32mm 
     29/** @addtogroup ppc32mm
    3030 * @{
    3131 */
     
    4141
    4242uintptr_t last_frame = 0;
     43memmap_t memmap;
    4344
    4445void physmem_print(void)
     
    4950        printf("---------- ----------\n");
    5051               
    51         for (i = 0; i < bootinfo.memmap.count; i++) {
    52                 printf("%#10x %#10x\n", bootinfo.memmap.zones[i].start,
    53                         bootinfo.memmap.zones[i].size);
     52        for (i = 0; i < memmap.cnt; i++) {
     53                printf("%#10x %#10x\n", memmap.zones[i].start,
     54                        memmap.zones[i].size);
    5455        }
    5556}
     
    6263        size_t size;
    6364       
    64         for (i = 0; i < bootinfo.memmap.count; i++) {
    65                 start = ADDR2PFN(ALIGN_UP(bootinfo.memmap.zones[i].start, FRAME_SIZE));
    66                 size = SIZE2FRAMES(ALIGN_DOWN(bootinfo.memmap.zones[i].size, FRAME_SIZE));
     65        for (i = 0; i < memmap.cnt; i++) {
     66                start = ADDR2PFN(ALIGN_UP((uintptr_t) memmap.zones[i].start, FRAME_SIZE));
     67                size = SIZE2FRAMES(ALIGN_DOWN(memmap.zones[i].size, FRAME_SIZE));
    6768               
    6869                if ((minconf < start) || (minconf >= start + size))
     
    7273               
    7374                zone_create(start, size, conf, 0);
    74                 if (last_frame < ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE))
    75                         last_frame = ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE);
     75                if (last_frame < ALIGN_UP((uintptr_t) memmap.zones[i].start + memmap.zones[i].size, FRAME_SIZE))
     76                        last_frame = ALIGN_UP((uintptr_t) memmap.zones[i].start + memmap.zones[i].size, FRAME_SIZE);
    7677        }
    7778       
  • kernel/arch/ppc32/src/mm/page.c

    r6c39a907 r25a76ab8  
    4545}
    4646
    47 
    4847uintptr_t hw_map(uintptr_t physaddr, size_t size)
    4948{
  • kernel/arch/ppc32/src/ppc32.c

    r6c39a907 r25a76ab8  
    6565
    6666/** Performs ppc32-specific initialization before main_bsp() is called. */
    67 void arch_pre_main(void)
    68 {
    69         init.cnt = bootinfo.taskmap.count;
    70        
    71         uint32_t i;
    72        
    73         for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
    74                 init.tasks[i].addr = bootinfo.taskmap.tasks[i].addr;
    75                 init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
     67void arch_pre_main(bootinfo_t *bootinfo)
     68{
     69        /* Copy tasks map. */
     70        init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
     71        size_t i;
     72        for (i = 0; i < init.cnt; i++) {
     73                init.tasks[i].addr = (uintptr_t) bootinfo->taskmap.tasks[i].addr;
     74                init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
    7675                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
    77                     bootinfo.taskmap.tasks[i].name);
     76                    bootinfo->taskmap.tasks[i].name);
     77        }
     78       
     79        /* Copy physical memory map. */
     80        memmap.total = bootinfo->memmap.total;
     81        memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
     82        for (i = 0; i < memmap.cnt; i++) {
     83                memmap.zones[i].start = bootinfo->memmap.zones[i].start;
     84                memmap.zones[i].size = bootinfo->memmap.zones[i].size;
    7885        }
    7986       
    8087        /* Copy boot allocations info. */
    81         ballocs.base = bootinfo.ballocs.base;
    82         ballocs.size = bootinfo.ballocs.size;
    83        
    84         ofw_tree_init(bootinfo.ofw_root);
     88        ballocs.base = bootinfo->ballocs.base;
     89        ballocs.size = bootinfo->ballocs.size;
     90       
     91        /* Copy OFW tree. */
     92        ofw_tree_init(bootinfo->ofw_root);
    8593}
    8694
  • kernel/arch/sparc64/include/arch.h

    r6c39a907 r25a76ab8  
    2727 */
    2828
    29 /** @addtogroup sparc64 
     29/** @addtogroup sparc64
    3030 * @{
    3131 */
    3232/**
    3333 * @file
    34  * @brief       Various sparc64-specific macros.
     34 * @brief Various sparc64-specific macros.
    3535 */
    3636
    3737#ifndef KERN_sparc64_ARCH_H_
    3838#define KERN_sparc64_ARCH_H_
     39
     40#include <arch/boot/boot.h>
    3941
    4042#if defined (SUN4U)
     
    4446#endif
    4547
    46 #define ASI_AIUP                0x10    /** Access to primary context with user privileges. */
    47 #define ASI_AIUS                0x11    /** Access to secondary context with user privileges. */
     48#define ASI_AIUP  0x10  /** Access to primary context with user privileges. */
     49#define ASI_AIUS  0x11  /** Access to secondary context with user privileges. */
    4850
    49 #define NWINDOWS                8       /** Number of register window sets. */
     51#define NWINDOWS  8  /** Number of register window sets. */
    5052
    5153#ifndef __ASM__
    5254
    53 extern void arch_pre_main(void);
     55extern void arch_pre_main(bootinfo_t *);
    5456
    5557#endif /* __ASM__ */
    56 
    5758
    5859#endif
  • kernel/arch/sparc64/include/boot/boot.h

    r6c39a907 r25a76ab8  
    2727 */
    2828
    29 /** @addtogroup sparc64 
     29/** @addtogroup sparc64
    3030 * @{
    3131 */
     
    3636#define KERN_sparc64_BOOT_H_
    3737
    38 #define VMA                     0x400000
    39 #define LMA                     VMA
     38#define VMA  0x400000
     39#define LMA  VMA
    4040
    4141#ifndef __ASM__
     
    4646#include <genarch/ofw/ofw_tree.h>
    4747
    48 #define TASKMAP_MAX_RECORDS     32
    49 #define MEMMAP_MAX_RECORDS      32
     48#define TASKMAP_MAX_RECORDS  32
     49#define MEMMAP_MAX_RECORDS   32
    5050
    51 #define BOOTINFO_TASK_NAME_BUFLEN 32
     51#define BOOTINFO_TASK_NAME_BUFLEN  32
    5252
    5353typedef struct {
    54         void * addr;
    55         uint32_t size;
     54        void *addr;
     55        size_t size;
    5656        char name[BOOTINFO_TASK_NAME_BUFLEN];
    5757} utask_t;
    5858
    5959typedef struct {
    60         uint32_t count;
     60        size_t cnt;
    6161        utask_t tasks[TASKMAP_MAX_RECORDS];
    6262} taskmap_t;
    6363
    6464typedef struct {
    65         uintptr_t start;
    66         uint32_t size;
     65        void *start;
     66        size_t size;
    6767} memzone_t;
    6868
    6969typedef struct {
    70         uint32_t total;
    71         uint32_t count;
     70        uint64_t total;
     71        size_t cnt;
    7272        memzone_t zones[MEMMAP_MAX_RECORDS];
    7373} memmap_t;
     
    7676 *
    7777 * Must be in sync with bootinfo structure used by the boot loader.
     78 *
    7879 */
    7980typedef struct {
     
    8586} bootinfo_t;
    8687
    87 extern bootinfo_t bootinfo;
     88extern memmap_t memmap;
     89extern uintptr_t physmem_start;
    8890
    8991#endif
  • kernel/arch/sparc64/src/mm/sun4u/frame.c

    r6c39a907 r25a76ab8  
    4343uintptr_t last_frame = NULL;
    4444
    45 /** Create memory zones according to information stored in bootinfo.
     45/** Create memory zones according to information stored in memmap.
    4646 *
    47  * Walk the bootinfo memory map and create frame zones according to it.
     47 * Walk the memory map and create frame zones according to it.
    4848 */
    4949void frame_arch_init(void)
     
    5353
    5454        if (config.cpu_active == 1) {
    55                 for (i = 0; i < bootinfo.memmap.count; i++) {
    56                         uintptr_t start = bootinfo.memmap.zones[i].start;
    57                         size_t size = bootinfo.memmap.zones[i].size;
     55                for (i = 0; i < memmap.cnt; i++) {
     56                        uintptr_t start = (uintptr_t) memmap.zones[i].start;
     57                        size_t size = memmap.zones[i].size;
    5858
    5959                        /*
  • kernel/arch/sparc64/src/mm/sun4v/frame.c

    r6c39a907 r25a76ab8  
    4141#include <macros.h>
    4242
    43 /** Create memory zones according to information stored in bootinfo.
     43/** Create memory zones according to information stored in memmap.
    4444 *
    45  * Walk the bootinfo memory map and create frame zones according to it.
     45 * Walk the memory map and create frame zones according to it.
    4646 */
    4747void frame_arch_init(void)
     
    5151
    5252        if (config.cpu_active == 1) {
    53                 for (i = 0; i < bootinfo.memmap.count; i++) {
    54                         uintptr_t start = bootinfo.memmap.zones[i].start;
    55                         size_t size = bootinfo.memmap.zones[i].size;
     53                for (i = 0; i < memmap.cnt; i++) {
     54                        uintptr_t start = (uintptr_t) memmap.zones[i].start;
     55                        size_t size = memmap.zones[i].size;
    5656
    5757                        /*
  • kernel/arch/sparc64/src/smp/sun4v/smp.c

    r6c39a907 r25a76ab8  
    417417static bool wake_cpu(uint64_t cpuid)
    418418{
    419 
    420419#ifdef CONFIG_SIMICS_SMP_HACK
    421420        ipi_unicast_to((void (*)(void)) 1234, cpuid);
     
    424423        if (__hypercall_fast1(CPU_STOP, cpuid) != EOK)
    425424                return false;
    426 
     425       
    427426        /* wait for the CPU to stop */
    428427        uint64_t state;
    429         __hypercall_fast_ret1(cpuid, 0, 0, 0, 0,
    430                 CPU_STATE, &state);
    431         while (state == CPU_STATE_RUNNING) {
    432                 __hypercall_fast_ret1(cpuid, 0, 0, 0, 0,
    433                         CPU_STATE, &state);
    434         }
    435 
     428        __hypercall_fast_ret1(cpuid, 0, 0, 0, 0, CPU_STATE, &state);
     429        while (state == CPU_STATE_RUNNING)
     430                __hypercall_fast_ret1(cpuid, 0, 0, 0, 0, CPU_STATE, &state);
     431       
    436432        /* make the CPU run again and execute HelenOS code */
    437         if (__hypercall_fast4(
    438                 CPU_START, cpuid,
    439                 (uint64_t) KA2PA(kernel_image_start),
    440                 KA2PA(trap_table), bootinfo.physmem_start                       
    441                 ) != EOK)
    442                         return false;
     433        if (__hypercall_fast4(CPU_START, cpuid,
     434            (uint64_t) KA2PA(kernel_image_start), KA2PA(trap_table),
     435            physmem_start) != EOK)
     436                return false;
    443437#endif
    444 
     438       
    445439        if (waitq_sleep_timeout(&ap_completion_wq, 10000000, SYNCH_FLAGS_NONE) ==
    446                         ESYNCH_TIMEOUT)
    447                 printf("%s: waiting for processor (cpuid = %" PRIu32
    448                 ") timed out\n", __func__, cpuid);
    449 
     440            ESYNCH_TIMEOUT)
     441                printf("%s: waiting for processor (cpuid = %" PRIu32 ") timed out\n",
     442                    __func__, cpuid);
     443       
    450444        return true;
    451445}
  • kernel/arch/sparc64/src/sun4u/sparc64.c

    r6c39a907 r25a76ab8  
    3636#include <debug.h>
    3737#include <config.h>
     38#include <macros.h>
    3839#include <arch/trap/trap.h>
    3940#include <arch/console.h>
     
    5051#include <str.h>
    5152
    52 bootinfo_t bootinfo;
     53memmap_t memmap;
    5354
    5455/** Perform sparc64-specific initialization before main_bsp() is called. */
    55 void arch_pre_main(void)
     56void arch_pre_main(bootinfo_t *bootinfo)
    5657{
    5758        /* Copy init task info. */
    58         init.cnt = bootinfo.taskmap.count;
     59        init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
    5960       
    60         uint32_t i;
    61 
    62         for (i = 0; i < bootinfo.taskmap.count; i++) {
    63                 init.tasks[i].addr = (uintptr_t) bootinfo.taskmap.tasks[i].addr;
    64                 init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
     61        size_t i;
     62        for (i = 0; i < init.cnt; i++) {
     63                init.tasks[i].addr = (uintptr_t) bootinfo->taskmap.tasks[i].addr;
     64                init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
    6565                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
    66                     bootinfo.taskmap.tasks[i].name);
     66                    bootinfo->taskmap.tasks[i].name);
     67        }
     68       
     69        /* Copy physical memory map. */
     70        memmap.total = bootinfo->memmap.total;
     71        memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
     72        for (i = 0; i < memmap.cnt; i++) {
     73                memmap.zones[i].start = bootinfo->memmap.zones[i].start;
     74                memmap.zones[i].size = bootinfo->memmap.zones[i].size;
    6775        }
    6876       
    6977        /* Copy boot allocations info. */
    70         ballocs.base = bootinfo.ballocs.base;
    71         ballocs.size = bootinfo.ballocs.size;
     78        ballocs.base = bootinfo->ballocs.base;
     79        ballocs.size = bootinfo->ballocs.size;
    7280       
    73         ofw_tree_init(bootinfo.ofw_root);
     81        ofw_tree_init(bootinfo->ofw_root);
    7482}
    7583
  • kernel/arch/sparc64/src/sun4u/start.S

    r6c39a907 r25a76ab8  
    6060/*
    6161 * Here is where the kernel is passed control from the boot loader.
    62  * 
     62 *
    6363 * The registers are expected to be in this state:
    64  * - %o0 starting address of physical memory + bootstrap processor flag
    65  *      bits 63...1:    physical memory starting address / 2
    66  *      bit 0:          non-zero on BSP processor, zero on AP processors
    67  * - %o1 bootinfo structure address (BSP only)
    68  * - %o2 bootinfo structure size (BSP only)
     64 *  - %o0 bootinfo structure address (BSP only)
     65 *  - %o1 starting address of physical memory
     66 *        + bootstrap processor flag
     67 *          bits 63...1: physical memory starting address / 2
     68 *          bit 0:       non-zero on BSP processor, zero on AP processors
    6969 *
    7070 * Moreover, we depend on boot having established the following environment:
    71  * - TLBs are on
    72  * - identity mapping for the kernel image
     71 *  - TLBs are on
     72 *  - identity mapping for the kernel image
     73 *
    7374 */
    7475
     
    7677kernel_image_start:
    7778        mov BSP_FLAG, %l0
    78         and %o0, %l0, %l7                       ! l7 <= bootstrap processor?
    79         andn %o0, %l0, %l6                      ! l6 <= start of physical memory
     79        and %o1, %l0, %l7                       ! l7 <= bootstrap processor?
     80        andn %o1, %l0, %l6                      ! l6 <= start of physical memory
    8081
    8182        ! Get bits (PHYSMEM_ADDR_SIZE - 1):13 of physmem_base.
     
    282283        sub %sp, STACK_BIAS, %sp
    283284
    284         sethi %hi(bootinfo), %o0
    285         call memcpy                             ! copy bootinfo
    286         or %o0, %lo(bootinfo), %o0
    287 
    288285        call arch_pre_main
    289286        nop
  • kernel/arch/sparc64/src/sun4v/sparc64.c

    r6c39a907 r25a76ab8  
    3636#include <debug.h>
    3737#include <config.h>
     38#include <macros.h>
    3839#include <arch/trap/trap.h>
    3940#include <arch/console.h>
     
    5253#include <arch/drivers/niagara.h>
    5354
    54 bootinfo_t bootinfo;
     55memmap_t memmap;
    5556
    5657/** Perform sparc64-specific initialization before main_bsp() is called. */
    57 void arch_pre_main(void)
     58void arch_pre_main(bootinfo_t *bootinfo)
    5859{
    5960        /* Copy init task info. */
    60         init.cnt = bootinfo.taskmap.count;
     61        init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
    6162       
    62         uint32_t i;
    63 
    64         for (i = 0; i < bootinfo.taskmap.count; i++) {
    65                 init.tasks[i].addr = (uintptr_t) bootinfo.taskmap.tasks[i].addr;
    66                 init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
     63        size_t i;
     64        for (i = 0; i < init.cnt; i++) {
     65                init.tasks[i].addr = (uintptr_t) bootinfo->taskmap.tasks[i].addr;
     66                init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
    6767                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
    68                     bootinfo.taskmap.tasks[i].name);
     68                    bootinfo->taskmap.tasks[i].name);
    6969        }
    70 
     70       
     71        /* Copy physical memory map. */
     72        memmap.total = bootinfo->memmap.total;
     73        memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
     74        for (i = 0; i < memmap.cnt; i++) {
     75                memmap.zones[i].start = bootinfo->memmap.zones[i].start;
     76                memmap.zones[i].size = bootinfo->memmap.zones[i].size;
     77        }
     78       
    7179        md_init();
    7280}
  • kernel/arch/sparc64/src/sun4v/start.S

    r6c39a907 r25a76ab8  
    7575 *
    7676 * parameters:
    77  *      addr:                   virtual address to be mapped
    78  *      rphysmem_start:         register containing the starting address of the
    79  *                              physical memory
    80  *      rtmp1:                  a register to be used as temporary
    81  *      rtmp2:                  a register to be used as temporary
    82  *      rd:                     register where the result will be saved
     77 *  addr:           virtual address to be mapped
     78 *  rphysmem_start: register containing the starting address
     79 *                  of the physical memory
     80 *  rtmp1:          a register to be used as temporary
     81 *  rtmp2:          a register to be used as temporary
     82 *  rd:             register where the result will be saved
     83 *
    8384 */
    8485#define TTE_DATA(addr, rphysmem_start, rtmp1, rtmp2, rd) \
     
    9091/*
    9192 * Here is where the kernel is passed control from the boot loader.
    92  * 
     93 *
    9394 * The registers are expected to be in this state:
    94  * - %o0 starting address of physical memory + bootstrap processor flag
    95  *      bits 63...1:    physical memory starting address / 2
    96  *      bit 0:          non-zero on BSP processor, zero on AP processors
    97  * - %o1 bootinfo structure address (BSP only)
    98  * - %o2 bootinfo structure size (BSP only)
     95 *  - %o0 bootinfo structure address (BSP only)
     96 *  - %o1 starting address of physical memory
     97 *        + bootstrap processor flag
     98 *          bits 63...1: physical memory starting address / 2
     99 *          bit 0:       non-zero on BSP processor, zero on AP processors
    99100 *
    100101 * Moreover, we depend on boot having established the following environment:
    101  * - TLBs are on
    102  * - identity mapping for the kernel image
     102 *  - TLBs are on
     103 *  - identity mapping for the kernel image
     104 *
    103105 */
    104106.global kernel_image_start
    105107kernel_image_start:
    106108        mov BSP_FLAG, %l0
    107         and %o0, %l0, %l7                       ! l7 <= bootstrap processor?
    108         andn %o0, %l0, %l6                      ! l6 <= start of physical memory
    109         or %o1, %g0, %l1
    110         or %o2, %g0, %l2
     109        and %o1, %l0, %l7                       ! l7 <= bootstrap processor?
     110        andn %o1, %l0, %l6                      ! l6 <= start of physical memory
     111        or %o0, %g0, %l0
    111112
    112113        ! Get bits (PHYSMEM_ADDR_SIZE - 1):13 of physmem_base.
     
    245246        sub %sp, STACK_BIAS, %sp
    246247
    247         or %l1, %g0, %o1
    248         or %l2, %g0, %o2
    249         sethi %hi(bootinfo), %o0
    250         call memcpy                             ! copy bootinfo
    251         or %o0, %lo(bootinfo), %o0
    252 
     248        or %l0, %g0, %o0
    253249        call arch_pre_main
    254250        nop
  • kernel/doc/arch/ppc32

    r6c39a907 r25a76ab8  
    44ppc32 port is the fourth port of SPARTAN, originally written by Martin Decky.
    55The goal is to support 32-bit PowerPC architecture.
    6 So far, it runs only in emulator.
    76
    87HARDWARE REQUIREMENTS
    9         o no real hardware supported
     8        o Apple iMac G4
    109
    1110EMULATORS AND VIRTUALIZERS
    12         o PearPC
     11        o QEMU
    1312
    1413TOOLCHAIN REQUIREMENTS
    1514        o binutils 2.16
    16         o gcc 4.0.1, 4.1.0, 4.1.1
     15        o gcc 4.0.1, 4.1.0, 4.1.1
  • kernel/genarch/include/ofw/ofw_tree.h

    r6c39a907 r25a76ab8  
    3434#define OFW_TREE_PROPERTY_MAX_NAMELEN  32
    3535
     36typedef uint32_t phandle;
     37
    3638/** Memory representation of OpenFirmware device tree node property. */
    3739typedef struct {
     
    4749        struct ofw_tree_node *child;
    4850       
    49         uint32_t node_handle;           /**< Old OpenFirmware node handle. */
     51        phandle node_handle;            /**< Old OpenFirmware node handle. */
    5052       
    5153        char *da_name;                  /**< Disambigued name. */
    5254       
    53         unsigned int properties;        /**< Number of properties. */
     55        size_t properties;              /**< Number of properties. */
    5456        ofw_tree_property_t *property;
    5557       
     
    8385    const char *);
    8486extern ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *,
    85     uint32_t);
     87    phandle);
    8688
    8789#endif
  • kernel/genarch/src/ofw/ofw_tree.c

    r6c39a907 r25a76ab8  
    6565    const char *name)
    6666{
    67         unsigned int i;
     67        size_t i;
    6868       
    6969        for (i = 0; i < node->properties; i++) {
     
    170170 */
    171171ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root,
    172     uint32_t handle)
     172    phandle handle)
    173173{
    174174        ofw_tree_node_t *cur;
  • kernel/generic/include/func.h

    r6c39a907 r25a76ab8  
    4242
    4343extern void halt(void) __attribute__((noreturn));
    44 extern unative_t atoi(const char *text);
    4544
    4645#endif
  • kernel/generic/include/mm/as.h

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    227227extern void as_init(void);
    228228
    229 extern as_t *as_create(int flags);
    230 extern void as_destroy(as_t *as);
    231 extern void as_switch(as_t *old_as, as_t *new_as);
    232 extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate);
    233 
    234 extern as_area_t *as_area_create(as_t *as, int flags, size_t size,
    235     uintptr_t base, int attrs, mem_backend_t *backend,
    236     mem_backend_data_t *backend_data);
    237 extern int as_area_destroy(as_t *as, uintptr_t address);       
    238 extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags);
    239 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
    240     as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
    241 extern int as_area_change_flags(as_t *as, int flags, uintptr_t address);
    242 
    243 extern int as_area_get_flags(as_area_t *area);
    244 extern bool as_area_check_access(as_area_t *area, pf_access_t access);
    245 extern size_t as_area_get_size(uintptr_t base);
    246 extern int used_space_insert(as_area_t *a, uintptr_t page, size_t count);
    247 extern int used_space_remove(as_area_t *a, uintptr_t page, size_t count);
     229extern as_t *as_create(int);
     230extern void as_destroy(as_t *);
     231extern void as_hold(as_t *);
     232extern void as_release(as_t *);
     233extern void as_switch(as_t *, as_t *);
     234extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
     235
     236extern as_area_t *as_area_create(as_t *, int, size_t, uintptr_t, int,
     237    mem_backend_t *, mem_backend_data_t *);
     238extern int as_area_destroy(as_t *, uintptr_t);
     239extern int as_area_resize(as_t *, uintptr_t, size_t, int);
     240extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t, int);
     241extern int as_area_change_flags(as_t *, int, uintptr_t);
     242
     243extern int as_area_get_flags(as_area_t *);
     244extern bool as_area_check_access(as_area_t *, pf_access_t);
     245extern size_t as_area_get_size(uintptr_t);
     246extern int used_space_insert(as_area_t *, uintptr_t, size_t);
     247extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    248248
    249249
    250250/* Interface to be implemented by architectures. */
    251251#ifndef as_constructor_arch
    252 extern int as_constructor_arch(as_t *as, int flags);
     252extern int as_constructor_arch(as_t *, int);
    253253#endif /* !def as_constructor_arch */
    254254#ifndef as_destructor_arch
    255 extern int as_destructor_arch(as_t *as);
     255extern int as_destructor_arch(as_t *);
    256256#endif /* !def as_destructor_arch */
    257257#ifndef as_create_arch
    258 extern int as_create_arch(as_t *as, int flags);
     258extern int as_create_arch(as_t *, int);
    259259#endif /* !def as_create_arch */
    260260#ifndef as_install_arch
    261 extern void as_install_arch(as_t *as);
     261extern void as_install_arch(as_t *);
    262262#endif /* !def as_install_arch */
    263263#ifndef as_deinstall_arch
    264 extern void as_deinstall_arch(as_t *as);
     264extern void as_deinstall_arch(as_t *);
    265265#endif /* !def as_deinstall_arch */
    266266
     
    277277#define ELD_F_LOADER    1
    278278
    279 extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags);
     279extern unsigned int elf_load(elf_header_t *, as_t *, int);
    280280
    281281/* Address space area related syscalls. */
    282 extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags);
    283 extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags);
    284 extern unative_t sys_as_area_change_flags(uintptr_t address, int flags);
    285 extern unative_t sys_as_area_destroy(uintptr_t address);
     282extern unative_t sys_as_area_create(uintptr_t, size_t, int);
     283extern unative_t sys_as_area_resize(uintptr_t, size_t, int);
     284extern unative_t sys_as_area_change_flags(uintptr_t, int);
     285extern unative_t sys_as_area_destroy(uintptr_t);
    286286
    287287/* Introspection functions. */
    288 extern void as_get_area_info(as_t *as, as_area_info_t **obuf, size_t *osize);
    289 extern void as_print(as_t *as);
     288extern void as_get_area_info(as_t *, as_area_info_t **, size_t *);
     289extern void as_print(as_t *);
    290290
    291291#endif /* KERNEL */
  • kernel/generic/include/proc/task.h

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    131131extern void task_init(void);
    132132extern void task_done(void);
    133 extern task_t *task_create(as_t *as, const char *name);
    134 extern void task_destroy(task_t *t);
    135 extern task_t *task_find_by_id(task_id_t id);
    136 extern int task_kill(task_id_t id);
    137 extern void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles);
     133extern task_t *task_create(as_t *, const char *);
     134extern void task_destroy(task_t *);
     135extern void task_hold(task_t *);
     136extern void task_release(task_t *);
     137extern task_t *task_find_by_id(task_id_t);
     138extern int task_kill(task_id_t);
     139extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
    138140extern void task_print_list(void);
    139141
    140 extern void cap_set(task_t *t, cap_t caps);
    141 extern cap_t cap_get(task_t *t);
     142extern void cap_set(task_t *, cap_t);
     143extern cap_t cap_get(task_t *);
    142144
    143145#ifndef task_create_arch
    144 extern void task_create_arch(task_t *t);
     146extern void task_create_arch(task_t *);
    145147#endif
    146148
    147149#ifndef task_destroy_arch
    148 extern void task_destroy_arch(task_t *t);
     150extern void task_destroy_arch(task_t *);
    149151#endif
    150152
    151 extern unative_t sys_task_get_id(task_id_t *uspace_task_id);
    152 extern unative_t sys_task_set_name(const char *uspace_name, size_t name_len);
     153extern unative_t sys_task_get_id(task_id_t *);
     154extern unative_t sys_task_set_name(const char *, size_t);
    153155
    154156#endif
  • kernel/generic/include/synch/spinlock.h

    r6c39a907 r25a76ab8  
    7777        }
    7878
    79 #define spinlock_lock(lock)  spinlock_lock_debug(lock)
     79#define spinlock_lock(lock)     spinlock_lock_debug((lock))
     80#define spinlock_unlock(lock)   spinlock_unlock_debug((lock))
    8081
    8182#else
     
    9192        }
    9293
    93 #define spinlock_lock(lock)  atomic_lock_arch(&(lock)->val)
     94#define spinlock_lock(lock)     atomic_lock_arch(&(lock)->val)
     95#define spinlock_unlock(lock)   spinlock_unlock_nondebug((lock))
    9496
    9597#endif
     
    104106extern int spinlock_trylock(spinlock_t *lock);
    105107extern void spinlock_lock_debug(spinlock_t *lock);
     108extern void spinlock_unlock_debug(spinlock_t *lock);
    106109
    107110/** Unlock spinlock
    108111 *
    109  * Unlock spinlock.
     112 * Unlock spinlock for non-debug kernels.
    110113 *
    111114 * @param sl Pointer to spinlock_t structure.
    112115 */
    113 static inline void spinlock_unlock(spinlock_t *lock)
     116static inline void spinlock_unlock_nondebug(spinlock_t *lock)
    114117{
    115         ASSERT(atomic_get(&lock->val) != 0);
    116        
    117118        /*
    118119         * Prevent critical section code from bleeding out this way down.
  • kernel/generic/src/console/cmd.c

    r6c39a907 r25a76ab8  
    837837        bool pointer = false;
    838838        int rc;
    839 
    840         if (((char *)argv->buffer)[0] == '*') {
     839       
     840        if (((char *) argv->buffer)[0] == '*') {
    841841                rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
    842842                pointer = true;
    843         } else if (((char *) argv->buffer)[0] >= '0' &&
    844                    ((char *)argv->buffer)[0] <= '9') {
    845                 rc = EOK;
    846                 addr = atoi((char *)argv->buffer);
    847         } else {
     843        } else if (((char *) argv->buffer)[0] >= '0' &&
     844                   ((char *) argv->buffer)[0] <= '9') {
     845                uint64_t value;
     846                rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
     847                if (rc == EOK)
     848                        addr = (uintptr_t) value;
     849        } else
    848850                rc = symtab_addr_lookup((char *) argv->buffer, &addr);
    849         }
    850 
     851       
    851852        if (rc == ENOENT)
    852853                printf("Symbol %s not found.\n", argv->buffer);
     854        else if (rc == EINVAL)
     855                printf("Invalid address.\n");
    853856        else if (rc == EOVERFLOW) {
    854857                symtab_print_search((char *) argv->buffer);
    855                 printf("Duplicate symbol, be more specific.\n");
     858                printf("Duplicate symbol (be more specific) or address overflow.\n");
    856859        } else if (rc == EOK) {
    857860                if (pointer)
     
    859862                printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
    860863                *(uint32_t *) addr = arg1;
    861         } else {
     864        } else
    862865                printf("No symbol information available.\n");
    863         }
    864866       
    865867        return 1;
  • kernel/generic/src/console/kconsole.c

    r6c39a907 r25a76ab8  
    455455                        printf("No symbol information available.\n");
    456456                        return false;
    457                 }
    458                
    459                 if (isaddr)
    460                         *result = (unative_t) symaddr;
    461                 else if (isptr)
    462                         *result = **((unative_t **) symaddr);
    463                 else
    464                         *result = *((unative_t *) symaddr);
     457                case EOK:
     458                        if (isaddr)
     459                                *result = (unative_t) symaddr;
     460                        else if (isptr)
     461                                *result = **((unative_t **) symaddr);
     462                        else
     463                                *result = *((unative_t *) symaddr);
     464                        break;
     465                default:
     466                        printf("Unknown error.\n");
     467                        return false;
     468                }
    465469        } else {
    466470                /* It's a number - convert it */
    467                 *result = atoi(text);
    468                 if (isptr)
    469                         *result = *((unative_t *) *result);
     471                uint64_t value;
     472                int rc = str_uint64(text, NULL, 0, true, &value);
     473                switch (rc) {
     474                case EINVAL:
     475                        printf("Invalid number.\n");
     476                        return false;
     477                case EOVERFLOW:
     478                        printf("Integer overflow.\n");
     479                        return false;
     480                case EOK:
     481                        *result = (unative_t) value;
     482                        if (isptr)
     483                                *result = *((unative_t *) *result);
     484                        break;
     485                default:
     486                        printf("Unknown error.\n");
     487                        return false;
     488                }
    470489        }
    471490       
  • kernel/generic/src/ddi/ddi.c

    r6c39a907 r25a76ab8  
    4646#include <mm/frame.h>
    4747#include <mm/as.h>
    48 #include <synch/spinlock.h>
     48#include <synch/mutex.h>
    4949#include <syscall/copy.h>
    5050#include <adt/btree.h>
     
    5454
    5555/** This lock protects the parea_btree. */
    56 SPINLOCK_INITIALIZE(parea_lock);
     56static mutex_t parea_lock;
    5757
    5858/** B+tree with enabled physical memory areas. */
     
    6363{
    6464        btree_create(&parea_btree);
     65        mutex_initialize(&parea_lock, MUTEX_PASSIVE);
    6566}
    6667
     
    7273void ddi_parea_register(parea_t *parea)
    7374{
    74         ipl_t ipl = interrupts_disable();
    75         spinlock_lock(&parea_lock);
     75        mutex_lock(&parea_lock);
    7676       
    7777        /*
     
    8080        btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
    8181       
    82         spinlock_unlock(&parea_lock);
    83         interrupts_restore(ipl);
     82        mutex_unlock(&parea_lock);
    8483}
    8584
     
    141140                spinlock_unlock(&zones.lock);
    142141               
    143                 spinlock_lock(&parea_lock);
     142                mutex_lock(&parea_lock);
    144143                btree_node_t *nodep;
    145144                parea_t *parea = (parea_t *) btree_search(&parea_btree,
     
    147146               
    148147                if ((!parea) || (parea->frames < pages)) {
    149                         spinlock_unlock(&parea_lock);
     148                        mutex_unlock(&parea_lock);
    150149                        goto err;
    151150                }
    152151               
    153                 spinlock_unlock(&parea_lock);
     152                mutex_unlock(&parea_lock);
    154153                goto map;
    155154        }
     
    161160       
    162161map:
    163         spinlock_lock(&TASK->lock);
    164        
     162        interrupts_restore(ipl);
     163
    165164        if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,
    166165            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
     
    169168                 * We report it using ENOMEM.
    170169                 */
    171                 spinlock_unlock(&TASK->lock);
    172                 interrupts_restore(ipl);
    173170                return ENOMEM;
    174171        }
     
    177174         * Mapping is created on-demand during page fault.
    178175         */
    179        
    180         spinlock_unlock(&TASK->lock);
    181         interrupts_restore(ipl);
    182176        return 0;
    183177}
  • kernel/generic/src/ipc/ipc.c

    r6c39a907 r25a76ab8  
    218218        answerbox_t *callerbox = call->callerbox;
    219219        bool do_lock = ((!selflocked) || callerbox != (&TASK->answerbox));
     220        ipl_t ipl;
    220221
    221222        /* Count sent answer */
     223        ipl = interrupts_disable();
    222224        spinlock_lock(&TASK->lock);
    223225        TASK->ipc_info.answer_sent++;
    224226        spinlock_unlock(&TASK->lock);
     227        interrupts_restore(ipl);
    225228
    226229        call->flags |= IPC_CALL_ANSWERED;
     
    281284static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call)
    282285{
     286        ipl_t ipl;
     287
    283288        /* Count sent ipc call */
     289        ipl = interrupts_disable();
    284290        spinlock_lock(&TASK->lock);
    285291        TASK->ipc_info.call_sent++;
    286292        spinlock_unlock(&TASK->lock);
     293        interrupts_restore(ipl);
    287294
    288295        if (!(call->flags & IPC_CALL_FORWARDED)) {
     
    386393int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox, int mode)
    387394{
     395        ipl_t ipl;
     396
    388397        /* Count forwarded calls */
     398        ipl = interrupts_disable();
    389399        spinlock_lock(&TASK->lock);
    390400        TASK->ipc_info.forwarded++;
    391401        spinlock_unlock(&TASK->lock);
     402        interrupts_restore(ipl);
    392403
    393404        spinlock_lock(&oldbox->lock);
     
    422433        call_t *request;
    423434        ipl_t ipl;
     435        uint64_t irq_cnt = 0;
     436        uint64_t answer_cnt = 0;
     437        uint64_t call_cnt = 0;
    424438        int rc;
    425439
     
    431445        spinlock_lock(&box->lock);
    432446        if (!list_empty(&box->irq_notifs)) {
    433 
    434447                /* Count recieved IRQ notification */
    435                 spinlock_lock(&TASK->lock);
    436                 TASK->ipc_info.irq_notif_recieved++;
    437                 spinlock_unlock(&TASK->lock);
     448                irq_cnt++;     
    438449
    439450                ipl = interrupts_disable();
     
    447458        } else if (!list_empty(&box->answers)) {
    448459                /* Count recieved answer */
    449                 spinlock_lock(&TASK->lock);
    450                 TASK->ipc_info.answer_recieved++;
    451                 spinlock_unlock(&TASK->lock);
     460                answer_cnt++;
    452461
    453462                /* Handle asynchronous answers */
     
    457466        } else if (!list_empty(&box->calls)) {
    458467                /* Count recieved call */
    459                 spinlock_lock(&TASK->lock);
    460                 TASK->ipc_info.call_recieved++;
    461                 spinlock_unlock(&TASK->lock);
     468                call_cnt++;
    462469
    463470                /* Handle requests */
     
    472479        }
    473480        spinlock_unlock(&box->lock);
     481       
     482        ipl = interrupts_disable();
     483        spinlock_lock(&TASK->lock);
     484        TASK->ipc_info.irq_notif_recieved += irq_cnt;
     485        TASK->ipc_info.answer_recieved += answer_cnt;
     486        TASK->ipc_info.call_recieved += call_cnt;
     487        spinlock_unlock(&TASK->lock);
     488        interrupts_restore(ipl);
     489
    474490        return request;
    475491}
     
    675691        call_t *call;
    676692        link_t *tmp;
     693        ipl_t ipl;
    677694       
     695        ipl = interrupts_disable();
    678696        spinlock_lock(&tasks_lock);
    679697        task = task_find_by_id(taskid);
     
    681699                spinlock_lock(&task->lock);
    682700        spinlock_unlock(&tasks_lock);
    683         if (!task)
     701        if (!task) {
     702                interrupts_restore(ipl);
    684703                return;
     704        }
    685705
    686706        /* Print opened phones & details */
     
    765785        spinlock_unlock(&task->answerbox.lock);
    766786        spinlock_unlock(&task->lock);
     787        interrupts_restore(ipl);
    767788}
    768789
  • kernel/generic/src/lib/func.c

    r6c39a907 r25a76ab8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3333/**
    3434 * @file
    35  * @brief       Miscellaneous functions.
     35 * @brief Miscellaneous functions.
    3636 */
    3737
     
    7979}
    8080
    81 /** Convert ascii representation to unative_t
    82  *
    83  * Supports 0x for hexa & 0 for octal notation.
    84  * Does not check for overflows, does not support negative numbers
    85  *
    86  * @param text Textual representation of number
    87  * @return Converted number or 0 if no valid number ofund
    88  */
    89 unative_t atoi(const char *text)
    90 {
    91         int base = 10;
    92         unative_t result = 0;
    93 
    94         if (text[0] == '0' && text[1] == 'x') {
    95                 base = 16;
    96                 text += 2;
    97         } else if (text[0] == '0')
    98                 base = 8;
    99 
    100         while (*text) {
    101                 if (base != 16 && \
    102                     ((*text >= 'A' && *text <= 'F' )
    103                      || (*text >='a' && *text <='f')))
    104                         break;
    105                 if (base == 8 && *text >='8')
    106                         break;
    107 
    108                 if (*text >= '0' && *text <= '9') {
    109                         result *= base;
    110                         result += *text - '0';
    111                 } else if (*text >= 'A' && *text <= 'F') {
    112                         result *= base;
    113                         result += *text - 'A' + 10;
    114                 } else if (*text >= 'a' && *text <= 'f') {
    115                         result *= base;
    116                         result += *text - 'a' + 10;
    117                 } else
    118                         break;
    119                 text++;
    120         }
    121 
    122         return result;
    123 }
    124 
    12581/** @}
    12682 */
  • kernel/generic/src/lib/str.c

    r6c39a907 r25a76ab8  
    823823                                str++;
    824824                                break;
     825                        default:
     826                                str--;
    825827                        }
    826828                }
     
    886888 * @param base   Zero or number between 2 and 36 inclusive.
    887889 * @param strict Do not allow any trailing characters.
    888  * @apram result Result of the conversion.
     890 * @param result Result of the conversion.
    889891 *
    890892 * @return EOK if conversion was successful.
  • kernel/generic/src/mm/as.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2006 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    152152         * reference count never drops to zero.
    153153         */
    154         atomic_set(&AS_KERNEL->refcount, 1);
     154        as_hold(AS_KERNEL);
    155155}
    156156
     
    200200        DEADLOCK_PROBE_INIT(p_asidlock);
    201201
     202        ASSERT(as != AS);
    202203        ASSERT(atomic_get(&as->refcount) == 0);
    203204       
    204205        /*
    205          * Since there is no reference to this area,
    206          * it is safe not to lock its mutex.
     206         * Since there is no reference to this address space, it is safe not to
     207         * lock its mutex.
    207208         */
    208209
     
    225226        preemption_enable();    /* Interrupts disabled, enable preemption */
    226227        if (as->asid != ASID_INVALID && as != AS_KERNEL) {
    227                 if (as != AS && as->cpu_refcount == 0)
     228                if (as->cpu_refcount == 0)
    228229                        list_remove(&as->inactive_as_with_asid_link);
    229230                asid_put(as->asid);
     
    258259
    259260        slab_free(as_slab, as);
     261}
     262
     263/** Hold a reference to an address space.
     264 *
     265 * Holding a reference to an address space prevents destruction of that address
     266 * space.
     267 *
     268 * @param a             Address space to be held.
     269 */
     270void as_hold(as_t *as)
     271{
     272        atomic_inc(&as->refcount);
     273}
     274
     275/** Release a reference to an address space.
     276 *
     277 * The last one to release a reference to an address space destroys the address
     278 * space.
     279 *
     280 * @param a             Address space to be released.
     281 */
     282void as_release(as_t *as)
     283{
     284        if (atomic_predec(&as->refcount) == 0)
     285                as_destroy(as);
    260286}
    261287
  • kernel/generic/src/mm/frame.c

    r6c39a907 r25a76ab8  
    10331033                spinlock_unlock(&zones.lock);
    10341034                interrupts_restore(ipl);
     1035
     1036                if (!THREAD)
     1037                        panic("Cannot wait for memory to become available.");
    10351038               
    10361039                /*
  • kernel/generic/src/mm/slab.c

    r6c39a907 r25a76ab8  
    555555 * Initialize mag_cache structure in slab cache
    556556 */
    557 static void make_magcache(slab_cache_t *cache)
     557static bool make_magcache(slab_cache_t *cache)
    558558{
    559559        unsigned int i;
     
    562562
    563563        cache->mag_cache = malloc(sizeof(slab_mag_cache_t) * config.cpu_count,
    564             0);
     564            FRAME_ATOMIC);
     565        if (!cache->mag_cache)
     566                return false;
     567
    565568        for (i = 0; i < config.cpu_count; i++) {
    566569                memsetb(&cache->mag_cache[i], sizeof(cache->mag_cache[i]), 0);
     
    568571                    "slab_maglock_cpu");
    569572        }
     573        return true;
    570574}
    571575
     
    597601        spinlock_initialize(&cache->maglock, "slab_maglock");
    598602        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    599                 make_magcache(cache);
     603                (void) make_magcache(cache);
    600604
    601605        /* Compute slab sizes, object counts in slabs etc. */
     
    923927                    SLAB_CACHE_MAGDEFERRED)
    924928                        continue;
    925                 make_magcache(s);
     929                (void) make_magcache(s);
    926930                s->flags &= ~SLAB_CACHE_MAGDEFERRED;
    927931        }
  • kernel/generic/src/printf/printf_core.c

    r6c39a907 r25a76ab8  
    261261        if (str == NULL)
    262262                return printf_putstr(nullstr, ps);
    263 
     263       
    264264        /* Print leading spaces. */
    265265        size_t strw = str_length(str);
    266266        if (precision == 0)
    267267                precision = strw;
    268 
     268       
    269269        /* Left padding */
    270270        size_t counter = 0;
     
    276276                }
    277277        }
    278 
     278       
    279279        /* Part of @a str fitting into the alloted space. */
    280280        int retval;
     
    391391         */
    392392        if (flags & __PRINTF_FLAG_PREFIX) {
    393                 switch(base) {
     393                switch (base) {
    394394                case 2:
    395395                        /* Binary formating is not standard, but usefull */
     
    455455        /* Print prefix */
    456456        if (flags & __PRINTF_FLAG_PREFIX) {
    457                 switch(base) {
     457                switch (base) {
    458458                case 2:
    459459                        /* Binary formating is not standard, but usefull */
     
    570570 *
    571571 *  - P, p Print value of a pointer. Void * value is expected and it is
    572  *         printed in hexadecimal notation with prefix (as with \%#X / \%#x
    573  *         for 32-bit or \%#X / \%#x for 64-bit long pointers).
     572 *         printed in hexadecimal notation with prefix (as with
     573 *         \%#0.8X / \%#0.8x for 32-bit or \%#0.16lX / \%#0.16lx for 64-bit
     574 *         long pointers).
    574575 *
    575576 *  - b Print value as unsigned binary number. Prefix is not printed by
     
    784785                        case 'p':
    785786                                flags |= __PRINTF_FLAG_PREFIX;
     787                                flags |= __PRINTF_FLAG_ZEROPADDED;
    786788                                base = 16;
    787789                                qualifier = PrintfQualifierPointer;
     
    846848                        case PrintfQualifierPointer:
    847849                                size = sizeof(void *);
    848                                 number = (uint64_t) (unsigned long) va_arg(ap, void *);
     850                                precision = size << 1;
     851                                number = (uint64_t) (uintptr_t) va_arg(ap, void *);
    849852                                break;
    850853                        default:
  • kernel/generic/src/proc/scheduler.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2007 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    187187
    188188loop:
    189         interrupts_enable();
    190189       
    191190        if (atomic_get(&CPU->nrdy) == 0) {
     
    196195                 */
    197196
    198                 /*
     197                 /* Mark CPU as it was idle this clock tick */
     198                 spinlock_lock(&CPU->lock);
     199                 CPU->idle = true;
     200                 spinlock_unlock(&CPU->lock);
     201
     202                 interrupts_enable();
     203                 /*
    199204                 * An interrupt might occur right now and wake up a thread.
    200205                 * In such case, the CPU will continue to go to sleep
    201206                 * even though there is a runnable thread.
    202207                 */
    203 
    204                  spinlock_lock(&CPU->lock);
    205                  CPU->idle = true;
    206                  spinlock_unlock(&CPU->lock);
    207208                 cpu_sleep();
     209                 interrupts_disable();
    208210                 goto loop;
    209211        }
    210 
    211         interrupts_disable();
    212212       
    213213        for (i = 0; i < RQ_COUNT; i++) {
     
    382382        int priority;
    383383        DEADLOCK_PROBE_INIT(p_joinwq);
     384        task_t *old_task = TASK;
     385        as_t *old_as = AS;
    384386
    385387        ASSERT(CPU != NULL);
    386388       
     389        /*
     390         * Hold the current task and the address space to prevent their
     391         * possible destruction should thread_destroy() be called on this or any
     392         * other processor while the scheduler is still using them.
     393         */
     394        if (old_task)
     395                task_hold(old_task);
     396        if (old_as)
     397                as_hold(old_as);
     398
    387399        if (THREAD) {
    388400                /* must be run after the switch to scheduler stack */
     
    476488         */
    477489        if (TASK != THREAD->task) {
    478                 as_t *as1 = NULL;
    479                 as_t *as2;
    480 
    481                 if (TASK) {
    482                         spinlock_lock(&TASK->lock);
    483                         as1 = TASK->as;
    484                         spinlock_unlock(&TASK->lock);
    485                 }
    486 
    487                 spinlock_lock(&THREAD->task->lock);
    488                 as2 = THREAD->task->as;
    489                 spinlock_unlock(&THREAD->task->lock);
     490                as_t *new_as = THREAD->task->as;
    490491               
    491492                /*
     
    493494                 * space.
    494495                 */
    495                 if (as1 != as2) {
     496                if (old_as != new_as) {
    496497                        /*
    497498                         * Both tasks and address spaces are different.
    498499                         * Replace the old one with the new one.
    499500                         */
    500                         as_switch(as1, as2);
     501                        as_switch(old_as, new_as);
    501502                }
     503
    502504                TASK = THREAD->task;
    503505                before_task_runs();
    504506        }
    505507
     508        if (old_task)
     509                task_release(old_task);
     510        if (old_as)
     511                as_release(old_as);
     512       
    506513        spinlock_lock(&THREAD->lock);   
    507514        THREAD->state = Running;
  • kernel/generic/src/proc/task.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    210210        btree_create(&ta->futexes);
    211211       
     212        /*
     213         * Get a reference to the address space.
     214         */
     215        as_hold(ta->as);
     216
    212217        ipl = interrupts_disable();
    213         atomic_inc(&as->refcount);
    214218        spinlock_lock(&tasks_lock);
    215219        ta->taskid = ++task_counter;
     
    250254         * Drop our reference to the address space.
    251255         */
    252         if (atomic_predec(&t->as->refcount) == 0)
    253                 as_destroy(t->as);
     256        as_release(t->as);
    254257       
    255258        slab_free(task_slab, t);
    256         TASK = NULL;
     259}
     260
     261/** Hold a reference to a task.
     262 *
     263 * Holding a reference to a task prevents destruction of that task.
     264 *
     265 * @param t             Task to be held.
     266 */
     267void task_hold(task_t *t)
     268{
     269        atomic_inc(&t->refcount);
     270}
     271
     272/** Release a reference to a task.
     273 *
     274 * The last one to release a reference to a task destroys the task.
     275 *
     276 * @param t             Task to be released.
     277 */
     278void task_release(task_t *t)
     279{
     280        if ((atomic_predec(&t->refcount)) == 0)
     281                task_destroy(t);
    257282}
    258283
  • kernel/generic/src/proc/thread.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    409409
    410410        /*
    411          * t is guaranteed to be the very last thread of its task.
    412          * It is safe to destroy the task.
     411         * Drop the reference to the containing task.
    413412         */
    414         if (atomic_predec(&t->task->refcount) == 0)
    415                 task_destroy(t->task);
     413        task_release(t->task);
    416414       
    417415        slab_free(thread_slab, t);
     
    436434        spinlock_lock(&task->lock);
    437435
    438         atomic_inc(&task->refcount);
     436        /* Hold a reference to the task. */
     437        task_hold(task);
    439438
    440439        /* Must not count kbox thread into lifecount */
  • kernel/generic/src/synch/mutex.c

    r6c39a907 r25a76ab8  
    4040#include <synch/synch.h>
    4141#include <debug.h>
     42#include <arch.h>
    4243
    4344/** Initialize mutex.
     
    6970        int rc;
    7071
    71         if (mtx->type == MUTEX_PASSIVE) {
     72        if (mtx->type == MUTEX_PASSIVE && THREAD) {
    7273                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
    7374        } else {
    74                 ASSERT(mtx->type == MUTEX_ACTIVE);
     75                ASSERT(mtx->type == MUTEX_ACTIVE || !THREAD);
    7576                ASSERT(usec == SYNCH_NO_TIMEOUT);
    7677                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
  • kernel/generic/src/synch/spinlock.c

    r6c39a907 r25a76ab8  
    120120}
    121121
     122/** Unlock spinlock
     123 *
     124 * Unlock spinlock.
     125 *
     126 * @param sl Pointer to spinlock_t structure.
     127 */
     128void spinlock_unlock_debug(spinlock_t *lock)
     129{
     130        ASSERT(atomic_get(&lock->val) != 0);
     131       
     132        /*
     133         * Prevent critical section code from bleeding out this way down.
     134         */
     135        CS_LEAVE_BARRIER();
     136       
     137        atomic_set(&lock->val, 0);
     138        preemption_enable();
     139}
     140
    122141#endif
    123142
  • kernel/generic/src/sysinfo/stats.c

    r6c39a907 r25a76ab8  
    3838#include <sysinfo/stats.h>
    3939#include <sysinfo/sysinfo.h>
     40#include <synch/spinlock.h>
     41#include <synch/mutex.h>
    4042#include <time/clock.h>
    4143#include <mm/frame.h>
     
    6870static load_t avenrdy[LOAD_STEPS] = {0, 0, 0};
    6971
    70 /** Load calculation spinlock */
    71 SPINLOCK_STATIC_INITIALIZE_NAME(load_lock, "load_lock");
     72/** Load calculation lock */
     73static mutex_t load_lock;
    7274
    7375/** Get system uptime
     
    156158static size_t get_task_virtmem(as_t *as)
    157159{
    158         mutex_lock(&as->lock);
    159        
    160160        size_t result = 0;
     161
     162        /*
     163         * We are holding some spinlocks here and therefore are not allowed to
     164         * block. Only attempt to lock the address space and address space area
     165         * mutexes conditionally. If it is not possible to lock either object,
     166         * allow the statistics to be inexact by skipping the respective object.
     167         *
     168         * Note that it may be infinitely better to let the address space
     169         * management code compute these statistics as it proceeds instead of
     170         * having them calculated here over and over again here.
     171         */
     172
     173        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     174                return result * PAGE_SIZE;
    161175       
    162176        /* Walk the B+ tree and count pages */
     
    171185                        as_area_t *area = node->value[i];
    172186                       
    173                         mutex_lock(&area->lock);
     187                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     188                                continue;
    174189                        result += area->pages;
    175190                        mutex_unlock(&area->lock);
     
    331346       
    332347        /* Interrupts are already disabled */
    333         spinlock_lock(&(thread->lock));
     348        spinlock_lock(&thread->lock);
    334349       
    335350        /* Record the statistics and increment the iterator */
     
    337352        (*iterator)++;
    338353       
    339         spinlock_unlock(&(thread->lock));
     354        spinlock_unlock(&thread->lock);
    340355       
    341356        return true;
     
    602617        }
    603618       
    604         /* To always get consistent values acquire the spinlock */
    605         ipl_t ipl = interrupts_disable();
    606         spinlock_lock(&load_lock);
     619        /* To always get consistent values acquire the mutex */
     620        mutex_lock(&load_lock);
    607621       
    608622        unsigned int i;
     
    610624                stats_load[i] = avenrdy[i] << LOAD_FIXED_SHIFT;
    611625       
    612         spinlock_unlock(&load_lock);
    613         interrupts_restore(ipl);
     626        mutex_unlock(&load_lock);
    614627       
    615628        return ((void *) stats_load);
     
    642655               
    643656                /* Mutually exclude with get_stats_load() */
    644                 ipl_t ipl = interrupts_disable();
    645                 spinlock_lock(&load_lock);
     657                mutex_lock(&load_lock);
    646658               
    647659                unsigned int i;
     
    649661                        avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready);
    650662               
    651                 spinlock_unlock(&load_lock);
    652                 interrupts_restore(ipl);
     663                mutex_unlock(&load_lock);
    653664               
    654665                thread_sleep(LOAD_INTERVAL);
     
    661672void stats_init(void)
    662673{
     674        mutex_initialize(&load_lock, MUTEX_PASSIVE);
     675
    663676        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    664677        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
  • kernel/generic/src/sysinfo/sysinfo.c

    r6c39a907 r25a76ab8  
    3737#include <print.h>
    3838#include <syscall/copy.h>
    39 #include <synch/spinlock.h>
     39#include <synch/mutex.h>
    4040#include <arch/asm.h>
    4141#include <errno.h>
     
    5252static slab_cache_t *sysinfo_item_slab;
    5353
    54 /** Sysinfo spinlock */
    55 SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "sysinfo_lock");
     54/** Sysinfo lock */
     55static mutex_t sysinfo_lock;
    5656
    5757/** Sysinfo item constructor
     
    9898            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    9999            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
     100
     101        mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    100102}
    101103
    102104/** Recursively find an item in sysinfo tree
    103105 *
    104  * Should be called with interrupts disabled
    105  * and sysinfo_lock held.
     106 * Should be called with sysinfo_lock held.
    106107 *
    107108 * @param name    Current sysinfo path suffix.
     
    168169/** Recursively create items in sysinfo tree
    169170 *
    170  * Should be called with interrupts disabled
    171  * and sysinfo_lock held.
     171 * Should be called with sysinfo_lock held.
    172172 *
    173173 * @param name     Current sysinfo path suffix.
     
    299299{
    300300        /* Protect sysinfo tree consistency */
    301         ipl_t ipl = interrupts_disable();
    302         spinlock_lock(&sysinfo_lock);
     301        mutex_lock(&sysinfo_lock);
    303302       
    304303        if (root == NULL)
     
    311310        }
    312311       
    313         spinlock_unlock(&sysinfo_lock);
    314         interrupts_restore(ipl);
     312        mutex_unlock(&sysinfo_lock);
    315313}
    316314
     
    332330{
    333331        /* Protect sysinfo tree consistency */
    334         ipl_t ipl = interrupts_disable();
    335         spinlock_lock(&sysinfo_lock);
     332        mutex_lock(&sysinfo_lock);
    336333       
    337334        if (root == NULL)
     
    345342        }
    346343       
    347         spinlock_unlock(&sysinfo_lock);
    348         interrupts_restore(ipl);
     344        mutex_unlock(&sysinfo_lock);
    349345}
    350346
     
    361357{
    362358        /* Protect sysinfo tree consistency */
    363         ipl_t ipl = interrupts_disable();
    364         spinlock_lock(&sysinfo_lock);
     359        mutex_lock(&sysinfo_lock);
    365360       
    366361        if (root == NULL)
     
    373368        }
    374369       
    375         spinlock_unlock(&sysinfo_lock);
    376         interrupts_restore(ipl);
     370        mutex_unlock(&sysinfo_lock);
    377371}
    378372
     
    394388{
    395389        /* Protect sysinfo tree consistency */
    396         ipl_t ipl = interrupts_disable();
    397         spinlock_lock(&sysinfo_lock);
     390        mutex_lock(&sysinfo_lock);
    398391       
    399392        if (root == NULL)
     
    406399        }
    407400       
    408         spinlock_unlock(&sysinfo_lock);
    409         interrupts_restore(ipl);
     401        mutex_unlock(&sysinfo_lock);
    410402}
    411403
     
    420412{
    421413        /* Protect sysinfo tree consistency */
    422         ipl_t ipl = interrupts_disable();
    423         spinlock_lock(&sysinfo_lock);
     414        mutex_lock(&sysinfo_lock);
    424415       
    425416        if (root == NULL)
     
    430421                item->val_type = SYSINFO_VAL_UNDEFINED;
    431422       
    432         spinlock_unlock(&sysinfo_lock);
    433         interrupts_restore(ipl);
     423        mutex_unlock(&sysinfo_lock);
    434424}
    435425
     
    446436{
    447437        /* Protect sysinfo tree consistency */
    448         ipl_t ipl = interrupts_disable();
    449         spinlock_lock(&sysinfo_lock);
     438        mutex_lock(&sysinfo_lock);
    450439       
    451440        if (root == NULL)
     
    461450        }
    462451       
    463         spinlock_unlock(&sysinfo_lock);
    464         interrupts_restore(ipl);
     452        mutex_unlock(&sysinfo_lock);
    465453}
    466454
     
    479467/** Dump the structure of sysinfo tree
    480468 *
    481  * Should be called with interrupts disabled
    482  * and sysinfo_lock held. Because this routine
    483  * might take a reasonable long time to proceed,
    484  * having the spinlock held is not optimal, but
    485  * there is no better simple solution.
     469 * Should be called with sysinfo_lock held.
    486470 *
    487471 * @param root  Root item of the current (sub)tree.
     
    559543        /* Avoid other functions to mess with sysinfo
    560544           while we are dumping it */
    561         ipl_t ipl = interrupts_disable();
    562         spinlock_lock(&sysinfo_lock);
     545        mutex_lock(&sysinfo_lock);
    563546       
    564547        if (root == NULL)
     
    567550                sysinfo_dump_internal(root, 0);
    568551       
    569         spinlock_unlock(&sysinfo_lock);
    570         interrupts_restore(ipl);
     552        mutex_unlock(&sysinfo_lock);
    571553}
    572554
    573555/** Return sysinfo item value determined by name
    574556 *
    575  * Should be called with interrupts disabled
    576  * and sysinfo_lock held.
     557 * Should be called with sysinfo_lock held.
    577558 *
    578559 * @param name    Sysinfo path.
     
    632613/** Return sysinfo item determined by name from user space
    633614 *
    634  * Should be called with interrupts disabled
    635  * and sysinfo_lock held. The path string passed from
    636  * the user space has to be properly null-terminated
     615 * The path string passed from the user space has to be properly null-terminated
    637616 * (the last passed character must be null).
    638617 *
     
    656635       
    657636        if ((copy_from_uspace(path, ptr, size + 1) == 0)
    658             && (path[size] == 0))
     637            && (path[size] == 0)) {
     638                /*
     639                 * Prevent other functions from messing with sysinfo while we
     640                 * are reading it.
     641                 */
     642                mutex_lock(&sysinfo_lock);
    659643                ret = sysinfo_get_item(path, NULL, dry_run);
    660        
     644                mutex_unlock(&sysinfo_lock);
     645        }
    661646        free(path);
    662647        return ret;
     
    677662unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
    678663{
    679         /* Avoid other functions to mess with sysinfo
    680            while we are reading it */
    681         ipl_t ipl = interrupts_disable();
    682         spinlock_lock(&sysinfo_lock);
    683        
    684         /* Get the item.
    685        
    686            N.B.: There is no need to free any potential generated
    687            binary data since we request a dry run */
     664        /*
     665         * Get the item.
     666         *
     667         * N.B.: There is no need to free any potential generated
     668         * binary data since we request a dry run.
     669         */
    688670        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    689671       
    690         /* Map generated value types to constant types
    691            (user space does not care whether the
    692            value is constant or generated) */
     672        /*
     673         * Map generated value types to constant types (user space does not care
     674         * whether the value is constant or generated).
     675         */
    693676        if (ret.tag == SYSINFO_VAL_FUNCTION_VAL)
    694677                ret.tag = SYSINFO_VAL_VAL;
     
    696679                ret.tag = SYSINFO_VAL_DATA;
    697680       
    698         spinlock_unlock(&sysinfo_lock);
    699         interrupts_restore(ipl);
    700        
    701681        return (unative_t) ret.tag;
    702682}
     
    719699    void *value_ptr)
    720700{
    721         /* Avoid other functions to mess with sysinfo
    722            while we are reading it */
    723         ipl_t ipl = interrupts_disable();
    724         spinlock_lock(&sysinfo_lock);
    725        
    726         /* Get the item.
    727        
    728            N.B.: There is no need to free any potential generated
    729            binary data since we request a dry run */
     701        int rc;
     702
     703        /*
     704         * Get the item.
     705         *
     706         * N.B.: There is no need to free any potential generated binary data
     707         * since we request a dry run.
     708         */
    730709        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    731         int rc;
    732710       
    733711        /* Only constant or generated numerical value is returned */
     
    737715                rc = EINVAL;
    738716       
    739         spinlock_unlock(&sysinfo_lock);
    740         interrupts_restore(ipl);
    741        
    742717        return (unative_t) rc;
    743718}
     
    760735    void *size_ptr)
    761736{
    762         /* Avoid other functions to mess with sysinfo
    763            while we are reading it */
    764         ipl_t ipl = interrupts_disable();
    765         spinlock_lock(&sysinfo_lock);
    766        
    767         /* Get the item.
    768        
    769            N.B.: There is no need to free any potential generated
    770            binary data since we request a dry run */
     737        int rc;
     738       
     739        /*
     740         * Get the item.
     741         *
     742         * N.B.: There is no need to free any potential generated binary data
     743         * since we request a dry run.
     744         */
    771745        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    772         int rc;
    773746       
    774747        /* Only the size of constant or generated binary data is considered */
     
    779752                rc = EINVAL;
    780753       
    781         spinlock_unlock(&sysinfo_lock);
    782         interrupts_restore(ipl);
    783        
    784754        return (unative_t) rc;
    785755}
     
    807777    void *buffer_ptr, size_t buffer_size)
    808778{
    809         /* Avoid other functions to mess with sysinfo
    810            while we are reading it */
    811         ipl_t ipl = interrupts_disable();
    812         spinlock_lock(&sysinfo_lock);
     779        int rc;
    813780       
    814781        /* Get the item */
    815782        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    816         int rc;
    817        
     783
    818784        /* Only constant or generated binary data is considered */
    819785        if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     
    831797                free(ret.data.data);
    832798       
    833         spinlock_unlock(&sysinfo_lock);
    834         interrupts_restore(ipl);
    835        
    836799        return (unative_t) rc;
    837800}
  • kernel/generic/src/time/clock.c

    r6c39a907 r25a76ab8  
    140140        /* Account lost ticks to CPU usage */
    141141        if (CPU->idle) {
    142                 ASSERT(missed_clock_ticks == 0);
    143                 CPU->idle_ticks++;
     142                CPU->idle_ticks += missed_clock_ticks + 1;
    144143        } else {
    145144                CPU->busy_ticks += missed_clock_ticks + 1;
Note: See TracChangeset for help on using the changeset viewer.