Changeset 04803bf in mainline for uspace/app


Ignore:
Timestamp:
2011-03-21T22:00:17Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
143932e3
Parents:
b50b5af2 (diff), 7308e84 (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 (needs fixes).

Location:
uspace/app
Files:
149 added
3 deleted
79 edited
11 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/Makefile

    rb50b5af2 r04803bf  
    1 # Copyright (c) 2005,  Martin Decky
    2 # All rights reserved.
    3 # Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
     1#
     2# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    44# All rights reserved.
    55#
    66# Redistribution and use in source and binary forms, with or without
    7 # modification, are permitted provided that the following conditions are met:
     7# modification, are permitted provided that the following conditions
     8# are met:
    89#
    9 # Redistributions of source code must retain the above copyright notice, this
    10 # list of conditions and the following disclaimer.
     10# - Redistributions of source code must retain the above copyright
     11#   notice, this list of conditions and the following disclaimer.
     12# - Redistributions in binary form must reproduce the above copyright
     13#   notice, this list of conditions and the following disclaimer in the
     14#   documentation and/or other materials provided with the distribution.
     15# - The name of the author may not be used to endorse or promote products
     16#   derived from this software without specific prior written permission.
    1117#
    12 # Redistributions in binary form must reproduce the above copyright notice,
    13 # this list of conditions and the following disclaimer in the documentation
    14 # and/or other materials provided with the distribution.
     18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1528#
    16 # Neither the name of the original program's authors nor the names of its
    17 # contributors may be used to endorse or promote products derived from this
    18 # software without specific prior written permission.
    19 #
    20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    30 # POSSIBILITY OF SUCH DAMAGE.
    3129
    32 include ../../../version
    33 
    34 LIBC_PREFIX = ../../lib/libc
    35 SOFTINT_PREFIX = ../../lib/softint
    36 LIBBLOCK_PREFIX = ../../lib/libblock
    37 
    38 include $(LIBC_PREFIX)/Makefile.toolchain
    39 include $(LIBC_PREFIX)/Makefile.app
    40 
    41 CFLAGS += -I../../srv/kbd/include -I$(LIBBLOCK_PREFIX)
    42 
    43 LIBS += $(LIBBLOCK_PREFIX)/libblock.a $(LIBC_PREFIX)/libc.a
    44 DEFS += -DRELEASE=$(RELEASE)
    45 
    46 PROGRAM = bdsh
    47 
    48 # Any directory that cleaning targets should know about
    49 SUBDIRS = \
    50         ./ \
    51         cmds/ \
    52         cmds/modules/ \
    53         cmds/modules/help/ \
    54         cmds/modules/mkdir/ \
    55         cmds/modules/rm/ \
    56         cmds/modules/bdd/ \
    57         cmds/modules/cat/ \
    58         cmds/modules/touch/ \
    59         cmds/modules/ls/ \
    60         cmds/modules/pwd/ \
    61         cmds/modules/sleep/ \
    62         cmds/modules/cp/ \
    63         cmds/modules/mv/ \
    64         cmds/modules/mount/ \
    65         cmds/modules/kcon/ \
    66         cmds/builtins/ \
    67         cmds/builtins/exit/\
    68         cmds/builtins/cd/
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \
     33        -Icmds/builtins -Icmds/modules
     34BINARY = bdsh
    6935
    7036SOURCES = \
    7137        cmds/modules/help/help.c \
    7238        cmds/modules/mkdir/mkdir.c \
     39        cmds/modules/mkfile/mkfile.c \
    7340        cmds/modules/rm/rm.c \
    7441        cmds/modules/bdd/bdd.c \
     
    8148        cmds/modules/mv/mv.c \
    8249        cmds/modules/mount/mount.c \
     50        cmds/modules/unmount/unmount.c \
    8351        cmds/modules/kcon/kcon.c \
    8452        cmds/builtins/exit/exit.c \
     
    9260        scli.c
    9361
    94 CFLAGS += -I. -Icmds/ -Icmds/builtins -Icmds/modules
    95 
    96 OBJECTS = $(SOURCES:.c=.o)
    97 
    98 # For easy cleaning, *.o is already handled
    99 CLEANDIRS := $(addsuffix *~,$(SUBDIRS))
    100 CLEANDIRS += $(addsuffix *.bak,$(SUBDIRS))
    101 CLEANDIRS += $(addsuffix *.tmp,$(SUBDIRS))
    102 CLEANDIRS += $(addsuffix *.out,$(SUBDIRS))
    103 CLEANDIRS += $(addsuffix *.d,$(SUBDIRS))
    104 CLEANDIRS += $(addsuffix *.gch,$(SUBDIRS) )
    105 
    106 %.o: %.S
    107         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    108 
    109 %.o: %.s
    110         $(AS) $(AFLAGS) $< -o $@
    111 
    112 %.o: %.c
    113         $(CC) $(CFLAGS) $(INC) -c $< -o $@
    114         @$(CC) -M $(CFLAGS) $(INC) $*.c > $*.d
    115 
    116 $(PROGRAM): $(OBJECTS) $(LIBS)
    117         $(LD) -T $(LD_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(PROGRAM).map
    118 
    119 # Everything else is a phony target
    120 .PHONY: all clean distclean depend disasm
    121 
    122 all: $(PROGRAM) disasm
    123 
    124 clean:
    125         @-rm -f $(OBJECTS)
    126         @-rm -f $(PROGRAM)
    127         @-rm -f $(PROGRAM).map
    128         @-rm -f $(PROGRAM).disasm
    129         @-rm -f $(CLEANDIRS)
    130 
    131 depend:
    132         @echo ''
    133 
    134 disasm:
    135         $(OBJDUMP) -d $(PROGRAM) >$(PROGRAM).disasm
    136 
    137 distclean: clean
    138 
    139 # Do not delete - dependencies
    140 -include $(OBJECTS:.o=.d)
     62include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/bdsh/cmds/builtin_cmds.c

    rb50b5af2 r04803bf  
    3434#include <stdio.h>
    3535#include <stdlib.h>
    36 #include <string.h>
     36#include <str.h>
    3737#include "errors.h"
    3838#include "cmds.h"
  • uspace/app/bdsh/cmds/builtins/builtins.h

    rb50b5af2 r04803bf  
    1010#include "cd/cd_def.h"
    1111#include "exit/exit_def.h"
    12         {NULL, NULL, NULL, NULL}
     12        {NULL, NULL, NULL, NULL, 0}
    1313};
    1414
  • uspace/app/bdsh/cmds/builtins/cd/cd.c

    rb50b5af2 r04803bf  
    3232#include <stdlib.h>
    3333#include <unistd.h>
    34 #include <string.h>
     34#include <str.h>
    3535#include <errno.h>
    3636
     
    4141#include "cd.h"
    4242
    43 static char * cmdname = "cd";
     43static const char *cmdname = "cd";
    4444
    4545void help_cmd_cd(unsigned int level)
  • uspace/app/bdsh/cmds/builtins/cd/cd_def.h

    rb50b5af2 r04803bf  
    44        &cmd_cd,
    55        &help_cmd_cd,
     6        0
    67},
  • uspace/app/bdsh/cmds/builtins/exit/exit_def.h

    rb50b5af2 r04803bf  
    44        &cmd_exit,
    55        &help_cmd_exit,
     6        0
    67},
  • uspace/app/bdsh/cmds/cmds.h

    rb50b5af2 r04803bf  
    3333/* Module structure */
    3434typedef struct {
    35         char *name;         /* Name of the command */
    36         char *desc;         /* Description of the command */
     35        const char *name;   /* Name of the command */
     36        const char *desc;   /* Description of the command */
    3737        mod_entry_t entry;  /* Command (exec) entry function */
    3838        mod_help_t help;    /* Command (help) entry function */
     
    4141/* Builtin structure, same as modules except different types of entry points */
    4242typedef struct {
    43         char *name;
    44         char *desc;
     43        const char *name;
     44        const char *desc;
    4545        builtin_entry_t entry;
    4646        builtin_help_t help;
     
    5757extern int is_module(const char *);
    5858extern int is_module_alias(const char *);
    59 extern char * alias_for_module(const char *);
     59extern char *alias_for_module(const char *);
    6060extern int help_module(int, unsigned int);
    6161extern int run_module(int, char *[]);
     
    6565extern int is_builtin(const char *);
    6666extern int is_builtin_alias(const char *);
    67 extern char * alias_for_builtin(const char *);
     67extern char *alias_for_builtin(const char *);
    6868extern int help_builtin(int, unsigned int);
    6969extern int run_builtin(int, char *[], cliuser_t *);
  • uspace/app/bdsh/cmds/mod_cmds.c

    rb50b5af2 r04803bf  
    4747#include <stdio.h>
    4848#include <stdlib.h>
    49 #include <string.h>
     49#include <str.h>
    5050#include "errors.h"
    5151#include "cmds.h"
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rb50b5af2 r04803bf  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <string.h>
     31#include <str.h>
     32#include <sys/typefmt.h>
    3233#include "config.h"
    3334#include "util.h"
     
    4041#include <devmap.h>
    4142#include <errno.h>
     43#include <assert.h>
    4244
    43 #define BLOCK_SIZE      512
    44 #define BPR              16
     45enum {
     46        /* Number of bytes per row */
     47        BPR = 16
     48};
    4549
    4650static const char *cmdname = "bdd";
     
    6569        unsigned int argc;
    6670        unsigned int i, j;
    67         dev_handle_t handle;
    68         block_t *block;
     71        devmap_handle_t handle;
     72        aoff64_t offset;
    6973        uint8_t *blk;
    7074        size_t size, bytes, rows;
     75        size_t block_size;
    7176        int rc;
    72         bn_t boff;
     77        aoff64_t ba;
    7378        uint8_t b;
    7479
     
    8287
    8388        if (argc >= 3)
    84                 boff = strtol(argv[2], NULL, 0);
     89                ba = strtol(argv[2], NULL, 0);
    8590        else
    86                 boff = 0;
     91                ba = 0;
    8792
    8893        if (argc >= 4)
     
    9398        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9499        if (rc != EOK) {
    95                 printf("Error: could not resolve device `%s'.\n", argv[1]);
     100                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
    96101                return CMD_FAILURE;
    97102        }
    98103
    99         rc = block_init(handle, BLOCK_SIZE);
     104        rc = block_init(handle, 2048);
    100105        if (rc != EOK)  {
    101                 printf("Error: could not init libblock.\n");
     106                printf("%s: Error initializing libblock.\n", cmdname);
    102107                return CMD_FAILURE;
    103108        }
    104109
    105         rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
     110        rc = block_get_bsize(handle, &block_size);
    106111        if (rc != EOK) {
    107                 printf("Error: could not init block cache.\n");
     112                printf("%s: Error determining device block size.\n", cmdname);
    108113                return CMD_FAILURE;
    109114        }
    110115
     116        blk = malloc(block_size);
     117        if (blk == NULL) {
     118                printf("%s: Error allocating memory.\n", cmdname);
     119                block_fini(handle);
     120                return CMD_FAILURE;
     121        }
     122
     123        offset = ba * block_size;
     124
    111125        while (size > 0) {
    112                 block = block_get(handle, boff, 0);
    113                 blk = (uint8_t *) block->data;
     126                rc = block_read_direct(handle, ba, 1, blk);
     127                if (rc != EOK) {
     128                        printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba);
     129                        free(blk);
     130                        block_fini(handle);
     131                        return CMD_FAILURE;
     132                }
    114133
    115                 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
     134                bytes = (size < block_size) ? size : block_size;
    116135                rows = (bytes + BPR - 1) / BPR;
    117136
    118137                for (j = 0; j < rows; j++) {
     138                        printf("[%06" PRIxOFF64 "] ", offset);
    119139                        for (i = 0; i < BPR; i++) {
    120140                                if (j * BPR + i < bytes)
     
    136156                                }
    137157                        }
     158                        offset += BPR;
    138159                        putchar('\n');
    139160                }
    140 
    141                 block_put(block);
    142161
    143162                if (size > rows * BPR)
     
    146165                        size = 0;
    147166
    148                 boff += rows * BPR;
     167                /* Next block */
     168                ba += 1;
    149169        }
    150170
     171        free(blk);
    151172        block_fini(handle);
    152173
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    rb50b5af2 r04803bf  
    3333#include <unistd.h>
    3434#include <getopt.h>
    35 #include <string.h>
     35#include <str.h>
    3636#include <fcntl.h>
    3737
     
    4343#include "cmds.h"
    4444
    45 static char *cmdname = "cat";
     45static const char *cmdname = "cat";
    4646#define CAT_VERSION "0.0.1"
    4747#define CAT_DEFAULT_BUFLEN 1024
    4848
    49 static char *cat_oops = "That option is not yet supported\n";
     49static const char *cat_oops = "That option is not yet supported\n";
    5050
    5151static struct option const long_options[] = {
     
    8585{
    8686        int fd, bytes = 0, count = 0, reads = 0;
    87         off_t total = 0;
     87        off64_t total = 0;
    8888        char *buff = NULL;
    8989
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rb50b5af2 r04803bf  
    3333#include <unistd.h>
    3434#include <getopt.h>
    35 #include <string.h>
     35#include <str.h>
    3636#include <fcntl.h>
    3737#include "config.h"
     
    7474{
    7575        int fd1, fd2, bytes = 0;
    76         off_t total = 0;
     76        off64_t total = 0;
    7777        int64_t copied = 0;
    7878        char *buff = NULL;
     
    9595
    9696        if (vb)
    97                 printf("%d bytes to copy\n", total);
     97                printf("%" PRIu64 " bytes to copy\n", total);
    9898
    9999        lseek(fd1, 0, SEEK_SET);
     
    130130                 */
    131131                if (res != 0) {
    132                         printf("\n%d more bytes than actually exist were copied\n", res);
     132                        printf("\n%zd more bytes than actually exist were copied\n", res);
    133133                        goto err;
    134134                }
     
    187187                        return CMD_SUCCESS;
    188188                case 'v':
    189                         printf("%d\n", CP_VERSION);
     189                        printf("%s\n", CP_VERSION);
    190190                        return CMD_SUCCESS;
    191191                case 'V':
     
    223223
    224224        if (verbose)
    225                 printf("%d bytes copied\n", ret);
     225                printf("%" PRId64 " bytes copied\n", ret);
    226226
    227227        if (ret >= 0)
  • uspace/app/bdsh/cmds/modules/help/help.c

    rb50b5af2 r04803bf  
    3131#include <stdio.h>
    3232#include <stdlib.h>
    33 #include <string.h>
     33#include <str.h>
    3434
    3535#include "config.h"
     
    4242#include "util.h"
    4343
    44 static char *cmdname = "help";
     44static const char *cmdname = "help";
    4545extern const char *progname;
    4646
    47 #define HELP_IS_MODULE   1
    48 #define HELP_IS_BUILTIN  0
    49 #define HELP_IS_RUBBISH  -1
     47#define HELP_IS_COMMANDS        2
     48#define HELP_IS_MODULE          1
     49#define HELP_IS_BUILTIN         0
     50#define HELP_IS_RUBBISH         -1
    5051
    5152volatile int mod_switch = -1;
     
    5556{
    5657        int rc = HELP_IS_RUBBISH;
     58
     59        if (str_cmp(cmd, "commands") == 0)
     60                return HELP_IS_COMMANDS;
    5761
    5862        rc = is_builtin(cmd);
     
    9094}
    9195
    92 int cmd_help(char *argv[])
     96static void help_commands(void)
    9397{
     98        builtin_t *cmd;
    9499        module_t *mod;
    95         builtin_t *cmd;
    96         unsigned int i = 0;
    97         int rc = 0;
    98         int argc;
    99         int level = HELP_SHORT;
     100        unsigned int i;
    100101
    101         argc = cli_count_args(argv);
    102 
    103         if (argc > 3) {
    104                 printf("\nToo many arguments to `%s', try:\n", cmdname);
    105                 help_cmd_help(HELP_SHORT);
    106                 return CMD_FAILURE;
    107         }
    108 
    109         if (argc == 3) {
    110                 if (!str_cmp("extended", argv[2]))
    111                         level = HELP_LONG;
    112                 else
    113                         level = HELP_SHORT;
    114         }
    115 
    116         if (argc > 1) {
    117                 rc = is_mod_or_builtin(argv[1]);
    118                 switch (rc) {
    119                 case HELP_IS_RUBBISH:
    120                         printf("Invalid command %s\n", argv[1]);
    121                         return CMD_FAILURE;
    122                 case HELP_IS_MODULE:
    123                         help_module(mod_switch, level);
    124                         return CMD_SUCCESS;
    125                 case HELP_IS_BUILTIN:
    126                         help_builtin(mod_switch, level);
    127                         return CMD_SUCCESS;
    128                 }
    129         }
    130 
    131         printf("\n  Available commands are:\n");
     102        printf("\n  Bdsh built-in commands:\n");
    132103        printf("  ------------------------------------------------------------\n");
    133104
     
    154125        printf("\n  Try %s %s for more information on how `%s' works.\n\n",
    155126                cmdname, cmdname, cmdname);
     127}
     128
     129/** Display survival tips. ('help' without arguments) */
     130static void help_survival(void)
     131{
     132        printf("Don't panic!\n\n");
     133
     134        printf("This is Bdsh, the Brain dead shell, currently "
     135            "the primary user interface to HelenOS. Bdsh allows you to enter "
     136            "commands and supports history (Up, Down arrow keys), "
     137            "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
     138            "selection (Shift + movement keys), copy and paste (Ctrl-C, "
     139            "Ctrl-V), similar to common desktop environments.\n\n");
     140
     141        printf("The most basic filesystem commands are Bdsh builtins. Type "
     142            "'help commands' [Enter] to see the list of Bdsh builtin commands. "
     143            "Other commands are external executables located in the /app and "
     144            "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
     145            "to see their list. You can execute an external command simply "
     146            "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
     147
     148        printf("HelenOS has virtual consoles (VCs). You can switch between "
     149            "these using the F1-F11 keys.\n\n");
     150
     151        printf("This is but a small glimpse of what you can do with HelenOS. "
     152            "To learn more please point your browser to the HelenOS User's "
     153            "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
     154}
     155
     156int cmd_help(char *argv[])
     157{
     158        int rc = 0;
     159        int argc;
     160        int level = HELP_SHORT;
     161
     162        argc = cli_count_args(argv);
     163
     164        if (argc > 3) {
     165                printf("\nToo many arguments to `%s', try:\n", cmdname);
     166                help_cmd_help(HELP_SHORT);
     167                return CMD_FAILURE;
     168        }
     169
     170        if (argc == 3) {
     171                if (!str_cmp("extended", argv[2]))
     172                        level = HELP_LONG;
     173                else
     174                        level = HELP_SHORT;
     175        }
     176
     177        if (argc > 1) {
     178                rc = is_mod_or_builtin(argv[1]);
     179                switch (rc) {
     180                case HELP_IS_RUBBISH:
     181                        printf("Invalid topic %s\n", argv[1]);
     182                        return CMD_FAILURE;
     183                case HELP_IS_COMMANDS:
     184                        help_commands();
     185                        return CMD_SUCCESS;
     186                case HELP_IS_MODULE:
     187                        help_module(mod_switch, level);
     188                        return CMD_SUCCESS;
     189                case HELP_IS_BUILTIN:
     190                        help_builtin(mod_switch, level);
     191                        return CMD_SUCCESS;
     192                }
     193        }
     194
     195        help_survival();
    156196
    157197        return CMD_SUCCESS;
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    rb50b5af2 r04803bf  
    4040#include "cmds.h"
    4141
    42 static char *cmdname = "kcon";
     42static const char *cmdname = "kcon";
    4343
    4444/* Dispays help for kcon in various levels */
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    rb50b5af2 r04803bf  
    4040#include <sys/types.h>
    4141#include <sys/stat.h>
    42 #include <string.h>
     42#include <str.h>
    4343
    4444#include "errors.h"
     
    4949#include "cmds.h"
    5050
    51 static char *cmdname = "ls";
     51static const char *cmdname = "ls";
    5252
    5353static void ls_scan_dir(const char *d, DIR *dirp)
     
    100100        if (s.is_file)
    101101                printf("%-40s\t%llu\n", name, (long long) s.size);
     102        else if (s.is_directory)
     103                printf("%-40s\t<dir>\n", name);
    102104        else
    103105                printf("%-40s\n", name);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    rb50b5af2 r04803bf  
    3838#include <getopt.h>
    3939#include <stdarg.h>
    40 #include <string.h>
     40#include <str.h>
    4141
    4242#include "config.h"
     
    4949#define MKDIR_VERSION "0.0.1"
    5050
    51 static char *cmdname = "mkdir";
     51static const char *cmdname = "mkdir";
    5252
    5353static struct option const long_options[] = {
  • uspace/app/bdsh/cmds/modules/module_aliases.h

    rb50b5af2 r04803bf  
    1212 * the entry point being reached. */
    1313
    14 char *mod_aliases[] = {
     14const char *mod_aliases[] = {
    1515        "ren", "mv",
     16        "umount", "unmount",
    1617        NULL, NULL
    1718};
  • uspace/app/bdsh/cmds/modules/modules.h

    rb50b5af2 r04803bf  
    2020#include "help/entry.h"
    2121#include "mkdir/entry.h"
     22#include "mkfile/entry.h"
    2223#include "rm/entry.h"
    2324#include "bdd/entry.h"
     
    3031#include "mv/entry.h"
    3132#include "mount/entry.h"
     33#include "unmount/entry.h"
    3234#include "kcon/entry.h"
    3335
     
    3941#include "help/help_def.h"
    4042#include "mkdir/mkdir_def.h"
     43#include "mkfile/mkfile_def.h"
    4144#include "rm/rm_def.h"
    4245#include "bdd/bdd_def.h"
     
    4952#include "mv/mv_def.h"
    5053#include "mount/mount_def.h"
     54#include "unmount/unmount_def.h"
    5155#include "kcon/kcon_def.h"
    5256
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    rb50b5af2 r04803bf  
    3131#include <vfs/vfs.h>
    3232#include <errno.h>
     33#include <getopt.h>
    3334#include "config.h"
    3435#include "util.h"
     
    4041static const char *cmdname = "mount";
    4142
    42 /* Dispays help for mount in various levels */
     43static struct option const long_options[] = {
     44        { "help", no_argument, 0, 'h' },
     45        { 0, 0, 0, 0 }
     46};
     47
     48
     49/* Displays help for mount in various levels */
    4350void help_cmd_mount(unsigned int level)
    4451{
     
    5865{
    5966        unsigned int argc;
    60         char *mopts = "";
    61         int rc;
     67        const char *mopts = "";
     68        int rc, c, opt_ind;
    6269
    6370        argc = cli_count_args(argv);
    6471
     72        for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
     73                c = getopt_long(argc, argv, "h", long_options, &opt_ind);
     74                switch (c) {
     75                case 'h':
     76                        help_cmd_mount(HELP_LONG);
     77                        return CMD_SUCCESS;
     78                }
     79        }
     80
    6581        if ((argc < 4) || (argc > 5)) {
    66                 printf("%s: invalid number of arguments.\n",
     82                printf("%s: invalid number of arguments. Try `mount --help'\n",
    6783                    cmdname);
    6884                return CMD_FAILURE;
  • uspace/app/bdsh/cmds/modules/pwd/pwd.c

    rb50b5af2 r04803bf  
    3939#include "pwd.h"
    4040
    41 static char * cmdname = "pwd";
     41static const char *cmdname = "pwd";
    4242
    4343void help_cmd_pwd(unsigned int level)
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    rb50b5af2 r04803bf  
    3636#include <getopt.h>
    3737#include <mem.h>
    38 #include <string.h>
     38#include <str.h>
    3939
    4040#include "config.h"
     
    4545#include "cmds.h"
    4646
    47 static char *cmdname = "rm";
     47static const char *cmdname = "rm";
    4848#define RM_VERSION "0.0.1"
    4949
  • uspace/app/bdsh/cmds/modules/sleep/sleep.c

    rb50b5af2 r04803bf  
    3838#include "cmds.h"
    3939
    40 static char *cmdname = "sleep";
     40static const char *cmdname = "sleep";
    4141
    4242/* Dispays help for sleep in various levels */
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rb50b5af2 r04803bf  
    3838#include <dirent.h>
    3939#include <sys/types.h>
    40 #include <string.h>
     40#include <str.h>
    4141
    4242#include "config.h"
     
    4747#include "cmds.h"
    4848
    49 static char *cmdname = "touch";
     49static const char *cmdname = "touch";
    5050
    5151/* Dispays help for touch in various levels */
  • uspace/app/bdsh/errors.c

    rb50b5af2 r04803bf  
    3030
    3131#include <stdio.h>
    32 #include <string.h>
     32#include <str.h>
    3333#include <stdlib.h>
    3434#include <unistd.h>
     
    4747/* Look up errno in cl_errors and return the corresponding string.
    4848 * Return NULL if not found */
    49 static char *err2str(int err)
     49static const char *err2str(int err)
    5050{
    5151
  • uspace/app/bdsh/errstr.h

    rb50b5af2 r04803bf  
    44/* Simple array to translate error codes to meaningful strings */
    55
    6 static char *cl_errors[] = {
     6static const char *cl_errors[] = {
    77        "Success",
    88        "Failure",
     
    1818};
    1919
    20 static char *err2str(int);
     20static const char *err2str(int);
    2121
    2222#endif
  • uspace/app/bdsh/exec.c

    rb50b5af2 r04803bf  
    3838#include <stdlib.h>
    3939#include <unistd.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <fcntl.h>
     42#include <str_error.h>
     43#include <errno.h>
    4244
    4345#include "config.h"
     
    115117        task_exit_t texit;
    116118        char *tmp;
    117         int retval;
     119        int rc, retval;
    118120
    119121        tmp = str_dup(find_command(cmd));
    120122        free(found);
    121123
    122         tid = task_spawn((const char *)tmp, argv);
     124        rc = task_spawnv(&tid, tmp, (const char **) argv);
    123125        free(tmp);
    124126
    125         if (tid == 0) {
    126                 cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd);
     127        if (rc != 0) {
     128                cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
     129                    str_error(rc));
    127130                return 1;
    128131        }
    129132       
    130         task_wait(tid, &texit, &retval);
    131         if (texit != TASK_EXIT_NORMAL) {
    132                 printf("Command failed (unexpectedly terminated).\n");
     133        rc = task_wait(tid, &texit, &retval);
     134        if (rc != EOK) {
     135                printf("%s: Failed waiting for command (%s)\n", progname,
     136                    str_error(rc));
     137        } else if (texit != TASK_EXIT_NORMAL) {
     138                printf("%s: Command failed (unexpectedly terminated)\n", progname);
    133139        } else if (retval != 0) {
    134                 printf("Command failed (return value %d).\n", retval);
     140                printf("%s: Command failed (exit code %d)\n",
     141                    progname, retval);
    135142        }
    136143
  • uspace/app/bdsh/exec.h

    rb50b5af2 r04803bf  
    55
    66extern unsigned int try_exec(char *, char **);
     7
    78#endif
  • uspace/app/bdsh/input.c

    rb50b5af2 r04803bf  
    11/* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
    22 * All rights reserved.
    3  * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved
    43 *
    54 * Redistribution and use in source and binary forms, with or without
     
    3231#include <stdio.h>
    3332#include <stdlib.h>
    34 #include <string.h>
     33#include <str.h>
    3534#include <io/console.h>
    3635#include <io/keycode.h>
    3736#include <io/style.h>
     37#include <io/color.h>
    3838#include <vfs/vfs.h>
     39#include <clipboard.h>
     40#include <macros.h>
    3941#include <errno.h>
     42#include <assert.h>
    4043#include <bool.h>
     44#include <tinput.h>
    4145
    4246#include "config.h"
     
    4751#include "exec.h"
    4852
    49 static void read_line(char *, int);
     53extern volatile unsigned int cli_quit;
     54
     55/** Text input field. */
     56static tinput_t *tinput;
    5057
    5158/* Tokenizes input from console, sees if the first word is a built-in, if so
     
    99106}
    100107
    101 static void read_line(char *buffer, int n)
    102 {
    103         console_event_t ev;
    104         size_t offs, otmp;
    105         wchar_t dec;
    106 
    107         offs = 0;
    108         while (true) {
    109                 fflush(stdout);
    110                 if (!console_get_event(fphone(stdin), &ev))
    111                         return;
    112                
    113                 if (ev.type != KEY_PRESS)
    114                         continue;
    115                
    116                 if (ev.key == KC_ENTER || ev.key == KC_NENTER)
    117                         break;
    118                 if (ev.key == KC_BACKSPACE) {
    119                         if (offs > 0) {
    120                                 /*
    121                                  * Back up until we reach valid start of
    122                                  * character.
    123                                  */
    124                                 while (offs > 0) {
    125                                         --offs; otmp = offs;
    126                                         dec = str_decode(buffer, &otmp, n);
    127                                         if (dec != U_SPECIAL)
    128                                                 break;
    129                                 }
    130                                 putchar('\b');
    131                         }
    132                         continue;
    133                 }
    134                 if (ev.c >= ' ') {
    135                         if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK)
    136                                 putchar(ev.c);
    137                 }
    138         }
    139         putchar('\n');
    140         buffer[offs] = '\0';
    141 }
    142 
    143 /* TODO:
    144  * Implement something like editline() / readline(), if even
    145  * just for command history and making arrows work. */
    146108void get_input(cliuser_t *usr)
    147109{
    148         char line[INPUT_MAX];
     110        char *str;
     111        int rc;
    149112
    150113        fflush(stdout);
     
    154117        console_set_style(fphone(stdout), STYLE_NORMAL);
    155118
    156         read_line(line, INPUT_MAX);
    157         /* Make sure we don't have rubbish or a C/R happy user */
    158         if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0)
     119        rc = tinput_read(tinput, &str);
     120        if (rc == ENOENT) {
     121                /* User requested exit */
     122                cli_quit = 1;
     123                putchar('\n');
    159124                return;
    160         usr->line = str_dup(line);
     125        }
    161126
     127        if (rc != EOK) {
     128                /* Error in communication with console */
     129                return;
     130        }
     131
     132        /* Check for empty input. */
     133        if (str_cmp(str, "") == 0) {
     134                free(str);
     135                return;
     136        }
     137
     138        usr->line = str;
    162139        return;
    163140}
    164141
     142int input_init(void)
     143{
     144        tinput = tinput_new();
     145        if (tinput == NULL) {
     146                printf("Failed to initialize input.\n");
     147                return 1;
     148        }
     149
     150        return 0;
     151}
  • uspace/app/bdsh/input.h

    rb50b5af2 r04803bf  
    88extern void get_input(cliuser_t *);
    99extern int tok_input(cliuser_t *);
     10extern int input_init(void);
    1011
    1112#endif
  • uspace/app/bdsh/scli.c

    rb50b5af2 r04803bf  
    3131#include <stdio.h>
    3232#include <stdlib.h>
    33 #include <string.h>
     33#include <str.h>
    3434#include <unistd.h>
    3535#include "config.h"
     
    6161        usr->line = (char *) NULL;
    6262        usr->name = "root";
    63         usr->home = "/";
    6463        usr->cwd = (char *) NULL;
    6564        usr->prompt = (char *) NULL;
    66         chdir(usr->home);
    6765        usr->lasterr = 0;
     66
     67        if (input_init() != 0)
     68                return 1;
     69
    6870        return (int) cli_set_prompt(usr);
    6971}
     
    8789                exit(EXIT_FAILURE);
    8890
    89         printf("Welcome to %s - %s\nType `help' at any time for usage information.\n",
    90                 progname, PACKAGE_STRING);
    91 
    9291        while (!cli_quit) {
    9392                get_input(&usr);
     
    9897                }
    9998        }
    100         goto finit;
    10199
    102 finit:
     100        printf("Leaving %s.\n", progname);
     101
    103102        cli_finit(&usr);
    104103        return ret;
  • uspace/app/bdsh/scli.h

    rb50b5af2 r04803bf  
    66
    77typedef struct {
    8         char *name;
    9         char *home;
     8        const char *name;
    109        char *line;
    1110        char *cwd;
     
    1413} cliuser_t;
    1514
     15extern const char *progname;
     16
    1617#endif
  • uspace/app/bdsh/util.c

    rb50b5af2 r04803bf  
    2929
    3030#include <stdio.h>
    31 #include <string.h>
     31#include <str.h>
    3232#include <stdarg.h>
    3333#include <stdlib.h>
  • uspace/app/dload/Makefile

    rb50b5af2 r04803bf  
    11#
    2 # Copyright (c) 2005 Martin Decky
     2# Copyright (c) 2011 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 include ../../../version
     29USPACE_PREFIX = ../..
     30LIBS =
     31EXTRA_CFLAGS = -I../../srv/loader/include -I../../lib/c/rtld/include -Iinclude
     32BINARY = dload
    3033
    31 ## Setup toolchain
    32 #
    33 
    34 LIBC_PREFIX = ../../lib/libc
    35 SOFTINT_PREFIX = ../../lib/softint
    36 
    37 include $(LIBC_PREFIX)/Makefile.toolchain
     34include $(USPACE_PREFIX)/../Makefile.config
    3835include arch/$(UARCH)/Makefile.inc
    3936
    40 CFLAGS += -Iinclude -I../../srv/loader/include -I../../lib/libc/rtld/include -O0 -ggdb
    41 LFLAGS +=
     37SOURCES = \
     38        dload.c \
     39        $(ARCH_SOURCES)
    4240
    43 LIBS = $(LIBC_PREFIX)/libc.a $(SOFTINT_PREFIX)/libsoftint.a
    44 DEFS += -DRELEASE=\"$(RELEASE)\"
    45 
    46 ## Sources
    47 #
    48 
    49 OUTPUT = dload
    50 GENERIC_SOURCES = \
    51         dload.c
    52 
    53 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
    54 ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
    55 
    56 .PHONY: all clean depend disasm sections inc
    57 
    58 all: inc $(OUTPUT) disasm sections
    59 
    60 inc:
    61         ln -sfn ../arch/$(UARCH)/include include/arch
    62 
    63 -include Makefile.depend
    64 
    65 clean:
    66         -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm $(OUTPUT).sections Makefile.depend *.o arch/$(UARCH)/_link.ld include/arch
    67         find arch/$(UARCH)/ -name '*.o' -follow -exec rm \{\} \;
    68 
    69 depend:
    70         $(CC) $(DEFS) $(CFLAGS) -M $(ARCH_SOURCES) $(GENERIC_SOURCES)> Makefile.depend
    71 
    72 $(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) arch/$(UARCH)/_link.ld
    73         $(LD) -T arch/$(UARCH)/_link.ld $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    74 
    75 disasm:
    76         $(OBJDUMP) -d -S -s $(OUTPUT) >$(OUTPUT).disasm
    77 
    78 sections:
    79         $(OBJDUMP) -h $(OUTPUT) >$(OUTPUT).sections
    80 
    81 arch/$(UARCH)/_link.ld: arch/$(UARCH)/_link.ld.in
    82         $(CC) $(DEFS) $(CFLAGS) -DLIBC_PREFIX=$(LIBC_PREFIX) -E -x c $< | grep -v "^\#" > $@
    83 
    84 %.o: %.S
    85         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    86 
    87 %.o: %.s
    88         $(AS) $(AFLAGS) $< -o $@
    89 
    90 %.o: %.c
    91         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     41include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/dload/arch/ia32/start.c

    rb50b5af2 r04803bf  
    3636
    3737#include <loader/pcb.h>
     38#include "start.h"
    3839
    3940void program_run(void *entry, pcb_t *pcb)
  • uspace/app/dload/dload.c

    rb50b5af2 r04803bf  
    4848#include <module.h>
    4949
    50 void program_run(void *entry, pcb_t *pcb);
     50#include "start.h"
    5151
    5252runtime_env_t dload_re;
  • uspace/app/dltest/Makefile

    rb50b5af2 r04803bf  
    11#
    2 # Copyright (c) 2005 Martin Decky
     2# Copyright (c) 2011 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 include ../../../version
     29USPACE_PREFIX = ../..
     30BINARY = dltest
    3031
    31 ## Setup toolchain
    32 #
    33 
    34 LIBC_PREFIX = ../../lib/libc
    35 SOFTINT_PREFIX = ../../lib/softint
    36 
    37 include $(LIBC_PREFIX)/Makefile.toolchain
    38 
    39 CFLAGS += -I../../lib/libc -O0
    40 LFLAGS := -Bdynamic -I/lib/rtld -rpath-link $(LIBC_PREFIX)/shared
    41 
    42 LIBS = $(LIBC_PREFIX)/shared/libc.so.0
    43 
    44 ## Sources
    45 #
    46 
    47 OUTPUT = dltest
    4832SOURCES = \
    4933        dltest.c
    5034
    51 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    52 
    53 .PHONY: all clean depend disasm
    54 
    55 all: $(OUTPUT) disasm
    56 
    57 -include Makefile.depend
    58 
    59 clean:
    60         -rm -f $(OUTPUT) $(OBJECTS) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend arch/$(UARCH)/_link.ld
    61 
    62 depend:
    63         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    64 
    65 $(OUTPUT): $(OBJECTS) $(LIBS)
    66         $(LD) -T $(LIBC_PREFIX)/shared/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    67 
    68 disasm:
    69         $(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
    70 
    71 %.o: %.S
    72         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    73 
    74 %.o: %.s
    75         $(AS) $(AFLAGS) $< -o $@
    76 
    77 %.o: %.c
    78         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     35include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/dltest/dltest.c

    rb50b5af2 r04803bf  
    7070        int i;
    7171
    72         char *lib_name;
    73         char *sym_name;
     72        const char *lib_name;
     73        const char *sym_name;
    7474
    75 //      kputint(-1);
     75        if (0) kputint(-1);
    7676        printf("Hello from dltest!\n");
    7777
     
    8585        } else {
    8686                printf("failed to dlopen() library '%s'\n", lib_name);
     87                return -1;
    8788        }
    8889
  • uspace/app/dltest2/Makefile

    rb50b5af2 r04803bf  
    11#
    2 # Copyright (c) 2005 Martin Decky
     2# Copyright (c) 2011 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 include ../../../version
     29USPACE_PREFIX = ../..
     30BINARY = dltest2
    3031
    31 ## Setup toolchain
    32 #
    33 
    34 LIBC_PREFIX = ../../lib/libc
    35 SOFTINT_PREFIX = ../../lib/softint
    36 
    37 include $(LIBC_PREFIX)/Makefile.toolchain
    38 
    39 CFLAGS += -D__32_BITS__ -I../../srv/loader/include -I../../lib/rtld/include -I../../lib/libc -O0
    40 LIBS = $(LIBC_PREFIX)/libc.a $(SOFTINT_PREFIX)/libsoftint.a
    41 
    42 ## Sources
    43 #
    44 
    45 OUTPUT = dltest2
    4632SOURCES = \
    4733        dltest2.c
    4834
    49 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    50 
    51 .PHONY: all clean depend disasm
    52 
    53 all: $(OUTPUT) disasm
    54 
    55 -include Makefile.depend
    56 
    57 clean:
    58         -rm -f $(OUTPUT) $(OBJECTS) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend arch/$(UARCH)/_link.ld
    59 
    60 depend:
    61         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    62 
    63 $(OUTPUT): $(OBJECTS) $(LIBS)
    64         $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LFLAGS) $(LIBS) -o $@ -Map $(OUTPUT).map
    65 
    66 disasm:
    67         $(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
    68 
    69 %.o: %.S
    70         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    71 
    72 %.o: %.s
    73         $(AS) $(AFLAGS) $< -o $@
    74 
    75 %.o: %.c
    76         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     35include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/dltest2/dltest2.c

    rb50b5af2 r04803bf  
    7070        int i;
    7171
    72         char *lib_name;
    73         char *sym_name;
     72        const char *lib_name;
     73        const char *sym_name;
    7474
    75 //      kputint(-1);
     75        if (0) kputint(-1);
    7676        printf("Hello from dltest!\n");
    7777
     
    8585        } else {
    8686                printf("failed to dlopen() library '%s'\n", lib_name);
     87                return -1;
    8788        }
    8889
  • uspace/app/edit/Makefile

    rb50b5af2 r04803bf  
    11#
    22# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 #include <arch/asm/macro.h>
     30USPACE_PREFIX = ../..
     31BINARY = edit
    3032
    31 .text
    32 .global panic_printf
     33SOURCES = \
     34        edit.c \
     35        sheet.c
    3336
    34 panic_printf:
    35         lis %r14, halt@ha
    36         addi %r14, %r14, halt@l
    37         mtlr %r14       # fake stack to make printf return to halt
    38         b printf
     37include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/getterm/getterm.c

    rb50b5af2 r04803bf  
    2727 */
    2828
    29 /** @addtogroup getvc GetVC
     29/** @addtogroup getterm GetTerm
    3030 * @brief Console initialization task.
    3131 * @{
     
    3636
    3737#include <sys/types.h>
     38#include <fcntl.h>
    3839#include <unistd.h>
    3940#include <stdio.h>
    4041#include <task.h>
     42#include <str_error.h>
     43#include <errno.h>
    4144#include "version.h"
     45#include "welcome.h"
     46
     47#define APP_NAME  "getterm"
    4248
    4349static void usage(void)
    4450{
    45         printf("Usage: getvc <device> <path>\n");
     51        printf("Usage: %s <terminal> [-w] <command> [<arguments...>]\n", APP_NAME);
    4652}
    4753
    48 static void closeall(void)
     54static void reopen(FILE **stream, int fd, const char *path, int flags, const char *mode)
    4955{
    50         fclose(stdin);
    51         fclose(stdout);
    52         fclose(stderr);
     56        if (fclose(*stream))
     57                return;
    5358       
    54         close(0);
    55         close(1);
    56         close(2);
    57 }
    58 
    59 static task_id_t spawn(char *fname)
    60 {
    61         char *argv[2];
     59        *stream = NULL;
    6260       
    63         argv[0] = fname;
    64         argv[1] = NULL;
     61        int oldfd = open(path, flags);
     62        if (oldfd < 0)
     63                return;
    6564       
    66         task_id_t id = task_spawn(fname, argv);
     65        if (oldfd != fd) {
     66                if (dup2(oldfd, fd) != fd)
     67                        return;
     68               
     69                if (close(oldfd))
     70                        return;
     71        }
    6772       
    68         if (id == 0)
    69                 printf("Error spawning %s\n", fname);
    70        
    71         return id;
     73        *stream = fdopen(fd, mode);
    7274}
    7375
    7476int main(int argc, char *argv[])
    7577{
     78        int rc;
    7679        task_exit_t texit;
    7780        int retval;
     81        task_id_t id;
     82        char *fname, *term;
     83        char **cmd_args;
     84        bool print_wmsg;
    7885
    79         if (argc < 3) {
     86        argv++;
     87        argc--;
     88        if (argc < 1) {
    8089                usage();
    8190                return -1;
    8291        }
     92
     93        if (str_cmp(*argv, "-w") == 0) {
     94                print_wmsg = true;
     95                argv++;
     96                argc--;
     97        } else {
     98                print_wmsg = false;
     99        }
     100
     101        if (argc < 2) {
     102                usage();
     103                return -1;
     104        }
     105
     106        term = *argv++;
     107        fname = *argv;
     108        cmd_args = argv;
    83109       
    84         closeall();
     110        reopen(&stdin, 0, term, O_RDONLY, "r");
     111        reopen(&stdout, 1, term, O_WRONLY, "w");
     112        reopen(&stderr, 2, term, O_WRONLY, "w");
    85113       
    86         stdin = fopen(argv[1], "r");
    87         stdout = fopen(argv[1], "w");
    88         stderr = fopen(argv[1], "w");
    89 
    90114        /*
    91          * FIXME: fopen() should actually detect that we are opening a console
     115         * FIXME: fdopen() should actually detect that we are opening a console
    92116         * and it should set line-buffering mode automatically.
    93117         */
    94118        setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
    95119       
    96         if ((stdin == NULL)
    97             || (stdout == NULL)
    98             || (stderr == NULL))
     120        if (stdin == NULL)
    99121                return -2;
    100122       
    101         version_print(argv[1]);
    102         task_id_t id = spawn(argv[2]);
    103         task_wait(id, &texit, &retval);
     123        if (stdout == NULL)
     124                return -3;
    104125       
     126        if (stderr == NULL)
     127                return -4;
     128       
     129        version_print(term);
     130        if (print_wmsg)
     131                welcome_msg_print();
     132
     133        rc = task_spawnv(&id, fname, (const char * const *) cmd_args);
     134        if (rc != EOK) {
     135                printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
     136                    str_error(rc));
     137                return -5;
     138        }
     139
     140        rc = task_wait(id, &texit, &retval);
     141        if (rc != EOK) {
     142                printf("%s: Error waiting for %s (%s)\n", APP_NAME, fname,
     143                    str_error(rc));
     144                return -6;
     145        }
     146
    105147        return 0;
    106148}
  • uspace/app/getterm/getterm.h

    rb50b5af2 r04803bf  
    2727 */
    2828
    29 /** @addtogroup getvc
     29/** @addtogroup getterm
    3030 * @{
    3131 */
     
    3434 */
    3535
    36 #ifndef GETVC_H__
    37 #define GETVC_H__
     36#ifndef GETTERM_H__
     37#define GETTERM_H__
    3838
    3939#endif
  • uspace/app/getterm/version.c

    rb50b5af2 r04803bf  
    2727 */
    2828
    29 /** @addtogroup getvc
     29/** @addtogroup getterm
    3030 * @{
    3131 */
     
    3737#include <stdio.h>
    3838#include <macros.h>
    39 #include "getvc.h"
     39#include "getterm.h"
    4040#include "version.h"
    4141
    42 static char *release = STRING(RELEASE);
    43 static char *name = STRING(NAME);
    44 static char *arch = STRING(UARCH);
     42static const char *release = STRING(RELEASE);
     43static const char *name = STRING(NAME);
     44static const char *arch = STRING(UARCH);
    4545
    4646#ifdef REVISION
    47         static char *revision = ", revision " STRING(REVISION);
     47        static const char *revision = ", revision " STRING(REVISION);
    4848#else
    49         static char *revision = "";
     49        static const char *revision = "";
    5050#endif
    5151
    5252#ifdef TIMESTAMP
    53         static char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
     53        static const char *timestamp = "\nBuilt on " STRING(TIMESTAMP);
    5454#else
    55         static char *timestamp = "";
     55        static const char *timestamp = "";
    5656#endif
    5757
    5858/** Print version information. */
    59 void version_print(const char *vc)
     59void version_print(const char *term)
    6060{
    6161        printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp);
    62         printf("Running on %s (%s)\n", arch, vc);
    63         printf("Copyright (c) 2001-2009 HelenOS project\n\n");
     62        printf("Running on %s (%s)\n", arch, term);
     63        printf("Copyright (c) 2001-2010 HelenOS project\n\n");
    6464}
    6565
  • uspace/app/getterm/version.h

    rb50b5af2 r04803bf  
    2727 */
    2828
    29 /** @addtogroup getvc
     29/** @addtogroup getterm
    3030 * @{
    3131 */
     
    3737#define VERSION_H__
    3838
    39 extern void version_print(const char *vc);
     39extern void version_print(const char *term);
    4040
    4141#endif
  • uspace/app/init/Makefile

    rb50b5af2 r04803bf  
    11#
    22# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 ## Setup toolchain
    30 #
     30USPACE_PREFIX = ../..
     31BINARY = init
    3132
    32 LIBC_PREFIX = ../../lib/libc
    33 SOFTINT_PREFIX = ../../lib/softint
    34 
    35 include $(LIBC_PREFIX)/Makefile.toolchain
    36 
    37 CFLAGS += -I../../..
    38 LIBS = $(LIBC_PREFIX)/libc.a
    39 
    40 ## Sources
    41 #
    42 
    43 OUTPUT = init
    4433SOURCES = \
    4534        init.c
    4635
    47 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    48 
    49 .PHONY: all clean depend disasm
    50 
    51 all: $(OUTPUT) $(OUTPUT).disasm
    52 
    53 -include Makefile.depend
    54 
    55 clean:
    56         -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend $(OBJECTS)
    57 
    58 depend:
    59         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    60 
    61 $(OUTPUT): $(OBJECTS) $(LIBS)
    62         $(LD) -T $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    63 
    64 disasm: $(OUTPUT).disasm
    65 
    66 $(OUTPUT).disasm: $(OUTPUT)
    67         $(OBJDUMP) -d $< > $@
    68 
    69 %.o: %.S
    70         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    71 
    72 %.o: %.s
    73         $(AS) $(AFLAGS) $< -o $@
    74 
    75 %.o: %.c
    76         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/init/init.c

    rb50b5af2 r04803bf  
    3737#include <stdio.h>
    3838#include <unistd.h>
    39 #include <ipc/ipc.h>
    4039#include <vfs/vfs.h>
    4140#include <bool.h>
     
    4645#include <malloc.h>
    4746#include <macros.h>
    48 #include <string.h>
     47#include <str.h>
    4948#include <devmap.h>
    50 #include <config.h>
     49#include <str_error.h>
    5150#include "init.h"
    5251
     52#define ROOT_DEVICE       "bd/initrd"
     53#define ROOT_MOUNT_POINT  "/"
     54
     55#define DEVFS_FS_TYPE      "devfs"
     56#define DEVFS_MOUNT_POINT  "/dev"
     57
     58#define TMPFS_FS_TYPE      "tmpfs"
     59#define TMPFS_MOUNT_POINT  "/tmp"
     60
     61#define DATA_FS_TYPE      "fat"
     62#define DATA_DEVICE       "bd/ata1disk0"
     63#define DATA_MOUNT_POINT  "/data"
     64
     65#define SRV_CONSOLE  "/srv/console"
     66#define APP_GETTERM  "/app/getterm"
     67
    5368static void info_print(void)
    5469{
    55         printf(NAME ": HelenOS init\n");
     70        printf("%s: HelenOS init\n", NAME);
     71}
     72
     73static bool mount_report(const char *desc, const char *mntpt,
     74    const char *fstype, const char *dev, int rc)
     75{
     76        switch (rc) {
     77        case EOK:
     78                if (dev != NULL)
     79                        printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
     80                            fstype, dev);
     81                else
     82                        printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
     83                break;
     84        case EBUSY:
     85                printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
     86                return false;
     87        case ELIMIT:
     88                printf("%s: %s limit exceeded\n", NAME, desc);
     89                return false;
     90        case ENOENT:
     91                printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
     92                return false;
     93        default:
     94                printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
     95                    str_error(rc));
     96                return false;
     97        }
     98       
     99        return true;
    56100}
    57101
    58102static bool mount_root(const char *fstype)
    59103{
    60         char *opts = "";
    61         const char *root_dev = "initrd";
     104        const char *opts = "";
    62105       
    63106        if (str_cmp(fstype, "tmpfs") == 0)
    64107                opts = "restore";
    65108       
    66         int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING);
    67        
    68         switch (rc) {
    69         case EOK:
    70                 printf(NAME ": Root filesystem mounted, %s at %s\n",
    71                     fstype, root_dev);
    72                 break;
    73         case EBUSY:
    74                 printf(NAME ": Root filesystem already mounted\n");
    75                 return false;
    76         case ELIMIT:
    77                 printf(NAME ": Unable to mount root filesystem\n");
    78                 return false;
    79         case ENOENT:
    80                 printf(NAME ": Unknown filesystem type (%s)\n", fstype);
    81                 return false;
    82         default:
    83                 printf(NAME ": Error mounting root filesystem (%d)\n", rc);
    84                 return false;
    85         }
    86        
    87         return true;
     109        int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
     110            IPC_FLAG_BLOCKING);
     111        return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
     112            ROOT_DEVICE, rc);
    88113}
    89114
    90115static bool mount_devfs(void)
    91116{
    92         char null[MAX_DEVICE_NAME];
    93         int null_id = devmap_null_create();
    94        
    95         if (null_id == -1) {
    96                 printf(NAME ": Unable to create null device\n");
    97                 return false;
    98         }
    99        
    100         snprintf(null, MAX_DEVICE_NAME, "null%d", null_id);
    101         int rc = mount("devfs", "/dev", null, "", IPC_FLAG_BLOCKING);
    102        
    103         switch (rc) {
    104         case EOK:
    105                 printf(NAME ": Device filesystem mounted\n");
    106                 break;
    107         case EBUSY:
    108                 printf(NAME ": Device filesystem already mounted\n");
    109                 devmap_null_destroy(null_id);
    110                 return false;
    111         case ELIMIT:
    112                 printf(NAME ": Unable to mount device filesystem\n");
    113                 devmap_null_destroy(null_id);
    114                 return false;
    115         case ENOENT:
    116                 printf(NAME ": Unknown filesystem type (devfs)\n");
    117                 devmap_null_destroy(null_id);
    118                 return false;
    119         default:
    120                 printf(NAME ": Error mounting device filesystem (%d)\n", rc);
    121                 devmap_null_destroy(null_id);
    122                 return false;
    123         }
    124        
    125         return true;
    126 }
    127 
    128 static void spawn(char *fname)
    129 {
    130         char *argv[2];
     117        int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
     118            IPC_FLAG_BLOCKING);
     119        return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
     120            NULL, rc);
     121}
     122
     123static void spawn(const char *fname)
     124{
     125        int rc;
    131126        struct stat s;
    132127       
     
    134129                return;
    135130       
    136         printf(NAME ": Spawning %s\n", fname);
    137        
    138         argv[0] = fname;
    139         argv[1] = NULL;
    140        
    141         if (!task_spawn(fname, argv))
    142                 printf(NAME ": Error spawning %s\n", fname);
    143 }
    144 
    145 static void srv_start(char *fname)
    146 {
    147         char *argv[2];
     131        printf("%s: Spawning %s\n", NAME, fname);
     132        rc = task_spawnl(NULL, fname, fname, NULL);
     133        if (rc != EOK) {
     134                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     135                    str_error(rc));
     136        }
     137}
     138
     139static void srv_start(const char *fname)
     140{
    148141        task_id_t id;
    149142        task_exit_t texit;
     
    154147                return;
    155148       
    156         printf(NAME ": Starting %s\n", fname);
    157        
    158         argv[0] = fname;
    159         argv[1] = NULL;
    160        
    161         id = task_spawn(fname, argv);
     149        printf("%s: Starting %s\n", NAME, fname);
     150        rc = task_spawnl(&id, fname, fname, NULL);
    162151        if (!id) {
    163                 printf(NAME ": Error spawning %s\n", fname);
    164                 return;
    165         }
    166 
     152                printf("%s: Error spawning %s (%s)\n", NAME, fname,
     153                    str_error(rc));
     154                return;
     155        }
     156       
    167157        rc = task_wait(id, &texit, &retval);
    168158        if (rc != EOK) {
    169                 printf(NAME ": Error waiting for %s\n", fname);
    170                 return;
    171         }
    172 
    173         if (texit != TASK_EXIT_NORMAL || retval != 0) {
    174                 printf(NAME ": Server %s failed to start (returned %d)\n",
     159                printf("%s: Error waiting for %s (%s(\n", NAME, fname,
     160                    str_error(rc));
     161                return;
     162        }
     163       
     164        if (texit != TASK_EXIT_NORMAL) {
     165                printf("%s: Server %s failed to start (unexpectedly "
     166                    "terminated)\n", NAME, fname);
     167                return;
     168        }
     169
     170        if (retval != 0) {
     171                printf("%s: Server %s failed to start (exit code %d)\n", NAME,
    175172                        fname, retval);
    176173        }
    177174}
    178175
    179 static void getvc(char *dev, char *app)
    180 {
    181         char *argv[4];
    182         char vc[MAX_DEVICE_NAME];
     176static void console(const char *dev)
     177{
     178        char hid_in[DEVMAP_NAME_MAXLEN];
    183179        int rc;
    184180       
    185         snprintf(vc, MAX_DEVICE_NAME, "/dev/%s", dev);
    186        
    187         printf(NAME ": Spawning getvc on %s\n", vc);
    188        
    189         dev_handle_t handle;
     181        snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
     182       
     183        printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
     184       
     185        /* Wait for the input device to be ready */
     186        devmap_handle_t handle;
    190187        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    191        
    192         if (rc == EOK) {
    193                 argv[0] = "/app/getvc";
    194                 argv[1] = vc;
    195                 argv[2] = app;
    196                 argv[3] = NULL;
    197                
    198                 if (!task_spawn("/app/getvc", argv))
    199                         printf(NAME ": Error spawning getvc on %s\n", vc);
     188        if (rc != EOK) {
     189                printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
     190                    str_error(rc));
     191                return;
     192        }
     193       
     194        rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);
     195        if (rc != EOK) {
     196                printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
     197                    hid_in, str_error(rc));
     198        }
     199}
     200
     201static void getterm(const char *dev, const char *app, bool wmsg)
     202{
     203        char term[DEVMAP_NAME_MAXLEN];
     204        int rc;
     205       
     206        snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
     207       
     208        printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
     209       
     210        /* Wait for the terminal device to be ready */
     211        devmap_handle_t handle;
     212        rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
     213        if (rc != EOK) {
     214                printf("%s: Error waiting on %s (%s)\n", NAME, term,
     215                    str_error(rc));
     216                return;
     217        }
     218       
     219        if (wmsg) {
     220                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, "-w", term,
     221                    app, NULL);
     222                if (rc != EOK) {
     223                        printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
     224                            APP_GETTERM, term, app, str_error(rc));
     225                }
    200226        } else {
    201                 printf(NAME ": Error waiting on %s\n", vc);
    202         }
    203 }
    204 
    205 static void mount_data(void)
    206 {
    207         int rc;
    208 
    209         printf("Trying to mount disk0 on /data... ");
    210         fflush(stdout);
    211 
    212         rc = mount("fat", "/data", "disk0", "wtcache", 0);
    213         if (rc == EOK)
    214                 printf("OK\n");
    215         else
    216                 printf("Failed\n");
     227                rc = task_spawnl(NULL, APP_GETTERM, APP_GETTERM, term, app,
     228                    NULL);
     229                if (rc != EOK) {
     230                        printf("%s: Error spawning %s %s %s (%s)\n", NAME,
     231                            APP_GETTERM, term, app, str_error(rc));
     232                }
     233        }
     234}
     235
     236static bool mount_tmpfs(void)
     237{
     238        int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0);
     239        return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
     240            TMPFS_FS_TYPE, NULL, rc);
     241}
     242
     243static bool mount_data(void)
     244{
     245        int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
     246        return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
     247            DATA_DEVICE, rc);
    217248}
    218249
     
    222253       
    223254        if (!mount_root(STRING(RDFMT))) {
    224                 printf(NAME ": Exiting\n");
     255                printf("%s: Exiting\n", NAME);
    225256                return -1;
    226257        }
    227258       
     259        /* Make sure tmpfs is running. */
     260        if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
     261                spawn("/srv/tmpfs");
     262        }
     263       
    228264        spawn("/srv/devfs");
     265        spawn("/srv/taskmon");
    229266       
    230267        if (!mount_devfs()) {
    231                 printf(NAME ": Exiting\n");
     268                printf("%s: Exiting\n", NAME);
    232269                return -2;
    233270        }
     271       
     272        mount_tmpfs();
     273       
     274        spawn("/srv/apic");
     275        spawn("/srv/i8259");
     276        spawn("/srv/fhc");
     277        spawn("/srv/obio");
     278        srv_start("/srv/cuda_adb");
     279        srv_start("/srv/i8042");
     280        srv_start("/srv/s3c24ser");
     281        srv_start("/srv/adb_ms");
     282        srv_start("/srv/char_ms");
     283        srv_start("/srv/s3c24ts");
    234284       
    235285        spawn("/srv/fb");
    236286        spawn("/srv/kbd");
    237         spawn("/srv/console");
    238         spawn("/srv/fhc");
    239         spawn("/srv/obio");
    240 
     287        console("hid_in/kbd");
     288       
     289        spawn("/srv/clip");
     290       
    241291        /*
    242292         * Start these synchronously so that mount_data() can be
     
    249299        (void) srv_start;
    250300#endif
    251 
     301       
    252302#ifdef CONFIG_MOUNT_DATA
    253303        mount_data();
     
    255305        (void) mount_data;
    256306#endif
    257 
    258         getvc("vc0", "/app/bdsh");
    259         getvc("vc1", "/app/bdsh");
    260         getvc("vc2", "/app/bdsh");
    261         getvc("vc3", "/app/bdsh");
    262         getvc("vc4", "/app/bdsh");
    263         getvc("vc5", "/app/bdsh");
    264         getvc("vc6", "/app/klog");
     307       
     308        getterm("term/vc0", "/app/bdsh", true);
     309        getterm("term/vc1", "/app/bdsh", false);
     310        getterm("term/vc2", "/app/bdsh", false);
     311        getterm("term/vc3", "/app/bdsh", false);
     312        getterm("term/vc4", "/app/bdsh", false);
     313        getterm("term/vc5", "/app/bdsh", false);
     314        getterm("term/vc6", "/app/klog", false);
    265315       
    266316        return 0;
  • uspace/app/init/init.h

    rb50b5af2 r04803bf  
    3939#define NAME  "init"
    4040
    41 #define MAX_DEVICE_NAME  32
    42 
    4341#endif
    4442
  • uspace/app/kill/Makefile

    rb50b5af2 r04803bf  
    11#
    2 # Copyright (c) 2005 Jakub Jermar
     2# Copyright (c) 2010 Jiri Svoboda
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 .text
     29USPACE_PREFIX = ../..
     30LIBS =
     31EXTRA_CFLAGS =
     32BINARY = kill
    3033
    31 #include <arch/stack.h>
     34SOURCES = \
     35        kill.c
    3236
    33 .global panic_printf
    34 panic_printf:
    35         call printf
    36         nop
    37         call halt
    38         nop
    39         /* Not reached. */
    40 
     37include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/klog/Makefile

    rb50b5af2 r04803bf  
    11#
    22# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 ## Setup toolchain
    30 #
     30USPACE_PREFIX = ../..
     31BINARY = klog
    3132
    32 LIBC_PREFIX = ../../lib/libc
    33 SOFTINT_PREFIX = ../../lib/softint
    34 
    35 include $(LIBC_PREFIX)/Makefile.toolchain
    36 include $(LIBC_PREFIX)/Makefile.app
    37 
    38 ## Sources
    39 #
    40 
    41 OUTPUT = klog
    4233SOURCES = \
    4334        klog.c
    4435
    45 
    46 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    47 
    48 .PHONY: all clean depend disasm
    49 
    50 all: $(OUTPUT) $(OUTPUT).disasm
    51 
    52 -include Makefile.depend
    53 
    54 clean:
    55         -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend $(OBJECTS)
    56 
    57 depend:
    58         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    59 
    60 $(OUTPUT): $(OBJECTS) $(LIBS)
    61         $(LD) -T $(LD_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    62 
    63 disasm: $(OUTPUT).disasm
    64 
    65 $(OUTPUT).disasm: $(OUTPUT)
    66         $(OBJDUMP) -d $< > $@
    67 
    68 %.o: %.S
    69         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    70 
    71 %.o: %.s
    72         $(AS) $(AFLAGS) $< -o $@
    73 
    74 %.o: %.c
    75         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     36include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/klog/klog.c

    rb50b5af2 r04803bf  
    3636
    3737#include <stdio.h>
    38 #include <ipc/ipc.h>
    3938#include <async.h>
    40 #include <ipc/services.h>
    4139#include <as.h>
    42 #include <sysinfo.h>
     40#include <ddi.h>
    4341#include <event.h>
    4442#include <errno.h>
     43#include <str_error.h>
    4544#include <io/klog.h>
     45#include <sysinfo.h>
    4646
    47 #define NAME  "klog"
     47#define NAME       "klog"
     48#define LOG_FNAME  "/log/klog"
    4849
    4950/* Pointer to klog area */
    5051static wchar_t *klog;
    5152static size_t klog_length;
     53
     54static FILE *log;
    5255
    5356static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     
    5861        size_t i;
    5962       
    60         for (i = klog_len - klog_stored; i < klog_len; i++)
    61                 putchar(klog[(klog_start + i) % klog_length]);
     63        for (i = klog_len - klog_stored; i < klog_len; i++) {
     64                wchar_t ch = klog[(klog_start + i) % klog_length];
     65               
     66                putchar(ch);
     67               
     68                if (log != NULL)
     69                        fputc(ch, log);
     70        }
     71       
     72        if (log != NULL) {
     73                fflush(log);
     74                fsync(fileno(log));
     75        }
    6276}
    6377
    6478int main(int argc, char *argv[])
    6579{
    66         size_t klog_pages = sysinfo_value("klog.pages");
    67         size_t klog_size = klog_pages * PAGE_SIZE;
    68         klog_length = klog_size / sizeof(wchar_t);
    69        
    70         klog = (wchar_t *) as_get_mappable_page(klog_size);
    71         if (klog == NULL) {
    72                 printf(NAME ": Error allocating memory area\n");
    73                 return -1;
    74         }
    75 
    76         printf("got area at 0x%08lx, length %lx byes\n", klog, klog_size);
    77        
    78         int res = ipc_share_in_start_1_0(PHONE_NS, (void *) klog,
    79             klog_size, SERVICE_MEM_KLOG);
    80         if (res != EOK) {
    81                 printf(NAME ": Error initializing memory area\n");
    82                 return -1;
     80        size_t pages;
     81        int rc = sysinfo_get_value("klog.pages", &pages);
     82        if (rc != EOK) {
     83                fprintf(stderr, "%s: Unable to get number of klog pages\n",
     84                    NAME);
     85                return rc;
    8386        }
    8487       
    85         if (event_subscribe(EVENT_KLOG, 0) != EOK) {
    86                 printf(NAME ": Error registering klog notifications\n");
    87                 return -1;
     88        uintptr_t faddr;
     89        rc = sysinfo_get_value("klog.faddr", &faddr);
     90        if (rc != EOK) {
     91                fprintf(stderr, "%s: Unable to get klog physical address\n",
     92                    NAME);
     93                return rc;
    8894        }
     95       
     96        size_t size = pages * PAGE_SIZE;
     97        klog_length = size / sizeof(wchar_t);
     98       
     99        klog = (wchar_t *) as_get_mappable_page(size);
     100        if (klog == NULL) {
     101                fprintf(stderr, "%s: Unable to allocate virtual memory area\n",
     102                    NAME);
     103                return ENOMEM;
     104        }
     105       
     106        rc = physmem_map((void *) faddr, (void *) klog, pages,
     107            AS_AREA_READ | AS_AREA_CACHEABLE);
     108        if (rc != EOK) {
     109                fprintf(stderr, "%s: Unable to map klog\n", NAME);
     110                return rc;
     111        }
     112       
     113        rc = event_subscribe(EVENT_KLOG, 0);
     114        if (rc != EOK) {
     115                fprintf(stderr, "%s: Unable to register klog notifications\n",
     116                    NAME);
     117                return rc;
     118        }
     119       
     120        /*
     121         * Mode "a" would be definitively much better here, but it is
     122         * not well supported by the FAT driver.
     123         */
     124        log = fopen(LOG_FNAME, "w");
     125        if (log == NULL)
     126                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
     127                    str_error(errno));
    89128       
    90129        async_set_interrupt_received(interrupt_received);
  • uspace/app/netecho/print_error.h

    rb50b5af2 r04803bf  
    11/*
    2  * Copyright (c) 2005 Jakub Jermar
     2 * Copyright (c) 2009 Lukas Mejdrech
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup net_app
    3030 * @{
    3131 */
     32
    3233/** @file
     34 * Generic application error printing functions.
    3335 */
    3436
    35 #ifndef LIBC_ia64_ATOMIC_H_
    36 #define LIBC_ia64_ATOMIC_H_
     37#ifndef NET_APP_PRINT_
     38#define NET_APP_PRINT_
    3739
    38 /** Atomic addition.
     40#include <stdio.h>
     41
     42/** Returns whether the error code may be an ICMP error code.
    3943 *
    40  * @param val Atomic value.
    41  * @param imm Value to add.
     44 * @param[in] error_code The error code.
     45 * @return A value indicating whether the error code may be an ICMP error code.
     46 */
     47#define IS_ICMP_ERROR(error_code)       ((error_code) > 0)
     48
     49/** Returns whether the error code may be socket error code.
    4250 *
    43  * @return Value before addition.
     51 * @param[in] error_code The error code.
     52 * @return A value indicating whether the error code may be a socket error code.
    4453 */
    45 static inline long atomic_add(atomic_t *val, int imm)
    46 {
    47         long v;
     54#define IS_SOCKET_ERROR(error_code)     ((error_code) < 0)
    4855
    49         asm volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v), "+m" (val->count) : "i" (imm));
    50  
    51         return v;
    52 }
    53 
    54 static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
    55 static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
    56 
    57 static inline long atomic_preinc(atomic_t *val) { return atomic_add(val, 1) + 1; }
    58 static inline long atomic_predec(atomic_t *val) { return atomic_add(val, -1) - 1; }
    59 
    60 static inline long atomic_postinc(atomic_t *val) { return atomic_add(val, 1); }
    61 static inline long atomic_postdec(atomic_t *val) { return atomic_add(val, -1); }
     56extern void icmp_print_error(FILE *, int, const char *, const char *);
     57extern void print_error(FILE *, int, const char *, const char *);
     58extern void socket_print_error(FILE *, int, const char *, const char *);
    6259
    6360#endif
  • uspace/app/nettest1/nettest.h

    rb50b5af2 r04803bf  
    11/*
    2  * Copyright (c) 2005 Jakub Jermar
     2 * Copyright (c) 2009 Lukas Mejdrech
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup mips32 
     29/** @addtogroup nettest
    3030 * @{
    3131 */
     32
    3233/** @file
     34 * Networking test support functions.
    3335 */
    3436
    35 #ifndef KERN_mips32_ARG_H_
    36 #define KERN_mips32_ARG_H_
     37#ifndef NET_TEST_
     38#define NET_TEST_
    3739
    38 #include <arch/types.h>
     40#include <net/socket.h>
    3941
    40 /**
    41  * va_arg macro for MIPS32 - problem is that 64 bit values must be aligned on an 8-byte boundary (32bit values not)
    42  * To satisfy this, paddings must be sometimes inserted.
    43  */
    44 
    45 typedef uintptr_t va_list;
    46 
    47 #define va_start(ap, lst) \
    48         ((ap) = (va_list)&(lst) + sizeof(lst))
    49 
    50 #define va_arg(ap, type)        \
    51         (((type *)((ap) = (va_list)( (sizeof(type) <= 4) ? ((uintptr_t)((ap) + 2*4 - 1) & (~3)) : ((uintptr_t)((ap) + 2*8 -1) & (~7)) )))[-1])
    52 
    53 #define va_copy(dst,src) ((dst)=(src))
    54 
    55 #define va_end(ap)
     42extern void print_mark(int);
     43extern int sockets_create(int, int *, int, int, sock_type_t);
     44extern int sockets_close(int, int *, int);
     45extern int sockets_connect(int, int *, int, struct sockaddr *, socklen_t);
     46extern int sockets_sendto(int, int *, int, struct sockaddr *, socklen_t, char *, int, int);
     47extern int sockets_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int);
     48extern int sockets_sendto_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int);
    5649
    5750#endif
     
    5952/** @}
    6053 */
     54
  • uspace/app/sbi/Makefile

    rb50b5af2 r04803bf  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
     2# Copyright (c) 2010 Jiri Svoboda
    43# All rights reserved.
    54#
     
    2827#
    2928
    30 ## Common compiler flags
    31 #
     29USPACE_PREFIX = ../..
     30LIBS = $(LIBCLUI_PREFIX)/libclui.a
     31EXTRA_CFLAGS = -D__HELENOS__ -I$(LIBCLUI_PREFIX)
    3232
    33 LIBC_PREFIX = ../libc
    34 
    35 ## Setup toolchain
    36 #
    37 
    38 include $(LIBC_PREFIX)/Makefile.toolchain
    39 
    40 CFLAGS += -Iinclude
    41 
    42 ## Sources
    43 #
     33BINARY = sbi
    4434
    4535SOURCES = \
    46         libblock.c
     36        src/builtin/bi_boxed.c \
     37        src/builtin/bi_error.c \
     38        src/builtin/bi_char.c \
     39        src/builtin/bi_console.c \
     40        src/builtin/bi_int.c \
     41        src/builtin/bi_task.c \
     42        src/builtin/bi_textfile.c \
     43        src/builtin/bi_string.c \
     44        src/os/helenos.c \
     45        src/ancr.c \
     46        src/bigint.c \
     47        src/builtin.c \
     48        src/cspan.c \
     49        src/imode.c \
     50        src/input.c \
     51        src/intmap.c \
     52        src/lex.c \
     53        src/list.c \
     54        src/main.c \
     55        src/p_expr.c \
     56        src/p_type.c \
     57        src/parse.c \
     58        src/program.c \
     59        src/rdata.c \
     60        src/run.c \
     61        src/run_expr.c \
     62        src/run_texpr.c \
     63        src/stree.c \
     64        src/strtab.c \
     65        src/stype.c \
     66        src/stype_expr.c \
     67        src/symbol.c \
     68        src/tdata.c
    4769
    48 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    49 
    50 .PHONY: all clean depend
    51 
    52 all: libblock.a
    53 
    54 -include Makefile.depend
    55 
    56 clean:
    57         -rm -f libblock.a Makefile.depend
    58         find . -name '*.o' -follow -exec rm \{\} \;
    59 
    60 depend:
    61         -makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > Makefile.depend 2> /dev/null
    62 
    63 libblock.a: depend $(OBJECTS)
    64         $(AR) rc libblock.a $(OBJECTS)
    65 
    66 %.o: %.c
    67         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     70include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/sbi/src/lex.h

    rb50b5af2 r04803bf  
    11/*
    2  * Copyright (c) 2006 Martin Decky
     2 * Copyright (c) 2010 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #ifndef BOOT_ia64_TYPES_H_
    30 #define BOOT_ia64_TYPES_H_
     29#ifndef LEX_H_
     30#define LEX_H_
    3131
    32 #include <gentypes.h>
     32#include "mytypes.h"
    3333
    34 typedef signed char int8_t;
     34void lclass_print(lclass_t lclass);
     35void lem_print(lem_t *lem);
     36void lem_print_coords(lem_t *lem);
    3537
    36 typedef unsigned char uint8_t;
    37 typedef unsigned short uint16_t;
    38 typedef unsigned int uint32_t;
    39 typedef unsigned long uint64_t;
    40 
    41 typedef uint64_t uintptr_t;
    42 typedef uint64_t unative_t;
     38void lex_init(lex_t *lex, struct input *input);
     39void lex_next(lex_t *lex);
     40lem_t *lex_get_current(lex_t *lex);
     41lem_t *lex_peek_prev(lex_t *lex);
    4342
    4443#endif
  • uspace/app/tester/Makefile

    rb50b5af2 r04803bf  
    11#
    22# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 ## Setup toolchain
    30 #
     30USPACE_PREFIX = ../..
     31BINARY = tester
    3132
    32 LIBC_PREFIX = ../../lib/libc
    33 SOFTINT_PREFIX = ../../lib/softint
    34 
    35 include $(LIBC_PREFIX)/Makefile.toolchain
    36 include $(LIBC_PREFIX)/Makefile.app
    37 
    38 CFLAGS += -I../../srv/kbd/include
    39 
    40 ## Sources
    41 #
    42 
    43 OUTPUT = tester
    44 SOURCES = tester.c \
     33SOURCES = \
     34        tester.c \
    4535        thread/thread1.c \
    4636        print/print1.c \
     
    4838        print/print3.c \
    4939        print/print4.c \
     40        print/print5.c \
    5041        console/console1.c \
    5142        stdio/stdio1.c \
     
    5344        fault/fault1.c \
    5445        fault/fault2.c \
     46        fault/fault3.c \
    5547        vfs/vfs1.c \
    5648        ipc/ping_pong.c \
    57         ipc/register.c \
    58         ipc/connect.c \
    5949        loop/loop1.c \
    60         mm/malloc1.c
     50        mm/malloc1.c \
     51        hw/misc/virtchar1.c \
     52        hw/serial/serial1.c
    6153
    62 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    63 
    64 .PHONY: all clean depend disasm
    65 
    66 all: $(OUTPUT) $(OUTPUT).disasm
    67 
    68 -include Makefile.depend
    69 
    70 clean:
    71         -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend $(OBJECTS)
    72 
    73 depend:
    74         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    75 
    76 $(OUTPUT): $(OBJECTS) $(LIBS)
    77         $(LD) -T $(LD_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    78 
    79 disasm: $(OUTPUT).disasm
    80 
    81 $(OUTPUT).disasm: $(OUTPUT)
    82         $(OBJDUMP) -d $< > $@
    83 
    84 %.o: %.S
    85         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    86 
    87 %.o: %.s
    88         $(AS) $(AFLAGS) $< -o $@
    89 
    90 %.o: %.c
    91         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     54include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/console/console1.c

    rb50b5af2 r04803bf  
    3636#include "../tester.h"
    3737
    38 const char *color_name[] = {
     38static const char *color_name[] = {
    3939        [COLOR_BLACK] = "black",
    4040        [COLOR_BLUE] = "blue",
     
    4747};
    4848
    49 char *test_console1(void)
     49const char *test_console1(void)
    5050{
    5151        if (!test_quiet) {
     
    5353                fflush(stdout);
    5454                console_set_style(fphone(stdout), STYLE_NORMAL);
    55                 printf("normal ");
     55                printf(" normal ");
    5656                fflush(stdout);
    5757                console_set_style(fphone(stdout), STYLE_EMPHASIS);
    58                 printf("emphasized");
     58                printf(" emphasized ");
     59                fflush(stdout);
     60                console_set_style(fphone(stdout), STYLE_INVERTED);
     61                printf(" inverted ");
     62                fflush(stdout);
     63                console_set_style(fphone(stdout), STYLE_SELECTED);
     64                printf(" selected ");
    5965                fflush(stdout);
    6066                console_set_style(fphone(stdout), STYLE_NORMAL);
    61                 printf(".\n");
     67                printf("\n");
    6268               
    6369                unsigned int i;
     
    7379                        }
    7480                        fflush(stdout);
    75                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     81                        console_set_style(fphone(stdout), STYLE_NORMAL);
    7682                        putchar('\n');
    7783                }
     
    8692                        }
    8793                        fflush(stdout);
    88                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     94                        console_set_style(fphone(stdout), STYLE_NORMAL);
    8995                        putchar('\n');
    9096                }
     
    94100                for (i = 0; i < 255; i += 16) {
    95101                        fflush(stdout);
    96                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
     102                        console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
    97103                        putchar('X');
    98104                }
     
    103109                for (i = 0; i < 255; i += 16) {
    104110                        fflush(stdout);
    105                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
     111                        console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
    106112                        putchar('X');
    107113                }
     
    112118                for (i = 0; i < 255; i += 16) {
    113119                        fflush(stdout);
    114                         console_set_rgb_color(fphone(stdout), 0xffffff, i);
     120                        console_set_rgb_color(fphone(stdout), 255 - i, i);
    115121                        putchar('X');
    116122                }
    117123                fflush(stdout);
    118                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     124                console_set_style(fphone(stdout), STYLE_NORMAL);
    119125                putchar('\n');
    120126        }
  • uspace/app/tester/fault/fault1.c

    rb50b5af2 r04803bf  
    3030#include "../tester.h"
    3131
    32 char *test_fault1(void)
     32const char *test_fault1(void)
    3333{
    3434        ((int *)(0))[1] = 0;
  • uspace/app/tester/fault/fault2.c

    rb50b5af2 r04803bf  
    3030#include "../tester.h"
    3131
    32 char *test_fault2(void)
     32typedef int __attribute__((may_alias)) aliasing_int;
     33
     34const char *test_fault2(void)
    3335{
    3436        volatile long long var;
    3537        volatile int var1;
    3638       
    37         var1 = *((int *) (((char *) (&var)) + 1));
     39        var1 = *((aliasing_int *) (((char *) (&var)) + 1));
    3840       
    3941        return "Survived unaligned read";
  • uspace/app/tester/ipc/ping_pong.c

    rb50b5af2 r04803bf  
    3838#define COUNT_GRANULARITY  100
    3939
    40 char *test_ping_pong(void)
     40const char *test_ping_pong(void)
    4141{
    4242        TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS);
     
    7272        }
    7373       
    74         TPRINTF("OK\nCompleted %llu round trips in %u seconds, %llu rt/s.\n",
     74        TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n",
    7575            count, DURATION_SECS, count / DURATION_SECS);
    7676       
  • uspace/app/tester/loop/loop1.c

    rb50b5af2 r04803bf  
    3131#include "../tester.h"
    3232
    33 char *test_loop1(void)
     33const char *test_loop1(void)
    3434{
    3535        TPRINTF("Looping...");
  • uspace/app/tester/mm/malloc1.c

    rb50b5af2 r04803bf  
    7373
    7474typedef struct {
    75         char *name;
     75        const char *name;
    7676        sp_term_cond_s cond;
    7777        sp_action_prob_s prob;
     
    9090
    9191typedef struct {
    92         char *name;
     92        const char *name;
    9393        ph_alloc_size_s alloc;
    9494        subphase_s *subphases;
     
    628628}
    629629
    630 char *test_malloc1(void)
     630const char *test_malloc1(void)
    631631{
    632632        init_mem();
  • uspace/app/tester/print/print1.c

    rb50b5af2 r04803bf  
    3131#include "../tester.h"
    3232
    33 char *test_print1(void)
     33const char *test_print1(void)
    3434{
    3535        TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
     
    4949        TPRINTF("Real output:     \"%8.10s\"\n\n", "very long text");
    5050       
    51         TPRINTF("Testing printf(\"%%s\", NULL):\n");
    52         TPRINTF("Expected output: \"(NULL)\"\n");
    53         TPRINTF("Real output:     \"%s\"\n\n", NULL);
    54        
    5551        return NULL;
    5652}
  • uspace/app/tester/print/print2.c

    rb50b5af2 r04803bf  
    3131#include "../tester.h"
    3232
    33 char *test_print2(void)
     33const char *test_print2(void)
    3434{
    35         TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
    36         TPRINTF("Expected output: [a] [  b] [c  ] [ d] [e ]\n");
    37         TPRINTF("Real output:     [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
     35        TPRINTF("Testing printf(\"%%c\", 'a'):\n");
     36        TPRINTF("Expected output: [a]\n");
     37        TPRINTF("Real output:     [%c]\n\n", 'a');
    3838       
    3939        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
  • uspace/app/tester/print/print3.c

    rb50b5af2 r04803bf  
    3434#define BUFFER_SIZE  32
    3535
    36 char *test_print3(void)
     36const char *test_print3(void)
    3737{
    3838        char buffer[BUFFER_SIZE];
  • uspace/app/tester/print/print4.c

    rb50b5af2 r04803bf  
    3131#include "../tester.h"
    3232
    33 char *test_print4(void)
     33const char *test_print4(void)
    3434{
    3535        TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
     
    4545                TPRINTF("  ");
    4646                for (index = 0; index < 32; index++)
    47                         TPRINTF("%lc", (wchar_t) ((group << 5) + index));
     47                        TPRINTF("%lc", (wint_t) ((group << 5) + index));
    4848               
    4949                TPRINTF("\n");
     
    5757                uint8_t index;
    5858                for (index = 0; index < 32; index++)
    59                         TPRINTF("%lc", (wchar_t) ((group << 5) + index));
     59                        TPRINTF("%lc", (wint_t) ((group << 5) + index));
    6060               
    6161                TPRINTF("\n");
  • uspace/app/tester/stdio/stdio1.c

    rb50b5af2 r04803bf  
    3636static char buf[BUF_SIZE + 1];
    3737
    38 char *test_stdio1(void)
     38const char *test_stdio1(void)
    3939{
    4040        FILE *file;
    41         char *file_name = "/readme";
     41        const char *file_name = "/readme";
    4242       
    4343        TPRINTF("Open file \"%s\"...", file_name);
     
    6060       
    6161        buf[cnt] = '\0';
    62         TPRINTF("Read %u bytes, string \"%s\"\n", cnt, buf);
     62        TPRINTF("Read %zu bytes, string \"%s\"\n", cnt, buf);
    6363       
    6464        TPRINTF("Seek to beginning...");
  • uspace/app/tester/stdio/stdio2.c

    rb50b5af2 r04803bf  
    3232#include "../tester.h"
    3333
    34 char *test_stdio2(void)
     34const char *test_stdio2(void)
    3535{
    3636        FILE *file;
    37         char *file_name = "/test";
     37        const char *file_name = "/test";
    3838       
    3939        TPRINTF("Open file \"%s\" for writing...", file_name);
  • uspace/app/tester/tester.c

    rb50b5af2 r04803bf  
    3838#include <unistd.h>
    3939#include <stdio.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include "tester.h"
    4242
     
    5151#include "print/print3.def"
    5252#include "print/print4.def"
     53#include "print/print5.def"
    5354#include "console/console1.def"
    5455#include "stdio/stdio1.def"
     
    5657#include "fault/fault1.def"
    5758#include "fault/fault2.def"
     59#include "fault/fault3.def"
    5860#include "vfs/vfs1.def"
    5961#include "ipc/ping_pong.def"
    60 #include "ipc/register.def"
    61 #include "ipc/connect.def"
    6262#include "loop/loop1.def"
    6363#include "mm/malloc1.def"
     64#include "hw/serial/serial1.def"
     65#include "hw/misc/virtchar1.def"
    6466        {NULL, NULL, NULL, false}
    6567};
     
    6870{
    6971        /* Execute the test */
    70         char *ret = test->entry();
     72        const char *ret = test->entry();
    7173       
    7274        if (ret == NULL) {
     
    109111        }
    110112       
     113        unsigned int _len = (unsigned int) len;
     114        if ((_len != len) || (((int) _len) < 0)) {
     115                printf("Command length overflow\n");
     116                return;
     117        }
     118       
    111119        for (test = tests; test->name != NULL; test++)
    112                 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
     120                printf("%-*s %s%s\n", _len, test->name, test->desc,
     121                    (test->safe ? "" : " (unsafe)"));
    113122       
    114         printf("%-*s Run all safe tests\n", len, "*");
     123        printf("%-*s Run all safe tests\n", _len, "*");
    115124}
    116125
  • uspace/app/tester/tester.h

    rb50b5af2 r04803bf  
    3838#include <sys/types.h>
    3939#include <bool.h>
    40 #include <ipc/ipc.h>
    4140
    4241#define IPC_TEST_SERVICE  10240
     
    5453        }
    5554
    56 typedef char *(*test_entry_t)(void);
     55typedef const char *(*test_entry_t)(void);
    5756
    5857typedef struct {
    59         char *name;
    60         char *desc;
     58        const char *name;
     59        const char *desc;
    6160        test_entry_t entry;
    6261        bool safe;
    6362} test_t;
    6463
    65 extern char *test_thread1(void);
    66 extern char *test_print1(void);
    67 extern char *test_print2(void);
    68 extern char *test_print3(void);
    69 extern char *test_print4(void);
    70 extern char *test_console1(void);
    71 extern char *test_stdio1(void);
    72 extern char *test_stdio2(void);
    73 extern char *test_fault1(void);
    74 extern char *test_fault2(void);
    75 extern char *test_vfs1(void);
    76 extern char *test_ping_pong(void);
    77 extern char *test_register(void);
    78 extern char *test_connect(void);
    79 extern char *test_loop1(void);
    80 extern char *test_malloc1(void);
     64extern const char *test_thread1(void);
     65extern const char *test_print1(void);
     66extern const char *test_print2(void);
     67extern const char *test_print3(void);
     68extern const char *test_print4(void);
     69extern const char *test_print5(void);
     70extern const char *test_console1(void);
     71extern const char *test_stdio1(void);
     72extern const char *test_stdio2(void);
     73extern const char *test_fault1(void);
     74extern const char *test_fault2(void);
     75extern const char *test_fault3(void);
     76extern const char *test_vfs1(void);
     77extern const char *test_ping_pong(void);
     78extern const char *test_loop1(void);
     79extern const char *test_malloc1(void);
     80extern const char *test_serial1(void);
     81extern const char *test_virtchar1(void);
    8182
    8283extern test_t tests[];
  • uspace/app/tester/thread/thread1.c

    rb50b5af2 r04803bf  
    3535#include <stdio.h>
    3636#include <unistd.h>
     37#include <inttypes.h>
    3738#include "../tester.h"
    3839
     
    5051}
    5152
    52 char *test_thread1(void)
     53const char *test_thread1(void)
    5354{
    5455        unsigned int i;
    55         int total = 0;
     56        atomic_count_t total = 0;
    5657       
    5758        atomic_set(&finish, 1);
     
    7475        atomic_set(&finish, 0);
    7576        while (atomic_get(&threads_finished) < total) {
    76                 TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished));
     77                TPRINTF("Threads left: %" PRIua "\n",
     78                    total - atomic_get(&threads_finished));
    7779                sleep(1);
    7880        }
  • uspace/app/tester/vfs/vfs1.c

    rb50b5af2 r04803bf  
    3030#include <stdio.h>
    3131#include <stdlib.h>
    32 #include <string.h>
     32#include <str.h>
    3333#include <vfs/vfs.h>
    3434#include <unistd.h>
     
    4040#include "../tester.h"
    4141
    42 #define FS_TYPE      "tmpfs"
    43 #define MOUNT_POINT  "/tmp"
    44 #define OPTIONS      ""
    45 #define FLAGS        0
    46 
    47 #define TEST_DIRECTORY  MOUNT_POINT "/testdir"
     42#define TEST_DIRECTORY  "/tmp/testdir"
    4843#define TEST_FILE       TEST_DIRECTORY "/testfile"
    4944#define TEST_FILE2      TEST_DIRECTORY "/nextfile"
     
    5449static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
    5550
    56 static char *read_root(void)
     51static const char *read_root(void)
    5752{
    5853        TPRINTF("Opening the root directory...");
     
    7368}
    7469
    75 char *test_vfs1(void)
     70const char *test_vfs1(void)
    7671{
    77         if (mkdir(MOUNT_POINT, 0) != 0)
     72        int rc;
     73        if ((rc = mkdir(TEST_DIRECTORY, 0)) != 0) {
     74                TPRINTF("rc=%d\n", rc);
    7875                return "mkdir() failed";
    79         TPRINTF("Created directory %s\n", MOUNT_POINT);
    80        
    81         char null[MAX_DEVICE_NAME];
    82         int null_id = devmap_null_create();
    83        
    84         if (null_id == -1)
    85                 return "Unable to create null device";
    86        
    87         snprintf(null, MAX_DEVICE_NAME, "null%d", null_id);
    88         int rc = mount(FS_TYPE, MOUNT_POINT, null, OPTIONS, FLAGS);
    89         switch (rc) {
    90         case EOK:
    91                 TPRINTF("Mounted /dev/%s as %s on %s\n", null, FS_TYPE, MOUNT_POINT);
    92                 break;
    93         case EBUSY:
    94                 TPRINTF("(INFO) Filesystem already mounted on %s\n", MOUNT_POINT);
    95                 break;
    96         default:
    97                 TPRINTF("(ERR) IPC returned errno %d (is tmpfs loaded?)\n", rc);
    98                 return "mount() failed";
    9976        }
    100        
    101         if (mkdir(TEST_DIRECTORY, 0) != 0)
    102                 return "mkdir() failed";
    10377        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
    10478       
     
    11286        if (cnt < 0)
    11387                return "write() failed";
    114         TPRINTF("Written %d bytes\n", cnt);
     88        TPRINTF("Written %zd bytes\n", cnt);
    11589       
    11690        if (lseek(fd0, 0, SEEK_SET) != 0)
     
    12397                        return "read() failed";
    12498               
    125                 TPRINTF("Read %d bytes: \".*s\"\n", cnt, cnt, buf);
     99                int _cnt = (int) cnt;
     100                if (_cnt != cnt) {
     101                        /* Count overflow, just to be sure. */
     102                        TPRINTF("Read %zd bytes\n", cnt);
     103                } else {
     104                        TPRINTF("Read %zd bytes: \"%.*s\"\n", cnt, _cnt, buf);
     105                }
    126106        }
    127107       
    128108        close(fd0);
    129109       
    130         char *rv = read_root();
     110        const char *rv = read_root();
    131111        if (rv != NULL)
    132112                return rv;
  • uspace/app/tetris/Makefile

    rb50b5af2 r04803bf  
    1 LIBC_PREFIX = ../../lib/libc
    2 SOFTINT_PREFIX = ../../lib/softint
     1#
     2# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
     4# All rights reserved.
     5#
     6# Redistribution and use in source and binary forms, with or without
     7# modification, are permitted provided that the following conditions
     8# are met:
     9#
     10# - Redistributions of source code must retain the above copyright
     11#   notice, this list of conditions and the following disclaimer.
     12# - Redistributions in binary form must reproduce the above copyright
     13#   notice, this list of conditions and the following disclaimer in the
     14#   documentation and/or other materials provided with the distribution.
     15# - The name of the author may not be used to endorse or promote products
     16#   derived from this software without specific prior written permission.
     17#
     18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28#
    329
    4 include $(LIBC_PREFIX)/Makefile.toolchain
    5 include $(LIBC_PREFIX)/Makefile.app
     30USPACE_PREFIX = ../..
     31BINARY = tetris
    632
    7 OUTPUT = tetris
    8 SOURCES = shapes.c scores.c input.c tetris.c screen.c
    9 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
     33SOURCES = \
     34        shapes.c \
     35        scores.c \
     36        input.c \
     37        tetris.c \
     38        screen.c
    1039
    11 .PHONY: all clean depend disasm
    12 
    13 all: $(OUTPUT) $(OUTPUT).disasm
    14 
    15 -include Makefile.depend
    16 
    17 depend:
    18         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    19 
    20 $(OUTPUT): $(OBJECTS) $(LIBS)
    21         $(LD) -T $(LD_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    22 
    23 clean:
    24         -rm -f $(OUTPUT) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend *.o
    25 
    26 disasm: $(OUTPUT).disasm
    27 
    28 $(OUTPUT).disasm: $(OUTPUT)
    29         $(OBJDUMP) -d $< > $@
    30 
    31 %.o: %.S
    32         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    33 
    34 %.o: %.s
    35         $(AS) $(AFLAGS) $< -o $@
    36 
    37 %.o: %.c
    38         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     40include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tetris/input.c

    rb50b5af2 r04803bf  
    5252#include <errno.h>
    5353#include <unistd.h>
    54 #include <string.h>
     54#include <str.h>
    5555
    5656#include "input.h"
     
    9797        struct timeval starttv, endtv, *s;
    9898        static ipc_call_t charcall;
    99         ipcarg_t rc;
     99        sysarg_t rc;
    100100       
    101101        /*
  • uspace/app/tetris/scores.c

    rb50b5af2 r04803bf  
    5252#include <errno.h>
    5353#include <stdio.h>
    54 #include <string.h>
     54#include <str.h>
    5555#include <io/console.h>
    5656#include <io/keycode.h>
  • uspace/app/tetris/scores.h

    rb50b5af2 r04803bf  
    4848
    4949#include <sys/time.h>
    50 #include <string.h>
     50#include <str.h>
    5151
    5252#define MAXLOGNAME   16
  • uspace/app/tetris/screen.c

    rb50b5af2 r04803bf  
    4949#include <stdio.h>
    5050#include <stdlib.h>
    51 #include <string.h>
     51#include <str.h>
    5252#include <unistd.h>
    5353#include <vfs/vfs.h>
    5454#include <async.h>
     55#include <bool.h>
     56#include <io/console.h>
     57#include <io/style.h>
    5558#include "screen.h"
    5659#include "tetris.h"
    57 #include <io/console.h>
    5860
    5961#define STOP  (B_COLS - 3)
     
    6365static int isset;               /* true => terminal is in game mode */
    6466
    65 static int use_color;           /* true => use colors */
     67static bool use_color;          /* true => use colors */
    6668
    6769static const struct shape *lastshape;
     
    7274 * simply literal strings);
    7375 */
    74 static inline void putstr(char *s)
     76static inline void putstr(const char *s)
    7577{
    7678        while (*s)
     
    8183{
    8284        fflush(stdout);
    83         console_set_rgb_color(fphone(stdout), 0xf0f0f0,
     85        console_set_rgb_color(fphone(stdout), 0xffffff,
    8486            use_color ? color : 0x000000);
    8587}
     
    8890{
    8991        fflush(stdout);
    90         console_set_rgb_color(fphone(stdout), 0, 0xf0f0f0);
     92        console_set_style(fphone(stdout), STYLE_NORMAL);
    9193}
    9294
     
    118120}
    119121
    120 void moveto(int r, int c)
     122void moveto(sysarg_t r, sysarg_t c)
    121123{
    122124        fflush(stdout);
    123         console_goto(fphone(stdout), c, r);
     125        console_set_pos(fphone(stdout), c, r);
    124126}
    125127
     
    131133}
    132134
    133 static int get_display_color_sup(void)
    134 {
    135         int rc;
    136         int ccap;
    137 
    138         rc = console_get_color_cap(fphone(stdout), &ccap);
     135static bool get_display_color_sup(void)
     136{
     137        sysarg_t ccap;
     138        int rc = console_get_color_cap(fphone(stdout), &ccap);
     139       
    139140        if (rc != 0)
    140                 return 0;
    141 
     141                return false;
     142       
    142143        return (ccap >= CONSOLE_CCAP_RGB);
    143144}
     
    181182}
    182183
    183 void stop(char *why)
     184void stop(const char *why)
    184185{
    185186        if (isset)
     
    308309 * (We need its length in case we have to overwrite with blanks.)
    309310 */
    310 void scr_msg(char *s, int set)
     311void scr_msg(char *s, bool set)
    311312{
    312313        int l = str_size(s);
  • uspace/app/tetris/screen.h

    rb50b5af2 r04803bf  
    4949#include <sys/types.h>
    5050#include <async.h>
     51#include <bool.h>
    5152
    5253typedef struct {
    53         ipcarg_t ws_row;
    54         ipcarg_t ws_col;
     54        sysarg_t ws_row;
     55        sysarg_t ws_col;
    5556} winsize_t;
    5657
    5758extern winsize_t winsize;
    5859
    59 extern void moveto(int r, int c);
     60extern void moveto(sysarg_t r, sysarg_t c);
    6061extern void clear_screen(void);
    6162
     
    6566extern void scr_end(void);
    6667extern void scr_init(void);
    67 extern void scr_msg(char *, int);
     68extern void scr_msg(char *, bool);
    6869extern void scr_set(void);
    6970extern void scr_update(void);
  • uspace/app/tetris/tetris.c

    rb50b5af2 r04803bf  
    5353#include <stdio.h>
    5454#include <stdlib.h>
    55 #include <string.h>
     55#include <str.h>
    5656#include <unistd.h>
    5757#include <getopt.h>
  • uspace/app/tetris/tetris.h

    rb50b5af2 r04803bf  
    186186extern int fits_in(const struct shape *, int);
    187187extern void place(const struct shape *, int, int);
    188 extern void stop(char *);
     188extern void stop(const char *);
    189189
    190190/** @}
  • uspace/app/top/top.h

    rb50b5af2 r04803bf  
    11/*
    2  * Copyright (c) 2005 Martin Decky
     2 * Copyright (c) 2010 Stanislav Kozina
     3 * Copyright (c) 2010 Martin Decky
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 #ifndef BOOT_sparc64_MAIN_H_
    30 #define BOOT_sparc64_MAIN_H_
     30/** @addtogroup top
     31 * @{
     32 */
    3133
    32 #include <ofw.h>
    33 #include <ofw_tree.h>
    34 #include <balloc.h>
    35 #include <types.h>
     34#ifndef TOP_TOP_H_
     35#define TOP_TOP_H_
    3636
    37 #define KERNEL_VIRTUAL_ADDRESS  0x400000
     37#include <task.h>
     38#include <stats.h>
     39#include <time.h>
    3840
    39 #define TASKMAP_MAX_RECORDS  32
     41#define FRACTION_TO_FLOAT(float, a, b) \
     42        do { \
     43                if ((b) != 0) { \
     44                        (float).upper = (a); \
     45                        (float).lower = (b); \
     46                } else { \
     47                        (float).upper = 0; \
     48                        (float).lower = 1; \
     49                } \
     50        } while (0)
    4051
    41 /** Size of buffer for storing task name in task_t. */
    42 #define BOOTINFO_TASK_NAME_BUFLEN  32
     52typedef enum {
     53        OP_TASKS,
     54        OP_IPC,
     55        OP_EXCS,
     56        OP_HELP
     57} op_mode_t;
    4358
    44 #define BSP_PROCESSOR  1
    45 #define AP_PROCESSOR   0
     59typedef enum {
     60        SORT_TASK_CYCLES
     61} sort_mode_t;
    4662
    47 #define SUBARCH_US   1
    48 #define SUBARCH_US3  3
     63extern op_mode_t op_mode;
     64extern sort_mode_t sort_mode;
     65extern bool excs_all;
    4966
    5067typedef struct {
    51         void *addr;
    52         uint32_t size;
    53         char name[BOOTINFO_TASK_NAME_BUFLEN];
    54 } task_t;
     68        uint64_t upper;
     69        uint64_t lower;
     70} fixed_float;
    5571
    5672typedef struct {
    57         uint32_t count;
    58         task_t tasks[TASKMAP_MAX_RECORDS];
    59 } taskmap_t;
     73        fixed_float idle;
     74        fixed_float busy;
     75} perc_cpu_t;
    6076
    6177typedef struct {
    62         uintptr_t physmem_start;
    63         taskmap_t taskmap;
    64         memmap_t memmap;
    65         ballocs_t ballocs;
    66         ofw_tree_node_t *ofw_root;
    67 } bootinfo_t;
     78        fixed_float virtmem;
     79        fixed_float resmem;
     80        fixed_float ucycles;
     81        fixed_float kcycles;
     82} perc_task_t;
    6883
    69 extern uint32_t silo_ramdisk_image;
    70 extern uint32_t silo_ramdisk_size;
     84typedef struct {
     85        fixed_float cycles;
     86        fixed_float count;
     87} perc_exc_t;
    7188
    72 extern void start(void);
    73 extern void bootstrap(void);
     89typedef struct {
     90        time_t hours;
     91        time_t minutes;
     92        time_t seconds;
     93       
     94        sysarg_t udays;
     95        sysarg_t uhours;
     96        sysarg_t uminutes;
     97        sysarg_t useconds;
     98       
     99        size_t load_count;
     100        load_t *load;
     101       
     102        size_t cpus_count;
     103        stats_cpu_t *cpus;
     104        perc_cpu_t *cpus_perc;
     105       
     106        size_t tasks_count;
     107        stats_task_t *tasks;
     108        perc_task_t *tasks_perc;
     109        size_t *tasks_map;
     110       
     111        size_t threads_count;
     112        stats_thread_t *threads;
     113       
     114        size_t exceptions_count;
     115        stats_exc_t *exceptions;
     116        perc_exc_t *exceptions_perc;
     117       
     118        stats_physmem_t *physmem;
     119       
     120        uint64_t *ucycles_diff;
     121        uint64_t *kcycles_diff;
     122        uint64_t *ecycles_diff;
     123        uint64_t *ecount_diff;
     124} data_t;
    74125
    75126#endif
     127
     128/**
     129 * @}
     130 */
  • uspace/app/trace/Makefile

    rb50b5af2 r04803bf  
    11#
    22# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 ## Setup toolchain
    30 #
     30USPACE_PREFIX = ../..
     31BINARY = trace
    3132
    32 LIBC_PREFIX = ../../lib/libc
    33 SOFTINT_PREFIX = ../../lib/softint
    34 
    35 include $(LIBC_PREFIX)/Makefile.toolchain
    36 include $(LIBC_PREFIX)/Makefile.app
    37 
    38 CFLAGS += -I../../srv/kbd/include
    39 
    40 ## Sources
    41 #
    42 
    43 OUTPUT = trace
    44 SOURCES = trace.c \
     33SOURCES = \
     34        trace.c \
    4535        syscalls.c \
    4636        ipcp.c \
     
    4939        errors.c
    5040
    51 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    52 
    53 .PHONY: all clean depend disasm
    54 
    55 all: $(OUTPUT) disasm
    56 
    57 -include Makefile.depend
    58 
    59 clean:
    60         -rm -f $(OUTPUT) $(OBJECTS) $(OUTPUT).map $(OUTPUT).disasm Makefile.depend
    61 
    62 depend:
    63         $(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
    64 
    65 $(OUTPUT): $(OBJECTS) $(LIBS)
    66         $(LD) -T $(LD_SCRIPT) $(OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
    67 
    68 disasm:
    69         $(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
    70 
    71 %.o: %.S
    72         $(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
    73 
    74 %.o: %.s
    75         $(AS) $(AFLAGS) $< -o $@
    76 
    77 %.o: %.c
    78         $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
     41include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/trace/errors.h

    rb50b5af2 r04803bf  
    3737
    3838typedef struct {
    39         char *name;     /**< Error value name (Exx) */
    40         char *desc;     /**< Error description */
     39        const char *name;  /**< Error value name (Exx) */
     40        const char *desc;  /**< Error description */
    4141} err_desc_t;
    4242
  • uspace/app/trace/ipc_desc.c

    rb50b5af2 r04803bf  
    3333 */
    3434
     35#include <ipc/common.h>
    3536#include <stdlib.h>
    36 #include <ipc/ipc.h>
    3737#include "ipc_desc.h"
    3838
  • uspace/app/trace/ipc_desc.h

    rb50b5af2 r04803bf  
    3838typedef struct {
    3939        int number;
    40         char *name;
     40        const char *name;
    4141} ipc_m_desc_t;
    4242
  • uspace/app/trace/ipcp.c

    rb50b5af2 r04803bf  
    3636#include <stdlib.h>
    3737#include <adt/hash_table.h>
     38#include <sys/typefmt.h>
    3839
    3940#include "ipc_desc.h"
     
    4546
    4647typedef struct {
    47         ipcarg_t phone_hash;
     48        sysarg_t phone_hash;
    4849        ipc_call_t question;
    4950        oper_t *oper;
     
    123124}
    124125
    125 static void ipc_m_print(proto_t *proto, ipcarg_t method)
     126static void ipc_m_print(proto_t *proto, sysarg_t method)
    126127{
    127128        oper_t *oper;
     
    136137
    137138        if (oper != NULL) {
    138                 printf("%s (%ld)", oper->name, method);
     139                printf("%s (%" PRIun ")", oper->name, method);
    139140                return;
    140141        }
    141142
    142         printf("%ld", method);
     143        printf("%" PRIun, method);
    143144}
    144145
     
    191192        unsigned long key[1];
    192193        oper_t *oper;
    193         ipcarg_t *args;
     194        sysarg_t *args;
    194195        int i;
    195196
     
    200201
    201202        if ((display_mask & DM_IPC) != 0) {
    202                 printf("Call ID: 0x%lx, phone: %d, proto: %s, method: ", hash,
    203                         phone, (proto ? proto->name : "n/a"));
    204                 ipc_m_print(proto, IPC_GET_METHOD(*call));
    205                 printf(" args: (%lu, %lu, %lu, %lu, %lu)\n", args[1], args[2],
    206                     args[3], args[4], args[5]);
     203                printf("Call ID: %p, phone: %d, proto: %s, method: ",
     204                    (void *) hash, phone,
     205                    (proto ? proto->name : "n/a"));
     206                ipc_m_print(proto, IPC_GET_IMETHOD(*call));
     207                printf(" args: (%" PRIun ", %" PRIun ", %" PRIun ", "
     208                    "%" PRIun ", %" PRIun ")\n",
     209                    args[1], args[2], args[3], args[4], args[5]);
    207210        }
    208211
     
    211214
    212215                if (proto != NULL) {
    213                         oper = proto_get_oper(proto, IPC_GET_METHOD(*call));
     216                        oper = proto_get_oper(proto, IPC_GET_IMETHOD(*call));
    214217                } else {
    215218                        oper = NULL;
     
    259262    ipc_call_t *answer)
    260263{
    261         ipcarg_t phone;
    262         ipcarg_t method;
    263         ipcarg_t service;
    264         ipcarg_t retval;
     264        sysarg_t phone;
     265        sysarg_t method;
     266        sysarg_t service;
     267        sysarg_t retval;
    265268        proto_t *proto;
    266269        int cphone;
    267270
    268         ipcarg_t *resp;
     271        sysarg_t *resp;
    269272        oper_t *oper;
    270273        int i;
     
    273276
    274277        phone = pcall->phone_hash;
    275         method = IPC_GET_METHOD(pcall->question);
     278        method = IPC_GET_IMETHOD(pcall->question);
    276279        retval = IPC_GET_RETVAL(*answer);
    277280
     
    279282
    280283        if ((display_mask & DM_IPC) != 0) {
    281                 printf("Response to 0x%lx: retval=%ld, args = (%lu, %lu, %lu, %lu, %lu)\n",
    282                         hash, retval, IPC_GET_ARG1(*answer),
    283                         IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer),
    284                         IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
     284                printf("Response to %p: retval=%" PRIdn ", args = (%" PRIun ", "
     285                    "%" PRIun ", %" PRIun ", %" PRIun ", %" PRIun ")\n",
     286                    (void *) hash, retval, IPC_GET_ARG1(*answer),
     287                    IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer),
     288                    IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
    285289        }
    286290
     
    336340                /* Not a response */
    337341                if ((display_mask & DM_IPC) != 0) {
    338                         printf("Not a response (hash 0x%lx)\n", hash);
     342                        printf("Not a response (hash %p)\n", (void *) hash);
    339343                }
    340344                return;
  • uspace/app/trace/ipcp.h

    rb50b5af2 r04803bf  
    3636#define IPCP_H_
    3737
    38 #include <ipc/ipc.h>
    3938#include "proto.h"
    4039
  • uspace/app/trace/proto.c

    rb50b5af2 r04803bf  
    3535#include <stdio.h>
    3636#include <stdlib.h>
    37 #include <ipc/ipc.h>
    3837#include <adt/hash_table.h>
    3938
     
    5352
    5453typedef struct {
    55         ipcarg_t method;
     54        sysarg_t method;
    5655        oper_t *oper;
    5756        link_t link;
     
    157156}
    158157
    159 static void proto_struct_init(proto_t *proto, char *name)
     158static void proto_struct_init(proto_t *proto, const char *name)
    160159{
    161160        proto->name = name;
     
    164163}
    165164
    166 proto_t *proto_new(char *name)
     165proto_t *proto_new(const char *name)
    167166{
    168167        proto_t *p;
     
    206205}
    207206
    208 static void oper_struct_init(oper_t *oper, char *name)
     207static void oper_struct_init(oper_t *oper, const char *name)
    209208{
    210209        oper->name = name;
    211210}
    212211
    213 oper_t *oper_new(char *name, int argc, val_type_t *arg_types,
     212oper_t *oper_new(const char *name, int argc, val_type_t *arg_types,
    214213    val_type_t rv_type, int respc, val_type_t *resp_types)
    215214{
  • uspace/app/trace/proto.h

    rb50b5af2 r04803bf  
    3636#define PROTO_H_
    3737
     38#include <ipc/common.h>
    3839#include <adt/hash_table.h>
    39 #include <ipc/ipc.h>
    4040#include "trace.h"
    4141
     
    4343
    4444typedef struct {
    45         char *name;
     45        const char *name;
    4646
    4747        int argc;
     
    5656typedef struct {
    5757        /** Protocol name */
    58         char *name;
     58        const char *name;
    5959
    6060        /** Maps method number to operation */
     
    7070void proto_register(int srv, proto_t *proto);
    7171proto_t *proto_get_by_srv(int srv);
    72 proto_t *proto_new(char *name);
     72proto_t *proto_new(const char *name);
    7373void proto_delete(proto_t *proto);
    7474void proto_add_oper(proto_t *proto, int method, oper_t *oper);
    7575oper_t *proto_get_oper(proto_t *proto, int method);
    7676
    77 oper_t *oper_new(char *name, int argc, val_type_t *arg_types,
     77oper_t *oper_new(const char *name, int argc, val_type_t *arg_types,
    7878    val_type_t rv_type, int respc, val_type_t *resp_types);
    7979
  • uspace/app/trace/syscalls.c

    rb50b5af2 r04803bf  
    6464    [SYS_IPC_POKE] = { "ipc_poke",                      0,      V_ERRNO },
    6565    [SYS_IPC_HANGUP] = { "ipc_hangup",                  1,      V_ERRNO },
    66     [SYS_IPC_REGISTER_IRQ] = { "ipc_register_irq",      4,      V_ERRNO },
    67     [SYS_IPC_UNREGISTER_IRQ] = { "ipc_unregister_irq",  2,      V_ERRNO },
    6866
    6967    [SYS_EVENT_SUBSCRIBE] = { "event_subscribe",        2,      V_ERRNO },
     
    7371    [SYS_PHYSMEM_MAP] = { "physmem_map",                4,      V_ERRNO },
    7472    [SYS_IOSPACE_ENABLE] = { "iospace_enable",          1,      V_ERRNO },
    75     [SYS_PREEMPT_CONTROL] = { "preempt_control",        1,      V_ERRNO },
     73    [SYS_REGISTER_IRQ] = { "register_irq",      4,      V_ERRNO },
     74    [SYS_UNREGISTER_IRQ] = { "unregister_irq",  2,      V_ERRNO },
    7675
    77     [SYS_SYSINFO_VALID] = { "sysinfo_valid",            2,      V_HASH },
    78     [SYS_SYSINFO_VALUE] = { "sysinfo_value",            2,      V_HASH },
     76    [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",                2,      V_INTEGER },
     77    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",            3,      V_ERRNO },
     78    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",    3,      V_ERRNO },
     79    [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data",              5,      V_ERRNO },
     80
    7981    [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0,   V_ERRNO },
    8082    [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox",      1,      V_ERRNO }
  • uspace/app/trace/syscalls.h

    rb50b5af2 r04803bf  
    3939
    4040typedef struct {
    41         char *name;
     41        const char *name;
    4242        int n_args;
    4343        val_type_t rv_type;
  • uspace/app/trace/trace.c

    rb50b5af2 r04803bf  
    3636#include <stdlib.h>
    3737#include <unistd.h>
    38 #include <ipc/ipc.h>
    3938#include <fibril.h>
    4039#include <errno.h>
     
    4342#include <task.h>
    4443#include <mem.h>
    45 #include <string.h>
     44#include <str.h>
    4645#include <bool.h>
    4746#include <loader/loader.h>
    4847#include <io/console.h>
    4948#include <io/keycode.h>
    50 #include <fibril_sync.h>
     49#include <fibril_synch.h>
     50#include <sys/types.h>
     51#include <sys/typefmt.h>
    5152
    5253#include <libc.h>
     
    147148        int rc;
    148149
    149         rc = ipc_connect_kbox(task_id);
     150        rc = async_connect_kbox(task_id);
    150151
    151152        if (rc == ENOTSUP) {
     
    159160        if (rc < 0) {
    160161                printf("Error connecting\n");
    161                 printf("ipc_connect_task(%lld) -> %d ", task_id, rc);
     162                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
    162163                return rc;
    163164        }
     
    198199        printf("Threads:");
    199200        for (i = 0; i < n_threads; i++) {
    200                 printf(" [%d] (hash 0x%lx)", 1+i, thread_hash_buf[i]);
    201         }
    202         printf("\ntotal of %u threads\n", tb_needed / sizeof(uintptr_t));
     201                printf(" [%d] (hash %p)", 1 + i, (void *) thread_hash_buf[i]);
     202        }
     203        printf("\ntotal of %zu threads\n", tb_needed / sizeof(uintptr_t));
    203204
    204205        return 0;
     
    222223        case V_HASH:
    223224        case V_PTR:
    224                 printf("0x%08lx", val);
     225                printf("%p", (void *) val);
    225226                break;
    226227
     
    246247        case V_CHAR:
    247248                if (sval >= 0x20 && sval < 0x7f) {
    248                         printf("'%c'", sval);
     249                        printf("'%c'", (char) sval);
    249250                } else {
    250251                        switch (sval) {
     
    255256                        case '\t': printf("'\\t'"); break;
    256257                        case '\\': printf("'\\\\'"); break;
    257                         default: printf("'\\x%02lX'", val); break;
     258                        default: printf("'\\x%02" PRIxn "'", val); break;
    258259                        }
    259260                }
     
    275276
    276277        putchar('(');
    277         if (n > 0) printf("%ld", sc_args[0]);
     278        if (n > 0) printf("%" PRIun, sc_args[0]);
    278279        for (i = 1; i < n; i++) {
    279                 printf(", %ld", sc_args[i]);
     280                printf(", %" PRIun, sc_args[i]);
    280281        }
    281282        putchar(')');
     
    285286{
    286287        ipc_call_t call;
    287         ipcarg_t phoneid;
     288        sysarg_t phoneid;
    288289       
    289290        if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL ||
     
    293294        phoneid = sc_args[0];
    294295
    295         IPC_SET_METHOD(call, sc_args[1]);
     296        IPC_SET_IMETHOD(call, sc_args[1]);
    296297        IPC_SET_ARG1(call, sc_args[2]);
    297298        IPC_SET_ARG2(call, sc_args[3]);
     
    329330        phoneidx = sc_args[0];
    330331
    331         IPC_SET_METHOD(question, sc_args[1]);
     332        IPC_SET_IMETHOD(question, sc_args[1]);
    332333        IPC_SET_ARG1(question, sc_args[2]);
    333334        IPC_SET_ARG2(question, sc_args[3]);
     
    487488{
    488489        async_serialize_start();
    489         printf("New thread, hash 0x%lx\n", hash);
     490        printf("New thread, hash %p\n", (void *) hash);
    490491        async_serialize_end();
    491492
     
    508509        }
    509510
    510         printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash);
     511        printf("Start tracing thread [%u] (hash %p).\n",
     512            thread_id, (void *) thread_hash);
    511513
    512514        while (!abort_trace) {
     
    514516                fibril_mutex_lock(&state_lock);
    515517                if (paused) {
    516                         printf("Thread [%d] paused. Press R to resume.\n",
     518                        printf("Thread [%u] paused. Press R to resume.\n",
    517519                            thread_id);
    518520
     
    520522                                fibril_condvar_wait(&state_cv, &state_lock);
    521523
    522                         printf("Thread [%d] resumed.\n", thread_id);
     524                        printf("Thread [%u] resumed.\n", thread_id);
    523525                }
    524526                fibril_mutex_unlock(&state_lock);
     
    552554                                break;
    553555                        case UDEBUG_EVENT_THREAD_E:
    554                                 printf("Thread 0x%lx exited.\n", val0);
     556                                printf("Thread %" PRIun " exited.\n", val0);
    555557                                fibril_mutex_lock(&state_lock);
    556558                                abort_trace = true;
     
    583585}
    584586
    585 static loader_t *preload_task(const char *path, char *const argv[],
     587static loader_t *preload_task(const char *path, char **argv,
    586588    task_id_t *task_id)
    587589{
     
    589591        int rc;
    590592
    591         /* Spawn a program loader */   
     593        /* Spawn a program loader */
    592594        ldr = loader_connect();
    593595        if (ldr == NULL)
     
    605607
    606608        /* Send arguments */
    607         rc = loader_set_args(ldr, argv);
     609        rc = loader_set_args(ldr, (const char **) argv);
    608610        if (rc != EOK)
    609611                goto error;
     
    742744        abort_trace = true;
    743745        udebug_end(phoneid);
    744         ipc_hangup(phoneid);
     746        async_hangup(phoneid);
    745747
    746748        ipcp_cleanup();
     
    868870}
    869871
    870 static display_mask_t parse_display_mask(char *text)
     872static display_mask_t parse_display_mask(const char *text)
    871873{
    872874        display_mask_t dm;
    873         char *c;
    874 
    875         c = text;
    876 
     875        const char *c = text;
     876       
    877877        while (*c) {
    878878                switch (*c) {
    879                 case 't': dm = dm | DM_THREAD; break;
    880                 case 's': dm = dm | DM_SYSCALL; break;
    881                 case 'i': dm = dm | DM_IPC; break;
    882                 case 'p': dm = dm | DM_SYSTEM | DM_USER; break;
     879                case 't':
     880                        dm = dm | DM_THREAD;
     881                        break;
     882                case 's':
     883                        dm = dm | DM_SYSCALL;
     884                        break;
     885                case 'i':
     886                        dm = dm | DM_IPC;
     887                        break;
     888                case 'p':
     889                        dm = dm | DM_SYSTEM | DM_USER;
     890                        break;
    883891                default:
    884892                        printf("Unexpected event type '%c'.\n", *c);
    885893                        exit(1);
    886894                }
    887 
     895               
    888896                ++c;
    889897        }
    890 
     898       
    891899        return dm;
    892900}
     
    894902static int parse_args(int argc, char *argv[])
    895903{
    896         char *arg;
    897904        char *err_p;
    898905
    899906        task_id = 0;
    900907
    901         --argc; ++argv;
     908        --argc;
     909        ++argv;
    902910
    903911        while (argc > 0) {
    904                 arg = *argv;
     912                char *arg = *argv;
    905913                if (arg[0] == '+') {
    906914                        display_mask = parse_display_mask(&arg[1]);
     
    908916                        if (arg[1] == 't') {
    909917                                /* Trace an already running task */
    910                                 --argc; ++argv;
     918                                --argc;
     919                                ++argv;
    911920                                task_id = strtol(*argv, &err_p, 10);
    912921                                task_ldr = NULL;
     
    918927                                }
    919928                        } else {
    920                                 printf("Uknown option '%s'\n", arg[0]);
     929                                printf("Uknown option '%c'\n", arg[0]);
    921930                                print_syntax();
    922931                                return -1;
     
    925934                        break;
    926935                }
    927 
    928                 --argc; ++argv;
     936               
     937                --argc;
     938                ++argv;
    929939        }
    930940
    931941        if (task_id != 0) {
    932                 if (argc == 0) return 0;
     942                if (argc == 0)
     943                        return 0;
    933944                printf("Extra arguments\n");
    934945                print_syntax();
     
    944955        /* Preload the specified program file. */
    945956        printf("Spawning '%s' with arguments:\n", *argv);
    946         {
    947                 char **cp = argv;
    948                 while (*cp) printf("'%s'\n", *cp++);
    949         }
     957       
     958        char **cp = argv;
     959        while (*cp)
     960                printf("'%s'\n", *cp++);
     961       
    950962        task_ldr = preload_task(*argv, argv, &task_id);
    951963        task_wait_for = true;
     
    972984        rc = connect_task(task_id);
    973985        if (rc < 0) {
    974                 printf("Failed connecting to task %lld.\n", task_id);
     986                printf("Failed connecting to task %" PRIu64 ".\n", task_id);
    975987                return 1;
    976988        }
    977989
    978         printf("Connected to task %lld.\n", task_id);
     990        printf("Connected to task %" PRIu64 ".\n", task_id);
    979991
    980992        if (task_ldr != NULL)
Note: See TracChangeset for help on using the changeset viewer.