Changeset 46c20c8 in mainline for kernel/generic/include


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (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/include
Files:
4 added
70 edited
2 moved

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/adt/avl.h

    rfb150d78 r46c20c8  
    3434
    3535#ifndef KERN_AVLTREE_H_
    36 #define KERN_AVLTREE_H_ 
     36#define KERN_AVLTREE_H_
    3737
    38 #include <arch/types.h>
    3938#include <typedefs.h>
     39#include <trace.h>
    4040
    4141/**
     
    111111 * @param t AVL tree.
    112112 */
    113 static inline void avltree_create(avltree_t *t)
     113NO_TRACE static inline void avltree_create(avltree_t *t)
    114114{
    115115        t->root = NULL;
     
    121121 * @param node Node which is initialized.
    122122 */
    123 static inline void avltree_node_initialize(avltree_node_t *node)
     123NO_TRACE static inline void avltree_node_initialize(avltree_node_t *node)
    124124{
    125125        node->key = 0;
  • kernel/generic/include/adt/bitmap.h

    rfb150d78 r46c20c8  
    3636#define KERN_BITMAP_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040#define BITS2BYTES(bits)        (bits ? ((((bits)-1)>>3)+1) : 0)
  • kernel/generic/include/adt/btree.h

    rfb150d78 r46c20c8  
    3636#define KERN_BTREE_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <adt/list.h>
    4040
  • kernel/generic/include/adt/hash_table.h

    rfb150d78 r46c20c8  
    3737
    3838#include <adt/list.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040
    4141/** Set of operations for hash table. */
  • kernel/generic/include/adt/list.h

    rfb150d78 r46c20c8  
    3636#define KERN_LIST_H_
    3737
    38 #include <arch/types.h>
    3938#include <typedefs.h>
     39#include <trace.h>
    4040
    4141/** Doubly linked list head and link type. */
     
    5858 * @param link Pointer to link_t structure to be initialized.
    5959 */
    60 static inline void link_initialize(link_t *link)
     60NO_TRACE static inline void link_initialize(link_t *link)
    6161{
    6262        link->prev = NULL;
     
    7070 * @param head Pointer to link_t structure representing head of the list.
    7171 */
    72 static inline void list_initialize(link_t *head)
     72NO_TRACE static inline void list_initialize(link_t *head)
    7373{
    7474        head->prev = head;
     
    8383 * @param head Pointer to link_t structure representing head of the list.
    8484 */
    85 static inline void list_prepend(link_t *link, link_t *head)
     85NO_TRACE static inline void list_prepend(link_t *link, link_t *head)
    8686{
    8787        link->next = head->next;
     
    9898 * @param head Pointer to link_t structure representing head of the list.
    9999 */
    100 static inline void list_append(link_t *link, link_t *head)
     100NO_TRACE static inline void list_append(link_t *link, link_t *head)
    101101{
    102102        link->prev = head->prev;
     
    113113 *              contained in.
    114114 */
    115 static inline void list_remove(link_t *link)
     115NO_TRACE static inline void list_remove(link_t *link)
    116116{
    117117        link->next->prev = link->prev;
     
    126126 * @param head Pointer to link_t structure representing head of the list.
    127127 */
    128 static inline bool list_empty(link_t *head)
     128NO_TRACE static inline bool list_empty(link_t *head)
    129129{
    130130        return head->next == head ? true : false;
     
    144144 *              headless) list.
    145145 */
    146 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     146NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
    147147{
    148148        link_t *hlp;
     
    165165 *              headless list.
    166166 */
    167 static inline void headless_list_split(link_t *part1, link_t *part2)
     167NO_TRACE static inline void headless_list_split(link_t *part1, link_t *part2)
    168168{
    169169        headless_list_split_or_concat(part1, part2);
     
    177177 * @param part2 Pointer to link_t structure leading the second headless list.
    178178 */
    179 static inline void headless_list_concat(link_t *part1, link_t *part2)
     179NO_TRACE static inline void headless_list_concat(link_t *part1, link_t *part2)
    180180{
    181181        headless_list_split_or_concat(part1, part2);
  • kernel/generic/include/arch.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    4141#include <mm/as.h>
    4242
    43 #define DEFAULT_CONTEXT         0
     43#define DEFAULT_CONTEXT  0
    4444
    45 #define CPU                     THE->cpu
    46 #define THREAD                  THE->thread
    47 #define TASK                    THE->task
    48 #define AS                      THE->as
    49 #define CONTEXT         (THE->task ? THE->task->context : DEFAULT_CONTEXT)
    50 #define PREEMPTION_DISABLED     THE->preemption_disabled
     45#define CPU                  THE->cpu
     46#define THREAD               THE->thread
     47#define TASK                 THE->task
     48#define AS                   THE->as
     49#define CONTEXT              (THE->task ? THE->task->context : DEFAULT_CONTEXT)
     50#define PREEMPTION_DISABLED  THE->preemption_disabled
    5151
    52 #define context_check(ctx1, ctx2)       ((ctx1) == (ctx2))
     52#define context_check(ctx1, ctx2)  ((ctx1) == (ctx2))
    5353
    5454/**
     
    5858 */
    5959typedef struct {
    60         size_t preemption_disabled;     /**< Preemption disabled counter. */
    61         thread_t *thread;               /**< Current thread. */
    62         task_t *task;                   /**< Current task. */
    63         cpu_t *cpu;                     /**< Executing cpu. */
    64         as_t *as;                       /**< Current address space. */
     60        size_t preemption_disabled;  /**< Preemption disabled counter. */
     61        thread_t *thread;            /**< Current thread. */
     62        task_t *task;                /**< Current task. */
     63        cpu_t *cpu;                  /**< Executing cpu. */
     64        as_t *as;                    /**< Current address space. */
    6565} the_t;
    6666
     67/*
     68 * THE is not an abbreviation, but the English definite article written in
     69 * capital letters. It means the current pointer to something, e.g. thread,
     70 * processor or address space. Kind reader of this comment shall appreciate
     71 * the wit of constructs like THE->thread and similar.
     72 */
    6773#define THE  ((the_t * )(get_stack_base()))
    6874
    69 extern void the_initialize(the_t *the);
    70 extern void the_copy(the_t *src, the_t *dst);
     75extern void the_initialize(the_t *);
     76extern void the_copy(the_t *, the_t *);
    7177
    7278extern void arch_pre_mm_init(void);
     
    8086extern void reboot(void);
    8187extern void arch_reboot(void);
    82 extern void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller);
     88extern void *arch_construct_function(fncptr_t *, void *, void *);
    8389
    8490#endif
  • kernel/generic/include/atomic.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_ATOMIC_H_
    3737
    38 typedef struct atomic {
    39         volatile long count;
    40 } atomic_t;
     38#include <typedefs.h>
     39#include <arch/atomic.h>
     40#include <verify.h>
    4141
    42 #include <arch/atomic.h>
    43 
    44 static inline void atomic_set(atomic_t *val, long i)
     42NO_TRACE ATOMIC static inline void atomic_set(atomic_t *val, atomic_count_t i)
     43    WRITES(&val->count)
     44    REQUIRES_EXTENT_MUTABLE(val)
    4545{
    4646        val->count = i;
    4747}
    4848
    49 static inline long atomic_get(atomic_t *val)
     49NO_TRACE ATOMIC static inline atomic_count_t atomic_get(atomic_t *val)
     50    REQUIRES_EXTENT_MUTABLE(val)
    5051{
    5152        return val->count;
  • kernel/generic/include/bitops.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_BITOPS_H_
    3737
     38#include <trace.h>
    3839
    39 /** Return position of first non-zero bit from left (i.e. [log_2(arg)]).
     40#ifdef __32_BITS__
     41        #define fnzb(arg)  fnzb32(arg)
     42#endif
     43
     44#ifdef __64_BITS__
     45        #define fnzb(arg)  fnzb64(arg)
     46#endif
     47
     48/** Return position of first non-zero bit from left (32b variant).
    4049 *
    41  * If number is zero, it returns 0
     50 * @return 0 (if the number is zero) or [log_2(arg)].
     51 *
    4252 */
    43 static inline int fnzb32(uint32_t arg)
     53NO_TRACE static inline uint8_t fnzb32(uint32_t arg)
    4454{
    45         int n = 0;
    46 
     55        uint8_t n = 0;
     56       
    4757        if (arg >> 16) {
    4858                arg >>= 16;
     
    6575        }
    6676       
    67         if (arg >> 1) {
    68                 arg >>= 1;
     77        if (arg >> 1)
    6978                n += 1;
    70         }
    7179       
    7280        return n;
    7381}
    7482
    75 static inline int fnzb64(uint64_t arg)
     83/** Return position of first non-zero bit from left (64b variant).
     84 *
     85 * @return 0 (if the number is zero) or [log_2(arg)].
     86 *
     87 */
     88NO_TRACE static inline uint8_t fnzb64(uint64_t arg)
    7689{
    77         int n = 0;
    78 
     90        uint8_t n = 0;
     91       
    7992        if (arg >> 32) {
    8093                arg >>= 32;
     
    8598}
    8699
    87 #define fnzb(x) fnzb32(x)
    88 
    89100#endif
    90101
  • kernel/generic/include/byteorder.h

    rfb150d78 r46c20c8  
    3636#define KERN_BYTEORDER_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040#if !(defined(__BE__) ^ defined(__LE__))
  • kernel/generic/include/config.h

    rfb150d78 r46c20c8  
    3636#define KERN_CONFIG_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <arch/mm/page.h>
    4040
     
    6666
    6767typedef struct {
    68         size_t cpu_count;            /**< Number of processors detected. */
     68        unsigned int cpu_count;      /**< Number of processors detected. */
    6969        volatile size_t cpu_active;  /**< Number of processors that are up and running. */
    7070       
    7171        uintptr_t base;
    72         size_t kernel_size;           /**< Size of memory in bytes taken by kernel and stack */
     72        size_t kernel_size;          /**< Size of memory in bytes taken by kernel and stack */
    7373       
    74         uintptr_t stack_base;         /**< Base adddress of initial stack */
    75         size_t stack_size;            /**< Size of initial stack */
     74        uintptr_t stack_base;        /**< Base adddress of initial stack */
     75        size_t stack_size;           /**< Size of initial stack */
    7676} config_t;
    7777
  • kernel/generic/include/console/chardev.h

    rfb150d78 r46c20c8  
    3737
    3838#include <adt/list.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040#include <synch/waitq.h>
    4141#include <synch/spinlock.h>
     
    5353/** Character input device. */
    5454typedef struct indev {
    55         char *name;
     55        const char *name;
    5656        waitq_t wq;
    5757       
    5858        /** Protects everything below. */
    59         SPINLOCK_DECLARE(lock);
     59        IRQ_SPINLOCK_DECLARE(lock);
    6060        wchar_t buffer[INDEV_BUFLEN];
    6161        size_t counter;
     
    8181/** Character output device. */
    8282typedef struct outdev {
    83         char *name;
     83        const char *name;
    8484       
    8585        /** Protects everything below. */
     
    9595} outdev_t;
    9696
    97 extern void indev_initialize(char *name, indev_t *indev,
    98     indev_operations_t *op);
    99 extern void indev_push_character(indev_t *indev, wchar_t ch);
    100 extern wchar_t indev_pop_character(indev_t *indev);
     97extern void indev_initialize(const char *, indev_t *,
     98    indev_operations_t *);
     99extern void indev_push_character(indev_t *, wchar_t);
     100extern wchar_t indev_pop_character(indev_t *);
    101101
    102 extern void outdev_initialize(char *name, outdev_t *outdev,
    103     outdev_operations_t *op);
     102extern void outdev_initialize(const char *, outdev_t *,
     103    outdev_operations_t *);
    104104
    105 extern bool check_poll(indev_t *indev);
     105extern bool check_poll(indev_t *);
    106106
    107107#endif /* KERN_CHARDEV_H_ */
  • kernel/generic/include/console/console.h

    rfb150d78 r46c20c8  
    3636#define KERN_CONSOLE_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
     39#include <print.h>
    3940#include <console/chardev.h>
     41
     42#define PAGING(counter, increment, before, after) \
     43        do { \
     44                (counter) += (increment); \
     45                if ((counter) > 23) { \
     46                        before; \
     47                        printf(" -- Press any key to continue -- "); \
     48                        indev_pop_character(stdin); \
     49                        after; \
     50                        printf("\n"); \
     51                        (counter) = 0; \
     52                } \
     53        } while (0)
    4054
    4155extern indev_t *stdin;
    4256extern outdev_t *stdout;
    43 extern bool silent;
     57
     58extern void early_putchar(wchar_t);
    4459
    4560extern indev_t *stdin_wire(void);
  • kernel/generic/include/console/kconsole.h

    rfb150d78 r46c20c8  
    4747        ARG_TYPE_INT,
    4848        ARG_TYPE_STRING,
     49        /** Optional string */
     50        ARG_TYPE_STRING_OPTIONAL,
    4951        /** Variable type - either symbol or string. */
    5052        ARG_TYPE_VAR
     
    9496extern void kconsole_notify_init(void);
    9597extern bool kconsole_check_poll(void);
    96 extern void kconsole(char *prompt, char *msg, bool kcon);
     98extern void kconsole(const char *prompt, const char *msg, bool kcon);
    9799extern void kconsole_thread(void *data);
    98100
  • kernel/generic/include/context.h

    rfb150d78 r46c20c8  
    3636#define KERN_CONTEXT_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
     39#include <trace.h>
    3940#include <arch/context.h>
    4041
     
    8788 *
    8889 * @param ctx Context structure.
     90 *
    8991 */
    90 static inline void context_restore(context_t *ctx)
     92NO_TRACE static inline void context_restore(context_t *ctx)
    9193{
    9294        context_restore_arch(ctx);
  • kernel/generic/include/cpu.h

    rfb150d78 r46c20c8  
    4242#include <arch/context.h>
    4343
    44 #define CPU_STACK_SIZE  STACK_SIZE
     44#define CPU_STACK_SIZE  STACK_SIZE
    4545
    4646/** CPU structure.
     
    4848 * There is one structure like this for every processor.
    4949 */
    50 typedef struct {
    51         SPINLOCK_DECLARE(lock);
    52 
     50typedef struct cpu {
     51        IRQ_SPINLOCK_DECLARE(lock);
     52       
    5353        tlb_shootdown_msg_t tlb_messages[TLB_MESSAGE_QUEUE_LEN];
    5454        size_t tlb_messages_count;
    5555       
    5656        context_t saved_context;
    57 
     57       
    5858        atomic_t nrdy;
    5959        runq_t rq[RQ_COUNT];
    6060        volatile size_t needs_relink;
    61 
    62         SPINLOCK_DECLARE(timeoutlock);
     61       
     62        IRQ_SPINLOCK_DECLARE(timeoutlock);
    6363        link_t timeout_active_head;
    64 
    65         size_t missed_clock_ticks;      /**< When system clock loses a tick, it is recorded here
    66                                              so that clock() can react. This variable is
    67                                              CPU-local and can be only accessed when interrupts
    68                                              are disabled. */
    69 
     64       
     65        /**
     66         * When system clock loses a tick, it is
     67         * recorded here so that clock() can react.
     68         * This variable is CPU-local and can be
     69         * only accessed when interrupts are
     70         * disabled.
     71         */
     72        size_t missed_clock_ticks;
     73       
     74        /**
     75         * Processor cycle accounting.
     76         */
     77        bool idle;
     78        uint64_t last_cycle;
     79        uint64_t idle_cycles;
     80        uint64_t busy_cycles;
     81       
    7082        /**
    7183         * Processor ID assigned by kernel.
     
    7385        unsigned int id;
    7486       
    75         int active;
    76         int tlb_active;
    77 
     87        bool active;
     88        bool tlb_active;
     89       
    7890        uint16_t frequency_mhz;
    7991        uint32_t delay_loop_const;
    80 
     92       
    8193        cpu_arch_t arch;
    82 
     94       
    8395        struct thread *fpu_owner;
    8496       
     
    96108extern void cpu_arch_init(void);
    97109extern void cpu_identify(void);
    98 extern void cpu_print_report(cpu_t *m);
     110extern void cpu_print_report(cpu_t *);
    99111
    100112#endif
  • kernel/generic/include/ddi/ddi.h

    rfb150d78 r46c20c8  
    3737
    3838#include <ddi/ddi_arg.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040#include <proc/task.h>
    4141#include <adt/list.h>
     
    5050
    5151extern void ddi_init(void);
    52 extern void ddi_parea_register(parea_t *parea);
     52extern void ddi_parea_register(parea_t *);
    5353
    54 extern unative_t sys_physmem_map(unative_t phys_base, unative_t virt_base,
    55         unative_t pages, unative_t flags);
    56 extern unative_t sys_iospace_enable(ddi_ioarg_t *uspace_io_arg);
    57 extern unative_t sys_preempt_control(int enable);
     54extern unative_t sys_physmem_map(unative_t, unative_t, unative_t, unative_t);
     55extern unative_t sys_iospace_enable(ddi_ioarg_t *);
     56extern unative_t sys_interrupt_enable(int irq, int enable);
    5857
    5958/*
    6059 * Interface to be implemented by all architectures.
    6160 */
    62 extern int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size);
     61extern int ddi_iospace_enable_arch(task_t *, uintptr_t, size_t);
     62
    6363
    6464#endif
  • kernel/generic/include/ddi/ddi_arg.h

    rfb150d78 r46c20c8  
    3636#define KERN_DDI_ARG_H_
    3737
     38#ifdef KERNEL
     39
     40#include <typedefs.h>
     41
     42#endif /* KERNEL */
     43
    3844/** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
    3945typedef struct {
    4046        /** ID of the destination task. */
    41         unsigned long long task_id;
     47        uint64_t task_id;
    4248        /** Physical address of starting frame. */
    4349        void *phys_base;
     
    4551        void *virt_base;
    4652        /** Number of pages to map. */
    47         unsigned long pages;
     53        size_t pages;
    4854        /** Address space area flags for the mapping. */
    49         int flags;
     55        unsigned int flags;
    5056} ddi_memarg_t;
    5157
    5258/** Structure encapsulating arguments for SYS_ENABLE_IOSPACE syscall. */
    5359typedef struct {
    54         unsigned long long task_id;     /**< ID of the destination task. */
    55         void *ioaddr;                   /**< Starting I/O space address. */
    56         unsigned long size;             /**< Number of bytes. */
     60        uint64_t task_id;  /**< ID of the destination task. */
     61        void *ioaddr;      /**< Starting I/O space address. */
     62        size_t size;       /**< Number of bytes. */
    5763} ddi_ioarg_t;
    5864
  • kernel/generic/include/ddi/device.h

    rfb150d78 r46c20c8  
    3636#define KERN_DEVICE_H_
    3737
    38 #include <arch/types.h>
    3938#include <typedefs.h>
    4039
  • kernel/generic/include/ddi/irq.h

    rfb150d78 r46c20c8  
    3535#ifndef KERN_IRQ_H_
    3636#define KERN_IRQ_H_
     37
     38#ifdef KERNEL
     39
     40#include <typedefs.h>
     41#include <adt/list.h>
     42#include <adt/hash_table.h>
     43#include <synch/spinlock.h>
     44#include <proc/task.h>
     45#include <ipc/ipc.h>
     46
     47#endif /* KERNEL */
    3748
    3849typedef enum {
     
    4960        /** Write 4 bytes to the I/O space. */
    5061        CMD_PIO_WRITE_32,
     62       
    5163        /**
    5264         * Perform a bit test on the source argument and store the result into
     
    5466         */
    5567        CMD_BTEST,
     68       
    5669        /**
    5770         * Predicate the execution of the following N commands by the boolean
     
    5972         */
    6073        CMD_PREDICATE,
     74       
    6175        /** Accept the interrupt. */
    6276        CMD_ACCEPT,
     
    6983        irq_cmd_type cmd;
    7084        void *addr;
    71         unsigned long long value;
    72         unsigned int srcarg;
    73         unsigned int dstarg;
     85        uint32_t value;
     86        uintptr_t srcarg;
     87        uintptr_t dstarg;
    7488} irq_cmd_t;
    7589
    7690typedef struct {
    77         unsigned int cmdcount;
     91        size_t cmdcount;
    7892        irq_cmd_t *cmds;
    7993} irq_code_t;
     
    8195#ifdef KERNEL
    8296
    83 #include <arch/types.h>
    84 #include <adt/list.h>
    85 #include <adt/hash_table.h>
    86 #include <synch/spinlock.h>
    87 #include <proc/task.h>
    88 #include <ipc/ipc.h>
    89 
    9097typedef enum {
    91         IRQ_DECLINE,            /**< Decline to service. */
    92         IRQ_ACCEPT              /**< Accept to service. */
     98        IRQ_DECLINE,  /**< Decline to service. */
     99        IRQ_ACCEPT    /**< Accept to service. */
    93100} irq_ownership_t;
    94101
     
    108115 * Primarily, this structure is encapsulated in the irq_t structure.
    109116 * It is protected by irq_t::lock.
     117 *
    110118 */
    111119typedef struct {
     
    117125        unative_t method;
    118126        /** Arguments that will be sent if the IRQ is claimed. */
    119         unative_t scratch[IPC_CALL_LEN];
     127        uint32_t scratch[IPC_CALL_LEN];
    120128        /** Top-half pseudocode. */
    121129        irq_code_t *code;
    122130        /** Counter. */
    123131        size_t counter;
     132       
    124133        /**
    125134         * Link between IRQs that are notifying the same answerbox. The list is
     
    133142 * If one device has multiple interrupts, there will be multiple irq_t
    134143 * instantions with the same devno.
     144 *
    135145 */
    136146typedef struct irq {
    137147        /** Hash table link. */
    138148        link_t link;
    139 
     149       
    140150        /** Lock protecting everything in this structure
    141151         *  except the link member. When both the IRQ
     
    143153         *  this lock must not be taken first.
    144154         */
    145         SPINLOCK_DECLARE(lock);
     155        IRQ_SPINLOCK_DECLARE(lock);
    146156       
    147157        /** Send EOI before processing the interrupt.
     
    152162         */
    153163        bool preack;
    154 
     164       
    155165        /** Unique device number. -1 if not yet assigned. */
    156166        devno_t devno;
    157 
     167       
    158168        /** Actual IRQ number. -1 if not yet assigned. */
    159169        inr_t inr;
     
    166176        /** Instance argument for the handler and the claim function. */
    167177        void *instance;
    168 
     178       
    169179        /** Clear interrupt routine. */
    170180        cir_t cir;
    171181        /** First argument to the clear interrupt routine. */
    172182        void *cir_arg;
    173 
     183       
    174184        /** Notification configuration structure. */
    175185        ipc_notif_cfg_t notif_cfg;
    176186} irq_t;
    177187
    178 SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
     188IRQ_SPINLOCK_EXTERN(irq_uspace_hash_table_lock);
    179189extern hash_table_t irq_uspace_hash_table;
    180190
     
    184194extern irq_t *irq_dispatch_and_lock(inr_t);
    185195
     196#endif /* KERNEL */
     197
    186198#endif
    187199
    188 #endif
    189 
    190200/** @}
    191201 */
  • kernel/generic/include/debug.h

    rfb150d78 r46c20c8  
    3737
    3838#include <panic.h>
    39 #include <arch/debug.h>
     39#include <symtab.h>
    4040
    41 #define CALLER ((uintptr_t) __builtin_return_address(0))
     41#define CALLER  ((uintptr_t) __builtin_return_address(0))
    4242
    43 #ifndef HERE
    44 /** Current Instruction Pointer address */
    45 #       define HERE ((uintptr_t *) 0)
    46 #endif
     43#ifdef CONFIG_DEBUG
    4744
    4845/** Debugging ASSERT macro
     
    5552 *
    5653 */
    57 #ifdef CONFIG_DEBUG
    58 #       define ASSERT(expr) \
    59                 if (!(expr)) { \
    60                         panic("Assertion failed (%s), caller=%p.", #expr, CALLER); \
    61                 }
    62 #else
    63 #       define ASSERT(expr)
    64 #endif
     54#define ASSERT(expr) \
     55        do { \
     56                if (!(expr)) \
     57                        panic_assert("%s", #expr); \
     58        } while (0)
     59
     60/** Debugging verbose ASSERT macro
     61 *
     62 * If CONFIG_DEBUG is set, the ASSERT() macro
     63 * evaluates expr and if it is false raises
     64 * kernel panic. The panic message contains also
     65 * the supplied message.
     66 *
     67 * @param expr Expression which is expected to be true.
     68 * @param msg  Additional message to show (string).
     69 *
     70 */
     71#define ASSERT_VERBOSE(expr, msg) \
     72        do { \
     73                if (!(expr)) \
     74                        panic_assert("%s, %s", #expr, msg); \
     75        } while (0)
     76
     77#else /* CONFIG_DEBUG */
     78
     79#define ASSERT(expr)
     80#define ASSERT_VERBOSE(expr, msg)
     81
     82#endif /* CONFIG_DEBUG */
     83
     84#ifdef CONFIG_LOG
    6585
    6686/** Extensive logging output macro
     
    7191 *
    7292 */
     93#define LOG(format, ...) \
     94        do { \
     95                printf("%s() from %s at %s:%u: " format "\n", __func__, \
     96                    symtab_fmt_name_lookup(CALLER), __FILE__, __LINE__, \
     97                    ##__VA_ARGS__); \
     98        } while (0)
    7399
    74 #ifdef CONFIG_LOG
    75 #       define LOG(format, ...) \
    76                 printf("%s() at %s:%u: " format "\n", __func__, __FILE__, \
    77                     __LINE__, ##__VA_ARGS__);
    78 #else
    79 #       define LOG(format, ...)
    80 #endif
     100#else /* CONFIG_LOG */
    81101
    82 /** Extensive logging execute macro
    83  *
    84  * If CONFIG_LOG is set, the LOG_EXEC() macro
    85  * will print an information about calling a given
    86  * function and call it.
    87  *
    88  */
     102#define LOG(format, ...)
    89103
    90 #ifdef CONFIG_LOG
    91 #       define LOG_EXEC(fnc) \
    92                 { \
    93                         printf("%s() at %s:%u: " #fnc "\n", __func__, __FILE__, \
    94                             __LINE__); \
    95                         fnc; \
    96                 }
    97 #else
    98 #       define LOG_EXEC(fnc) fnc
    99 #endif
     104#endif /* CONFIG_LOG */
    100105
     106#ifdef CONFIG_TRACE
     107
     108extern void __cyg_profile_func_enter(void *, void *);
     109extern void __cyg_profile_func_exit(void *, void *);
     110
     111#endif /* CONFIG_TRACE */
    101112
    102113#endif
  • kernel/generic/include/func.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_FUNC_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <atomic.h>
    4040
     
    4242
    4343extern void halt(void) __attribute__((noreturn));
    44 extern unative_t atoi(const char *text);
    45 extern void order(const uint64_t val, uint64_t *rv, char *suffix);
    4644
    4745#endif
  • kernel/generic/include/interrupt.h

    rfb150d78 r46c20c8  
    3737
    3838#include <arch/interrupt.h>
    39 #include <arch/types.h>
     39#include <print.h>
     40#include <typedefs.h>
    4041#include <proc/task.h>
    4142#include <proc/thread.h>
     
    4445#include <stacktrace.h>
    4546
    46 typedef void (* iroutine)(int n, istate_t *istate);
     47typedef void (* iroutine_t)(unsigned int, istate_t *);
    4748
    48 extern void fault_if_from_uspace(istate_t *istate, char *fmt, ...);
    49 extern iroutine exc_register(int n, const char *name, iroutine f);
    50 extern void exc_dispatch(int n, istate_t *t);
    51 void exc_init(void);
     49typedef struct {
     50        const char *name;
     51        bool hot;
     52        iroutine_t handler;
     53        uint64_t cycles;
     54        uint64_t count;
     55} exc_table_t;
    5256
    53 extern void irq_initialize_arch(irq_t *irq);
     57IRQ_SPINLOCK_EXTERN(exctbl_lock);
     58extern exc_table_t exc_table[];
     59
     60extern void fault_if_from_uspace(istate_t *, const char *, ...)
     61    PRINTF_ATTRIBUTE(2, 3);
     62extern iroutine_t exc_register(unsigned int, const char *, bool, iroutine_t);
     63extern void exc_dispatch(unsigned int, istate_t *);
     64extern void exc_init(void);
     65
     66extern void irq_initialize_arch(irq_t *);
     67
     68extern void istate_decode(istate_t *);
    5469
    5570#endif
  • kernel/generic/include/ipc/event.h

    rfb150d78 r46c20c8  
    3737
    3838#include <ipc/event_types.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040#include <synch/spinlock.h>
    4141#include <ipc/ipc.h>
  • kernel/generic/include/ipc/ipc.h

    rfb150d78 r46c20c8  
    3636#define KERN_IPC_H_
    3737
    38 /* Length of data being transfered with IPC call */
    39 /* - the uspace may not be able to utilize full length */
    40 #define IPC_CALL_LEN            6       
     38/** Length of data being transfered with IPC call
     39 *
     40 * The uspace may not be able to utilize full length
     41 *
     42 */
     43#define IPC_CALL_LEN  6
    4144
    4245/** Maximum active async calls per thread */
    4346#ifdef CONFIG_DEBUG
    44 #define IPC_MAX_ASYNC_CALLS     4
     47        #define IPC_MAX_ASYNC_CALLS  4
    4548#else
    46 #define IPC_MAX_ASYNC_CALLS     4000
     49        #define IPC_MAX_ASYNC_CALLS  4000
    4750#endif
    4851
     
    5053
    5154/** This is answer to a call */
    52 #define IPC_CALL_ANSWERED       (1 << 0)
     55#define IPC_CALL_ANSWERED  (1 << 0)
     56
    5357/** Answer will not be passed to userspace, will be discarded */
    54 #define IPC_CALL_DISCARD_ANSWER (1 << 1)
     58#define IPC_CALL_DISCARD_ANSWER  (1 << 1)
     59
    5560/** Call was forwarded */
    56 #define IPC_CALL_FORWARDED      (1 << 2)
     61#define IPC_CALL_FORWARDED  (1 << 2)
     62
    5763/** Identify connect_me_to answer */
    58 #define IPC_CALL_CONN_ME_TO     (1 << 3)
     64#define IPC_CALL_CONN_ME_TO  (1 << 3)
     65
    5966/** Interrupt notification */
    60 #define IPC_CALL_NOTIF          (1 << 4)
    61 
    62 /*
    63  * Bits used in call hashes.
     67#define IPC_CALL_NOTIF  (1 << 4)
     68
     69
     70/** Bits used in call hashes.
     71 *
    6472 * The addresses are aligned at least to 4 that is why we can use the 2 least
    6573 * significant bits of the call address.
    66  */
     74 *
     75 */
     76
    6777/** Type of this call is 'answer' */
    68 #define IPC_CALLID_ANSWERED     1
     78#define IPC_CALLID_ANSWERED  1
     79
    6980/** Type of this call is 'notification' */
    70 #define IPC_CALLID_NOTIFICATION 2
     81#define IPC_CALLID_NOTIFICATION  2
    7182
    7283/* Return values from sys_ipc_call_async(). */
    73 #define IPC_CALLRET_FATAL       -1
    74 #define IPC_CALLRET_TEMPORARY   -2
     84#define IPC_CALLRET_FATAL      -1
     85#define IPC_CALLRET_TEMPORARY  -2
    7586
    7687
    7788/* Macros for manipulating calling data */
    78 #define IPC_SET_RETVAL(data, retval)    ((data).args[0] = (retval))
    79 #define IPC_SET_METHOD(data, val)       ((data).args[0] = (val))
    80 #define IPC_SET_ARG1(data, val)         ((data).args[1] = (val))
    81 #define IPC_SET_ARG2(data, val)         ((data).args[2] = (val))
    82 #define IPC_SET_ARG3(data, val)         ((data).args[3] = (val))
    83 #define IPC_SET_ARG4(data, val)         ((data).args[4] = (val))
    84 #define IPC_SET_ARG5(data, val)         ((data).args[5] = (val))
    85 
    86 #define IPC_GET_METHOD(data)            ((data).args[0])
    87 #define IPC_GET_RETVAL(data)            ((data).args[0])
    88 
    89 #define IPC_GET_ARG1(data)              ((data).args[1])
    90 #define IPC_GET_ARG2(data)              ((data).args[2])
    91 #define IPC_GET_ARG3(data)              ((data).args[3])
    92 #define IPC_GET_ARG4(data)              ((data).args[4])
    93 #define IPC_GET_ARG5(data)              ((data).args[5])
     89#define IPC_SET_RETVAL(data, retval)  ((data).args[0] = (retval))
     90#define IPC_SET_METHOD(data, val)     ((data).args[0] = (val))
     91#define IPC_SET_ARG1(data, val)       ((data).args[1] = (val))
     92#define IPC_SET_ARG2(data, val)       ((data).args[2] = (val))
     93#define IPC_SET_ARG3(data, val)       ((data).args[3] = (val))
     94#define IPC_SET_ARG4(data, val)       ((data).args[4] = (val))
     95#define IPC_SET_ARG5(data, val)       ((data).args[5] = (val))
     96
     97#define IPC_GET_METHOD(data)  ((data).args[0])
     98#define IPC_GET_RETVAL(data)  ((data).args[0])
     99
     100#define IPC_GET_ARG1(data)  ((data).args[1])
     101#define IPC_GET_ARG2(data)  ((data).args[2])
     102#define IPC_GET_ARG3(data)  ((data).args[3])
     103#define IPC_GET_ARG4(data)  ((data).args[4])
     104#define IPC_GET_ARG5(data)  ((data).args[5])
    94105
    95106/* Well known phone descriptors */
    96 #define PHONE_NS        0
     107#define PHONE_NS  0
    97108
    98109/* Forwarding flags. */
    99 #define IPC_FF_NONE             0
     110#define IPC_FF_NONE  0
     111
    100112/**
    101113 * The call will be routed as though it was initially sent via the phone used to
     
    104116 * calls that were initially sent by the forwarder to the same destination. This
    105117 * flag has no imapct on routing replies.
    106  */
    107 #define IPC_FF_ROUTE_FROM_ME    (1 << 0)
    108 
    109 /* System-specific methods - only through special syscalls
     118 *
     119 */
     120#define IPC_FF_ROUTE_FROM_ME  (1 << 0)
     121
     122/** System-specific methods - only through special syscalls
    110123 * These methods have special behaviour
    111  */
     124 *
     125 */
     126
    112127/** Clone connection.
    113128 *
     
    115130 *
    116131 * - ARG1 - The caller sets ARG1 to the phone of the cloned connection.
    117  *        - The callee gets the new phone from ARG1.
     132 *        - The callee gets the new phone from ARG1.
     133 *
    118134 * - on answer, the callee acknowledges the new connection by sending EOK back
    119135 *   or the kernel closes it
    120  */
    121 #define IPC_M_CONNECTION_CLONE  1
     136 *
     137 */
     138#define IPC_M_CONNECTION_CLONE  1
     139
    122140/** Protocol for CONNECT - ME
    123141 *
    124142 * Through this call, the recipient learns about the new cloned connection.
    125  * 
     143 *
    126144 * - ARG5 - the kernel sets ARG5 to contain the hash of the used phone
    127145 * - on asnwer, the callee acknowledges the new connection by sending EOK back
    128146 *   or the kernel closes it
    129  */
    130 #define IPC_M_CONNECT_ME        2
    131 /** Protocol for CONNECT - TO - ME
     147 *
     148 */
     149#define IPC_M_CONNECT_ME  2
     150
     151/** Protocol for CONNECT - TO - ME
    132152 *
    133153 * Calling process asks the callee to create a callback connection,
     
    144164 *                     - the allocated phoneid is passed to userspace
    145165 *                       (on the receiving side) as ARG5 of the call.
    146  */
    147 #define IPC_M_CONNECT_TO_ME     3       
     166 *
     167 */
     168#define IPC_M_CONNECT_TO_ME  3
     169
    148170/** Protocol for CONNECT - ME - TO
    149171 *
     
    163185 *
    164186 */
    165 #define IPC_M_CONNECT_ME_TO     4       
    166 /** This message is sent to answerbox when the phone
    167  * is hung up
    168  */
    169 #define IPC_M_PHONE_HUNGUP      5
     187#define IPC_M_CONNECT_ME_TO  4
     188
     189/** This message is sent to answerbox when the phone is hung up
     190 *
     191 */
     192#define IPC_M_PHONE_HUNGUP  5
    170193
    171194/** Send as_area over IPC.
     
    173196 * - ARG2 - size of source as_area (filled automatically by kernel)
    174197 * - ARG3 - flags of the as_area being sent
    175  * 
     198 *
    176199 * on answer, the recipient must set:
    177200 * - ARG1 - dst as_area base adress
    178  */
    179 #define IPC_M_SHARE_OUT         6       
     201 *
     202 */
     203#define IPC_M_SHARE_OUT  6
    180204
    181205/** Receive as_area over IPC.
     
    183207 * - ARG2 - destination as_area size
    184208 * - ARG3 - user defined argument
    185  * 
     209 *
    186210 * on answer, the recipient must set:
    187211 *
    188212 * - ARG1 - source as_area base address
    189213 * - ARG2 - flags that will be used for sharing
    190  */
    191 #define IPC_M_SHARE_IN          7       
     214 *
     215 */
     216#define IPC_M_SHARE_IN  7
    192217
    193218/** Send data to another address space over IPC.
     
    199224 * - ARG1 - final destination address space virtual address
    200225 * - ARG2 - final size of data to be copied
    201  */
    202 #define IPC_M_DATA_WRITE        8
     226 *
     227 */
     228#define IPC_M_DATA_WRITE  8
    203229
    204230/** Receive data from another address space over IPC.
     
    210236 * - ARG1 - source virtual address in the destination address space
    211237 * - ARG2 - final size of data to be copied
    212  */
    213 #define IPC_M_DATA_READ         9
     238 *
     239 */
     240#define IPC_M_DATA_READ  9
    214241
    215242/** Debug the recipient.
    216243 * - ARG1 - specifies the debug method (from udebug_method_t)
    217244 * - other arguments are specific to the debug method
    218  */
    219 #define IPC_M_DEBUG_ALL         10
     245 *
     246 */
     247#define IPC_M_DEBUG_ALL  10
    220248
    221249/* Well-known methods */
    222 #define IPC_M_LAST_SYSTEM       511
    223 #define IPC_M_PING              512
     250#define IPC_M_LAST_SYSTEM  511
     251#define IPC_M_PING         512
     252
    224253/* User methods */
    225 #define IPC_FIRST_USER_METHOD   1024
     254#define IPC_FIRST_USER_METHOD  1024
    226255
    227256#ifdef KERNEL
    228257
    229 #define IPC_MAX_PHONES  16
     258#define IPC_MAX_PHONES  32
    230259
    231260#include <synch/spinlock.h>
     
    259288
    260289typedef struct answerbox {
    261         SPINLOCK_DECLARE(lock);
    262 
     290        IRQ_SPINLOCK_DECLARE(lock);
     291       
    263292        struct task *task;
    264 
     293       
    265294        waitq_t wq;
    266 
     295       
    267296        /** Linkage for the list of task's synchronous answerboxes. */
    268297        link_t sync_box_link;
    269 
     298       
    270299        /** Phones connected to this answerbox. */
    271300        link_t connected_phones;
    272301        /** Received calls. */
    273         link_t calls;                   
    274         link_t dispatched_calls;        /* Should be hash table in the future */
    275 
     302        link_t calls;
     303        link_t dispatched_calls;  /* Should be hash table in the future */
     304       
    276305        /** Answered calls. */
    277306        link_t answers;
    278 
    279         SPINLOCK_DECLARE(irq_lock);
     307       
     308        IRQ_SPINLOCK_DECLARE(irq_lock);
     309       
    280310        /** Notifications from IRQ handlers. */
    281311        link_t irq_notifs;
     
    291321typedef struct {
    292322        link_t link;
    293 
    294         int flags;
    295 
     323       
     324        unsigned int flags;
     325       
    296326        /** Identification of the caller. */
    297327        struct task *sender;
    298         /** The caller box is different from sender->answerbox for synchronous
    299          *  calls. */
     328       
     329        /*
     330         * The caller box is different from sender->answerbox
     331         * for synchronous calls.
     332         *
     333         */
    300334        answerbox_t *callerbox;
    301 
     335       
    302336        /** Private data to internal IPC. */
    303337        unative_t priv;
    304 
     338       
    305339        /** Data passed from/to userspace. */
    306340        ipc_data_t data;
    307 
     341       
    308342        /** Buffer for IPC_M_DATA_WRITE and IPC_M_DATA_READ. */
    309343        uint8_t *buffer;
    310 
     344       
    311345        /*
    312346         * The forward operation can masquerade the caller phone. For those
    313347         * cases, we must keep it aside so that the answer is processed
    314348         * correctly.
     349         *
    315350         */
    316351        phone_t *caller_phone;
    317352} call_t;
    318353
    319 
    320354extern answerbox_t *ipc_phone_0;
    321355
    322 
    323356extern void ipc_init(void);
    324357
    325 extern call_t * ipc_call_alloc(int);
     358extern call_t *ipc_call_alloc(unsigned int);
    326359extern void ipc_call_free(call_t *);
    327360
    328361extern int ipc_call(phone_t *, call_t *);
    329362extern int ipc_call_sync(phone_t *, call_t *);
    330 extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, int);
    331 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, int);
     363extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
     364extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
    332365extern void ipc_answer(answerbox_t *, call_t *);
    333366
     
    345378extern void ipc_print_task(task_id_t);
    346379
     380#endif /* KERNEL */
     381
    347382#endif
    348383
    349 #endif
    350 
    351384/** @}
    352385 */
  • kernel/generic/include/ipc/irq.h

    rfb150d78 r46c20c8  
    3737
    3838/** Maximum length of IPC IRQ program */
    39 #define IRQ_MAX_PROG_SIZE       20
     39#define IRQ_MAX_PROG_SIZE  20
    4040
    4141#include <ipc/ipc.h>
    4242#include <ddi/irq.h>
    43 #include <arch/types.h>
     43#include <typedefs.h>
    4444#include <adt/list.h>
    4545
     
    5858 */
    5959#define ipc_irq_send_msg_0(irq) \
    60     ipc_irq_send_msg((irq), 0, 0, 0, 0, 0)
     60        ipc_irq_send_msg((irq), 0, 0, 0, 0, 0)
     61
    6162#define ipc_irq_send_msg_1(irq, a1) \
    62     ipc_irq_send_msg((irq), (a1), 0, 0, 0, 0)
     63        ipc_irq_send_msg((irq), (a1), 0, 0, 0, 0)
     64
    6365#define ipc_irq_send_msg_2(irq, a1, a2) \
    64     ipc_irq_send_msg((irq), (a1), (a2), 0, 0, 0)
     66        ipc_irq_send_msg((irq), (a1), (a2), 0, 0, 0)
     67
    6568#define ipc_irq_send_msg_3(irq, a1, a2, a3) \
    66     ipc_irq_send_msg((irq), (a1), (a2), (a3), 0, 0)
     69        ipc_irq_send_msg((irq), (a1), (a2), (a3), 0, 0)
     70
    6771#define ipc_irq_send_msg_4(irq, a1, a2, a3, a4) \
    68     ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), 0)
     72        ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), 0)
     73
    6974#define ipc_irq_send_msg_5(irq, a1, a2, a3, a4, a5) \
    70     ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), (a5))
     75        ipc_irq_send_msg((irq), (a1), (a2), (a3), (a4), (a5))
    7176
    7277extern void ipc_irq_send_msg(irq_t *, unative_t, unative_t, unative_t, unative_t,
  • kernel/generic/include/ipc/sysipc.h

    rfb150d78 r46c20c8  
    3838#include <ipc/ipc.h>
    3939#include <ipc/irq.h>
    40 #include <arch/types.h>
     40#include <typedefs.h>
    4141
    42 unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method,
     42extern unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method,
    4343    unative_t arg1, unative_t arg2, unative_t arg3, ipc_data_t *data);
    44 unative_t sys_ipc_call_sync_slow(unative_t phoneid, ipc_data_t *question,
     44extern unative_t sys_ipc_call_sync_slow(unative_t phoneid, ipc_data_t *question,
    4545    ipc_data_t *reply);
    46 unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method,
     46extern unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method,
    4747    unative_t arg1, unative_t arg2, unative_t arg3, unative_t arg4);
    48 unative_t sys_ipc_call_async_slow(unative_t phoneid, ipc_data_t *data);
    49 unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval,
     48extern unative_t sys_ipc_call_async_slow(unative_t phoneid, ipc_data_t *data);
     49extern unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval,
    5050    unative_t arg1, unative_t arg2, unative_t arg3, unative_t arg4);
    51 unative_t sys_ipc_answer_slow(unative_t callid, ipc_data_t *data);
    52 unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
    53     int nonblocking);
    54 unative_t sys_ipc_poke(void);
    55 unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
    56     unative_t method, unative_t arg1, unative_t arg2, int mode);
    57 unative_t sys_ipc_forward_slow(unative_t callid, unative_t phoneid,
    58     ipc_data_t *data, int mode);
    59 unative_t sys_ipc_hangup(int phoneid);
    60 unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
     51extern unative_t sys_ipc_answer_slow(unative_t callid, ipc_data_t *data);
     52extern unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
     53    unsigned int nonblocking);
     54extern unative_t sys_ipc_poke(void);
     55extern unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
     56    unative_t method, unative_t arg1, unative_t arg2, unsigned int mode);
     57extern unative_t sys_ipc_forward_slow(unative_t callid, unative_t phoneid,
     58    ipc_data_t *data, unsigned int mode);
     59extern unative_t sys_ipc_hangup(unative_t phoneid);
     60extern unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
    6161    irq_code_t *ucode);
    62 unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno);
    63 unative_t sys_ipc_connect_kbox(sysarg64_t *task_id);
     62extern unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno);
     63extern unative_t sys_ipc_connect_kbox(sysarg64_t *task_id);
    6464
    6565#endif
  • kernel/generic/include/lib/elf.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3737
    3838#include <arch/elf.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040
    4141/**
    4242 * current ELF version
    4343 */
    44 #define EV_CURRENT      1
    45 
    46 /** 
    47  * ELF types 
    48  */
    49 #define ET_NONE         0       /* No type */
    50 #define ET_REL          1       /* Relocatable file */
    51 #define ET_EXEC         2       /* Executable */
    52 #define ET_DYN          3       /* Shared object */
    53 #define ET_CORE         4       /* Core */
    54 #define ET_LOPROC       0xff00  /* Processor specific */
    55 #define ET_HIPROC       0xffff  /* Processor specific */
    56 
    57 /** 
     44#define EV_CURRENT  1
     45
     46/**
     47 * ELF types
     48 */
     49#define ET_NONE    0       /* No type */
     50#define ET_REL     1       /* Relocatable file */
     51#define ET_EXEC    2       /* Executable */
     52#define ET_DYN     3       /* Shared object */
     53#define ET_CORE    4       /* Core */
     54#define ET_LOPROC  0xff00  /* Processor specific */
     55#define ET_HIPROC  0xffff  /* Processor specific */
     56
     57/**
    5858 * ELF machine types
    5959 */
    60 #define EM_NO           0       /* No machine */
    61 #define EM_SPARC        2       /* SPARC */
    62 #define EM_386          3       /* i386 */
    63 #define EM_MIPS         8       /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10      /* MIPS RS3000 LE */
    65 #define EM_PPC          20      /* PPC32 */
    66 #define EM_PPC64        21      /* PPC64 */
    67 #define EM_ARM          40      /* ARM */
    68 #define EM_SPARCV9      43      /* SPARC64 */
    69 #define EM_IA_64        50      /* IA-64 */
    70 #define EM_X86_64       62      /* AMD64/EMT64 */
     60#define EM_NO           0   /* No machine */
     61#define EM_SPARC        2   /* SPARC */
     62#define EM_386          3   /* i386 */
     63#define EM_MIPS         8   /* MIPS RS3000 */
     64#define EM_MIPS_RS3_LE  10  /* MIPS RS3000 LE */
     65#define EM_PPC          20  /* PPC32 */
     66#define EM_PPC64        21  /* PPC64 */
     67#define EM_ARM          40  /* ARM */
     68#define EM_SPARCV9      43  /* SPARC64 */
     69#define EM_IA_64        50  /* IA-64 */
     70#define EM_X86_64       62  /* AMD64/EMT64 */
    7171
    7272/**
    7373 * ELF identification indexes
    7474 */
    75 #define EI_MAG0         0
    76 #define EI_MAG1         1
    77 #define EI_MAG2         2
    78 #define EI_MAG3         3
    79 #define EI_CLASS        4               /* File class */
    80 #define EI_DATA         5               /* Data encoding */
    81 #define EI_VERSION      6               /* File version */
    82 #define EI_OSABI        7
    83 #define EI_ABIVERSION   8
    84 #define EI_PAD          9               /* Start of padding bytes */
    85 #define EI_NIDENT       16              /* ELF identification table size */
     75#define EI_MAG0        0
     76#define EI_MAG1        1
     77#define EI_MAG2        2
     78#define EI_MAG3        3
     79#define EI_CLASS       4   /* File class */
     80#define EI_DATA        5   /* Data encoding */
     81#define EI_VERSION     6   /* File version */
     82#define EI_OSABI       7
     83#define EI_ABIVERSION  8
     84#define EI_PAD         9   /* Start of padding bytes */
     85#define EI_NIDENT      16  /* ELF identification table size */
    8686
    8787/**
    8888 * ELF magic number
    8989 */
    90 #define ELFMAG0         0x7f
    91 #define ELFMAG1         'E'
    92 #define ELFMAG2         'L'
    93 #define ELFMAG3         'F'
     90#define ELFMAG0  0x7f
     91#define ELFMAG1  'E'
     92#define ELFMAG2  'L'
     93#define ELFMAG3  'F'
    9494
    9595/**
    9696 * ELF file classes
    9797 */
    98 #define ELFCLASSNONE    0
    99 #define ELFCLASS32      1
    100 #define ELFCLASS64      2
     98#define ELFCLASSNONE  0
     99#define ELFCLASS32    1
     100#define ELFCLASS64    2
    101101
    102102/**
    103103 * ELF data encoding types
    104104 */
    105 #define ELFDATANONE     0
    106 #define ELFDATA2LSB     1               /* Least significant byte first (little endian) */
    107 #define ELFDATA2MSB     2               /* Most signigicant byte first (big endian) */
     105#define ELFDATANONE  0
     106#define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
     107#define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
    108108
    109109/**
    110110 * ELF error return codes
    111111 */
    112 #define EE_OK                   0       /* No error */
    113 #define EE_INVALID              1       /* Invalid ELF image */
    114 #define EE_MEMORY               2       /* Cannot allocate address space */
    115 #define EE_INCOMPATIBLE         3       /* ELF image is not compatible with current architecture */
    116 #define EE_UNSUPPORTED          4       /* Non-supported ELF (e.g. dynamic ELFs) */
    117 #define EE_LOADER               5       /* The image is actually a program loader */
    118 #define EE_IRRECOVERABLE        6
     112#define EE_OK             0  /* No error */
     113#define EE_INVALID        1  /* Invalid ELF image */
     114#define EE_MEMORY         2  /* Cannot allocate address space */
     115#define EE_INCOMPATIBLE   3  /* ELF image is not compatible with current architecture */
     116#define EE_UNSUPPORTED    4  /* Non-supported ELF (e.g. dynamic ELFs) */
     117#define EE_LOADER         5  /* The image is actually a program loader */
     118#define EE_IRRECOVERABLE  6
    119119
    120120/**
    121121 * ELF section types
    122122 */
    123 #define SHT_NULL                0
    124 #define SHT_PROGBITS            1
    125 #define SHT_SYMTAB              2
    126 #define SHT_STRTAB              3
    127 #define SHT_RELA                4
    128 #define SHT_HASH                5
    129 #define SHT_DYNAMIC             6
    130 #define SHT_NOTE                7
    131 #define SHT_NOBITS              8
    132 #define SHT_REL                 9
    133 #define SHT_SHLIB               10
    134 #define SHT_DYNSYM              11
    135 #define SHT_LOOS                0x60000000
    136 #define SHT_HIOS                0x6fffffff
    137 #define SHT_LOPROC              0x70000000
    138 #define SHT_HIPROC              0x7fffffff
    139 #define SHT_LOUSER              0x80000000
    140 #define SHT_HIUSER              0xffffffff
     123#define SHT_NULL      0
     124#define SHT_PROGBITS  1
     125#define SHT_SYMTAB    2
     126#define SHT_STRTAB    3
     127#define SHT_RELA      4
     128#define SHT_HASH      5
     129#define SHT_DYNAMIC   6
     130#define SHT_NOTE      7
     131#define SHT_NOBITS    8
     132#define SHT_REL       9
     133#define SHT_SHLIB     10
     134#define SHT_DYNSYM    11
     135#define SHT_LOOS      0x60000000
     136#define SHT_HIOS      0x6fffffff
     137#define SHT_LOPROC    0x70000000
     138#define SHT_HIPROC    0x7fffffff
     139#define SHT_LOUSER    0x80000000
     140#define SHT_HIUSER    0xffffffff
    141141
    142142/**
    143143 * ELF section flags
    144144 */
    145 #define SHF_WRITE               0x1
    146 #define SHF_ALLOC               0x2
    147 #define SHF_EXECINSTR           0x4
    148 #define SHF_TLS                 0x400
    149 #define SHF_MASKPROC            0xf0000000
     145#define SHF_WRITE      0x1
     146#define SHF_ALLOC      0x2
     147#define SHF_EXECINSTR  0x4
     148#define SHF_TLS        0x400
     149#define SHF_MASKPROC   0xf0000000
    150150
    151151/**
    152152 * Symbol binding
    153153 */
    154 #define STB_LOCAL               0
    155 #define STB_GLOBAL              1
    156 #define STB_WEAK                2
    157 #define STB_LOPROC              13
    158 #define STB_HIPROC              15
     154#define STB_LOCAL   0
     155#define STB_GLOBAL  1
     156#define STB_WEAK    2
     157#define STB_LOPROC  13
     158#define STB_HIPROC  15
    159159
    160160/**
    161161 * Symbol types
    162162 */
    163 #define STT_NOTYPE              0
    164 #define STT_OBJECT              1
    165 #define STT_FUNC                2
    166 #define STT_SECTION             3
    167 #define STT_FILE                4
    168 #define STT_LOPROC              13
    169 #define STT_HIPROC              15
     163#define STT_NOTYPE   0
     164#define STT_OBJECT   1
     165#define STT_FUNC     2
     166#define STT_SECTION  3
     167#define STT_FILE     4
     168#define STT_LOPROC   13
     169#define STT_HIPROC   15
    170170
    171171/**
    172172 * Program segment types
    173173 */
    174 #define PT_NULL                 0
    175 #define PT_LOAD                 1
    176 #define PT_DYNAMIC              2
    177 #define PT_INTERP               3
    178 #define PT_NOTE                 4
    179 #define PT_SHLIB                5
    180 #define PT_PHDR                 6
    181 #define PT_LOPROC               0x70000000
    182 #define PT_HIPROC               0x7fffffff
     174#define PT_NULL     0
     175#define PT_LOAD     1
     176#define PT_DYNAMIC  2
     177#define PT_INTERP   3
     178#define PT_NOTE     4
     179#define PT_SHLIB    5
     180#define PT_PHDR     6
     181#define PT_LOPROC   0x70000000
     182#define PT_HIPROC   0x7fffffff
    183183
    184184/**
    185185 * Program segment attributes.
    186186 */
    187 #define PF_X    1
    188 #define PF_W    2
    189 #define PF_R    4
     187#define PF_X  1
     188#define PF_W  2
     189#define PF_R  4
    190190
    191191/**
     
    195195 * ELF object file specifications. They are the only types used
    196196 * in ELF header.
     197 *
    197198 */
    198199typedef uint64_t elf_xword;
     
    206207 *
    207208 * These types are specific for 32-bit format.
     209 *
    208210 */
    209211typedef uint32_t elf32_addr;
     
    214216 *
    215217 * These types are specific for 64-bit format.
     218 *
    216219 */
    217220typedef uint64_t elf64_addr;
     
    235238        elf_half e_shstrndx;
    236239};
     240
    237241struct elf64_header {
    238242        uint8_t e_ident[EI_NIDENT];
     
    252256};
    253257
    254 /*
     258/**
    255259 * ELF segment header.
    256260 * Segments headers are also known as program headers.
     
    266270        elf_word p_align;
    267271};
     272
    268273struct elf64_segment_header {
    269274        elf_word p_type;
     
    277282};
    278283
    279 /*
     284/**
    280285 * ELF section header
    281286 */
     
    292297        elf_word sh_entsize;
    293298};
     299
    294300struct elf64_section_header {
    295301        elf_word sh_name;
     
    305311};
    306312
    307 /*
     313/**
    308314 * ELF symbol table entry
    309315 */
     
    316322        elf_half st_shndx;
    317323};
     324
    318325struct elf64_symbol {
    319326        elf_word st_name;
     
    325332};
    326333
    327 #ifdef __32_BITS__ 
     334#ifdef __32_BITS__
    328335typedef struct elf32_header elf_header_t;
    329336typedef struct elf32_segment_header elf_segment_header_t;
     
    331338typedef struct elf32_symbol elf_symbol_t;
    332339#endif
     340
    333341#ifdef __64_BITS__
    334342typedef struct elf64_header elf_header_t;
     
    338346#endif
    339347
    340 extern char *elf_error(unsigned int rc);
    341 
    342 /* Interpreter string used to recognize the program loader */
    343 #define ELF_INTERP_ZSTR "kernel"
     348extern const char *elf_error(unsigned int rc);
     349
     350/** Interpreter string used to recognize the program loader */
     351#define ELF_INTERP_ZSTR  "kernel"
    344352#define ELF_INTERP_ZLEN  sizeof(ELF_INTERP_ZSTR)
    345353
  • kernel/generic/include/lib/rd.h

    rfb150d78 r46c20c8  
    3636#define KERN_RD_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040/**
    4141 * RAM disk version
    4242 */
    43 #define RD_VERSION      1
     43#define RD_VERSION      1
    4444
    4545/**
  • kernel/generic/include/macros.h

    rfb150d78 r46c20c8  
    3838#ifndef __ASM__
    3939
    40 #include <arch/types.h>
     40#include <typedefs.h>
     41#include <trace.h>
    4142
    4243/** Return true if the intervals overlap.
     
    4647 * @param s2  Start address of the second interval.
    4748 * @param sz2 Size of the second interval.
     49 *
    4850 */
    49 static inline int overlaps(uintptr_t s1, size_t sz1, uintptr_t s2, size_t sz2)
     51NO_TRACE static inline int overlaps(uint64_t s1, uint64_t sz1, uint64_t s2,
     52    uint64_t sz2)
    5053{
    51         uintptr_t e1 = s1 + sz1;
    52         uintptr_t e2 = s2 + sz2;
     54        uint64_t e1 = s1 + sz1;
     55        uint64_t e2 = s2 + sz2;
    5356       
    5457        return ((s1 < e2) && (s2 < e1));
     58}
     59
     60/** Return true if the second interval is within the first interval.
     61 *
     62 * @param s1  Start address of the first interval.
     63 * @param sz1 Size of the first interval.
     64 * @param s2  Start address of the second interval.
     65 * @param sz2 Size of the second interval.
     66 *
     67 */
     68NO_TRACE static inline int iswithin(uint64_t s1, uint64_t sz1, uint64_t s2,
     69    uint64_t sz2)
     70{
     71        uint64_t e1 = s1 + sz1;
     72        uint64_t e2 = s2 + sz2;
     73       
     74        return ((s1 <= s2) && (e1 >= e2));
    5575}
    5676
     
    7292
    7393/* Compute overlapping of physical addresses */
    74 #define PA_overlaps(x, szx, y, szy) \
     94#define PA_OVERLAPS(x, szx, y, szy) \
    7595        overlaps(KA2PA((x)), (szx), KA2PA((y)), (szy))
    7696
     
    84104#define STRING_ARG(arg)  #arg
    85105
    86 #define LOWER32(arg)  ((arg) & 0xffffffff)
    87 #define UPPER32(arg)  (((arg) >> 32) & 0xffffffff)
     106#define LOWER32(arg)  (((uint64_t) (arg)) & UINT32_C(0xffffffff))
     107#define UPPER32(arg)  (((((uint64_t) arg)) >> 32) & UINT32_C(0xffffffff))
    88108
    89109#define MERGE_LOUP32(lo, up) \
    90         ((((uint64_t) (lo)) & 0xffffffff) \
    91             | ((((uint64_t) (up)) & 0xffffffff) << 32))
     110        ((((uint64_t) (lo)) & UINT32_C(0xffffffff)) \
     111            | ((((uint64_t) (up)) & UINT32_C(0xffffffff)) << 32))
    92112
    93113/** Pseudorandom generator
  • kernel/generic/include/main/main.h

    rfb150d78 r46c20c8  
    3232/** @file
    3333 */
    34  
     34
    3535#ifndef KERN_MAIN_H_
    3636#define KERN_MAIN_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040extern size_t hardcoded_kdata_size;
  • kernel/generic/include/main/uinit.h

    rfb150d78 r46c20c8  
    3636#define KERN_UINIT_H_
    3737
    38 #include <arch/types.h>
    39 
    4038extern void uinit(void *arg);
    4139
  • kernel/generic/include/main/version.h

    rfb150d78 r46c20c8  
    4242/** @}
    4343 */
    44 
  • kernel/generic/include/memstr.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_MEMSTR_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <arch/memstr.h>
    4040
  • kernel/generic/include/mm/as.h

    rfb150d78 r46c20c8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3737
    3838#ifdef KERNEL
    39 #include <arch/types.h>
     39        #include <typedefs.h>
    4040#else
    41 #include <sys/types.h>
     41        #include <sys/types.h>
    4242#endif
    4343
    4444/** Address space area flags. */
    45 #define AS_AREA_READ            1
    46 #define AS_AREA_WRITE           2
    47 #define AS_AREA_EXEC            4
    48 #define AS_AREA_CACHEABLE       8
     45#define AS_AREA_READ       1
     46#define AS_AREA_WRITE      2
     47#define AS_AREA_EXEC       4
     48#define AS_AREA_CACHEABLE  8
    4949
    5050/** Address space area info exported to userspace. */
     
    5252        /** Starting address */
    5353        uintptr_t start_addr;
    54 
     54       
    5555        /** Area size */
    5656        size_t size;
    57 
     57       
    5858        /** Area flags */
    59         int flags;
     59        unsigned int flags;
    6060} as_area_info_t;
    6161
     
    6565#include <arch/mm/as.h>
    6666#include <arch/mm/asid.h>
    67 #include <arch/types.h>
     67#include <typedefs.h>
    6868#include <synch/spinlock.h>
    6969#include <synch/mutex.h>
     
    7575 * Defined to be true if user address space and kernel address space shadow each
    7676 * other.
    77  */
    78 #define KERNEL_ADDRESS_SPACE_SHADOWED   KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
    79 
    80 #define KERNEL_ADDRESS_SPACE_START      KERNEL_ADDRESS_SPACE_START_ARCH
    81 #define KERNEL_ADDRESS_SPACE_END        KERNEL_ADDRESS_SPACE_END_ARCH
    82 #define USER_ADDRESS_SPACE_START        USER_ADDRESS_SPACE_START_ARCH
    83 #define USER_ADDRESS_SPACE_END          USER_ADDRESS_SPACE_END_ARCH
    84 
    85 #define USTACK_ADDRESS                  USTACK_ADDRESS_ARCH
     77 *
     78 */
     79#define KERNEL_ADDRESS_SPACE_SHADOWED  KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
     80
     81#define KERNEL_ADDRESS_SPACE_START  KERNEL_ADDRESS_SPACE_START_ARCH
     82#define KERNEL_ADDRESS_SPACE_END    KERNEL_ADDRESS_SPACE_END_ARCH
     83#define USER_ADDRESS_SPACE_START    USER_ADDRESS_SPACE_START_ARCH
     84#define USER_ADDRESS_SPACE_END      USER_ADDRESS_SPACE_END_ARCH
     85
     86#define USTACK_ADDRESS  USTACK_ADDRESS_ARCH
    8687
    8788/** Kernel address space. */
    88 #define FLAG_AS_KERNEL                  (1 << 0)       
     89#define FLAG_AS_KERNEL  (1 << 0)
    8990
    9091/* Address space area attributes. */
    91 #define AS_AREA_ATTR_NONE       0
    92 #define AS_AREA_ATTR_PARTIAL    1       /**< Not fully initialized area. */
     92#define AS_AREA_ATTR_NONE     0
     93#define AS_AREA_ATTR_PARTIAL  1  /**< Not fully initialized area. */
    9394
    9495/** The page fault was not resolved by as_page_fault(). */
    95 #define AS_PF_FAULT             0
     96#define AS_PF_FAULT  0
     97
    9698/** The page fault was resolved by as_page_fault(). */
    97 #define AS_PF_OK                1
     99#define AS_PF_OK  1
     100
    98101/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
    99 #define AS_PF_DEFER             2
     102#define AS_PF_DEFER  2
    100103
    101104/** Address space structure.
     
    105108 * supposed to figure in the list as they are shared by all tasks and
    106109 * set up during system initialization.
     110 *
    107111 */
    108112typedef struct as {
    109113        /** Protected by asidlock. */
    110114        link_t inactive_as_with_asid_link;
     115       
    111116        /**
    112117         * Number of processors on wich is this address space active.
     
    114119         */
    115120        size_t cpu_refcount;
     121       
    116122        /**
    117123         * Address space identifier.
     
    120126         */
    121127        asid_t asid;
    122 
     128       
    123129        /** Number of references (i.e tasks that reference this as). */
    124130        atomic_t refcount;
    125 
     131       
    126132        mutex_t lock;
    127 
     133       
    128134        /** B+tree of address space areas. */
    129135        btree_t as_area_btree;
     
    131137        /** Non-generic content. */
    132138        as_genarch_t genarch;
    133 
     139       
    134140        /** Architecture specific content. */
    135141        as_arch_t arch;
     
    137143
    138144typedef struct {
    139         pte_t *(* page_table_create)(int flags);
    140         void (* page_table_destroy)(pte_t *page_table);
    141         void (* page_table_lock)(as_t *as, bool lock);
    142         void (* page_table_unlock)(as_t *as, bool unlock);
     145        pte_t *(* page_table_create)(unsigned int);
     146        void (* page_table_destroy)(pte_t *);
     147        void (* page_table_lock)(as_t *, bool);
     148        void (* page_table_unlock)(as_t *, bool);
     149        bool (* page_table_locked)(as_t *);
    143150} as_operations_t;
    144151
     
    146153 * This structure contains information associated with the shared address space
    147154 * area.
     155 *
    148156 */
    149157typedef struct {
    150158        /** This lock must be acquired only when the as_area lock is held. */
    151         mutex_t lock;           
     159        mutex_t lock;
    152160        /** This structure can be deallocated if refcount drops to 0. */
    153161        size_t refcount;
     162       
    154163        /**
    155164         * B+tree containing complete map of anonymous pages of the shared area.
     
    162171        PF_ACCESS_READ,
    163172        PF_ACCESS_WRITE,
    164         PF_ACCESS_EXEC
     173        PF_ACCESS_EXEC,
     174        PF_ACCESS_UNKNOWN
    165175} pf_access_t;
    166176
     
    169179/** Backend data stored in address space area. */
    170180typedef union mem_backend_data {
    171         struct {        /**< elf_backend members */
     181        /** elf_backend members */
     182        struct {
    172183                elf_header_t *elf;
    173184                elf_segment_header_t *segment;
    174185        };
    175         struct {        /**< phys_backend members */
     186       
     187        /** phys_backend members */
     188        struct {
    176189                uintptr_t base;
    177190                size_t frames;
     
    182195 *
    183196 * Each as_area_t structure describes one contiguous area of virtual memory.
     197 *
    184198 */
    185199typedef struct {
    186200        mutex_t lock;
    187201        /** Containing address space. */
    188         as_t *as;               
     202        as_t *as;
     203       
    189204        /**
    190205         * Flags related to the memory represented by the address space area.
    191206         */
    192         int flags;
     207        unsigned int flags;
     208       
    193209        /** Attributes related to the address space area itself. */
    194         int attributes;
     210        unsigned int attributes;
    195211        /** Size of this area in multiples of PAGE_SIZE. */
    196212        size_t pages;
     
    199215        /** Map of used space. */
    200216        btree_t used_space;
    201 
     217       
    202218        /**
    203219         * If the address space area has been shared, this pointer will
     
    205221         */
    206222        share_info_t *sh_info;
    207 
     223       
    208224        /** Memory backend backing this address space area. */
    209225        struct mem_backend *backend;
    210 
     226       
    211227        /** Data to be used by the backend. */
    212228        mem_backend_data_t backend_data;
     
    215231/** Address space area backend structure. */
    216232typedef struct mem_backend {
    217         int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access);
    218         void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame);
    219         void (* share)(as_area_t *area);
     233        int (* page_fault)(as_area_t *, uintptr_t, pf_access_t);
     234        void (* frame_free)(as_area_t *, uintptr_t, uintptr_t);
     235        void (* share)(as_area_t *);
    220236} mem_backend_t;
    221237
     
    227243extern void as_init(void);
    228244
    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);
     245extern as_t *as_create(unsigned int);
     246extern void as_destroy(as_t *);
     247extern void as_hold(as_t *);
     248extern void as_release(as_t *);
     249extern void as_switch(as_t *, as_t *);
     250extern int as_page_fault(uintptr_t, pf_access_t, istate_t *);
     251
     252extern as_area_t *as_area_create(as_t *, unsigned int, size_t, uintptr_t,
     253    unsigned int, mem_backend_t *, mem_backend_data_t *);
     254extern int as_area_destroy(as_t *, uintptr_t);
     255extern int as_area_resize(as_t *, uintptr_t, size_t, unsigned int);
     256extern int as_area_share(as_t *, uintptr_t, size_t, as_t *, uintptr_t,
     257    unsigned int);
     258extern int as_area_change_flags(as_t *, unsigned int, uintptr_t);
     259
     260extern unsigned int as_area_get_flags(as_area_t *);
     261extern bool as_area_check_access(as_area_t *, pf_access_t);
     262extern size_t as_area_get_size(uintptr_t);
     263extern int used_space_insert(as_area_t *, uintptr_t, size_t);
     264extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    248265
    249266
    250267/* Interface to be implemented by architectures. */
     268
    251269#ifndef as_constructor_arch
    252 extern int as_constructor_arch(as_t *as, int flags);
     270extern int as_constructor_arch(as_t *, unsigned int);
    253271#endif /* !def as_constructor_arch */
     272
    254273#ifndef as_destructor_arch
    255 extern int as_destructor_arch(as_t *as);
     274extern int as_destructor_arch(as_t *);
    256275#endif /* !def as_destructor_arch */
     276
    257277#ifndef as_create_arch
    258 extern int as_create_arch(as_t *as, int flags);
     278extern int as_create_arch(as_t *, unsigned int);
    259279#endif /* !def as_create_arch */
     280
    260281#ifndef as_install_arch
    261 extern void as_install_arch(as_t *as);
     282extern void as_install_arch(as_t *);
    262283#endif /* !def as_install_arch */
     284
    263285#ifndef as_deinstall_arch
    264 extern void as_deinstall_arch(as_t *as);
     286extern void as_deinstall_arch(as_t *);
    265287#endif /* !def as_deinstall_arch */
    266288
     
    270292extern mem_backend_t phys_backend;
    271293
    272 /** 
     294/**
    273295 * This flags is passed when running the loader, otherwise elf_load()
    274296 * would return with a EE_LOADER error code.
    275  */
    276 #define ELD_F_NONE      0
    277 #define ELD_F_LOADER    1
    278 
    279 extern unsigned int elf_load(elf_header_t *header, as_t *as, int flags);
     297 *
     298 */
     299#define ELD_F_NONE    0
     300#define ELD_F_LOADER  1
     301
     302extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
    280303
    281304/* 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);
     305extern unative_t sys_as_area_create(uintptr_t, size_t, unsigned int);
     306extern unative_t sys_as_area_resize(uintptr_t, size_t, unsigned int);
     307extern unative_t sys_as_area_change_flags(uintptr_t, unsigned int);
     308extern unative_t sys_as_area_destroy(uintptr_t);
    286309
    287310/* 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);
     311extern void as_get_area_info(as_t *, as_area_info_t **, size_t *);
     312extern void as_print(as_t *);
    290313
    291314#endif /* KERNEL */
  • kernel/generic/include/mm/buddy.h

    rfb150d78 r46c20c8  
    3636#define KERN_BUDDY_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <adt/list.h>
    4040
  • kernel/generic/include/mm/frame.h

    rfb150d78 r46c20c8  
    3737#define KERN_FRAME_H_
    3838
    39 #include <arch/types.h>
     39#include <typedefs.h>
     40#include <trace.h>
    4041#include <adt/list.h>
    4142#include <mm/buddy.h>
     
    8182
    8283typedef struct {
    83         size_t refcount;     /**< Tracking of shared frames */
     84        size_t refcount;      /**< Tracking of shared frames */
    8485        uint8_t buddy_order;  /**< Buddy system block order */
    8586        link_t buddy_link;    /**< Link to the next free block inside
     
    9192        pfn_t base;                    /**< Frame_no of the first frame
    9293                                        in the frames array */
    93         size_t count;                 /**< Size of zone */
    94         size_t free_count;            /**< Number of free frame_t
     94        size_t count;                  /**< Size of zone */
     95        size_t free_count;             /**< Number of free frame_t
    9596                                        structures */
    96         size_t busy_count;            /**< Number of busy frame_t
     97        size_t busy_count;             /**< Number of busy frame_t
    9798                                        structures */
    9899        zone_flags_t flags;            /**< Type of the zone */
     
    108109 */
    109110typedef struct {
    110         SPINLOCK_DECLARE(lock);
     111        IRQ_SPINLOCK_DECLARE(lock);
    111112        size_t count;
    112113        zone_t info[ZONES_MAX];
     
    115116extern zones_t zones;
    116117
    117 static inline uintptr_t PFN2ADDR(pfn_t frame)
     118NO_TRACE static inline uintptr_t PFN2ADDR(pfn_t frame)
    118119{
    119120        return (uintptr_t) (frame << FRAME_WIDTH);
    120121}
    121122
    122 static inline pfn_t ADDR2PFN(uintptr_t addr)
     123NO_TRACE static inline pfn_t ADDR2PFN(uintptr_t addr)
    123124{
    124125        return (pfn_t) (addr >> FRAME_WIDTH);
    125126}
    126127
    127 static inline size_t SIZE2FRAMES(size_t size)
     128NO_TRACE static inline size_t SIZE2FRAMES(size_t size)
    128129{
    129130        if (!size)
     
    132133}
    133134
    134 static inline size_t FRAMES2SIZE(size_t frames)
     135NO_TRACE static inline size_t FRAMES2SIZE(size_t frames)
    135136{
    136137        return (size_t) (frames << FRAME_WIDTH);
    137138}
    138139
    139 static inline bool zone_flags_available(zone_flags_t flags)
     140NO_TRACE static inline bool zone_flags_available(zone_flags_t flags)
    140141{
    141142        return ((flags & (ZONE_RESERVED | ZONE_FIRMWARE)) == 0);
     
    166167extern void frame_set_parent(pfn_t, void *, size_t);
    167168extern void frame_mark_unavailable(pfn_t, size_t);
    168 extern uintptr_t zone_conf_size(size_t);
     169extern size_t zone_conf_size(size_t);
    169170extern bool zone_merge(size_t, size_t);
    170171extern void zone_merge_all(void);
    171 extern uint64_t zone_total_size(void);
     172extern uint64_t zones_total_size(void);
     173extern void zones_stats(uint64_t *, uint64_t *, uint64_t *, uint64_t *);
    172174
    173175/*
    174176 * Console functions
    175177 */
    176 extern void zone_print_list(void);
     178extern void zones_print_list(void);
    177179extern void zone_print_one(size_t);
    178180
  • kernel/generic/include/mm/page.h

    rfb150d78 r46c20c8  
    3636#define KERN_PAGE_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <mm/as.h>
    4040#include <memstr.h>
     
    4242/** Operations to manipulate page mappings. */
    4343typedef struct {
    44         void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame,
    45             int flags);
    46         void (* mapping_remove)(as_t *as, uintptr_t page);
    47         pte_t *(* mapping_find)(as_t *as, uintptr_t page);
     44        void (* mapping_insert)(as_t *, uintptr_t, uintptr_t, unsigned int);
     45        void (* mapping_remove)(as_t *, uintptr_t);
     46        pte_t *(* mapping_find)(as_t *, uintptr_t);
    4847} page_mapping_operations_t;
    4948
     
    5150
    5251extern void page_init(void);
    53 extern void page_table_lock(as_t *as, bool lock);
    54 extern void page_table_unlock(as_t *as, bool unlock);
    55 extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
    56     int flags);
    57 extern void page_mapping_remove(as_t *as, uintptr_t page);
    58 extern pte_t *page_mapping_find(as_t *as, uintptr_t page);
    59 extern pte_t *page_table_create(int flags);
    60 extern void page_table_destroy(pte_t *page_table);
    61 extern void map_structure(uintptr_t s, size_t size);
     52extern void page_table_lock(as_t *, bool);
     53extern void page_table_unlock(as_t *, bool);
     54extern bool page_table_locked(as_t *);
     55extern void page_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
     56extern void page_mapping_remove(as_t *, uintptr_t);
     57extern pte_t *page_mapping_find(as_t *, uintptr_t);
     58extern pte_t *page_table_create(unsigned int);
     59extern void page_table_destroy(pte_t *);
     60extern void map_structure(uintptr_t, size_t);
    6261
    63 extern uintptr_t hw_map(uintptr_t physaddr, size_t size);
     62extern uintptr_t hw_map(uintptr_t, size_t);
    6463
    6564#endif
  • kernel/generic/include/mm/slab.h

    rfb150d78 r46c20c8  
    8484} slab_mag_cache_t;
    8585
    86 
    8786typedef struct {
    88         char *name;
     87        const char *name;
    8988       
    9089        link_t link;
     
    9493        size_t size;
    9594       
    96         int (*constructor)(void *obj, int kmflag);
    97         int (*destructor)(void *obj);
     95        int (*constructor)(void *obj, unsigned int kmflag);
     96        size_t (*destructor)(void *obj);
    9897       
    9998        /** Flags changing behaviour of cache */
    100         int flags;
     99        unsigned int flags;
    101100       
    102101        /* Computed values */
    103         uint8_t order;         /**< Order of frames to be allocated */
    104         unsigned int objects;  /**< Number of objects that fit in */
     102        uint8_t order;   /**< Order of frames to be allocated */
     103        size_t objects;  /**< Number of objects that fit in */
    105104       
    106105        /* Statistics */
     
    109108        atomic_t cached_objs;
    110109        /** How many magazines in magazines list */
    111         atomic_t magazine_counter; 
     110        atomic_t magazine_counter;
    112111       
    113112        /* Slabs */
     
    123122} slab_cache_t;
    124123
    125 extern slab_cache_t *slab_cache_create(char *, size_t, size_t,
    126     int (*)(void *, int), int (*)(void *), int);
     124extern slab_cache_t *slab_cache_create(const char *, size_t, size_t,
     125    int (*)(void *, unsigned int), size_t (*)(void *), unsigned int);
    127126extern void slab_cache_destroy(slab_cache_t *);
    128127
    129 extern void * slab_alloc(slab_cache_t *, int);
     128extern void *slab_alloc(slab_cache_t *, unsigned int)
     129    __attribute__((malloc));
    130130extern void slab_free(slab_cache_t *, void *);
    131 extern size_t slab_reclaim(int);
     131extern size_t slab_reclaim(unsigned int);
    132132
    133133/* slab subsytem initialization */
     
    139139
    140140/* malloc support */
    141 extern void *malloc(unsigned int, int);
    142 extern void *realloc(void *, unsigned int, int);
     141extern void *malloc(size_t, unsigned int)
     142    __attribute__((malloc));
     143extern void *realloc(void *, size_t, unsigned int);
    143144extern void free(void *);
    144145
  • kernel/generic/include/mm/tlb.h

    rfb150d78 r46c20c8  
    3737
    3838#include <arch/mm/asid.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040
    4141/**
     
    6868
    6969#ifdef CONFIG_SMP
    70 extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
    71     uintptr_t page, size_t count);
    72 extern void tlb_shootdown_finalize(void);
     70extern ipl_t tlb_shootdown_start(tlb_invalidate_type_t, asid_t, uintptr_t,
     71    size_t);
     72extern void tlb_shootdown_finalize(ipl_t);
    7373extern void tlb_shootdown_ipi_recv(void);
    7474#else
    75 #define tlb_shootdown_start(w, x, y, z)
    76 #define tlb_shootdown_finalize()
     75#define tlb_shootdown_start(w, x, y, z) (0)
     76#define tlb_shootdown_finalize(i)       ((i) = (i));
    7777#define tlb_shootdown_ipi_recv()
    7878#endif /* CONFIG_SMP */
     
    8484
    8585extern void tlb_invalidate_all(void);
    86 extern void tlb_invalidate_asid(asid_t asid);
    87 extern void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt);
     86extern void tlb_invalidate_asid(asid_t);
     87extern void tlb_invalidate_pages(asid_t, uintptr_t, size_t);
    8888#endif
    8989
  • kernel/generic/include/panic.h

    rfb150d78 r46c20c8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_PANIC_H_
    3737
    38 #include <stacktrace.h>
     38#include <typedefs.h>
    3939#include <print.h>
    4040
    41 #ifdef CONFIG_DEBUG
    42 #       define panic(format, ...) \
    43                 do { \
    44                         printf("Kernel panic in %s() at %s:%u.\n", \
    45                             __func__, __FILE__, __LINE__); \
    46                         stack_trace(); \
    47                         panic_printf("Panic message: " format "\n", \
    48                             ##__VA_ARGS__);\
    49                 } while (0)
    50 #else
    51 #       define panic(format, ...) \
    52                 panic_printf("Kernel panic: " format "\n", ##__VA_ARGS__);
    53 #endif
     41#define panic(fmt, ...) \
     42        panic_common(PANIC_OTHER, NULL, 0, 0, fmt, ##__VA_ARGS__)
    5443
    55 extern void panic_printf(char *fmt, ...) __attribute__((noreturn));
     44#define panic_assert(fmt, ...) \
     45        panic_common(PANIC_ASSERT, NULL, 0, 0, fmt, ##__VA_ARGS__)
     46
     47#define panic_badtrap(istate, n, fmt, ...) \
     48        panic_common(PANIC_BADTRAP, istate, 0, n, fmt, ##__VA_ARGS__)
     49
     50#define panic_memtrap(istate, access, addr, fmt, ...) \
     51        panic_common(PANIC_MEMTRAP, istate, access, addr, fmt, ##__VA_ARGS__)
     52
     53typedef enum {
     54        PANIC_OTHER,
     55        PANIC_ASSERT,
     56        PANIC_BADTRAP,
     57        PANIC_MEMTRAP
     58} panic_category_t;
     59
     60struct istate;
     61
     62extern bool silent;
     63
     64extern void panic_common(panic_category_t, struct istate *, int,
     65    uintptr_t, const char *, ...) __attribute__ ((noreturn))
     66    PRINTF_ATTRIBUTE(5, 6);
    5667
    5768#endif
  • kernel/generic/include/preemption.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
  • kernel/generic/include/print.h

    rfb150d78 r46c20c8  
    3636#define KERN_PRINT_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <stdarg.h>
    4040
    41 #define EOF (-1)
     41#ifndef NVERIFY_PRINTF
     42
     43#define PRINTF_ATTRIBUTE(start, end) \
     44        __attribute__((format(gnu_printf, start, end)))
     45
     46#else /* NVERIFY_PRINTF */
     47
     48#define PRINTF_ATTRIBUTE(start, end)
     49
     50#endif /* NVERIFY_PRINTF */
     51
     52#define EOF  (-1)
    4253
    4354extern int puts(const char *s);
    44 extern int printf(const char *fmt, ...);
    45 extern int snprintf(char *str, size_t size, const char *fmt, ...);
     55extern int printf(const char *fmt, ...)
     56    PRINTF_ATTRIBUTE(1, 2);
     57extern int snprintf(char *str, size_t size, const char *fmt, ...)
     58    PRINTF_ATTRIBUTE(3, 4);
    4659
    4760extern int vprintf(const char *fmt, va_list ap);
  • kernel/generic/include/printf/printf_core.h

    rfb150d78 r46c20c8  
    5151} printf_spec_t;
    5252
    53 int printf_core(const char *fmt, printf_spec_t *ps, va_list ap);
     53extern int printf_core(const char *fmt, printf_spec_t *ps, va_list ap);
    5454
    5555#endif
  • kernel/generic/include/proc/program.h

    rfb150d78 r46c20c8  
    3636#define KERN_PROGRAM_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040struct task;
     
    4545 * A program is an abstraction of a freshly created (not yet running)
    4646 * userspace task containing a main thread along with its userspace stack.
     47 *
    4748 */
    4849typedef struct program {
    49         struct task *task;              /**< Program task */
    50         struct thread *main_thread;     /**< Program main thread */
     50        struct task *task;           /**< Program task */
     51        struct thread *main_thread;  /**< Program main thread */
    5152} program_t;
    5253
    5354extern void *program_loader;
    5455
    55 extern void program_create(as_t *as, uintptr_t entry_addr, char *name,
    56     program_t *p);
    57 extern int program_create_from_image(void *image_addr, char *name,
    58     program_t *p);
    59 extern int program_create_loader(program_t *p, char *name);
    60 extern void program_ready(program_t *p);
     56extern int program_create(as_t *, uintptr_t, char *, program_t *);
     57extern int program_create_from_image(void *, char *, program_t *);
     58extern int program_create_loader(program_t *, char *);
     59extern void program_ready(program_t *);
    6160
    62 extern unative_t sys_program_spawn_loader(char *uspace_name, size_t name_len);
     61extern unative_t sys_program_spawn_loader(char *, size_t);
    6362
    6463#endif
  • kernel/generic/include/proc/scheduler.h

    rfb150d78 r46c20c8  
    3737
    3838#include <synch/spinlock.h>
    39 #include <time/clock.h>         /* HZ */
     39#include <time/clock.h>
     40#include <typedefs.h>
    4041#include <atomic.h>
    4142#include <adt/list.h>
    4243
    43 #define RQ_COUNT                16
    44 #define NEEDS_RELINK_MAX        (HZ)
     44#define RQ_COUNT          16
     45#define NEEDS_RELINK_MAX  (HZ)
    4546
    4647/** Scheduler run queue structure. */
    4748typedef struct {
    48         SPINLOCK_DECLARE(lock);
    49         link_t rq_head;         /**< List of ready threads. */
    50         size_t n;               /**< Number of threads in rq_ready. */
     49        IRQ_SPINLOCK_DECLARE(lock);
     50        link_t rq_head;              /**< List of ready threads. */
     51        size_t n;                    /**< Number of threads in rq_ready. */
    5152} runq_t;
    5253
     
    6162
    6263/*
    63  * To be defined by architectures:
     64 * To be defined by architectures.
    6465 */
    6566extern void before_task_runs_arch(void);
  • kernel/generic/include/proc/task.h

    rfb150d78 r46c20c8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    4040#include <synch/spinlock.h>
    4141#include <synch/mutex.h>
    42 #include <synch/rwlock.h>
    4342#include <synch/futex.h>
    4443#include <adt/avl.h>
     
    5655#include <ipc/kbox.h>
    5756#include <mm/as.h>
    58 
    59 #define TASK_NAME_BUFLEN        20
     57#include <sysinfo/abi.h>
    6058
    6159struct thread;
     
    7169         * threads.
    7270         */
    73         SPINLOCK_DECLARE(lock);
    74 
     71        IRQ_SPINLOCK_DECLARE(lock);
     72       
    7573        char name[TASK_NAME_BUFLEN];
    7674        /** List of threads contained in this task. */
     
    8179        task_id_t taskid;
    8280        /** Task security context. */
    83         context_id_t context;   
    84 
     81        context_id_t context;
     82       
    8583        /** Number of references (i.e. threads). */
    8684        atomic_t refcount;
    8785        /** Number of threads that haven't exited yet. */
    8886        atomic_t lifecount;
    89 
     87       
    9088        /** Task capabilities. */
    91         cap_t capabilities;     
    92 
     89        cap_t capabilities;
     90       
    9391        /* IPC stuff */
    9492        answerbox_t answerbox;  /**< Communication endpoint */
    9593        phone_t phones[IPC_MAX_PHONES];
     94        stats_ipc_t ipc_info;   /**< IPC statistics */
    9695        /**
    9796         * Active asynchronous messages. It is used for limiting uspace to
     
    101100        /** List of synchronous answerboxes. */
    102101        link_t sync_box_head;
    103 
     102       
    104103#ifdef CONFIG_UDEBUG
    105104        /** Debugging stuff. */
    106105        udebug_task_t udebug;
    107 
     106       
    108107        /** Kernel answerbox. */
    109108        kbox_t kb;
    110 #endif
    111 
     109#endif /* CONFIG_UDEBUG */
     110       
    112111        /** Architecture specific task data. */
    113112        task_arch_t arch;
     
    119118        mutex_t futexes_lock;
    120119        /** B+tree of futexes referenced by this task. */
    121         btree_t futexes;       
     120        btree_t futexes;
    122121       
    123122        /** Accumulated accounting. */
    124         uint64_t cycles;
     123        uint64_t ucycles;
     124        uint64_t kcycles;
    125125} task_t;
    126126
    127 SPINLOCK_EXTERN(tasks_lock);
     127IRQ_SPINLOCK_EXTERN(tasks_lock);
    128128extern avltree_t tasks_tree;
    129129
    130130extern void task_init(void);
    131131extern void task_done(void);
    132 extern task_t *task_create(as_t *as, char *name);
    133 extern void task_destroy(task_t *t);
    134 extern task_t *task_find_by_id(task_id_t id);
    135 extern int task_kill(task_id_t id);
    136 extern uint64_t task_get_accounting(task_t *t);
    137 extern void task_print_list(void);
     132extern task_t *task_create(as_t *, const char *);
     133extern void task_destroy(task_t *);
     134extern void task_hold(task_t *);
     135extern void task_release(task_t *);
     136extern task_t *task_find_by_id(task_id_t);
     137extern int task_kill(task_id_t);
     138extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
     139extern void task_print_list(bool);
    138140
    139 extern void cap_set(task_t *t, cap_t caps);
    140 extern cap_t cap_get(task_t *t);
     141extern void cap_set(task_t *, cap_t);
     142extern cap_t cap_get(task_t *);
    141143
    142144#ifndef task_create_arch
    143 extern void task_create_arch(task_t *t);
     145extern void task_create_arch(task_t *);
    144146#endif
    145147
    146148#ifndef task_destroy_arch
    147 extern void task_destroy_arch(task_t *t);
     149extern void task_destroy_arch(task_t *);
    148150#endif
    149151
    150 extern unative_t sys_task_get_id(task_id_t *uspace_task_id);
    151 extern unative_t sys_task_set_name(const char *uspace_name, size_t name_len);
     152extern unative_t sys_task_get_id(task_id_t *);
     153extern unative_t sys_task_set_name(const char *, size_t);
    152154
    153155#endif
  • kernel/generic/include/proc/thread.h

    rfb150d78 r46c20c8  
    4040#include <time/timeout.h>
    4141#include <cpu.h>
    42 #include <synch/rwlock.h>
    4342#include <synch/spinlock.h>
    4443#include <adt/avl.h>
     
    4847#include <proc/uarg.h>
    4948#include <udebug/udebug.h>
    50 
    51 #define THREAD_STACK_SIZE       STACK_SIZE
    52 #define THREAD_NAME_BUFLEN      20
    53 
    54 extern char *thread_states[];
     49#include <sysinfo/abi.h>
     50
     51#define THREAD_STACK_SIZE   STACK_SIZE
     52#define THREAD_NAME_BUFLEN  20
     53
     54extern const char *thread_states[];
    5555
    5656/* Thread flags */
     
    6060 * When using this flag, the caller must set cpu in the thread_t
    6161 * structure manually before calling thread_ready (even on uniprocessor).
    62  */
    63 #define THREAD_FLAG_WIRED       (1 << 0)
     62 *
     63 */
     64#define THREAD_FLAG_WIRED  (1 << 0)
     65
    6466/** Thread was migrated to another CPU and has not run yet. */
    65 #define THREAD_FLAG_STOLEN      (1 << 1)
     67#define THREAD_FLAG_STOLEN  (1 << 1)
     68
    6669/** Thread executes in userspace. */
    67 #define THREAD_FLAG_USPACE      (1 << 2)
     70#define THREAD_FLAG_USPACE  (1 << 2)
     71
    6872/** Thread will be attached by the caller. */
    69 #define THREAD_FLAG_NOATTACH    (1 << 3)
    70 
    71 /** Thread states. */
    72 typedef enum {
    73         /** It is an error, if thread is found in this state. */
    74         Invalid,
    75         /** State of a thread that is currently executing on some CPU. */
    76         Running,
    77         /** Thread in this state is waiting for an event. */
    78         Sleeping,
    79         /** State of threads in a run queue. */
    80         Ready,
    81         /** Threads are in this state before they are first readied. */
    82         Entering,
    83         /** After a thread calls thread_exit(), it is put into Exiting state. */
    84         Exiting,
    85         /** Threads that were not detached but exited are Lingering. */
    86         Lingering
    87 } state_t;
     73#define THREAD_FLAG_NOATTACH  (1 << 3)
    8874
    8975/** Thread structure. There is one per thread. */
    9076typedef struct thread {
    91         link_t rq_link;         /**< Run queue link. */
    92         link_t wq_link;         /**< Wait queue link. */
    93         link_t th_link;         /**< Links to threads within containing task. */
    94 
     77        link_t rq_link;  /**< Run queue link. */
     78        link_t wq_link;  /**< Wait queue link. */
     79        link_t th_link;  /**< Links to threads within containing task. */
     80       
    9581        /** Threads linkage to the threads_tree. */
    9682        avltree_node_t threads_tree_node;
     
    10086         * Protects the whole thread structure except list links above.
    10187         */
    102         SPINLOCK_DECLARE(lock);
    103 
     88        IRQ_SPINLOCK_DECLARE(lock);
     89       
    10490        char name[THREAD_NAME_BUFLEN];
    105 
     91       
    10692        /** Function implementing the thread. */
    10793        void (* thread_code)(void *);
    10894        /** Argument passed to thread_code() function. */
    10995        void *thread_arg;
    110 
     96       
    11197        /**
    11298         * From here, the stored context is restored when the thread is
     
    124110         */
    125111        context_t sleep_interruption_context;
    126 
     112       
    127113        /** If true, the thread can be interrupted from sleep. */
    128114        bool sleep_interruptible;
     
    132118        timeout_t sleep_timeout;
    133119        /** Flag signalling sleep timeout in progress. */
    134         volatile int timeout_pending;
    135 
     120        volatile bool timeout_pending;
     121       
    136122        /**
    137123         * True if this thread is executing copy_from_uspace().
     
    149135         * thread_exit() before returning to userspace.
    150136         */
    151         bool interrupted;                       
     137        bool interrupted;
    152138       
    153139        /** If true, thread_join_timeout() cannot be used on this thread. */
     
    157143        /** Link used in the joiner_head list. */
    158144        link_t joiner_link;
    159 
     145       
    160146        fpu_context_t *saved_fpu_context;
    161147        int fpu_context_exists;
    162 
     148       
    163149        /*
    164150         * Defined only if thread doesn't run.
     
    167153         */
    168154        int fpu_context_engaged;
    169 
    170         rwlock_type_t rwlock_holder_type;
    171 
    172         /** Callback fired in scheduler before the thread is put asleep. */
    173         void (* call_me)(void *);
    174         /** Argument passed to call_me(). */
    175         void *call_me_with;
    176 
     155       
    177156        /** Thread's state. */
    178157        state_t state;
    179158        /** Thread's flags. */
    180         int flags;
     159        unsigned int flags;
    181160       
    182161        /** Thread's CPU. */
     
    184163        /** Containing task. */
    185164        task_t *task;
    186 
     165       
    187166        /** Ticks before preemption. */
    188167        uint64_t ticks;
    189168       
    190169        /** Thread accounting. */
    191         uint64_t cycles;
     170        uint64_t ucycles;
     171        uint64_t kcycles;
    192172        /** Last sampled cycle. */
    193173        uint64_t last_cycle;
    194         /** Thread doesn't affect accumulated accounting. */   
     174        /** Thread doesn't affect accumulated accounting. */
    195175        bool uncounted;
    196 
     176       
    197177        /** Thread's priority. Implemented as index to CPU->rq */
    198178        int priority;
     
    202182        /** Architecture-specific data. */
    203183        thread_arch_t arch;
    204 
     184       
    205185        /** Thread's kernel stack. */
    206186        uint8_t *kstack;
    207 
     187       
    208188#ifdef CONFIG_UDEBUG
    209189        /** Debugging stuff */
    210190        udebug_thread_t udebug;
    211 #endif
    212 
     191#endif /* CONFIG_UDEBUG */
    213192} thread_t;
    214193
     
    219198 *
    220199 */
    221 SPINLOCK_EXTERN(threads_lock);
     200IRQ_SPINLOCK_EXTERN(threads_lock);
    222201
    223202/** AVL tree containing all threads. */
     
    225204
    226205extern void thread_init(void);
    227 extern thread_t *thread_create(void (*)(void *), void *, task_t *, int, char *,
    228     bool);
     206extern thread_t *thread_create(void (*)(void *), void *, task_t *,
     207    unsigned int, const char *, bool);
    229208extern void thread_attach(thread_t *, task_t *);
    230209extern void thread_ready(thread_t *);
     
    234213extern void thread_create_arch(thread_t *);
    235214#endif
     215
    236216#ifndef thr_constructor_arch
    237217extern void thr_constructor_arch(thread_t *);
    238218#endif
     219
    239220#ifndef thr_destructor_arch
    240221extern void thr_destructor_arch(thread_t *);
     
    246227#define thread_join(t) \
    247228        thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    248 extern int thread_join_timeout(thread_t *, uint32_t, int);
     229
     230extern int thread_join_timeout(thread_t *, uint32_t, unsigned int);
    249231extern void thread_detach(thread_t *);
    250232
    251 extern void thread_register_call_me(void (*)(void *), void *);
    252 extern void thread_print_list(void);
    253 extern void thread_destroy(thread_t *);
    254 extern void thread_update_accounting(void);
     233extern void thread_print_list(bool);
     234extern void thread_destroy(thread_t *, bool);
     235extern thread_t *thread_find_by_id(thread_id_t);
     236extern void thread_update_accounting(bool);
    255237extern bool thread_exists(thread_t *);
    256238
  • kernel/generic/include/security/cap.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3535/**
    3636 * @file
    37  * @brief       Capabilities definitions.
     37 * @brief Capabilities definitions.
    3838 *
    3939 * Capabilities represent virtual rights that entitle their
     
    4949
    5050#include <syscall/sysarg64.h>
    51 #include <arch/types.h>
     51#include <typedefs.h>
    5252
    5353/**
     
    7070
    7171/**
    72  * CAP_PREEMPT_CONTROL allows its holder to disable/enable preemption.
    73  */
    74 #define CAP_PREEMPT_CONTROL     (1<<3)
    75 
    76 /**
    7772 * CAP_IRQ_REG entitles its holder to register IRQ handlers.
    7873 */
    79 #define CAP_IRQ_REG             (1<<4)
     74#define CAP_IRQ_REG             (1<<3)
    8075
    8176typedef uint32_t cap_t;
  • kernel/generic/include/smp/ipi.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3737
    3838#ifdef CONFIG_SMP
    39 extern void ipi_broadcast(int ipi);
    40 extern void ipi_broadcast_arch(int ipi);
     39
     40extern void ipi_broadcast(int);
     41extern void ipi_broadcast_arch(int);
     42
    4143#else
    42 #define ipi_broadcast(x)        ;
     44
     45#define ipi_broadcast(ipi)
     46
    4347#endif /* CONFIG_SMP */
    4448
  • kernel/generic/include/smp/smp.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    4141
    4242#ifdef CONFIG_SMP
     43
    4344extern void smp_init(void);
    4445extern void kmp(void *arg);
    45 #else
     46
     47#else /* CONFIG_SMP */
     48
    4649#define smp_init()
     50
    4751#endif /* CONFIG_SMP */
    4852
  • kernel/generic/include/sort.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3636#define KERN_SORT_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    40 /*
    41  * sorting routines
    42  */
    43 extern void bubblesort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b));
    44 extern void qsort(void * data, size_t n, size_t e_size, int (* cmp) (void * a, void * b));
     40typedef int (* sort_cmp_t)(void *, void *, void *);
    4541
    46 /*
    47  * default sorting comparators
    48  */
    49 extern int int_cmp(void * a, void * b);
    50 extern int uint32_t_cmp(void * a, void * b);
    51 extern int uint16_t_cmp(void * a, void * b);
    52 extern int uint8_t_cmp(void * a, void * b);
     42extern bool gsort(void *, size_t, size_t, sort_cmp_t, void *);
     43extern bool qsort(void *, size_t, size_t, sort_cmp_t, void *);
    5344
    5445#endif
  • kernel/generic/include/stacktrace.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup genericdebug 
     29/** @addtogroup genericdebug
    3030 * @{
    3131 */
     
    3636#define KERN_STACKTRACE_H_
    3737
    38 #include <arch/types.h>
    3938#include <typedefs.h>
    4039
    41 /* Forward declarations. */
     40/* Forward declaration. */
    4241struct istate;
    4342
    4443typedef struct {
    45         bool (* frame_pointer_validate)(uintptr_t);
    46         bool (* frame_pointer_prev)(uintptr_t, uintptr_t *);
    47         bool (* return_address_get)(uintptr_t, uintptr_t *);
    48         bool (* symbol_resolve)(uintptr_t, char **, uintptr_t *);
     44        uintptr_t fp;
     45        uintptr_t pc;
     46        struct istate *istate;
     47} stack_trace_context_t;
     48
     49typedef struct {
     50        bool (* stack_trace_context_validate)(stack_trace_context_t *);
     51        bool (* frame_pointer_prev)(stack_trace_context_t *, uintptr_t *);
     52        bool (* return_address_get)(stack_trace_context_t *, uintptr_t *);
     53        bool (* symbol_resolve)(uintptr_t, const char **, uintptr_t *);
    4954} stack_trace_ops_t;
    5055
     
    5459extern void stack_trace(void);
    5560extern void stack_trace_istate(struct istate *);
    56 extern void stack_trace_fp_pc(stack_trace_ops_t *, uintptr_t, uintptr_t);
     61extern void stack_trace_ctx(stack_trace_ops_t *, stack_trace_context_t *);
    5762
    5863/*
     
    6267extern uintptr_t program_counter_get(void);
    6368
    64 extern bool kernel_frame_pointer_validate(uintptr_t);
    65 extern bool kernel_frame_pointer_prev(uintptr_t, uintptr_t *);
    66 extern bool kernel_return_address_get(uintptr_t, uintptr_t *);
     69extern bool kernel_stack_trace_context_validate(stack_trace_context_t *);
     70extern bool kernel_frame_pointer_prev(stack_trace_context_t *, uintptr_t *);
     71extern bool kernel_return_address_get(stack_trace_context_t *, uintptr_t *);
    6772
    68 extern bool uspace_frame_pointer_validate(uintptr_t);
    69 extern bool uspace_frame_pointer_prev(uintptr_t, uintptr_t *);
    70 extern bool uspace_return_address_get(uintptr_t, uintptr_t *);
     73extern bool uspace_stack_trace_context_validate(stack_trace_context_t *);
     74extern bool uspace_frame_pointer_prev(stack_trace_context_t *, uintptr_t *);
     75extern bool uspace_return_address_get(stack_trace_context_t *, uintptr_t *);
    7176
    7277#endif
  • kernel/generic/include/str.h

    rfb150d78 r46c20c8  
    3333 */
    3434
    35 #ifndef KERN_STRING_H_
    36 #define KERN_STRING_H_
     35#ifndef KERN_STR_H_
     36#define KERN_STR_H_
    3737
    3838#include <typedefs.h>
     
    8989extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
    9090
     91extern char *str_dup(const char *src);
     92extern char *str_ndup(const char *src, size_t n);
     93
    9194extern char *str_chr(const char *str, wchar_t ch);
    9295
     
    9497extern bool wstr_remove(wchar_t *str, size_t pos);
    9598
     99extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *);
     100
     101extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
     102
    96103#endif
    97104
  • kernel/generic/include/symtab.h

    rfb150d78 r46c20c8  
    3636#define KERN_SYMTAB_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    40 #define MAX_SYMBOL_NAME 64
     40#define MAX_SYMBOL_NAME  64
    4141
    4242struct symtab_entry {
     
    4545};
    4646
    47 extern int symtab_name_lookup(uintptr_t, char **, uintptr_t *);
    48 extern char *symtab_fmt_name_lookup(uintptr_t);
     47extern int symtab_name_lookup(uintptr_t, const char **, uintptr_t *);
     48extern const char *symtab_fmt_name_lookup(uintptr_t);
    4949extern int symtab_addr_lookup(const char *, uintptr_t *);
    5050extern void symtab_print_search(const char *);
     
    5353#ifdef CONFIG_SYMTAB
    5454
    55 /* Symtable linked together by build process */
     55/** Symtable linked together by build process
     56 *
     57 */
    5658extern struct symtab_entry symbol_table[];
    5759
    58 #endif
     60#endif /* CONFIG_SYMTAB */
    5961
    6062#endif
  • kernel/generic/include/synch/condvar.h

    rfb150d78 r46c20c8  
    3636#define KERN_CONDVAR_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <synch/waitq.h>
    4040#include <synch/mutex.h>
  • kernel/generic/include/synch/futex.h

    rfb150d78 r46c20c8  
    3636#define KERN_FUTEX_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <synch/waitq.h>
    4040
  • kernel/generic/include/synch/mutex.h

    rfb150d78 r46c20c8  
    3636#define KERN_MUTEX_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <synch/semaphore.h>
    4040#include <synch/synch.h>
     
    5050} mutex_t;
    5151
    52 #define mutex_lock(mtx)                 \
     52#define mutex_lock(mtx) \
    5353        _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    54 #define mutex_trylock(mtx)              \
     54
     55#define mutex_trylock(mtx) \
    5556        _mutex_lock_timeout((mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
    56 #define mutex_lock_timeout(mtx, usec)   \
     57
     58#define mutex_lock_timeout(mtx, usec) \
    5759        _mutex_lock_timeout((mtx), (usec), SYNCH_FLAGS_NON_BLOCKING)
    5860
    5961extern void mutex_initialize(mutex_t *, mutex_type_t);
    60 extern int _mutex_lock_timeout(mutex_t *, uint32_t, int);
     62extern bool mutex_locked(mutex_t *);
     63extern int _mutex_lock_timeout(mutex_t *, uint32_t, unsigned int);
    6164extern void mutex_unlock(mutex_t *);
    6265
  • kernel/generic/include/synch/semaphore.h

    rfb150d78 r46c20c8  
    3636#define KERN_SEMAPHORE_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <synch/waitq.h>
    4040#include <synch/synch.h>
     
    4646#define semaphore_down(s) \
    4747        _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
     48
    4849#define semaphore_trydown(s) \
    4950        _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
     51
    5052#define semaphore_down_timeout(s, usec) \
    5153        _semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)
    5254
    53 extern void semaphore_initialize(semaphore_t *s, int val);
    54 extern int _semaphore_down_timeout(semaphore_t *s, uint32_t usec, int flags);
    55 extern void semaphore_up(semaphore_t *s);
     55extern void semaphore_initialize(semaphore_t *, int);
     56extern int _semaphore_down_timeout(semaphore_t *, uint32_t, unsigned int);
     57extern void semaphore_up(semaphore_t *);
     58extern int semaphore_count_get(semaphore_t *);
    5659
    5760#endif
  • kernel/generic/include/synch/spinlock.h

    rfb150d78 r46c20c8  
    3636#define KERN_SPINLOCK_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <arch/barrier.h>
    4040#include <preemption.h>
    4141#include <atomic.h>
    4242#include <debug.h>
     43#include <arch/asm.h>
    4344
    4445#ifdef CONFIG_SMP
     
    4849       
    4950#ifdef CONFIG_DEBUG_SPINLOCK
    50         char *name;
    51 #endif
     51        const char *name;
     52#endif /* CONFIG_DEBUG_SPINLOCK */
    5253} spinlock_t;
    5354
     
    6061
    6162/*
    62  * SPINLOCK_INITIALIZE is to be used for statically allocated spinlocks.
    63  * It declares and initializes the lock.
     63 * SPINLOCK_INITIALIZE and SPINLOCK_STATIC_INITIALIZE are to be used
     64 * for statically allocated spinlocks. They declare (either as global
     65 * or static) symbol and initialize the lock.
    6466 */
    6567#ifdef CONFIG_DEBUG_SPINLOCK
     
    7779        }
    7880
    79 #define spinlock_lock(lock)  spinlock_lock_debug(lock)
    80 
    81 #else
     81#define ASSERT_SPINLOCK(expr, lock) \
     82        ASSERT_VERBOSE(expr, (lock)->name)
     83
     84#define spinlock_lock(lock)    spinlock_lock_debug((lock))
     85#define spinlock_unlock(lock)  spinlock_unlock_debug((lock))
     86
     87#else /* CONFIG_DEBUG_SPINLOCK */
    8288
    8389#define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     
    9197        }
    9298
    93 #define spinlock_lock(lock)  atomic_lock_arch(&(lock)->val)
    94 
    95 #endif
     99#define ASSERT_SPINLOCK(expr, lock) \
     100        ASSERT(expr)
     101
     102#define spinlock_lock(lock)    atomic_lock_arch(&(lock)->val)
     103#define spinlock_unlock(lock)  spinlock_unlock_nondebug((lock))
     104
     105#endif /* CONFIG_DEBUG_SPINLOCK */
    96106
    97107#define SPINLOCK_INITIALIZE(lock_name) \
     
    101111        SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name)
    102112
    103 extern void spinlock_initialize(spinlock_t *lock, char *name);
    104 extern int spinlock_trylock(spinlock_t *lock);
    105 extern void spinlock_lock_debug(spinlock_t *lock);
     113extern void spinlock_initialize(spinlock_t *, const char *);
     114extern int spinlock_trylock(spinlock_t *);
     115extern void spinlock_lock_debug(spinlock_t *);
     116extern void spinlock_unlock_debug(spinlock_t *);
     117extern bool spinlock_locked(spinlock_t *);
    106118
    107119/** Unlock spinlock
    108120 *
    109  * Unlock spinlock.
     121 * Unlock spinlock for non-debug kernels.
    110122 *
    111123 * @param sl Pointer to spinlock_t structure.
    112  */
    113 static inline void spinlock_unlock(spinlock_t *lock)
     124 *
     125 */
     126NO_TRACE static inline void spinlock_unlock_nondebug(spinlock_t *lock)
    114127{
    115         ASSERT(atomic_get(&lock->val) != 0);
    116        
    117128        /*
    118129         * Prevent critical section code from bleeding out this way down.
     
    135146        if ((pname)++ > (value)) { \
    136147                (pname) = 0; \
    137                 printf("Deadlock probe %s: exceeded threshold %u\n", \
     148                printf("Deadlock probe %s: exceeded threshold %u\n" \
    138149                    "cpu%u: function=%s, line=%u\n", \
    139150                    #pname, (value), CPU->id, __func__, __LINE__); \
    140151        }
    141152
    142 #else
     153#else /* CONFIG_DEBUG_SPINLOCK */
    143154
    144155#define DEADLOCK_PROBE_INIT(pname)
    145156#define DEADLOCK_PROBE(pname, value)
    146157
    147 #endif
     158#endif /* CONFIG_DEBUG_SPINLOCK */
    148159
    149160#else /* CONFIG_SMP */
     
    159170#define SPINLOCK_INITIALIZE_NAME(name, desc_name)
    160171#define SPINLOCK_STATIC_INITIALIZE_NAME(name, desc_name)
     172
     173#define ASSERT_SPINLOCK(expr, lock)  ASSERT(expr)
    161174
    162175#define spinlock_initialize(lock, name)
     
    165178#define spinlock_trylock(lock)  (preemption_disable(), 1)
    166179#define spinlock_unlock(lock)   preemption_enable()
     180#define spinlock_locked(lock)   1
     181#define spinlock_unlocked(lock) 1
    167182
    168183#define DEADLOCK_PROBE_INIT(pname)
    169184#define DEADLOCK_PROBE(pname, value)
    170185
     186#endif /* CONFIG_SMP */
     187
     188typedef struct {
     189        SPINLOCK_DECLARE(lock);  /**< Spinlock */
     190        bool guard;              /**< Flag whether ipl is valid */
     191        ipl_t ipl;               /**< Original interrupt level */
     192} irq_spinlock_t;
     193
     194#define IRQ_SPINLOCK_DECLARE(lock_name)  irq_spinlock_t lock_name
     195#define IRQ_SPINLOCK_EXTERN(lock_name)   extern irq_spinlock_t lock_name
     196
     197#ifdef CONFIG_SMP
     198
     199#define ASSERT_IRQ_SPINLOCK(expr, irq_lock) \
     200        ASSERT_SPINLOCK(expr, &((irq_lock)->lock))
     201
     202/*
     203 * IRQ_SPINLOCK_INITIALIZE and IRQ_SPINLOCK_STATIC_INITIALIZE are to be used
     204 * for statically allocated interrupts-disabled spinlocks. They declare (either
     205 * as global or static symbol) and initialize the lock.
     206 */
     207#ifdef CONFIG_DEBUG_SPINLOCK
     208
     209#define IRQ_SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     210        irq_spinlock_t lock_name = { \
     211                .lock = { \
     212                        .name = desc_name, \
     213                        .val = { 0 } \
     214                }, \
     215                .guard = false, \
     216                .ipl = 0 \
     217        }
     218
     219#define IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
     220        static irq_spinlock_t lock_name = { \
     221                .lock = { \
     222                        .name = desc_name, \
     223                        .val = { 0 } \
     224                }, \
     225                .guard = false, \
     226                .ipl = 0 \
     227        }
     228
     229#else /* CONFIG_DEBUG_SPINLOCK */
     230
     231#define IRQ_SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     232        irq_spinlock_t lock_name = { \
     233                .lock = { \
     234                        .val = { 0 } \
     235                }, \
     236                .guard = false, \
     237                .ipl = 0 \
     238        }
     239
     240#define IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
     241        static irq_spinlock_t lock_name = { \
     242                .lock = { \
     243                        .val = { 0 } \
     244                }, \
     245                .guard = false, \
     246                .ipl = 0 \
     247        }
     248
     249#endif /* CONFIG_DEBUG_SPINLOCK */
     250
     251#else /* CONFIG_SMP */
     252
     253/*
     254 * Since the spinlocks are void on UP systems, we also need
     255 * to have a special variant of interrupts-disabled spinlock
     256 * macros which take this into account.
     257 */
     258
     259#define ASSERT_IRQ_SPINLOCK(expr, irq_lock) \
     260        ASSERT_SPINLOCK(expr, NULL)
     261
     262#define IRQ_SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \
     263        irq_spinlock_t lock_name = { \
     264                .guard = false, \
     265                .ipl = 0 \
     266        }
     267
     268#define IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \
     269        static irq_spinlock_t lock_name = { \
     270                .guard = false, \
     271                .ipl = 0 \
     272        }
     273
     274#endif /* CONFIG_SMP */
     275
     276#define IRQ_SPINLOCK_INITIALIZE(lock_name) \
     277        IRQ_SPINLOCK_INITIALIZE_NAME(lock_name, #lock_name)
     278
     279#define IRQ_SPINLOCK_STATIC_INITIALIZE(lock_name) \
     280        IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name)
     281
     282extern void irq_spinlock_initialize(irq_spinlock_t *, const char *);
     283extern void irq_spinlock_lock(irq_spinlock_t *, bool);
     284extern void irq_spinlock_unlock(irq_spinlock_t *, bool);
     285extern int irq_spinlock_trylock(irq_spinlock_t *);
     286extern void irq_spinlock_pass(irq_spinlock_t *, irq_spinlock_t *);
     287extern void irq_spinlock_exchange(irq_spinlock_t *, irq_spinlock_t *);
     288extern bool irq_spinlock_locked(irq_spinlock_t *);
     289
    171290#endif
    172291
    173 #endif
    174 
    175292/** @}
    176293 */
  • kernel/generic/include/synch/waitq.h

    rfb150d78 r46c20c8  
    3636#define KERN_WAITQ_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <synch/spinlock.h>
    4040#include <synch/synch.h>
     
    4646} wakeup_mode_t;
    4747
    48 /** Wait queue structure. */
     48/** Wait queue structure.
     49 *
     50 */
    4951typedef struct {
    50 
    5152        /** Lock protecting wait queue structure.
    5253         *
    5354         * Must be acquired before T.lock for each T of type thread_t.
    5455         */
    55         SPINLOCK_DECLARE(lock);
    56 
     56        IRQ_SPINLOCK_DECLARE(lock);
     57       
    5758        /**
    5859         * Number of waitq_wakeup() calls that didn't find a thread to wake up.
     60         *
    5961         */
    6062        int missed_wakeups;
     63       
    6164        /** List of sleeping threads for wich there was no missed_wakeup. */
    6265        link_t head;
     
    6972
    7073extern void waitq_initialize(waitq_t *);
    71 extern int waitq_sleep_timeout(waitq_t *, uint32_t, int);
     74extern int waitq_sleep_timeout(waitq_t *, uint32_t, unsigned int);
    7275extern ipl_t waitq_sleep_prepare(waitq_t *);
    73 extern int waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, int);
     76extern int waitq_sleep_timeout_unsafe(waitq_t *, uint32_t, unsigned int);
    7477extern void waitq_sleep_finish(waitq_t *, int, ipl_t);
    7578extern void waitq_wakeup(waitq_t *, wakeup_mode_t);
     
    7780extern void waitq_interrupt_sleep(struct thread *);
    7881extern void waitq_unsleep(waitq_t *);
     82extern int waitq_count_get(waitq_t *);
     83extern void waitq_count_set(waitq_t *, int val);
    7984
    8085#endif
  • kernel/generic/include/syscall/copy.h

    rfb150d78 r46c20c8  
    3636#define KERN_COPY_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040/** Label within memcpy_from_uspace() that contains return -1. */
  • kernel/generic/include/syscall/sysarg64.h

    rfb150d78 r46c20c8  
    3333/**
    3434 * @file
    35  * @brief       Wrapper for explicit 64-bit arguments passed to syscalls.
     35 * @brief Wrapper for explicit 64-bit arguments passed to syscalls.
    3636 */
    3737
  • kernel/generic/include/syscall/syscall.h

    rfb150d78 r46c20c8  
    7171        SYS_IPC_REGISTER_IRQ,
    7272        SYS_IPC_UNREGISTER_IRQ,
    73 
     73       
    7474        SYS_EVENT_SUBSCRIBE,
    7575       
     
    8080        SYS_PHYSMEM_MAP,
    8181        SYS_IOSPACE_ENABLE,
    82         SYS_PREEMPT_CONTROL,
     82        SYS_INTERRUPT_ENABLE,
    8383       
    84         SYS_SYSINFO_VALID,
    85         SYS_SYSINFO_VALUE,
     84        SYS_SYSINFO_GET_TAG,
     85        SYS_SYSINFO_GET_VALUE,
     86        SYS_SYSINFO_GET_DATA_SIZE,
     87        SYS_SYSINFO_GET_DATA,
    8688       
    8789        SYS_DEBUG_ENABLE_CONSOLE,
    8890        SYS_DEBUG_DISABLE_CONSOLE,
     91       
    8992        SYS_IPC_CONNECT_KBOX,
    9093        SYSCALL_END
     
    9396#ifdef KERNEL
    9497
    95 #include <arch/types.h>
     98#include <typedefs.h>
    9699
    97100typedef unative_t (*syshandler_t)(unative_t, unative_t, unative_t, unative_t,
  • kernel/generic/include/sysinfo/stats.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup abs32ledebug
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef KERN_abs32le_DEBUG_H_
    36 #define KERN_abs32le_DEBUG_H_
     35#ifndef KERN_STATS_H_
     36#define KERN_STATS_H_
    3737
    38 #include <arch/asm.h>
    39 
    40 #define HERE  get_ip()
     38extern void kload(void *arg);
     39extern void stats_init(void);
    4140
    4241#endif
  • kernel/generic/include/sysinfo/sysinfo.h

    rfb150d78 r46c20c8  
    3636#define KERN_SYSINFO_H_
    3737
    38 #include <arch/types.h>
    39 #include <string.h>
     38#include <typedefs.h>
     39#include <str.h>
    4040
     41/** Framebuffer info exported flags */
    4142extern bool fb_exported;
    4243
    43 typedef union sysinfo_item_val {
    44         unative_t val;
    45         void *fn;
     44/** Item value type
     45 *
     46 */
     47typedef enum {
     48        SYSINFO_VAL_UNDEFINED = 0,     /**< Undefined value */
     49        SYSINFO_VAL_VAL = 1,           /**< Constant numeric value */
     50        SYSINFO_VAL_DATA = 2,          /**< Constant binary data */
     51        SYSINFO_VAL_FUNCTION_VAL = 3,  /**< Generated numeric value */
     52        SYSINFO_VAL_FUNCTION_DATA = 4  /**< Generated binary data */
     53} sysinfo_item_val_type_t;
     54
     55/** Subtree type
     56 *
     57 */
     58typedef enum {
     59        SYSINFO_SUBTREE_NONE = 0,     /**< No subtree (leaf item) */
     60        SYSINFO_SUBTREE_TABLE = 1,    /**< Fixed subtree */
     61        SYSINFO_SUBTREE_FUNCTION = 2  /**< Generated subtree */
     62} sysinfo_subtree_type_t;
     63
     64struct sysinfo_item;
     65
     66/** Gerated numeric value function */
     67typedef unative_t (*sysinfo_fn_val_t)(struct sysinfo_item *);
     68
     69/** Generated binary data function */
     70typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool);
     71
     72/** Sysinfo item binary data
     73 *
     74 */
     75typedef struct {
     76        void *data;   /**< Data */
     77        size_t size;  /**< Size (bytes) */
     78} sysinfo_data_t;
     79
     80/** Sysinfo item value (union)
     81 *
     82 */
     83typedef union {
     84        unative_t val;              /**< Constant numberic value */
     85        sysinfo_fn_val_t fn_val;    /**< Generated numeric value function */
     86        sysinfo_fn_data_t fn_data;  /**< Generated binary data function */
     87        sysinfo_data_t data;        /**< Constant binary data */
    4688} sysinfo_item_val_t;
    4789
     90/** Sysinfo return holder
     91 *
     92 * This structure is generated from the constant
     93 * items or by the generating functions. Note that
     94 * the validity of the data is limited by the scope
     95 * of single sysinfo invocation guarded by sysinfo_lock.
     96 *
     97 */
     98typedef struct {
     99        sysinfo_item_val_type_t tag;  /**< Return value type */
     100        union {
     101                unative_t val;            /**< Numberic value */
     102                sysinfo_data_t data;      /**< Binary data */
     103        };
     104} sysinfo_return_t;
     105
     106/** Generated subtree function */
     107typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool);
     108
     109/** Sysinfo subtree (union)
     110 *
     111 */
     112typedef union {
     113        struct sysinfo_item *table;     /**< Fixed subtree (list of subitems) */
     114        sysinfo_fn_subtree_t get_data;  /**< Generated subtree function */
     115} sysinfo_subtree_t;
     116
     117/** Sysinfo item
     118 *
     119 */
    48120typedef struct sysinfo_item {
    49         char *name;
    50         union {
    51                 unative_t val;
    52                 void *fn;
    53         } val;
    54 
    55         union {
    56                 struct sysinfo_item *table;
    57                 void *fn;
    58         } subinfo;
    59 
    60         struct sysinfo_item *next;
    61         int val_type;
    62         int subinfo_type;
     121        char *name;                           /**< Item name */
     122       
     123        sysinfo_item_val_type_t val_type;     /**< Item value type */
     124        sysinfo_item_val_t val;               /**< Item value */
     125       
     126        sysinfo_subtree_type_t subtree_type;  /**< Subtree type */
     127        sysinfo_subtree_t subtree;            /**< Subtree */
     128       
     129        struct sysinfo_item *next;            /**< Sibling item */
    63130} sysinfo_item_t;
    64131
    65 #define SYSINFO_VAL_VAL        0
    66 #define SYSINFO_VAL_FUNCTION   1
    67 #define SYSINFO_VAL_UNDEFINED  U_SPECIAL
     132extern void sysinfo_set_item_val(const char *, sysinfo_item_t **, unative_t);
     133extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *,
     134    size_t);
     135extern void sysinfo_set_item_fn_val(const char *, sysinfo_item_t **,
     136    sysinfo_fn_val_t);
     137extern void sysinfo_set_item_fn_data(const char *, sysinfo_item_t **,
     138    sysinfo_fn_data_t);
     139extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **);
    68140
    69 #define SYSINFO_SUBINFO_NONE      0
    70 #define SYSINFO_SUBINFO_TABLE     1
    71 #define SYSINFO_SUBINFO_FUNCTION  2
     141extern void sysinfo_set_subtree_fn(const char *, sysinfo_item_t **,
     142    sysinfo_fn_subtree_t);
    72143
    73 typedef unative_t (*sysinfo_val_fn_t)(sysinfo_item_t *root);
    74 typedef unative_t (*sysinfo_subinfo_fn_t)(const char *subname);
     144extern void sysinfo_init(void);
     145extern void sysinfo_dump(sysinfo_item_t *);
    75146
    76 typedef struct sysinfo_rettype {
    77         unative_t val;
    78         unative_t valid;
    79 } sysinfo_rettype_t;
    80 
    81 void sysinfo_set_item_val(const char *name, sysinfo_item_t **root, unative_t val);
    82 void sysinfo_dump(sysinfo_item_t **root, int depth);
    83 void sysinfo_set_item_function(const char *name, sysinfo_item_t **root, sysinfo_val_fn_t fn);
    84 void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root);
    85 
    86 sysinfo_rettype_t sysinfo_get_val(const char *name, sysinfo_item_t **root);
    87 
    88 unative_t sys_sysinfo_valid(unative_t ptr, unative_t len);
    89 unative_t sys_sysinfo_value(unative_t ptr, unative_t len);
     147extern unative_t sys_sysinfo_get_tag(void *, size_t);
     148extern unative_t sys_sysinfo_get_value(void *, size_t, void *);
     149extern unative_t sys_sysinfo_get_data_size(void *, size_t, void *);
     150extern unative_t sys_sysinfo_get_data(void *, size_t, void *, size_t);
    90151
    91152#endif
  • kernel/generic/include/time/clock.h

    rfb150d78 r46c20c8  
    3636#define KERN_CLOCK_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    40 #define HZ              100
     40#define HZ  100
    4141
    4242/** Uptime structure */
  • kernel/generic/include/time/delay.h

    rfb150d78 r46c20c8  
    3636#define KERN_DELAY_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939
    4040extern void delay(uint32_t microseconds);
  • kernel/generic/include/time/timeout.h

    rfb150d78 r46c20c8  
    3636#define KERN_TIMEOUT_H_
    3737
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <adt/list.h>
    4040#include <cpu.h>
     
    4343
    4444typedef struct {
    45         SPINLOCK_DECLARE(lock);
    46 
     45        IRQ_SPINLOCK_DECLARE(lock);
     46       
    4747        /** Link to the list of active timeouts on THE->cpu */
    4848        link_t link;
    49         /** Timeout will be activated in this amount of clock() ticks. */       
     49        /** Timeout will be activated in this amount of clock() ticks. */
    5050        uint64_t ticks;
    5151        /** Function that will be called on timeout activation. */
     
    5757} timeout_t;
    5858
    59 #define us2ticks(us)    ((uint64_t) (((uint32_t) (us) / (1000000 / HZ))))
     59#define us2ticks(us)  ((uint64_t) (((uint32_t) (us) / (1000000 / HZ))))
    6060
    6161extern void timeout_init(void);
    62 extern void timeout_initialize(timeout_t *t);
    63 extern void timeout_reinitialize(timeout_t *t);
    64 extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f,
    65     void *arg);
    66 extern bool timeout_unregister(timeout_t *t);
     62extern void timeout_initialize(timeout_t *);
     63extern void timeout_reinitialize(timeout_t *);
     64extern void timeout_register(timeout_t *, uint64_t, timeout_handler_t, void *);
     65extern bool timeout_unregister(timeout_t *);
    6766
    6867#endif
  • kernel/generic/include/typedefs.h

    rfb150d78 r46c20c8  
    3636#define KERN_TYPEDEFS_H_
    3737
     38#include <stdint.h>
     39#include <arch/common.h>
    3840#include <arch/types.h>
    3941
    40 #define NULL 0
    41 #define false 0
    42 #define true 1
     42#define NULL  ((void *) 0)
     43
     44#define false  0
     45#define true   1
     46
     47typedef struct {
     48        uint64_t lo;
     49        int64_t hi;
     50} int128_t;
     51
     52typedef struct {
     53        uint64_t lo;
     54        uint64_t hi;
     55} uint128_t;
     56
     57typedef struct {
     58        volatile atomic_count_t count;
     59} atomic_t;
    4360
    4461typedef void (* function)();
     
    5269typedef int32_t devno_t;
    5370
    54 typedef int32_t wchar_t;
    55 
    5671typedef volatile uint8_t ioport8_t;
    5772typedef volatile uint16_t ioport16_t;
  • kernel/generic/include/udebug/udebug_ipc.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    4141void udebug_call_receive(call_t *call);
    4242
    43 
    4443#endif
    4544
  • kernel/generic/include/udebug/udebug_ops.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
  • kernel/generic/include/userspace.h

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3737
    3838#include <proc/thread.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040
    4141/** Switch to user-space (CPU user priviledge level) */
Note: See TracChangeset for help on using the changeset viewer.