- Timestamp:
- 2012-05-05T08:12:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ee04c28
- Parents:
- 2cc7f16 (diff), d21e935c (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:
-
- 1 added
- 43 edited
-
Makefile (modified) (1 diff)
-
arch/amd64/include/context.h (modified) (1 diff)
-
arch/arm32/Makefile.inc (modified) (2 diffs)
-
arch/arm32/include/context.h (modified) (1 diff)
-
arch/arm32/src/eabi.S (added)
-
arch/arm32/src/mach/testarm/testarm.c (modified) (5 diffs)
-
arch/ia64/include/asm.h (modified) (6 diffs)
-
arch/ia64/include/context.h (modified) (2 diffs)
-
arch/ia64/src/ia64.c (modified) (1 diff)
-
arch/mips32/include/context.h (modified) (1 diff)
-
arch/mips32/include/stack.h (modified) (2 diffs)
-
arch/mips32/src/start.S (modified) (5 diffs)
-
arch/mips64/include/context.h (modified) (1 diff)
-
arch/mips64/include/stack.h (modified) (1 diff)
-
arch/mips64/src/start.S (modified) (5 diffs)
-
arch/ppc32/src/ppc32.c (modified) (2 diffs)
-
arch/sparc64/include/context.h (modified) (2 diffs)
-
arch/sparc64/src/sun4u/sparc64.c (modified) (1 diff)
-
arch/sparc64/src/sun4v/sparc64.c (modified) (1 diff)
-
genarch/include/ofw/ofw_tree.h (modified) (1 diff)
-
genarch/include/softint/division.h (modified) (1 diff)
-
genarch/include/softint/multiplication.h (modified) (2 diffs)
-
genarch/src/fb/fb.c (modified) (1 diff)
-
genarch/src/ofw/ofw_tree.c (modified) (13 diffs)
-
genarch/src/softint/division.c (modified) (12 diffs)
-
genarch/src/softint/multiplication.c (modified) (2 diffs)
-
generic/include/context.h (modified) (1 diff)
-
generic/include/str.h (modified) (1 diff)
-
generic/include/sysinfo/sysinfo.h (modified) (6 diffs)
-
generic/src/console/cmd.c (modified) (1 diff)
-
generic/src/console/console.c (modified) (1 diff)
-
generic/src/console/kconsole.c (modified) (1 diff)
-
generic/src/ddi/ddi.c (modified) (1 diff)
-
generic/src/ipc/sysipc.c (modified) (4 diffs)
-
generic/src/lib/func.c (modified) (1 diff)
-
generic/src/lib/str.c (modified) (5 diffs)
-
generic/src/main/main.c (modified) (2 diffs)
-
generic/src/main/version.c (modified) (1 diff)
-
generic/src/mm/page.c (modified) (2 diffs)
-
generic/src/printf/printf_core.c (modified) (2 diffs)
-
generic/src/syscall/syscall.c (modified) (1 diff)
-
generic/src/sysinfo/stats.c (modified) (25 diffs)
-
generic/src/sysinfo/sysinfo.c (modified) (22 diffs)
-
test/print/print1.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
r2cc7f16 rc6588ce 90 90 endif 91 91 92 DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-D NAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__92 DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__ 93 93 94 94 GCC_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \ -
kernel/arch/amd64/include/context.h
r2cc7f16 rc6588ce 38 38 #include <typedefs.h> 39 39 40 /* According to ABI the stack MUST be aligned on 40 /* 41 * According to ABI the stack MUST be aligned on 41 42 * 16-byte boundary. If it is not, the va_arg calling will 42 43 * panic sooner or later -
kernel/arch/arm32/Makefile.inc
r2cc7f16 rc6588ce 33 33 ATSIGN = % 34 34 35 GCC_CFLAGS += - fno-zero-initialized-in-bss -mapcs-frame35 GCC_CFLAGS += -march=armv4 36 36 37 37 BITS = 32 … … 41 41 arch/$(KARCH)/src/start.S \ 42 42 arch/$(KARCH)/src/asm.S \ 43 arch/$(KARCH)/src/eabi.S \ 43 44 arch/$(KARCH)/src/exc_handler.S \ 44 45 arch/$(KARCH)/src/arm32.c \ -
kernel/arch/arm32/include/context.h
r2cc7f16 rc6588ce 27 27 */ 28 28 29 /** @addtogroup arm32 29 /** @addtogroup arm32 30 30 * @{ 31 31 */ -
kernel/arch/arm32/src/mach/testarm/testarm.c
r2cc7f16 rc6588ce 121 121 } 122 122 } 123 123 124 124 /* 125 125 * This is the necessary evil until the userspace driver is entirely … … 172 172 clock(); 173 173 spinlock_lock(&irq->lock); 174 174 175 175 /* acknowledge tick */ 176 176 *((uint32_t *) (gxemul_rtc + GXEMUL_RTC_ACK_OFFSET)) … … 181 181 static void gxemul_timer_irq_init(void) 182 182 { 183 irq_initialize(&gxemul_timer_irq);184 gxemul_timer_irq.devno = device_assign_devno();185 gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ;186 gxemul_timer_irq.claim = gxemul_timer_claim;187 gxemul_timer_irq.handler = gxemul_timer_irq_handler;188 189 irq_register(&gxemul_timer_irq);183 irq_initialize(&gxemul_timer_irq); 184 gxemul_timer_irq.devno = device_assign_devno(); 185 gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ; 186 gxemul_timer_irq.claim = gxemul_timer_claim; 187 gxemul_timer_irq.handler = gxemul_timer_irq_handler; 188 189 irq_register(&gxemul_timer_irq); 190 190 } 191 191 … … 198 198 void gxemul_timer_irq_start(void) 199 199 { 200 gxemul_timer_irq_init();201 gxemul_timer_start(GXEMUL_TIMER_FREQ);200 gxemul_timer_irq_init(); 201 gxemul_timer_start(GXEMUL_TIMER_FREQ); 202 202 } 203 203 … … 227 227 uint32_t sources = gxemul_irqc_get_sources(); 228 228 unsigned int i; 229 229 230 230 for (i = 0; i < GXEMUL_IRQ_COUNT; i++) { 231 231 if (sources & (1 << i)) { -
kernel/arch/ia64/include/asm.h
r2cc7f16 rc6588ce 61 61 asm volatile ( 62 62 "mf\n" 63 "mf.a\n" 63 64 ::: "memory" 64 65 ); … … 74 75 asm volatile ( 75 76 "mf\n" 77 "mf.a\n" 76 78 ::: "memory" 77 79 ); … … 87 89 asm volatile ( 88 90 "mf\n" 91 "mf.a\n" 89 92 ::: "memory" 90 93 ); … … 104 107 else 105 108 v = *port; 109 110 asm volatile ( 111 "mf.a\n" 112 ::: "memory" 113 ); 106 114 107 115 return v; … … 121 129 else 122 130 v = *port; 131 132 asm volatile ( 133 "mf.a\n" 134 ::: "memory" 135 ); 123 136 124 137 return v; … … 138 151 else 139 152 v = *port; 153 154 asm volatile ( 155 "mf.a\n" 156 ::: "memory" 157 ); 140 158 141 159 return v; -
kernel/arch/ia64/include/context.h
r2cc7f16 rc6588ce 27 27 */ 28 28 29 /** @addtogroup ia64 29 /** @addtogroup ia64 30 30 * @{ 31 31 */ … … 47 47 * One item is put onto the stack to support get_stack_base(). 48 48 */ 49 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))49 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 50 50 51 51 /* RSE stack starts at the bottom of memory stack, hence the division by 2. */ 52 #define context_set(c, _pc, stack, size) \53 do { \54 (c)->pc = (uintptr_t) _pc; \55 (c)->bsp = ((uintptr_t) stack) + ALIGN_UP((size / 2), REGISTER_STACK_ALIGNMENT); \56 (c)->ar_pfs &= PFM_MASK; \57 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size / 2), STACK_ALIGNMENT) - SP_DELTA; \58 } while (0) ;52 #define context_set(c, _pc, stack, size) \ 53 do { \ 54 (c)->pc = (uintptr_t) _pc; \ 55 (c)->bsp = ((uintptr_t) stack) + ALIGN_UP((size / 2), REGISTER_STACK_ALIGNMENT); \ 56 (c)->ar_pfs &= PFM_MASK; \ 57 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size / 2), STACK_ALIGNMENT) - SP_DELTA; \ 58 } while (0) 59 59 60 60 /* -
kernel/arch/ia64/src/ia64.c
r2cc7f16 rc6588ce 144 144 #endif 145 145 #ifdef MACHINE_i460GX 146 platform = " i460GX";146 platform = "pc"; 147 147 #endif 148 148 sysinfo_set_item_data("platform", NULL, (void *) platform, -
kernel/arch/mips32/include/context.h
r2cc7f16 rc6588ce 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))44 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 45 45 46 46 #ifndef __ASM__ -
kernel/arch/mips32/include/stack.h
r2cc7f16 rc6588ce 27 27 */ 28 28 29 /** @addtogroup mips32 29 /** @addtogroup mips32 30 30 * @{ 31 31 */ … … 36 36 #define KERN_mips32_STACK_H_ 37 37 38 #define STACK_ITEM_SIZE 4 39 #define STACK_ALIGNMENT 8 38 #define STACK_ITEM_SIZE 4 39 #define STACK_ALIGNMENT 8 40 #define ABI_STACK_FRAME 32 40 41 41 42 #endif -
kernel/arch/mips32/src/start.S
r2cc7f16 rc6588ce 241 241 /* $a1 contains physical address of bootinfo_t */ 242 242 jal arch_pre_main 243 nop243 addiu $sp, -ABI_STACK_FRAME 244 244 245 245 j main_bsp … … 281 281 282 282 move $a1, $sp 283 move $a0, $k0 283 284 jal exc_dispatch /* exc_dispatch(excno, register_space) */ 284 move $a0, $k0 285 addiu $sp, -ABI_STACK_FRAME 286 addiu $sp, ABI_STACK_FRAME 285 287 286 288 REGISTERS_LOAD $sp … … 323 325 sw $t0, ISTATE_OFFSET_T0($sp) /* save the 5th argument on the stack */ 324 326 sw $t1, ISTATE_OFFSET_T1($sp) /* save the 6th argument on the stack */ 327 325 328 jal syscall_handler 326 329 sw $v0, ISTATE_OFFSET_V0($sp) /* save the syscall number on the stack */ … … 357 360 move $sp, $k0 358 361 362 move $a0, $sp 359 363 jal tlb_refill 360 move $a0, $sp 364 addiu $sp, -ABI_STACK_FRAME 365 addiu $sp, ABI_STACK_FRAME 361 366 362 367 REGISTERS_LOAD $sp … … 366 371 cache_error_handler: 367 372 KERNEL_STACK_TO_K0 368 sub $k0, ISTATE_SOFT_SIZE 373 sub $k0, ISTATE_SOFT_SIZE 369 374 REGISTERS_STORE_AND_EXC_RESET $k0 370 375 sw $sp, ISTATE_OFFSET_SP($k0) 371 376 move $sp, $k0 372 377 378 move $a0, $sp 373 379 jal cache_error 374 move $a0, $sp 380 addiu $sp, -ABI_STACK_FRAME 381 addiu $sp, ABI_STACK_FRAME 375 382 376 383 REGISTERS_LOAD $sp -
kernel/arch/mips64/include/context.h
r2cc7f16 rc6588ce 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))44 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 45 45 46 46 #ifndef __ASM__ -
kernel/arch/mips64/include/stack.h
r2cc7f16 rc6588ce 38 38 #define STACK_ITEM_SIZE 8 39 39 #define STACK_ALIGNMENT 8 40 #define ABI_STACK_FRAME 64 40 41 41 42 #endif -
kernel/arch/mips64/src/start.S
r2cc7f16 rc6588ce 241 241 /* $a1 contains physical address of bootinfo_t */ 242 242 jal arch_pre_main 243 nop243 addiu $sp, -ABI_STACK_FRAME 244 244 245 245 j main_bsp … … 281 281 282 282 move $a1, $sp 283 move $a0, $k0 283 284 jal exc_dispatch /* exc_dispatch(excno, register_space) */ 284 move $a0, $k0 285 addiu $sp, -ABI_STACK_FRAME 286 addiu $sp, ABI_STACK_FRAME 285 287 286 288 REGISTERS_LOAD $sp … … 323 325 sw $t0, ISTATE_OFFSET_T0($sp) /* save the 5th argument on the stack */ 324 326 sw $t1, ISTATE_OFFSET_T1($sp) /* save the 6th argument on the stack */ 327 325 328 jal syscall_handler 326 329 sw $v0, ISTATE_OFFSET_V0($sp) /* save the syscall number on the stack */ … … 357 360 move $sp, $k0 358 361 362 move $a0, $sp 359 363 jal tlb_refill 360 move $a0, $sp 364 addiu $sp, -ABI_STACK_FRAME 365 addiu $sp, ABI_STACK_FRAME 361 366 362 367 REGISTERS_LOAD $sp … … 366 371 cache_error_handler: 367 372 KERNEL_STACK_TO_K0 368 sub $k0, ISTATE_SOFT_SIZE 373 sub $k0, ISTATE_SOFT_SIZE 369 374 REGISTERS_STORE_AND_EXC_RESET $k0 370 375 sw $sp, ISTATE_OFFSET_SP($k0) 371 376 move $sp, $k0 372 377 378 move $a0, $sp 373 379 jal cache_error 374 move $a0, $sp 380 addiu $sp, -ABI_STACK_FRAME 381 addiu $sp, ABI_STACK_FRAME 375 382 376 383 REGISTERS_LOAD $sp -
kernel/arch/ppc32/src/ppc32.c
r2cc7f16 rc6588ce 130 130 visual = VISUAL_INDIRECT_8; 131 131 break; 132 case 15: 133 visual = VISUAL_RGB_5_5_5_BE; 134 break; 132 135 case 16: 133 visual = VISUAL_RGB_5_ 5_5_BE;136 visual = VISUAL_RGB_5_6_5_BE; 134 137 break; 135 138 case 24: … … 173 176 ofw_tree_walk_by_device_type("display", display_register, NULL); 174 177 #endif 178 /* Map OFW information into sysinfo */ 179 ofw_sysinfo_map(); 175 180 176 181 /* Initialize IRQ routing */ -
kernel/arch/sparc64/include/context.h
r2cc7f16 rc6588ce 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ … … 40 40 #include <align.h> 41 41 42 #define SP_DELTA (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)42 #define SP_DELTA (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE) 43 43 44 #define context_set(c, _pc, stack, size) \ 45 (c)->pc = ((uintptr_t) _pc) - 8; \ 46 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), \ 47 STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ 48 (c)->fp = -STACK_BIAS 49 44 #define context_set(c, _pc, stack, size) \ 45 do { \ 46 (c)->pc = ((uintptr_t) _pc) - 8; \ 47 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), \ 48 STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ 49 (c)->fp = -STACK_BIAS; \ 50 } while (0) 50 51 51 52 /* -
kernel/arch/sparc64/src/sun4u/sparc64.c
r2cc7f16 rc6588ce 94 94 { 95 95 if (config.cpu_active == 1) { 96 /* Map OFW information into sysinfo */ 97 ofw_sysinfo_map(); 98 96 99 /* 97 100 * We have 2^11 different interrupt vectors. -
kernel/arch/sparc64/src/sun4v/sparc64.c
r2cc7f16 rc6588ce 92 92 { 93 93 if (config.cpu_active == 1) { 94 /* Map OFW information into sysinfo */ 95 ofw_sysinfo_map(); 96 94 97 /* 95 98 * We have 2^11 different interrupt vectors. -
kernel/genarch/include/ofw/ofw_tree.h
r2cc7f16 rc6588ce 67 67 68 68 extern void ofw_tree_init(ofw_tree_node_t *); 69 extern void ofw_ tree_print(void);69 extern void ofw_sysinfo_map(void); 70 70 71 71 extern const char *ofw_tree_node_name(const ofw_tree_node_t *); -
kernel/genarch/include/softint/division.h
r2cc7f16 rc6588ce 36 36 #define KERN_DIVISION_H_ 37 37 38 /* 32bit integer division */ 39 int __divsi3(int a, int b);38 extern int __divsi3(int, int); 39 extern long long __divdi3(long long, long long); 40 40 41 /* 64bit integer division */ 42 long long __divdi3(long long a, long long b);41 extern unsigned int __udivsi3(unsigned int, unsigned int); 42 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 43 43 44 /* 32bit unsigned integer division */ 45 unsigned int __udivsi3(unsigned int a, unsigned int b);44 extern int __modsi3(int, int); 45 extern long long __moddi3(long long, long long); 46 46 47 /* 64bit unsigned integer division */ 48 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);47 extern unsigned int __umodsi3(unsigned int, unsigned int); 48 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 49 49 50 /* 32bit remainder of the signed division */ 51 int __modsi3(int a, int b);50 extern int __divmodsi3(int, int, int *); 51 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 52 52 53 /* 64bit remainder of the signed division */ 54 long long __moddi3(long long a, long long b); 55 56 /* 32bit remainder of the unsigned division */ 57 unsigned int __umodsi3(unsigned int a, unsigned int b); 58 59 /* 64bit remainder of the unsigned division */ 60 unsigned long long __umoddi3(unsigned long long a, unsigned long long b); 61 62 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c); 53 extern long long __divmoddi3(long long, long long, long long *); 54 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 55 unsigned long long *); 63 56 64 57 #endif -
kernel/genarch/include/softint/multiplication.h
r2cc7f16 rc6588ce 29 29 /** @addtogroup genarch 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file 34 34 */ 35 35 36 #ifndef __SOFTINT_MULTIPLICATION_H__37 #define __SOFTINT_MULTIPLICATION_H__36 #ifndef KERN_MULTIPLICATION_H_ 37 #define KERN_MULTIPLICATION_H_ 38 38 39 39 /* 64 bit multiplication */ 40 long long __muldi3(long long a, long long b);40 extern long long __muldi3(long long, long long); 41 41 42 42 #endif … … 44 44 /** @} 45 45 */ 46 47 -
kernel/genarch/src/fb/fb.c
r2cc7f16 rc6588ce 390 390 instance->position / instance->cols, false); 391 391 instance->position++; 392 } while (( instance->position % 8)393 &&(instance->position < instance->cols * instance->rows));392 } while (((instance->position % instance->cols) % 8 != 0) && 393 (instance->position < instance->cols * instance->rows)); 394 394 break; 395 395 default: -
kernel/genarch/src/ofw/ofw_tree.c
r2cc7f16 rc6588ce 38 38 #include <genarch/ofw/ofw_tree.h> 39 39 #include <mm/slab.h> 40 #include <sysinfo/sysinfo.h> 40 41 #include <memstr.h> 41 42 #include <str.h> … … 65 66 const char *name) 66 67 { 67 size_t i; 68 69 for (i = 0; i < node->properties; i++) { 68 for (size_t i = 0; i < node->properties; i++) { 70 69 if (str_cmp(node->property[i].name, name) == 0) 71 70 return &node->property[i]; … … 104 103 const char *name) 105 104 { 106 ofw_tree_node_t *cur;107 108 105 /* 109 106 * Try to find the disambigued name. 110 107 */ 111 for ( cur = node->child; cur; cur = cur->peer) {108 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 112 109 if (str_cmp(cur->da_name, name) == 0) 113 110 return cur; … … 121 118 * are not always fully-qualified. 122 119 */ 123 for ( cur = node->child; cur; cur = cur->peer) {120 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 124 121 if (str_cmp(ofw_tree_node_name(cur), name) == 0) 125 122 return cur; … … 141 138 const char *dtype) 142 139 { 143 ofw_tree_node_t *cur; 144 145 for (cur = node->child; cur; cur = cur->peer) { 140 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 146 141 ofw_tree_property_t *prop = 147 142 ofw_tree_getprop(cur, "device_type"); … … 172 167 phandle handle) 173 168 { 174 ofw_tree_node_t *cur; 175 176 for (cur = root; cur; cur = cur->peer) { 169 for (ofw_tree_node_t *cur = root; cur; cur = cur->peer) { 177 170 if (cur->node_handle == handle) 178 171 return cur; 179 172 180 173 if (cur->child) { 181 ofw_tree_node_t *node 182 =ofw_tree_find_node_by_handle(cur->child, handle);174 ofw_tree_node_t *node = 175 ofw_tree_find_node_by_handle(cur->child, handle); 183 176 if (node) 184 177 return node; … … 201 194 const char *dtype) 202 195 { 203 ofw_tree_node_t *cur; 204 205 for (cur = node->peer; cur; cur = cur->peer) { 196 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 206 197 ofw_tree_property_t *prop = 207 198 ofw_tree_getprop(cur, "device_type"); … … 229 220 const char *name) 230 221 { 231 ofw_tree_node_t *cur; 232 233 for (cur = node->peer; cur; cur = cur->peer) { 234 ofw_tree_property_t *prop 235 = ofw_tree_getprop(cur, "name"); 222 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 223 ofw_tree_property_t *prop = 224 ofw_tree_getprop(cur, "name"); 236 225 237 226 if ((!prop) || (!prop->value)) … … 259 248 260 249 ofw_tree_node_t *node = ofw_root; 261 size_t i;262 250 size_t j; 263 251 264 for ( i = 1; (i < str_size(path)) && (node); i = j + 1) {252 for (size_t i = 1; (i < str_size(path)) && (node); i = j + 1) { 265 253 for (j = i; (j < str_size(path)) && (path[j] != '/'); j++); 266 254 … … 294 282 const char *dtype, ofw_tree_walker_t walker, void *arg) 295 283 { 296 ofw_tree_node_t *cur; 297 298 for (cur = node; cur; cur = cur->peer) { 284 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 299 285 ofw_tree_property_t *prop = 300 286 ofw_tree_getprop(cur, "device_type"); … … 334 320 } 335 321 336 /** Print OpenFirmware device subtree rooted in a node. 322 /** Get OpenFirmware node properties. 323 * 324 * @param item Sysinfo item (unused). 325 * @param size Size of the returned data. 326 * @param dry_run Do not get the data, just calculate the size. 327 * @param data OpenFirmware node. 328 * 329 * @return Data containing a serialized dump of all node 330 * properties. If the return value is not NULL, it 331 * should be freed in the context of the sysinfo request. 332 * 333 */ 334 static void *ofw_sysinfo_properties(struct sysinfo_item *item, size_t *size, 335 bool dry_run, void *data) 336 { 337 ofw_tree_node_t *node = (ofw_tree_node_t *) data; 338 339 /* Compute serialized data size */ 340 *size = 0; 341 for (size_t i = 0; i < node->properties; i++) 342 *size += str_size(node->property[i].name) + 1 + 343 sizeof(node->property[i].size) + node->property[i].size; 344 345 if (dry_run) 346 return NULL; 347 348 void *dump = malloc(*size, FRAME_ATOMIC); 349 if (dump == NULL) { 350 *size = 0; 351 return NULL; 352 } 353 354 /* Serialize the data */ 355 size_t pos = 0; 356 for (size_t i = 0; i < node->properties; i++) { 357 /* Property name */ 358 str_cpy(dump + pos, *size - pos, node->property[i].name); 359 pos += str_size(node->property[i].name) + 1; 360 361 /* Value size */ 362 memcpy(dump + pos, &node->property[i].size, 363 sizeof(node->property[i].size)); 364 pos += sizeof(node->property[i].size); 365 366 /* Value */ 367 memcpy(dump + pos, node->property[i].value, 368 node->property[i].size); 369 pos += node->property[i].size; 370 } 371 372 return ((void *) dump); 373 } 374 375 /** Map OpenFirmware device subtree rooted in a node into sysinfo. 337 376 * 338 377 * Child nodes are processed recursively and peer nodes are processed … … 343 382 * 344 383 */ 345 static void ofw_tree_node_ print(ofw_tree_node_t *node, const char *path)384 static void ofw_tree_node_sysinfo(ofw_tree_node_t *node, const char *path) 346 385 { 347 386 char *cur_path = (char *) malloc(PATH_MAX_LEN, 0); 348 ofw_tree_node_t *cur; 349 350 for (cur = node; cur; cur = cur->peer) { 351 if ((cur->parent) && (path)) { 352 snprintf(cur_path, PATH_MAX_LEN, "%s/%s", path, cur->da_name); 353 printf("%s\n", cur_path); 354 } else { 355 snprintf(cur_path, PATH_MAX_LEN, "%s", cur->da_name); 356 printf("/\n"); 357 } 387 388 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 389 if ((cur->parent) && (path)) 390 snprintf(cur_path, PATH_MAX_LEN, "%s.%s", path, cur->da_name); 391 else 392 snprintf(cur_path, PATH_MAX_LEN, "firmware.%s", cur->da_name); 393 394 sysinfo_set_item_gen_data(cur_path, NULL, ofw_sysinfo_properties, 395 (void *) cur); 358 396 359 397 if (cur->child) 360 ofw_tree_node_ print(cur->child, cur_path);398 ofw_tree_node_sysinfo(cur->child, cur_path); 361 399 } 362 400 … … 364 402 } 365 403 366 /** Print the structure of the OpenFirmware device tree. */367 void ofw_ tree_print(void)368 { 369 ofw_tree_node_ print(ofw_root, NULL);404 /** Map the OpenFirmware device tree into sysinfo. */ 405 void ofw_sysinfo_map(void) 406 { 407 ofw_tree_node_sysinfo(ofw_root, NULL); 370 408 } 371 409 -
kernel/genarch/src/softint/division.c
r2cc7f16 rc6588ce 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 35 35 #include <genarch/softint/division.h> 36 36 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x))38 #define SGN(x) ((x) >= 0 ? 1 : 0)39 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 38 #define SGN(x) ((x) >= 0 ? 1 : 0) 39 40 40 static unsigned int divandmod32(unsigned int a, unsigned int b, 41 41 unsigned int *remainder) … … 56 56 return 0; 57 57 } 58 58 59 59 for (; steps > 0; steps--) { 60 60 /* shift one bit to remainder */ … … 68 68 a <<= 1; 69 69 } 70 70 71 71 return result; 72 72 } 73 74 73 75 74 static unsigned long long divandmod64(unsigned long long a, … … 77 76 { 78 77 unsigned long long result; 79 int steps = sizeof(unsigned long long) * 8; 78 int steps = sizeof(unsigned long long) * 8; 80 79 81 80 *remainder = 0; … … 91 90 return 0; 92 91 } 93 92 94 93 for (; steps > 0; steps--) { 95 94 /* shift one bit to remainder */ … … 103 102 a <<= 1; 104 103 } 105 104 106 105 return result; 107 106 } 108 107 109 108 /* 32bit integer division */ 110 int __divsi3(int a, int b) 111 { 112 unsigned int rem; 113 int result; 114 115 result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 116 109 int __divsi3(int a, int b) 110 { 111 unsigned int rem; 112 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 113 117 114 if (SGN(a) == SGN(b)) 118 115 return result; 116 119 117 return -result; 120 118 } 121 119 122 120 /* 64bit integer division */ 123 long long __divdi3(long long a, long long b) 124 { 125 unsigned long long rem; 126 long long result; 127 128 result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 129 121 long long __divdi3(long long a, long long b) 122 { 123 unsigned long long rem; 124 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 125 130 126 if (SGN(a) == SGN(b)) 131 127 return result; 128 132 129 return -result; 133 130 } … … 143 140 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 144 141 { 145 unsigned long long rem;142 unsigned long long rem; 146 143 return divandmod64(a, b, &rem); 147 144 } … … 154 151 155 152 /* if divident is negative, remainder must be too */ 156 if (!(SGN(a))) {153 if (!(SGN(a))) 157 154 return -((int) rem); 158 }159 155 160 156 return (int) rem; … … 162 158 163 159 /* 64bit remainder of the signed division */ 164 long long __moddi3(long long a, longlong b)160 long long __moddi3(long long a, long long b) 165 161 { 166 162 unsigned long long rem; … … 168 164 169 165 /* if divident is negative, remainder must be too */ 170 if (!(SGN(a))) {166 if (!(SGN(a))) 171 167 return -((long long) rem); 172 }173 168 174 169 return (long long) rem; … … 191 186 } 192 187 188 int __divmodsi3(int a, int b, int *c) 189 { 190 unsigned int rem; 191 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 192 193 if (SGN(a) == SGN(b)) { 194 *c = rem; 195 return result; 196 } 197 198 *c = -rem; 199 return -result; 200 } 201 202 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 203 unsigned int *c) 204 { 205 return divandmod32(a, b, c); 206 } 207 208 long long __divmoddi3(long long a, long long b, long long *c) 209 { 210 unsigned long long rem; 211 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 212 213 if (SGN(a) == SGN(b)) { 214 *c = rem; 215 return result; 216 } 217 218 *c = -rem; 219 return -result; 220 } 221 193 222 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 194 223 unsigned long long *c) -
kernel/genarch/src/softint/multiplication.c
r2cc7f16 rc6588ce 29 29 /** @addtogroup genarch 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 130 130 131 131 return result; 132 } 132 } 133 133 134 134 /** @} -
kernel/generic/include/context.h
r2cc7f16 rc6588ce 41 41 42 42 #define context_set_generic(ctx, _pc, stack, size) \ 43 (ctx)->pc = (uintptr_t) (_pc); \ 44 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 43 do { \ 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 } while (0) 45 47 46 48 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice)); -
kernel/generic/include/str.h
r2cc7f16 rc6588ce 97 97 extern bool wstr_remove(wchar_t *str, size_t pos); 98 98 99 extern int str_uint64 (const char *, char **, unsigned int, bool, uint64_t *);99 extern int str_uint64_t(const char *, char **, unsigned int, bool, uint64_t *); 100 100 101 101 extern void order_suffix(const uint64_t, uint64_t *, char *); -
kernel/generic/include/sysinfo/sysinfo.h
r2cc7f16 rc6588ce 1 1 /* 2 2 * Copyright (c) 2006 Jakub Vana 3 * Copyright (c) 2012 Martin Decky 3 4 * All rights reserved. 4 5 * … … 54 55 struct sysinfo_item; 55 56 56 /** Gerated numeric value function */ 57 typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *); 57 /** Generated numeric value function */ 58 typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *, void *); 59 60 /** Sysinfo generated numberic value data 61 * 62 */ 63 typedef struct { 64 sysinfo_fn_val_t fn; /**< Generated value function */ 65 void *data; /**< Private data */ 66 } sysinfo_gen_val_data_t; 58 67 59 68 /** Generated binary data function */ 60 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool); 69 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool, 70 void *); 71 72 /** Sysinfo generated binary data data 73 * 74 */ 75 typedef struct { 76 sysinfo_fn_data_t fn; /**< Generated binary data function */ 77 void *data; /**< Private data */ 78 } sysinfo_gen_data_data_t; 61 79 62 80 /** Sysinfo item binary data … … 72 90 */ 73 91 typedef union { 74 sysarg_t val; /**< Constant numberic value */75 sysinfo_ fn_val_t fn_val; /**< Generated numeric value function*/76 sysinfo_ fn_data_t fn_data; /**< Generated binary datafunction */77 sysinfo_ data_t data; /**< Constant binary data*/92 sysarg_t val; /**< Constant numberic value */ 93 sysinfo_data_t data; /**< Constant binary data */ 94 sysinfo_gen_val_data_t gen_val; /**< Generated numeric value function */ 95 sysinfo_gen_data_data_t gen_data; /**< Generated binary data function */ 78 96 } sysinfo_item_val_t; 79 97 … … 95 113 96 114 /** Generated subtree function */ 97 typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool); 115 typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool, void *); 116 117 /** Sysinfo generated subtree data 118 * 119 */ 120 typedef struct { 121 sysinfo_fn_subtree_t fn; /**< Generated subtree function */ 122 void *data; /**< Private data */ 123 } sysinfo_gen_subtree_data_t; 98 124 99 125 /** Sysinfo subtree (union) … … 101 127 */ 102 128 typedef union { 103 struct sysinfo_item *table; /**< Fixed subtree (list of subitems) */104 sysinfo_ fn_subtree_t get_data; /**< Generated subtree function*/129 struct sysinfo_item *table; /**< Fixed subtree (list of subitems) */ 130 sysinfo_gen_subtree_data_t generator; /**< Generated subtree */ 105 131 } sysinfo_subtree_t; 106 132 … … 123 149 extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *, 124 150 size_t); 125 extern void sysinfo_set_item_ fn_val(const char *, sysinfo_item_t **,126 sysinfo_fn_val_t );127 extern void sysinfo_set_item_ fn_data(const char *, sysinfo_item_t **,128 sysinfo_fn_data_t );151 extern void sysinfo_set_item_gen_val(const char *, sysinfo_item_t **, 152 sysinfo_fn_val_t, void *); 153 extern void sysinfo_set_item_gen_data(const char *, sysinfo_item_t **, 154 sysinfo_fn_data_t, void *); 129 155 extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **); 130 156 131 157 extern void sysinfo_set_subtree_fn(const char *, sysinfo_item_t **, 132 sysinfo_fn_subtree_t );158 sysinfo_fn_subtree_t, void *); 133 159 134 160 extern void sysinfo_init(void); 135 161 extern void sysinfo_dump(sysinfo_item_t *); 136 162 163 extern sysarg_t sys_sysinfo_get_keys_size(void *, size_t, void *); 164 extern sysarg_t sys_sysinfo_get_keys(void *, size_t, void *, size_t, size_t *); 137 165 extern sysarg_t sys_sysinfo_get_val_type(void *, size_t); 138 166 extern sysarg_t sys_sysinfo_get_value(void *, size_t, void *); -
kernel/generic/src/console/cmd.c
r2cc7f16 rc6588ce 906 906 ((char *) argv->buffer)[0] <= '9') { 907 907 uint64_t value; 908 rc = str_uint64 ((char *) argv->buffer, NULL, 0, true, &value);908 rc = str_uint64_t((char *) argv->buffer, NULL, 0, true, &value); 909 909 if (rc == EOK) 910 910 addr = (uintptr_t) value; -
kernel/generic/src/console/console.c
r2cc7f16 rc6588ce 57 57 58 58 /** Kernel log cyclic buffer */ 59 static wchar_t klog[KLOG_LENGTH] __attribute__ ((aligned(PAGE_SIZE)));59 wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE))); 60 60 61 61 /** Kernel log initialized */ -
kernel/generic/src/console/kconsole.c
r2cc7f16 rc6588ce 472 472 /* It's a number - convert it */ 473 473 uint64_t value; 474 int rc = str_uint64 (text, NULL, 0, true, &value);474 int rc = str_uint64_t(text, NULL, 0, true, &value); 475 475 switch (rc) { 476 476 case EINVAL: -
kernel/generic/src/ddi/ddi.c
r2cc7f16 rc6588ce 166 166 } 167 167 168 if (zones.info[znum].flags & ZONE_FIRMWARE) {169 /* 170 * Frames are part of firmware 168 if (zones.info[znum].flags & (ZONE_FIRMWARE | ZONE_RESERVED)) { 169 /* 170 * Frames are part of firmware or reserved zone 171 171 * -> allow mapping for privileged tasks. 172 172 */ -
kernel/generic/src/ipc/sysipc.c
r2cc7f16 rc6588ce 111 111 switch (imethod) { 112 112 case IPC_M_CONNECTION_CLONE: 113 case IPC_M_C ONNECT_ME:113 case IPC_M_CLONE_ESTABLISH: 114 114 case IPC_M_PHONE_HUNGUP: 115 115 /* This message is meant only for the original recipient. */ … … 160 160 switch (IPC_GET_IMETHOD(call->data)) { 161 161 case IPC_M_CONNECTION_CLONE: 162 case IPC_M_C ONNECT_ME:162 case IPC_M_CLONE_ESTABLISH: 163 163 case IPC_M_CONNECT_TO_ME: 164 164 case IPC_M_CONNECT_ME_TO: … … 225 225 mutex_unlock(&phone->lock); 226 226 } 227 } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_C ONNECT_ME) {227 } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CLONE_ESTABLISH) { 228 228 phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata); 229 229 … … 459 459 break; 460 460 } 461 case IPC_M_C ONNECT_ME:461 case IPC_M_CLONE_ESTABLISH: 462 462 IPC_SET_ARG5(call->data, (sysarg_t) phone); 463 463 break; -
kernel/generic/src/lib/func.c
r2cc7f16 rc6588ce 53 53 void halt() 54 54 { 55 #if def CONFIG_DEBUG55 #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE)) 56 56 bool rundebugger = false; 57 57 -
kernel/generic/src/lib/str.c
r2cc7f16 rc6588ce 111 111 #include <debug.h> 112 112 #include <macros.h> 113 114 /** Check the condition if wchar_t is signed */ 115 #ifdef WCHAR_IS_UNSIGNED 116 #define WCHAR_SIGNED_CHECK(cond) (true) 117 #else 118 #define WCHAR_SIGNED_CHECK(cond) (cond) 119 #endif 113 120 114 121 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 206 213 * 207 214 * @return EOK if the character was encoded successfully, EOVERFLOW if there 208 * was not enough space in the output buffer or EINVAL if the character209 * code was invalid.210 */ 211 int chr_encode( wchar_t ch, char *str, size_t *offset, size_t size)215 * was not enough space in the output buffer or EINVAL if the character 216 * code was invalid. 217 */ 218 int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size) 212 219 { 213 220 if (*offset >= size) … … 427 434 bool ascii_check(wchar_t ch) 428 435 { 429 if ( (ch >= 0) && (ch <= 127))436 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 430 437 return true; 431 438 … … 440 447 bool chr_check(wchar_t ch) 441 448 { 442 if ( (ch >= 0) && (ch <= 1114111))449 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 443 450 return true; 444 451 … … 893 900 * 894 901 */ 895 int str_uint64 (const char *nptr, char **endptr, unsigned int base,902 int str_uint64_t(const char *nptr, char **endptr, unsigned int base, 896 903 bool strict, uint64_t *result) 897 904 { -
kernel/generic/src/main/main.c
r2cc7f16 rc6588ce 221 221 frame_init(); 222 222 slab_cache_init(); 223 ra_init(); 223 ra_init(); 224 224 sysinfo_init(); 225 225 btree_init(); … … 257 257 for (i = 0; i < init.cnt; i++) 258 258 LOG("init[%zu].addr=%p, init[%zu].size=%zu", 259 i, (void *) init.tasks[i]. addr, i, init.tasks[i].size);259 i, (void *) init.tasks[i].paddr, i, init.tasks[i].size); 260 260 } else 261 261 printf("No init binaries found.\n"); -
kernel/generic/src/main/version.c
r2cc7f16 rc6588ce 38 38 39 39 static const char *project = "SPARTAN kernel"; 40 static const char *copyright = "Copyright (c) 2001-2011 HelenOS project";40 static const char *copyright = STRING(COPYRIGHT); 41 41 static const char *release = STRING(RELEASE); 42 42 static const char *name = STRING(NAME); -
kernel/generic/src/mm/page.c
r2cc7f16 rc6588ce 168 168 int page_find_mapping(uintptr_t virt, void **phys) 169 169 { 170 mutex_lock(&AS->lock);170 page_table_lock(AS, true); 171 171 172 172 pte_t *pte = page_mapping_find(AS, virt, false); 173 173 if ((!PTE_VALID(pte)) || (!PTE_PRESENT(pte))) { 174 mutex_unlock(&AS->lock);174 page_table_unlock(AS, true); 175 175 return ENOENT; 176 176 } … … 179 179 (virt - ALIGN_DOWN(virt, PAGE_SIZE)); 180 180 181 mutex_unlock(&AS->lock);181 page_table_unlock(AS, true); 182 182 183 183 return EOK; -
kernel/generic/src/printf/printf_core.c
r2cc7f16 rc6588ce 284 284 /* Print leading spaces. */ 285 285 size_t strw = str_length(str); 286 if ( precision == 0)286 if ((precision == 0) || (precision > strw)) 287 287 precision = strw; 288 288 … … 332 332 /* Print leading spaces. */ 333 333 size_t strw = wstr_length(str); 334 if ( precision == 0)334 if ((precision == 0) || (precision > strw)) 335 335 precision = strw; 336 336 -
kernel/generic/src/syscall/syscall.c
r2cc7f16 rc6588ce 184 184 185 185 /* Sysinfo syscalls. */ 186 (syshandler_t) sys_sysinfo_get_keys_size, 187 (syshandler_t) sys_sysinfo_get_keys, 186 188 (syshandler_t) sys_sysinfo_get_val_type, 187 189 (syshandler_t) sys_sysinfo_get_value, -
kernel/generic/src/sysinfo/stats.c
r2cc7f16 rc6588ce 83 83 * 84 84 * @param item Sysinfo item (unused). 85 * @param data Unused. 85 86 * 86 87 * @return System uptime (in secords). 87 88 * 88 89 */ 89 static sysarg_t get_stats_uptime(struct sysinfo_item *item )90 static sysarg_t get_stats_uptime(struct sysinfo_item *item, void *data) 90 91 { 91 92 /* This doesn't have to be very accurate */ … … 98 99 * @param size Size of the returned data. 99 100 * @param dry_run Do not get the data, just calculate the size. 101 * @param data Unused. 100 102 * 101 103 * @return Data containing several stats_cpu_t structures. … … 104 106 */ 105 107 static void *get_stats_cpus(struct sysinfo_item *item, size_t *size, 106 bool dry_run )108 bool dry_run, void *data) 107 109 { 108 110 *size = sizeof(stats_cpu_t) * config.cpu_count; … … 249 251 ASSERT(interrupts_disabled()); 250 252 ASSERT(irq_spinlock_locked(&task->lock)); 251 253 252 254 stats_task->task_id = task->taskid; 253 255 str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name); … … 293 295 * @param size Size of the returned data. 294 296 * @param dry_run Do not get the data, just calculate the size. 297 * @param data Unused. 295 298 * 296 299 * @return Data containing several stats_task_t structures. … … 299 302 */ 300 303 static void *get_stats_tasks(struct sysinfo_item *item, size_t *size, 301 bool dry_run )304 bool dry_run, void *data) 302 305 { 303 306 /* Messing with task structures, avoid deadlock */ … … 350 353 ASSERT(interrupts_disabled()); 351 354 ASSERT(irq_spinlock_locked(&thread->lock)); 352 355 353 356 stats_thread->thread_id = thread->tid; 354 357 stats_thread->task_id = thread->task->taskid; … … 398 401 * @param size Size of the returned data. 399 402 * @param dry_run Do not get the data, just calculate the size. 403 * @param data Unused. 400 404 * 401 405 * @return Data containing several stats_task_t structures. … … 404 408 */ 405 409 static void *get_stats_threads(struct sysinfo_item *item, size_t *size, 406 bool dry_run )410 bool dry_run, void *data) 407 411 { 408 412 /* Messing with threads structures, avoid deadlock */ … … 451 455 * @param name Task ID (string-encoded number). 452 456 * @param dry_run Do not get the data, just calculate the size. 457 * @param data Unused. 453 458 * 454 459 * @return Sysinfo return holder. The type of the returned … … 460 465 * 461 466 */ 462 static sysinfo_return_t get_stats_task(const char *name, bool dry_run) 467 static sysinfo_return_t get_stats_task(const char *name, bool dry_run, 468 void *data) 463 469 { 464 470 /* Initially no return value */ … … 468 474 /* Parse the task ID */ 469 475 task_id_t task_id; 470 if (str_uint64 (name, NULL, 0, true, &task_id) != EOK)476 if (str_uint64_t(name, NULL, 0, true, &task_id) != EOK) 471 477 return ret; 472 478 … … 520 526 * @param name Thread ID (string-encoded number). 521 527 * @param dry_run Do not get the data, just calculate the size. 528 * @param data Unused. 522 529 * 523 530 * @return Sysinfo return holder. The type of the returned … … 529 536 * 530 537 */ 531 static sysinfo_return_t get_stats_thread(const char *name, bool dry_run) 538 static sysinfo_return_t get_stats_thread(const char *name, bool dry_run, 539 void *data) 532 540 { 533 541 /* Initially no return value */ … … 537 545 /* Parse the thread ID */ 538 546 thread_id_t thread_id; 539 if (str_uint64 (name, NULL, 0, true, &thread_id) != EOK)547 if (str_uint64_t(name, NULL, 0, true, &thread_id) != EOK) 540 548 return ret; 541 549 … … 586 594 * @param size Size of the returned data. 587 595 * @param dry_run Do not get the data, just calculate the size. 596 * @param data Unused. 588 597 * 589 598 * @return Data containing several stats_exc_t structures. … … 592 601 */ 593 602 static void *get_stats_exceptions(struct sysinfo_item *item, size_t *size, 594 bool dry_run )603 bool dry_run, void *data) 595 604 { 596 605 *size = sizeof(stats_exc_t) * IVT_ITEMS; … … 634 643 * @param name Exception number (string-encoded number). 635 644 * @param dry_run Do not get the data, just calculate the size. 645 * @param data Unused. 636 646 * 637 647 * @return Sysinfo return holder. The type of the returned … … 643 653 * 644 654 */ 645 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run) 655 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run, 656 void *data) 646 657 { 647 658 /* Initially no return value */ … … 651 662 /* Parse the exception number */ 652 663 uint64_t excn; 653 if (str_uint64 (name, NULL, 0, true, &excn) != EOK)664 if (str_uint64_t(name, NULL, 0, true, &excn) != EOK) 654 665 return ret; 655 666 … … 705 716 * @param size Size of the returned data. 706 717 * @param dry_run Do not get the data, just calculate the size. 718 * @param data Unused. 707 719 * 708 720 * @return Data containing stats_physmem_t. … … 711 723 */ 712 724 static void *get_stats_physmem(struct sysinfo_item *item, size_t *size, 713 bool dry_run )725 bool dry_run, void *data) 714 726 { 715 727 *size = sizeof(stats_physmem_t); … … 735 747 * @param size Size of the returned data. 736 748 * @param dry_run Do not get the data, just calculate the size. 749 * @param data Unused. 737 750 * 738 751 * @return Data several load_t values. … … 741 754 */ 742 755 static void *get_stats_load(struct sysinfo_item *item, size_t *size, 743 bool dry_run )756 bool dry_run, void *data) 744 757 { 745 758 *size = sizeof(load_t) * LOAD_STEPS; … … 810 823 mutex_initialize(&load_lock, MUTEX_PASSIVE); 811 824 812 sysinfo_set_item_ fn_val("system.uptime", NULL, get_stats_uptime);813 sysinfo_set_item_ fn_data("system.cpus", NULL, get_stats_cpus);814 sysinfo_set_item_ fn_data("system.physmem", NULL, get_stats_physmem);815 sysinfo_set_item_ fn_data("system.load", NULL, get_stats_load);816 sysinfo_set_item_ fn_data("system.tasks", NULL, get_stats_tasks);817 sysinfo_set_item_ fn_data("system.threads", NULL, get_stats_threads);818 sysinfo_set_item_ fn_data("system.exceptions", NULL, get_stats_exceptions);819 sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task );820 sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread );821 sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception );825 sysinfo_set_item_gen_val("system.uptime", NULL, get_stats_uptime, NULL); 826 sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL); 827 sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL); 828 sysinfo_set_item_gen_data("system.load", NULL, get_stats_load, NULL); 829 sysinfo_set_item_gen_data("system.tasks", NULL, get_stats_tasks, NULL); 830 sysinfo_set_item_gen_data("system.threads", NULL, get_stats_threads, NULL); 831 sysinfo_set_item_gen_data("system.exceptions", NULL, get_stats_exceptions, NULL); 832 sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task, NULL); 833 sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread, NULL); 834 sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception, NULL); 822 835 } 823 836 -
kernel/generic/src/sysinfo/sysinfo.c
r2cc7f16 rc6588ce 1 1 /* 2 2 * Copyright (c) 2006 Jakub Vana 3 * Copyright (c) 2012 Martin Decky 3 4 * All rights reserved. 4 5 * … … 99 100 sizeof(sysinfo_item_t), 0, sysinfo_item_constructor, 100 101 sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED); 101 102 102 103 mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE); 103 104 } … … 110 111 * @param subtree Current sysinfo (sub)tree root item. 111 112 * @param ret If the return value is NULL, this argument 112 * can be either also NULL (i.e. no item was113 * can be set either to NULL (i.e. no item was 113 114 * found and no data was generated) or the 114 115 * original pointer is used to store the value … … 125 126 { 126 127 ASSERT(subtree != NULL); 127 ASSERT(ret != NULL);128 128 129 129 sysinfo_item_t *cur = subtree; … … 151 151 case SYSINFO_SUBTREE_FUNCTION: 152 152 /* Get generated data */ 153 **ret = cur->subtree.get_data(name + i + 1, dry_run); 153 if (ret != NULL) 154 **ret = cur->subtree.generator.fn(name + i + 1, 155 dry_run, cur->subtree.generator.data); 156 154 157 return NULL; 155 158 default: 156 159 /* Not found, no data generated */ 157 *ret = NULL; 160 if (ret != NULL) 161 *ret = NULL; 162 158 163 return NULL; 159 164 } … … 164 169 165 170 /* Not found, no data generated */ 166 *ret = NULL; 171 if (ret != NULL) 172 *ret = NULL; 173 167 174 return NULL; 168 175 } … … 352 359 * a new root item (NULL for global sysinfo root). 353 360 * @param fn Numeric value generator function. 354 * 355 */ 356 void sysinfo_set_item_fn_val(const char *name, sysinfo_item_t **root, 357 sysinfo_fn_val_t fn) 361 * @param data Private data. 362 * 363 */ 364 void sysinfo_set_item_gen_val(const char *name, sysinfo_item_t **root, 365 sysinfo_fn_val_t fn, void *data) 358 366 { 359 367 /* Protect sysinfo tree consistency */ … … 366 374 if (item != NULL) { 367 375 item->val_type = SYSINFO_VAL_FUNCTION_VAL; 368 item->val.fn_val = fn; 376 item->val.gen_val.fn = fn; 377 item->val.gen_val.data = data; 369 378 } 370 379 … … 383 392 * a new root item (NULL for global sysinfo root). 384 393 * @param fn Binary data generator function. 385 * 386 */ 387 void sysinfo_set_item_fn_data(const char *name, sysinfo_item_t **root, 388 sysinfo_fn_data_t fn) 394 * @param data Private data. 395 * 396 */ 397 void sysinfo_set_item_gen_data(const char *name, sysinfo_item_t **root, 398 sysinfo_fn_data_t fn, void *data) 389 399 { 390 400 /* Protect sysinfo tree consistency */ … … 397 407 if (item != NULL) { 398 408 item->val_type = SYSINFO_VAL_FUNCTION_DATA; 399 item->val.fn_data = fn; 409 item->val.gen_data.fn = fn; 410 item->val.gen_data.data = data; 400 411 } 401 412 … … 431 442 * a new root item (NULL for global sysinfo root). 432 443 * @param fn Subtree generator function. 444 * @param data Private data to be passed to the generator. 433 445 * 434 446 */ 435 447 void sysinfo_set_subtree_fn(const char *name, sysinfo_item_t **root, 436 sysinfo_fn_subtree_t fn )448 sysinfo_fn_subtree_t fn, void *data) 437 449 { 438 450 /* Protect sysinfo tree consistency */ … … 448 460 if ((item != NULL) && (item->subtree_type != SYSINFO_SUBTREE_TABLE)) { 449 461 item->subtree_type = SYSINFO_SUBTREE_FUNCTION; 450 item->subtree.get_data = fn; 462 item->subtree.generator.fn = fn; 463 item->subtree.generator.data = data; 451 464 } 452 465 … … 456 469 /** Sysinfo dump indentation helper routine 457 470 * 458 * @param depth Number of indentation characters to print. 459 * 460 */ 461 NO_TRACE static void sysinfo_indent(unsigned int depth) 462 { 463 unsigned int i; 464 for (i = 0; i < depth; i++) 465 printf(" "); 471 * @param depth Number of spaces to print. 472 * 473 */ 474 NO_TRACE static void sysinfo_indent(size_t spaces) 475 { 476 for (size_t i = 0; i < spaces; i++) 477 printf(" "); 466 478 } 467 479 … … 470 482 * Should be called with sysinfo_lock held. 471 483 * 472 * @param root Root item of the current (sub)tree. 473 * @param depth Current depth in the sysinfo tree. 474 * 475 */ 476 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth) 477 { 478 sysinfo_item_t *cur = root; 479 484 * @param root Root item of the current (sub)tree. 485 * @param spaces Current indentation level. 486 * 487 */ 488 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, size_t spaces) 489 { 480 490 /* Walk all siblings */ 481 while (cur != NULL) { 482 sysinfo_indent(depth); 491 for (sysinfo_item_t *cur = root; cur; cur = cur->next) { 492 size_t length; 493 494 if (spaces == 0) { 495 printf("%s", cur->name); 496 length = str_length(cur->name); 497 } else { 498 sysinfo_indent(spaces); 499 printf(".%s", cur->name); 500 length = str_length(cur->name) + 1; 501 } 483 502 484 503 sysarg_t val; … … 488 507 switch (cur->val_type) { 489 508 case SYSINFO_VAL_UNDEFINED: 490 printf(" + %s\n", cur->name);509 printf(" [undefined]\n"); 491 510 break; 492 511 case SYSINFO_VAL_VAL: 493 printf(" + %s -> %" PRIun" (%#" PRIxn ")\n", cur->name,494 cur->val.val , cur->val.val);512 printf(" -> %" PRIun" (%#" PRIxn ")\n", cur->val.val, 513 cur->val.val); 495 514 break; 496 515 case SYSINFO_VAL_DATA: 497 printf("+ %s (%zu bytes)\n", cur->name, 498 cur->val.data.size); 516 printf(" (%zu bytes)\n", cur->val.data.size); 499 517 break; 500 518 case SYSINFO_VAL_FUNCTION_VAL: 501 val = cur->val. fn_val(cur);502 printf(" + %s -> %" PRIun" (%#" PRIxn ") [generated]\n",503 cur->name, val,val);519 val = cur->val.gen_val.fn(cur, cur->val.gen_val.data); 520 printf(" -> %" PRIun" (%#" PRIxn ") [generated]\n", val, 521 val); 504 522 break; 505 523 case SYSINFO_VAL_FUNCTION_DATA: 506 524 /* N.B.: No data was actually returned (only a dry run) */ 507 (void) cur->val. fn_data(cur, &size, true);508 printf("+ %s (%zu bytes) [generated]\n", cur->name,509 size);525 (void) cur->val.gen_data.fn(cur, &size, true, 526 cur->val.gen_data.data); 527 printf(" (%zu bytes) [generated]\n", size); 510 528 break; 511 529 default: … … 518 536 break; 519 537 case SYSINFO_SUBTREE_TABLE: 520 sysinfo_dump_internal(cur->subtree.table, depth + 1);538 sysinfo_dump_internal(cur->subtree.table, spaces + length); 521 539 break; 522 540 case SYSINFO_SUBTREE_FUNCTION: 523 sysinfo_indent( depth + 1);524 printf(" + [generated subtree]\n");541 sysinfo_indent(spaces + length); 542 printf("<generated subtree>\n"); 525 543 break; 526 544 default: 527 sysinfo_indent( depth + 1);528 printf(" + [unknown subtree]\n");545 sysinfo_indent(spaces + length); 546 printf("<unknown subtree>\n"); 529 547 } 530 531 cur = cur->next;532 548 } 533 549 } … … 594 610 break; 595 611 case SYSINFO_VAL_FUNCTION_VAL: 596 ret.val = item->val. fn_val(item);612 ret.val = item->val.gen_val.fn(item, item->val.gen_val.data); 597 613 break; 598 614 case SYSINFO_VAL_FUNCTION_DATA: 599 ret.data.data = item->val. fn_data(item, &ret.data.size,600 dry_run );615 ret.data.data = item->val.gen_data.fn(item, &ret.data.size, 616 dry_run, item->val.gen_data.data); 601 617 break; 602 618 } … … 635 651 ASSERT(path); 636 652 637 if ((copy_from_uspace(path, ptr, size + 1) == 0) 638 &&(path[size] == 0)) {653 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 654 (path[size] == 0)) { 639 655 /* 640 656 * Prevent other functions from messing with sysinfo while we … … 645 661 mutex_unlock(&sysinfo_lock); 646 662 } 663 647 664 free(path); 648 665 return ret; 666 } 667 668 /** Return sysinfo keys determined by name 669 * 670 * Should be called with sysinfo_lock held. 671 * 672 * @param name Sysinfo path. 673 * @param root Root item of the sysinfo (sub)tree. 674 * If it is NULL then consider the global 675 * sysinfo tree. 676 * @param dry_run Do not actually get any generated 677 * binary data, just calculate the size. 678 * 679 * @return Item value (constant or generated). 680 * 681 */ 682 NO_TRACE static sysinfo_return_t sysinfo_get_keys(const char *name, 683 sysinfo_item_t **root, bool dry_run) 684 { 685 if (root == NULL) 686 root = &global_root; 687 688 sysinfo_item_t *subtree = NULL; 689 690 if (name[0] != 0) { 691 /* Try to find the item */ 692 sysinfo_item_t *item = 693 sysinfo_find_item(name, *root, NULL, dry_run); 694 if ((item != NULL) && 695 (item->subtree_type == SYSINFO_SUBTREE_TABLE)) 696 subtree = item->subtree.table; 697 } else 698 subtree = *root; 699 700 sysinfo_return_t ret; 701 702 if (subtree != NULL) { 703 /* 704 * Calculate the size of subkeys. 705 */ 706 size_t size = 0; 707 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) 708 size += str_size(cur->name) + 1; 709 710 if (dry_run) { 711 ret.tag = SYSINFO_VAL_DATA; 712 ret.data.data = NULL; 713 ret.data.size = size; 714 } else { 715 /* Allocate buffer for subkeys */ 716 char *names = (char *) malloc(size, FRAME_ATOMIC); 717 if (names == NULL) 718 return ret; 719 720 size_t pos = 0; 721 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) { 722 str_cpy(names + pos, size - pos, cur->name); 723 pos += str_size(cur->name) + 1; 724 } 725 726 /* Correct return value */ 727 ret.tag = SYSINFO_VAL_DATA; 728 ret.data.data = (void *) names; 729 ret.data.size = size; 730 } 731 } else { 732 /* No item in the fixed sysinfo tree */ 733 ret.tag = SYSINFO_VAL_UNDEFINED; 734 } 735 736 return ret; 737 } 738 739 /** Return sysinfo keys determined by name from user space 740 * 741 * The path string passed from the user space has to be properly 742 * null-terminated (the last passed character must be null). 743 * 744 * @param ptr Sysinfo path in the user address space. 745 * @param size Size of the path string. 746 * @param dry_run Do not actually get any generated 747 * binary data, just calculate the size. 748 * 749 */ 750 NO_TRACE static sysinfo_return_t sysinfo_get_keys_uspace(void *ptr, size_t size, 751 bool dry_run) 752 { 753 sysinfo_return_t ret; 754 ret.tag = SYSINFO_VAL_UNDEFINED; 755 756 if (size > SYSINFO_MAX_PATH) 757 return ret; 758 759 char *path = (char *) malloc(size + 1, 0); 760 ASSERT(path); 761 762 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 763 (path[size] == 0)) { 764 /* 765 * Prevent other functions from messing with sysinfo while we 766 * are reading it. 767 */ 768 mutex_lock(&sysinfo_lock); 769 ret = sysinfo_get_keys(path, NULL, dry_run); 770 mutex_unlock(&sysinfo_lock); 771 } 772 773 free(path); 774 return ret; 775 } 776 777 /** Get the sysinfo keys size (syscall) 778 * 779 * The path string passed from the user space has 780 * to be properly null-terminated (the last passed 781 * character must be null). 782 * 783 * @param path_ptr Sysinfo path in the user address space. 784 * @param path_size Size of the path string. 785 * @param size_ptr User space pointer where to store the 786 * keys size. 787 * 788 * @return Error code (EOK in case of no error). 789 * 790 */ 791 sysarg_t sys_sysinfo_get_keys_size(void *path_ptr, size_t path_size, 792 void *size_ptr) 793 { 794 int rc; 795 796 /* 797 * Get the keys. 798 * 799 * N.B.: There is no need to free any potential keys 800 * since we request a dry run. 801 */ 802 sysinfo_return_t ret = 803 sysinfo_get_keys_uspace(path_ptr, path_size, true); 804 805 /* Check return data tag */ 806 if (ret.tag == SYSINFO_VAL_DATA) 807 rc = copy_to_uspace(size_ptr, &ret.data.size, 808 sizeof(ret.data.size)); 809 else 810 rc = EINVAL; 811 812 return (sysarg_t) rc; 813 } 814 815 /** Get the sysinfo keys (syscall) 816 * 817 * The path string passed from the user space has 818 * to be properly null-terminated (the last passed 819 * character must be null). 820 * 821 * If the user space buffer size does not equal 822 * the actual size of the returned data, the data 823 * is truncated. 824 * 825 * The actual size of data returned is stored to 826 * size_ptr. 827 * 828 * @param path_ptr Sysinfo path in the user address space. 829 * @param path_size Size of the path string. 830 * @param buffer_ptr User space pointer to the buffer where 831 * to store the binary data. 832 * @param buffer_size User space buffer size. 833 * @param size_ptr User space pointer where to store the 834 * binary data size. 835 * 836 * @return Error code (EOK in case of no error). 837 * 838 */ 839 sysarg_t sys_sysinfo_get_keys(void *path_ptr, size_t path_size, 840 void *buffer_ptr, size_t buffer_size, size_t *size_ptr) 841 { 842 int rc; 843 844 /* Get the keys */ 845 sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size, 846 false); 847 848 /* Check return data tag */ 849 if (ret.tag == SYSINFO_VAL_DATA) { 850 size_t size = min(ret.data.size, buffer_size); 851 rc = copy_to_uspace(buffer_ptr, ret.data.data, size); 852 if (rc == EOK) 853 rc = copy_to_uspace(size_ptr, &size, sizeof(size)); 854 855 free(ret.data.data); 856 } else 857 rc = EINVAL; 858 859 return (sysarg_t) rc; 649 860 } 650 861 … … 672 883 673 884 /* 674 * Map generated value types to constant types (user space does not care675 * whether the value is constant or generated).885 * Map generated value types to constant types (user space does 886 * not care whether the value is constant or generated). 676 887 */ 677 888 if (ret.tag == SYSINFO_VAL_FUNCTION_VAL) … … 701 912 { 702 913 int rc; 703 914 704 915 /* 705 916 * Get the item. 706 917 * 707 * N.B.: There is no need to free any potential generated binary data708 * since we request a dry run.918 * N.B.: There is no need to free any potential generated binary 919 * data since we request a dry run. 709 920 */ 710 921 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); … … 741 952 * Get the item. 742 953 * 743 * N.B.: There is no need to free any potential generated binary data744 * since we request a dry run.954 * N.B.: There is no need to free any potential generated binary 955 * data since we request a dry run. 745 956 */ 746 957 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); -
kernel/test/print/print1.c
r2cc7f16 rc6588ce 41 41 42 42 TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); 43 TPRINTF("Expected output: \" text\"\n");43 TPRINTF("Expected output: \" text\"\n"); 44 44 TPRINTF("Real output: \"%8.10s\"\n\n", "text"); 45 45 … … 48 48 TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); 49 49 50 TPRINTF("Testing printf(\"%%-*.*s\", 7, 7, \"text\"):\n"); 51 TPRINTF("Expected output: \"text \"\n"); 52 TPRINTF("Real output: \"%-*.*s\"\n\n", 7, 7, "text"); 53 50 54 return NULL; 51 55 }
Note:
See TracChangeset
for help on using the changeset viewer.
