Changeset 80bcaed in mainline
- Timestamp:
- 2007-02-03T13:22:24Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f619ec11
- Parents:
- fa8e7d2
- Location:
- kernel
- Files:
-
- 37 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/src/mm/page.c
rfa8e7d2 r80bcaed 112 112 113 113 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); 118 118 } 119 119 } -
kernel/arch/amd64/src/pm.c
rfa8e7d2 r80bcaed 202 202 * non boot-mapped pointer, initialize the CR3 register 203 203 * ahead of page_init */ 204 write_cr3((uintptr_t) AS_KERNEL-> page_table);204 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); 205 205 206 206 tss_p = (struct tss *) malloc(sizeof(tss_t), FRAME_ATOMIC); -
kernel/arch/ia32/src/mm/page.c
rfa8e7d2 r80bcaed 69 69 70 70 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); 72 72 } 73 73 else { 74 write_cr3((uintptr_t) AS_KERNEL-> page_table);74 write_cr3((uintptr_t) AS_KERNEL->genarch.page_table); 75 75 } 76 76 -
kernel/arch/ia32xen/src/mm/page.c
rfa8e7d2 r80bcaed 54 54 if (config.cpu_active == 1) { 55 55 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); 57 57 } else 58 SET_PTL0_ADDRESS_ARCH(AS_KERNEL-> page_table);58 SET_PTL0_ADDRESS_ARCH(AS_KERNEL->genarch.page_table); 59 59 } 60 60 -
kernel/arch/sparc64/include/mm/tsb.h
rfa8e7d2 r80bcaed 55 55 #include <arch/mm/mmu.h> 56 56 #include <arch/types.h> 57 #include <mm/as.h>58 57 59 58 /** TSB Base register. */ … … 109 108 } 110 109 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. */ 111 struct as; 112 struct pte; 113 114 extern void tsb_invalidate(struct as *as, uintptr_t page, count_t pages); 115 extern void itsb_pte_copy(struct pte *t); 116 extern void dtsb_pte_copy(struct pte *t, bool ro); 114 117 115 118 #endif /* !def __ASM__ */ -
kernel/genarch/include/mm/as_ht.h
rfa8e7d2 r80bcaed 37 37 38 38 #include <mm/mm.h> 39 #include <arch/mm/asid.h>40 39 #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> 72 41 73 42 typedef struct { 43 } as_genarch_t; 44 45 struct as; 46 47 typedef struct pte { 74 48 link_t link; /**< Page hash table link. */ 75 as_t*as; /**< Address space. */49 struct as *as; /**< Address space. */ 76 50 uintptr_t page; /**< Virtual memory page. */ 77 51 uintptr_t frame; /**< Physical memory frame. */ -
kernel/genarch/include/mm/as_pt.h
rfa8e7d2 r80bcaed 37 37 38 38 #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> 43 40 44 41 #define AS_PAGE_TABLE 45 42 46 /** Address space structure.47 *48 * as_t contains the list of as_areas of userspace accessible49 * pages for one or more tasks. Ranges of kernel memory pages are not50 * supposed to figure in the list as they are shared by all tasks and51 * set up during system initialization.52 */53 43 typedef 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 68 44 /** Page table pointer. */ 69 45 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; 77 47 78 48 #endif -
kernel/genarch/include/mm/page_ht.h
rfa8e7d2 r80bcaed 60 60 #define PTE_EXECUTABLE(pte) ((pte)->x != 0) 61 61 62 #define SET_PTL0_ADDRESS(x)63 64 62 extern as_operations_t as_ht_operations; 65 63 extern page_mapping_operations_t ht_mapping_operations; -
kernel/genarch/src/mm/as_pt.c
rfa8e7d2 r80bcaed 86 86 ipl = interrupts_disable(); 87 87 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); 89 89 90 90 src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)]; -
kernel/genarch/src/mm/page_pt.c
rfa8e7d2 r80bcaed 73 73 pte_t *newpt; 74 74 75 ptl0 = (pte_t *) PA2KA((uintptr_t) as-> page_table);75 ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table); 76 76 77 77 if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) { … … 129 129 */ 130 130 131 ptl0 = (pte_t *) PA2KA((uintptr_t) as-> page_table);131 ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table); 132 132 133 133 if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) … … 245 245 pte_t *ptl0, *ptl1, *ptl2, *ptl3; 246 246 247 ptl0 = (pte_t *) PA2KA((uintptr_t) as-> page_table);247 ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table); 248 248 249 249 if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) -
kernel/generic/include/adt/btree.h
rfa8e7d2 r80bcaed 49 49 count_t keys; 50 50 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 */ 52 55 btree_key_t key[BTREE_MAX_KEYS + 1]; 53 56 54 57 /** 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. 57 60 */ 58 61 void *value[BTREE_MAX_KEYS + 1]; 59 62 60 63 /** 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 * 62 67 * 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]. 64 70 * ... 65 71 * There is room for storing a subtree pointer for the extra key. … … 70 76 struct btree_node *parent; 71 77 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. */ 73 81 link_t leaf_link; 74 82 75 /* *Variables needed by btree_print(). */83 /* Variables needed by btree_print(). */ 76 84 link_t bfs_link; 77 85 int depth; … … 89 97 extern void btree_destroy(btree_t *t); 90 98 91 extern void btree_insert(btree_t *t, btree_key_t key, void *value, btree_node_t *leaf_node); 99 extern void btree_insert(btree_t *t, btree_key_t key, void *value, 100 btree_node_t *leaf_node); 92 101 extern void btree_remove(btree_t *t, btree_key_t key, btree_node_t *leaf_node); 93 102 extern void *btree_search(btree_t *t, btree_key_t key, btree_node_t **leaf_node); 94 103 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); 104 extern btree_node_t *btree_leaf_node_left_neighbour(btree_t *t, 105 btree_node_t *node); 106 extern btree_node_t *btree_leaf_node_right_neighbour(btree_t *t, 107 btree_node_t *node); 97 108 98 109 extern void btree_print(btree_t *t); -
kernel/generic/include/adt/fifo.h
rfa8e7d2 r80bcaed 107 107 */ 108 108 #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) 110 111 111 112 /** Allocate memory for dynamic FIFO. -
kernel/generic/include/adt/hash_table.h
rfa8e7d2 r80bcaed 43 43 /** Hash function. 44 44 * 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. 46 47 * 47 48 * @return Index into hash table. … … 51 52 /** Hash table item comparison function. 52 53 * 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. 54 56 * 55 57 * @return true if the keys match, false otherwise. … … 72 74 } hash_table_t; 73 75 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) 75 78 76 extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys, hash_table_operations_t *op); 79 extern void hash_table_create(hash_table_t *h, count_t m, count_t max_keys, 80 hash_table_operations_t *op); 77 81 extern void hash_table_insert(hash_table_t *h, unative_t key[], link_t *item); 78 82 extern link_t *hash_table_find(hash_table_t *h, unative_t key[]); -
kernel/generic/include/adt/list.h
rfa8e7d2 r80bcaed 48 48 * @param name Name of the new statically allocated list. 49 49 */ 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 } 51 52 52 53 /** Initialize doubly-linked circular list link … … 108 109 * Remove item from doubly-linked circular list. 109 110 * 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. 111 113 */ 112 114 static inline void list_remove(link_t *link) … … 136 138 * concatenates splitted lists and splits concatenated lists. 137 139 * 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. 140 144 */ 141 145 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) … … 155 159 * Split headless doubly-linked circular list. 156 160 * 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. 159 165 */ 160 166 static inline void headless_list_split(link_t *part1, link_t *part2) … … 168 174 * 169 175 * @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. 171 177 */ 172 178 static inline void headless_list_concat(link_t *part1, link_t *part2) … … 175 181 } 176 182 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)))) 178 185 179 186 extern bool list_member(const link_t *link, const link_t *head); -
kernel/generic/include/console/chardev.h
rfa8e7d2 r80bcaed 46 46 /* Character device operations interface. */ 47 47 typedef 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. */ 52 55 char (* read)(struct chardev *); 53 56 } chardev_operations_t; … … 58 61 59 62 waitq_t wq; 60 SPINLOCK_DECLARE(lock); /**< Protects everything below. */ 63 /** Protects everything below. */ 64 SPINLOCK_DECLARE(lock); 61 65 uint8_t buffer[CHARDEV_BUFLEN]; 62 66 count_t counter; 63 chardev_operations_t *op; /**< Implementation of chardev operations. */ 67 /** Implementation of chardev operations. */ 68 chardev_operations_t *op; 64 69 index_t index; 65 70 void *data; 66 71 } chardev_t; 67 72 68 extern void chardev_initialize(char *name, 69 chardev_t *chardev, 70 chardev_operations_t *op); 73 extern void chardev_initialize(char *name, chardev_t *chardev, 74 chardev_operations_t *op); 71 75 extern void chardev_push_character(chardev_t *chardev, uint8_t ch); 72 76 -
kernel/generic/include/console/kconsole.h
rfa8e7d2 r80bcaed 46 46 ARG_TYPE_INT, 47 47 ARG_TYPE_STRING, 48 ARG_TYPE_VAR /**< Variable type - either symbol or string */ 48 /** Variable type - either symbol or string. */ 49 ARG_TYPE_VAR 49 50 } cmd_arg_type_t; 50 51 51 52 /** Structure representing one argument of kconsole command line. */ 52 53 typedef 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; 58 64 } cmd_arg_t; 59 65 60 66 /** Structure representing one kconsole command. */ 61 67 typedef 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); 70 84 } cmd_info_t; 71 85 -
kernel/generic/include/ddi/ddi_arg.h
rfa8e7d2 r80bcaed 38 38 /** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */ 39 39 typedef 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; 45 50 } ddi_memarg_t; 46 51 47 52 /** Structure encapsulating arguments for SYS_ENABLE_IOSPACE syscall. */ 48 53 typedef 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. */ 52 57 } ddi_ioarg_t; 53 58 -
kernel/generic/include/ddi/irq.h
rfa8e7d2 r80bcaed 92 92 */ 93 93 typedef 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; 102 109 } ipc_notif_cfg_t; 103 110 104 111 /** Structure representing one device IRQ. 105 112 * 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. 109 115 */ 110 116 typedef struct irq { -
kernel/generic/include/ipc/ipc.h
rfa8e7d2 r80bcaed 48 48 49 49 /* 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) 56 63 57 64 /* Flags of callid (the addresses are aligned at least to 4, 58 65 * that is why we can use bottom 2 bits of the call address 59 66 */ 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 62 71 63 72 /* Return values from IPC_ASYNC */ 64 #define IPC_CALLRET_FATAL 65 #define IPC_CALLRET_TEMPORARY 73 #define IPC_CALLRET_FATAL -1 74 #define IPC_CALLRET_TEMPORARY -2 66 75 67 76 68 77 /* Macros for manipulating calling data */ 69 #define IPC_SET_RETVAL(data, retval) 70 #define IPC_SET_METHOD(data, val) 71 #define IPC_SET_ARG1(data, val) 72 #define IPC_SET_ARG2(data, val) 73 #define IPC_SET_ARG3(data, val) 74 75 #define IPC_GET_METHOD(data) 76 #define IPC_GET_RETVAL(data) 77 78 #define IPC_GET_ARG1(data) 79 #define IPC_GET_ARG2(data) 80 #define IPC_GET_ARG3(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 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]) 81 90 82 91 /* Well known phone descriptors */ 83 #define PHONE_NS 92 #define PHONE_NS 0 84 93 85 94 /* System-specific methods - only through special syscalls … … 167 176 168 177 typedef 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 174 188 } ipc_phone_state_t; 175 189 … … 190 204 waitq_t wq; 191 205 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; 194 210 link_t dispatched_calls; /* Should be hash table in the future */ 195 211 196 link_t answers; /**< Answered calls */ 212 /** Answered calls */ 213 link_t answers; 197 214 198 215 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; 201 220 } answerbox_t; 202 221 … … 218 237 answerbox_t *callerbox; 219 238 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; 223 244 } call_t; 224 245 -
kernel/generic/include/ipc/irq.h
rfa8e7d2 r80bcaed 44 44 #include <adt/list.h> 45 45 46 extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, unative_t method,47 46 extern int ipc_irq_register(answerbox_t *box, inr_t inr, devno_t devno, 47 unative_t method, irq_code_t *ucode); 48 48 extern void ipc_irq_send_notif(irq_t *irq); 49 49 extern 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 41 41 42 42 unative_t sys_ipc_call_sync_fast(unative_t phoneid, unative_t method, 43 44 unative_t sys_ipc_call_sync(unative_t phoneid, ipc_data_t *question, 45 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); 46 46 unative_t sys_ipc_call_async_fast(unative_t phoneid, unative_t method, 47 47 unative_t arg1, unative_t arg2); 48 48 unative_t sys_ipc_call_async(unative_t phoneid, ipc_data_t *data); 49 49 unative_t sys_ipc_answer_fast(unative_t callid, unative_t retval, 50 50 unative_t arg1, unative_t arg2); 51 51 unative_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); 52 unative_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec, 53 int nonblocking); 53 54 unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid, 54 55 unative_t method, unative_t arg1); 55 56 unative_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); 57 unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method, 58 irq_code_t *ucode); 57 59 unative_t sys_ipc_unregister_irq(inr_t inr, devno_t devno); 58 60 -
kernel/generic/include/mm/as.h
rfa8e7d2 r80bcaed 54 54 #include <lib/elf.h> 55 55 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 */ 57 60 #define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH 58 61 … … 62 65 #define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH 63 66 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. */ 69 73 #define AS_AREA_ATTR_NONE 0 70 74 #define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ 71 75 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 */ 90 typedef 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; 75 117 76 118 typedef struct { … … 81 123 } as_operations_t; 82 124 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 */ 84 129 typedef 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; 88 138 } share_info_t; 89 139 … … 116 166 typedef struct { 117 167 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; 127 189 128 190 /** Data to be used by the backend. */ … … 147 209 extern as_t *as_create(int flags); 148 210 extern void as_destroy(as_t *as); 149 extern void as_switch(as_t *old , as_t *replace);211 extern void as_switch(as_t *old_as, as_t *new_as); 150 212 extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate); 151 213 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); 214 extern 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); 154 217 extern int as_area_destroy(as_t *as, uintptr_t address); 155 218 extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags); 156 219 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size, 157 220 as_t *dst_as, uintptr_t dst_base, int dst_flags_mask); 158 221 159 222 extern int as_area_get_flags(as_area_t *area); -
kernel/generic/include/mm/buddy.h
rfa8e7d2 r80bcaed 45 45 /** Buddy system operations to be implemented by each implementation. */ 46 46 typedef 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 */ 49 51 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 */ 52 56 link_t *(* bisect)(struct buddy_system *, link_t *); 53 57 /** Coalesce two buddies into a bigger block. */ … … 76 80 77 81 extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, 78 82 buddy_system_operations_t *op, void *data); 79 83 extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); 80 84 extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); -
kernel/generic/include/mm/mm.h
rfa8e7d2 r80bcaed 47 47 #define PAGE_GLOBAL_SHIFT 6 48 48 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) 51 51 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) 54 54 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) 57 57 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) 61 61 62 #define PAGE_GLOBAL (1 << PAGE_GLOBAL_SHIFT)62 #define PAGE_GLOBAL (1 << PAGE_GLOBAL_SHIFT) 63 63 64 64 #endif -
kernel/generic/include/mm/page.h
rfa8e7d2 r80bcaed 59 59 extern void page_table_unlock(as_t *as, bool unlock); 60 60 extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, 61 61 int flags); 62 62 extern void page_mapping_remove(as_t *as, uintptr_t page); 63 63 extern pte_t *page_mapping_find(as_t *as, uintptr_t page); -
kernel/generic/include/mm/slab.h
rfa8e7d2 r80bcaed 57 57 58 58 /* 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 60 62 61 63 /* 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) 65 71 66 72 typedef struct { … … 82 88 83 89 link_t link; 90 84 91 /* 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 86 95 int (*constructor)(void *obj, int kmflag); 87 96 int (*destructor)(void *obj); 88 int flags; /**< Flags changing behaviour of cache */ 97 98 /** Flags changing behaviour of cache */ 99 int flags; 89 100 90 101 /* Computed values */ … … 96 107 atomic_t allocated_objs; 97 108 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; 99 111 100 112 /* Slabs */ … … 110 122 } slab_cache_t; 111 123 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); 124 extern 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); 118 127 extern void slab_cache_destroy(slab_cache_t *cache); 119 128 … … 122 131 extern count_t slab_reclaim(int flags); 123 132 124 /* * Initialize slab subsytem*/133 /* slab subsytem initialization */ 125 134 extern void slab_cache_init(void); 126 135 extern void slab_enable_cpucache(void); -
kernel/generic/include/mm/tlb.h
rfa8e7d2 r80bcaed 40 40 41 41 /** 42 * Number of TLB shootdown messages that can be queued in processor 43 * tlb_messagesqueue.42 * Number of TLB shootdown messages that can be queued in processor tlb_messages 43 * queue. 44 44 */ 45 45 #define TLB_MESSAGE_QUEUE_LEN 10 … … 47 47 /** Type of TLB shootdown message. */ 48 48 typedef 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 53 57 } tlb_invalidate_type_t; 54 58 … … 64 68 65 69 #ifdef CONFIG_SMP 66 extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, uintptr_t page, count_t count); 70 extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, 71 uintptr_t page, count_t count); 67 72 extern void tlb_shootdown_finalize(void); 68 73 extern void tlb_shootdown_ipi_recv(void); 69 74 #else 70 # 71 # 72 # 75 #define tlb_shootdown_start(w, x, y, z) 76 #define tlb_shootdown_finalize() 77 #define tlb_shootdown_ipi_recv() 73 78 #endif /* CONFIG_SMP */ 74 79 -
kernel/generic/include/proc/task.h
rfa8e7d2 r80bcaed 59 59 /** Task lock. 60 60 * 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. 62 63 */ 63 64 SPINLOCK_DECLARE(lock); 64 65 65 66 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; 71 77 72 78 /** If this is true, new threads can become part of the task. */ 73 79 bool accept_new_threads; 80 /** Number of references (i.e. threads). */ 81 count_t refcount; 74 82 75 count_t refcount; /**< Number of references (i.e. threads). */ 76 77 cap_t capabilities; /**< Task capabilities. */ 83 /** Task capabilities. */ 84 cap_t capabilities; 78 85 79 86 /* IPC stuff */ 80 87 answerbox_t answerbox; /**< Communication endpoint */ 81 88 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; 85 94 86 task_arch_t arch; /**< Architecture specific task data. */ 95 /** Architecture specific task data. */ 96 task_arch_t arch; 87 97 88 98 /** … … 91 101 */ 92 102 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; 94 105 95 uint64_t cycles; /**< Accumulated accounting. */ 106 /** Accumulated accounting. */ 107 uint64_t cycles; 96 108 } task_t; 97 109 -
kernel/generic/include/proc/thread.h
rfa8e7d2 r80bcaed 53 53 54 54 /* 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) 58 62 59 63 /** Thread states. */ 60 64 typedef 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 68 79 } state_t; 69 80 … … 77 88 /** Thread structure. There is one per thread. */ 78 89 typedef struct thread { 79 link_t rq_link; 80 link_t wq_link; 81 link_t th_link; 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. */ 82 93 83 94 /** Lock protecting thread structure. … … 89 100 char name[THREAD_NAME_BUFLEN]; 90 101 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 */ 95 111 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 */ 97 116 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 */ 99 121 context_t sleep_interruption_context; 100 122 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 */ 107 136 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 */ 109 141 bool in_copy_to_uspace; 110 142 111 143 /** 112 * If true, the thread will not go to sleep at all and will 113 * callthread_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. 114 146 */ 115 147 bool interrupted; 116 148 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; 120 155 121 156 fpu_context_t *saved_fpu_context; … … 124 159 /* 125 160 * 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. 128 163 */ 129 164 int fpu_context_engaged; … … 131 166 rwlock_type_t rwlock_holder_type; 132 167 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; 154 203 } thread_t; 155 204 … … 162 211 SPINLOCK_EXTERN(threads_lock); 163 212 164 extern btree_t threads_btree; /**< B+tree containing all threads. */ 213 /** B+tree containing all threads. */ 214 extern btree_t threads_btree; 165 215 166 216 extern void thread_init(void); 167 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted); 217 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, 218 int flags, char *name, bool uncounted); 168 219 extern void thread_ready(thread_t *t); 169 220 extern void thread_exit(void) __attribute__((noreturn)); … … 182 233 extern void thread_usleep(uint32_t usec); 183 234 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) 185 237 extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags); 186 238 extern void thread_detach(thread_t *t); 187 239 188 extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with); 240 extern void thread_register_call_me(void (* call_me)(void *), 241 void *call_me_with); 189 242 extern void thread_print_list(void); 190 243 extern void thread_destroy(thread_t *t); … … 193 246 extern void thread_interrupt_sleep(thread_t *t); 194 247 195 /* Fpu context slab cache*/248 /** Fpu context slab cache. */ 196 249 extern slab_cache_t *fpu_context_slab; 197 250 198 /* *Thread syscall prototypes. */251 /* Thread syscall prototypes. */ 199 252 unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name); 200 253 unative_t sys_thread_exit(int uspace_status); -
kernel/generic/include/synch/condvar.h
rfa8e7d2 r80bcaed 45 45 } condvar_t; 46 46 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) 51 51 52 52 extern void condvar_initialize(condvar_t *cv); 53 53 extern void condvar_signal(condvar_t *cv); 54 54 extern void condvar_broadcast(condvar_t *cv); 55 extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, int flags); 55 extern int _condvar_wait_timeout(condvar_t *cv, mutex_t *mtx, uint32_t usec, 56 int flags); 56 57 57 58 #endif -
kernel/generic/include/synch/futex.h
rfa8e7d2 r80bcaed 43 43 /** Kernel-side futex structure. */ 44 44 typedef 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; 49 53 } futex_t; 50 54 51 55 extern void futex_init(void); 52 extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec, int flags); 56 extern unative_t sys_futex_sleep_timeout(uintptr_t uaddr, uint32_t usec, 57 int flags); 53 58 extern unative_t sys_futex_wakeup(uintptr_t uaddr); 54 59 -
kernel/generic/include/synch/rwlock.h
rfa8e7d2 r80bcaed 49 49 typedef struct { 50 50 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; 53 57 } rwlock_t; 54 58 55 59 #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) 57 61 #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) 59 63 #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) 61 66 #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) 67 73 68 74 extern void rwlock_initialize(rwlock_t *rwl); -
kernel/generic/include/synch/semaphore.h
rfa8e7d2 r80bcaed 47 47 _semaphore_down_timeout((s), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE) 48 48 #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) 50 50 #define semaphore_down_timeout(s, usec) \ 51 51 _semaphore_down_timeout((s), (usec), SYNCH_FLAGS_NONE) -
kernel/generic/include/synch/synch.h
rfa8e7d2 r80bcaed 36 36 #define KERN_SYNCH_H_ 37 37 38 #define SYNCH_NO_TIMEOUT 0 /**< Request with no timeout. */ 38 /** Request with no timeout. */ 39 #define SYNCH_NO_TIMEOUT 0 39 40 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) 43 47 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 49 58 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)) 52 63 53 64 #endif -
kernel/generic/include/synch/waitq.h
rfa8e7d2 r80bcaed 53 53 SPINLOCK_DECLARE(lock); 54 54 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; 57 61 } waitq_t; 58 62 -
kernel/generic/include/time/timeout.h
rfa8e7d2 r80bcaed 45 45 SPINLOCK_DECLARE(lock); 46 46 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; 55 57 } timeout_t; 56 58 … … 60 62 extern void timeout_initialize(timeout_t *t); 61 63 extern void timeout_reinitialize(timeout_t *t); 62 extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f, void *arg); 64 extern void timeout_register(timeout_t *t, uint64_t usec, timeout_handler_t f, 65 void *arg); 63 66 extern bool timeout_unregister(timeout_t *t); 64 67 -
kernel/generic/src/mm/as.c
rfa8e7d2 r80bcaed 169 169 as->cpu_refcount = 0; 170 170 #ifdef AS_PAGE_TABLE 171 as-> page_table = page_table_create(flags);171 as->genarch.page_table = page_table_create(flags); 172 172 #else 173 173 page_table_create(flags); … … 221 221 btree_destroy(&as->as_area_btree); 222 222 #ifdef AS_PAGE_TABLE 223 page_table_destroy(as-> page_table);223 page_table_destroy(as->genarch.page_table); 224 224 #else 225 225 page_table_destroy(NULL); … … 864 864 * @param new New address space. 865 865 */ 866 void as_switch(as_t *old , as_t *replace)866 void as_switch(as_t *old_as, as_t *new_as) 867 867 { 868 868 ipl_t ipl; … … 875 875 * First, take care of the old address space. 876 876 */ 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)) { 881 881 /* 882 882 * The old address space is no longer active on … … 885 885 * ASID. 886 886 */ 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, 889 889 &inactive_as_with_asid_head); 890 890 } 891 mutex_unlock(&old ->lock);891 mutex_unlock(&old_as->lock); 892 892 893 893 /* … … 895 895 * is being removed from the CPU. 896 896 */ 897 as_deinstall_arch(old );897 as_deinstall_arch(old_as); 898 898 } 899 899 … … 901 901 * Second, prepare the new address space. 902 902 */ 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); 907 907 } else { 908 908 /* 909 * Defer call to asid_get() until replace->lock is released.909 * Defer call to asid_get() until new_as->lock is released. 910 910 */ 911 911 needs_asid = true; 912 912 } 913 913 } 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); 916 918 917 919 if (needs_asid) { … … 923 925 924 926 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); 928 930 } 929 931 spinlock_unlock(&inactive_as_with_asid_lock); … … 934 936 * (e.g. write ASID to hardware register etc.) 935 937 */ 936 as_install_arch( replace);937 938 AS = replace;938 as_install_arch(new_as); 939 940 AS = new_as; 939 941 } 940 942
Note:
See TracChangeset
for help on using the changeset viewer.