Changeset 8f88beb7 in mainline for uspace


Ignore:
Timestamp:
2012-11-25T21:34:07Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
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.
Message:

Merge mainline changes

Location:
uspace
Files:
13 added
16 deleted
46 edited
4 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    r150a2718 r8f88beb7  
    4040        app/devctl \
    4141        app/edit \
    42         app/ext2info \
    4342        app/getterm \
    4443        app/init \
     
    105104        srv/fs/mfs \
    106105        srv/fs/locfs \
    107         srv/fs/ext2fs \
    108106        srv/fs/ext4fs \
    109107        srv/hid/compositor \
     
    218216        lib/net \
    219217        lib/nic \
    220         lib/ext2 \
    221218        lib/ext4 \
    222219        lib/usb \
  • uspace/Makefile.common

    r150a2718 r8f88beb7  
    118118LIBGUI_PREFIX = $(LIB_PREFIX)/gui
    119119
    120 LIBEXT2_PREFIX = $(LIB_PREFIX)/ext2
    121120LIBEXT4_PREFIX = $(LIB_PREFIX)/ext4
    122121
  • uspace/app/bdsh/config.h

    r150a2718 r8f88beb7  
    5555#define PACKAGE_STRING "The brain dead shell"
    5656#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  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS = $(LIBEXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
    32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)
    3333BINARY = tester
    3434
     
    4242        print/print4.c \
    4343        print/print5.c \
     44        print/print6.c \
    4445        console/console1.c \
    4546        stdio/stdio1.c \
     
    6263        mm/mapping1.c \
    6364        hw/misc/virtchar1.c \
    64         hw/serial/serial1.c \
    65         ext2/ext2_1.c
     65        hw/serial/serial1.c
    6666
    6767include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/float/softfloat1.c

    r150a2718 r8f88beb7  
    3434#include <mul.h>
    3535#include <div.h>
     36#include <comparison.h>
     37#include <conversion.h>
    3638#include <bool.h>
    3739#include "../tester.h"
    3840
    39 #define OPERANDS  6
     41#define OPERANDS  10
    4042#define PRECISION  10000
    4143
     
    4345
    4446typedef 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
     48typedef void (* uint_to_double_op_t)(unsigned int, double *, double_t *);
     49typedef void (* double_to_uint_op_t)(double, unsigned int *, unsigned int *);
     50typedef void (* float_binary_op_t)(float, float, float *, float_t *);
     51typedef void (* double_binary_op_t)(double, double, double *, double_t *);
     52typedef void (* double_cmp_op_t)(double, double, cmptype_t *, cmptype_t *);
     53
     54typedef void (* template_unary_t)(void *, unsigned, cmptype_t *, cmptype_t *);
     55typedef void (* template_binary_t)(void *, unsigned, unsigned, cmptype_t *,
    4856    cmptype_t *);
    4957
    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
     61static float fop_a[OPERANDS] = {
     62        NUMBERS
     63};
     64
     65static double dop_a[OPERANDS] = {
     66        NUMBERS
     67};
     68
     69static unsigned int uop_a[OPERANDS] = {
     70        4, -100, 100, 50, 1024, 0, 1000000, -1U, 0x80000000U, 500
     71};
    6172
    6273static cmptype_t cmpabs(cmptype_t a)
     
    6879}
    6980
    70 static void
    71 float_template(void *f, unsigned i, unsigned j, cmptype_t *pic,
     81static 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
     91static void
     92uint_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
     105static void
     106double_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
     120static void
     121float_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic,
    72122    cmptype_t *pisc)
    73123{
     
    75125        float_t sc;
    76126
    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);
    80130
    81131        *pic = (cmptype_t) (c * PRECISION);
     
    84134
    85135static void
    86 double_template(void *f, unsigned i, unsigned j, cmptype_t *pic,
     136double_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic,
    87137    cmptype_t *pisc)
    88138{
     
    90140        double_t sc;
    91141
    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);
    95145
    96146        *pic = (cmptype_t) (c * PRECISION);
     
    98148}
    99149
    100 static bool test_template(template_t template, void *f)
     150static void
     151double_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
     159static 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
     179static bool test_template_binary(template_binary_t template, void *f)
    101180{
    102181        bool correct = true;
     
    121200}
    122201
     202static 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
     208static void
     209double_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
     219static void
     220double_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
    123230static void float_add_operator(float a, float b, float *pc, float_t *psc)
    124231{
     
    221328}
    222329
     330static void
     331double_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
    223351const char *test_softfloat1(void)
    224352{
    225353        const char *err = NULL;
    226354
    227         if (!test_template(float_template, float_add_operator)) {
     355        if (!test_template_binary(float_template_binary, float_add_operator)) {
    228356                err = "Float addition failed";
    229357                TPRINTF("%s\n", err);
    230358        }
    231         if (!test_template(float_template, float_mul_operator)) {
     359        if (!test_template_binary(float_template_binary, float_mul_operator)) {
    232360                err = "Float multiplication failed";
    233361                TPRINTF("%s\n", err);
    234362        }
    235         if (!test_template(float_template, float_div_operator)) {
     363        if (!test_template_binary(float_template_binary, float_div_operator)) {
    236364                err = "Float division failed";
    237365                TPRINTF("%s\n", err);
    238366        }
    239         if (!test_template(double_template, double_add_operator)) {
     367        if (!test_template_binary(double_template_binary, double_add_operator)) {
    240368                err = "Double addition failed";
    241369                TPRINTF("%s\n", err);
    242370        }
    243         if (!test_template(double_template, double_mul_operator)) {
     371        if (!test_template_binary(double_template_binary, double_mul_operator)) {
    244372                err = "Double multiplication failed";
    245373                TPRINTF("%s\n", err);
    246374        }
    247         if (!test_template(double_template, double_div_operator)) {
     375        if (!test_template_binary(double_template_binary, double_div_operator)) {
    248376                err = "Double division failed";
    249377                TPRINTF("%s\n", err);
    250378        }
     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        }
    251398       
    252399        return err;
  • uspace/app/tester/print/print5.def

    r150a2718 r8f88beb7  
    11{
    2         "print1",
    3         "String printf test",
    4         &test_print1,
     2        "print5",
     3        "Char printf test",
     4        &test_print5,
    55        true
    66},
  • uspace/app/tester/tester.c

    r150a2718 r8f88beb7  
    5353#include "print/print4.def"
    5454#include "print/print5.def"
     55#include "print/print6.def"
    5556#include "console/console1.def"
    5657#include "stdio/stdio1.def"
     
    7374#include "hw/serial/serial1.def"
    7475#include "hw/misc/virtchar1.def"
    75 #include "ext2/ext2_1.def"
    7676        {NULL, NULL, NULL, false}
    7777};
  • uspace/app/tester/tester.h

    r150a2718 r8f88beb7  
    8585extern const char *test_print4(void);
    8686extern const char *test_print5(void);
     87extern const char *test_print6(void);
    8788extern const char *test_console1(void);
    8889extern const char *test_stdio1(void);
     
    105106extern const char *test_serial1(void);
    106107extern const char *test_virtchar1(void);
    107 extern const char *test_ext2_1(void);
    108108extern const char *test_devman1(void);
    109109extern const char *test_devman2(void);
  • uspace/drv/infrastructure/rootamdm37x/Makefile

    r150a2718 r8f88beb7  
    3333
    3434SOURCES = \
     35        amdm37x.c \
    3536        rootamdm37x.c
    3637
  • uspace/drv/infrastructure/rootamdm37x/amdm37x.h

    r150a2718 r8f88beb7  
    11/*
    2  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Jan Vesely
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libext2
     29/** @addtogroup amdm37xdrv
    3030 * @{
    3131 */
    32 /**
    33  * @file
     32/** @file
     33 * @brief AM/DM 37x device.
    3434 */
     35#ifndef AMDM37x_H
     36#define AMDM37x_H
    3537
    36 #ifndef LIBEXT2_LIBEXT2_BLOCK_GROUP_H_
    37 #define LIBEXT2_LIBEXT2_BLOCK_GROUP_H_
     38#include "uhh.h"
     39#include "usbtll.h"
    3840
    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"
    4046
    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"
    4949
    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>
    5451
    55 #define EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE 32
     52typedef 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;
    5667
    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);
     68int amdm37x_init(amdm37x_t *device, bool trace_io);
     69int amdm37x_usb_tll_init(amdm37x_t *device);
     70void amdm37x_setup_dpll_on_autoidle(amdm37x_t *device);
     71void amdm37x_usb_clocks_set(amdm37x_t *device, bool enabled);
    6572
    6673#endif
    67 
    68 /** @}
     74/**
     75 * @}
    6976 */
  • uspace/drv/infrastructure/rootamdm37x/cm/clock_control.h

    r150a2718 r8f88beb7  
    6767
    6868        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)
    7474
    7575        PADD32[6];
     
    114114        ioport32_t clksel1_pll;
    115115#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)
    117118#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)
    119121#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)
    121124#define CLOCK_CONTROL_CM_CLKSEL1_PLL_SOURCE_96M_FLAG   (1 << 6)
    122125#define CLOCK_CONTROL_CM_CLKSEL1_PLL_SOURCE_54M_FLAG   (1 << 5)
     
    140143        ioport32_t clksel4_pll;
    141144#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)
    143147#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)
    145150
    146151        ioport32_t clksel5_pll;
    147152#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)
    149155} clock_control_cm_regs_t;
    150156
  • uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c

    r150a2718 r8f88beb7  
    3535/** @file
    3636 */
    37 #define _DDF_DATA_IMPLANT
    38 
    39 #define DEBUG_CM
    40 
    41 #include <ddf/driver.h>
     37
     38#define DEBUG_CM 0
     39
    4240#include <ddf/log.h>
    4341#include <errno.h>
    4442#include <ops/hw_res.h>
    4543#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"
    5346
    5447#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_CM
    67 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 #endif
    73 
    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_CM
    105         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 #endif
    111         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_CM
    133         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 #endif
    137 
    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_CM
    152         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 #endif
    156         } 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 is
    211                  * one of bidirectional modes might be good choice
    212                  * 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 }
    22148
    22249typedef struct {
     
    22451} rootamdm37x_fun_t;
    22552
     53/* See amdm37x TRM page. 3316 for these values */
    22654#define OHCI_BASE_ADDRESS  0x48064400
    22755#define OHCI_SIZE  1024
     
    23260        {
    23361                .type = MEM_RANGE,
    234                 /* See amdm37x TRM page. 3316 for these values */
    23562                .res.io_range = {
    23663                        .address = OHCI_BASE_ADDRESS,
     
    24370                .res.interrupt = { .irq = 76 },
    24471        },
    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         }
    25272};
    25373
     
    26888};
    26989
     90static const rootamdm37x_fun_t ohci = {
     91        .hw_resources = {
     92            .resources = ohci_res,
     93            .count = sizeof(ohci_res)/sizeof(ohci_res[0]),
     94        }
     95};
     96
    27097static const rootamdm37x_fun_t ehci = {
    27198        .hw_resources = {
     
    283110};
    284111
    285 static ddf_dev_ops_t rootamdm37x_fun_ops =
    286 {
     112static ddf_dev_ops_t rootamdm37x_fun_ops = {
    287113        .interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops
    288114};
    289115
    290 static bool rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
     116static int rootamdm37x_add_fun(ddf_dev_t *dev, const char *name,
    291117    const char *str_match_id, const rootamdm37x_fun_t *fun)
    292118{
     
    298124                return ENOMEM;
    299125       
    300        
    301126        /* 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) {
    303129                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
    307142        /* Set provided operations to the device. */
    308         ddf_fun_data_implant(fnode, (void*)fun);
    309143        ddf_fun_set_ops(fnode, &rootamdm37x_fun_ops);
    310144       
    311145        /* Register function. */
    312         if (ddf_fun_bind(fnode) != EOK) {
     146        ret = ddf_fun_bind(fnode);
     147        if (ret != EOK) {
    313148                ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
    314                 // TODO This will try to free our data!
    315149                ddf_fun_destroy(fnode);
    316                 return false;
    317         }
    318        
    319         return true;
     150                return ret;
     151        }
     152       
     153        return EOK;
    320154}
    321155
     
    334168        if (!device)
    335169                return ENOMEM;
    336         int ret = amdm37x_hw_access_init(device);
     170        int ret = amdm37x_init(device, DEBUG_CM);
    337171        if (ret != EOK) {
    338172                ddf_msg(LVL_FATAL, "Failed to setup hw access!.\n");
     
    340174        }
    341175
    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);
    349184        if (ret != EOK) {
    350185                ddf_msg(LVL_FATAL, "Failed to init USB TLL!.\n");
    351                 usb_clocks(device, false);
     186                amdm37x_usb_clocks_set(device, false);
    352187                return ret;
    353188        }
    354189
    355190        /* 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)
    357192                ddf_msg(LVL_ERROR, "Failed to add OHCI function for "
    358193                    "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)
    360195                ddf_msg(LVL_ERROR, "Failed to add EHCI function for "
    361196                    "BeagleBoard-xM platform.");
     
    375210};
    376211
    377 static hw_resource_list_t *rootamdm37x_get_resources(ddf_fun_t *fnode)
     212static hw_resource_list_t * rootamdm37x_get_resources(ddf_fun_t *fnode)
    378213{
    379214        rootamdm37x_fun_t *fun = ddf_fun_data_get(fnode);
     
    384219static bool rootamdm37x_enable_interrupt(ddf_fun_t *fun)
    385220{
    386         /* TODO */
     221        //TODO: Implement
    387222        return false;
    388223}
  • uspace/drv/infrastructure/rootamdm37x/usbtll.h

    r150a2718 r8f88beb7  
    5757#define TLL_SYSCONFIG_CLOCKACTIVITY_FLAG  (1 << 8)
    5858
    59         ioport32_t sysstatus;
     59        const ioport32_t sysstatus;
    6060#define TLL_SYSSTATUS_RESET_DONE_FLAG  (1 << 0)
    6161
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    r150a2718 r8f88beb7  
    9999static time_t uptime_get(void);
    100100static bool is_battery_ok(rtc_t *rtc);
     101static int  rtc_fun_online(ddf_fun_t *fun);
     102static int  rtc_fun_offline(ddf_fun_t *fun);
    101103
    102104static ddf_dev_ops_t rtc_dev_ops;
     
    106108        .dev_add = rtc_dev_add,
    107109        .dev_remove = rtc_dev_remove,
     110        .fun_online = rtc_fun_online,
     111        .fun_offline = rtc_fun_offline,
    108112};
    109113
     
    405409        /* Try to normalize the content of the tm structure */
    406410        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        }
    409419
    410420        fibril_mutex_unlock(&rtc->mutex);
    411421
    412         return r < 0 ? EINVAL : EOK;
     422        return result;
    413423}
    414424
     
    637647        fibril_mutex_unlock(&rtc->mutex);
    638648
     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
    639655        rc = ddf_fun_unbind(rtc->fun);
    640656        if (rc != EOK) {
     
    725741}
    726742
     743static int
     744rtc_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
     757static int
     758rtc_fun_offline(ddf_fun_t *fun)
     759{
     760        ddf_msg(LVL_DEBUG, "rtc_fun_offline()");
     761        return ddf_fun_offline(fun);
     762}
     763
    727764int
    728765main(int argc, char **argv)
  • uspace/lib/c/Makefile

    r150a2718 r8f88beb7  
    7777        generic/device/pci.c \
    7878        generic/device/ahci.c \
     79        generic/dlfcn.c \
    7980        generic/elf/elf_load.c \
    8081        generic/event.c \
     
    115116        generic/iplink.c \
    116117        generic/iplink_srv.c \
     118        generic/ieee_double.c \
     119        generic/power_of_ten.c \
     120        generic/double_to_str.c \
    117121        generic/malloc.c \
    118122        generic/sysinfo.c \
     
    136140        generic/net/socket_client.c \
    137141        generic/net/socket_parse.c \
     142        generic/stack.c \
    138143        generic/stacktrace.c \
    139144        generic/arg_parse.c \
     
    145150ifeq ($(CONFIG_RTLD),y)
    146151        GENERIC_SOURCES += \
    147                 generic/dlfcn.c \
    148152                generic/rtld/rtld.c \
    149153                generic/rtld/dynamic.c \
  • uspace/lib/c/arch/abs32le/include/ddi.h

    r150a2718 r8f88beb7  
    5151}
    5252
    53 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     53static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    5454{
    5555        return *port;
    5656}
    5757
    58 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     58static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    5959{
    6060        return *port;
    6161}
    6262
    63 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     63static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    6464{
    6565        return *port;
  • uspace/lib/c/arch/arm32/include/ddi.h

    r150a2718 r8f88beb7  
    5252}
    5353
    54 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     54static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    5555{
    5656        return *port;
    5757}
    5858
    59 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     59static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    6060{
    6161        return *port;
    6262}
    6363
    64 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     64static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    6565{
    6666        return *port;
  • uspace/lib/c/arch/ia32/include/ddi.h

    r150a2718 r8f88beb7  
    3939#define IO_SPACE_BOUNDARY  ((void *) (64 * 1024))
    4040
    41 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     41static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    4242{
    4343        if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
     
    5555}
    5656
    57 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     57static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    5858{
    5959        if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
     
    7171}
    7272
    73 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     73static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    7474{
    7575        if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
  • uspace/lib/c/arch/ia64/include/ddi.h

    r150a2718 r8f88beb7  
    9595}
    9696
    97 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     97static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    9898{
    9999        uint8_t v;
     
    115115}
    116116
    117 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     117static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    118118{
    119119        uint16_t v;
     
    135135}
    136136
    137 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     137static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    138138{
    139139        uint32_t v;
  • uspace/lib/c/arch/mips32/include/ddi.h

    r150a2718 r8f88beb7  
    5252}
    5353
    54 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     54static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    5555{
    5656        return *port;
    5757}
    5858
    59 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     59static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    6060{
    6161        return *port;
    6262}
    6363
    64 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     64static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    6565{
    6666        return *port;
  • uspace/lib/c/arch/mips64/include/ddi.h

    r150a2718 r8f88beb7  
    5252}
    5353
    54 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     54static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    5555{
    5656        return *port;
    5757}
    5858
    59 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     59static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    6060{
    6161        return *port;
    6262}
    6363
    64 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     64static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    6565{
    6666        return *port;
  • uspace/lib/c/arch/ppc32/include/ddi.h

    r150a2718 r8f88beb7  
    5252}
    5353
    54 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     54static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    5555{
    5656        return *port;
    5757}
    5858
    59 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     59static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    6060{
    6161        return *port;
    6262}
    6363
    64 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     64static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    6565{
    6666        return *port;
  • uspace/lib/c/arch/sparc64/include/ddi.h

    r150a2718 r8f88beb7  
    6363}
    6464
    65 static inline uint8_t arch_pio_read_8(ioport8_t *port)
     65static inline uint8_t arch_pio_read_8(const ioport8_t *port)
    6666{
    6767        uint8_t rv;
     
    7373}
    7474
    75 static inline uint16_t arch_pio_read_16(ioport16_t *port)
     75static inline uint16_t arch_pio_read_16(const ioport16_t *port)
    7676{
    7777        uint16_t rv;
     
    8383}
    8484
    85 static inline uint32_t arch_pio_read_32(ioport32_t *port)
     85static inline uint32_t arch_pio_read_32(const ioport32_t *port)
    8686{
    8787        uint32_t rv;
  • uspace/lib/c/generic/ddi.c

    r150a2718 r8f88beb7  
    192192}
    193193
    194 uint8_t pio_read_8(ioport8_t *reg)
     194uint8_t pio_read_8(const ioport8_t *reg)
    195195{
    196196        const uint8_t val = arch_pio_read_8(reg);
     
    199199}
    200200
    201 uint16_t pio_read_16(ioport16_t *reg)
     201uint16_t pio_read_16(const ioport16_t *reg)
    202202{
    203203        const uint16_t val = arch_pio_read_16(reg);
     
    206206}
    207207
    208 uint32_t pio_read_32(ioport32_t *reg)
     208uint32_t pio_read_32(const ioport32_t *reg)
    209209{
    210210        const uint32_t val = arch_pio_read_32(reg);
  • uspace/lib/c/generic/dlfcn.c

    r150a2718 r8f88beb7  
    3838#include <stdlib.h>
    3939#include <dlfcn.h>
     40
     41#ifdef CONFIG_RTLD
    4042
    4143#include <rtld/module.h>
     
    8789}
    8890
     91#else /* CONFIG_RTLD not defined */
     92
     93void *dlopen(const char *path, int flag)
     94{
     95        return NULL;
     96}
     97
     98void *dlsym(void *mod, const char *sym_name)
     99{
     100        return NULL;
     101}
     102
     103#endif
     104
    89105/** @}
    90106 */
  • uspace/lib/c/generic/fibril.c

    r150a2718 r8f88beb7  
    3737#include <fibril.h>
    3838#include <thread.h>
     39#include <stack.h>
    3940#include <tls.h>
    4041#include <malloc.h>
     42#include <abi/mm/as.h>
     43#include <as.h>
    4144#include <unistd.h>
    4245#include <stdio.h>
     
    4649#include <assert.h>
    4750#include <async.h>
    48 
    49 #ifndef FIBRIL_INITIAL_STACK_PAGES_NO
    50         #define FIBRIL_INITIAL_STACK_PAGES_NO  1
    51 #endif
    5251
    5352/**
     
    195194                                         * stack member filled.
    196195                                         */
    197                                         free(stack);
     196                                        as_area_destroy(stack);
    198197                                }
    199198                                fibril_teardown(srcf->clean_after_me);
     
    269268                return 0;
    270269       
    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) {
    274275                fibril_teardown(fibril);
    275276                return 0;
     
    281282        context_save(&fibril->ctx);
    282283        context_set(&fibril->ctx, FADDR(fibril_main), fibril->stack,
    283             FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), fibril->tcb);
     284            stack_size, fibril->tcb);
    284285
    285286        return (fid_t) fibril;
     
    298299        fibril_t *fibril = (fibril_t *) fid;
    299300       
    300         free(fibril->stack);
     301        as_area_destroy(fibril->stack);
    301302        fibril_teardown(fibril);
    302303}
  • uspace/lib/c/generic/io/log.c

    r150a2718 r8f88beb7  
    239239
    240240        char *message_buffer = malloc(MESSAGE_BUFFER_SIZE);
    241         if (message_buffer == NULL) {
     241        if (message_buffer == NULL)
    242242                return;
    243         }
    244243
    245244        vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args);
    246245        logger_message(logger_session, ctx, level, message_buffer);
     246        free(message_buffer);
    247247}
    248248
  • uspace/lib/c/generic/io/printf_core.c

    r150a2718 r8f88beb7  
    4242#include <ctype.h>
    4343#include <str.h>
     44#include <double_to_str.h>
     45#include <ieee_double.h>
     46#include <assert.h>
     47#include <macros.h>
     48
    4449
    4550/** show prefixes 0x or 0 */
    4651#define __PRINTF_FLAG_PREFIX       0x00000001
    4752
     53/** show the decimal point even if no fractional digits present */
     54#define __PRINTF_FLAG_DECIMALPT    0x00000001
     55
    4856/** signed / unsigned number */
    4957#define __PRINTF_FLAG_SIGNED       0x00000002
     
    6674/** number has - sign */
    6775#define __PRINTF_FLAG_NEGATIVE     0x00000100
     76
     77/** don't print trailing zeros in the fractional part */
     78#define __PRINTF_FLAG_NOFRACZEROS  0x00000200
     79
    6880
    6981/**
     
    110122static const char invalch = U_SPECIAL;
    111123
     124
     125
     126/** Unformatted double number string representation. */
     127typedef 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. */
     141static 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. */
     155static 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
    112167/** Print one or more characters without adding newline.
    113168 *
     
    281336                return printf_putstr(nullstr, ps);
    282337       
    283         /* Print leading spaces. */
    284338        size_t strw = str_length(str);
     339
     340        /* Precision unspecified - print everything. */
    285341        if ((precision == 0) || (precision > strw))
    286342                precision = strw;
     
    329385                return printf_putstr(nullstr, ps);
    330386       
    331         /* Print leading spaces. */
    332387        size_t strw = wstr_length(str);
     388
     389        /* Precision not specified - print everything. */
    333390        if ((precision == 0) || (precision > strw))
    334391                precision = strw;
     
    377434    uint32_t flags, printf_spec_t *ps)
    378435{
     436        /* Precision not specified. */
     437        if (precision < 0) {
     438                precision = 0;
     439        }
     440       
    379441        const char *digits;
    380442        if (flags & __PRINTF_FLAG_BIGCHARS)
     
    525587       
    526588        return ((int) counter);
     589}
     590
     591/** Prints a special double (ie NaN, infinity) padded to width characters. */
     592static 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. */
     646static 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. */
     656static 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 */
     701static 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 */
     839static 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. */
     894static 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 */
     937static 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 */
     1061static 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 */
     1128static 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 */
     1213static 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        }
    5271241}
    5281242
     
    6561370                                case '#':
    6571371                                        flags |= __PRINTF_FLAG_PREFIX;
     1372                                        flags |= __PRINTF_FLAG_DECIMALPT;
    6581373                                        break;
    6591374                                case '-':
     
    7011416                       
    7021417                        /* Precision and '*' operator */
    703                         int precision = 0;
     1418                        int precision = -1;
    7041419                        if (uc == '.') {
    7051420                                i = nxt;
    7061421                                uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    7071422                                if (isdigit(uc)) {
     1423                                        precision = 0;
    7081424                                        while (true) {
    7091425                                                precision *= 10;
     
    7231439                                        precision = (int) va_arg(ap, int);
    7241440                                        if (precision < 0) {
    725                                                 /* Ignore negative precision */
    726                                                 precision = 0;
     1441                                                /* Ignore negative precision - use default instead */
     1442                                                precision = -1;
    7271443                                        }
    7281444                                }
     
    7741490                         */
    7751491                        case 's':
     1492                                precision = max(0,  precision);
     1493                               
    7761494                                if (qualifier == PrintfQualifierLong)
    7771495                                        retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps);
     
    7971515                                        goto out;
    7981516                                };
     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                                }
    7991538                               
    8001539                                counter += retval;
  • uspace/lib/c/generic/pio_trace.c

    r150a2718 r8f88beb7  
    9191
    9292
    93 void pio_trace_log(volatile void *r, uint32_t val, bool write)
     93void pio_trace_log(const volatile void *r, uint32_t val, bool write)
    9494{
    9595        pio_regions_t *regions = get_regions();
  • uspace/lib/c/generic/stack.c

    r150a2718 r8f88beb7  
    11/*
    2  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup fs
     29/** @addtogroup libc
    3030 * @{
    31  */
     31 */
     32/** @file
     33 */
    3234
    33 #ifndef EXT2FS_EXT2FS_H_
    34 #define EXT2FS_EXT2FS_H_
     35#include <stack.h>
     36#include <sysinfo.h>
    3537
    36 #include <libext2.h>
    37 #include <libfs.h>
    38 #include <sys/types.h>
     38size_t stack_size_get(void)
     39{
     40        static sysarg_t stack_size = 0;
    3941
    40 #define min(a, b)               ((a) < (b) ? (a) : (b))
     42        if (!stack_size)
     43                sysinfo_get_value("default.stack_size", &stack_size);
    4144
    42 extern vfs_out_ops_t ext2fs_ops;
    43 extern libfs_ops_t ext2fs_libfs_ops;
     45        return (size_t) stack_size;
     46}
    4447
    45 extern int ext2fs_global_init(void);
    46 extern int ext2fs_global_fini(void);
    47 
    48 #endif
    49 
    50 /**
    51  * @}
     48/** @}
    5249 */
  • uspace/lib/c/generic/thread.c

    r150a2718 r8f88beb7  
    3939#include <abi/proc/uarg.h>
    4040#include <fibril.h>
     41#include <stack.h>
    4142#include <str.h>
    4243#include <async.h>
     
    4445#include <as.h>
    4546#include "private/thread.h"
    46 
    47 #ifndef THREAD_INITIAL_STACK_PAGES
    48         #define THREAD_INITIAL_STACK_PAGES  2
    49 #endif
    5047
    5148/** Main thread function.
     
    10198                return ENOMEM;
    10299       
    103         size_t stack_size = getpagesize() * THREAD_INITIAL_STACK_PAGES;
     100        size_t stack_size = stack_size_get();
    104101        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);
    106104        if (stack == AS_MAP_FAILED) {
    107105                free(uarg);
  • uspace/lib/c/include/ddi.h

    r150a2718 r8f88beb7  
    5454extern int pio_enable(void *, size_t, void **);
    5555
    56 typedef void (*trace_fnc)(volatile void *place, uint32_t val,
     56typedef void (*trace_fnc)(const volatile void *place, uint32_t val,
    5757    volatile void* base, size_t size, void *data, bool write);
    5858
    5959extern int pio_trace_enable(void *, size_t, trace_fnc, void *);
    60 extern void pio_trace_log(volatile void *, uint32_t val, bool write);
     60extern void pio_trace_log(const volatile void *, uint32_t val, bool write);
    6161extern void pio_trace_disable(void *);
    6262
     
    6565extern void pio_write_32(ioport32_t *, uint32_t);
    6666
    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 *);
     67extern uint8_t pio_read_8(const ioport8_t *);
     68extern uint16_t pio_read_16(const ioport16_t *);
     69extern uint32_t pio_read_32(const ioport32_t *);
    7070
    7171static inline uint8_t pio_change_8(
  • uspace/lib/c/include/double_to_str.h

    r150a2718 r8f88beb7  
    11/*
    2  * Copyright (c) 2006 Martin Decky
    3  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Adam Hraska
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup fs
    31  * @{
    32  */
     29#ifndef DOUBLE_TO_STR_H_
     30#define DOUBLE_TO_STR_H_
    3331
    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.
    3740 */
     41#define MAX_DOUBLE_STR_LEN (20 + 1)
    3842
    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
    4947
    50 #define NAME    "ext2fs"
     48/* Fwd decl.*/
     49struct ieee_double_t_tag;
    5150
    52 vfs_info_t ext2fs_vfs_info = {
    53         .name = NAME,
    54         .instance = 0,
    55 };
     51extern int double_to_short_str(struct ieee_double_t_tag, char *, size_t, int *);
     52extern int double_to_fixed_str(struct ieee_double_t_tag, int, int, char *,
     53    size_t, int *);
    5654
    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  
    3838#define min(a, b)  ((a) < (b) ? (a) : (b))
    3939#define max(a, b)  ((a) > (b) ? (a) : (b))
     40#define abs(a)     ((a) >= 0 ? (a) : (-a))
     41
    4042
    4143#define KiB2SIZE(kb)  ((kb) << 10)
  • uspace/lib/c/include/stack.h

    r150a2718 r8f88beb7  
    11/*
    2  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libext2
     29/** @addtogroup libc
    3030 * @{
    3131 */
    32 /**
    33  * @file
     32/** @file
    3433 */
    3534
    36 #ifndef LIBEXT2_LIBEXT2_H_
    37 #define LIBEXT2_LIBEXT2_H_
     35#ifndef LIBC_STACK_H_
     36#define LIBC_STACK_H_
    3837
    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
     40extern size_t stack_size_get(void);
    4441
    4542#endif
  • uspace/lib/clui/tinput.c

    r150a2718 r8f88beb7  
    104104static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
    105105{
    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;
    107109       
    108110        size_t sa;
     
    146148       
    147149        console_flush(ti->console);
     150
     151        free(dbuf);
    148152}
    149153
  • uspace/lib/ext4/libext4_block_group.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_block_group.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_directory.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_directory.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_filesystem.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_filesystem.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_inode.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_inode.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_superblock.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_superblock.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/ext4/libext4_types.h

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/lib/softfloat/common.c

    r150a2718 r8f88beb7  
    3939/* Table for fast leading zeroes counting. */
    4040char 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, \
    4242        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    4343        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \
     
    307307/**
    308308 * 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.
    310310 *
    311311 * @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.
    313313 */
    314314void round_float64(int32_t *exp, uint64_t *fraction)
    315315{
    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         */
    317324        (*fraction) += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3));
    318325       
     326        /* See if there was a carry to bit 63. */
    319327        if ((*fraction) &
    320             (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 3))) {
     328            (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1))) {
    321329                /* rounding overflow */
    322330                ++(*exp);
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    r150a2718 r8f88beb7  
    11/*
     2 * Copyright (c) 2011 Martin Sucha
    23 * Copyright (c) 2012 Frantisek Princ
    34 * All rights reserved.
  • uspace/srv/logger/initlvl.c

    r150a2718 r8f88beb7  
    3838#include <sysinfo.h>
    3939#include <str.h>
     40#include <stdlib.h>
    4041#include "logger.h"
    4142
     
    9192        char level_str[200];
    9293        str_cpy(level_str, 200, (const char *) argument);
     94        free(argument);
    9395
    9496        parse_level_settings(level_str);
Note: See TracChangeset for help on using the changeset viewer.