- Timestamp:
- 2012-11-25T21:34:07Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e1a27be
- Parents:
- 150a2718 (diff), 7462674 (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:
- uspace
- Files:
-
- 13 added
- 16 deleted
- 46 edited
- 4 moved
-
Makefile (modified) (3 diffs)
-
Makefile.common (modified) (1 diff)
-
app/bdsh/config.h (modified) (1 diff)
-
app/ext2info/Makefile (deleted)
-
app/ext2info/ext2info.c (deleted)
-
app/tester/Makefile (modified) (3 diffs)
-
app/tester/ext2/ext2_1.c (deleted)
-
app/tester/ext2/ext2_1.def (deleted)
-
app/tester/float/softfloat1.c (modified) (9 diffs)
-
app/tester/print/print5.def (modified) (1 diff)
-
app/tester/print/print6.c (added)
-
app/tester/print/print6.def (added)
-
app/tester/tester.c (modified) (2 diffs)
-
app/tester/tester.h (modified) (2 diffs)
-
drv/infrastructure/rootamdm37x/Makefile (modified) (1 diff)
-
drv/infrastructure/rootamdm37x/amdm37x.c (added)
-
drv/infrastructure/rootamdm37x/amdm37x.h (moved) (moved from uspace/lib/ext2/libext2_block_group.h ) (2 diffs)
-
drv/infrastructure/rootamdm37x/cm/clock_control.h (modified) (3 diffs)
-
drv/infrastructure/rootamdm37x/cm/iva2.h (added)
-
drv/infrastructure/rootamdm37x/cm/mpu.h (added)
-
drv/infrastructure/rootamdm37x/prm/clock_control.h (added)
-
drv/infrastructure/rootamdm37x/prm/global_reg.h (added)
-
drv/infrastructure/rootamdm37x/prm/usbhost.h (added)
-
drv/infrastructure/rootamdm37x/rootamdm37x.c (modified) (11 diffs)
-
drv/infrastructure/rootamdm37x/usbtll.h (modified) (1 diff)
-
drv/time/cmos-rtc/cmos-rtc.c (modified) (5 diffs)
-
lib/c/Makefile (modified) (4 diffs)
-
lib/c/arch/abs32le/include/ddi.h (modified) (1 diff)
-
lib/c/arch/arm32/include/ddi.h (modified) (1 diff)
-
lib/c/arch/ia32/include/ddi.h (modified) (3 diffs)
-
lib/c/arch/ia64/include/ddi.h (modified) (3 diffs)
-
lib/c/arch/mips32/include/ddi.h (modified) (1 diff)
-
lib/c/arch/mips64/include/ddi.h (modified) (1 diff)
-
lib/c/arch/ppc32/include/ddi.h (modified) (1 diff)
-
lib/c/arch/sparc64/include/ddi.h (modified) (3 diffs)
-
lib/c/generic/ddi.c (modified) (3 diffs)
-
lib/c/generic/dlfcn.c (modified) (2 diffs)
-
lib/c/generic/double_to_str.c (added)
-
lib/c/generic/fibril.c (modified) (6 diffs)
-
lib/c/generic/ieee_double.c (added)
-
lib/c/generic/io/log.c (modified) (1 diff)
-
lib/c/generic/io/printf_core.c (modified) (12 diffs)
-
lib/c/generic/pio_trace.c (modified) (1 diff)
-
lib/c/generic/power_of_ten.c (added)
-
lib/c/generic/private/power_of_ten.h (added)
-
lib/c/generic/stack.c (moved) (moved from uspace/srv/fs/ext2fs/ext2fs.h ) (2 diffs)
-
lib/c/generic/thread.c (modified) (3 diffs)
-
lib/c/include/ddi.h (modified) (2 diffs)
-
lib/c/include/double_to_str.h (moved) (moved from uspace/srv/fs/ext2fs/ext2fs.c ) (2 diffs)
-
lib/c/include/ieee_double.h (added)
-
lib/c/include/macros.h (modified) (1 diff)
-
lib/c/include/stack.h (moved) (moved from uspace/lib/ext2/libext2.h ) (2 diffs)
-
lib/clui/tinput.c (modified) (2 diffs)
-
lib/ext2/Makefile (deleted)
-
lib/ext2/libext2_block_group.c (deleted)
-
lib/ext2/libext2_directory.c (deleted)
-
lib/ext2/libext2_directory.h (deleted)
-
lib/ext2/libext2_filesystem.c (deleted)
-
lib/ext2/libext2_filesystem.h (deleted)
-
lib/ext2/libext2_inode.c (deleted)
-
lib/ext2/libext2_inode.h (deleted)
-
lib/ext2/libext2_superblock.c (deleted)
-
lib/ext2/libext2_superblock.h (deleted)
-
lib/ext4/libext4_block_group.c (modified) (1 diff)
-
lib/ext4/libext4_block_group.h (modified) (1 diff)
-
lib/ext4/libext4_directory.c (modified) (1 diff)
-
lib/ext4/libext4_directory.h (modified) (1 diff)
-
lib/ext4/libext4_filesystem.c (modified) (1 diff)
-
lib/ext4/libext4_filesystem.h (modified) (1 diff)
-
lib/ext4/libext4_inode.c (modified) (1 diff)
-
lib/ext4/libext4_inode.h (modified) (1 diff)
-
lib/ext4/libext4_superblock.c (modified) (1 diff)
-
lib/ext4/libext4_superblock.h (modified) (1 diff)
-
lib/ext4/libext4_types.h (modified) (1 diff)
-
lib/softfloat/common.c (modified) (2 diffs)
-
srv/fs/ext2fs/Makefile (deleted)
-
srv/fs/ext2fs/ext2fs_ops.c (deleted)
-
srv/fs/ext4fs/ext4fs_ops.c (modified) (1 diff)
-
srv/logger/initlvl.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r150a2718 r8f88beb7 40 40 app/devctl \ 41 41 app/edit \ 42 app/ext2info \43 42 app/getterm \ 44 43 app/init \ … … 105 104 srv/fs/mfs \ 106 105 srv/fs/locfs \ 107 srv/fs/ext2fs \108 106 srv/fs/ext4fs \ 109 107 srv/hid/compositor \ … … 218 216 lib/net \ 219 217 lib/nic \ 220 lib/ext2 \221 218 lib/ext4 \ 222 219 lib/usb \ -
uspace/Makefile.common
r150a2718 r8f88beb7 118 118 LIBGUI_PREFIX = $(LIB_PREFIX)/gui 119 119 120 LIBEXT2_PREFIX = $(LIB_PREFIX)/ext2121 120 LIBEXT4_PREFIX = $(LIB_PREFIX)/ext4 122 121 -
uspace/app/bdsh/config.h
r150a2718 r8f88beb7 55 55 #define PACKAGE_STRING "The brain dead shell" 56 56 #define PACKAGE_TARNAME "bdsh" 57 #define PACKAGE_VERSION "0.0.1" 58 59 60 57 #define PACKAGE_VERSION "0.1.0" -
uspace/app/tester/Makefile
r150a2718 r8f88beb7 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIB EXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIB EXT2_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBSOFTFLOAT_PREFIX) 33 33 BINARY = tester 34 34 … … 42 42 print/print4.c \ 43 43 print/print5.c \ 44 print/print6.c \ 44 45 console/console1.c \ 45 46 stdio/stdio1.c \ … … 62 63 mm/mapping1.c \ 63 64 hw/misc/virtchar1.c \ 64 hw/serial/serial1.c \ 65 ext2/ext2_1.c 65 hw/serial/serial1.c 66 66 67 67 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tester/float/softfloat1.c
r150a2718 r8f88beb7 34 34 #include <mul.h> 35 35 #include <div.h> 36 #include <comparison.h> 37 #include <conversion.h> 36 38 #include <bool.h> 37 39 #include "../tester.h" 38 40 39 #define OPERANDS 641 #define OPERANDS 10 40 42 #define PRECISION 10000 41 43 … … 43 45 44 46 typedef int32_t cmptype_t; 45 typedef void (* float_op_t)(float, float, float *, float_t *); 46 typedef void (* double_op_t)(double, double, double *, double_t *); 47 typedef void (* template_t)(void *, unsigned, unsigned, cmptype_t *, 47 48 typedef void (* uint_to_double_op_t)(unsigned int, double *, double_t *); 49 typedef void (* double_to_uint_op_t)(double, unsigned int *, unsigned int *); 50 typedef void (* float_binary_op_t)(float, float, float *, float_t *); 51 typedef void (* double_binary_op_t)(double, double, double *, double_t *); 52 typedef void (* double_cmp_op_t)(double, double, cmptype_t *, cmptype_t *); 53 54 typedef void (* template_unary_t)(void *, unsigned, cmptype_t *, cmptype_t *); 55 typedef void (* template_binary_t)(void *, unsigned, unsigned, cmptype_t *, 48 56 cmptype_t *); 49 57 50 static float fop_a[OPERANDS] = 51 {3.5, -2.1, 100.0, 50.0, -1024.0, 0.0}; 52 53 static float fop_b[OPERANDS] = 54 {-2.1, 100.0, 50.0, -1024.0, 3.5, 0.0}; 55 56 static double dop_a[OPERANDS] = 57 {3.5, -2.1, 100.0, 50.0, -1024.0, 0.0}; 58 59 static double dop_b[OPERANDS] = 60 {-2.1, 100.0, 50.0, -1024.0, 3.5, 0.0}; 58 #define NUMBERS \ 59 3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0 60 61 static float fop_a[OPERANDS] = { 62 NUMBERS 63 }; 64 65 static double dop_a[OPERANDS] = { 66 NUMBERS 67 }; 68 69 static unsigned int uop_a[OPERANDS] = { 70 4, -100, 100, 50, 1024, 0, 1000000, -1U, 0x80000000U, 500 71 }; 61 72 62 73 static cmptype_t cmpabs(cmptype_t a) … … 68 79 } 69 80 70 static void 71 float_template(void *f, unsigned i, unsigned j, cmptype_t *pic, 81 static int dcmp(double a, double b) 82 { 83 if (a < b) 84 return -1; 85 else if (a > b) 86 return 1; 87 88 return 0; 89 } 90 91 static void 92 uint_to_double_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 93 { 94 double c; 95 double_t sc; 96 97 uint_to_double_op_t op = (uint_to_double_op_t) f; 98 99 op(uop_a[i], &c, &sc); 100 101 *pic = (cmptype_t) (c * PRECISION); 102 *pisc = (cmptype_t) (sc.val * PRECISION); 103 } 104 105 static void 106 double_to_uint_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc) 107 { 108 unsigned int c; 109 unsigned int sc; 110 111 double_to_uint_op_t op = (double_to_uint_op_t) f; 112 113 op(dop_a[i], &c, &sc); 114 115 *pic = (cmptype_t) c; 116 *pisc = (cmptype_t) sc; 117 } 118 119 120 static void 121 float_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic, 72 122 cmptype_t *pisc) 73 123 { … … 75 125 float_t sc; 76 126 77 float_ op_t op = (float_op_t) f;78 79 op(fop_a[i], fop_ b[j], &c, &sc);127 float_binary_op_t op = (float_binary_op_t) f; 128 129 op(fop_a[i], fop_a[j], &c, &sc); 80 130 81 131 *pic = (cmptype_t) (c * PRECISION); … … 84 134 85 135 static void 86 double_template (void *f, unsigned i, unsigned j, cmptype_t *pic,136 double_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic, 87 137 cmptype_t *pisc) 88 138 { … … 90 140 double_t sc; 91 141 92 double_ op_t op = (double_op_t) f;93 94 op(dop_a[i], dop_ b[j], &c, &sc);142 double_binary_op_t op = (double_binary_op_t) f; 143 144 op(dop_a[i], dop_a[j], &c, &sc); 95 145 96 146 *pic = (cmptype_t) (c * PRECISION); … … 98 148 } 99 149 100 static bool test_template(template_t template, void *f) 150 static void 151 double_compare_template(void *f, unsigned i, unsigned j, cmptype_t *pis, 152 cmptype_t *piss) 153 { 154 double_cmp_op_t op = (double_cmp_op_t) f; 155 156 op(dop_a[i], dop_a[j], pis, piss); 157 } 158 159 static bool test_template_unary(template_unary_t template, void *f) 160 { 161 bool correct = true; 162 163 for (unsigned int i = 0; i < OPERANDS; i++) { 164 cmptype_t ic; 165 cmptype_t isc; 166 167 template(f, i, &ic, &isc); 168 cmptype_t diff = cmpabs(ic - isc); 169 170 if (diff != 0) { 171 TPRINTF("i=%u diff=%" PRIdCMPTYPE "\n", i, diff); 172 correct = false; 173 } 174 } 175 176 return correct; 177 } 178 179 static bool test_template_binary(template_binary_t template, void *f) 101 180 { 102 181 bool correct = true; … … 121 200 } 122 201 202 static void uint_to_double_operator(unsigned int a, double *pc, double_t *psc) 203 { 204 *pc = (double) a; 205 psc->data = uint_to_double(a); 206 } 207 208 static void 209 double_to_uint_operator(double a, unsigned int *pc, unsigned int *psc) 210 { 211 double_t sa; 212 213 sa.val = a; 214 215 *pc = (unsigned int) a; 216 *psc = double_to_uint(sa.data); 217 } 218 219 static void 220 double_to_int_operator(double a, unsigned int *pc, unsigned int *psc) 221 { 222 double_t sa; 223 224 sa.val = a; 225 226 *pc = (int) a; 227 *psc = double_to_int(sa.data); 228 } 229 123 230 static void float_add_operator(float a, float b, float *pc, float_t *psc) 124 231 { … … 221 328 } 222 329 330 static void 331 double_cmp_operator(double a, double b, cmptype_t *pis, cmptype_t *piss) 332 { 333 *pis = dcmp(a, b); 334 335 double_t sa; 336 double_t sb; 337 338 sa.val = a; 339 sb.val = b; 340 341 if (is_double_lt(sa.data, sb.data)) 342 *piss = -1; 343 else if (is_double_gt(sa.data, sb.data)) 344 *piss = 1; 345 else if (is_double_eq(sa.data, sb.data)) 346 *piss = 0; 347 else 348 *piss = 42; 349 } 350 223 351 const char *test_softfloat1(void) 224 352 { 225 353 const char *err = NULL; 226 354 227 if (!test_template (float_template, float_add_operator)) {355 if (!test_template_binary(float_template_binary, float_add_operator)) { 228 356 err = "Float addition failed"; 229 357 TPRINTF("%s\n", err); 230 358 } 231 if (!test_template (float_template, float_mul_operator)) {359 if (!test_template_binary(float_template_binary, float_mul_operator)) { 232 360 err = "Float multiplication failed"; 233 361 TPRINTF("%s\n", err); 234 362 } 235 if (!test_template (float_template, float_div_operator)) {363 if (!test_template_binary(float_template_binary, float_div_operator)) { 236 364 err = "Float division failed"; 237 365 TPRINTF("%s\n", err); 238 366 } 239 if (!test_template (double_template, double_add_operator)) {367 if (!test_template_binary(double_template_binary, double_add_operator)) { 240 368 err = "Double addition failed"; 241 369 TPRINTF("%s\n", err); 242 370 } 243 if (!test_template (double_template, double_mul_operator)) {371 if (!test_template_binary(double_template_binary, double_mul_operator)) { 244 372 err = "Double multiplication failed"; 245 373 TPRINTF("%s\n", err); 246 374 } 247 if (!test_template (double_template, double_div_operator)) {375 if (!test_template_binary(double_template_binary, double_div_operator)) { 248 376 err = "Double division failed"; 249 377 TPRINTF("%s\n", err); 250 378 } 379 if (!test_template_binary(double_compare_template, double_cmp_operator)) { 380 err = "Double comparison failed"; 381 TPRINTF("%s\n", err); 382 } 383 if (!test_template_unary(uint_to_double_template, 384 uint_to_double_operator)) { 385 err = "Conversion from unsigned int to double failed"; 386 TPRINTF("%s\n", err); 387 } 388 if (!test_template_unary(double_to_uint_template, 389 double_to_uint_operator)) { 390 err = "Conversion from double to unsigned int failed"; 391 TPRINTF("%s\n", err); 392 } 393 if (!test_template_unary(double_to_uint_template, 394 double_to_int_operator)) { 395 err = "Conversion from double to signed int failed"; 396 TPRINTF("%s\n", err); 397 } 251 398 252 399 return err; -
uspace/app/tester/print/print5.def
r150a2718 r8f88beb7 1 1 { 2 "print 1",3 " Stringprintf test",4 &test_print 1,2 "print5", 3 "Char printf test", 4 &test_print5, 5 5 true 6 6 }, -
uspace/app/tester/tester.c
r150a2718 r8f88beb7 53 53 #include "print/print4.def" 54 54 #include "print/print5.def" 55 #include "print/print6.def" 55 56 #include "console/console1.def" 56 57 #include "stdio/stdio1.def" … … 73 74 #include "hw/serial/serial1.def" 74 75 #include "hw/misc/virtchar1.def" 75 #include "ext2/ext2_1.def"76 76 {NULL, NULL, NULL, false} 77 77 }; -
uspace/app/tester/tester.h
r150a2718 r8f88beb7 85 85 extern const char *test_print4(void); 86 86 extern const char *test_print5(void); 87 extern const char *test_print6(void); 87 88 extern const char *test_console1(void); 88 89 extern const char *test_stdio1(void); … … 105 106 extern const char *test_serial1(void); 106 107 extern const char *test_virtchar1(void); 107 extern const char *test_ext2_1(void);108 108 extern const char *test_devman1(void); 109 109 extern const char *test_devman2(void); -
uspace/drv/infrastructure/rootamdm37x/Makefile
r150a2718 r8f88beb7 33 33 34 34 SOURCES = \ 35 amdm37x.c \ 35 36 rootamdm37x.c 36 37 -
uspace/drv/infrastructure/rootamdm37x/amdm37x.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 201 1 Martin Sucha2 * Copyright (c) 2012 Jan Vesely 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libext229 /** @addtogroup amdm37xdrv 30 30 * @{ 31 31 */ 32 /** 33 * @ file32 /** @file 33 * @brief AM/DM 37x device. 34 34 */ 35 #ifndef AMDM37x_H 36 #define AMDM37x_H 35 37 36 #i fndef LIBEXT2_LIBEXT2_BLOCK_GROUP_H_37 # define LIBEXT2_LIBEXT2_BLOCK_GROUP_H_38 #include "uhh.h" 39 #include "usbtll.h" 38 40 39 #include <block.h> 41 #include "cm/core.h" 42 #include "cm/clock_control.h" 43 #include "cm/usbhost.h" 44 #include "cm/mpu.h" 45 #include "cm/iva2.h" 40 46 41 typedef struct ext2_block_group { 42 uint32_t block_bitmap_block; // Block ID for block bitmap 43 uint32_t inode_bitmap_block; // Block ID for inode bitmap 44 uint32_t inode_table_first_block; // Block ID of first block of inode table 45 uint16_t free_block_count; // Count of free blocks 46 uint16_t free_inode_count; // Count of free inodes 47 uint16_t directory_inode_count; // Number of inodes allocated to directories 48 } ext2_block_group_t; 47 #include "prm/clock_control.h" 48 #include "prm/global_reg.h" 49 49 50 typedef struct ext2_block_group_ref { 51 block_t *block; // Reference to a block containing this block group descr 52 ext2_block_group_t *block_group; 53 } ext2_block_group_ref_t; 50 #include <bool.h> 54 51 55 #define EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE 32 52 typedef struct { 53 uhh_regs_t *uhh; 54 tll_regs_t *tll; 55 struct { 56 mpu_cm_regs_t *mpu; 57 iva2_cm_regs_t *iva2; 58 core_cm_regs_t *core; 59 clock_control_cm_regs_t *clocks; 60 usbhost_cm_regs_t *usbhost; 61 } cm; 62 struct { 63 clock_control_prm_regs_t *clocks; 64 global_reg_prm_regs_t *global; 65 } prm; 66 } amdm37x_t; 56 67 57 extern uint32_t ext2_block_group_get_block_bitmap_block(ext2_block_group_t *); 58 extern uint32_t ext2_block_group_get_inode_bitmap_block(ext2_block_group_t *); 59 extern uint32_t ext2_block_group_get_inode_table_first_block(ext2_block_group_t *); 60 extern uint16_t ext2_block_group_get_free_block_count(ext2_block_group_t *); 61 extern uint16_t ext2_block_group_get_free_inode_count(ext2_block_group_t *); 62 extern uint16_t ext2_block_group_get_directory_inode_count(ext2_block_group_t *); 63 64 extern void ext2_block_group_set_free_block_count(ext2_block_group_t *, uint16_t); 68 int amdm37x_init(amdm37x_t *device, bool trace_io); 69 int amdm37x_usb_tll_init(amdm37x_t *device); 70 void amdm37x_setup_dpll_on_autoidle(amdm37x_t *device); 71 void amdm37x_usb_clocks_set(amdm37x_t *device, bool enabled); 65 72 66 73 #endif 67 68 /** @}74 /** 75 * @} 69 76 */ -
uspace/drv/infrastructure/rootamdm37x/cm/clock_control.h
r150a2718 r8f88beb7 67 67 68 68 ioport32_t clken2_pll; 69 #define CLOCK_CONTROL_CM_CLKEN _PLL_EN_PERIPH2_DPLL_LPMODE_FLAG (1 << 10)70 #define CLOCK_CONTROL_CM_CLKEN _PLL_EN_PERIPH2_DPLL_DRIFTGUARD_FLAG (1 << 3)71 #define CLOCK_CONTROL_CM_CLKEN _PLL_EN_PERIPH2_DPLL_MASK (0x7)72 #define CLOCK_CONTROL_CM_CLKEN _PLL_EN_PERIPH2_DPLL_LP_STOP (0x1)73 #define CLOCK_CONTROL_CM_CLKEN _PLL_EN_PERIPH2_DPLL_LOCK (0x7)69 #define CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_LPMODE_FLAG (1 << 10) 70 #define CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_DRIFTGUARD_FLAG (1 << 3) 71 #define CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_MASK (0x7) 72 #define CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_LP_STOP (0x1) 73 #define CLOCK_CONTROL_CM_CLKEN2_PLL_EN_PERIPH2_DPLL_LOCK (0x7) 74 74 75 75 PADD32[6]; … … 114 114 ioport32_t clksel1_pll; 115 115 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_CLKOUT_DIV_MASK (0x1f << 27) 116 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_CLKOUT_DIV_(x) (((x) & 0x1f) << 27) 116 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_CLKOUT_DIV_CREATE(x) (((x) & 0x1f) << 27) 117 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_CLKOUT_DIV_GET(x) (((x) >> 27) & 0x1f) 117 118 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_MULT_MASK (0x7ff << 16) 118 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_MULT(x) (((x) & 0x7ff) << 16) 119 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_MULT_CREATE(x) (((x) & 0x7ff) << 16) 120 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_MULT_GET(x) (((x) >> 16) & 0x7ff) 119 121 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_DIV_MASK (0x7f << 8) 120 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_DIV(x) (((x) & 0x7f) << 8) 122 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_DIV_CREATE(x) (((x) & 0x7f) << 8) 123 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_CORE_DPLL_DIV_GET(x) (((x) >> 8) & 0x7f) 121 124 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_SOURCE_96M_FLAG (1 << 6) 122 125 #define CLOCK_CONTROL_CM_CLKSEL1_PLL_SOURCE_54M_FLAG (1 << 5) … … 140 143 ioport32_t clksel4_pll; 141 144 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_MULT_MASK (0x7ff << 8) 142 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_MULT(x) (((x) & 0x7ff) << 8) 145 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_MULT_CREATE(x) (((x) & 0x7ff) << 8) 146 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_MULT_GET(x) (((x) >> 8) & 0x7ff) 143 147 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_DIV_MASK (0x7f) 144 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_DIV(x) ((x) & 0x7f) 148 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_DIV_CREATE(x) ((x) & 0x7f) 149 #define CLOCK_CONTROL_CM_CLKSEL4_PLL_PERIPH2_DPLL_DIV_GET(x) ((x) & 0x7f) 145 150 146 151 ioport32_t clksel5_pll; 147 152 #define CLOCK_CONTROL_CM_CLKSEL5_PLL_DIV120M_MASK (0x1f) 148 #define CLOCK_CONTROL_CM_CLKSEL5_PLL_DIV120M(x) ((x) & 0x1f) 153 #define CLOCK_CONTROL_CM_CLKSEL5_PLL_DIV120M_CREATE(x) ((x) & 0x1f) 154 #define CLOCK_CONTROL_CM_CLKSEL5_PLL_DIV120M_GET(x) ((x) & 0x1f) 149 155 } clock_control_cm_regs_t; 150 156 -
uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c
r150a2718 r8f88beb7 35 35 /** @file 36 36 */ 37 #define _DDF_DATA_IMPLANT 38 39 #define DEBUG_CM 40 41 #include <ddf/driver.h> 37 38 #define DEBUG_CM 0 39 42 40 #include <ddf/log.h> 43 41 #include <errno.h> 44 42 #include <ops/hw_res.h> 45 43 #include <stdio.h> 46 #include <ddi.h> 47 48 #include "uhh.h" 49 #include "usbtll.h" 50 #include "cm/core.h" 51 #include "cm/clock_control.h" 52 #include "cm/usbhost.h" 44 45 #include "amdm37x.h" 53 46 54 47 #define NAME "rootamdm37x" 55 56 typedef struct {57 uhh_regs_t *uhh;58 tll_regs_t *tll;59 struct {60 core_cm_regs_t *core;61 clock_control_cm_regs_t *clocks;62 usbhost_cm_regs_t *usbhost;63 } cm;64 } amdm37x_t;65 66 #ifdef DEBUG_CM67 static void log(volatile void *place, uint32_t val, volatile void* base, size_t size, void *data, bool write)68 {69 printf("PIO %s: %p(%p) %#"PRIx32"\n", write ? "WRITE" : "READ",70 (place - base) + data, place, val);71 }72 #endif73 74 static int amdm37x_hw_access_init(amdm37x_t *device)75 {76 assert(device);77 int ret = EOK;78 79 ret = pio_enable((void*)USBHOST_CM_BASE_ADDRESS, USBHOST_CM_SIZE,80 (void**)&device->cm.usbhost);81 if (ret != EOK)82 return ret;83 84 ret = pio_enable((void*)CORE_CM_BASE_ADDRESS, CORE_CM_SIZE,85 (void**)&device->cm.core);86 if (ret != EOK)87 return ret;88 89 ret = pio_enable((void*)CLOCK_CONTROL_CM_BASE_ADDRESS,90 CLOCK_CONTROL_CM_SIZE, (void**)&device->cm.clocks);91 if (ret != EOK)92 return ret;93 94 ret = pio_enable((void*)AMDM37x_USBTLL_BASE_ADDRESS,95 AMDM37x_USBTLL_SIZE, (void**)&device->tll);96 if (ret != EOK)97 return ret;98 99 ret = pio_enable((void*)AMDM37x_UHH_BASE_ADDRESS,100 AMDM37x_UHH_SIZE, (void**)&device->uhh);101 if (ret != EOK)102 return ret;103 104 #ifdef DEBUG_CM105 pio_trace_enable(device->tll, AMDM37x_USBTLL_SIZE, log, (void*)AMDM37x_USBTLL_BASE_ADDRESS);106 pio_trace_enable(device->cm.clocks, CLOCK_CONTROL_CM_SIZE, log, (void*)CLOCK_CONTROL_CM_BASE_ADDRESS);107 pio_trace_enable(device->cm.core, CORE_CM_SIZE, log, (void*)CORE_CM_BASE_ADDRESS);108 pio_trace_enable(device->cm.usbhost, USBHOST_CM_SIZE, log, (void*)USBHOST_CM_BASE_ADDRESS);109 pio_trace_enable(device->uhh, AMDM37x_UHH_SIZE, log, (void*)AMDM37x_UHH_BASE_ADDRESS);110 #endif111 return EOK;112 }113 114 static int usb_clocks(amdm37x_t *device, bool on)115 {116 /* Set DPLL3 to automatic */117 pio_change_32(&device->cm.clocks->autoidle_pll,118 CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_CORE_DPLL_AUTOMATIC,119 CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_CORE_DPLL_MASK, 5);120 121 /* Set DPLL4 to automatic */122 pio_change_32(&device->cm.clocks->autoidle_pll,123 CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_PERIPH_DPLL_AUTOMATIC,124 CLOCK_CONTROL_CM_AUTOIDLE_PLL_AUTO_PERIPH_DPLL_MASK, 5);125 126 /* Set DPLL5 to automatic */127 pio_change_32(&device->cm.clocks->autoidle2_pll,128 CLOCK_CONTROL_CM_AUTOIDLE2_PLL_AUTO_PERIPH2_DPLL_AUTOMATIC,129 CLOCK_CONTROL_CM_AUTOIDLE2_PLL_AUTO_PERIPH2_DPLL_MASK, 5);130 131 132 #ifdef DEBUG_CM133 printf("DPLL5 could be on: %"PRIx32" %"PRIx32".\n",134 pio_read_32((ioport32_t*)&device->cm.clocks->idlest_ckgen),135 pio_read_32((ioport32_t*)&device->cm.clocks->idlest2_ckgen));136 #endif137 138 if (on) {139 /* Enable interface and function clock for USB TLL */140 pio_set_32(&device->cm.core->fclken3,141 CORE_CM_FCLKEN3_EN_USBTLL_FLAG, 5);142 pio_set_32(&device->cm.core->iclken3,143 CORE_CM_ICLKEN3_EN_USBTLL_FLAG, 5);144 145 /* Enable interface and function clock for USB hosts */146 pio_set_32(&device->cm.usbhost->fclken,147 USBHOST_CM_FCLKEN_EN_USBHOST1_FLAG |148 USBHOST_CM_FCLKEN_EN_USBHOST2_FLAG, 5);149 pio_set_32(&device->cm.usbhost->iclken,150 USBHOST_CM_ICLKEN_EN_USBHOST, 5);151 #ifdef DEBUG_CM152 printf("DPLL5 (and everything else) should be on: %"PRIx32" %"PRIx32".\n",153 pio_read_32((ioport32_t*)&device->cm.clocks->idlest_ckgen),154 pio_read_32((ioport32_t*)&device->cm.clocks->idlest2_ckgen));155 #endif156 } else {157 /* Disable interface and function clock for USB hosts */158 pio_clear_32(&device->cm.usbhost->iclken,159 USBHOST_CM_ICLKEN_EN_USBHOST, 5);160 pio_clear_32(&device->cm.usbhost->fclken,161 USBHOST_CM_FCLKEN_EN_USBHOST1_FLAG |162 USBHOST_CM_FCLKEN_EN_USBHOST2_FLAG, 5);163 164 /* Disable interface and function clock for USB TLL */165 pio_clear_32(&device->cm.core->iclken3,166 CORE_CM_ICLKEN3_EN_USBTLL_FLAG, 5);167 pio_clear_32(&device->cm.core->fclken3,168 CORE_CM_FCLKEN3_EN_USBTLL_FLAG, 5);169 }170 171 return EOK;172 }173 174 /** Initialize USB TLL port connections.175 *176 * Different modes are on page 3312 of the Manual Figure 22-34.177 * Select mode than can operate in FS/LS.178 */179 static int usb_tll_init(amdm37x_t *device)180 {181 182 /* Reset USB TLL */183 pio_set_32(&device->tll->sysconfig, TLL_SYSCONFIG_SOFTRESET_FLAG, 5);184 ddf_msg(LVL_DEBUG2, "Waiting for USB TLL reset");185 while (!(pio_read_32(&device->tll->sysstatus) & TLL_SYSSTATUS_RESET_DONE_FLAG));186 ddf_msg(LVL_DEBUG, "USB TLL Reset done.");187 188 /* Setup idle mode (smart idle) */189 pio_change_32(&device->tll->sysconfig,190 TLL_SYSCONFIG_CLOCKACTIVITY_FLAG | TLL_SYSCONFIG_AUTOIDLE_FLAG |191 TLL_SYSCONFIG_SIDLE_MODE_SMART, TLL_SYSCONFIG_SIDLE_MODE_MASK, 5);192 193 /* Smart idle for UHH */194 pio_change_32(&device->uhh->sysconfig,195 UHH_SYSCONFIG_CLOCKACTIVITY_FLAG | UHH_SYSCONFIG_AUTOIDLE_FLAG |196 UHH_SYSCONFIG_SIDLE_MODE_SMART, UHH_SYSCONFIG_SIDLE_MODE_MASK, 5);197 198 /* Set all ports to go through TLL(UTMI)199 * Direct connection can only work in HS mode */200 pio_set_32(&device->uhh->hostconfig,201 UHH_HOSTCONFIG_P1_ULPI_BYPASS_FLAG |202 UHH_HOSTCONFIG_P2_ULPI_BYPASS_FLAG |203 UHH_HOSTCONFIG_P3_ULPI_BYPASS_FLAG, 5);204 205 /* What is this? */206 pio_set_32(&device->tll->shared_conf, TLL_SHARED_CONF_FCLK_IS_ON_FLAG, 5);207 208 for (unsigned i = 0; i < 3; ++i) {209 /* Serial mode is the only one capable of FS/LS operation.210 * Select FS/LS mode, no idea what the difference is211 * one of bidirectional modes might be good choice212 * 2 = 3pin bidi phy. */213 pio_change_32(&device->tll->channel_conf[i],214 TLL_CHANNEL_CONF_CHANMODE_UTMI_SERIAL_MODE |215 TLL_CHANNEL_CONF_FSLSMODE_3PIN_BIDI_PHY,216 TLL_CHANNEL_CONF_CHANMODE_MASK |217 TLL_CHANNEL_CONF_FSLSMODE_MASK, 5);218 }219 return EOK;220 }221 48 222 49 typedef struct { … … 224 51 } rootamdm37x_fun_t; 225 52 53 /* See amdm37x TRM page. 3316 for these values */ 226 54 #define OHCI_BASE_ADDRESS 0x48064400 227 55 #define OHCI_SIZE 1024 … … 232 60 { 233 61 .type = MEM_RANGE, 234 /* See amdm37x TRM page. 3316 for these values */235 62 .res.io_range = { 236 63 .address = OHCI_BASE_ADDRESS, … … 243 70 .res.interrupt = { .irq = 76 }, 244 71 }, 245 };246 247 static const rootamdm37x_fun_t ohci = {248 .hw_resources = {249 .resources = ohci_res,250 .count = sizeof(ohci_res)/sizeof(ohci_res[0]),251 }252 72 }; 253 73 … … 268 88 }; 269 89 90 static const rootamdm37x_fun_t ohci = { 91 .hw_resources = { 92 .resources = ohci_res, 93 .count = sizeof(ohci_res)/sizeof(ohci_res[0]), 94 } 95 }; 96 270 97 static const rootamdm37x_fun_t ehci = { 271 98 .hw_resources = { … … 283 110 }; 284 111 285 static ddf_dev_ops_t rootamdm37x_fun_ops = 286 { 112 static ddf_dev_ops_t rootamdm37x_fun_ops = { 287 113 .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops 288 114 }; 289 115 290 static boolrootamdm37x_add_fun(ddf_dev_t *dev, const char *name,116 static int rootamdm37x_add_fun(ddf_dev_t *dev, const char *name, 291 117 const char *str_match_id, const rootamdm37x_fun_t *fun) 292 118 { … … 298 124 return ENOMEM; 299 125 300 301 126 /* Add match id */ 302 if (ddf_fun_add_match_id(fnode, str_match_id, 100) != EOK) { 127 int ret = ddf_fun_add_match_id(fnode, str_match_id, 100); 128 if (ret != EOK) { 303 129 ddf_fun_destroy(fnode); 304 return false; 305 } 306 130 return ret; 131 } 132 133 /* Alloc needed data */ 134 rootamdm37x_fun_t *rf = 135 ddf_fun_data_alloc(fnode, sizeof(rootamdm37x_fun_t)); 136 if (!rf) { 137 ddf_fun_destroy(fnode); 138 return ENOMEM; 139 } 140 *rf = *fun; 141 307 142 /* Set provided operations to the device. */ 308 ddf_fun_data_implant(fnode, (void*)fun);309 143 ddf_fun_set_ops(fnode, &rootamdm37x_fun_ops); 310 144 311 145 /* Register function. */ 312 if (ddf_fun_bind(fnode) != EOK) { 146 ret = ddf_fun_bind(fnode); 147 if (ret != EOK) { 313 148 ddf_msg(LVL_ERROR, "Failed binding function %s.", name); 314 // TODO This will try to free our data!315 149 ddf_fun_destroy(fnode); 316 return false;317 } 318 319 return true;150 return ret; 151 } 152 153 return EOK; 320 154 } 321 155 … … 334 168 if (!device) 335 169 return ENOMEM; 336 int ret = amdm37x_ hw_access_init(device);170 int ret = amdm37x_init(device, DEBUG_CM); 337 171 if (ret != EOK) { 338 172 ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n"); … … 340 174 } 341 175 342 ret = usb_clocks(device, true); 343 if (ret != EOK) { 344 ddf_msg(LVL_FATAL, "Failed to enable USB HC clocks!.\n"); 345 return ret; 346 } 347 348 ret = usb_tll_init(device); 176 /* Set dplls to ON and automatic */ 177 amdm37x_setup_dpll_on_autoidle(device); 178 179 /* Enable function and interface clocks */ 180 amdm37x_usb_clocks_set(device, true); 181 182 /* Init TLL */ 183 ret = amdm37x_usb_tll_init(device); 349 184 if (ret != EOK) { 350 185 ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n"); 351 usb_clocks(device, false);186 amdm37x_usb_clocks_set(device, false); 352 187 return ret; 353 188 } 354 189 355 190 /* Register functions */ 356 if ( !rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci))191 if (rootamdm37x_add_fun(dev, "ohci", "usb/host=ohci", &ohci) != EOK) 357 192 ddf_msg(LVL_ERROR, "Failed to add OHCI function for " 358 193 "BeagleBoard-xM platform."); 359 if ( !rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci))194 if (rootamdm37x_add_fun(dev, "ehci", "usb/host=ehci", &ehci) != EOK) 360 195 ddf_msg(LVL_ERROR, "Failed to add EHCI function for " 361 196 "BeagleBoard-xM platform."); … … 375 210 }; 376 211 377 static hw_resource_list_t * rootamdm37x_get_resources(ddf_fun_t *fnode)212 static hw_resource_list_t * rootamdm37x_get_resources(ddf_fun_t *fnode) 378 213 { 379 214 rootamdm37x_fun_t *fun = ddf_fun_data_get(fnode); … … 384 219 static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun) 385 220 { 386 / * TODO */221 //TODO: Implement 387 222 return false; 388 223 } -
uspace/drv/infrastructure/rootamdm37x/usbtll.h
r150a2718 r8f88beb7 57 57 #define TLL_SYSCONFIG_CLOCKACTIVITY_FLAG (1 << 8) 58 58 59 ioport32_t sysstatus;59 const ioport32_t sysstatus; 60 60 #define TLL_SYSSTATUS_RESET_DONE_FLAG (1 << 0) 61 61 -
uspace/drv/time/cmos-rtc/cmos-rtc.c
r150a2718 r8f88beb7 99 99 static time_t uptime_get(void); 100 100 static bool is_battery_ok(rtc_t *rtc); 101 static int rtc_fun_online(ddf_fun_t *fun); 102 static int rtc_fun_offline(ddf_fun_t *fun); 101 103 102 104 static ddf_dev_ops_t rtc_dev_ops; … … 106 108 .dev_add = rtc_dev_add, 107 109 .dev_remove = rtc_dev_remove, 110 .fun_online = rtc_fun_online, 111 .fun_offline = rtc_fun_offline, 108 112 }; 109 113 … … 405 409 /* Try to normalize the content of the tm structure */ 406 410 time_t r = mktime(t); 407 408 rtc->boottime = r - uptime_get(); 411 int result; 412 413 if (r < 0) 414 result = EINVAL; 415 else { 416 rtc->boottime = r - uptime_get(); 417 result = EOK; 418 } 409 419 410 420 fibril_mutex_unlock(&rtc->mutex); 411 421 412 return r < 0 ? EINVAL : EOK;422 return result; 413 423 } 414 424 … … 637 647 fibril_mutex_unlock(&rtc->mutex); 638 648 649 rc = rtc_fun_offline(rtc->fun); 650 if (rc != EOK) { 651 ddf_msg(LVL_ERROR, "Failed to offline function"); 652 return rc; 653 } 654 639 655 rc = ddf_fun_unbind(rtc->fun); 640 656 if (rc != EOK) { … … 725 741 } 726 742 743 static int 744 rtc_fun_online(ddf_fun_t *fun) 745 { 746 int rc; 747 748 ddf_msg(LVL_DEBUG, "rtc_fun_online()"); 749 750 rc = ddf_fun_online(fun); 751 if (rc == EOK) 752 ddf_fun_add_to_category(fun, "clock"); 753 754 return rc; 755 } 756 757 static int 758 rtc_fun_offline(ddf_fun_t *fun) 759 { 760 ddf_msg(LVL_DEBUG, "rtc_fun_offline()"); 761 return ddf_fun_offline(fun); 762 } 763 727 764 int 728 765 main(int argc, char **argv) -
uspace/lib/c/Makefile
r150a2718 r8f88beb7 77 77 generic/device/pci.c \ 78 78 generic/device/ahci.c \ 79 generic/dlfcn.c \ 79 80 generic/elf/elf_load.c \ 80 81 generic/event.c \ … … 115 116 generic/iplink.c \ 116 117 generic/iplink_srv.c \ 118 generic/ieee_double.c \ 119 generic/power_of_ten.c \ 120 generic/double_to_str.c \ 117 121 generic/malloc.c \ 118 122 generic/sysinfo.c \ … … 136 140 generic/net/socket_client.c \ 137 141 generic/net/socket_parse.c \ 142 generic/stack.c \ 138 143 generic/stacktrace.c \ 139 144 generic/arg_parse.c \ … … 145 150 ifeq ($(CONFIG_RTLD),y) 146 151 GENERIC_SOURCES += \ 147 generic/dlfcn.c \148 152 generic/rtld/rtld.c \ 149 153 generic/rtld/dynamic.c \ -
uspace/lib/c/arch/abs32le/include/ddi.h
r150a2718 r8f88beb7 51 51 } 52 52 53 static inline uint8_t arch_pio_read_8( ioport8_t *port)53 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 54 54 { 55 55 return *port; 56 56 } 57 57 58 static inline uint16_t arch_pio_read_16( ioport16_t *port)58 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 59 59 { 60 60 return *port; 61 61 } 62 62 63 static inline uint32_t arch_pio_read_32( ioport32_t *port)63 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 64 64 { 65 65 return *port; -
uspace/lib/c/arch/arm32/include/ddi.h
r150a2718 r8f88beb7 52 52 } 53 53 54 static inline uint8_t arch_pio_read_8( ioport8_t *port)54 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 55 55 { 56 56 return *port; 57 57 } 58 58 59 static inline uint16_t arch_pio_read_16( ioport16_t *port)59 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 60 60 { 61 61 return *port; 62 62 } 63 63 64 static inline uint32_t arch_pio_read_32( ioport32_t *port)64 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 65 65 { 66 66 return *port; -
uspace/lib/c/arch/ia32/include/ddi.h
r150a2718 r8f88beb7 39 39 #define IO_SPACE_BOUNDARY ((void *) (64 * 1024)) 40 40 41 static inline uint8_t arch_pio_read_8( ioport8_t *port)41 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 42 42 { 43 43 if (port < (ioport8_t *) IO_SPACE_BOUNDARY) { … … 55 55 } 56 56 57 static inline uint16_t arch_pio_read_16( ioport16_t *port)57 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 58 58 { 59 59 if (port < (ioport16_t *) IO_SPACE_BOUNDARY) { … … 71 71 } 72 72 73 static inline uint32_t arch_pio_read_32( ioport32_t *port)73 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 74 74 { 75 75 if (port < (ioport32_t *) IO_SPACE_BOUNDARY) { -
uspace/lib/c/arch/ia64/include/ddi.h
r150a2718 r8f88beb7 95 95 } 96 96 97 static inline uint8_t arch_pio_read_8( ioport8_t *port)97 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 98 98 { 99 99 uint8_t v; … … 115 115 } 116 116 117 static inline uint16_t arch_pio_read_16( ioport16_t *port)117 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 118 118 { 119 119 uint16_t v; … … 135 135 } 136 136 137 static inline uint32_t arch_pio_read_32( ioport32_t *port)137 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 138 138 { 139 139 uint32_t v; -
uspace/lib/c/arch/mips32/include/ddi.h
r150a2718 r8f88beb7 52 52 } 53 53 54 static inline uint8_t arch_pio_read_8( ioport8_t *port)54 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 55 55 { 56 56 return *port; 57 57 } 58 58 59 static inline uint16_t arch_pio_read_16( ioport16_t *port)59 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 60 60 { 61 61 return *port; 62 62 } 63 63 64 static inline uint32_t arch_pio_read_32( ioport32_t *port)64 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 65 65 { 66 66 return *port; -
uspace/lib/c/arch/mips64/include/ddi.h
r150a2718 r8f88beb7 52 52 } 53 53 54 static inline uint8_t arch_pio_read_8( ioport8_t *port)54 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 55 55 { 56 56 return *port; 57 57 } 58 58 59 static inline uint16_t arch_pio_read_16( ioport16_t *port)59 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 60 60 { 61 61 return *port; 62 62 } 63 63 64 static inline uint32_t arch_pio_read_32( ioport32_t *port)64 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 65 65 { 66 66 return *port; -
uspace/lib/c/arch/ppc32/include/ddi.h
r150a2718 r8f88beb7 52 52 } 53 53 54 static inline uint8_t arch_pio_read_8( ioport8_t *port)54 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 55 55 { 56 56 return *port; 57 57 } 58 58 59 static inline uint16_t arch_pio_read_16( ioport16_t *port)59 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 60 60 { 61 61 return *port; 62 62 } 63 63 64 static inline uint32_t arch_pio_read_32( ioport32_t *port)64 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 65 65 { 66 66 return *port; -
uspace/lib/c/arch/sparc64/include/ddi.h
r150a2718 r8f88beb7 63 63 } 64 64 65 static inline uint8_t arch_pio_read_8( ioport8_t *port)65 static inline uint8_t arch_pio_read_8(const ioport8_t *port) 66 66 { 67 67 uint8_t rv; … … 73 73 } 74 74 75 static inline uint16_t arch_pio_read_16( ioport16_t *port)75 static inline uint16_t arch_pio_read_16(const ioport16_t *port) 76 76 { 77 77 uint16_t rv; … … 83 83 } 84 84 85 static inline uint32_t arch_pio_read_32( ioport32_t *port)85 static inline uint32_t arch_pio_read_32(const ioport32_t *port) 86 86 { 87 87 uint32_t rv; -
uspace/lib/c/generic/ddi.c
r150a2718 r8f88beb7 192 192 } 193 193 194 uint8_t pio_read_8( ioport8_t *reg)194 uint8_t pio_read_8(const ioport8_t *reg) 195 195 { 196 196 const uint8_t val = arch_pio_read_8(reg); … … 199 199 } 200 200 201 uint16_t pio_read_16( ioport16_t *reg)201 uint16_t pio_read_16(const ioport16_t *reg) 202 202 { 203 203 const uint16_t val = arch_pio_read_16(reg); … … 206 206 } 207 207 208 uint32_t pio_read_32( ioport32_t *reg)208 uint32_t pio_read_32(const ioport32_t *reg) 209 209 { 210 210 const uint32_t val = arch_pio_read_32(reg); -
uspace/lib/c/generic/dlfcn.c
r150a2718 r8f88beb7 38 38 #include <stdlib.h> 39 39 #include <dlfcn.h> 40 41 #ifdef CONFIG_RTLD 40 42 41 43 #include <rtld/module.h> … … 87 89 } 88 90 91 #else /* CONFIG_RTLD not defined */ 92 93 void *dlopen(const char *path, int flag) 94 { 95 return NULL; 96 } 97 98 void *dlsym(void *mod, const char *sym_name) 99 { 100 return NULL; 101 } 102 103 #endif 104 89 105 /** @} 90 106 */ -
uspace/lib/c/generic/fibril.c
r150a2718 r8f88beb7 37 37 #include <fibril.h> 38 38 #include <thread.h> 39 #include <stack.h> 39 40 #include <tls.h> 40 41 #include <malloc.h> 42 #include <abi/mm/as.h> 43 #include <as.h> 41 44 #include <unistd.h> 42 45 #include <stdio.h> … … 46 49 #include <assert.h> 47 50 #include <async.h> 48 49 #ifndef FIBRIL_INITIAL_STACK_PAGES_NO50 #define FIBRIL_INITIAL_STACK_PAGES_NO 151 #endif52 51 53 52 /** … … 195 194 * stack member filled. 196 195 */ 197 free(stack);196 as_area_destroy(stack); 198 197 } 199 198 fibril_teardown(srcf->clean_after_me); … … 269 268 return 0; 270 269 271 fibril->stack = 272 (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize()); 273 if (!fibril->stack) { 270 size_t stack_size = stack_size_get(); 271 fibril->stack = as_area_create((void *) -1, stack_size, 272 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD | 273 AS_AREA_LATE_RESERVE); 274 if (fibril->stack == (void *) -1) { 274 275 fibril_teardown(fibril); 275 276 return 0; … … 281 282 context_save(&fibril->ctx); 282 283 context_set(&fibril->ctx, FADDR(fibril_main), fibril->stack, 283 FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), fibril->tcb);284 stack_size, fibril->tcb); 284 285 285 286 return (fid_t) fibril; … … 298 299 fibril_t *fibril = (fibril_t *) fid; 299 300 300 free(fibril->stack);301 as_area_destroy(fibril->stack); 301 302 fibril_teardown(fibril); 302 303 } -
uspace/lib/c/generic/io/log.c
r150a2718 r8f88beb7 239 239 240 240 char *message_buffer = malloc(MESSAGE_BUFFER_SIZE); 241 if (message_buffer == NULL) {241 if (message_buffer == NULL) 242 242 return; 243 }244 243 245 244 vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args); 246 245 logger_message(logger_session, ctx, level, message_buffer); 246 free(message_buffer); 247 247 } 248 248 -
uspace/lib/c/generic/io/printf_core.c
r150a2718 r8f88beb7 42 42 #include <ctype.h> 43 43 #include <str.h> 44 #include <double_to_str.h> 45 #include <ieee_double.h> 46 #include <assert.h> 47 #include <macros.h> 48 44 49 45 50 /** show prefixes 0x or 0 */ 46 51 #define __PRINTF_FLAG_PREFIX 0x00000001 47 52 53 /** show the decimal point even if no fractional digits present */ 54 #define __PRINTF_FLAG_DECIMALPT 0x00000001 55 48 56 /** signed / unsigned number */ 49 57 #define __PRINTF_FLAG_SIGNED 0x00000002 … … 66 74 /** number has - sign */ 67 75 #define __PRINTF_FLAG_NEGATIVE 0x00000100 76 77 /** don't print trailing zeros in the fractional part */ 78 #define __PRINTF_FLAG_NOFRACZEROS 0x00000200 79 68 80 69 81 /** … … 110 122 static const char invalch = U_SPECIAL; 111 123 124 125 126 /** Unformatted double number string representation. */ 127 typedef struct { 128 /** Buffer with len digits, no sign or leading zeros. */ 129 char *str; 130 /** Number of digits in str. */ 131 int len; 132 /** Decimal exponent, ie number = str * 10^dec_exp */ 133 int dec_exp; 134 /** True if negative. */ 135 bool neg; 136 } double_str_t; 137 138 139 140 /** Returns the sign character or 0 if no sign should be printed. */ 141 static int get_sign_char(bool negative, uint32_t flags) 142 { 143 if (negative) { 144 return '-'; 145 } else if (flags & __PRINTF_FLAG_SHOWPLUS) { 146 return '+'; 147 } else if (flags & __PRINTF_FLAG_SPACESIGN) { 148 return ' '; 149 } else { 150 return 0; 151 } 152 } 153 154 /** Prints count times character ch. */ 155 static int print_padding(char ch, int count, printf_spec_t *ps) 156 { 157 for (int i = 0; i < count; ++i) { 158 if (ps->str_write(&ch, 1, ps->data) < 0) { 159 return -1; 160 } 161 } 162 163 return count; 164 } 165 166 112 167 /** Print one or more characters without adding newline. 113 168 * … … 281 336 return printf_putstr(nullstr, ps); 282 337 283 /* Print leading spaces. */284 338 size_t strw = str_length(str); 339 340 /* Precision unspecified - print everything. */ 285 341 if ((precision == 0) || (precision > strw)) 286 342 precision = strw; … … 329 385 return printf_putstr(nullstr, ps); 330 386 331 /* Print leading spaces. */332 387 size_t strw = wstr_length(str); 388 389 /* Precision not specified - print everything. */ 333 390 if ((precision == 0) || (precision > strw)) 334 391 precision = strw; … … 377 434 uint32_t flags, printf_spec_t *ps) 378 435 { 436 /* Precision not specified. */ 437 if (precision < 0) { 438 precision = 0; 439 } 440 379 441 const char *digits; 380 442 if (flags & __PRINTF_FLAG_BIGCHARS) … … 525 587 526 588 return ((int) counter); 589 } 590 591 /** Prints a special double (ie NaN, infinity) padded to width characters. */ 592 static int print_special(ieee_double_t val, int width, uint32_t flags, 593 printf_spec_t *ps) 594 { 595 assert(val.is_special); 596 597 char sign = get_sign_char(val.is_negative, flags); 598 599 const int str_len = 3; 600 const char *str; 601 602 if (flags & __PRINTF_FLAG_BIGCHARS) { 603 str = val.is_infinity ? "INF" : "NAN"; 604 } else { 605 str = val.is_infinity ? "inf" : "nan"; 606 } 607 608 int padding_len = max(0, width - ((sign ? 1 : 0) + str_len)); 609 610 int counter = 0; 611 int ret; 612 613 /* Leading padding. */ 614 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 615 if ((ret = print_padding(' ', padding_len, ps)) < 0) 616 return -1; 617 618 counter += ret; 619 } 620 621 if (sign) { 622 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 623 return -1; 624 625 counter += ret; 626 } 627 628 if ((ret = ps->str_write(str, str_len, ps->data)) < 0) 629 return -1; 630 631 counter += ret; 632 633 634 /* Trailing padding. */ 635 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 636 if ((ret = print_padding(' ', padding_len, ps)) < 0) 637 return -1; 638 639 counter += ret; 640 } 641 642 return counter; 643 } 644 645 /** Trims trailing zeros but leaves a single "0" intact. */ 646 static void fp_trim_trailing_zeros(char *buf, int *len, int *dec_exp) 647 { 648 /* Cut the zero off by adjusting the exponent. */ 649 while (2 <= *len && '0' == buf[*len - 1]) { 650 --*len; 651 ++*dec_exp; 652 } 653 } 654 655 /** Textually round up the last digit thereby eliminating it. */ 656 static void fp_round_up(char *buf, int *len, int *dec_exp) 657 { 658 assert(1 <= *len); 659 660 char *last_digit = &buf[*len - 1]; 661 662 int carry = ('5' <= *last_digit); 663 664 /* Cut the digit off by adjusting the exponent. */ 665 --*len; 666 ++*dec_exp; 667 --last_digit; 668 669 if (carry) { 670 /* Skip all the digits to cut off/round to zero. */ 671 while (buf <= last_digit && '9' == *last_digit) { 672 --last_digit; 673 } 674 675 /* last_digit points to the last digit to round but not '9' */ 676 if (buf <= last_digit) { 677 *last_digit += 1; 678 int new_len = last_digit - buf + 1; 679 *dec_exp += *len - new_len; 680 *len = new_len; 681 } else { 682 /* All len digits rounded to 0. */ 683 buf[0] = '1'; 684 *dec_exp += *len; 685 *len = 1; 686 } 687 } else { 688 /* The only digit was rounded to 0. */ 689 if (last_digit < buf) { 690 buf[0] = '0'; 691 *dec_exp = 0; 692 *len = 1; 693 } 694 } 695 } 696 697 698 /** Format and print the double string repressentation according 699 * to the %f specifier. 700 */ 701 static int print_double_str_fixed(double_str_t *val_str, int precision, int width, 702 uint32_t flags, printf_spec_t *ps) 703 { 704 int len = val_str->len; 705 char *buf = val_str->str; 706 int dec_exp = val_str->dec_exp; 707 708 assert(0 < len); 709 assert(0 <= precision); 710 assert(0 <= dec_exp || -dec_exp <= precision); 711 712 /* Number of integral digits to print (at least leading zero). */ 713 int int_len = max(1, len + dec_exp); 714 715 char sign = get_sign_char(val_str->neg, flags); 716 717 /* Fractional portion lengths. */ 718 int last_frac_signif_pos = max(0, -dec_exp); 719 int leading_frac_zeros = max(0, last_frac_signif_pos - len); 720 int signif_frac_figs = min(last_frac_signif_pos, len); 721 int trailing_frac_zeros = precision - last_frac_signif_pos; 722 char *buf_frac = buf + len - signif_frac_figs; 723 724 if (flags & __PRINTF_FLAG_NOFRACZEROS) { 725 trailing_frac_zeros = 0; 726 } 727 728 int frac_len = leading_frac_zeros + signif_frac_figs + trailing_frac_zeros; 729 730 bool has_decimal_pt = (0 < frac_len) || (flags & __PRINTF_FLAG_DECIMALPT); 731 732 /* Number of non-padding chars to print. */ 733 int num_len = (sign ? 1 : 0) + int_len + (has_decimal_pt ? 1 : 0) + frac_len; 734 735 int padding_len = max(0, width - num_len); 736 int ret = 0; 737 int counter = 0; 738 739 /* Leading padding and sign. */ 740 741 if (!(flags & (__PRINTF_FLAG_LEFTALIGNED | __PRINTF_FLAG_ZEROPADDED))) { 742 if ((ret = print_padding(' ', padding_len, ps)) < 0) 743 return -1; 744 745 counter += ret; 746 } 747 748 if (sign) { 749 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 750 return -1; 751 752 counter += ret; 753 } 754 755 if (flags & __PRINTF_FLAG_ZEROPADDED) { 756 if ((ret = print_padding('0', padding_len, ps)) < 0) 757 return -1; 758 759 counter += ret; 760 } 761 762 /* Print the intergral part of the buffer. */ 763 764 int buf_int_len = min(len, len + dec_exp); 765 766 if (0 < buf_int_len) { 767 if ((ret = ps->str_write(buf, buf_int_len, ps->data)) < 0) 768 return -1; 769 770 counter += ret; 771 772 /* Print trailing zeros of the integral part of the number. */ 773 if ((ret = print_padding('0', int_len - buf_int_len, ps)) < 0) 774 return -1; 775 } else { 776 /* Single leading integer 0. */ 777 char ch = '0'; 778 if ((ret = ps->str_write(&ch, 1, ps->data)) < 0) 779 return -1; 780 } 781 782 counter += ret; 783 784 /* Print the decimal point and the fractional part. */ 785 if (has_decimal_pt) { 786 char ch = '.'; 787 788 if ((ret = ps->str_write(&ch, 1, ps->data)) < 0) 789 return -1; 790 791 counter += ret; 792 793 /* Print leading zeros of the fractional part of the number. */ 794 if ((ret = print_padding('0', leading_frac_zeros, ps)) < 0) 795 return -1; 796 797 counter += ret; 798 799 /* Print significant digits of the fractional part of the number. */ 800 if (0 < signif_frac_figs) { 801 if ((ret = ps->str_write(buf_frac, signif_frac_figs, ps->data)) < 0) 802 return -1; 803 804 counter += ret; 805 } 806 807 /* Print trailing zeros of the fractional part of the number. */ 808 if ((ret = print_padding('0', trailing_frac_zeros, ps)) < 0) 809 return -1; 810 811 counter += ret; 812 } 813 814 /* Trailing padding. */ 815 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 816 if ((ret = print_padding(' ', padding_len, ps)) < 0) 817 return -1; 818 819 counter += ret; 820 } 821 822 return counter; 823 } 824 825 826 /** Convert, format and print a double according to the %f specifier. 827 * 828 * @param g Double to print. 829 * @param precision Number of fractional digits to print. If 0 no 830 * decimal point will be printed unless the flag 831 * __PRINTF_FLAG_DECIMALPT is specified. 832 * @param width Minimum number of characters to display. Pads 833 * with '0' or ' ' depending on the set flags; 834 * @param flags Printf flags. 835 * @param ps Printing functions. 836 * 837 * @return The number of characters printed; negative on failure. 838 */ 839 static int print_double_fixed(double g, int precision, int width, uint32_t flags, 840 printf_spec_t *ps) 841 { 842 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 843 flags &= ~__PRINTF_FLAG_ZEROPADDED; 844 } 845 846 if (flags & __PRINTF_FLAG_DECIMALPT) { 847 flags &= ~__PRINTF_FLAG_NOFRACZEROS; 848 } 849 850 ieee_double_t val = extract_ieee_double(g); 851 852 if (val.is_special) { 853 return print_special(val, width, flags, ps); 854 } 855 856 char buf[MAX_DOUBLE_STR_BUF_SIZE]; 857 const size_t buf_size = MAX_DOUBLE_STR_BUF_SIZE; 858 double_str_t val_str; 859 860 val_str.str = buf; 861 val_str.neg = val.is_negative; 862 863 if (0 <= precision) { 864 /* 865 * Request one more digit so we can round the result. The last 866 * digit it returns may have an error of at most +/- 1. 867 */ 868 val_str.len = double_to_fixed_str(val, -1, precision + 1, buf, buf_size, 869 &val_str.dec_exp); 870 871 /* 872 * Round using the last digit to produce precision fractional digits. 873 * If less than precision+1 fractional digits were output the last 874 * digit is definitely inaccurate so also round to get rid of it. 875 */ 876 fp_round_up(buf, &val_str.len, &val_str.dec_exp); 877 878 /* Rounding could have introduced trailing zeros. */ 879 if (flags & __PRINTF_FLAG_NOFRACZEROS) { 880 fp_trim_trailing_zeros(buf, &val_str.len, &val_str.dec_exp); 881 } 882 } else { 883 /* Let the implementation figure out the proper precision. */ 884 val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp); 885 886 /* Precision needed for the last significant digit. */ 887 precision = max(0, -val_str.dec_exp); 888 } 889 890 return print_double_str_fixed(&val_str, precision, width, flags, ps); 891 } 892 893 /** Prints the decimal exponent part of a %e specifier formatted number. */ 894 static int print_exponent(int exp_val, uint32_t flags, printf_spec_t *ps) 895 { 896 int counter = 0; 897 int ret; 898 899 char exp_ch = (flags & __PRINTF_FLAG_BIGCHARS) ? 'E' : 'e'; 900 901 if ((ret = ps->str_write(&exp_ch, 1, ps->data)) < 0) 902 return -1; 903 904 counter += ret; 905 906 char exp_sign = (exp_val < 0) ? '-' : '+'; 907 908 if ((ret = ps->str_write(&exp_sign, 1, ps->data)) < 0) 909 return -1; 910 911 counter += ret; 912 913 /* Print the exponent. */ 914 exp_val = abs(exp_val); 915 916 char exp_str[4] = { 0 }; 917 918 exp_str[0] = '0' + exp_val / 100; 919 exp_str[1] = '0' + (exp_val % 100) / 10 ; 920 exp_str[2] = '0' + (exp_val % 10); 921 922 int exp_len = (exp_str[0] == '0') ? 2 : 3; 923 const char *exp_str_start = &exp_str[3] - exp_len; 924 925 if ((ret = ps->str_write(exp_str_start, exp_len, ps->data)) < 0) 926 return -1; 927 928 counter += ret; 929 930 return counter; 931 } 932 933 934 /** Format and print the double string repressentation according 935 * to the %e specifier. 936 */ 937 static int print_double_str_scient(double_str_t *val_str, int precision, 938 int width, uint32_t flags, printf_spec_t *ps) 939 { 940 int len = val_str->len; 941 int dec_exp = val_str->dec_exp; 942 char *buf = val_str->str; 943 944 assert(0 < len); 945 946 char sign = get_sign_char(val_str->neg, flags); 947 bool has_decimal_pt = (0 < precision) || (flags & __PRINTF_FLAG_DECIMALPT); 948 int dec_pt_len = has_decimal_pt ? 1 : 0; 949 950 /* Fractional part lengths. */ 951 int signif_frac_figs = len - 1; 952 int trailing_frac_zeros = precision - signif_frac_figs; 953 954 if (flags & __PRINTF_FLAG_NOFRACZEROS) { 955 trailing_frac_zeros = 0; 956 } 957 958 int frac_len = signif_frac_figs + trailing_frac_zeros; 959 960 int exp_val = dec_exp + len - 1; 961 /* Account for exponent sign and 'e'; minimum 2 digits. */ 962 int exp_len = 2 + (abs(exp_val) >= 100 ? 3 : 2); 963 964 /* Number of non-padding chars to print. */ 965 int num_len = (sign ? 1 : 0) + 1 + dec_pt_len + frac_len + exp_len; 966 967 int padding_len = max(0, width - num_len); 968 int ret = 0; 969 int counter = 0; 970 971 if (!(flags & (__PRINTF_FLAG_LEFTALIGNED | __PRINTF_FLAG_ZEROPADDED))) { 972 if ((ret = print_padding(' ', padding_len, ps)) < 0) 973 return -1; 974 975 counter += ret; 976 } 977 978 if (sign) { 979 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 980 return -1; 981 982 counter += ret; 983 } 984 985 if (flags & __PRINTF_FLAG_ZEROPADDED) { 986 if ((ret = print_padding('0', padding_len, ps)) < 0) 987 return -1; 988 989 counter += ret; 990 } 991 992 /* Single leading integer. */ 993 if ((ret = ps->str_write(buf, 1, ps->data)) < 0) 994 return -1; 995 996 counter += ret; 997 998 /* Print the decimal point and the fractional part. */ 999 if (has_decimal_pt) { 1000 char ch = '.'; 1001 1002 if ((ret = ps->str_write(&ch, 1, ps->data)) < 0) 1003 return -1; 1004 1005 counter += ret; 1006 1007 /* Print significant digits of the fractional part of the number. */ 1008 if (0 < signif_frac_figs) { 1009 if ((ret = ps->str_write(buf + 1, signif_frac_figs, ps->data)) < 0) 1010 return -1; 1011 1012 counter += ret; 1013 } 1014 1015 /* Print trailing zeros of the fractional part of the number. */ 1016 if ((ret = print_padding('0', trailing_frac_zeros, ps)) < 0) 1017 return -1; 1018 1019 counter += ret; 1020 } 1021 1022 /* Print the exponent. */ 1023 if ((ret = print_exponent(exp_val, flags, ps)) < 0) 1024 return -1; 1025 1026 counter += ret; 1027 1028 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 1029 if ((ret = print_padding(' ', padding_len, ps)) < 0) 1030 return -1; 1031 1032 counter += ret; 1033 } 1034 1035 return counter; 1036 } 1037 1038 1039 /** Convert, format and print a double according to the %e specifier. 1040 * 1041 * Note that if g is large, the output may be huge (3e100 prints 1042 * with at least 100 digits). 1043 * 1044 * %e style: [-]d.dddde+dd 1045 * left-justified: [-]d.dddde+dd[space_pad] 1046 * right-justified: [space_pad][-][zero_pad]d.dddde+dd 1047 * 1048 * @param g Double to print. 1049 * @param precision Number of fractional digits to print, ie 1050 * precision + 1 significant digits to display. If 0 no 1051 * decimal point will be printed unless the flag 1052 * __PRINTF_FLAG_DECIMALPT is specified. If negative 1053 * the shortest accurate number will be printed. 1054 * @param width Minimum number of characters to display. Pads 1055 * with '0' or ' ' depending on the set flags; 1056 * @param flags Printf flags. 1057 * @param ps Printing functions. 1058 * 1059 * @return The number of characters printed; negative on failure. 1060 */ 1061 static int print_double_scientific(double g, int precision, int width, 1062 uint32_t flags, printf_spec_t *ps) 1063 { 1064 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 1065 flags &= ~__PRINTF_FLAG_ZEROPADDED; 1066 } 1067 1068 ieee_double_t val = extract_ieee_double(g); 1069 1070 if (val.is_special) { 1071 return print_special(val, width, flags, ps); 1072 } 1073 1074 char buf[MAX_DOUBLE_STR_BUF_SIZE]; 1075 const size_t buf_size = MAX_DOUBLE_STR_BUF_SIZE; 1076 double_str_t val_str; 1077 1078 val_str.str = buf; 1079 val_str.neg = val.is_negative; 1080 1081 if (0 <= precision) { 1082 /* 1083 * Request one more digit (in addition to the leading integer) 1084 * so we can round the result. The last digit it returns may 1085 * have an error of at most +/- 1. 1086 */ 1087 val_str.len = double_to_fixed_str(val, precision + 2, -1, buf, buf_size, 1088 &val_str.dec_exp); 1089 1090 /* 1091 * Round the extra digit to produce precision+1 significant digits. 1092 * If less than precision+2 significant digits were returned the last 1093 * digit is definitely inaccurate so also round to get rid of it. 1094 */ 1095 fp_round_up(buf, &val_str.len, &val_str.dec_exp); 1096 1097 /* Rounding could have introduced trailing zeros. */ 1098 if (flags & __PRINTF_FLAG_NOFRACZEROS) { 1099 fp_trim_trailing_zeros(buf, &val_str.len, &val_str.dec_exp); 1100 } 1101 } else { 1102 /* Let the implementation figure out the proper precision. */ 1103 val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp); 1104 1105 /* Use all produced digits. */ 1106 precision = val_str.len - 1; 1107 } 1108 1109 return print_double_str_scient(&val_str, precision, width, flags, ps); 1110 } 1111 1112 1113 /** Convert, format and print a double according to the %g specifier. 1114 * 1115 * %g style chooses between %f and %e. 1116 * 1117 * @param g Double to print. 1118 * @param precision Number of significant digits to display; excluding 1119 * any leading zeros from this count. If negative 1120 * the shortest accurate number will be printed. 1121 * @param width Minimum number of characters to display. Pads 1122 * with '0' or ' ' depending on the set flags; 1123 * @param flags Printf flags. 1124 * @param ps Printing functions. 1125 * 1126 * @return The number of characters printed; negative on failure. 1127 */ 1128 static int print_double_generic(double g, int precision, int width, 1129 uint32_t flags, printf_spec_t *ps) 1130 { 1131 ieee_double_t val = extract_ieee_double(g); 1132 1133 if (val.is_special) { 1134 return print_special(val, width, flags, ps); 1135 } 1136 1137 char buf[MAX_DOUBLE_STR_BUF_SIZE]; 1138 const size_t buf_size = MAX_DOUBLE_STR_BUF_SIZE; 1139 int dec_exp; 1140 int len; 1141 1142 /* Honor the user requested number of significant digits. */ 1143 if (0 <= precision) { 1144 /* 1145 * Do a quick and dirty conversion of a single digit to determine 1146 * the decimal exponent. 1147 */ 1148 len = double_to_fixed_str(val, 1, -1, buf, buf_size, &dec_exp); 1149 assert(0 < len); 1150 1151 precision = max(1, precision); 1152 1153 if (-4 <= dec_exp && dec_exp < precision) { 1154 precision = precision - (dec_exp + 1); 1155 return print_double_fixed(g, precision, width, 1156 flags | __PRINTF_FLAG_NOFRACZEROS, ps); 1157 } else { 1158 --precision; 1159 return print_double_scientific(g, precision, width, 1160 flags | __PRINTF_FLAG_NOFRACZEROS, ps); 1161 } 1162 } else { 1163 /* Convert to get the decimal exponent and digit count.*/ 1164 len = double_to_short_str(val, buf, buf_size, &dec_exp); 1165 assert(0 < len); 1166 1167 if (flags & __PRINTF_FLAG_LEFTALIGNED) { 1168 flags &= ~__PRINTF_FLAG_ZEROPADDED; 1169 } 1170 1171 double_str_t val_str; 1172 val_str.str = buf; 1173 val_str.len = len; 1174 val_str.neg = val.is_negative; 1175 val_str.dec_exp = dec_exp; 1176 1177 int first_digit_pos = len + dec_exp; 1178 int last_digit_pos = dec_exp; 1179 1180 /* The whole number (15 digits max) fits between dec places 15 .. -6 */ 1181 if (len <= 15 && -6 <= last_digit_pos && first_digit_pos <= 15) { 1182 /* Precision needed for the last significant digit. */ 1183 precision = max(0, -val_str.dec_exp); 1184 return print_double_str_fixed(&val_str, precision, width, flags, ps); 1185 } else { 1186 /* Use all produced digits. */ 1187 precision = val_str.len - 1; 1188 return print_double_str_scient(&val_str, precision, width, flags, ps); 1189 } 1190 } 1191 } 1192 1193 1194 /** Convert, format and print a double according to the specifier. 1195 * 1196 * Depending on the specifier it prints the double using the styles 1197 * %g, %f or %e by means of print_double_generic(), print_double_fixed(), 1198 * print_double_scientific(). 1199 * 1200 * @param g Double to print. 1201 * @param spec Specifier of the style to print in; one of: 'g','G','f','F', 1202 * 'e','E'. 1203 * @param precision Number of fractional digits to display. If negative 1204 * the shortest accurate number will be printed for style %g; 1205 * negative precision defaults to 6 for styles %f, %e. 1206 * @param width Minimum number of characters to display. Pads 1207 * with '0' or ' ' depending on the set flags; 1208 * @param flags Printf flags. 1209 * @param ps Printing functions. 1210 * 1211 * @return The number of characters printed; negative on failure. 1212 */ 1213 static int print_double(double g, char spec, int precision, int width, 1214 uint32_t flags, printf_spec_t *ps) 1215 { 1216 switch (spec) { 1217 case 'F': 1218 flags |= __PRINTF_FLAG_BIGCHARS; 1219 /* Fall through.*/ 1220 case 'f': 1221 precision = (precision < 0) ? 6 : precision; 1222 return print_double_fixed(g, precision, width, flags, ps); 1223 1224 case 'E': 1225 flags |= __PRINTF_FLAG_BIGCHARS; 1226 /* Fall through.*/ 1227 case 'e': 1228 precision = (precision < 0) ? 6 : precision; 1229 return print_double_scientific(g, precision, width, flags, ps); 1230 1231 case 'G': 1232 flags |= __PRINTF_FLAG_BIGCHARS; 1233 /* Fall through.*/ 1234 case 'g': 1235 return print_double_generic(g, precision, width, flags, ps); 1236 1237 default: 1238 assert(false); 1239 return -1; 1240 } 527 1241 } 528 1242 … … 656 1370 case '#': 657 1371 flags |= __PRINTF_FLAG_PREFIX; 1372 flags |= __PRINTF_FLAG_DECIMALPT; 658 1373 break; 659 1374 case '-': … … 701 1416 702 1417 /* Precision and '*' operator */ 703 int precision = 0;1418 int precision = -1; 704 1419 if (uc == '.') { 705 1420 i = nxt; 706 1421 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 707 1422 if (isdigit(uc)) { 1423 precision = 0; 708 1424 while (true) { 709 1425 precision *= 10; … … 723 1439 precision = (int) va_arg(ap, int); 724 1440 if (precision < 0) { 725 /* Ignore negative precision */726 precision = 0;1441 /* Ignore negative precision - use default instead */ 1442 precision = -1; 727 1443 } 728 1444 } … … 774 1490 */ 775 1491 case 's': 1492 precision = max(0, precision); 1493 776 1494 if (qualifier == PrintfQualifierLong) 777 1495 retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps); … … 797 1515 goto out; 798 1516 }; 1517 1518 counter += retval; 1519 j = nxt; 1520 goto next_char; 1521 1522 /* 1523 * Floating point values 1524 */ 1525 case 'G': 1526 case 'g': 1527 case 'F': 1528 case 'f': 1529 case 'E': 1530 case 'e': 1531 retval = print_double(va_arg(ap, double), uc, precision, 1532 width, flags, ps); 1533 1534 if (retval < 0) { 1535 counter = -counter; 1536 goto out; 1537 } 799 1538 800 1539 counter += retval; -
uspace/lib/c/generic/pio_trace.c
r150a2718 r8f88beb7 91 91 92 92 93 void pio_trace_log( volatile void *r, uint32_t val, bool write)93 void pio_trace_log(const volatile void *r, uint32_t val, bool write) 94 94 { 95 95 pio_regions_t *regions = get_regions(); -
uspace/lib/c/generic/stack.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 201 1 Martin Sucha2 * Copyright (c) 2012 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup fs29 /** @addtogroup libc 30 30 * @{ 31 */ 31 */ 32 /** @file 33 */ 32 34 33 #i fndef EXT2FS_EXT2FS_H_34 # define EXT2FS_EXT2FS_H_35 #include <stack.h> 36 #include <sysinfo.h> 35 37 36 #include <libext2.h> 37 #include <libfs.h> 38 #include <sys/types.h> 38 size_t stack_size_get(void) 39 { 40 static sysarg_t stack_size = 0; 39 41 40 #define min(a, b) ((a) < (b) ? (a) : (b)) 42 if (!stack_size) 43 sysinfo_get_value("default.stack_size", &stack_size); 41 44 42 extern vfs_out_ops_t ext2fs_ops;43 extern libfs_ops_t ext2fs_libfs_ops; 45 return (size_t) stack_size; 46 } 44 47 45 extern int ext2fs_global_init(void); 46 extern int ext2fs_global_fini(void); 47 48 #endif 49 50 /** 51 * @} 48 /** @} 52 49 */ -
uspace/lib/c/generic/thread.c
r150a2718 r8f88beb7 39 39 #include <abi/proc/uarg.h> 40 40 #include <fibril.h> 41 #include <stack.h> 41 42 #include <str.h> 42 43 #include <async.h> … … 44 45 #include <as.h> 45 46 #include "private/thread.h" 46 47 #ifndef THREAD_INITIAL_STACK_PAGES48 #define THREAD_INITIAL_STACK_PAGES 249 #endif50 47 51 48 /** Main thread function. … … 101 98 return ENOMEM; 102 99 103 size_t stack_size = getpagesize() * THREAD_INITIAL_STACK_PAGES;100 size_t stack_size = stack_size_get(); 104 101 void *stack = as_area_create(AS_AREA_ANY, stack_size, 105 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 102 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD | 103 AS_AREA_LATE_RESERVE); 106 104 if (stack == AS_MAP_FAILED) { 107 105 free(uarg); -
uspace/lib/c/include/ddi.h
r150a2718 r8f88beb7 54 54 extern int pio_enable(void *, size_t, void **); 55 55 56 typedef void (*trace_fnc)( volatile void *place, uint32_t val,56 typedef void (*trace_fnc)(const volatile void *place, uint32_t val, 57 57 volatile void* base, size_t size, void *data, bool write); 58 58 59 59 extern int pio_trace_enable(void *, size_t, trace_fnc, void *); 60 extern void pio_trace_log( volatile void *, uint32_t val, bool write);60 extern void pio_trace_log(const volatile void *, uint32_t val, bool write); 61 61 extern void pio_trace_disable(void *); 62 62 … … 65 65 extern void pio_write_32(ioport32_t *, uint32_t); 66 66 67 extern uint8_t pio_read_8( ioport8_t *);68 extern uint16_t pio_read_16( ioport16_t *);69 extern uint32_t pio_read_32( ioport32_t *);67 extern uint8_t pio_read_8(const ioport8_t *); 68 extern uint16_t pio_read_16(const ioport16_t *); 69 extern uint32_t pio_read_32(const ioport32_t *); 70 70 71 71 static inline uint8_t pio_change_8( -
uspace/lib/c/include/double_to_str.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2006 Martin Decky 3 * Copyright (c) 2011 Martin Sucha 2 * Copyright (c) 2012 Adam Hraska 4 3 * All rights reserved. 5 4 * … … 28 27 */ 29 28 30 /** @addtogroup fs 31 * @{ 32 */ 29 #ifndef DOUBLE_TO_STR_H_ 30 #define DOUBLE_TO_STR_H_ 33 31 34 /** 35 * @file ext2.c 36 * @brief EXT2 file system driver for HelenOS. 32 #include <unistd.h> 33 34 /** Maximum number of digits double_to_*_str conversion functions produce. 35 * 36 * Both double_to_short_str and double_to_fixed_str generate digits out 37 * of a 64bit unsigned int number representation. The max number of 38 * of digits is therefore 20. Add 1 to help users who forget to reserve 39 * space for a null terminator. 37 40 */ 41 #define MAX_DOUBLE_STR_LEN (20 + 1) 38 42 39 #include "ext2fs.h" 40 #include <ipc/services.h> 41 #include <ns.h> 42 #include <async.h> 43 #include <errno.h> 44 #include <unistd.h> 45 #include <task.h> 46 #include <stdio.h> 47 #include <libfs.h> 48 #include "../../vfs/vfs.h" 43 /** Maximum buffer size needed to store the output of double_to_*_str 44 * functions. 45 */ 46 #define MAX_DOUBLE_STR_BUF_SIZE 21 49 47 50 #define NAME "ext2fs" 48 /* Fwd decl.*/ 49 struct ieee_double_t_tag; 51 50 52 vfs_info_t ext2fs_vfs_info = { 53 .name = NAME, 54 .instance = 0, 55 }; 51 extern int double_to_short_str(struct ieee_double_t_tag, char *, size_t, int *); 52 extern int double_to_fixed_str(struct ieee_double_t_tag, int, int, char *, 53 size_t, int *); 56 54 57 int main(int argc, char **argv) 58 { 59 printf(NAME ": HelenOS EXT2 file system server\n"); 60 61 if (argc == 3) { 62 if (!str_cmp(argv[1], "--instance")) 63 ext2fs_vfs_info.instance = strtol(argv[2], NULL, 10); 64 else { 65 printf(NAME " Unrecognized parameters"); 66 return -1; 67 } 68 } 69 70 async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE, 71 SERVICE_VFS, 0, 0); 72 if (!vfs_sess) { 73 printf(NAME ": failed to connect to VFS\n"); 74 return -1; 75 } 76 77 int rc = ext2fs_global_init(); 78 if (rc != EOK) { 79 printf(NAME ": Failed global initialization\n"); 80 return 1; 81 } 82 83 rc = fs_register(vfs_sess, &ext2fs_vfs_info, &ext2fs_ops, 84 &ext2fs_libfs_ops); 85 if (rc != EOK) { 86 fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc); 87 return 1; 88 } 89 90 printf(NAME ": Accepting connections\n"); 91 task_retval(0); 92 async_manager(); 93 /* not reached */ 94 return 0; 95 } 96 97 /** 98 * @} 99 */ 55 #endif -
uspace/lib/c/include/macros.h
r150a2718 r8f88beb7 38 38 #define min(a, b) ((a) < (b) ? (a) : (b)) 39 39 #define max(a, b) ((a) > (b) ? (a) : (b)) 40 #define abs(a) ((a) >= 0 ? (a) : (-a)) 41 40 42 41 43 #define KiB2SIZE(kb) ((kb) << 10) -
uspace/lib/c/include/stack.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 201 1 Martin Sucha2 * Copyright (c) 2012 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup lib ext229 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 /** 33 * @file 32 /** @file 34 33 */ 35 34 36 #ifndef LIB EXT2_LIBEXT2_H_37 #define LIB EXT2_LIBEXT2_H_35 #ifndef LIBC_STACK_H_ 36 #define LIBC_STACK_H_ 38 37 39 #include "libext2_superblock.h" 40 #include "libext2_block_group.h" 41 #include "libext2_inode.h" 42 #include "libext2_filesystem.h" 43 #include "libext2_directory.h" 38 #include <libarch/types.h> 39 40 extern size_t stack_size_get(void); 44 41 45 42 #endif -
uspace/lib/clui/tinput.c
r150a2718 r8f88beb7 104 104 static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad) 105 105 { 106 wchar_t dbuf[INPUT_MAX_SIZE + 1]; 106 wchar_t *dbuf = malloc((INPUT_MAX_SIZE + 1) * sizeof(wchar_t)); 107 if (!dbuf) 108 return; 107 109 108 110 size_t sa; … … 146 148 147 149 console_flush(ti->console); 150 151 free(dbuf); 148 152 } 149 153 -
uspace/lib/ext4/libext4_block_group.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_block_group.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_directory.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_directory.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_filesystem.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_filesystem.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_inode.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_inode.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_superblock.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_superblock.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/ext4/libext4_types.h
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/lib/softfloat/common.c
r150a2718 r8f88beb7 39 39 /* Table for fast leading zeroes counting. */ 40 40 char zeroTable[256] = { 41 8, 7, 7, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, \41 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, \ 42 42 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ 43 43 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ … … 307 307 /** 308 308 * Round and normalize number expressed by exponent and fraction with 309 * first bit (equal to hidden bit) at 62nd bit.309 * first bit (equal to hidden bit) at bit 62. 310 310 * 311 311 * @param exp Exponent part. 312 * @param fraction Fraction with hidden bit shifted to 62nd bit.312 * @param fraction Fraction with hidden bit shifted to bit 62. 313 313 */ 314 314 void round_float64(int32_t *exp, uint64_t *fraction) 315 315 { 316 /* rounding - if first bit after fraction is set then round up */ 316 /* 317 * Rounding - if first bit after fraction is set then round up. 318 */ 319 320 /* 321 * Add 1 to the least significant bit of the fraction respecting the 322 * current shift to bit 62 and see if there will be a carry to bit 63. 323 */ 317 324 (*fraction) += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 318 325 326 /* See if there was a carry to bit 63. */ 319 327 if ((*fraction) & 320 (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 3))) {328 (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1))) { 321 329 /* rounding overflow */ 322 330 ++(*exp); -
uspace/srv/fs/ext4fs/ext4fs_ops.c
r150a2718 r8f88beb7 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. -
uspace/srv/logger/initlvl.c
r150a2718 r8f88beb7 38 38 #include <sysinfo.h> 39 39 #include <str.h> 40 #include <stdlib.h> 40 41 #include "logger.h" 41 42 … … 91 92 char level_str[200]; 92 93 str_cpy(level_str, 200, (const char *) argument); 94 free(argument); 93 95 94 96 parse_level_settings(level_str);
Note:
See TracChangeset
for help on using the changeset viewer.
