Changeset 80bcaed in mainline


Ignore:
Timestamp:
2007-02-03T13:22:24Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f619ec11
Parents:
fa8e7d2
Message:

Merge as_t structure into one and leave the differring parts in as_genarch_t.

Indentation and formatting changes in header files.

Location:
kernel
Files:
37 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/mm/page.c

    rfa8e7d2 r80bcaed  
    112112
    113113                exc_register(14, "page_fault", (iroutine) page_fault);
    114                 write_cr3((uintptr_t) AS_KERNEL->page_table);
    115         }
    116         else {
    117                 write_cr3((uintptr_t) AS_KERNEL->page_table);
     114                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
     115        }
     116        else {
     117                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    118118        }
    119119}
  • kernel/arch/amd64/src/pm.c

    rfa8e7d2 r80bcaed  
    202202                 * non boot-mapped pointer, initialize the CR3 register
    203203                 * ahead of page_init */
    204                 write_cr3((uintptr_t) AS_KERNEL->page_table);
     204                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    205205
    206206                tss_p = (struct tss *) malloc(sizeof(tss_t), FRAME_ATOMIC);
  • kernel/arch/ia32/src/mm/page.c

    rfa8e7d2 r80bcaed  
    6969
    7070                exc_register(14, "page_fault", (iroutine) page_fault);
    71                 write_cr3((uintptr_t) AS_KERNEL->page_table);
     71                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    7272        }
    7373        else {
    74                 write_cr3((uintptr_t) AS_KERNEL->page_table);
     74                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    7575        }
    7676
  • kernel/arch/ia32xen/src/mm/page.c

    rfa8e7d2 r80bcaed  
    5454        if (config.cpu_active == 1) {
    5555                page_mapping_operations = &pt_mapping_operations;
    56                 AS_KERNEL->page_table = (pte_t *) KA2PA(start_info.ptl0);
     56                AS_KERNEL->genarch.page_table = (pte_t *) KA2PA(start_info.ptl0);
    5757        } else
    58                 SET_PTL0_ADDRESS_ARCH(AS_KERNEL->page_table);
     58                SET_PTL0_ADDRESS_ARCH(AS_KERNEL->genarch.page_table);
    5959}
    6060
  • kernel/arch/sparc64/include/mm/tsb.h

    rfa8e7d2 r80bcaed  
    5555#include <arch/mm/mmu.h>
    5656#include <arch/types.h>
    57 #include <mm/as.h>
    5857
    5958/** TSB Base register. */
     
    109108}
    110109
    111 extern void tsb_invalidate(as_t *as, uintptr_t page, count_t pages);
    112 extern void itsb_pte_copy(pte_t *t);
    113 extern void dtsb_pte_copy(pte_t *t, bool ro);
     110/* Forward declarations. */
     111struct as;
     112struct pte;
     113
     114extern void tsb_invalidate(struct as *as, uintptr_t page, count_t pages);
     115extern void itsb_pte_copy(struct pte *t);
     116extern void dtsb_pte_copy(struct pte *t, bool ro);
    114117
    115118#endif /* !def __ASM__ */
  • kernel/genarch/include/mm/as_ht.h

    rfa8e7d2 r80bcaed  
    3737
    3838#include <mm/mm.h>
    39 #include <arch/mm/asid.h>
    4039#include <adt/list.h>
    41 #include <adt/btree.h>
    42 #include <synch/mutex.h>
    43 
    44 /** Address space structure.
    45  *
    46  * as_t contains the list of as_areas of userspace accessible
    47  * pages for one or more tasks. Ranges of kernel memory pages are not
    48  * supposed to figure in the list as they are shared by all tasks and
    49  * set up during system initialization.
    50  */
    51 typedef struct {
    52         /** Protected by asidlock. */
    53         link_t inactive_as_with_asid_link;
    54 
    55         mutex_t lock;
    56 
    57         /** Number of references (i.e tasks that reference this as). */
    58         count_t refcount;
    59 
    60         /** Number of processors on wich is this address space active. */
    61         count_t cpu_refcount;
    62 
    63         /** B+tree of address space areas. */
    64         btree_t as_area_btree;
    65 
    66         /** Address space identifier. Constant on architectures that do not support ASIDs.*/
    67         asid_t asid;
    68        
    69         /** Architecture specific content. */
    70         as_arch_t arch;
    71 } as_t;
     40#include <arch/types.h>
    7241
    7342typedef struct {
     43} as_genarch_t;
     44
     45struct as;
     46
     47typedef struct pte {
    7448        link_t link;            /**< Page hash table link. */
    75         as_t *as;               /**< Address space. */
     49        struct as *as;          /**< Address space. */
    7650        uintptr_t page;         /**< Virtual memory page. */
    7751        uintptr_t frame;        /**< Physical memory frame. */
  • kernel/genarch/include/mm/as_pt.h

    rfa8e7d2 r80bcaed  
    3737
    3838#include <mm/mm.h>
    39 #include <arch/mm/asid.h>
    40 #include <adt/list.h>
    41 #include <adt/btree.h>
    42 #include <synch/mutex.h>
     39#include <arch/types.h>
    4340
    4441#define AS_PAGE_TABLE
    4542
    46 /** Address space structure.
    47  *
    48  * as_t contains the list of as_areas of userspace accessible
    49  * pages for one or more tasks. Ranges of kernel memory pages are not
    50  * supposed to figure in the list as they are shared by all tasks and
    51  * set up during system initialization.
    52  */
    5343typedef struct {
    54         /** Protected by asidlock. */
    55         link_t inactive_as_with_asid_link;
    56 
    57         mutex_t lock;
    58 
    59         /** Number of references (i.e tasks that reference this as). */
    60         count_t refcount;
    61 
    62         /** Number of processors on wich is this address space active. */
    63         count_t cpu_refcount;
    64 
    65         /** B+tree of address space areas. */
    66         btree_t as_area_btree;
    67        
    6844        /** Page table pointer. */
    6945        pte_t *page_table;
    70 
    71         /** Address space identifier. Constant on architectures that do not support ASIDs.*/
    72         asid_t asid;
    73        
    74         /** Architecture specific content. */
    75         as_arch_t arch;
    76 } as_t;
     46} as_genarch_t;
    7747
    7848#endif
  • kernel/genarch/include/mm/page_ht.h

    rfa8e7d2 r80bcaed  
    6060#define PTE_EXECUTABLE(pte)     ((pte)->x != 0)
    6161
    62 #define SET_PTL0_ADDRESS(x)
    63 
    6462extern as_operations_t as_ht_operations;
    6563extern page_mapping_operations_t ht_mapping_operations;
  • kernel/genarch/src/mm/as_pt.c

    rfa8e7d2 r80bcaed  
    8686                ipl = interrupts_disable();
    8787                mutex_lock(&AS_KERNEL->lock);           
    88                 src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->page_table);
     88                src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    8989
    9090                src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
  • kernel/genarch/src/mm/page_pt.c

    rfa8e7d2 r80bcaed  
    7373        pte_t *newpt;
    7474
    75         ptl0 = (pte_t *) PA2KA((uintptr_t) as->page_table);
     75        ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    7676
    7777        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
     
    129129         */
    130130
    131         ptl0 = (pte_t *) PA2KA((uintptr_t) as->page_table);
     131        ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    132132
    133133        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
     
    245245        pte_t *ptl0, *ptl1, *ptl2, *ptl3;
    246246
    247         ptl0 = (pte_t *) PA2KA((uintptr_t) as->page_table);
     247        ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    248248
    249249        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
  • kernel/generic/include/adt/btree.h

    rfa8e7d2 r80bcaed  
    4949        count_t keys;
    5050
    51         /** Keys. We currently support only single keys. Additional room for one extra key is provided. */
     51        /**
     52         * Keys. We currently support only single keys. Additional room for one
     53         * extra key is provided.
     54         */
    5255        btree_key_t key[BTREE_MAX_KEYS + 1];
    5356
    5457        /**
    55          * Pointers to values. Sorted according to the key array. Defined only in leaf-level.
    56          * There is room for storing value for the extra key.
     58         * Pointers to values. Sorted according to the key array. Defined only in
     59         * leaf-level. There is room for storing value for the extra key.
    5760         */
    5861        void *value[BTREE_MAX_KEYS + 1];
    5962       
    6063        /**
    61          * Pointers to descendants of this node sorted according to the key array.
     64         * Pointers to descendants of this node sorted according to the key
     65         * array.
     66         *
    6267         * subtree[0] points to subtree with keys lesser than to key[0].
    63          * subtree[1] points to subtree with keys greater than or equal to key[0] and lesser than key[1].
     68         * subtree[1] points to subtree with keys greater than or equal to
     69         *            key[0] and lesser than key[1].
    6470         * ...
    6571         * There is room for storing a subtree pointer for the extra key.
     
    7076        struct btree_node *parent;
    7177
    72         /** Link connecting leaf-level nodes. Defined only when this node is a leaf. */
     78        /**
     79         * Link connecting leaf-level nodes. Defined only when this node is a
     80         * leaf. */
    7381        link_t leaf_link;
    7482
    75         /** Variables needed by btree_print(). */       
     83        /* Variables needed by btree_print(). */       
    7684        link_t bfs_link;
    7785        int depth;
     
    8997extern void btree_destroy(btree_t *t);
    9098
    91 extern void btree_insert(btree_t *t, btree_key_t key, void *value, btree_node_t *leaf_node);
     99extern void btree_insert(btree_t *t, btree_key_t key, void *value,
     100    btree_node_t *leaf_node);
    92101extern void btree_remove(btree_t *t, btree_key_t key, btree_node_t *leaf_node);
    93102extern void *btree_search(btree_t *t, btree_key_t key, btree_node_t **leaf_node);
    94103
    95 extern btree_node_t *btree_leaf_node_left_neighbour(btree_t *t, btree_node_t *node);
    96 extern btree_node_t *btree_leaf_node_right_neighbour(btree_t *t, btree_node_t *node);
     104extern btree_node_t *btree_leaf_node_left_neighbour(btree_t *t,
     105    btree_node_t *node);
     106extern btree_node_t *btree_leaf_node_right_neighbour(btree_t *t,
     107    btree_node_t *node);
    97108
    98109extern void btree_print(btree_t *t);
  • kernel/generic/include/adt/fifo.h

    rfa8e7d2 r80bcaed  
    107107 */
    108108#define fifo_push(name, value) \
    109         name.fifo[name.tail = (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value)
     109        name.fifo[name.tail = \
     110            (name.tail + 1) < name.items ? (name.tail + 1) : 0] = (value)
    110111
    111112/** Allocate memory for dynamic FIFO.
  • kernel/generic/include/adt/hash_table.h

    rfa8e7d2 r80bcaed  
    4343        /** Hash function.
    4444         *
    45          * @param key Array of keys needed to compute hash index. All keys must be passed.
     45         * @param key   Array of keys needed to compute hash index. All keys must
     46         *              be passed.
    4647         *
    4748         * @return Index into hash table.
     
    5152        /** Hash table item comparison function.
    5253         *
    53          * @param key Array of keys that will be compared with item. It is not necessary to pass all keys.
     54         * @param key   Array of keys that will be compared with item. It is not
     55         *              necessary to pass all keys.
    5456         *
    5557         * @return true if the keys match, false otherwise.
     
    7274} hash_table_t;
    7375
    74 #define hash_table_get_instance(item, type, member)     list_get_instance((item), type, member)
     76#define hash_table_get_instance(item, type, member) \
     77        list_get_instance((item), type, member)
    7578
    76 extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys, hash_table_operations_t *op);
     79extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys,
     80    hash_table_operations_t *op);
    7781extern void hash_table_insert(hash_table_t *h, unative_t key[], link_t *item);
    7882extern link_t *hash_table_find(hash_table_t *h, unative_t key[]);
  • kernel/generic/include/adt/list.h

    rfa8e7d2 r80bcaed  
    4848 * @param name Name of the new statically allocated list.
    4949 */
    50 #define LIST_INITIALIZE(name)           link_t name = { .prev = &name, .next = &name }
     50#define LIST_INITIALIZE(name) \
     51        link_t name = { .prev = &name, .next = &name }
    5152
    5253/** Initialize doubly-linked circular list link
     
    108109 * Remove item from doubly-linked circular list.
    109110 *
    110  * @param link Pointer to link_t structure to be removed from the list it is contained in.
     111 * @param link  Pointer to link_t structure to be removed from the list it is
     112 *              contained in.
    111113 */
    112114static inline void list_remove(link_t *link)
     
    136138 * concatenates splitted lists and splits concatenated lists.
    137139 *
    138  * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
    139  * @param part2 Pointer to link_t structure leading the second (half of the headless) list.
     140 * @param part1 Pointer to link_t structure leading the first (half of the
     141 *              headless) list.
     142 * @param part2 Pointer to link_t structure leading the second (half of the
     143 *              headless) list.
    140144 */
    141145static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     
    155159 * Split headless doubly-linked circular list.
    156160 *
    157  * @param part1 Pointer to link_t structure leading the first half of the headless list.
    158  * @param part2 Pointer to link_t structure leading the second half of the headless list.
     161 * @param part1 Pointer to link_t structure leading the first half of the
     162 *              headless list.
     163 * @param part2 Pointer to link_t structure leading the second half of the
     164 *              headless list.
    159165 */
    160166static inline void headless_list_split(link_t *part1, link_t *part2)
     
    168174 *
    169175 * @param part1 Pointer to link_t structure leading the first headless list.
    170  * @param part2 Pointer to link_t structure leading the second headless list. 
     176 * @param part2 Pointer to link_t structure leading the second headless list.
    171177 */
    172178static inline void headless_list_concat(link_t *part1, link_t *part2)
     
    175181}
    176182
    177 #define list_get_instance(link,type,member) (type *)(((uint8_t*)(link))-((uint8_t*)&(((type *)NULL)->member)))
     183#define list_get_instance(link,type,member) \
     184        ((type *)(((uint8_t *)(link)) - ((uint8_t *)&(((type *)NULL)->member))))
    178185
    179186extern bool list_member(const link_t *link, const link_t *head);
  • kernel/generic/include/console/chardev.h

    rfa8e7d2 r80bcaed  
    4646/* Character device operations interface. */
    4747typedef struct {
    48         void (* suspend)(struct chardev *);             /**< Suspend pushing characters. */
    49         void (* resume)(struct chardev *);              /**< Resume pushing characters. */
    50         void (* write)(struct chardev *, char c);       /**< Write character to stream. */
    51         /** Read character directly from device, assume interrupts disabled */
     48        /** Suspend pushing characters. */
     49        void (* suspend)(struct chardev *);
     50        /** Resume pushing characters. */
     51        void (* resume)(struct chardev *);
     52        /** Write character to stream. */
     53        void (* write)(struct chardev *, char c);
     54        /** Read character directly from device, assume interrupts disabled. */
    5255        char (* read)(struct chardev *);
    5356} chardev_operations_t;
     
    5861       
    5962        waitq_t wq;
    60         SPINLOCK_DECLARE(lock);         /**< Protects everything below. */
     63        /** Protects everything below. */
     64        SPINLOCK_DECLARE(lock);
    6165        uint8_t buffer[CHARDEV_BUFLEN];
    6266        count_t counter;
    63         chardev_operations_t *op;       /**< Implementation of chardev operations. */
     67        /** Implementation of chardev operations. */
     68        chardev_operations_t *op;
    6469        index_t index;
    6570        void *data;
    6671} chardev_t;
    6772
    68 extern void chardev_initialize(char *name,
    69                                chardev_t *chardev,
    70                                chardev_operations_t *op);
     73extern void chardev_initialize(char *name, chardev_t *chardev,
     74    chardev_operations_t *op);
    7175extern void chardev_push_character(chardev_t *chardev, uint8_t ch);
    7276
  • kernel/generic/include/console/kconsole.h

    rfa8e7d2 r80bcaed  
    4646        ARG_TYPE_INT,
    4747        ARG_TYPE_STRING,
    48         ARG_TYPE_VAR      /**< Variable type - either symbol or string */
     48        /** Variable type - either symbol or string. */
     49        ARG_TYPE_VAR     
    4950} cmd_arg_type_t;
    5051
    5152/** Structure representing one argument of kconsole command line. */
    5253typedef struct {
    53         cmd_arg_type_t type;            /**< Type descriptor. */
    54         void *buffer;                   /**< Buffer where to store data. */
    55         size_t len;                     /**< Size of the buffer. */
    56         unative_t intval;                /**< Integer value */
    57         cmd_arg_type_t vartype;         /**< Resulting type of variable arg */
     54        /** Type descriptor. */
     55        cmd_arg_type_t type;
     56        /** Buffer where to store data. */
     57        void *buffer;
     58        /** Size of the buffer. */
     59        size_t len;
     60        /** Integer value. */
     61        unative_t intval;
     62        /** Resulting type of variable arg */
     63        cmd_arg_type_t vartype;
    5864} cmd_arg_t;
    5965
    6066/** Structure representing one kconsole command. */
    6167typedef struct {
    62         link_t link;                    /**< Command list link. */
    63         SPINLOCK_DECLARE(lock);         /**< This lock protects everything below. */
    64         const char *name;               /**< Command name. */
    65         const char *description;        /**< Textual description. */
    66         int (* func)(cmd_arg_t *);      /**< Function implementing the command. */
    67         count_t argc;                   /**< Number of arguments. */
    68         cmd_arg_t *argv;                /**< Argument vector. */
    69         void (* help)(void);            /**< Function for printing detailed help. */
     68        /** Command list link. */
     69        link_t link;
     70        /** This lock protects everything below. */
     71        SPINLOCK_DECLARE(lock);
     72        /** Command name. */
     73        const char *name;
     74        /** Textual description. */
     75        const char *description;
     76        /** Function implementing the command. */
     77        int (* func)(cmd_arg_t *);
     78        /** Number of arguments. */
     79        count_t argc;
     80        /** Argument vector. */
     81        cmd_arg_t *argv;
     82        /** Function for printing detailed help. */
     83        void (* help)(void);
    7084} cmd_info_t;
    7185
  • kernel/generic/include/ddi/ddi_arg.h

    rfa8e7d2 r80bcaed  
    3838/** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
    3939typedef struct {
    40         unsigned long long task_id;     /** ID of the destination task. */
    41         void *phys_base;                /** Physical address of starting frame. */
    42         void *virt_base;                /** Virtual address of starting page. */
    43         unsigned long pages;            /** Number of pages to map. */
    44         int flags;                      /** Address space area flags for the mapping. */
     40        /** ID of the destination task. */
     41        unsigned long long task_id;
     42        /** Physical address of starting frame. */
     43        void *phys_base;
     44        /** Virtual address of starting page. */
     45        void *virt_base;
     46        /** Number of pages to map. */
     47        unsigned long pages;
     48        /** Address space area flags for the mapping. */
     49        int flags;
    4550} ddi_memarg_t;
    4651
    4752/** Structure encapsulating arguments for SYS_ENABLE_IOSPACE syscall. */
    4853typedef struct {
    49         unsigned long long task_id;     /** ID of the destination task. */
    50         void *ioaddr;                   /** Starting I/O space address. */
    51         unsigned long size;             /** Number of bytes. */
     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. */
    5257} ddi_ioarg_t;
    5358
  • kernel/generic/include/ddi/irq.h

    rfa8e7d2 r80bcaed  
    9292 */
    9393typedef struct {
    94         bool notify;                    /**< When false, notifications are not sent. */
    95         answerbox_t *answerbox;         /**< Answerbox for notifications. */
    96         unative_t method;               /**< Method to be used for the notification. */
    97         irq_code_t *code;               /**< Top-half pseudocode. */
    98         count_t counter;                /**< Counter. */
    99         link_t link;                    /**< Link between IRQs that are notifying the
    100                                              same answerbox. The list is protected by
    101                                              the answerbox irq_lock. */
     94        /** When false, notifications are not sent. */
     95        bool notify;
     96        /** Answerbox for notifications. */
     97        answerbox_t *answerbox;
     98        /** Method to be used for the notification. */
     99        unative_t method;
     100        /** Top-half pseudocode. */
     101        irq_code_t *code;
     102        /** Counter. */
     103        count_t counter;
     104        /**
     105         * Link between IRQs that are notifying the same answerbox. The list is
     106         * protected by the answerbox irq_lock.
     107         */
     108        link_t link;
    102109} ipc_notif_cfg_t;
    103110
    104111/** Structure representing one device IRQ.
    105112 *
    106  * If one device has multiple interrupts, there will
    107  * be multiple irq_t instantions with the same
    108  * devno.
     113 * If one device has multiple interrupts, there will be multiple irq_t
     114 * instantions with the same devno.
    109115 */
    110116typedef struct irq {
  • kernel/generic/include/ipc/ipc.h

    rfa8e7d2 r80bcaed  
    4848
    4949/* Flags for calls */
    50 #define IPC_CALL_ANSWERED       (1<<0) /**< This is answer to a call */
    51 #define IPC_CALL_STATIC_ALLOC   (1<<1) /**< This call will not be freed on error */
    52 #define IPC_CALL_DISCARD_ANSWER (1<<2) /**< Answer will not be passed to userspace, will be discarded */
    53 #define IPC_CALL_FORWARDED      (1<<3) /**< Call was forwarded */
    54 #define IPC_CALL_CONN_ME_TO     (1<<4) /**< Identify connect_me_to answer */
    55 #define IPC_CALL_NOTIF          (1<<5) /**< Interrupt notification */
     50
     51/** This is answer to a call */
     52#define IPC_CALL_ANSWERED       (1 << 0)
     53/** This call will not be freed on error */
     54#define IPC_CALL_STATIC_ALLOC   (1 << 1)
     55/** Answer will not be passed to userspace, will be discarded */
     56#define IPC_CALL_DISCARD_ANSWER (1 << 2)
     57/** Call was forwarded */
     58#define IPC_CALL_FORWARDED      (1 << 3)
     59/** Identify connect_me_to answer */
     60#define IPC_CALL_CONN_ME_TO     (1 << 4)
     61/** Interrupt notification */
     62#define IPC_CALL_NOTIF          (1 << 5)
    5663
    5764/* Flags of callid (the addresses are aligned at least to 4,
    5865 * that is why we can use bottom 2 bits of the call address
    5966 */
    60 #define IPC_CALLID_ANSWERED       1 /**< Type of this msg is 'answer' */
    61 #define IPC_CALLID_NOTIFICATION   2 /**< Type of this msg is 'notification' */
     67/** Type of this msg is 'answer' */
     68#define IPC_CALLID_ANSWERED     1
     69/** Type of this msg is 'notification' */
     70#define IPC_CALLID_NOTIFICATION 2
    6271
    6372/* Return values from IPC_ASYNC */
    64 #define IPC_CALLRET_FATAL         -1
    65 #define IPC_CALLRET_TEMPORARY     -2
     73#define IPC_CALLRET_FATAL       -1
     74#define IPC_CALLRET_TEMPORARY   -2
    6675
    6776
    6877/* Macros for manipulating calling data */
    69 #define IPC_SET_RETVAL(data, retval)   ((data).args[0] = (retval))
    70 #define IPC_SET_METHOD(data, val)   ((data).args[0] = (val))
    71 #define IPC_SET_ARG1(data, val)   ((data).args[1] = (val))
    72 #define IPC_SET_ARG2(data, val)   ((data).args[2] = (val))
    73 #define IPC_SET_ARG3(data, val)   ((data).args[3] = (val))
    74 
    75 #define IPC_GET_METHOD(data)           ((data).args[0])
    76 #define IPC_GET_RETVAL(data)           ((data).args[0])
    77 
    78 #define IPC_GET_ARG1(data)              ((data).args[1])
    79 #define IPC_GET_ARG2(data)              ((data).args[2])
    80 #define IPC_GET_ARG3(data)              ((data).args[3])
     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
     84#define IPC_GET_METHOD(data)            ((data).args[0])
     85#define IPC_GET_RETVAL(data)            ((data).args[0])
     86
     87#define IPC_GET_ARG1(data)              ((data).args[1])
     88#define IPC_GET_ARG2(data)              ((data).args[2])
     89#define IPC_GET_ARG3(data)              ((data).args[3])
    8190
    8291/* Well known phone descriptors */
    83 #define PHONE_NS              0
     92#define PHONE_NS        0
    8493
    8594/* System-specific methods - only through special syscalls
     
    167176
    168177typedef enum {
    169         IPC_PHONE_FREE = 0,     /**< Phone is free and can be allocated */
    170         IPC_PHONE_CONNECTING,   /**< Phone is connecting somewhere */
    171         IPC_PHONE_CONNECTED,    /**< Phone is connected */
    172         IPC_PHONE_HUNGUP,       /**< Phone is hung up, waiting for answers to come */
    173         IPC_PHONE_SLAMMED       /**< Phone was hungup from server */
     178        /** Phone is free and can be allocated */
     179        IPC_PHONE_FREE = 0,
     180        /** Phone is connecting somewhere */
     181        IPC_PHONE_CONNECTING,
     182        /** Phone is connected */
     183        IPC_PHONE_CONNECTED,
     184        /** Phone is hung up, waiting for answers to come */
     185        IPC_PHONE_HUNGUP,
     186        /** Phone was hungup from server */
     187        IPC_PHONE_SLAMMED
    174188} ipc_phone_state_t;
    175189
     
    190204        waitq_t wq;
    191205
    192         link_t connected_phones;        /**< Phones connected to this answerbox */
    193         link_t calls;                   /**< Received calls */
     206        /** Phones connected to this answerbox */
     207        link_t connected_phones;
     208        /** Received calls */
     209        link_t calls;                   
    194210        link_t dispatched_calls;        /* Should be hash table in the future */
    195211
    196         link_t answers;                 /**< Answered calls */
     212        /** Answered calls */
     213        link_t answers;
    197214
    198215        SPINLOCK_DECLARE(irq_lock);
    199         link_t irq_notifs;              /**< Notifications from IRQ handlers */
    200         link_t irq_head;                /**< IRQs with notifications to this answerbox. */
     216        /** Notifications from IRQ handlers */
     217        link_t irq_notifs;
     218        /** IRQs with notifications to this answerbox. */
     219        link_t irq_head;
    201220} answerbox_t;
    202221
     
    218237        answerbox_t *callerbox;
    219238
    220         unative_t priv; /**< Private data to internal IPC */
    221 
    222         ipc_data_t data;  /**< Data passed from/to userspace */
     239        /** Private data to internal IPC */
     240        unative_t priv;
     241
     242        /** Data passed from/to userspace */
     243        ipc_data_t data;
    223244} call_t;
    224245
  • kernel/generic/include/ipc/irq.h

    rfa8e7d2 r80bcaed  
    4444#include <adt/list.h>
    4545
    46 extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method,
    47         irq_code_t *ucode);
     46extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno,
     47    unative_t method, irq_code_t *ucode);
    4848extern void ipc_irq_send_notif(irq_t *irq);
    4949extern void ipc_irq_send_msg(irq_t *irq, unative_t a1, unative_t a2, unative_t a3);
  • kernel/generic/include/ipc/sysipc.h

    rfa8e7d2 r80bcaed  
    4141
    4242unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method,
    43                                 unative_t arg1, ipc_data_t *data);
    44 unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question, 
    45                            ipc_data_t *reply);
     43    unative_t arg1, ipc_data_t *data);
     44unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question,
     45    ipc_data_t *reply);
    4646unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method,
    47                                 unative_t arg1, unative_t arg2);
     47    unative_t arg1, unative_t arg2);
    4848unative_t sys_ipc_call_async(unative_t phoneid, ipc_data_t *data);
    4949unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval,
    50                              unative_t arg1, unative_t arg2);
     50    unative_t arg1, unative_t arg2);
    5151unative_t sys_ipc_answer(unative_t callid, ipc_data_t *data);
    52 unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec, int nonblocking);
     52unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
     53    int nonblocking);
    5354unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
    54                               unative_t method, unative_t arg1);
     55    unative_t method, unative_t arg1);
    5556unative_t sys_ipc_hangup(int phoneid);
    56 unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, irq_code_t *ucode);
     57unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
     58    irq_code_t *ucode);
    5759unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno);
    5860
  • kernel/generic/include/mm/as.h

    rfa8e7d2 r80bcaed  
    5454#include <lib/elf.h>
    5555
    56 /** Defined to be true if user address space and kernel address space shadow each other. */
     56/**
     57 * Defined to be true if user address space and kernel address space shadow each
     58 * other.
     59 */
    5760#define KERNEL_ADDRESS_SPACE_SHADOWED   KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
    5861
     
    6265#define USER_ADDRESS_SPACE_END          USER_ADDRESS_SPACE_END_ARCH
    6366
    64 #define USTACK_ADDRESS  USTACK_ADDRESS_ARCH
    65 
    66 #define FLAG_AS_KERNEL      (1 << 0)    /**< Kernel address space. */
    67 
    68 /** Address space area attributes. */
     67#define USTACK_ADDRESS                  USTACK_ADDRESS_ARCH
     68
     69/** Kernel address space. */
     70#define FLAG_AS_KERNEL                  (1 << 0)       
     71
     72/* Address space area attributes. */
    6973#define AS_AREA_ATTR_NONE       0
    7074#define AS_AREA_ATTR_PARTIAL    1       /**< Not fully initialized area. */
    7175
    72 #define AS_PF_FAULT             0       /**< The page fault was not resolved by as_page_fault(). */
    73 #define AS_PF_OK                1       /**< The page fault was resolved by as_page_fault(). */
    74 #define AS_PF_DEFER             2       /**< The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
     76/** The page fault was not resolved by as_page_fault(). */
     77#define AS_PF_FAULT             0
     78/** The page fault was resolved by as_page_fault(). */
     79#define AS_PF_OK                1
     80/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
     81#define AS_PF_DEFER             2
     82
     83/** Address space structure.
     84 *
     85 * as_t contains the list of as_areas of userspace accessible
     86 * pages for one or more tasks. Ranges of kernel memory pages are not
     87 * supposed to figure in the list as they are shared by all tasks and
     88 * set up during system initialization.
     89 */
     90typedef struct as {
     91        /** Protected by asidlock. */
     92        link_t inactive_as_with_asid_link;
     93
     94        mutex_t lock;
     95
     96        /** Number of references (i.e tasks that reference this as). */
     97        count_t refcount;
     98
     99        /** Number of processors on wich is this address space active. */
     100        count_t cpu_refcount;
     101
     102        /** B+tree of address space areas. */
     103        btree_t as_area_btree;
     104       
     105        /**
     106         *  Address space identifier.
     107         *  Constant on architectures that do not support ASIDs.
     108         */
     109        asid_t asid;
     110       
     111        /** Non-generic content. */
     112        as_genarch_t genarch;
     113
     114        /** Architecture specific content. */
     115        as_arch_t arch;
     116} as_t;
    75117
    76118typedef struct {
     
    81123} as_operations_t;
    82124
    83 /** This structure contains information associated with the shared address space area. */
     125/**
     126 * This structure contains information associated with the shared address space
     127 * area.
     128 */
    84129typedef struct {
    85         mutex_t lock;           /**< This lock must be acquired only when the as_area lock is held. */
    86         count_t refcount;       /**< This structure can be deallocated if refcount drops to 0. */
    87         btree_t pagemap;        /**< B+tree containing complete map of anonymous pages of the shared area. */
     130        /** This lock must be acquired only when the as_area lock is held. */
     131        mutex_t lock;           
     132        /** This structure can be deallocated if refcount drops to 0. */
     133        count_t refcount;
     134        /**
     135         * B+tree containing complete map of anonymous pages of the shared area.
     136         */
     137        btree_t pagemap;
    88138} share_info_t;
    89139
     
    116166typedef struct {
    117167        mutex_t lock;
    118         as_t *as;               /**< Containing address space. */
    119         int flags;              /**< Flags related to the memory represented by the address space area. */
    120         int attributes;         /**< Attributes related to the address space area itself. */
    121         count_t pages;          /**< Size of this area in multiples of PAGE_SIZE. */
    122         uintptr_t base;         /**< Base address of this area. */
    123         btree_t used_space;     /**< Map of used space. */
    124         share_info_t *sh_info;  /**< If the address space area has been shared, this pointer will
    125                                      reference the share info structure. */
    126         struct mem_backend *backend;    /**< Memory backend backing this address space area. */
     168        /** Containing address space. */
     169        as_t *as;               
     170        /** Flags related to the memory represented by the address space area. */
     171        int flags;
     172        /** Attributes related to the address space area itself. */
     173        int attributes;
     174        /** Size of this area in multiples of PAGE_SIZE. */
     175        count_t pages;
     176        /** Base address of this area. */
     177        uintptr_t base;
     178        /** Map of used space. */
     179        btree_t used_space;
     180
     181        /**
     182         * If the address space area has been shared, this pointer will reference
     183         * the share info structure.
     184         */
     185        share_info_t *sh_info;
     186
     187        /** Memory backend backing this address space area. */
     188        struct mem_backend *backend;
    127189
    128190        /** Data to be used by the backend. */
     
    147209extern as_t *as_create(int flags);
    148210extern void as_destroy(as_t *as);
    149 extern void as_switch(as_t *old, as_t *replace);
     211extern void as_switch(as_t *old_as, as_t *new_as);
    150212extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate);
    151213
    152 extern as_area_t *as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
    153         mem_backend_t *backend, mem_backend_data_t *backend_data);
     214extern as_area_t *as_area_create(as_t *as, int flags, size_t size,
     215    uintptr_t base, int attrs, mem_backend_t *backend,
     216    mem_backend_data_t *backend_data);
    154217extern int as_area_destroy(as_t *as, uintptr_t address);       
    155218extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags);
    156219int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
    157                   as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
     220    as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
    158221
    159222extern int as_area_get_flags(as_area_t *area);
  • kernel/generic/include/mm/buddy.h

    rfa8e7d2 r80bcaed  
    4545/** Buddy system operations to be implemented by each implementation. */
    4646typedef struct {
    47         /** Return pointer to left-side or right-side buddy for block passed as
    48           * argument. */
     47        /**
     48         * Return pointer to left-side or right-side buddy for block passed as
     49         * argument.
     50         */
    4951        link_t *(* find_buddy)(struct buddy_system *, link_t *);
    50         /** Bisect the block passed as argument and return pointer to the new
    51           * right-side buddy. */
     52        /**
     53         * Bisect the block passed as argument and return pointer to the new
     54         * right-side buddy.
     55         */
    5256        link_t *(* bisect)(struct buddy_system *, link_t *);
    5357        /** Coalesce two buddies into a bigger block. */
     
    7680
    7781extern void buddy_system_create(buddy_system_t *b, uint8_t max_order,
    78         buddy_system_operations_t *op, void *data);
     82    buddy_system_operations_t *op, void *data);
    7983extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i);
    8084extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order);
  • kernel/generic/include/mm/mm.h

    rfa8e7d2 r80bcaed  
    4747#define PAGE_GLOBAL_SHIFT               6
    4848
    49 #define PAGE_NOT_CACHEABLE      (0 << PAGE_CACHEABLE_SHIFT)
    50 #define PAGE_CACHEABLE          (1 << PAGE_CACHEABLE_SHIFT)
     49#define PAGE_NOT_CACHEABLE              (0 << PAGE_CACHEABLE_SHIFT)
     50#define PAGE_CACHEABLE                  (1 << PAGE_CACHEABLE_SHIFT)
    5151
    52 #define PAGE_PRESENT            (0 << PAGE_PRESENT_SHIFT)
    53 #define PAGE_NOT_PRESENT        (1 << PAGE_PRESENT_SHIFT)
     52#define PAGE_PRESENT                    (0 << PAGE_PRESENT_SHIFT)
     53#define PAGE_NOT_PRESENT                (1 << PAGE_PRESENT_SHIFT)
    5454
    55 #define PAGE_USER               (1 << PAGE_USER_SHIFT)
    56 #define PAGE_KERNEL             (0 << PAGE_USER_SHIFT)
     55#define PAGE_USER                       (1 << PAGE_USER_SHIFT)
     56#define PAGE_KERNEL                     (0 << PAGE_USER_SHIFT)
    5757
    58 #define PAGE_READ               (1 << PAGE_READ_SHIFT)
    59 #define PAGE_WRITE              (1 << PAGE_WRITE_SHIFT)
    60 #define PAGE_EXEC               (1 << PAGE_EXEC_SHIFT)
     58#define PAGE_READ                       (1 << PAGE_READ_SHIFT)
     59#define PAGE_WRITE                      (1 << PAGE_WRITE_SHIFT)
     60#define PAGE_EXEC                       (1 << PAGE_EXEC_SHIFT)
    6161
    62 #define PAGE_GLOBAL             (1 << PAGE_GLOBAL_SHIFT)
     62#define PAGE_GLOBAL                     (1 << PAGE_GLOBAL_SHIFT)
    6363
    6464#endif
  • kernel/generic/include/mm/page.h

    rfa8e7d2 r80bcaed  
    5959extern void page_table_unlock(as_t *as, bool unlock);
    6060extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
    61         int flags);
     61    int flags);
    6262extern void page_mapping_remove(as_t *as, uintptr_t page);
    6363extern pte_t *page_mapping_find(as_t *as, uintptr_t page);
  • kernel/generic/include/mm/slab.h

    rfa8e7d2 r80bcaed  
    5757
    5858/* slab_reclaim constants */
    59 #define SLAB_RECLAIM_ALL  0x1 /**< Reclaim all possible memory, because we are in memory stress */
     59
     60/** Reclaim all possible memory, because we are in memory stress */
     61#define SLAB_RECLAIM_ALL  0x1
    6062
    6163/* cache_create flags */
    62 #define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */
    63 #define SLAB_CACHE_SLINSIDE   0x2 /**< Have control structure inside SLAB */
    64 #define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE) /**< We add magazine cache later, if we have this flag */
     64
     65/** Do not use per-cpu cache */
     66#define SLAB_CACHE_NOMAGAZINE 0x1
     67/** Have control structure inside SLAB */
     68#define SLAB_CACHE_SLINSIDE   0x2
     69/** We add magazine cache later, if we have this flag */
     70#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE)
    6571
    6672typedef struct {
     
    8288
    8389        link_t link;
     90
    8491        /* Configuration */
    85         size_t size;            /**< Size of slab position - align_up(sizeof(obj)) */
     92        /** Size of slab position - align_up(sizeof(obj)) */
     93        size_t size;
     94
    8695        int (*constructor)(void *obj, int kmflag);
    8796        int (*destructor)(void *obj);
    88         int flags;              /**< Flags changing behaviour of cache */
     97
     98        /** Flags changing behaviour of cache */
     99        int flags;
    89100
    90101        /* Computed values */
     
    96107        atomic_t allocated_objs;
    97108        atomic_t cached_objs;
    98         atomic_t magazine_counter; /**< How many magazines in magazines list */
     109        /** How many magazines in magazines list */
     110        atomic_t magazine_counter;
    99111
    100112        /* Slabs */
     
    110122} slab_cache_t;
    111123
    112 extern slab_cache_t * slab_cache_create(char *name,
    113                                         size_t size,
    114                                         size_t align,
    115                                         int (*constructor)(void *obj, int kmflag),
    116                                         int (*destructor)(void *obj),
    117                                         int flags);
     124extern slab_cache_t * slab_cache_create(char *name, size_t size, size_t align,
     125    int (*constructor)(void *obj, int kmflag), int (*destructor)(void *obj),
     126    int flags);
    118127extern void slab_cache_destroy(slab_cache_t *cache);
    119128
     
    122131extern count_t slab_reclaim(int flags);
    123132
    124 /** Initialize slab subsytem */
     133/* slab subsytem initialization */
    125134extern void slab_cache_init(void);
    126135extern void slab_enable_cpucache(void);
  • kernel/generic/include/mm/tlb.h

    rfa8e7d2 r80bcaed  
    4040
    4141/**
    42  * Number of TLB shootdown messages that can be queued in processor
    43  * tlb_messages queue.
     42 * Number of TLB shootdown messages that can be queued in processor tlb_messages
     43 * queue.
    4444 */
    4545#define TLB_MESSAGE_QUEUE_LEN   10
     
    4747/** Type of TLB shootdown message. */
    4848typedef enum {
    49         TLB_INVL_INVALID = 0,           /**< Invalid type. */
    50         TLB_INVL_ALL,                   /**< Invalidate all entries in TLB. */
    51         TLB_INVL_ASID,                  /**< Invalidate all entries belonging to one address space. */
    52         TLB_INVL_PAGES                  /**< Invalidate specified page range belonging to one address space. */
     49        /** Invalid type. */
     50        TLB_INVL_INVALID = 0,
     51        /** Invalidate all entries in TLB. */
     52        TLB_INVL_ALL,
     53        /** Invalidate all entries belonging to one address space. */
     54        TLB_INVL_ASID,
     55        /** Invalidate specified page range belonging to one address space. */
     56        TLB_INVL_PAGES
    5357} tlb_invalidate_type_t;
    5458
     
    6468
    6569#ifdef CONFIG_SMP
    66 extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, uintptr_t page, count_t count);
     70extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
     71    uintptr_t page, count_t count);
    6772extern void tlb_shootdown_finalize(void);
    6873extern void tlb_shootdown_ipi_recv(void);
    6974#else
    70 #  define tlb_shootdown_start(w, x, y, z)
    71 #  define tlb_shootdown_finalize()
    72 #  define tlb_shootdown_ipi_recv()
     75#define tlb_shootdown_start(w, x, y, z)
     76#define tlb_shootdown_finalize()
     77#define tlb_shootdown_ipi_recv()
    7378#endif /* CONFIG_SMP */
    7479
  • kernel/generic/include/proc/task.h

    rfa8e7d2 r80bcaed  
    5959        /** Task lock.
    6060         *
    61          * Must be acquired before threads_lock and thread lock of any of its threads.
     61         * Must be acquired before threads_lock and thread lock of any of its
     62         * threads.
    6263         */
    6364        SPINLOCK_DECLARE(lock);
    6465       
    6566        char *name;
    66         struct thread *main_thread;     /**< Pointer to the main thread. */
    67         link_t th_head;         /**< List of threads contained in this task. */
    68         as_t *as;               /**< Address space. */
    69         task_id_t taskid;       /**< Unique identity of task */
    70         context_id_t context;   /**< Task security context */
     67        /** Pointer to the main thread. */
     68        struct thread *main_thread;
     69        /** List of threads contained in this task. */
     70        link_t th_head;
     71        /** Address space. */
     72        as_t *as;
     73        /** Unique identity of task. */
     74        task_id_t taskid;
     75        /** Task security context. */
     76        context_id_t context;   
    7177
    7278        /** If this is true, new threads can become part of the task. */
    7379        bool accept_new_threads;
     80        /** Number of references (i.e. threads). */
     81        count_t refcount;       
    7482
    75         count_t refcount;       /**< Number of references (i.e. threads). */
    76 
    77         cap_t capabilities;     /**< Task capabilities. */
     83        /** Task capabilities. */
     84        cap_t capabilities;     
    7885
    7986        /* IPC stuff */
    8087        answerbox_t answerbox;  /**< Communication endpoint */
    8188        phone_t phones[IPC_MAX_PHONES];
    82         atomic_t active_calls;  /**< Active asynchronous messages.
    83                                  *   It is used for limiting uspace to
    84                                  *   certain extent. */
     89        /**
     90         * Active asynchronous messages. It is used for limiting uspace to
     91         * certain extent.
     92         */
     93        atomic_t active_calls; 
    8594       
    86         task_arch_t arch;       /**< Architecture specific task data. */
     95        /** Architecture specific task data. */
     96        task_arch_t arch;       
    8797       
    8898        /**
     
    91101         */
    92102        mutex_t futexes_lock;
    93         btree_t futexes;        /**< B+tree of futexes referenced by this task. */
     103        /** B+tree of futexes referenced by this task. */
     104        btree_t futexes;       
    94105       
    95         uint64_t cycles;        /**< Accumulated accounting. */
     106        /** Accumulated accounting. */
     107        uint64_t cycles;
    96108} task_t;
    97109
  • kernel/generic/include/proc/thread.h

    rfa8e7d2 r80bcaed  
    5353
    5454/* Thread flags */
    55 #define THREAD_FLAG_WIRED       (1 << 0)        /**< Thread cannot be migrated to another CPU. */
    56 #define THREAD_FLAG_STOLEN      (1 << 1)        /**< Thread was migrated to another CPU and has not run yet. */
    57 #define THREAD_FLAG_USPACE      (1 << 2)        /**< Thread executes in userspace. */
     55
     56/** Thread cannot be migrated to another CPU. */
     57#define THREAD_FLAG_WIRED       (1 << 0)
     58/** Thread was migrated to another CPU and has not run yet. */
     59#define THREAD_FLAG_STOLEN      (1 << 1)
     60/** Thread executes in userspace. */
     61#define THREAD_FLAG_USPACE      (1 << 2)
    5862
    5963/** Thread states. */
    6064typedef enum {
    61         Invalid,        /**< It is an error, if thread is found in this state. */
    62         Running,        /**< State of a thread that is currently executing on some CPU. */
    63         Sleeping,       /**< Thread in this state is waiting for an event. */
    64         Ready,          /**< State of threads in a run queue. */
    65         Entering,       /**< Threads are in this state before they are first readied. */
    66         Exiting,        /**< After a thread calls thread_exit(), it is put into Exiting state. */
    67         Undead          /**< Threads that were not detached but exited are in the Undead state. */
     65        /** It is an error, if thread is found in this state. */
     66        Invalid,
     67        /** State of a thread that is currently executing on some CPU. */
     68        Running,
     69        /** Thread in this state is waiting for an event. */
     70        Sleeping,
     71        /** State of threads in a run queue. */
     72        Ready,
     73        /** Threads are in this state before they are first readied. */
     74        Entering,
     75        /** After a thread calls thread_exit(), it is put into Exiting state. */
     76        Exiting,
     77        /** Threads that were not detached but exited are in the Undead state. */
     78        Undead
    6879} state_t;
    6980
     
    7788/** Thread structure. There is one per thread. */
    7889typedef struct thread {
    79         link_t rq_link;                         /**< Run queue link. */
    80         link_t wq_link;                         /**< Wait queue link. */
    81         link_t th_link;                         /**< Links to threads within containing task. */
     90        link_t rq_link;         /**< Run queue link. */
     91        link_t wq_link;         /**< Wait queue link. */
     92        link_t th_link;         /**< Links to threads within containing task. */
    8293       
    8394        /** Lock protecting thread structure.
     
    89100        char name[THREAD_NAME_BUFLEN];
    90101
    91         void (* thread_code)(void *);           /**< Function implementing the thread. */
    92         void *thread_arg;                       /**< Argument passed to thread_code() function. */
    93 
    94         /** From here, the stored context is restored when the thread is scheduled. */
     102        /** Function implementing the thread. */
     103        void (* thread_code)(void *);
     104        /** Argument passed to thread_code() function. */
     105        void *thread_arg;
     106
     107        /**
     108         * From here, the stored context is restored when the thread is
     109         * scheduled.
     110         */
    95111        context_t saved_context;
    96         /** From here, the stored timeout context is restored when sleep times out. */
     112        /**
     113         * From here, the stored timeout context is restored when sleep times
     114         * out.
     115         */
    97116        context_t sleep_timeout_context;
    98         /** From here, the stored interruption context is restored when sleep is interrupted. */
     117        /**
     118         * From here, the stored interruption context is restored when sleep is
     119         * interrupted.
     120         */
    99121        context_t sleep_interruption_context;
    100122
    101         bool sleep_interruptible;               /**< If true, the thread can be interrupted from sleep. */
    102         waitq_t *sleep_queue;                   /**< Wait queue in which this thread sleeps. */
    103         timeout_t sleep_timeout;                /**< Timeout used for timeoutable sleeping.  */
    104         volatile int timeout_pending;           /**< Flag signalling sleep timeout in progress. */
    105 
    106         /** True if this thread is executing copy_from_uspace(). False otherwise. */
     123        /** If true, the thread can be interrupted from sleep. */
     124        bool sleep_interruptible;
     125        /** Wait queue in which this thread sleeps. */
     126        waitq_t *sleep_queue;
     127        /** Timeout used for timeoutable sleeping.  */
     128        timeout_t sleep_timeout;
     129        /** Flag signalling sleep timeout in progress. */
     130        volatile int timeout_pending;
     131
     132        /**
     133         * True if this thread is executing copy_from_uspace().
     134         * False otherwise.
     135         */
    107136        bool in_copy_from_uspace;
    108         /** True if this thread is executing copy_to_uspace(). False otherwise. */
     137        /**
     138         * True if this thread is executing copy_to_uspace().
     139         * False otherwise.
     140         */
    109141        bool in_copy_to_uspace;
    110142       
    111143        /**
    112          * If true, the thread will not go to sleep at all and will
    113          * call thread_exit() before returning to userspace.
     144         * If true, the thread will not go to sleep at all and will call
     145         * thread_exit() before returning to userspace.
    114146         */
    115147        bool interrupted;                       
    116148       
    117         thread_join_type_t      join_type;      /**< Who joinins the thread. */
    118         bool detached;                          /**< If true, thread_join_timeout() cannot be used on this thread. */
    119         waitq_t join_wq;                        /**< Waitq for thread_join_timeout(). */
     149        /** Who joinins the thread. */
     150        thread_join_type_t join_type;
     151        /** If true, thread_join_timeout() cannot be used on this thread. */
     152        bool detached;
     153        /** Waitq for thread_join_timeout(). */
     154        waitq_t join_wq;
    120155
    121156        fpu_context_t *saved_fpu_context;
     
    124159        /*
    125160         * Defined only if thread doesn't run.
    126          * It means that fpu context is in CPU that last time executes this thread.
    127          * This disables migration.
     161         * It means that fpu context is in CPU that last time executes this
     162         * thread. This disables migration.
    128163         */
    129164        int fpu_context_engaged;
     
    131166        rwlock_type_t rwlock_holder_type;
    132167
    133         void (* call_me)(void *);               /**< Funtion to be called in scheduler before the thread is put asleep. */
    134         void *call_me_with;                     /**< Argument passed to call_me(). */
    135 
    136         state_t state;                          /**< Thread's state. */
    137         int flags;                              /**< Thread's flags. */
    138        
    139         cpu_t *cpu;                             /**< Thread's CPU. */
    140         task_t *task;                           /**< Containing task. */
    141 
    142         uint64_t ticks;                         /**< Ticks before preemption. */
    143        
    144         uint64_t cycles;                        /**< Thread accounting. */
    145         uint64_t last_cycle;            /**< Last sampled cycle. */
    146         bool uncounted;                         /**< Thread doesn't affect accumulated accounting. */
    147 
    148         int priority;                           /**< Thread's priority. Implemented as index to CPU->rq */
    149         uint32_t tid;                           /**< Thread ID. */
    150        
    151         thread_arch_t arch;                     /**< Architecture-specific data. */
    152 
    153         uint8_t *kstack;                        /**< Thread's kernel stack. */
     168        /** Callback fired in scheduler before the thread is put asleep. */
     169        void (* call_me)(void *);
     170        /** Argument passed to call_me(). */
     171        void *call_me_with;
     172
     173        /** Thread's state. */
     174        state_t state;
     175        /** Thread's flags. */
     176        int flags;
     177       
     178        /** Thread's CPU. */
     179        cpu_t *cpu;
     180        /** Containing task. */
     181        task_t *task;
     182
     183        /** Ticks before preemption. */
     184        uint64_t ticks;
     185       
     186        /** Thread accounting. */
     187        uint64_t cycles;
     188        /** Last sampled cycle. */
     189        uint64_t last_cycle;
     190        /** Thread doesn't affect accumulated accounting. */   
     191        bool uncounted;
     192
     193        /** Thread's priority. Implemented as index to CPU->rq */
     194        int priority;
     195        /** Thread ID. */
     196        uint32_t tid;
     197       
     198        /** Architecture-specific data. */
     199        thread_arch_t arch;
     200
     201        /** Thread's kernel stack. */
     202        uint8_t *kstack;
    154203} thread_t;
    155204
     
    162211SPINLOCK_EXTERN(threads_lock);
    163212
    164 extern btree_t threads_btree;                   /**< B+tree containing all threads. */
     213/** B+tree containing all threads. */
     214extern btree_t threads_btree;
    165215
    166216extern void thread_init(void);
    167 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted);
     217extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
     218    int flags, char *name, bool uncounted);
    168219extern void thread_ready(thread_t *t);
    169220extern void thread_exit(void) __attribute__((noreturn));
     
    182233extern void thread_usleep(uint32_t usec);
    183234
    184 #define thread_join(t)  thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
     235#define thread_join(t) \
     236        thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    185237extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags);
    186238extern void thread_detach(thread_t *t);
    187239
    188 extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with);
     240extern void thread_register_call_me(void (* call_me)(void *),
     241    void *call_me_with);
    189242extern void thread_print_list(void);
    190243extern void thread_destroy(thread_t *t);
     
    193246extern void thread_interrupt_sleep(thread_t *t);
    194247
    195 /* Fpu context slab cache */
     248/** Fpu context slab cache. */
    196249extern slab_cache_t *fpu_context_slab;
    197250
    198 /** Thread syscall prototypes. */
     251/* Thread syscall prototypes. */
    199252unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name);
    200253unative_t sys_thread_exit(int uspace_status);
  • kernel/generic/include/synch/condvar.h

    rfa8e7d2 r80bcaed  
    4545} condvar_t;
    4646
    47 #define condvar_wait(cv,mtx) \
    48         _condvar_wait_timeout((cv),(mtx),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
    49 #define condvar_wait_timeout(cv,mtx,usec) \
    50         _condvar_wait_timeout((cv),(mtx),(usec),SYNCH_FLAGS_NONE)
     47#define condvar_wait(cv, mtx) \
     48        _condvar_wait_timeout((cv), (mtx), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
     49#define condvar_wait_timeout(cv, mtx, usec) \
     50        _condvar_wait_timeout((cv), (mtx), (usec), SYNCH_FLAGS_NONE)
    5151
    5252extern void condvar_initialize(condvar_t *cv);
    5353extern void condvar_signal(condvar_t *cv);
    5454extern void condvar_broadcast(condvar_t *cv);
    55 extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags);
     55extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec,
     56    int flags);
    5657
    5758#endif
  • kernel/generic/include/synch/futex.h

    rfa8e7d2 r80bcaed  
    4343/** Kernel-side futex structure. */
    4444typedef struct {
    45         uintptr_t paddr;        /**< Physical address of the status variable. */
    46         waitq_t wq;             /**< Wait queue for threads waiting for futex availability. */
    47         link_t ht_link;         /**< Futex hash table link. */
    48         count_t refcount;       /**< Number of tasks that reference this futex. */
     45        /** Physical address of the status variable. */
     46        uintptr_t paddr;
     47        /** Wait queue for threads waiting for futex availability. */
     48        waitq_t wq;
     49        /** Futex hash table link. */
     50        link_t ht_link;
     51        /** Number of tasks that reference this futex. */
     52        count_t refcount;
    4953} futex_t;
    5054
    5155extern void futex_init(void);
    52 extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec, int flags);
     56extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec,
     57    int flags);
    5358extern unative_t sys_futex_wakeup(uintptr_t uaddr);
    5459
  • kernel/generic/include/synch/rwlock.h

    rfa8e7d2 r80bcaed  
    4949typedef struct {
    5050        SPINLOCK_DECLARE(lock);
    51         mutex_t exclusive;      /**< Mutex for writers, readers can bypass it if readers_in is positive. */
    52         count_t readers_in;     /**< Number of readers in critical section. */
     51        /**
     52         * Mutex for writers, readers can bypass it if readers_in is positive.
     53         */
     54        mutex_t exclusive;
     55        /** Number of readers in critical section. */
     56        count_t readers_in;
    5357} rwlock_t;
    5458
    5559#define rwlock_write_lock(rwl) \
    56         _rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
     60        _rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    5761#define rwlock_read_lock(rwl) \
    58         _rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NONE)
     62        _rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    5963#define rwlock_write_trylock(rwl) \
    60         _rwlock_write_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
     64        _rwlock_write_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
     65            SYNCH_FLAGS_NON_BLOCKING)
    6166#define rwlock_read_trylock(rwl) \
    62         _rwlock_read_lock_timeout((rwl),SYNCH_NO_TIMEOUT,SYNCH_FLAGS_NON_BLOCKING)
    63 #define rwlock_write_lock_timeout(rwl,usec) \
    64         _rwlock_write_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
    65 #define rwlock_read_lock_timeout(rwl,usec) \
    66         _rwlock_read_lock_timeout((rwl),(usec),SYNCH_FLAGS_NONE)
     67        _rwlock_read_lock_timeout((rwl), SYNCH_NO_TIMEOUT, \
     68            SYNCH_FLAGS_NON_BLOCKING)
     69#define rwlock_write_lock_timeout(rwl, usec) \
     70        _rwlock_write_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
     71#define rwlock_read_lock_timeout(rwl, usec) \
     72        _rwlock_read_lock_timeout((rwl), (usec), SYNCH_FLAGS_NONE)
    6773
    6874extern void rwlock_initialize(rwlock_t *rwl);
  • kernel/generic/include/synch/semaphore.h

    rfa8e7d2 r80bcaed  
    4747        _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    4848#define semaphore_trydown(s) \
    49         _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)       
     49        _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING)
    5050#define semaphore_down_timeout(s, usec) \
    5151        _semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE)
  • kernel/generic/include/synch/synch.h

    rfa8e7d2 r80bcaed  
    3636#define KERN_SYNCH_H_
    3737
    38 #define SYNCH_NO_TIMEOUT        0       /**< Request with no timeout. */
     38/** Request with no timeout. */
     39#define SYNCH_NO_TIMEOUT        0
    3940
    40 #define SYNCH_FLAGS_NONE                0       /**< No flags specified. */
    41 #define SYNCH_FLAGS_NON_BLOCKING        (1<<0)  /**< Non-blocking operation request. */
    42 #define SYNCH_FLAGS_INTERRUPTIBLE       (1<<1)  /**< Interruptible operation. */
     41/** No flags specified. */
     42#define SYNCH_FLAGS_NONE                0
     43/** Non-blocking operation request. */
     44#define SYNCH_FLAGS_NON_BLOCKING        (1 << 0)
     45/** Interruptible operation. */
     46#define SYNCH_FLAGS_INTERRUPTIBLE       (1 << 1)
    4347
    44 #define ESYNCH_WOULD_BLOCK      1       /**< Could not satisfy the request without going to sleep. */
    45 #define ESYNCH_TIMEOUT          2       /**< Timeout occurred. */
    46 #define ESYNCH_INTERRUPTED      4       /**< Sleep was interrupted. */
    47 #define ESYNCH_OK_ATOMIC        8       /**< Operation succeeded without sleeping. */
    48 #define ESYNCH_OK_BLOCKED       16      /**< Operation succeeded and did sleep. */
     48/** Could not satisfy the request without going to sleep. */
     49#define ESYNCH_WOULD_BLOCK      1
     50/** Timeout occurred. */
     51#define ESYNCH_TIMEOUT          2
     52/** Sleep was interrupted. */
     53#define ESYNCH_INTERRUPTED      4
     54/** Operation succeeded without sleeping. */
     55#define ESYNCH_OK_ATOMIC        8
     56/** Operation succeeded and did sleep. */
     57#define ESYNCH_OK_BLOCKED       16
    4958
    50 #define SYNCH_FAILED(rc)        ((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
    51 #define SYNCH_OK(rc)            ((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
     59#define SYNCH_FAILED(rc) \
     60        ((rc) & (ESYNCH_WOULD_BLOCK | ESYNCH_TIMEOUT | ESYNCH_INTERRUPTED))
     61#define SYNCH_OK(rc) \
     62        ((rc) & (ESYNCH_OK_ATOMIC | ESYNCH_OK_BLOCKED))
    5263
    5364#endif
  • kernel/generic/include/synch/waitq.h

    rfa8e7d2 r80bcaed  
    5353        SPINLOCK_DECLARE(lock);
    5454
    55         int missed_wakeups;     /**< Number of waitq_wakeup() calls that didn't find a thread to wake up. */
    56         link_t head;            /**< List of sleeping threads for wich there was no missed_wakeup. */
     55        /**
     56         * Number of waitq_wakeup() calls that didn't find a thread to wake up.
     57         */
     58        int missed_wakeups;
     59        /** List of sleeping threads for wich there was no missed_wakeup. */
     60        link_t head;
    5761} waitq_t;
    5862
  • kernel/generic/include/time/timeout.h

    rfa8e7d2 r80bcaed  
    4545        SPINLOCK_DECLARE(lock);
    4646
    47         link_t link;                    /**< Link to the list of active timeouts on THE->cpu */
    48        
    49         uint64_t ticks;                 /**< Timeout will be activated in this amount of clock() ticks. */
    50 
    51         timeout_handler_t handler;      /**< Function that will be called on timeout activation. */
    52         void *arg;                      /**< Argument to be passed to handler() function. */
    53        
    54         cpu_t *cpu;                     /**< On which processor is this timeout registered. */
     47        /** Link to the list of active timeouts on THE->cpu */
     48        link_t link;
     49        /** Timeout will be activated in this amount of clock() ticks. */       
     50        uint64_t ticks;
     51        /** Function that will be called on timeout activation. */
     52        timeout_handler_t handler;
     53        /** Argument to be passed to handler() function. */
     54        void *arg;
     55        /** On which processor is this timeout registered. */
     56        cpu_t *cpu;
    5557} timeout_t;
    5658
     
    6062extern void timeout_initialize(timeout_t *t);
    6163extern void timeout_reinitialize(timeout_t *t);
    62 extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f, void *arg);
     64extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f,
     65    void *arg);
    6366extern bool timeout_unregister(timeout_t *t);
    6467
  • kernel/generic/src/mm/as.c

    rfa8e7d2 r80bcaed  
    169169        as->cpu_refcount = 0;
    170170#ifdef AS_PAGE_TABLE
    171         as->page_table = page_table_create(flags);
     171        as->genarch.page_table = page_table_create(flags);
    172172#else
    173173        page_table_create(flags);
     
    221221        btree_destroy(&as->as_area_btree);
    222222#ifdef AS_PAGE_TABLE
    223         page_table_destroy(as->page_table);
     223        page_table_destroy(as->genarch.page_table);
    224224#else
    225225        page_table_destroy(NULL);
     
    864864 * @param new New address space.
    865865 */
    866 void as_switch(as_t *old, as_t *replace)
     866void as_switch(as_t *old_as, as_t *new_as)
    867867{
    868868        ipl_t ipl;
     
    875875         * First, take care of the old address space.
    876876         */     
    877         if (old) {
    878                 mutex_lock_active(&old->lock);
    879                 ASSERT(old->cpu_refcount);
    880                 if((--old->cpu_refcount == 0) && (old != AS_KERNEL)) {
     877        if (old_as) {
     878                mutex_lock_active(&old_as->lock);
     879                ASSERT(old_as->cpu_refcount);
     880                if((--old_as->cpu_refcount == 0) && (old_as != AS_KERNEL)) {
    881881                        /*
    882882                         * The old address space is no longer active on
     
    885885                         * ASID.
    886886                         */
    887                          ASSERT(old->asid != ASID_INVALID);
    888                          list_append(&old->inactive_as_with_asid_link,
     887                         ASSERT(old_as->asid != ASID_INVALID);
     888                         list_append(&old_as->inactive_as_with_asid_link,
    889889                             &inactive_as_with_asid_head);
    890890                }
    891                 mutex_unlock(&old->lock);
     891                mutex_unlock(&old_as->lock);
    892892
    893893                /*
     
    895895                 * is being removed from the CPU.
    896896                 */
    897                 as_deinstall_arch(old);
     897                as_deinstall_arch(old_as);
    898898        }
    899899
     
    901901         * Second, prepare the new address space.
    902902         */
    903         mutex_lock_active(&replace->lock);
    904         if ((replace->cpu_refcount++ == 0) && (replace != AS_KERNEL)) {
    905                 if (replace->asid != ASID_INVALID) {
    906                         list_remove(&replace->inactive_as_with_asid_link);
     903        mutex_lock_active(&new_as->lock);
     904        if ((new_as->cpu_refcount++ == 0) && (new_as != AS_KERNEL)) {
     905                if (new_as->asid != ASID_INVALID) {
     906                        list_remove(&new_as->inactive_as_with_asid_link);
    907907                } else {
    908908                        /*
    909                          * Defer call to asid_get() until replace->lock is released.
     909                         * Defer call to asid_get() until new_as->lock is released.
    910910                         */
    911911                        needs_asid = true;
    912912                }
    913913        }
    914         SET_PTL0_ADDRESS(replace->page_table);
    915         mutex_unlock(&replace->lock);
     914#ifdef AS_PAGE_TABLE
     915        SET_PTL0_ADDRESS(new_as->genarch.page_table);
     916#endif
     917        mutex_unlock(&new_as->lock);
    916918
    917919        if (needs_asid) {
     
    923925               
    924926                asid = asid_get();
    925                 mutex_lock_active(&replace->lock);
    926                 replace->asid = asid;
    927                 mutex_unlock(&replace->lock);
     927                mutex_lock_active(&new_as->lock);
     928                new_as->asid = asid;
     929                mutex_unlock(&new_as->lock);
    928930        }
    929931        spinlock_unlock(&inactive_as_with_asid_lock);
     
    934936         * (e.g. write ASID to hardware register etc.)
    935937         */
    936         as_install_arch(replace);
    937        
    938         AS = replace;
     938        as_install_arch(new_as);
     939       
     940        AS = new_as;
    939941}
    940942
Note: See TracChangeset for help on using the changeset viewer.