- Timestamp:
- 2010-02-19T17:16:46Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 617652f
- Parents:
- b86d436 (diff), f41aa81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- kernel
- Files:
-
- 37 added
- 36 edited
-
Makefile.build (modified) (1 diff)
-
arch/abs32le/Makefile.inc (added)
-
arch/abs32le/_link.ld.in (added)
-
arch/abs32le/include/arch.h (added)
-
arch/abs32le/include/asm.h (added)
-
arch/abs32le/include/atomic.h (added)
-
arch/abs32le/include/barrier.h (added)
-
arch/abs32le/include/context.h (added)
-
arch/abs32le/include/context_offset.h (added)
-
arch/abs32le/include/cpu.h (added)
-
arch/abs32le/include/cycle.h (added)
-
arch/abs32le/include/debug.h (added)
-
arch/abs32le/include/elf.h (added)
-
arch/abs32le/include/faddr.h (added)
-
arch/abs32le/include/fpu_context.h (added)
-
arch/abs32le/include/interrupt.h (added)
-
arch/abs32le/include/memstr.h (added)
-
arch/abs32le/include/mm/as.h (added)
-
arch/abs32le/include/mm/asid.h (added)
-
arch/abs32le/include/mm/frame.h (added)
-
arch/abs32le/include/mm/page.h (added)
-
arch/abs32le/include/mm/tlb.h (added)
-
arch/abs32le/include/proc/task.h (added)
-
arch/abs32le/include/proc/thread.h (added)
-
arch/abs32le/include/types.h (added)
-
arch/abs32le/src/abs32le.c (added)
-
arch/abs32le/src/cpu/cpu.c (added)
-
arch/abs32le/src/ddi/ddi.c (added)
-
arch/abs32le/src/debug/stacktrace.c (added)
-
arch/abs32le/src/mm/as.c (added)
-
arch/abs32le/src/mm/frame.c (added)
-
arch/abs32le/src/mm/page.c (added)
-
arch/abs32le/src/mm/tlb.c (added)
-
arch/abs32le/src/proc/scheduler.c (added)
-
arch/abs32le/src/proc/task.c (added)
-
arch/abs32le/src/proc/thread.c (added)
-
arch/abs32le/src/smp/smp.c (added)
-
arch/abs32le/src/userspace.c (added)
-
arch/amd64/include/asm.h (modified) (1 diff)
-
arch/amd64/src/amd64.c (modified) (1 diff)
-
arch/arm32/include/asm.h (modified) (1 diff)
-
arch/arm32/src/arm32.c (modified) (3 diffs)
-
arch/ia32/include/asm.h (modified) (1 diff)
-
arch/ia32/src/ia32.c (modified) (1 diff)
-
arch/ia64/include/asm.h (modified) (1 diff)
-
arch/ia64/include/context.h (modified) (1 diff)
-
arch/ia64/src/ia64.c (modified) (2 diffs)
-
arch/mips32/include/asm.h (modified) (1 diff)
-
arch/mips32/include/context.h (modified) (2 diffs)
-
arch/mips32/src/mips32.c (modified) (2 diffs)
-
arch/ppc32/include/asm.h (modified) (2 diffs)
-
arch/ppc32/include/context.h (modified) (3 diffs)
-
arch/ppc32/src/ppc32.c (modified) (7 diffs)
-
arch/sparc64/include/asm.h (modified) (1 diff)
-
arch/sparc64/include/context.h (modified) (1 diff)
-
arch/sparc64/src/sun4u/sparc64.c (modified) (2 diffs)
-
arch/sparc64/src/sun4v/sparc64.c (modified) (2 diffs)
-
generic/include/context.h (modified) (4 diffs)
-
generic/include/func.h (modified) (1 diff)
-
generic/include/interrupt.h (modified) (1 diff)
-
generic/include/ipc/event_types.h (modified) (1 diff)
-
generic/include/macros.h (modified) (1 diff)
-
generic/include/mm/as.h (modified) (3 diffs)
-
generic/include/stacktrace.h (modified) (1 diff)
-
generic/include/udebug/udebug.h (modified) (7 diffs)
-
generic/include/udebug/udebug_ops.h (modified) (1 diff)
-
generic/src/ddi/irq.c (modified) (2 diffs)
-
generic/src/interrupt/interrupt.c (modified) (2 diffs)
-
generic/src/ipc/ipc.c (modified) (6 diffs)
-
generic/src/mm/as.c (modified) (1 diff)
-
generic/src/udebug/udebug.c (modified) (3 diffs)
-
generic/src/udebug/udebug_ipc.c (modified) (6 diffs)
-
generic/src/udebug/udebug_ops.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile.build
rb86d436 r5cde90f 55 55 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \ 56 56 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \ 57 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -Werror\58 - pipe57 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \ 58 -Werror-implicit-function-declaration -Werror -pipe 59 59 60 60 ICC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros ../config.h \ 61 61 -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \ 62 -Werror -wd17062 -Werror-implicit-function-declaration -Werror -wd170 63 63 64 64 SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \ -
kernel/arch/amd64/include/asm.h
rb86d436 r5cde90f 68 68 } 69 69 70 static inline void cpu_halt(void)71 { 72 asm volatile (73 "0:\n"74 "hlt\n"75 " jmp 0b\n"76 );70 static inline void __attribute__((noreturn)) cpu_halt(void) 71 { 72 while (true) { 73 asm volatile ( 74 "hlt\n" 75 ); 76 } 77 77 } 78 78 -
kernel/arch/amd64/src/amd64.c
rb86d436 r5cde90f 278 278 } 279 279 280 void irq_initialize_arch(irq_t *irq) 281 { 282 (void) irq; 283 } 284 280 285 /** @} 281 286 */ -
kernel/arch/arm32/include/asm.h
rb86d436 r5cde90f 96 96 } 97 97 98 extern void cpu_halt(void) ;98 extern void cpu_halt(void) __attribute__((noreturn)); 99 99 extern void asm_delay_loop(uint32_t t); 100 100 extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg, -
kernel/arch/arm32/src/arm32.c
rb86d436 r5cde90f 155 155 void cpu_halt(void) 156 156 { 157 machine_cpu_halt(); 157 while (true) 158 machine_cpu_halt(); 158 159 } 159 160 … … 162 163 { 163 164 /* not implemented */ 164 while ( 1);165 while (true); 165 166 } 166 167 … … 179 180 } 180 181 182 void irq_initialize_arch(irq_t *irq) 183 { 184 (void) irq; 185 } 186 181 187 /** @} 182 188 */ -
kernel/arch/ia32/include/asm.h
rb86d436 r5cde90f 60 60 * 61 61 */ 62 static inline void cpu_halt(void)63 { 64 asm volatile (65 "0:\n"66 "hlt\n"67 " jmp 0b\n"68 );62 static inline __attribute__((noreturn)) void cpu_halt(void) 63 { 64 while (true) { 65 asm volatile ( 66 "hlt\n" 67 ); 68 } 69 69 } 70 70 -
kernel/arch/ia32/src/ia32.c
rb86d436 r5cde90f 234 234 } 235 235 236 void irq_initialize_arch(irq_t *irq) 237 { 238 (void) irq; 239 } 240 236 241 /** @} 237 242 */ -
kernel/arch/ia64/include/asm.h
rb86d436 r5cde90f 428 428 } 429 429 430 extern void cpu_halt(void) ;430 extern void cpu_halt(void) __attribute__((noreturn)); 431 431 extern void cpu_sleep(void); 432 432 extern void asm_delay_loop(uint32_t t); -
kernel/arch/ia64/include/context.h
rb86d436 r5cde90f 48 48 */ 49 49 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 50 51 #ifdef context_set52 #undef context_set53 #endif54 50 55 51 /* RSE stack starts at the bottom of memory stack. */ -
kernel/arch/ia64/src/ia64.c
rb86d436 r5cde90f 44 44 #include <arch/stack.h> 45 45 #include <arch/mm/page.h> 46 #include <interrupt.h> 46 47 #include <mm/as.h> 47 48 #include <config.h> … … 280 281 } 281 282 283 void irq_initialize_arch(irq_t *irq) 284 { 285 (void) irq; 286 } 287 282 288 /** @} 283 289 */ -
kernel/arch/mips32/include/asm.h
rb86d436 r5cde90f 66 66 } 67 67 68 extern void cpu_halt(void) ;68 extern void cpu_halt(void) __attribute__((noreturn)); 69 69 extern void asm_delay_loop(uint32_t t); 70 70 extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg, -
kernel/arch/mips32/include/context.h
rb86d436 r5cde90f 27 27 */ 28 28 29 /** @addtogroup mips32 29 /** @addtogroup mips32 30 30 * @{ 31 31 */ … … 42 42 * Put one item onto the stack to support get_stack_base() and align it up. 43 43 */ 44 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 45 44 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 46 45 47 46 #ifndef __ASM__ 48 47 49 48 #include <arch/types.h> 49 50 #define context_set(ctx, pc, stack, size) \ 51 context_set_generic(ctx, pc, stack, size) 50 52 51 53 /* -
kernel/arch/mips32/src/mips32.c
rb86d436 r5cde90f 46 46 #include <sysinfo/sysinfo.h> 47 47 #include <arch/interrupt.h> 48 #include <interrupt.h> 48 49 #include <console/chardev.h> 49 50 #include <arch/barrier.h> … … 257 258 } 258 259 260 void irq_initialize_arch(irq_t *irq) 261 { 262 (void) irq; 263 } 264 259 265 /** @} 260 266 */ -
kernel/arch/ppc32/include/asm.h
rb86d436 r5cde90f 27 27 */ 28 28 29 /** @addtogroup ppc32 29 /** @addtogroup ppc32 30 30 * @{ 31 31 */ … … 146 146 } 147 147 148 void cpu_halt(void); 149 void asm_delay_loop(uint32_t t); 150 148 extern void cpu_halt(void) __attribute__((noreturn)); 149 extern void asm_delay_loop(uint32_t t); 151 150 extern void userspace_asm(uintptr_t uspace_uarg, uintptr_t stack, uintptr_t entry); 152 151 153 152 static inline void pio_write_8(ioport8_t *port, uint8_t v) 154 153 { 155 *port = v; 154 *port = v; 156 155 } 157 156 158 157 static inline void pio_write_16(ioport16_t *port, uint16_t v) 159 158 { 160 *port = v; 159 *port = v; 161 160 } 162 161 163 162 static inline void pio_write_32(ioport32_t *port, uint32_t v) 164 163 { 165 *port = v; 164 *port = v; 166 165 } 167 166 168 167 static inline uint8_t pio_read_8(ioport8_t *port) 169 168 { 170 return *port; 169 return *port; 171 170 } 172 171 173 172 static inline uint16_t pio_read_16(ioport16_t *port) 174 173 { 175 return *port; 174 return *port; 176 175 } 177 176 178 177 static inline uint32_t pio_read_32(ioport32_t *port) 179 178 { 180 return *port; 179 return *port; 181 180 } 182 181 -
kernel/arch/ppc32/include/context.h
rb86d436 r5cde90f 27 27 */ 28 28 29 /** @addtogroup ppc32 29 /** @addtogroup ppc32 30 30 * @{ 31 31 */ … … 38 38 #include <arch/types.h> 39 39 40 #define SP_DELTA 16 40 #define SP_DELTA 16 41 42 #define context_set(ctx, pc, stack, size) \ 43 context_set_generic(ctx, pc, stack, size) 41 44 42 45 typedef struct { … … 68 71 69 72 ipl_t ipl; 70 } __attribute__ ((packed)) context_t;73 } __attribute__((packed)) context_t; 71 74 72 75 #endif -
kernel/arch/ppc32/src/ppc32.c
rb86d436 r5cde90f 39 39 #include <genarch/kbrd/kbrd.h> 40 40 #include <arch/interrupt.h> 41 #include <interrupt.h> 41 42 #include <genarch/fb/fb.h> 42 43 #include <genarch/fb/visuals.h> … … 47 48 #include <proc/uarg.h> 48 49 #include <console/console.h> 50 #include <sysinfo/sysinfo.h> 49 51 #include <ddi/irq.h> 50 52 #include <arch/drivers/pic.h> … … 58 60 59 61 bootinfo_t bootinfo; 62 63 static cir_t pic_cir; 64 static void *pic_cir_arg; 60 65 61 66 /** Performs ppc32-specific initialization before main_bsp() is called. */ … … 186 191 if (assigned_address) { 187 192 /* Initialize PIC */ 188 cir_t cir; 189 void *cir_arg; 190 pic_init(assigned_address[0].addr, PAGE_SIZE, &cir, &cir_arg); 191 193 pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir, 194 &pic_cir_arg); 195 192 196 #ifdef CONFIG_MAC_KBD 193 197 uintptr_t pa = assigned_address[0].addr + 0x16000; … … 201 205 /* Initialize I/O controller */ 202 206 cuda_instance_t *cuda_instance = 203 cuda_init(cuda, IRQ_CUDA, cir,cir_arg);207 cuda_init(cuda, IRQ_CUDA, pic_cir, pic_cir_arg); 204 208 if (cuda_instance) { 205 209 kbrd_instance_t *kbrd_instance = kbrd_init(); … … 211 215 } 212 216 } 217 218 /* 219 * This is the necessary evil until the userspace driver is entirely 220 * self-sufficient. 221 */ 222 sysinfo_set_item_val("cuda", NULL, true); 223 sysinfo_set_item_val("cuda.inr", NULL, IRQ_CUDA); 224 sysinfo_set_item_val("cuda.address.physical", NULL, pa); 225 sysinfo_set_item_val("cuda.address.kernel", NULL, 226 (uintptr_t) cuda); 213 227 #endif 214 228 } … … 216 230 /* Consider only a single device for now */ 217 231 return false; 232 } 233 234 void irq_initialize_arch(irq_t *irq) 235 { 236 irq->cir = pic_cir; 237 irq->cir_arg = pic_cir_arg; 238 irq->preack = true; 218 239 } 219 240 -
kernel/arch/sparc64/include/asm.h
rb86d436 r5cde90f 430 430 } 431 431 432 extern void cpu_halt(void) ;432 extern void cpu_halt(void) __attribute__((noreturn)); 433 433 extern void cpu_sleep(void); 434 434 extern void asm_delay_loop(const uint32_t usec); -
kernel/arch/sparc64/include/context.h
rb86d436 r5cde90f 42 42 #define SP_DELTA (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE) 43 43 44 #ifdef context_set45 #undef context_set46 #endif47 48 44 #define context_set(c, _pc, stack, size) \ 49 45 (c)->pc = ((uintptr_t) _pc) - 8; \ -
kernel/arch/sparc64/src/sun4u/sparc64.c
rb86d436 r5cde90f 44 44 #include <arch/mm/page.h> 45 45 #include <arch/stack.h> 46 #include <interrupt.h> 46 47 #include <genarch/ofw/ofw_tree.h> 47 48 #include <userspace.h> … … 166 167 } 167 168 169 void irq_initialize_arch(irq_t *irq) 170 { 171 (void) irq; 172 } 173 168 174 /** @} 169 175 */ -
kernel/arch/sparc64/src/sun4v/sparc64.c
rb86d436 r5cde90f 45 45 #include <arch/mm/page.h> 46 46 #include <arch/stack.h> 47 #include <interrupt.h> 47 48 #include <genarch/ofw/ofw_tree.h> 48 49 #include <userspace.h> … … 166 167 } 167 168 169 void irq_initialize_arch(irq_t *irq) 170 { 171 (void) irq; 172 } 173 168 174 /** @} 169 175 */ -
kernel/generic/include/context.h
rb86d436 r5cde90f 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 39 39 #include <arch/context.h> 40 40 41 #define context_set_generic(ctx, _pc, stack, size) \ 42 (ctx)->pc = (uintptr_t) (_pc); \ 43 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 41 44 42 #ifndef context_set 43 #define context_set(c, _pc, stack, size) \ 44 (c)->pc = (uintptr_t) (_pc); \ 45 (c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 46 #endif /* context_set */ 47 48 extern int context_save_arch(context_t *c) __attribute__ ((returns_twice)); 49 extern void context_restore_arch(context_t *c) __attribute__ ((noreturn)); 45 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice)); 46 extern void context_restore_arch(context_t *ctx) __attribute__((noreturn)); 50 47 51 48 /** Save register context. … … 73 70 * saved like that would therefore lead to a disaster. 74 71 * 75 * @param c Context structure.72 * @param ctx Context structure. 76 73 * 77 * @return context_save() returns 1, context_restore() returns 0. 74 * @return context_save() returns 1, context_restore() returns 0. 75 * 78 76 */ 79 #define context_save(c ) context_save_arch(c)77 #define context_save(ctx) context_save_arch(ctx) 80 78 81 79 /** Restore register context. … … 88 86 * being return value. 89 87 * 90 * @param c Context structure.88 * @param ctx Context structure. 91 89 */ 92 static inline void context_restore(context_t *c )90 static inline void context_restore(context_t *ctx) 93 91 { 94 context_restore_arch(c );92 context_restore_arch(ctx); 95 93 } 96 94 -
kernel/generic/include/func.h
rb86d436 r5cde90f 41 41 extern atomic_t haltstate; 42 42 43 extern void halt(void) ;43 extern void halt(void) __attribute__((noreturn)); 44 44 extern unative_t atoi(const char *text); 45 45 extern void order(const uint64_t val, uint64_t *rv, char *suffix); -
kernel/generic/include/interrupt.h
rb86d436 r5cde90f 46 46 typedef void (* iroutine)(int n, istate_t *istate); 47 47 48 #define fault_if_from_uspace(istate, fmt, ...) \ 49 { \ 50 if (istate_from_uspace(istate)) { \ 51 task_t *task = TASK; \ 52 printf("Task %s (%" PRIu64 ") killed due to an exception at " \ 53 "program counter %p.\n", task->name, task->taskid, istate_get_pc(istate)); \ 54 stack_trace_istate(istate); \ 55 printf("Kill message: " fmt "\n", ##__VA_ARGS__); \ 56 task_kill(task->taskid); \ 57 thread_exit(); \ 58 } \ 59 } 60 48 extern void fault_if_from_uspace(istate_t *istate, char *fmt, ...); 61 49 extern iroutine exc_register(int n, const char *name, iroutine f); 62 50 extern void exc_dispatch(int n, istate_t *t); 63 51 void exc_init(void); 52 53 extern void irq_initialize_arch(irq_t *irq); 64 54 65 55 #endif -
kernel/generic/include/ipc/event_types.h
rb86d436 r5cde90f 37 37 38 38 typedef enum event_type { 39 /** New data available in kernel log */ 39 40 EVENT_KLOG = 0, 41 /** Returning from kernel console to userspace */ 40 42 EVENT_KCONSOLE, 43 /** A thread has faulted and will be terminated */ 44 EVENT_FAULT, 41 45 EVENT_END 42 46 } event_type_t; -
kernel/generic/include/macros.h
rb86d436 r5cde90f 84 84 #define STRING_ARG(arg) #arg 85 85 86 #define LOWER32(arg) (( arg) & 0xffffffff)87 #define UPPER32(arg) ((( arg) >> 32) & 0xffffffff)86 #define LOWER32(arg) (((uint64_t) (arg)) & 0xffffffff) 87 #define UPPER32(arg) (((((uint64_t) arg)) >> 32) & 0xffffffff) 88 88 89 89 #define MERGE_LOUP32(lo, up) \ -
kernel/generic/include/mm/as.h
rb86d436 r5cde90f 36 36 #define KERN_AS_H_ 37 37 38 #ifdef KERNEL 39 #include <arch/types.h> 40 #else 41 #include <sys/types.h> 42 #endif 43 38 44 /** Address space area flags. */ 39 45 #define AS_AREA_READ 1 … … 41 47 #define AS_AREA_EXEC 4 42 48 #define AS_AREA_CACHEABLE 8 49 50 /** Address space area info exported to userspace. */ 51 typedef struct { 52 /** Starting address */ 53 uintptr_t start_addr; 54 55 /** Area size */ 56 size_t size; 57 58 /** Area flags */ 59 int flags; 60 } as_area_info_t; 43 61 44 62 #ifdef KERNEL … … 268 286 269 287 /* Introspection functions. */ 288 extern void as_get_area_info(as_t *as, as_area_info_t **obuf, size_t *osize); 270 289 extern void as_print(as_t *as); 271 290 -
kernel/generic/include/stacktrace.h
rb86d436 r5cde90f 60 60 */ 61 61 extern uintptr_t frame_pointer_get(void); 62 extern uintptr_t program_counter_get( );62 extern uintptr_t program_counter_get(void); 63 63 64 64 extern bool kernel_frame_pointer_validate(uintptr_t); -
kernel/generic/include/udebug/udebug.h
rb86d436 r5cde90f 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 83 83 UDEBUG_M_ARGS_READ, 84 84 85 /** Read thread's userspace register state (istate_t). 86 * 87 * - ARG2 - thread identification 88 * - ARG3 - destination address in the caller's address space 89 * 90 * or, on error, retval will be 91 * - ENOENT - thread does not exist 92 * - EBUSY - register state not available 93 */ 94 UDEBUG_M_REGS_READ, 95 85 96 /** Read the list of the debugged tasks's threads. 86 97 * … … 97 108 UDEBUG_M_THREAD_READ, 98 109 110 /** Read the name of the debugged task. 111 * 112 * - ARG2 - destination address in the caller's address space 113 * - ARG3 - size of receiving buffer in bytes 114 * 115 * The kernel fills the buffer with a non-terminated string. 116 * 117 * - ARG2 - number of bytes that were actually copied 118 * - ARG3 - number of bytes of the complete data 119 * 120 */ 121 UDEBUG_M_NAME_READ, 122 123 /** Read the list of the debugged task's address space areas. 124 * 125 * - ARG2 - destination address in the caller's address space 126 * - ARG3 - size of receiving buffer in bytes 127 * 128 * The kernel fills the buffer with a series of as_area_info_t structures. 129 * Upon answer, the kernel will set: 130 * 131 * - ARG2 - number of bytes that were actually copied 132 * - ARG3 - number of bytes of the complete data 133 * 134 */ 135 UDEBUG_M_AREAS_READ, 136 99 137 /** Read the debugged tasks's memory. 100 138 * … … 108 146 } udebug_method_t; 109 147 110 148 111 149 typedef enum { 112 150 UDEBUG_EVENT_FINISHED = 1, /**< Debuging session has finished */ … … 139 177 140 178 #include <synch/mutex.h> 179 #include <synch/condvar.h> 141 180 #include <arch/interrupt.h> 142 181 #include <atomic.h> … … 181 220 bool stoppable; /**< thread is stoppable */ 182 221 bool active; /**< thread is in a debugging session */ 222 condvar_t active_cv; 183 223 } udebug_thread_t; 184 224 … … 202 242 203 243 int udebug_task_cleanup(struct task *ta); 244 void udebug_thread_fault(void); 204 245 205 246 #endif -
kernel/generic/include/udebug/udebug_ops.h
rb86d436 r5cde90f 45 45 int udebug_stop(thread_t *t, call_t *call); 46 46 47 int udebug_thread_read(void **buffer, size_t buf_size, size_t *n); 47 int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored, 48 size_t *needed); 49 int udebug_name_read(char **data, size_t *data_size); 48 50 int udebug_args_read(thread_t *t, void **buffer); 51 52 int udebug_regs_read(thread_t *t, void **buffer); 49 53 50 54 int udebug_mem_read(unative_t uspace_addr, size_t n, void **buffer); -
kernel/generic/src/ddi/irq.c
rb86d436 r5cde90f 74 74 #include <synch/spinlock.h> 75 75 #include <console/console.h> 76 #include <interrupt.h> 76 77 #include <memstr.h> 77 78 #include <arch.h> … … 169 170 irq->inr = -1; 170 171 irq->devno = -1; 172 173 irq_initialize_arch(irq); 171 174 } 172 175 -
kernel/generic/src/interrupt/interrupt.c
rb86d436 r5cde90f 44 44 #include <console/console.h> 45 45 #include <console/cmd.h> 46 #include <ipc/event.h> 47 #include <synch/mutex.h> 48 #include <time/delay.h> 49 #include <macros.h> 46 50 #include <panic.h> 47 51 #include <print.h> … … 107 111 fault_if_from_uspace(istate, "Unhandled exception %d.", n); 108 112 panic("Unhandled exception %d.", n); 113 } 114 115 /** Terminate thread and task if exception came from userspace. */ 116 void fault_if_from_uspace(istate_t *istate, char *fmt, ...) 117 { 118 task_t *task = TASK; 119 va_list args; 120 121 if (!istate_from_uspace(istate)) 122 return; 123 124 printf("Task %s (%" PRIu64 ") killed due to an exception at " 125 "program counter %p.\n", task->name, task->taskid, 126 istate_get_pc(istate)); 127 128 stack_trace_istate(istate); 129 130 printf("Kill message: "); 131 va_start(args, fmt); 132 vprintf(fmt, args); 133 va_end(args); 134 printf("\n"); 135 136 /* 137 * Userspace can subscribe for FAULT events to take action 138 * whenever a thread faults. (E.g. take a dump, run a debugger). 139 * The notification is always available, but unless Udebug is enabled, 140 * that's all you get. 141 */ 142 if (event_is_subscribed(EVENT_FAULT)) { 143 /* Notify the subscriber that a fault occurred. */ 144 event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid), 145 UPPER32(TASK->taskid), (unative_t) THREAD); 146 147 #ifdef CONFIG_UDEBUG 148 /* Wait for a debugging session. */ 149 udebug_thread_fault(); 150 #endif 151 } 152 153 task_kill(task->taskid); 154 thread_exit(); 109 155 } 110 156 -
kernel/generic/src/ipc/ipc.c
rb86d436 r5cde90f 212 212 * 213 213 * @param call Call structure to be answered. 214 */ 215 static void _ipc_answer_free_call(call_t *call) 214 * @param selflocked If true, then TASK->answebox is locked. 215 */ 216 static void _ipc_answer_free_call(call_t *call, bool selflocked) 216 217 { 217 218 answerbox_t *callerbox = call->callerbox; 219 bool do_lock = ((!selflocked) || callerbox != (&TASK->answerbox)); 218 220 219 221 call->flags |= IPC_CALL_ANSWERED; … … 226 228 } 227 229 228 spinlock_lock(&callerbox->lock); 230 if (do_lock) 231 spinlock_lock(&callerbox->lock); 229 232 list_append(&call->link, &callerbox->answers); 230 spinlock_unlock(&callerbox->lock); 233 if (do_lock) 234 spinlock_unlock(&callerbox->lock); 231 235 waitq_wakeup(&callerbox->wq, WAKEUP_FIRST); 232 236 } … … 244 248 spinlock_unlock(&box->lock); 245 249 /* Send back answer */ 246 _ipc_answer_free_call(call );250 _ipc_answer_free_call(call, false); 247 251 } 248 252 … … 261 265 atomic_inc(&phone->active_calls); 262 266 IPC_SET_RETVAL(call->data, err); 263 _ipc_answer_free_call(call );267 _ipc_answer_free_call(call, false); 264 268 } 265 269 … … 300 304 if (call->flags & IPC_CALL_FORWARDED) { 301 305 IPC_SET_RETVAL(call->data, EFORWARD); 302 _ipc_answer_free_call(call );306 _ipc_answer_free_call(call, false); 303 307 } else { 304 308 if (phone->state == IPC_PHONE_HUNGUP) … … 455 459 456 460 IPC_SET_RETVAL(call->data, EHANGUP); 457 _ipc_answer_free_call(call );461 _ipc_answer_free_call(call, true); 458 462 } 459 463 } -
kernel/generic/src/mm/as.c
rb86d436 r5cde90f 1920 1920 } 1921 1921 1922 /** Get list of adress space areas. 1923 * 1924 * @param as Address space. 1925 * @param obuf Place to save pointer to returned buffer. 1926 * @param osize Place to save size of returned buffer. 1927 */ 1928 void as_get_area_info(as_t *as, as_area_info_t **obuf, size_t *osize) 1929 { 1930 ipl_t ipl; 1931 size_t area_cnt, area_idx, i; 1932 link_t *cur; 1933 1934 as_area_info_t *info; 1935 size_t isize; 1936 1937 ipl = interrupts_disable(); 1938 mutex_lock(&as->lock); 1939 1940 /* First pass, count number of areas. */ 1941 1942 area_cnt = 0; 1943 1944 for (cur = as->as_area_btree.leaf_head.next; 1945 cur != &as->as_area_btree.leaf_head; cur = cur->next) { 1946 btree_node_t *node; 1947 1948 node = list_get_instance(cur, btree_node_t, leaf_link); 1949 area_cnt += node->keys; 1950 } 1951 1952 isize = area_cnt * sizeof(as_area_info_t); 1953 info = malloc(isize, 0); 1954 1955 /* Second pass, record data. */ 1956 1957 area_idx = 0; 1958 1959 for (cur = as->as_area_btree.leaf_head.next; 1960 cur != &as->as_area_btree.leaf_head; cur = cur->next) { 1961 btree_node_t *node; 1962 1963 node = list_get_instance(cur, btree_node_t, leaf_link); 1964 1965 for (i = 0; i < node->keys; i++) { 1966 as_area_t *area = node->value[i]; 1967 1968 ASSERT(area_idx < area_cnt); 1969 mutex_lock(&area->lock); 1970 1971 info[area_idx].start_addr = area->base; 1972 info[area_idx].size = FRAMES2SIZE(area->pages); 1973 info[area_idx].flags = area->flags; 1974 ++area_idx; 1975 1976 mutex_unlock(&area->lock); 1977 } 1978 } 1979 1980 mutex_unlock(&as->lock); 1981 interrupts_restore(ipl); 1982 1983 *obuf = info; 1984 *osize = isize; 1985 } 1986 1987 1922 1988 /** Print out information about address space. 1923 1989 * -
kernel/generic/src/udebug/udebug.c
rb86d436 r5cde90f 69 69 mutex_initialize(&ut->lock, MUTEX_PASSIVE); 70 70 waitq_initialize(&ut->go_wq); 71 condvar_initialize(&ut->active_cv); 71 72 72 73 ut->go_call = NULL; … … 446 447 waitq_wakeup(&t->udebug.go_wq, WAKEUP_FIRST); 447 448 } 449 mutex_unlock(&t->udebug.lock); 450 condvar_broadcast(&t->udebug.active_cv); 451 } else { 452 mutex_unlock(&t->udebug.lock); 448 453 } 449 mutex_unlock(&t->udebug.lock);450 454 } 451 455 … … 456 460 } 457 461 462 /** Wait for debugger to handle a fault in this thread. 463 * 464 * When a thread faults and someone is subscribed to the FAULT kernel event, 465 * this function is called to wait for a debugging session to give userspace 466 * a chance to examine the faulting thead/task. When the debugging session 467 * is over, this function returns (so that thread/task cleanup can continue). 468 */ 469 void udebug_thread_fault(void) 470 { 471 udebug_stoppable_begin(); 472 473 /* Wait until a debugger attends to us. */ 474 mutex_lock(&THREAD->udebug.lock); 475 while (!THREAD->udebug.active) 476 condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock); 477 mutex_unlock(&THREAD->udebug.lock); 478 479 /* Make sure the debugging session is over before proceeding. */ 480 mutex_lock(&THREAD->udebug.lock); 481 while (THREAD->udebug.active) 482 condvar_wait(&THREAD->udebug.active_cv, &THREAD->udebug.lock); 483 mutex_unlock(&THREAD->udebug.lock); 484 485 udebug_stoppable_end(); 486 } 458 487 459 488 /** @} -
kernel/generic/src/udebug/udebug_ipc.c
rb86d436 r5cde90f 41 41 #include <proc/task.h> 42 42 #include <proc/thread.h> 43 #include <mm/as.h> 43 44 #include <arch.h> 44 45 #include <errno.h> … … 165 166 static void udebug_receive_thread_read(call_t *call) 166 167 { 168 uintptr_t uspace_addr; 169 size_t buf_size; 170 void *buffer; 171 size_t copied, needed; 172 int rc; 173 174 uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ 175 buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ 176 177 /* 178 * Read thread list. Variable n will be filled with actual number 179 * of threads times thread-id size. 180 */ 181 rc = udebug_thread_read(&buffer, buf_size, &copied, &needed); 182 if (rc < 0) { 183 IPC_SET_RETVAL(call->data, rc); 184 ipc_answer(&TASK->kb.box, call); 185 return; 186 } 187 188 /* 189 * Make use of call->buffer to transfer data to caller's userspace 190 */ 191 192 IPC_SET_RETVAL(call->data, 0); 193 /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that 194 same code in process_answer() can be used 195 (no way to distinguish method in answer) */ 196 IPC_SET_ARG1(call->data, uspace_addr); 197 IPC_SET_ARG2(call->data, copied); 198 IPC_SET_ARG3(call->data, needed); 199 call->buffer = buffer; 200 201 ipc_answer(&TASK->kb.box, call); 202 } 203 204 /** Process a NAME_READ call. 205 * 206 * Returns a string containing the name of the task. 207 * 208 * @param call The call structure. 209 */ 210 static void udebug_receive_name_read(call_t *call) 211 { 167 212 unative_t uspace_addr; 168 213 unative_t to_copy; 169 unsigned total_bytes; 170 unsigned buf_size; 171 void *buffer; 172 size_t n; 173 int rc; 214 size_t data_size; 215 size_t buf_size; 216 void *data; 174 217 175 218 uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ … … 177 220 178 221 /* 179 * Read thread list. Variable n will be filled with actual number 180 * of threads times thread-id size. 181 */ 182 rc = udebug_thread_read(&buffer, buf_size, &n); 183 if (rc < 0) { 184 IPC_SET_RETVAL(call->data, rc); 185 ipc_answer(&TASK->kb.box, call); 186 return; 187 } 188 189 total_bytes = n; 190 191 /* Copy MAX(buf_size, total_bytes) bytes */ 192 193 if (buf_size > total_bytes) 194 to_copy = total_bytes; 222 * Read task name. 223 */ 224 udebug_name_read((char **) &data, &data_size); 225 226 /* Copy MAX(buf_size, data_size) bytes */ 227 228 if (buf_size > data_size) 229 to_copy = data_size; 195 230 else 196 231 to_copy = buf_size; … … 207 242 IPC_SET_ARG2(call->data, to_copy); 208 243 209 IPC_SET_ARG3(call->data, total_bytes); 210 call->buffer = buffer; 211 212 ipc_answer(&TASK->kb.box, call); 213 } 244 IPC_SET_ARG3(call->data, data_size); 245 call->buffer = data; 246 247 ipc_answer(&TASK->kb.box, call); 248 } 249 250 /** Process an AREAS_READ call. 251 * 252 * Returns a list of address space areas in the current task, as an array 253 * of as_area_info_t structures. 254 * 255 * @param call The call structure. 256 */ 257 static void udebug_receive_areas_read(call_t *call) 258 { 259 unative_t uspace_addr; 260 unative_t to_copy; 261 size_t data_size; 262 size_t buf_size; 263 void *data; 264 265 uspace_addr = IPC_GET_ARG2(call->data); /* Destination address */ 266 buf_size = IPC_GET_ARG3(call->data); /* Dest. buffer size */ 267 268 /* 269 * Read area list. 270 */ 271 as_get_area_info(AS, (as_area_info_t **) &data, &data_size); 272 273 /* Copy MAX(buf_size, data_size) bytes */ 274 275 if (buf_size > data_size) 276 to_copy = data_size; 277 else 278 to_copy = buf_size; 279 280 /* 281 * Make use of call->buffer to transfer data to caller's userspace 282 */ 283 284 IPC_SET_RETVAL(call->data, 0); 285 /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that 286 same code in process_answer() can be used 287 (no way to distinguish method in answer) */ 288 IPC_SET_ARG1(call->data, uspace_addr); 289 IPC_SET_ARG2(call->data, to_copy); 290 291 IPC_SET_ARG3(call->data, data_size); 292 call->buffer = data; 293 294 ipc_answer(&TASK->kb.box, call); 295 } 296 214 297 215 298 /** Process an ARGS_READ call. … … 250 333 ipc_answer(&TASK->kb.box, call); 251 334 } 335 336 /** Receive a REGS_READ call. 337 * 338 * Reads the thread's register state (istate structure). 339 */ 340 static void udebug_receive_regs_read(call_t *call) 341 { 342 thread_t *t; 343 unative_t uspace_addr; 344 unative_t to_copy; 345 void *buffer; 346 int rc; 347 348 t = (thread_t *) IPC_GET_ARG2(call->data); 349 350 rc = udebug_regs_read(t, &buffer); 351 if (rc < 0) { 352 IPC_SET_RETVAL(call->data, rc); 353 ipc_answer(&TASK->kb.box, call); 354 return; 355 } 356 357 /* 358 * Make use of call->buffer to transfer data to caller's userspace 359 */ 360 361 uspace_addr = IPC_GET_ARG3(call->data); 362 to_copy = sizeof(istate_t); 363 364 IPC_SET_RETVAL(call->data, 0); 365 /* ARG1=dest, ARG2=size as in IPC_M_DATA_READ so that 366 same code in process_answer() can be used 367 (no way to distinguish method in answer) */ 368 IPC_SET_ARG1(call->data, uspace_addr); 369 IPC_SET_ARG2(call->data, to_copy); 370 371 call->buffer = buffer; 372 373 ipc_answer(&TASK->kb.box, call); 374 } 375 252 376 253 377 /** Process an MEM_READ call. … … 331 455 udebug_receive_thread_read(call); 332 456 break; 457 case UDEBUG_M_NAME_READ: 458 udebug_receive_name_read(call); 459 break; 460 case UDEBUG_M_AREAS_READ: 461 udebug_receive_areas_read(call); 462 break; 333 463 case UDEBUG_M_ARGS_READ: 334 464 udebug_receive_args_read(call); 335 465 break; 466 case UDEBUG_M_REGS_READ: 467 udebug_receive_regs_read(call); 468 break; 336 469 case UDEBUG_M_MEM_READ: 337 470 udebug_receive_mem_read(call); -
kernel/generic/src/udebug/udebug_ops.c
rb86d436 r5cde90f 46 46 #include <errno.h> 47 47 #include <print.h> 48 #include <string.h> 48 49 #include <syscall/copy.h> 49 50 #include <ipc/ipc.h> … … 209 210 210 211 mutex_lock(&t->udebug.lock); 211 if ((t->flags & THREAD_FLAG_USPACE) != 0) 212 if ((t->flags & THREAD_FLAG_USPACE) != 0) { 212 213 t->udebug.active = true; 213 mutex_unlock(&t->udebug.lock); 214 mutex_unlock(&t->udebug.lock); 215 condvar_broadcast(&t->udebug.active_cv); 216 } else { 217 mutex_unlock(&t->udebug.lock); 218 } 214 219 } 215 220 … … 355 360 * 356 361 * If the sequence is longer than @a buf_size bytes, only as much hashes 357 * as can fit are copied. The number of thread hashes copied is stored 358 * in @a n. 362 * as can fit are copied. The number of bytes copied is stored in @a stored. 363 * The total number of thread bytes that could have been saved had there been 364 * enough space is stored in @a needed. 359 365 * 360 366 * The rationale for having @a buf_size is that this function is only … … 364 370 * @param buffer The buffer for storing thread hashes. 365 371 * @param buf_size Buffer size in bytes. 366 * @param n The actual number of hashes copied will be stored here. 367 */ 368 int udebug_thread_read(void **buffer, size_t buf_size, size_t *n) 372 * @param stored The actual number of bytes copied will be stored here. 373 * @param needed Total number of hashes that could have been saved. 374 */ 375 int udebug_thread_read(void **buffer, size_t buf_size, size_t *stored, 376 size_t *needed) 369 377 { 370 378 thread_t *t; 371 379 link_t *cur; 372 380 unative_t tid; 373 unsigned copied_ids; 381 size_t copied_ids; 382 size_t extra_ids; 374 383 ipl_t ipl; 375 384 unative_t *id_buffer; … … 380 389 381 390 /* Allocate a buffer to hold thread IDs */ 382 id_buffer = malloc(buf_size , 0);391 id_buffer = malloc(buf_size + 1, 0); 383 392 384 393 mutex_lock(&TASK->udebug.lock); … … 396 405 max_ids = buf_size / sizeof(unative_t); 397 406 copied_ids = 0; 407 extra_ids = 0; 398 408 399 409 /* FIXME: make sure the thread isn't past debug shutdown... */ 400 410 for (cur = TASK->th_head.next; cur != &TASK->th_head; cur = cur->next) { 401 /* Do not write past end of buffer */402 if (copied_ids >= max_ids) break;403 404 411 t = list_get_instance(cur, thread_t, th_link); 405 412 … … 409 416 410 417 /* Not interested in kernel threads. */ 411 if ((flags & THREAD_FLAG_USPACE) != 0) { 418 if ((flags & THREAD_FLAG_USPACE) == 0) 419 continue; 420 421 if (copied_ids < max_ids) { 412 422 /* Using thread struct pointer as identification hash */ 413 423 tid = (unative_t) t; 414 424 id_buffer[copied_ids++] = tid; 425 } else { 426 extra_ids++; 415 427 } 416 428 } … … 422 434 423 435 *buffer = id_buffer; 424 *n = copied_ids * sizeof(unative_t); 436 *stored = copied_ids * sizeof(unative_t); 437 *needed = (copied_ids + extra_ids) * sizeof(unative_t); 438 439 return 0; 440 } 441 442 /** Read task name. 443 * 444 * Returns task name as non-terminated string in a newly allocated buffer. 445 * Also returns the size of the data. 446 * 447 * @param data Place to store pointer to newly allocated block. 448 * @param data_size Place to store size of the data. 449 * 450 * @returns EOK. 451 */ 452 int udebug_name_read(char **data, size_t *data_size) 453 { 454 size_t name_size; 455 456 name_size = str_size(TASK->name) + 1; 457 *data = malloc(name_size, 0); 458 *data_size = name_size; 459 460 memcpy(*data, TASK->name, name_size); 425 461 426 462 return 0; … … 437 473 * this function will fail with an EINVAL error code. 438 474 * 439 * @param buffer The buffer for storing thread hashes. 475 * @param t Thread where call arguments are to be read. 476 * @param buffer Place to store pointer to new buffer. 477 * @return EOK on success, ENOENT if @a t is invalid, EINVAL 478 * if thread state is not valid for this operation. 440 479 */ 441 480 int udebug_args_read(thread_t *t, void **buffer) … … 469 508 } 470 509 510 /** Read the register state of the thread. 511 * 512 * The contents of the thread's istate structure are copied to a newly 513 * allocated buffer and a pointer to it is written to @a buffer. The size of 514 * the buffer will be sizeof(istate_t). 515 * 516 * Currently register state cannot be read if the thread is inside a system 517 * call (as opposed to an exception). This is an implementation limit. 518 * 519 * @param t Thread whose state is to be read. 520 * @param buffer Place to store pointer to new buffer. 521 * @return EOK on success, ENOENT if @a t is invalid, EINVAL 522 * if thread is not in valid state, EBUSY if istate 523 * is not available. 524 */ 525 int udebug_regs_read(thread_t *t, void **buffer) 526 { 527 istate_t *state, *state_buf; 528 int rc; 529 530 /* Prepare a buffer to hold the data. */ 531 state_buf = malloc(sizeof(istate_t), 0); 532 533 /* On success, this will lock t->udebug.lock */ 534 rc = _thread_op_begin(t, false); 535 if (rc != EOK) { 536 return rc; 537 } 538 539 state = t->udebug.uspace_state; 540 if (state == NULL) { 541 _thread_op_end(t); 542 return EBUSY; 543 } 544 545 /* Copy to the allocated buffer */ 546 memcpy(state_buf, state, sizeof(istate_t)); 547 548 _thread_op_end(t); 549 550 *buffer = (void *) state_buf; 551 return 0; 552 } 553 471 554 /** Read the memory of the debugged task. 472 555 *
Note:
See TracChangeset
for help on using the changeset viewer.
