Changeset 1affcdf3 in mainline for uspace/app


Ignore:
Timestamp:
2011-06-10T19:33:41Z (14 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1878386
Parents:
13ecdac9 (diff), 79a141a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/app
Files:
40 added
4 deleted
41 edited
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    r13ecdac9 r1affcdf3  
    102102        }
    103103
    104         rc = block_init(handle, 2048);
     104        rc = block_init(EXCHANGE_SERIALIZE, handle, 2048);
    105105        if (rc != EOK)  {
    106106                printf("%s: Error initializing libblock.\n", cmdname);
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r13ecdac9 r1affcdf3  
    6464static sysarg_t console_rows = 0;
    6565static bool should_quit = false;
     66
     67static console_ctrl_t *console = NULL;
    6668
    6769static struct option const long_options[] = {
     
    102104static void waitprompt()
    103105{
    104         console_set_pos(fphone(stdout), 0, console_rows-1);
    105         console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0);
     106        console_set_pos(console, 0, console_rows-1);
     107        console_set_color(console, COLOR_BLUE, COLOR_WHITE, 0);
     108       
    106109        printf("ENTER/SPACE/PAGE DOWN - next page, "
    107110               "ESC/Q - quit, C - continue unpaged");
    108111        fflush(stdout);
    109         console_set_style(fphone(stdout), STYLE_NORMAL);
     112       
     113        console_set_style(console, STYLE_NORMAL);
    110114}
    111115
    112116static void waitkey()
    113117{
    114         console_event_t ev;
     118        kbd_event_t ev;
    115119       
    116120        while (true) {
    117                 if (!console_get_event(fphone(stdin), &ev)) {
     121                if (!console_get_kbd_event(console, &ev)) {
    118122                        return;
    119123                }
     
    138142static void newpage()
    139143{
    140         console_clear(fphone(stdout));
     144        console_clear(console);
    141145        chars_remaining = console_cols;
    142         lines_remaining = console_rows-1;
     146        lines_remaining = console_rows - 1;
    143147}
    144148
     
    238242        console_rows = 0;
    239243        should_quit = false;
     244        console = console_init(stdin, stdout);
    240245
    241246        argc = cli_count_args(argv);
     
    280285       
    281286        if (more) {
    282                 rc = console_get_size(fphone(stdout), &cols, &rows);
     287                rc = console_get_size(console, &cols, &rows);
    283288                if (rc != EOK) {
    284289                        printf("%s - cannot get console size\n", cmdname);
  • uspace/app/bdsh/cmds/modules/kcon/kcon.c

    r13ecdac9 r1affcdf3  
    3232#include <stdlib.h>
    3333#include <io/console.h>
    34 #include <vfs/vfs.h>
    3534#include "config.h"
    3635#include "util.h"
     
    4241static const char *cmdname = "kcon";
    4342
    44 /* Dispays help for kcon in various levels */
     43/* Display help for kcon in various levels */
    4544void help_cmd_kcon(unsigned int level)
    4645{
    4746        printf("`kcon' switches to the kernel debug console.\n");
    48 
    49         if (level != HELP_SHORT) {
    50                 printf("Usage:  %s\n", cmdname);
    51         }
    52 
     47       
     48        if (level != HELP_SHORT)
     49                printf("Usage: %s\n", cmdname);
     50       
    5351        return;
    5452}
     
    5755int cmd_kcon(char **argv)
    5856{
    59         unsigned int argc;
    60 
    61         argc = cli_count_args(argv);
    62 
     57        unsigned int argc = cli_count_args(argv);
     58       
    6359        if (argc != 1) {
    6460                printf("%s - incorrect number of arguments. Try `%s --help'\n",
    65                         cmdname, cmdname);
     61                    cmdname, cmdname);
    6662                return CMD_FAILURE;
    6763        }
    68 
    69         console_kcon_enable(fphone(stdout));
    70 
    71         return CMD_SUCCESS;
     64       
     65        if (console_kcon())
     66                return CMD_SUCCESS;
     67        else
     68                return CMD_FAILURE;
    7269}
    73 
  • uspace/app/bdsh/cmds/modules/mount/mount.c

    r13ecdac9 r1affcdf3  
    5151{
    5252        static char helpfmt[] =
    53             "Usage:  %s <fstype> <mp> <dev> [<moptions>]\n";
     53            "Usage:  %s <fstype> <mp> [dev] [<moptions>]\n";
    5454        if (level == HELP_SHORT) {
    5555                printf("'%s' mounts a file system.\n", cmdname);
     
    6666        unsigned int argc;
    6767        const char *mopts = "";
     68        const char *dev = "";
    6869        int rc, c, opt_ind;
    6970
     
    7980        }
    8081
    81         if ((argc < 4) || (argc > 5)) {
     82        if ((argc < 3) || (argc > 5)) {
    8283                printf("%s: invalid number of arguments. Try `mount --help'\n",
    8384                    cmdname);
    8485                return CMD_FAILURE;
    8586        }
     87        if (argc > 3)
     88                dev = argv[3];
    8689        if (argc == 5)
    8790                mopts = argv[4];
    8891
    89         rc = mount(argv[1], argv[2], argv[3], mopts, 0);
     92        rc = mount(argv[1], argv[2], dev, mopts, 0);
    9093        if (rc != EOK) {
    9194                printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
  • uspace/app/bdsh/input.c

    r13ecdac9 r1affcdf3  
    110110        char *str;
    111111        int rc;
    112 
    113         fflush(stdout);
    114         console_set_style(fphone(stdout), STYLE_EMPHASIS);
     112       
     113        console_flush(tinput->console);
     114        console_set_style(tinput->console, STYLE_EMPHASIS);
    115115        printf("%s", usr->prompt);
    116         fflush(stdout);
    117         console_set_style(fphone(stdout), STYLE_NORMAL);
     116        console_flush(tinput->console);
     117        console_set_style(tinput->console, STYLE_NORMAL);
    118118
    119119        rc = tinput_read(tinput, &str);
  • uspace/app/blkdump/Makefile

    r13ecdac9 r1affcdf3  
    11#
    2 # Copyright (c) 2008 Jiri Svoboda
     2# Copyright (c) 2005 Martin Decky
     3# Copyright (c) 2007 Jakub Jermar
    34# All rights reserved.
    45#
     
    2728#
    2829
    29 ARCH_SOURCES = arch/$(UARCH)/arm32.s
     30USPACE_PREFIX = ../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
     33BINARY = blkdump
     34
     35SOURCES = \
     36        blkdump.c
     37
     38include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/bnchmark/Makefile

    r13ecdac9 r1affcdf3  
    11#
    2 # Copyright (c) 2008 Jiri Svoboda
     2# Copyright (c) 2011 Martin Sucha
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 ARCH_SOURCES = arch/$(UARCH)/ia32.s
     29USPACE_PREFIX = ../..
     30BINARY = bnchmark
     31
     32SOURCES = \
     33        bnchmark.c
     34
     35include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/edit/edit.c

    r13ecdac9 r1affcdf3  
    9494} doc_t;
    9595
    96 static int con;
     96static console_ctrl_t *con;
    9797static doc_t doc;
    9898static bool done;
     
    115115static void cursor_setvis(bool visible);
    116116
    117 static void key_handle_unmod(console_event_t const *ev);
    118 static void key_handle_ctrl(console_event_t const *ev);
    119 static void key_handle_shift(console_event_t const *ev);
     117static void key_handle_unmod(kbd_event_t const *ev);
     118static void key_handle_ctrl(kbd_event_t const *ev);
     119static void key_handle_shift(kbd_event_t const *ev);
    120120static void key_handle_movement(unsigned int key, bool shift);
    121121
     
    158158int main(int argc, char *argv[])
    159159{
    160         console_event_t ev;
     160        kbd_event_t ev;
    161161        coord_t coord;
    162162        bool new_file;
     
    164164        spt_t pt;
    165165
    166         con = fphone(stdout);
     166        con = console_init(stdin, stdout);
    167167        console_clear(con);
    168168
     
    219219
    220220        while (!done) {
    221                 console_get_event(con, &ev);
     221                console_get_kbd_event(con, &ev);
    222222                pane.rflags = 0;
    223223
     
    277277
    278278/** Handle key without modifier. */
    279 static void key_handle_unmod(console_event_t const *ev)
     279static void key_handle_unmod(kbd_event_t const *ev)
    280280{
    281281        switch (ev->key) {
     
    320320
    321321/** Handle Shift-key combination. */
    322 static void key_handle_shift(console_event_t const *ev)
     322static void key_handle_shift(kbd_event_t const *ev)
    323323{
    324324        switch (ev->key) {
     
    344344
    345345/** Handle Ctrl-key combination. */
    346 static void key_handle_ctrl(console_event_t const *ev)
     346static void key_handle_ctrl(kbd_event_t const *ev)
    347347{
    348348        switch (ev->key) {
     
    497497static char *filename_prompt(char const *prompt, char const *init_value)
    498498{
    499         console_event_t ev;
     499        kbd_event_t ev;
    500500        char *str;
    501501        wchar_t buffer[INFNAME_MAX_LEN + 1];
     
    517517
    518518        while (!done) {
    519                 console_get_event(con, &ev);
     519                console_get_kbd_event(con, &ev);
    520520
    521521                if (ev.type == KEY_PRESS) {
     
    531531                                        if (nc > 0) {
    532532                                                putchar('\b');
    533                                                 fflush(stdout);
     533                                                console_flush(con);
    534534                                                --nc;
    535535                                        }
     
    541541                                        if (ev.c >= 32 && nc < max_len) {
    542542                                                putchar(ev.c);
    543                                                 fflush(stdout);
     543                                                console_flush(con);
    544544                                                buffer[nc++] = ev.c;
    545545                                        }
     
    689689                for (j = 0; j < scr_columns; ++j)
    690690                        putchar(' ');
    691                 fflush(stdout);
     691                console_flush(con);
    692692        }
    693693
     
    757757                if (coord_cmp(&csel_start, &rbc) <= 0 &&
    758758                    coord_cmp(&rbc, &csel_end) < 0) {
    759                         fflush(stdout);
     759                        console_flush(con);
    760760                        console_set_style(con, STYLE_SELECTED);
    761                         fflush(stdout);
     761                        console_flush(con);
    762762                }
    763763
     
    768768                while (pos < size) {
    769769                        if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
    770                                 fflush(stdout);
     770                                console_flush(con);
    771771                                console_set_style(con, STYLE_SELECTED);
    772                                 fflush(stdout);
     772                                console_flush(con);
    773773                        }
    774774       
    775775                        if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    776                                 fflush(stdout);
     776                                console_flush(con);
    777777                                console_set_style(con, STYLE_NORMAL);
    778                                 fflush(stdout);
     778                                console_flush(con);
    779779                        }
    780780       
     
    794794
    795795                if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    796                         fflush(stdout);
     796                        console_flush(con);
    797797                        console_set_style(con, STYLE_NORMAL);
    798                         fflush(stdout);
     798                        console_flush(con);
    799799                }
    800800
     
    808808                for (j = 0; j < fill; ++j)
    809809                        putchar(' ');
    810                 fflush(stdout);
     810                console_flush(con);
    811811                console_set_style(con, STYLE_NORMAL);
    812812        }
     
    833833        int pos = scr_columns - 1 - n;
    834834        printf("%*s", pos, "");
    835         fflush(stdout);
     835        console_flush(con);
    836836        console_set_style(con, STYLE_NORMAL);
    837837
     
    11581158        int pos = -(scr_columns - 3);
    11591159        printf(" %*s ", pos, str);
    1160         fflush(stdout);
     1160        console_flush(con);
    11611161        console_set_style(con, STYLE_NORMAL);
    11621162
  • uspace/app/getterm/version.c

    r13ecdac9 r1affcdf3  
    6161        printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp);
    6262        printf("Running on %s (%s)\n", arch, term);
    63         printf("Copyright (c) 2001-2010 HelenOS project\n\n");
     63        printf("Copyright (c) 2001-2011 HelenOS project\n\n");
    6464}
    6565
  • uspace/app/init/Makefile

    r13ecdac9 r1affcdf3  
    3030USPACE_PREFIX = ../..
    3131BINARY = init
     32STATIC_NEEDED = y
    3233
    3334SOURCES = \
  • uspace/app/init/init.c

    r13ecdac9 r1affcdf3  
    176176static void console(const char *dev)
    177177{
    178         char hid_in[DEVMAP_NAME_MAXLEN];
    179         int rc;
    180        
    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);
     178        printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, dev);
    184179       
    185180        /* Wait for the input device to be ready */
    186181        devmap_handle_t handle;
    187         rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
    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);
     182        int rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
     183        if (rc != EOK) {
     184                printf("%s: Error waiting on %s (%s)\n", NAME, dev,
     185                    str_error(rc));
     186                return;
     187        }
     188       
     189        rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, dev, NULL);
    195190        if (rc != EOK) {
    196191                printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
    197                     hid_in, str_error(rc));
     192                    dev, str_error(rc));
    198193        }
    199194}
     
    272267        mount_tmpfs();
    273268       
    274 #ifdef CONFIG_START_DEVMAN
    275269        spawn("/srv/devman");
    276 #endif
    277270        spawn("/srv/apic");
    278271        spawn("/srv/i8259");
  • uspace/app/klog/klog.c

    r13ecdac9 r1affcdf3  
    4444#include <io/klog.h>
    4545#include <sysinfo.h>
     46#include <malloc.h>
     47#include <fibril_synch.h>
     48#include <adt/list.h>
     49#include <adt/prodcons.h>
    4650
    4751#define NAME       "klog"
    4852#define LOG_FNAME  "/log/klog"
     53
     54/* Producer/consumer buffers */
     55typedef struct {
     56        link_t link;
     57        size_t length;
     58        wchar_t *data;
     59} item_t;
     60
     61static prodcons_t pc;
    4962
    5063/* Pointer to klog area */
     
    5265static size_t klog_length;
    5366
    54 static FILE *log;
    55 
    56 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    57 {
     67/* Notification mutex */
     68static FIBRIL_MUTEX_INITIALIZE(mtx);
     69
     70/** Klog producer
     71 *
     72 * Copies the contents of a character buffer to local
     73 * producer/consumer queue.
     74 *
     75 * @param length Number of characters to copy.
     76 * @param data   Pointer to the kernel klog buffer.
     77 *
     78 */
     79static void producer(size_t length, wchar_t *data)
     80{
     81        item_t *item = (item_t *) malloc(sizeof(item_t));
     82        if (item == NULL)
     83                return;
     84       
     85        size_t sz = sizeof(wchar_t) * length;
     86        wchar_t *buf = (wchar_t *) malloc(sz);
     87        if (data == NULL) {
     88                free(item);
     89                return;
     90        }
     91       
     92        memcpy(buf, data, sz);
     93       
     94        link_initialize(&item->link);
     95        item->length = length;
     96        item->data = buf;
     97        prodcons_produce(&pc, &item->link);
     98}
     99
     100/** Klog consumer
     101 *
     102 * Waits in an infinite loop for the character data created by
     103 * the producer and outputs them to stdout and optionally into
     104 * a file.
     105 *
     106 * @param data Unused.
     107 *
     108 * @return Always EOK (unreachable).
     109 *
     110 */
     111static int consumer(void *data)
     112{
     113        FILE *log = fopen(LOG_FNAME, "a");
     114        if (log == NULL)
     115                printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
     116                    str_error(errno));
     117       
     118        while (true) {
     119                link_t *link = prodcons_consume(&pc);
     120                item_t *item = list_get_instance(link, item_t, link);
     121               
     122                for (size_t i = 0; i < item->length; i++)
     123                        putchar(item->data[i]);
     124               
     125                if (log != NULL) {
     126                        for (size_t i = 0; i < item->length; i++)
     127                                fputc(item->data[i], log);
     128                       
     129                        fflush(log);
     130                        fsync(fileno(log));
     131                }
     132               
     133                free(item->data);
     134                free(item);
     135        }
     136       
     137        fclose(log);
     138        return EOK;
     139}
     140
     141/** Kernel notification handler
     142 *
     143 * Receives kernel klog notifications.
     144 *
     145 * @param callid IPC call ID.
     146 * @param call   IPC call structure.
     147 *
     148 */
     149static void notification_received(ipc_callid_t callid, ipc_call_t *call)
     150{
     151        /*
     152         * Make sure we process only a single notification
     153         * at any time to limit the chance of the consumer
     154         * starving.
     155         *
     156         * Note: Usually the automatic masking of the klog
     157         * notifications on the kernel side does the trick
     158         * of limiting the chance of accidentally copying
     159         * the same data multiple times. However, due to
     160         * the non-blocking architecture of klog notifications,
     161         * this possibility cannot be generally avoided.
     162         */
     163       
     164        fibril_mutex_lock(&mtx);
     165       
    58166        size_t klog_start = (size_t) IPC_GET_ARG1(*call);
    59167        size_t klog_len = (size_t) IPC_GET_ARG2(*call);
    60168        size_t klog_stored = (size_t) IPC_GET_ARG3(*call);
    61         size_t i;
    62        
    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         }
     169       
     170        size_t offset = (klog_start + klog_len - klog_stored) % klog_length;
     171       
     172        /* Copy data from the ring buffer */
     173        if (offset + klog_stored >= klog_length) {
     174                size_t split = klog_length - offset;
     175               
     176                producer(split, klog + offset);
     177                producer(klog_stored - split, klog);
     178        } else
     179                producer(klog_stored, klog + offset);
     180       
     181        event_unmask(EVENT_KLOG);
     182        fibril_mutex_unlock(&mtx);
    76183}
    77184
     
    111218        }
    112219       
     220        prodcons_initialize(&pc);
     221        async_set_interrupt_received(notification_received);
    113222        rc = event_subscribe(EVENT_KLOG, 0);
    114223        if (rc != EOK) {
     
    118227        }
    119228       
    120         log = fopen(LOG_FNAME, "a");
    121         if (log == NULL)
    122                 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME,
    123                     str_error(errno));
    124        
    125         async_set_interrupt_received(interrupt_received);
     229        fid_t fid = fibril_create(consumer, NULL);
     230        if (!fid) {
     231                fprintf(stderr, "%s: Unable to create consumer fibril\n",
     232                    NAME);
     233                return ENOMEM;
     234        }
     235       
     236        fibril_add_ready(fid);
     237        event_unmask(EVENT_KLOG);
    126238        klog_update();
     239       
     240        task_retval(0);
    127241        async_manager();
    128242       
  • uspace/app/mkfat/mkfat.c

    r13ecdac9 r1affcdf3  
    144144        }
    145145
    146         rc = block_init(handle, 2048);
     146        rc = block_init(EXCHANGE_SERIALIZE, handle, 2048);
    147147        if (rc != EOK)  {
    148148                printf(NAME ": Error initializing libblock.\n");
  • uspace/app/mkminix/mkminix.c

    r13ecdac9 r1affcdf3  
    208208        }
    209209
    210         rc = block_init(handle, 2048);
     210        rc = block_init(EXCHANGE_SERIALIZE, handle, 2048);
    211211        if (rc != EOK)  {
    212212                printf(NAME ": Error initializing libblock.\n");
  • uspace/app/ping/ping.c

    r13ecdac9 r1affcdf3  
    3636
    3737#include <async.h>
     38#include <async_obsolete.h>
    3839#include <stdio.h>
    3940#include <str.h>
     
    355356                            str_error(ret));
    356357                       
    357                         async_hangup(icmp_phone);
     358                        async_obsolete_hangup(icmp_phone);
    358359                        return ret;
    359360                }
     
    370371                            str_error(ret));
    371372                       
    372                         async_hangup(icmp_phone);
     373                        async_obsolete_hangup(icmp_phone);
    373374                        return ret;
    374375                }
     
    390391        }
    391392       
    392         async_hangup(icmp_phone);
     393        async_obsolete_hangup(icmp_phone);
    393394       
    394395        return 0;
  • uspace/app/redir/redir.c

    r13ecdac9 r1affcdf3  
    4949static void usage(void)
    5050{
    51         printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
     51        fprintf(stderr, "Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
    5252            NAME);
    5353}
     
    8383        args = (const char **) calloc(argc + 1, sizeof(char *));
    8484        if (!args) {
    85                 printf("No memory available\n");
     85                fprintf(stderr, "No memory available\n");
    8686                return 0;
    8787        }
     
    9898       
    9999        if (rc != EOK) {
    100                 printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
     100                fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, argv[0],
    101101                    str_error(rc));
     102                return 0;
    102103        }
    103104       
  • uspace/app/taskdump/elf_core.c

    r13ecdac9 r1affcdf3  
    6262#include "include/elf_core.h"
    6363
    64 static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size);
    65 static int write_all(int fd, void *data, size_t len);
    66 static int write_mem_area(int fd, as_area_info_t *area, int phoneid);
     64static off64_t align_foff_up(off64_t, uintptr_t, size_t);
     65static int write_all(int, void *, size_t);
     66static int write_mem_area(int, as_area_info_t *, async_sess_t *);
    6767
    6868#define BUFFER_SIZE 0x1000
     
    7171/** Save ELF core file.
    7272 *
    73  * @param file_name     Name of file to save to.
    74  * @param ainfo         Array of @a n memory area info structures.
    75  * @param n             Number of memory areas.
    76  * @param phoneid       Debugging phone.
    77  *
    78  * @return              EOK on sucess, ENOENT if file cannot be created,
    79  *                      ENOMEM on out of memory, EIO on write error.
    80  */
    81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid)
     73 * @param file_name Name of file to save to.
     74 * @param ainfo     Array of @a n memory area info structures.
     75 * @param n         Number of memory areas.
     76 * @param sess      Debugging session.
     77 *
     78 * @return EOK on sucess.
     79 * @return ENOENT if file cannot be created.
     80 * @return ENOMEM on out of memory.
     81 * @return EIO on write error.
     82 *
     83 */
     84int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n,
     85    async_sess_t *sess)
    8286{
    8387        elf_header_t elf_hdr;
     
    189193                        return EIO;
    190194                }
    191                 if (write_mem_area(fd, &ainfo[i], phoneid) != EOK) {
     195                if (write_mem_area(fd, &ainfo[i], sess) != EOK) {
    192196                        printf("Failed writing memory data.\n");
    193197                        free(p_hdr);
     
    215219/** Write memory area from application to core file.
    216220 *
    217  * @param fd            File to write to.
    218  * @param area          Memory area info structure.
    219  * @param phoneid       Debugging phone.
    220  *
    221  * @return              EOK on success, EIO on failure.
    222  */
    223 static int write_mem_area(int fd, as_area_info_t *area, int phoneid)
     221 * @param fd   File to write to.
     222 * @param area Memory area info structure.
     223 * @param sess Debugging session.
     224 *
     225 * @return EOK on success, EIO on failure.
     226 *
     227 */
     228static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
    224229{
    225230        size_t to_copy;
     
    233238        while (total < area->size) {
    234239                to_copy = min(area->size - total, BUFFER_SIZE);
    235                 rc = udebug_mem_read(phoneid, buffer, addr, to_copy);
     240                rc = udebug_mem_read(sess, buffer, addr, to_copy);
    236241                if (rc < 0) {
    237242                        printf("Failed reading task memory.\n");
  • uspace/app/taskdump/include/elf_core.h

    r13ecdac9 r1affcdf3  
    3636#define ELF_CORE_H_
    3737
    38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid);
     38#include <async.h>
     39
     40extern int elf_core_save(const char *, as_area_info_t *, unsigned int,
     41    async_sess_t *);
    3942
    4043#endif
  • uspace/app/taskdump/taskdump.c

    r13ecdac9 r1affcdf3  
    5454#define LINE_BYTES 16
    5555
    56 static int phoneid;
     56static async_sess_t *sess;
    5757static task_id_t task_id;
    5858static bool write_core_file;
     
    104104                printf("Failed dumping address space areas.\n");
    105105
    106         udebug_end(phoneid);
    107         async_hangup(phoneid);
     106        udebug_end(sess);
     107        async_hangup(sess);
    108108
    109109        return 0;
     
    112112static int connect_task(task_id_t task_id)
    113113{
    114         int rc;
    115 
    116         rc = async_connect_kbox(task_id);
    117 
    118         if (rc == ENOTSUP) {
    119                 printf("You do not have userspace debugging support "
    120                     "compiled in the kernel.\n");
    121                 printf("Compile kernel with 'Support for userspace debuggers' "
    122                     "(CONFIG_UDEBUG) enabled.\n");
    123                 return rc;
    124         }
    125 
    126         if (rc < 0) {
     114        async_sess_t *ksess = async_connect_kbox(task_id);
     115       
     116        if (!ksess) {
     117                if (errno == ENOTSUP) {
     118                        printf("You do not have userspace debugging support "
     119                            "compiled in the kernel.\n");
     120                        printf("Compile kernel with 'Support for userspace debuggers' "
     121                            "(CONFIG_UDEBUG) enabled.\n");
     122                        return errno;
     123                }
     124               
    127125                printf("Error connecting\n");
    128                 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, rc);
    129                 return rc;
    130         }
    131 
    132         phoneid = rc;
    133 
    134         rc = udebug_begin(phoneid);
     126                printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno);
     127                return errno;
     128        }
     129       
     130        int rc = udebug_begin(ksess);
    135131        if (rc < 0) {
    136132                printf("udebug_begin() -> %d\n", rc);
    137133                return rc;
    138134        }
    139 
     135       
     136        sess = ksess;
    140137        return 0;
    141138}
     
    213210
    214211        /* TODO: See why NULL does not work. */
    215         rc = udebug_thread_read(phoneid, &dummy_buf, 0, &copied, &needed);
     212        rc = udebug_thread_read(sess, &dummy_buf, 0, &copied, &needed);
    216213        if (rc < 0) {
    217214                printf("udebug_thread_read() -> %d\n", rc);
     
    227224        thash_buf = malloc(buf_size);
    228225
    229         rc = udebug_thread_read(phoneid, thash_buf, buf_size, &copied, &needed);
     226        rc = udebug_thread_read(sess, thash_buf, buf_size, &copied, &needed);
    230227        if (rc < 0) {
    231228                printf("udebug_thread_read() -> %d\n", rc);
     
    262259        int rc;
    263260
    264         rc = udebug_areas_read(phoneid, &dummy_buf, 0, &copied, &needed);
     261        rc = udebug_areas_read(sess, &dummy_buf, 0, &copied, &needed);
    265262        if (rc < 0) {
    266263                printf("udebug_areas_read() -> %d\n", rc);
     
    271268        ainfo_buf = malloc(buf_size);
    272269
    273         rc = udebug_areas_read(phoneid, ainfo_buf, buf_size, &copied, &needed);
     270        rc = udebug_areas_read(sess, ainfo_buf, buf_size, &copied, &needed);
    274271        if (rc < 0) {
    275272                printf("udebug_areas_read() -> %d\n", rc);
     
    296293        if (write_core_file) {
    297294                printf("Writing core file '%s'\n", core_file_name);
    298                 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid);
     295                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess);
    299296                if (rc != EOK) {
    300297                        printf("Failed writing core file.\n");
     
    316313        int rc;
    317314
    318         rc = udebug_regs_read(phoneid, thash, &istate);
     315        rc = udebug_regs_read(sess, thash, &istate);
    319316        if (rc < 0) {
    320317                printf("Failed reading registers (%d).\n", rc);
     
    359356        (void) arg;
    360357
    361         rc = udebug_mem_read(phoneid, &data, addr, sizeof(data));
     358        rc = udebug_mem_read(sess, &data, addr, sizeof(data));
    362359        if (rc < 0) {
    363360                printf("Warning: udebug_mem_read() failed.\n");
     
    430427        int rc;
    431428
    432         rc = udebug_name_read(phoneid, &dummy_buf, 0, &copied, &needed);
     429        rc = udebug_name_read(sess, &dummy_buf, 0, &copied, &needed);
    433430        if (rc < 0)
    434431                return NULL;
     
    436433        name_size = needed;
    437434        name = malloc(name_size + 1);
    438         rc = udebug_name_read(phoneid, name, name_size, &copied, &needed);
     435        rc = udebug_name_read(sess, name, name_size, &copied, &needed);
    439436        if (rc < 0) {
    440437                free(name);
  • uspace/app/tester/Makefile

    r13ecdac9 r1affcdf3  
    2929
    3030USPACE_PREFIX = ../..
     31LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBEXT2_PREFIX)/libext2.a
     32EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX)
    3133BINARY = tester
    3234
    3335SOURCES = \
    3436        tester.c \
     37        util.c \
    3538        thread/thread1.c \
    3639        print/print1.c \
     
    4851        ipc/ping_pong.c \
    4952        loop/loop1.c \
     53        mm/common.c \
    5054        mm/malloc1.c \
    5155        mm/malloc2.c \
     56        mm/malloc3.c \
     57        mm/mapping1.c \
    5258        devs/devman1.c \
     59        devs/devman2.c \
    5360        hw/misc/virtchar1.c \
    54         hw/serial/serial1.c
     61        hw/serial/serial1.c \
     62        libext2/libext2_1.c
    5563
    5664include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tester/console/console1.c

    r13ecdac9 r1affcdf3  
    5050{
    5151        if (!test_quiet) {
     52                console_ctrl_t *console = console_init(stdin, stdout);
     53               
    5254                printf("Style test: ");
    53                 fflush(stdout);
    54                 console_set_style(fphone(stdout), STYLE_NORMAL);
     55                console_flush(console);
     56                console_set_style(console, STYLE_NORMAL);
    5557                printf(" normal ");
    56                 fflush(stdout);
    57                 console_set_style(fphone(stdout), STYLE_EMPHASIS);
     58                console_flush(console);
     59                console_set_style(console, STYLE_EMPHASIS);
    5860                printf(" emphasized ");
    59                 fflush(stdout);
    60                 console_set_style(fphone(stdout), STYLE_INVERTED);
     61                console_flush(console);
     62                console_set_style(console, STYLE_INVERTED);
    6163                printf(" inverted ");
    62                 fflush(stdout);
    63                 console_set_style(fphone(stdout), STYLE_SELECTED);
     64                console_flush(console);
     65                console_set_style(console, STYLE_SELECTED);
    6466                printf(" selected ");
    65                 fflush(stdout);
    66                 console_set_style(fphone(stdout), STYLE_NORMAL);
     67                console_flush(console);
     68                console_set_style(console, STYLE_NORMAL);
    6769                printf("\n");
    6870               
     
    7375                for (j = 0; j < 2; j++) {
    7476                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    75                                 fflush(stdout);
    76                                 console_set_color(fphone(stdout), i, COLOR_WHITE,
     77                                console_flush(console);
     78                                console_set_color(console, i, COLOR_WHITE,
    7779                                    j ? CATTR_BRIGHT : 0);
    7880                                printf(" %s ", color_name[i]);
    7981                        }
    80                         fflush(stdout);
    81                         console_set_style(fphone(stdout), STYLE_NORMAL);
     82                        console_flush(console);
     83                        console_set_style(console, STYLE_NORMAL);
    8284                        putchar('\n');
    8385                }
     
    8688                for (j = 0; j < 2; j++) {
    8789                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    88                                 fflush(stdout);
    89                                 console_set_color(fphone(stdout), COLOR_WHITE, i,
     90                                console_flush(console);
     91                                console_set_color(console, COLOR_WHITE, i,
    9092                                    j ? CATTR_BRIGHT : 0);
    9193                                printf(" %s ", color_name[i]);
    9294                        }
    93                         fflush(stdout);
    94                         console_set_style(fphone(stdout), STYLE_NORMAL);
     95                        console_flush(console);
     96                        console_set_style(console, STYLE_NORMAL);
    9597                        putchar('\n');
    9698                }
     
    99101               
    100102                for (i = 0; i < 255; i += 16) {
    101                         fflush(stdout);
    102                         console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
     103                        console_flush(console);
     104                        console_set_rgb_color(console, (255 - i) << 16, i << 16);
    103105                        putchar('X');
    104106                }
    105                 fflush(stdout);
    106                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     107                console_flush(console);
     108                console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0);
    107109                putchar('\n');
    108110               
    109111                for (i = 0; i < 255; i += 16) {
    110                         fflush(stdout);
    111                         console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
     112                        console_flush(console);
     113                        console_set_rgb_color(console, (255 - i) << 8, i << 8);
    112114                        putchar('X');
    113115                }
    114                 fflush(stdout);
    115                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     116                console_flush(console);
     117                console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0);
    116118                putchar('\n');
    117119               
    118120                for (i = 0; i < 255; i += 16) {
    119                         fflush(stdout);
    120                         console_set_rgb_color(fphone(stdout), 255 - i, i);
     121                        console_flush(console);
     122                        console_set_rgb_color(console, 255 - i, i);
    121123                        putchar('X');
    122124                }
    123                 fflush(stdout);
    124                 console_set_style(fphone(stdout), STYLE_NORMAL);
     125                console_flush(console);
     126                console_set_style(console, STYLE_NORMAL);
    125127                putchar('\n');
    126128        }
  • uspace/app/tester/hw/misc/virtchar1.c

    r13ecdac9 r1affcdf3  
    4343#include <str.h>
    4444#include <vfs/vfs.h>
     45#include <vfs/vfs_sess.h>
    4546#include <sys/stat.h>
    4647#include <fcntl.h>
     
    6667        TPRINTF("   ...file handle %d\n", fd);
    6768
    68         TPRINTF(" Asking for phone...\n");
    69         int phone = fd_phone(fd);
    70         if (phone < 0) {
     69        TPRINTF(" Asking for session...\n");
     70        async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     71        if (!sess) {
    7172                close(fd);
    72                 TPRINTF("   ...error: %s\n", str_error(phone));
    73                 return "Failed to get phone to device";
     73                TPRINTF("   ...error: %s\n", str_error(errno));
     74                return "Failed to get session to device";
    7475        }
    75         TPRINTF("   ...phone is %d\n", phone);
     76        TPRINTF("   ...session is %p\n", sess);
    7677       
    7778        TPRINTF(" Will try to read...\n");
    7879        size_t i;
    7980        char buffer[BUFFER_SIZE];
    80         char_dev_read(phone, buffer, BUFFER_SIZE);
     81        char_dev_read(sess, buffer, BUFFER_SIZE);
    8182        TPRINTF(" ...verifying that we read zeroes only...\n");
    8283        for (i = 0; i < BUFFER_SIZE; i++) {
     
    8889       
    8990        /* Clean-up. */
    90         TPRINTF(" Closing phones and file descriptors\n");
    91         async_hangup(phone);
     91        TPRINTF(" Closing session and file descriptor\n");
     92        async_hangup(sess);
    9293        close(fd);
    9394       
  • uspace/app/tester/hw/serial/serial1.c

    r13ecdac9 r1affcdf3  
    7171                }
    7272       
    73         int res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING);
    74        
    7573        devman_handle_t handle;
    76         res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
     74        int res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,
    7775            IPC_FLAG_BLOCKING);
    7876        if (res != EOK)
    7977                return "Could not get serial device handle";
    8078       
    81         int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING);
    82         if (phone < 0) {
    83                 devman_hangup_phone(DEVMAN_CLIENT);
     79        async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
     80            IPC_FLAG_BLOCKING);
     81        if (!sess)
    8482                return "Unable to connect to serial device";
    85         }
    8683       
    8784        char *buf = (char *) malloc(cnt + 1);
    8885        if (buf == NULL) {
    89                 async_hangup(phone);
    90                 devman_hangup_phone(DEVMAN_CLIENT);
     86                async_hangup(sess);
    9187                return "Failed to allocate input buffer";
    9288        }
     
    9793        sysarg_t old_word_size;
    9894       
    99         res = async_req_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud,
     95        async_exch_t *exch = async_exchange_begin(sess);
     96        res = async_req_0_4(exch, SERIAL_GET_COM_PROPS, &old_baud,
    10097            &old_par, &old_word_size, &old_stop);
     98        async_exchange_end(exch);
     99       
    101100        if (res != EOK) {
    102101                free(buf);
    103                 async_hangup(phone);
    104                 devman_hangup_phone(DEVMAN_CLIENT);
     102                async_hangup(sess);
    105103                return "Failed to get old serial communication parameters";
    106104        }
    107105       
    108         res = async_req_4_0(phone, SERIAL_SET_COM_PROPS, 1200,
     106        exch = async_exchange_begin(sess);
     107        res = async_req_4_0(exch, SERIAL_SET_COM_PROPS, 1200,
    109108            SERIAL_NO_PARITY, 8, 1);
     109        async_exchange_end(exch);
     110       
    110111        if (EOK != res) {
    111112                free(buf);
    112                 async_hangup(phone);
    113                 devman_hangup_phone(DEVMAN_CLIENT);
     113                async_hangup(sess);
    114114                return "Failed to set serial communication parameters";
    115115        }
     
    120120        size_t total = 0;
    121121        while (total < cnt) {
    122                 ssize_t read = char_dev_read(phone, buf, cnt - total);
     122                ssize_t read = char_dev_read(sess, buf, cnt - total);
    123123               
    124124                if (read < 0) {
    125                         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     125                        exch = async_exchange_begin(sess);
     126                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    126127                            old_par, old_word_size, old_stop);
     128                        async_exchange_end(exch);
     129                       
    127130                        free(buf);
    128                         async_hangup(phone);
    129                         devman_hangup_phone(DEVMAN_CLIENT);
     131                        async_hangup(sess);
    130132                        return "Failed read from serial device";
    131133                }
    132134               
    133135                if ((size_t) read > cnt - total) {
    134                         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     136                        exch = async_exchange_begin(sess);
     137                        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    135138                            old_par, old_word_size, old_stop);
     139                        async_exchange_end(exch);
     140                       
    136141                        free(buf);
    137                         async_hangup(phone);
    138                         devman_hangup_phone(DEVMAN_CLIENT);
     142                        async_hangup(sess);
    139143                        return "Read more data than expected";
    140144                }
     
    151155                         * direction of data transfer.
    152156                         */
    153                         ssize_t written = char_dev_write(phone, buf, read);
     157                        ssize_t written = char_dev_write(sess, buf, read);
    154158                       
    155159                        if (written < 0) {
    156                                 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     160                                exch = async_exchange_begin(sess);
     161                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    157162                                    old_par, old_word_size, old_stop);
     163                                async_exchange_end(exch);
     164                               
    158165                                free(buf);
    159                                 async_hangup(phone);
    160                                 devman_hangup_phone(DEVMAN_CLIENT);
     166                                async_hangup(sess);
    161167                                return "Failed write to serial device";
    162168                        }
    163169                       
    164170                        if (written != read) {
    165                                 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     171                                exch = async_exchange_begin(sess);
     172                                async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    166173                                    old_par, old_word_size, old_stop);
     174                                async_exchange_end(exch);
     175                               
    167176                                free(buf);
    168                                 async_hangup(phone);
    169                                 devman_hangup_phone(DEVMAN_CLIENT);
     177                                async_hangup(sess);
    170178                                return "Written less data than read from serial device";
    171179                        }
     
    180188       
    181189        size_t eot_size = str_size(EOT);
    182         ssize_t written = char_dev_write(phone, (void *) EOT, eot_size);
    183        
    184         async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud,
     190        ssize_t written = char_dev_write(sess, (void *) EOT, eot_size);
     191       
     192        exch = async_exchange_begin(sess);
     193        async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud,
    185194            old_par, old_word_size, old_stop);
     195        async_exchange_end(exch);
     196       
    186197        free(buf);
    187         async_hangup(phone);
    188         devman_hangup_phone(DEVMAN_CLIENT);
     198        async_hangup(sess);
    189199       
    190200        if (written < 0)
  • uspace/app/tester/ipc/ping_pong.c

    r13ecdac9 r1affcdf3  
    3030#include <stdlib.h>
    3131#include <sys/time.h>
    32 #include <ipc/ns.h>
     32#include <ns.h>
    3333#include <async.h>
    3434#include <errno.h>
     
    6161                size_t i;
    6262                for (i = 0; i < COUNT_GRANULARITY; i++) {
    63                         int retval = async_req_0_0(PHONE_NS, NS_PING);
     63                        int retval = ns_ping();
    6464                       
    6565                        if (retval != EOK) {
  • uspace/app/tester/mm/malloc1.c

    r13ecdac9 r1affcdf3  
    3030
    3131#include <stdio.h>
    32 #include <unistd.h>
    3332#include <stdlib.h>
    34 #include <malloc.h>
     33#include "common.h"
    3534#include "../tester.h"
    3635
     
    4544 */
    4645
    47 /**
    48  * sizeof_array
    49  * @array array to determine the size of
    50  *
    51  * Returns the size of @array in array elements.
    52  */
    53 #define sizeof_array(array) \
    54         (sizeof(array) / sizeof((array)[0]))
    55 
    56 #define MAX_ALLOC (16 * 1024 * 1024)
    57 
    58 /*
    59  * Subphase control structures: subphase termination conditions,
    60  * probabilities of individual actions, subphase control structure.
    61  */
    62 
    63 typedef struct {
    64         unsigned int max_cycles;
    65         unsigned int no_memory;
    66         unsigned int no_allocated;
    67 } sp_term_cond_s;
    68 
    69 typedef struct {
    70         unsigned int alloc;
    71         unsigned int free;
    72 } sp_action_prob_s;
    73 
    74 typedef struct {
    75         const char *name;
    76         sp_term_cond_s cond;
    77         sp_action_prob_s prob;
    78 } subphase_s;
    79 
    80 
    81 /*
    82  * Phase control structures: The minimum and maximum block size that
    83  * can be allocated during the phase execution, phase control structure.
    84  */
    85 
    86 typedef struct {
    87         size_t min_block_size;
    88         size_t max_block_size;
    89 } ph_alloc_size_s;
    90 
    91 typedef struct {
    92         const char *name;
    93         ph_alloc_size_s alloc;
    94         subphase_s *subphases;
    95 } phase_s;
    96 
    97 
    9846/*
    9947 * Subphases are defined separately here. This is for two reasons:
     
    10149 * how many subphases a phase contains.
    10250 */
    103 static subphase_s subphases_32B[] = {
     51static subphase_t subphases_32B[] = {
    10452        {
    10553                .name = "Allocation",
     
    14088};
    14189
    142 static subphase_s subphases_128K[] = {
     90static subphase_t subphases_128K[] = {
    14391        {
    14492                .name = "Allocation",
     
    179127};
    180128
    181 static subphase_s subphases_default[] = {
     129static subphase_t subphases_default[] = {
    182130        {
    183131                .name = "Allocation",
     
    217165        }
    218166};
    219 
    220167
    221168/*
    222169 * Phase definitions.
    223170 */
    224 static phase_s phases[] = {
     171static phase_t phases[] = {
    225172        {
    226173                .name = "32 B memory blocks",
     
    257204};
    258205
    259 
    260 /*
    261  * Global error flag. The flag is set if an error
    262  * is encountered (overlapping blocks, inconsistent
    263  * block data, etc.)
    264  */
    265 static bool error_flag = false;
    266 
    267 /*
    268  * Memory accounting: the amount of allocated memory and the
    269  * number and list of allocated blocks.
    270  */
    271 static size_t mem_allocated;
    272 static size_t mem_blocks_count;
    273 
    274 static LIST_INITIALIZE(mem_blocks);
    275 
    276 typedef struct {
    277         /* Address of the start of the block */
    278         void *addr;
    279        
    280         /* Size of the memory block */
    281         size_t size;
    282        
    283         /* link to other blocks */
    284         link_t link;
    285 } mem_block_s;
    286 
    287 typedef mem_block_s *mem_block_t;
    288 
    289 
    290 /** init_mem
    291  *
    292  * Initializes the memory accounting structures.
    293  *
    294  */
    295 static void init_mem(void)
     206static void do_subphase(phase_t *phase, subphase_t *subphase)
    296207{
    297         mem_allocated = 0;
    298         mem_blocks_count = 0;
    299 }
    300 
    301 
    302 static bool overlap_match(link_t *entry, void *addr, size_t size)
    303 {
    304         mem_block_t mblk = list_get_instance(entry, mem_block_s, link);
    305        
    306         /* Entry block control structure <mbeg, mend) */
    307         uint8_t *mbeg = (uint8_t *) mblk;
    308         uint8_t *mend = (uint8_t *) mblk + sizeof(mem_block_s);
    309        
    310         /* Entry block memory <bbeg, bend) */
    311         uint8_t *bbeg = (uint8_t *) mblk->addr;
    312         uint8_t *bend = (uint8_t *) mblk->addr + mblk->size;
    313        
    314         /* Data block <dbeg, dend) */
    315         uint8_t *dbeg = (uint8_t *) addr;
    316         uint8_t *dend = (uint8_t *) addr + size;
    317        
    318         /* Check for overlaps */
    319         if (((mbeg >= dbeg) && (mbeg < dend)) ||
    320                 ((mend > dbeg) && (mend <= dend)) ||
    321                 ((bbeg >= dbeg) && (bbeg < dend)) ||
    322                 ((bend > dbeg) && (bend <= dend)))
    323                 return true;
    324        
    325         return false;
    326 }
    327 
    328 
    329 /** test_overlap
    330  *
    331  * Test whether a block starting at @addr overlaps with another, previously
    332  * allocated memory block or its control structure.
    333  *
    334  * @param addr Initial address of the block
    335  * @param size Size of the block
    336  *
    337  * @return false if the block does not overlap.
    338  *
    339  */
    340 static int test_overlap(void *addr, size_t size)
    341 {
    342         link_t *entry;
    343         bool fnd = false;
    344        
    345         for (entry = mem_blocks.next; entry != &mem_blocks; entry = entry->next) {
    346                 if (overlap_match(entry, addr, size)) {
    347                         fnd = true;
    348                         break;
    349                 }
    350         }
    351        
    352         return fnd;
    353 }
    354 
    355 
    356 /** checked_malloc
    357  *
    358  * Allocate @size bytes of memory and check whether the chunk comes
    359  * from the non-mapped memory region and whether the chunk overlaps
    360  * with other, previously allocated, chunks.
    361  *
    362  * @param size Amount of memory to allocate
    363  *
    364  * @return NULL if the allocation failed. Sets the global error_flag to
    365  *         true if the allocation succeeded but is illegal.
    366  *
    367  */
    368 static void *checked_malloc(size_t size)
    369 {
    370         void *data;
    371        
    372         /* Allocate the chunk of memory */
    373         data = malloc(size);
    374         if (data == NULL)
    375                 return NULL;
    376        
    377         /* Check for overlaps with other chunks */
    378         if (test_overlap(data, size)) {
    379                 TPRINTF("\nError: Allocated block overlaps with another "
    380                         "previously allocated block.\n");
    381                 error_flag = true;
    382         }
    383        
    384         return data;
    385 }
    386 
    387 
    388 /** alloc_block
    389  *
    390  * Allocate a block of memory of @size bytes and add record about it into
    391  * the mem_blocks list. Return a pointer to the block holder structure or
    392  * NULL if the allocation failed.
    393  *
    394  * If the allocation is illegal (e.g. the memory does not come from the
    395  * right region or some of the allocated blocks overlap with others),
    396  * set the global error_flag.
    397  *
    398  * @param size Size of the memory block
    399  *
    400  */
    401 static mem_block_t alloc_block(size_t size)
    402 {
    403         /* Check for allocation limit */
    404         if (mem_allocated >= MAX_ALLOC)
    405                 return NULL;
    406        
    407         /* Allocate the block holder */
    408         mem_block_t block = (mem_block_t) checked_malloc(sizeof(mem_block_s));
    409         if (block == NULL)
    410                 return NULL;
    411        
    412         link_initialize(&block->link);
    413        
    414         /* Allocate the block memory */
    415         block->addr = checked_malloc(size);
    416         if (block->addr == NULL) {
    417                 free(block);
    418                 return NULL;
    419         }
    420        
    421         block->size = size;
    422        
    423         /* Register the allocated block */
    424         list_append(&block->link, &mem_blocks);
    425         mem_allocated += size + sizeof(mem_block_s);
    426         mem_blocks_count++;
    427        
    428         return block;
    429 }
    430 
    431 
    432 /** free_block
    433  *
    434  * Free the block of memory and the block control structure allocated by
    435  * alloc_block. Set the global error_flag if an error occurs.
    436  *
    437  * @param block Block control structure
    438  *
    439  */
    440 static void free_block(mem_block_t block)
    441 {
    442         /* Unregister the block */
    443         list_remove(&block->link);
    444         mem_allocated -= block->size + sizeof(mem_block_s);
    445         mem_blocks_count--;
    446        
    447         /* Free the memory */
    448         free(block->addr);
    449         free(block);
    450 }
    451 
    452 
    453 /** expected_value
    454  *
    455  * Compute the expected value of a byte located at @pos in memory
    456  * block described by @blk.
    457  *
    458  * @param blk Memory block control structure
    459  * @param pos Position in the memory block data area
    460  *
    461  */
    462 static inline uint8_t expected_value(mem_block_t blk, uint8_t *pos)
    463 {
    464         return ((unsigned long) blk ^ (unsigned long) pos) & 0xff;
    465 }
    466 
    467 
    468 /** fill_block
    469  *
    470  * Fill the memory block controlled by @blk with data.
    471  *
    472  * @param blk Memory block control structure
    473  *
    474  */
    475 static void fill_block(mem_block_t blk)
    476 {
    477         uint8_t *pos;
    478         uint8_t *end;
    479        
    480         for (pos = blk->addr, end = pos + blk->size; pos < end; pos++)
    481                 *pos = expected_value(blk, pos);
    482 }
    483 
    484 
    485 /** check_block
    486  *
    487  * Check whether the block @blk contains the data it was filled with.
    488  * Set global error_flag if an error occurs.
    489  *
    490  * @param blk Memory block control structure
    491  *
    492  */
    493 static void check_block(mem_block_t blk)
    494 {
    495         uint8_t *pos;
    496         uint8_t *end;
    497        
    498         for (pos = blk->addr, end = pos + blk->size; pos < end; pos++) {
    499                 if (*pos != expected_value (blk, pos)) {
    500                         TPRINTF("\nError: Corrupted content of a data block.\n");
    501                         error_flag = true;
    502                         return;
    503                 }
    504         }
    505 }
    506 
    507 
    508 static link_t *list_get_nth(link_t *list, unsigned int i)
    509 {
    510         unsigned int cnt = 0;
    511         link_t *entry;
    512        
    513         for (entry = list->next; entry != list; entry = entry->next) {
    514                 if (cnt == i)
    515                         return entry;
    516                
    517                 cnt++;
    518         }
    519        
    520         return NULL;
    521 }
    522 
    523 
    524 /** get_random_block
    525  *
    526  * Select a random memory block from the list of allocated blocks.
    527  *
    528  * @return Block control structure or NULL if the list is empty.
    529  *
    530  */
    531 static mem_block_t get_random_block(void)
    532 {
    533         if (mem_blocks_count == 0)
    534                 return NULL;
    535        
    536         unsigned int blkidx = rand() % mem_blocks_count;
    537         link_t *entry = list_get_nth(&mem_blocks, blkidx);
    538        
    539         if (entry == NULL) {
    540                 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n");
    541                 error_flag = true;
    542         }
    543        
    544         return list_get_instance(entry, mem_block_s, link);
    545 }
    546 
    547 
    548 #define RETURN_IF_ERROR \
    549 { \
    550         if (error_flag) \
    551                 return; \
    552 }
    553 
    554 
    555 static void do_subphase(phase_s *phase, subphase_s *subphase)
    556 {
    557         unsigned int cycles;
    558         for (cycles = 0; /* always */; cycles++) {
    559                
    560                 if (subphase->cond.max_cycles &&
    561                         cycles >= subphase->cond.max_cycles) {
     208        for (unsigned int cycles = 0; /* always */; cycles++) {
     209               
     210                if ((subphase->cond.max_cycles) &&
     211                    (cycles >= subphase->cond.max_cycles)) {
    562212                        /*
    563213                         * We have performed the required number of
     
    572222                unsigned int rnd = rand() % 100;
    573223                if (rnd < subphase->prob.alloc) {
    574                         /* Compute a random number lying in interval <min_block_size, max_block_size> */
     224                        /*
     225                         * Compute a random number lying in interval
     226                         * <min_block_size, max_block_size>
     227                         */
    575228                        int alloc = phase->alloc.min_block_size +
    576229                            (rand() % (phase->alloc.max_block_size - phase->alloc.min_block_size + 1));
    577230                       
    578                         mem_block_t blk = alloc_block(alloc);
     231                        mem_block_t *blk = alloc_block(alloc);
    579232                        RETURN_IF_ERROR;
    580233                       
     
    585238                                        break;
    586239                                }
    587                                
    588240                        } else {
    589241                                TPRINTF("A");
    590242                                fill_block(blk);
     243                                RETURN_IF_ERROR;
    591244                        }
    592245                       
    593246                } else if (rnd < subphase->prob.free) {
    594                         mem_block_t blk = get_random_block();
     247                        mem_block_t *blk = get_random_block();
    595248                        if (blk == NULL) {
    596249                                TPRINTF("F(R)");
     
    599252                                        break;
    600253                                }
    601                                
    602254                        } else {
    603255                                TPRINTF("R");
     
    614266}
    615267
    616 
    617 static void do_phase(phase_s *phase)
     268static void do_phase(phase_t *phase)
    618269{
    619         unsigned int subno;
    620        
    621         for (subno = 0; subno < 3; subno++) {
    622                 subphase_s *subphase = & phase->subphases [subno];
     270        for (unsigned int subno = 0; subno < 3; subno++) {
     271                subphase_t *subphase = &phase->subphases[subno];
    623272               
    624273                TPRINTF(".. Sub-phase %u (%s)\n", subno + 1, subphase->name);
     
    632281        init_mem();
    633282       
    634         unsigned int phaseno;
    635         for (phaseno = 0; phaseno < sizeof_array(phases); phaseno++) {
    636                 phase_s *phase = &phases[phaseno];
     283        for (unsigned int phaseno = 0; phaseno < sizeof_array(phases);
     284            phaseno++) {
     285                phase_t *phase = &phases[phaseno];
    637286               
    638287                TPRINTF("Entering phase %u (%s)\n", phaseno + 1, phase->name);
     
    645294        }
    646295       
     296        TPRINTF("Cleaning up.\n");
     297        done_mem();
    647298        if (error_flag)
    648299                return "Test failed";
  • uspace/app/tester/tester.c

    r13ecdac9 r1affcdf3  
    6363#include "mm/malloc1.def"
    6464#include "mm/malloc2.def"
     65#include "mm/malloc3.def"
     66#include "mm/mapping1.def"
    6567#include "hw/serial/serial1.def"
    6668#include "hw/misc/virtchar1.def"
     69#include "libext2/libext2_1.def"
    6770#include "devs/devman1.def"
     71#include "devs/devman2.def"
    6872        {NULL, NULL, NULL, false}
    6973};
  • uspace/app/tester/tester.h

    r13ecdac9 r1affcdf3  
    3838#include <sys/types.h>
    3939#include <bool.h>
     40#include <stacktrace.h>
    4041
    4142#define IPC_TEST_SERVICE  10240
     
    4647extern char **test_argv;
    4748
     49/**
     50 * sizeof_array
     51 * @array array to determine the size of
     52 *
     53 * Returns the size of @array in array elements.
     54 */
     55#define sizeof_array(array) \
     56        (sizeof(array) / sizeof((array)[0]))
     57
    4858#define TPRINTF(format, ...) \
    49         { \
     59        do { \
    5060                if (!test_quiet) { \
    51                         fprintf(stderr, format, ##__VA_ARGS__); \
     61                        fprintf(stderr, (format), ##__VA_ARGS__); \
    5262                } \
    53         }
     63        } while (0)
     64
     65#define TSTACKTRACE() \
     66        do { \
     67                if (!test_quiet) { \
     68                        stacktrace_print(); \
     69                } \
     70        } while (0)
    5471
    5572typedef const char *(*test_entry_t)(void);
     
    7996extern const char *test_malloc1(void);
    8097extern const char *test_malloc2(void);
     98extern const char *test_malloc3(void);
     99extern const char *test_mapping1(void);
    81100extern const char *test_serial1(void);
    82101extern const char *test_virtchar1(void);
     102extern const char *test_libext2_1(void);
    83103extern const char *test_devman1(void);
     104extern const char *test_devman2(void);
    84105
    85106extern test_t tests[];
  • uspace/app/testread/Makefile

    r13ecdac9 r1affcdf3  
    11#
    2 # Copyright (c) 2008 Jiri Svoboda
     2# Copyright (c) 2011 Martin Sucha
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 ARCH_SOURCES = arch/$(UARCH)/abs32le.c
     29USPACE_PREFIX = ../..
     30BINARY = testread
     31
     32SOURCES = \
     33        testread.c
     34
     35include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/tetris/Makefile

    r13ecdac9 r1affcdf3  
    3434        shapes.c \
    3535        scores.c \
    36         input.c \
    3736        tetris.c \
    3837        screen.c
  • uspace/app/tetris/scores.c

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray Exp $ */
    2 /*      $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $   */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)scores.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * scores.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd
     33 * OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    6068#include <err.h>
    6169#include <time.h>
    62 
    6370#include "screen.h"
    6471#include "tetris.h"
     
    118125        int j;
    119126        size_t off;
    120         console_event_t ev;
     127        kbd_event_t ev;
    121128       
    122129        clear_screen();
     
    133140       
    134141        while (1) {
    135                 fflush(stdout);
    136                 if (!console_get_event(fphone(stdin), &ev))
     142                console_flush(console);
     143                if (!console_get_kbd_event(console, &ev))
    137144                        exit(1);
    138145               
  • uspace/app/tetris/scores.h

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * scores.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd
     33 * OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)scores.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
     
    4149/** @file
    4250 */
    43 
    4451
    4552/*
  • uspace/app/tetris/screen.c

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray Exp $ */
    2 /*      $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $       */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)screen.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * screen.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft
     33 * OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    6977static const struct shape *lastshape;
    7078
     79static suseconds_t timeleft = 0;
     80
     81console_ctrl_t *console;
     82
    7183
    7284/*
     
    8294static void start_standout(uint32_t color)
    8395{
    84         fflush(stdout);
    85         console_set_rgb_color(fphone(stdout), 0xffffff,
     96        console_flush(console);
     97        console_set_rgb_color(console, 0xffffff,
    8698            use_color ? color : 0x000000);
    8799}
     
    89101static void resume_normal(void)
    90102{
    91         fflush(stdout);
    92         console_set_style(fphone(stdout), STYLE_NORMAL);
     103        console_flush(console);
     104        console_set_style(console, STYLE_NORMAL);
    93105}
    94106
    95107void clear_screen(void)
    96108{
    97         console_clear(fphone(stdout));
     109        console_clear(console);
    98110        moveto(0, 0);
    99111}
     
    105117{
    106118        resume_normal();
    107         console_clear(fphone(stdout));
     119        console_clear(console);
    108120        curscore = -1;
    109121        memset(curscreen, 0, sizeof(curscreen));
     
    115127void scr_init(void)
    116128{
    117         console_cursor_visibility(fphone(stdout), 0);
     129        console_cursor_visibility(console, 0);
    118130        resume_normal();
    119131        scr_clear();
     
    122134void moveto(sysarg_t r, sysarg_t c)
    123135{
    124         fflush(stdout);
    125         console_set_pos(fphone(stdout), c, r);
     136        console_flush(console);
     137        console_set_pos(console, c, r);
    126138}
    127139
     
    130142static int get_display_size(winsize_t *ws)
    131143{
    132         return console_get_size(fphone(stdout), &ws->ws_col, &ws->ws_row);
     144        return console_get_size(console, &ws->ws_col, &ws->ws_row);
    133145}
    134146
     
    136148{
    137149        sysarg_t ccap;
    138         int rc = console_get_color_cap(fphone(stdout), &ccap);
     150        int rc = console_get_color_cap(console, &ccap);
    139151       
    140152        if (rc != 0)
     
    179191void scr_end(void)
    180192{
    181         console_cursor_visibility(fphone(stdout), 1);
     193        console_cursor_visibility(console, 1);
    182194}
    183195
     
    302314                resume_normal();
    303315       
    304         fflush(stdout);
     316        console_flush(console);
    305317}
    306318
     
    322334}
    323335
     336/** Sleep for the current turn time
     337 *
     338 * Eat any input that might be available.
     339 *
     340 */
     341void tsleep(void)
     342{
     343        suseconds_t timeout = fallrate;
     344       
     345        while (timeout > 0) {
     346                kbd_event_t event;
     347               
     348                if (!console_get_kbd_event_timeout(console, &event, &timeout))
     349                        break;
     350        }
     351}
     352
     353/** Get char with timeout
     354 *
     355 */
     356int tgetchar(void)
     357{
     358        /*
     359         * Reset timeleft to fallrate whenever it is not positive
     360         * and increase speed.
     361         */
     362       
     363        if (timeleft <= 0) {
     364                faster();
     365                timeleft = fallrate;
     366        }
     367       
     368        /*
     369         * Wait to see if there is any input. If so, take it and
     370         * update timeleft so that the next call to tgetchar()
     371         * will not wait as long. If there is no input,
     372         * make timeleft zero and return -1.
     373         */
     374       
     375        wchar_t c = 0;
     376       
     377        while (c == 0) {
     378                kbd_event_t event;
     379               
     380                if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
     381                        timeleft = 0;
     382                        return -1;
     383                }
     384               
     385                if (event.type == KEY_PRESS)
     386                        c = event.c;
     387        }
     388       
     389        return (int) c;
     390}
     391
     392/** Get char without timeout
     393 *
     394 */
     395int twait(void)
     396{
     397        wchar_t c = 0;
     398       
     399        while (c == 0) {
     400                kbd_event_t event;
     401               
     402                if (!console_get_kbd_event(console, &event))
     403                        return -1;
     404               
     405                if (event.type == KEY_PRESS)
     406                        c = event.c;
     407        }
     408       
     409        return (int) c;
     410}
     411
    324412/** @}
    325413 */
  • uspace/app/tetris/screen.h

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * screen.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd
     33 * OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)screen.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
     
    4856
    4957#include <sys/types.h>
     58#include <io/console.h>
    5059#include <async.h>
    5160#include <bool.h>
     
    5665} winsize_t;
    5766
     67extern console_ctrl_t *console;
    5868extern winsize_t winsize;
    5969
     
    6171extern void clear_screen(void);
    6272
    63 /* just calls putchar; for tputs */
    6473extern int put(int);
    6574extern void scr_clear(void);
     
    7079extern void scr_update(void);
    7180
     81extern void tsleep(void);
     82extern int tgetchar(void);
     83extern int twait(void);
     84
    7285/** @}
    7386 */
  • uspace/app/tetris/shapes.c

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt Exp $      */
    2 /*      $NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * shapes.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd
     33 * OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)shapes.c    8.1 (Berkeley) 5/31/93
    3644 */
    3745
  • uspace/app/tetris/tetris.c

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */
    2 /*      $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $   */
    3 
    4 /*-
    5  * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
    7  *
    8  * This code is derived from software contributed to Berkeley by
    9  * Chris Torek and Darren F. Provine.
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
    104 *
    115 * Redistribution and use in source and binary forms, with or without
    126 * modification, are permitted provided that the following conditions
    137 * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)tetris.c    8.1 (Berkeley) 5/31/93
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28
     29/** Attributations
     30 *
     31 * tetris.c 8.1 (Berkeley) 5/31/93
     32 * NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd
     33 * OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray
     34 *
     35 * Based upon BSD Tetris
     36 *
     37 * Copyright (c) 1992, 1993
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
     40 *
     41 * This code is derived from software contributed to Berkeley by
     42 * Chris Torek and Darren F. Provine.
     43 *
    3644 */
    3745
     
    5664#include <unistd.h>
    5765#include <getopt.h>
    58 
    59 #include "input.h"
    6066#include "scores.h"
    6167#include "screen.h"
     
    245251        int ch;
    246252       
     253        console = console_init(stdin, stdout);
     254       
    247255        keys = "jkl pq";
    248256       
    249257        classic = 0;
    250         showpreview = 1; 
     258        showpreview = 1;
    251259       
    252260        while ((ch = getopt(argc, argv, "ck:ps")) != -1)
     
    371379                                        scr_msg(key_msg, 0);
    372380                                        scr_msg(msg, 1);
    373                                         (void) fflush(stdout);
    374                                 } while (rwait((struct timeval *) NULL) == -1);
     381                                        console_flush(console);
     382                                } while (!twait());
    375383                               
    376384                                scr_msg(msg, 0);
  • uspace/app/tetris/tetris.h

    r13ecdac9 r1affcdf3  
    1 /*      $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $      */
    2 /*      $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $   */
     1/*
     2 * Copyright (c) 2011 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    328
    4 /*-
     29/** Attributations
     30 *
     31 * tetris.h 8.1 (Berkeley) 5/31/93
     32 * NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd
     33 * OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert
     34 *
     35 * Based upon BSD Tetris
     36 *
    537 * Copyright (c) 1992, 1993
    6  *      The Regents of the University of California.  All rights reserved.
     38 *      The Regents of the University of California.
     39 *      Distributed under BSD license.
    740 *
    841 * This code is derived from software contributed to Berkeley by
    942 * Chris Torek and Darren F. Provine.
    1043 *
    11  * Redistribution and use in source and binary forms, with or without
    12  * modification, are permitted provided that the following conditions
    13  * are met:
    14  * 1. Redistributions of source code must retain the above copyright
    15  *    notice, this list of conditions and the following disclaimer.
    16  * 2. Redistributions in binary form must reproduce the above copyright
    17  *    notice, this list of conditions and the following disclaimer in the
    18  *    documentation and/or other materials provided with the distribution.
    19  * 3. Neither the name of the University nor the names of its contributors
    20  *    may be used to endorse or promote products derived from this software
    21  *    without specific prior written permission.
    22  *
    23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    33  * SUCH DAMAGE.
    34  *
    35  *      @(#)tetris.h    8.1 (Berkeley) 5/31/93
    3644 */
    3745
  • uspace/app/top/Makefile

    r13ecdac9 r1affcdf3  
    3333SOURCES = \
    3434        top.c \
    35         screen.c \
    36         input.c
     35        screen.c
    3736
    3837include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/top/screen.c

    r13ecdac9 r1affcdf3  
    4646#include "top.h"
    4747
     48#define USEC_COUNT  1000000
     49
    4850static sysarg_t warn_col = 0;
    4951static sysarg_t warn_row = 0;
     52static suseconds_t timeleft = 0;
     53
     54console_ctrl_t *console;
    5055
    5156static void screen_style_normal(void)
    5257{
    53         fflush(stdout);
    54         console_set_style(fphone(stdout), STYLE_NORMAL);
     58        console_flush(console);
     59        console_set_style(console, STYLE_NORMAL);
    5560}
    5661
    5762static void screen_style_inverted(void)
    5863{
    59         fflush(stdout);
    60         console_set_style(fphone(stdout), STYLE_INVERTED);
     64        console_flush(console);
     65        console_set_style(console, STYLE_INVERTED);
    6166}
    6267
    6368static void screen_moveto(sysarg_t col, sysarg_t row)
    6469{
    65         fflush(stdout);
    66         console_set_pos(fphone(stdout), col, row);
     70        console_flush(console);
     71        console_set_pos(console, col, row);
    6772}
    6873
    6974static void screen_get_pos(sysarg_t *col, sysarg_t *row)
    7075{
    71         fflush(stdout);
    72         console_get_pos(fphone(stdout), col, row);
     76        console_flush(console);
     77        console_get_pos(console, col, row);
    7378}
    7479
    7580static void screen_get_size(sysarg_t *col, sysarg_t *row)
    7681{
    77         fflush(stdout);
    78         console_get_size(fphone(stdout), col, row);
     82        console_flush(console);
     83        console_get_size(console, col, row);
    7984}
    8085
     
    8489       
    8590        if (clear) {
    86                 fflush(stdout);
    87                 console_clear(fphone(stdout));
     91                console_flush(console);
     92                console_clear(console);
    8893        }
    8994       
     
    111116void screen_init(void)
    112117{
    113         fflush(stdout);
    114         console_cursor_visibility(fphone(stdout), false);
     118        console = console_init(stdin, stdout);
     119       
     120        console_flush(console);
     121        console_cursor_visibility(console, false);
    115122       
    116123        screen_restart(true);
     
    121128        screen_restart(true);
    122129       
    123         fflush(stdout);
    124         console_cursor_visibility(fphone(stdout), true);
     130        console_flush(console);
     131        console_cursor_visibility(console, true);
    125132}
    126133
     
    508515        }
    509516       
    510         fflush(stdout);
     517        console_flush(console);
    511518}
    512519
     
    521528       
    522529        screen_newline();
    523         fflush(stdout);
     530        console_flush(console);
     531}
     532
     533/** Get char with timeout
     534 *
     535 */
     536int tgetchar(unsigned int sec)
     537{
     538        /*
     539         * Reset timeleft whenever it is not positive.
     540         */
     541       
     542        if (timeleft <= 0)
     543                timeleft = sec * USEC_COUNT;
     544       
     545        /*
     546         * Wait to see if there is any input. If so, take it and
     547         * update timeleft so that the next call to tgetchar()
     548         * will not wait as long. If there is no input,
     549         * make timeleft zero and return -1.
     550         */
     551       
     552        wchar_t c = 0;
     553       
     554        while (c == 0) {
     555                kbd_event_t event;
     556               
     557                if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
     558                        timeleft = 0;
     559                        return -1;
     560                }
     561               
     562                if (event.type == KEY_PRESS)
     563                        c = event.c;
     564        }
     565       
     566        return (int) c;
    524567}
    525568
  • uspace/app/top/screen.h

    r13ecdac9 r1affcdf3  
    3535#define TOP_SCREEN_H_
    3636
     37#include <io/console.h>
    3738#include "top.h"
     39
     40extern console_ctrl_t *console;
    3841
    3942extern void screen_init(void);
     
    4245extern void print_warning(const char *, ...);
    4346
     47extern int tgetchar(unsigned int);
     48
    4449#endif
    4550
  • uspace/app/top/top.c

    r13ecdac9 r1affcdf3  
    4646#include <sort.h>
    4747#include "screen.h"
    48 #include "input.h"
    4948#include "top.h"
    5049
  • uspace/app/trace/ipc_desc.c

    r13ecdac9 r1affcdf3  
    3333 */
    3434
    35 #include <ipc/common.h>
     35#include <kernel/ipc/ipc.h>
     36#include <kernel/ipc/ipc_methods.h>
    3637#include <stdlib.h>
    3738#include "ipc_desc.h"
     
    3940ipc_m_desc_t ipc_methods[] = {
    4041        /* System methods */
    41         { IPC_M_CONNECT_TO_ME,  "CONNECT_TO_ME" },
    42         { IPC_M_CONNECT_ME_TO,  "CONNECT_ME_TO" },
    43         { IPC_M_PHONE_HUNGUP,   "PHONE_HUNGUP" },
    44         { IPC_M_SHARE_OUT,      "SHARE_OUT" },
    45         { IPC_M_SHARE_IN,       "SHARE_IN" },
    46         { IPC_M_DATA_WRITE,     "DATA_WRITE" },
    47         { IPC_M_DATA_READ,      "DATA_READ" },
    48         { IPC_M_DEBUG_ALL,      "DEBUG_ALL" },
    49 
    50         /* Well-known methods */
    51         { IPC_M_PING,           "PING" },
    52 
     42        { IPC_M_PHONE_HUNGUP,  "PHONE_HUNGUP" },
     43        { IPC_M_CONNECT_ME,    "CONNECT_ME" },
     44        { IPC_M_CONNECT_ME_TO, "CONNECT_ME_TO" },
     45        { IPC_M_CONNECT_TO_ME, "CONNECT_TO_ME" },
     46        { IPC_M_SHARE_OUT,     "SHARE_OUT" },
     47        { IPC_M_SHARE_IN,      "SHARE_IN" },
     48        { IPC_M_DATA_WRITE,    "DATA_WRITE" },
     49        { IPC_M_DATA_READ,     "DATA_READ" },
     50        { IPC_M_DEBUG,         "DEBUG" },
     51       
    5352        /* Terminating entry */
    5453        { 0, NULL }
  • uspace/app/trace/ipcp.c

    r13ecdac9 r1affcdf3  
    3737#include <adt/hash_table.h>
    3838#include <sys/typefmt.h>
    39 
     39#include <kernel/ipc/ipc_methods.h>
    4040#include "ipc_desc.h"
    4141#include "proto.h"
     
    268268        proto_t *proto;
    269269        int cphone;
    270 
     270       
    271271        sysarg_t *resp;
    272272        oper_t *oper;
    273273        int i;
    274 
    275 //      printf("parse_answer\n");
    276 
     274       
    277275        phone = pcall->phone_hash;
    278276        method = IPC_GET_IMETHOD(pcall->question);
    279277        retval = IPC_GET_RETVAL(*answer);
    280 
     278       
    281279        resp = answer->args;
    282 
     280       
    283281        if ((display_mask & DM_IPC) != 0) {
    284282                printf("Response to %p: retval=%" PRIdn ", args = (%" PRIun ", "
     
    288286                    IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
    289287        }
    290 
     288       
    291289        if ((display_mask & DM_USER) != 0) {
    292290                oper = pcall->oper;
    293 
    294                 if (oper != NULL && (oper->rv_type != V_VOID || oper->respc > 0)) {
     291               
     292                if ((oper != NULL) &&
     293                    ((oper->rv_type != V_VOID) || (oper->respc > 0))) {
    295294                        printf("->");
    296 
     295                       
    297296                        if (oper->rv_type != V_VOID) {
    298297                                putchar(' ');
     
    304303                                putchar('(');
    305304                                for (i = 1; i <= oper->respc; ++i) {
    306                                         if (i > 1) printf(", ");
     305                                        if (i > 1)
     306                                                printf(", ");
    307307                                        val_print(resp[i], oper->resp_type[i - 1]);
    308308                                }
    309309                                putchar(')');
    310310                        }
    311 
     311                       
    312312                        putchar('\n');
    313313                }
    314314        }
    315 
    316         if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) {
     315       
     316        if ((phone == PHONE_NS) && (method == IPC_M_CONNECT_ME_TO) &&
     317            (retval == 0)) {
    317318                /* Connected to a service (through NS) */
    318319                service = IPC_GET_ARG1(pcall->question);
    319320                proto = proto_get_by_srv(service);
    320                 if (proto == NULL) proto = proto_unknown;
    321 
     321                if (proto == NULL)
     322                        proto = proto_unknown;
     323               
    322324                cphone = IPC_GET_ARG5(*answer);
    323325                if ((display_mask & DM_SYSTEM) != 0) {
    324326                        printf("Registering connection (phone %d, protocol: %s)\n", cphone,
    325                                 proto->name);
    326                 }
     327                    proto->name);
     328                }
     329               
    327330                ipcp_connection_set(cphone, 0, proto);
    328331        }
     
    334337        pending_call_t *pcall;
    335338        unsigned long key[1];
    336 
    337 //      printf("ipcp_call_in()\n");
    338 
     339       
    339340        if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) {
    340341                /* Not a response */
     
    344345                return;
    345346        }
    346 
     347       
    347348        hash = hash & ~IPC_CALLID_ANSWERED;
    348349        key[0] = hash;
    349 
     350       
    350351        item = hash_table_find(&pending_calls, key);
    351         if (item == NULL) return; // No matching question found
    352 
     352        if (item == NULL)
     353                return; /* No matching question found */
     354       
    353355        /*
    354356         * Response matched to question.
     
    357359        pcall = hash_table_get_instance(item, pending_call_t, link);
    358360        hash_table_remove(&pending_calls, key, 1);
    359 
     361       
    360362        parse_answer(hash, pcall, call);
    361363        free(pcall);
  • uspace/app/trace/syscalls.c

    r13ecdac9 r1affcdf3  
    4040    [SYS_KLOG] ={ "klog",                               3,      V_INT_ERRNO },
    4141    [SYS_TLS_SET] = { "tls_set",                        1,      V_ERRNO },
     42
    4243    [SYS_THREAD_CREATE] = { "thread_create",            3,      V_ERRNO },
    4344    [SYS_THREAD_EXIT] = { "thread_exit",                1,      V_ERRNO },
  • uspace/app/trace/trace.c

    r13ecdac9 r1affcdf3  
    7272ipc_call_t thread_ipc_req[THBUF_SIZE];
    7373
    74 int phoneid;
     74async_sess_t *sess;
    7575bool abort_trace;
    7676
     
    8181
    8282static bool cev_valid;
    83 static console_event_t cev;
     83static kbd_event_t cev;
    8484
    8585void thread_trace_start(uintptr_t thread_hash);
     
    146146static int connect_task(task_id_t task_id)
    147147{
    148         int rc;
    149 
    150         rc = async_connect_kbox(task_id);
    151 
    152         if (rc == ENOTSUP) {
    153                 printf("You do not have userspace debugging support "
    154                     "compiled in the kernel.\n");
    155                 printf("Compile kernel with 'Support for userspace debuggers' "
    156                     "(CONFIG_UDEBUG) enabled.\n");
    157                 return rc;
    158         }
    159 
    160         if (rc < 0) {
     148        async_sess_t *ksess = async_connect_kbox(task_id);
     149       
     150        if (!ksess) {
     151                if (errno == ENOTSUP) {
     152                        printf("You do not have userspace debugging support "
     153                            "compiled in the kernel.\n");
     154                        printf("Compile kernel with 'Support for userspace debuggers' "
     155                            "(CONFIG_UDEBUG) enabled.\n");
     156                        return errno;
     157                }
     158               
    161159                printf("Error connecting\n");
    162                 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc);
    163                 return rc;
    164         }
    165 
    166         phoneid = rc;
    167 
    168         rc = udebug_begin(phoneid);
     160                printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
     161                return errno;
     162        }
     163       
     164        int rc = udebug_begin(ksess);
    169165        if (rc < 0) {
    170166                printf("udebug_begin() -> %d\n", rc);
    171167                return rc;
    172168        }
    173 
    174         rc = udebug_set_evmask(phoneid, UDEBUG_EM_ALL);
     169       
     170        rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL);
    175171        if (rc < 0) {
    176172                printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc);
    177173                return rc;
    178174        }
    179 
     175       
     176        sess = ksess;
    180177        return 0;
    181178}
     
    188185        int i;
    189186
    190         rc = udebug_thread_read(phoneid, thread_hash_buf,
     187        rc = udebug_thread_read(sess, thread_hash_buf,
    191188                THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed);
    192189        if (rc < 0) {
     
    314311
    315312        memset(&call, 0, sizeof(call));
    316         rc = udebug_mem_read(phoneid, &call.args, sc_args[1], sizeof(call.args));
     313        rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args));
    317314
    318315        if (rc >= 0) {
     
    325322        ipc_call_t question, reply;
    326323        int rc;
    327         int phoneidx;
    328 
    329 //      printf("sc_ipc_call_sync_fast()\n");
    330         phoneidx = sc_args[0];
     324        int phoneid;
     325
     326        phoneid = sc_args[0];
    331327
    332328        IPC_SET_IMETHOD(question, sc_args[1]);
     
    337333        IPC_SET_ARG5(question, 0);
    338334
    339 //      printf("memset\n");
    340335        memset(&reply, 0, sizeof(reply));
    341 //      printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n",
    342 //              phoneid, &reply.args, sc_args[5], sizeof(reply.args));
    343         rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args));
    344 //      printf("dmr->%d\n", rc);
    345         if (rc < 0) return;
    346 
    347 //      printf("call ipc_call_sync\n");
    348         ipcp_call_sync(phoneidx, &question, &reply);
     336        rc = udebug_mem_read(sess, &reply.args, sc_args[5], sizeof(reply.args));
     337        if (rc < 0)
     338                return;
     339       
     340        ipcp_call_sync(phoneid, &question, &reply);
    349341}
    350342
     
    355347
    356348        memset(&question, 0, sizeof(question));
    357         rc = udebug_mem_read(phoneid, &question.args, sc_args[1],
     349        rc = udebug_mem_read(sess, &question.args, sc_args[1],
    358350            sizeof(question.args));
    359351
     
    372364
    373365        memset(&reply, 0, sizeof(reply));
    374         rc = udebug_mem_read(phoneid, &reply.args, sc_args[2],
     366        rc = udebug_mem_read(sess, &reply.args, sc_args[2],
    375367            sizeof(reply.args));
    376368
     
    391383
    392384        memset(&call, 0, sizeof(call));
    393         rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call));
    394 //      printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n",
    395 //              phoneid, (int)&call, sc_args[0], sizeof(call), rc);
    396 
    397         if (rc >= 0) {
     385        rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call));
     386       
     387        if (rc >= 0)
    398388                ipcp_call_in(&call, sc_rc);
    399         }
    400389}
    401390
     
    407396
    408397        /* Read syscall arguments */
    409         rc = udebug_args_read(phoneid, thread_hash, sc_args);
    410 
    411         async_serialize_start();
    412 
    413 //      printf("[%d] ", thread_id);
     398        rc = udebug_args_read(sess, thread_hash, sc_args);
    414399
    415400        if (rc < 0) {
    416401                printf("error\n");
    417                 async_serialize_end();
    418402                return;
    419403        }
     
    432416                break;
    433417        }
    434 
    435         async_serialize_end();
    436418}
    437419
     
    444426
    445427        /* Read syscall arguments */
    446         rc = udebug_args_read(phoneid, thread_hash, sc_args);
    447 
    448         async_serialize_start();
     428        rc = udebug_args_read(sess, thread_hash, sc_args);
    449429
    450430//      printf("[%d] ", thread_id);
     
    452432        if (rc < 0) {
    453433                printf("error\n");
    454                 async_serialize_end();
    455434                return;
    456435        }
     
    481460                break;
    482461        }
    483 
    484         async_serialize_end();
    485462}
    486463
    487464static void event_thread_b(uintptr_t hash)
    488465{
    489         async_serialize_start();
    490466        printf("New thread, hash %p\n", (void *) hash);
    491         async_serialize_end();
    492 
    493467        thread_trace_start(hash);
    494468}
     
    527501
    528502                /* Run thread until an event occurs */
    529                 rc = udebug_go(phoneid, thread_hash,
     503                rc = udebug_go(sess, thread_hash,
    530504                    &ev_type, &val0, &val1);
    531505
     
    656630{
    657631        (void) arg;
    658 
     632       
     633        console_ctrl_t *console = console_init(stdin, stdout);
     634       
    659635        while (true) {
    660636                fibril_mutex_lock(&state_lock);
     
    662638                        fibril_condvar_wait(&state_cv, &state_lock);
    663639                fibril_mutex_unlock(&state_lock);
    664 
    665                 if (!console_get_event(fphone(stdin), &cev))
     640               
     641                if (!console_get_kbd_event(console, &cev))
    666642                        return -1;
    667 
     643               
    668644                fibril_mutex_lock(&state_lock);
    669645                cev_valid = true;
    670646                fibril_condvar_broadcast(&state_cv);
    671                 fibril_mutex_unlock(&state_lock);               
     647                fibril_mutex_unlock(&state_lock);
    672648        }
    673649}
     
    675651static void trace_task(task_id_t task_id)
    676652{
    677         console_event_t ev;
     653        kbd_event_t ev;
    678654        bool done;
    679655        int i;
     
    727703                case KC_P:
    728704                        printf("Pause...\n");
    729                         rc = udebug_stop(phoneid, thash);
     705                        rc = udebug_stop(sess, thash);
    730706                        if (rc != EOK)
    731707                                printf("Error: stop -> %d\n", rc);
     
    743719        printf("\nTerminate debugging session...\n");
    744720        abort_trace = true;
    745         udebug_end(phoneid);
    746         async_hangup(phoneid);
     721        udebug_end(sess);
     722        async_hangup(sess);
    747723
    748724        ipcp_cleanup();
Note: See TracChangeset for help on using the changeset viewer.