Changes in / [efcebe1:358dc13] in mainline


Ignore:
Files:
18 added
30 deleted
34 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/mips32/src/Makefile

    refcebe1 r358dc13  
    3232.PHONY: all clean
    3333
    34 all: ../../../../version ../../../../Makefile.config ../../../../config.h ../../../../config.defs
     34all: ../../../../version ../../../../Makefile.common ../../../../Makefile.config ../../../../config.h
    3535        -[ -f $(DEPEND) ] && mv -f $(DEPEND) $(DEPEND_PREV)
    3636        $(MAKE) -f Makefile.build PRECHECK=$(PRECHECK)
    3737
    3838clean:
     39        rm -f $(USPACEDIR)/dist/srv/*
     40        rm -f $(USPACEDIR)/dist/app/*
     41        rm -f $(USPACEDIR)/dist/cfg/net/*
     42
    3943        for file in $(RD_SRVS) ; do \
    4044                rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \
     
    4347                rm -f $(USPACEDIR)/dist/app/`basename $$file` ; \
    4448        done
     49        for file in $(NET_CFG) ; do \
     50                rm -f $(USPACEDIR)/dist/cfg/net/`basename $$file` ; \
     51        done
    4552        rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(RAW) $(COMPS).h $(COMPS).c $(LINK) $(INITRD).img $(INITRD).fs
    4653        find . -name '*.o' -follow -exec rm \{\} \;
  • boot/arch/mips32/src/Makefile.build

    refcebe1 r358dc13  
    3232
    3333include ../../../../version
     34include ../../../../Makefile.common
    3435include ../../../../Makefile.config
    35 include ../../../../config.defs
    3636include Makefile.common
    3737include Makefile.toolchain
     
    7777
    7878$(DEPEND):
     79        rm -f $(USPACEDIR)/dist/srv/*
     80        rm -f $(USPACEDIR)/dist/app/*
     81        rm -f $(USPACEDIR)/dist/cfg/net/*
     82
    7983        for file in $(RD_SRVS) ; do \
    8084                cp $$file $(USPACEDIR)/dist/srv/ ; \
     
    8286        for file in $(RD_APPS) ; do \
    8387                cp $$file $(USPACEDIR)/dist/app/ ; \
     88        done
     89        for file in $(NET_CFG) ; do \
     90                cp $$file $(USPACEDIR)/dist/cfg/net/ ; \
    8491        done
    8592ifeq ($(RDFMT),tmpfs)
  • boot/arch/mips32/src/Makefile.toolchain

    refcebe1 r358dc13  
    2727#
    2828
    29 ## Toolchain configuration
    30 #
    31 
    32 ifndef CROSS_PREFIX
    33         CROSS_PREFIX = /usr/local
    34 endif
    35 
    3629BFD_ARCH = mips
    37 TARGET = mipsel-linux-gnu
    38 TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32/bin
    3930
    4031JOBFILE = ../../../../tools/jobfile.py
     
    4839        BFD_NAME = elf32-tradbigmips
    4940        BFD = ecoff-bigmips
    50         TOOLCHAIN_DIR = $(CROSS_PREFIX)/mips32eb/bin
    51         TARGET = mips-linux-gnu
    5241endif
    5342
     
    5544        BFD_NAME = elf32-tradlittlemips
    5645        BFD = binary
    57 endif
    58 
    59 ifeq ($(COMPILER),gcc_native)
    60         CC = gcc
    61         AS = as
    62         LD = ld
    63         OBJCOPY = objcopy
    64         OBJDUMP = objdump
    65 endif
    66 
    67 ifeq ($(COMPILER),gcc_cross)
    68         CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
    69         AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
    70         LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
    71         OBJCOPY = $(TOOLCHAIN_DIR)/$(TARGET)-objcopy
    72         OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
    7346endif
    7447
  • kernel/generic/include/lib/elf.h

    refcebe1 r358dc13  
    4242 * current ELF version
    4343 */
    44 #define EV_CURRENT  1
     44#define EV_CURRENT      1
    4545
    4646/**
    4747 * ELF types
    4848 */
    49 #define ET_NONE    0       /* No type */
    50 #define ET_REL     1       /* Relocatable file */
    51 #define ET_EXEC    2       /* Executable */
    52 #define ET_DYN     3       /* Shared object */
    53 #define ET_CORE    4       /* Core */
    54 #define ET_LOPROC  0xff00  /* Processor specific */
    55 #define ET_HIPROC  0xffff  /* Processor specific */
     49#define ET_NONE         0       /* No type */
     50#define ET_REL          1       /* Relocatable file */
     51#define ET_EXEC         2       /* Executable */
     52#define ET_DYN          3       /* Shared object */
     53#define ET_CORE         4       /* Core */
     54#define ET_LOPROC       0xff00  /* Processor specific */
     55#define ET_HIPROC       0xffff  /* Processor specific */
    5656
    5757/**
    5858 * ELF machine types
    5959 */
    60 #define EM_NO           0   /* No machine */
    61 #define EM_SPARC        2   /* SPARC */
    62 #define EM_386          3   /* i386 */
    63 #define EM_MIPS         8   /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10  /* MIPS RS3000 LE */
    65 #define EM_PPC          20  /* PPC32 */
    66 #define EM_PPC64        21  /* PPC64 */
    67 #define EM_ARM          40  /* ARM */
    68 #define EM_SPARCV9      43  /* SPARC64 */
    69 #define EM_IA_64        50  /* IA-64 */
    70 #define EM_X86_64       62  /* AMD64/EMT64 */
     60#define EM_NO           0       /* No machine */
     61#define EM_SPARC        2       /* SPARC */
     62#define EM_386          3       /* i386 */
     63#define EM_MIPS         8       /* MIPS RS3000 */
     64#define EM_MIPS_RS3_LE  10      /* MIPS RS3000 LE */
     65#define EM_PPC          20      /* PPC32 */
     66#define EM_PPC64        21      /* PPC64 */
     67#define EM_ARM          40      /* ARM */
     68#define EM_SPARCV9      43      /* SPARC64 */
     69#define EM_IA_64        50      /* IA-64 */
     70#define EM_X86_64       62      /* AMD64/EMT64 */
    7171
    7272/**
    7373 * ELF identification indexes
    7474 */
    75 #define EI_MAG0        0
    76 #define EI_MAG1        1
    77 #define EI_MAG2        2
    78 #define EI_MAG3        3
    79 #define EI_CLASS       4   /* File class */
    80 #define EI_DATA        5   /* Data encoding */
    81 #define EI_VERSION     6   /* File version */
    82 #define EI_OSABI       7
    83 #define EI_ABIVERSION  8
    84 #define EI_PAD         9   /* Start of padding bytes */
    85 #define EI_NIDENT      16  /* ELF identification table size */
     75#define EI_MAG0         0
     76#define EI_MAG1         1
     77#define EI_MAG2         2
     78#define EI_MAG3         3
     79#define EI_CLASS        4               /* File class */
     80#define EI_DATA         5               /* Data encoding */
     81#define EI_VERSION      6               /* File version */
     82#define EI_OSABI        7
     83#define EI_ABIVERSION   8
     84#define EI_PAD          9               /* Start of padding bytes */
     85#define EI_NIDENT       16              /* ELF identification table size */
    8686
    8787/**
    8888 * ELF magic number
    8989 */
    90 #define ELFMAG0  0x7f
    91 #define ELFMAG1  'E'
    92 #define ELFMAG2  'L'
    93 #define ELFMAG3  'F'
     90#define ELFMAG0         0x7f
     91#define ELFMAG1         'E'
     92#define ELFMAG2         'L'
     93#define ELFMAG3         'F'
    9494
    9595/**
    9696 * ELF file classes
    9797 */
    98 #define ELFCLASSNONE  0
    99 #define ELFCLASS32    1
    100 #define ELFCLASS64    2
     98#define ELFCLASSNONE    0
     99#define ELFCLASS32      1
     100#define ELFCLASS64      2
    101101
    102102/**
    103103 * ELF data encoding types
    104104 */
    105 #define ELFDATANONE  0
    106 #define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
    107 #define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
    108 
    109 /**
    110  * ELF error return codes
    111  */
    112 #define EE_OK             0  /* No error */
    113 #define EE_INVALID        1  /* Invalid ELF image */
    114 #define EE_MEMORY         2  /* Cannot allocate address space */
    115 #define EE_INCOMPATIBLE   3  /* ELF image is not compatible with current architecture */
    116 #define EE_UNSUPPORTED    4  /* Non-supported ELF (e.g. dynamic ELFs) */
    117 #define EE_LOADER         5  /* The image is actually a program loader */
    118 #define EE_IRRECOVERABLE  6
     105#define ELFDATANONE     0
     106#define ELFDATA2LSB     1               /* Least significant byte first (little endian) */
     107#define ELFDATA2MSB     2               /* Most signigicant byte first (big endian) */
    119108
    120109/**
    121110 * ELF section types
    122111 */
    123 #define SHT_NULL      0
    124 #define SHT_PROGBITS  1
    125 #define SHT_SYMTAB    2
    126 #define SHT_STRTAB    3
    127 #define SHT_RELA      4
    128 #define SHT_HASH      5
    129 #define SHT_DYNAMIC   6
    130 #define SHT_NOTE      7
    131 #define SHT_NOBITS    8
    132 #define SHT_REL       9
    133 #define SHT_SHLIB     10
    134 #define SHT_DYNSYM    11
    135 #define SHT_LOOS      0x60000000
    136 #define SHT_HIOS      0x6fffffff
    137 #define SHT_LOPROC    0x70000000
    138 #define SHT_HIPROC    0x7fffffff
    139 #define SHT_LOUSER    0x80000000
    140 #define SHT_HIUSER    0xffffffff
     112#define SHT_NULL                0
     113#define SHT_PROGBITS            1
     114#define SHT_SYMTAB              2
     115#define SHT_STRTAB              3
     116#define SHT_RELA                4
     117#define SHT_HASH                5
     118#define SHT_DYNAMIC             6
     119#define SHT_NOTE                7
     120#define SHT_NOBITS              8
     121#define SHT_REL                 9
     122#define SHT_SHLIB               10
     123#define SHT_DYNSYM              11
     124#define SHT_LOOS                0x60000000
     125#define SHT_HIOS                0x6fffffff
     126#define SHT_LOPROC              0x70000000
     127#define SHT_HIPROC              0x7fffffff
     128#define SHT_LOUSER              0x80000000
     129#define SHT_HIUSER              0xffffffff
    141130
    142131/**
    143132 * ELF section flags
    144133 */
    145 #define SHF_WRITE      0x1
    146 #define SHF_ALLOC      0x2
    147 #define SHF_EXECINSTR  0x4
    148 #define SHF_TLS        0x400
    149 #define SHF_MASKPROC   0xf0000000
     134#define SHF_WRITE               0x1
     135#define SHF_ALLOC               0x2
     136#define SHF_EXECINSTR           0x4
     137#define SHF_TLS                 0x400
     138#define SHF_MASKPROC            0xf0000000
     139
     140/** Macros for decomposing elf_symbol.st_info into binging and type */
     141#define ELF_ST_BIND(i)          ((i) >> 4)
     142#define ELF_ST_TYPE(i)          ((i) & 0x0f)
     143#define ELF_ST_INFO(b, t)       (((b) << 4) + ((t) & 0x0f))
    150144
    151145/**
    152146 * Symbol binding
    153147 */
    154 #define STB_LOCAL   0
    155 #define STB_GLOBAL  1
    156 #define STB_WEAK    2
    157 #define STB_LOPROC  13
    158 #define STB_HIPROC  15
     148#define STB_LOCAL               0
     149#define STB_GLOBAL              1
     150#define STB_WEAK                2
     151#define STB_LOPROC              13
     152#define STB_HIPROC              15
    159153
    160154/**
    161155 * Symbol types
    162156 */
    163 #define STT_NOTYPE   0
    164 #define STT_OBJECT   1
    165 #define STT_FUNC     2
    166 #define STT_SECTION  3
    167 #define STT_FILE     4
    168 #define STT_LOPROC   13
    169 #define STT_HIPROC   15
     157#define STT_NOTYPE              0
     158#define STT_OBJECT              1
     159#define STT_FUNC                2
     160#define STT_SECTION             3
     161#define STT_FILE                4
     162#define STT_LOPROC              13
     163#define STT_HIPROC              15
    170164
    171165/**
    172166 * Program segment types
    173167 */
    174 #define PT_NULL     0
    175 #define PT_LOAD     1
    176 #define PT_DYNAMIC  2
    177 #define PT_INTERP   3
    178 #define PT_NOTE     4
    179 #define PT_SHLIB    5
    180 #define PT_PHDR     6
    181 #define PT_LOPROC   0x70000000
    182 #define PT_HIPROC   0x7fffffff
     168#define PT_NULL                 0
     169#define PT_LOAD                 1
     170#define PT_DYNAMIC              2
     171#define PT_INTERP               3
     172#define PT_NOTE                 4
     173#define PT_SHLIB                5
     174#define PT_PHDR                 6
     175#define PT_LOPROC               0x70000000
     176#define PT_HIPROC               0x7fffffff
    183177
    184178/**
    185179 * Program segment attributes.
    186180 */
    187 #define PF_X  1
    188 #define PF_W  2
    189 #define PF_R  4
     181#define PF_X    1
     182#define PF_W    2
     183#define PF_R    4
    190184
    191185/**
     
    195189 * ELF object file specifications. They are the only types used
    196190 * in ELF header.
    197  *
    198191 */
    199192typedef uint64_t elf_xword;
     
    207200 *
    208201 * These types are specific for 32-bit format.
    209  *
    210202 */
    211203typedef uint32_t elf32_addr;
     
    216208 *
    217209 * These types are specific for 64-bit format.
    218  *
    219210 */
    220211typedef uint64_t elf64_addr;
     
    238229        elf_half e_shstrndx;
    239230};
    240 
    241231struct elf64_header {
    242232        uint8_t e_ident[EI_NIDENT];
     
    256246};
    257247
    258 /**
     248/*
    259249 * ELF segment header.
    260250 * Segments headers are also known as program headers.
     
    270260        elf_word p_align;
    271261};
    272 
    273262struct elf64_segment_header {
    274263        elf_word p_type;
     
    282271};
    283272
    284 /**
     273/*
    285274 * ELF section header
    286275 */
     
    297286        elf_word sh_entsize;
    298287};
    299 
    300288struct elf64_section_header {
    301289        elf_word sh_name;
     
    311299};
    312300
    313 /**
     301/*
    314302 * ELF symbol table entry
    315303 */
     
    322310        elf_half st_shndx;
    323311};
    324 
    325312struct elf64_symbol {
    326313        elf_word st_name;
     
    332319};
    333320
     321/*
     322 * ELF note segment entry
     323 */
     324struct elf32_note {
     325        elf_word namesz;
     326        elf_word descsz;
     327        elf_word type;
     328};
     329struct elf64_note {
     330        elf_xword namesz;
     331        elf_xword descsz;
     332        elf_xword type;
     333};
     334
    334335#ifdef __32_BITS__
    335336typedef struct elf32_header elf_header_t;
     
    337338typedef struct elf32_section_header elf_section_header_t;
    338339typedef struct elf32_symbol elf_symbol_t;
     340typedef struct elf32_note elf_note_t;
    339341#endif
    340 
    341342#ifdef __64_BITS__
    342343typedef struct elf64_header elf_header_t;
     
    344345typedef struct elf64_section_header elf_section_header_t;
    345346typedef struct elf64_symbol elf_symbol_t;
     347typedef struct elf64_note elf_note_t;
    346348#endif
    347 
    348 extern const char *elf_error(unsigned int rc);
    349349
    350350/** Interpreter string used to recognize the program loader */
  • kernel/generic/include/mm/as.h

    refcebe1 r358dc13  
    307307extern mem_backend_t phys_backend;
    308308
    309 /**
    310  * This flags is passed when running the loader, otherwise elf_load()
    311  * would return with a EE_LOADER error code.
    312  *
    313  */
    314 #define ELD_F_NONE    0
    315 #define ELD_F_LOADER  1
    316 
    317 extern unsigned int elf_load(elf_header_t *, as_t *, unsigned int);
    318 
    319309/* Address space area related syscalls. */
    320310extern sysarg_t sys_as_area_create(uintptr_t, size_t, unsigned int);
  • kernel/generic/src/lib/elf.c

    refcebe1 r358dc13  
    4747#include <macros.h>
    4848#include <arch.h>
     49
     50#include <lib/elf_load.h>
    4951
    5052static const char *error_codes[] = {
  • kernel/generic/src/proc/program.c

    refcebe1 r358dc13  
    4848#include <ipc/ipcrsc.h>
    4949#include <security/cap.h>
    50 #include <lib/elf.h>
     50#include <lib/elf_load.h>
    5151#include <errno.h>
    5252#include <print.h>
  • uspace/app/bdsh/exec.c

    refcebe1 r358dc13  
    5252static int try_access(const char *);
    5353
    54 const char *search_dir[] = { "app", "srv", NULL };
     54const char *search_dir[] = { "/app", "/srv", NULL };
    5555
    5656/* work-around for access() */
  • uspace/app/taskdump/elf_core.c

    refcebe1 r358dc13  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838 * Looking at core files produced by Linux, these don't have section headers,
    3939 * only program headers, although objdump shows them as having sections.
    40  * Basically at the beginning there should be a note segment (which we
    41  * do not write) and one loadable segment per memory area (which we do write).
    42  *
    43  * The note segment probably contains register state, etc. -- we don't
    44  * deal with these yet. Nevertheless you can use these core files with
    45  * objdump or gdb.
    46  */
    47 
     40 * Basically at the beginning there should be a note segment followed
     41 * by one loadable segment per memory area.
     42 *
     43 * The note segment contains a series of records with register state,
     44 * process info etc. We only write one record NT_PRSTATUS which contains
     45 * process/register state (anything which is not register state we fill
     46 * with zeroes).
     47 */
     48
     49#include <align.h>
     50#include <elf/elf.h>
     51#include <elf/elf_linux.h>
    4852#include <stdio.h>
    4953#include <stdlib.h>
     
    5862#include <udebug.h>
    5963#include <macros.h>
    60 
    61 #include <elf.h>
    62 #include "include/elf_core.h"
     64#include <libarch/istate.h>
     65
     66#include "elf_core.h"
    6367
    6468static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    65 static int write_all(int, void *, size_t);
     69static int align_pos(int, size_t);
    6670static int write_mem_area(int, as_area_info_t *, async_sess_t *);
    6771
     
    8387 */
    8488int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n,
    85     async_sess_t *sess)
     89    async_sess_t *sess, istate_t *istate)
    8690{
    8791        elf_header_t elf_hdr;
     
    9094        elf_word flags;
    9195        elf_segment_header_t *p_hdr;
     96        elf_prstatus_t pr_status;
     97        elf_note_t note;
     98        size_t word_size;
    9299
    93100        int fd;
    94         int rc;
     101        ssize_t rc;
    95102        unsigned int i;
    96103
    97         n_ph = n;
    98 
    99         p_hdr = malloc(sizeof(elf_segment_header_t) * n);
     104#ifdef __32_BITS__
     105        word_size = 4;
     106#endif
     107#ifdef __64_BITS__
     108        word_size = 8;
     109#endif
     110        memset(&pr_status, 0, sizeof(pr_status));
     111        istate_to_elf_regs(istate, &pr_status.regs);
     112
     113        n_ph = n + 1;
     114
     115        p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph);
    100116        if (p_hdr == NULL) {
    101117                printf("Failed allocating memory.\n");
     
    115131         *      ELF header
    116132         *      program headers
     133         *      note segment
    117134         * repeat:
    118135         *      (pad for alignment)
    119          *      segment data
     136         *      core segment
    120137         * end repeat
    121138         */
     
    147164        foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t);
    148165
    149         for (i = 1; i <= n; ++i) {
    150                 foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE);
     166        memset(&p_hdr[0], 0, sizeof(p_hdr[0]));
     167        p_hdr[0].p_type = PT_NOTE;
     168        p_hdr[0].p_offset = foff;
     169        p_hdr[0].p_vaddr = 0;
     170        p_hdr[0].p_paddr = 0;
     171        p_hdr[0].p_filesz = sizeof(elf_note_t)
     172            + ALIGN_UP((str_size("CORE") + 1), word_size)
     173            + ALIGN_UP(sizeof(elf_prstatus_t), word_size);
     174        p_hdr[0].p_memsz = 0;
     175        p_hdr[0].p_flags = 0;
     176        p_hdr[0].p_align = 1;
     177
     178        foff += p_hdr[0].p_filesz;
     179
     180        for (i = 0; i < n; ++i) {
     181                foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE);
    151182
    152183                flags = 0;
    153                 if (ainfo[i - 1].flags & AS_AREA_READ)
     184                if (ainfo[i].flags & AS_AREA_READ)
    154185                        flags |= PF_R;
    155                 if (ainfo[i - 1].flags & AS_AREA_WRITE)
     186                if (ainfo[i].flags & AS_AREA_WRITE)
    156187                        flags |= PF_W;
    157                 if (ainfo[i - 1].flags & AS_AREA_EXEC)
     188                if (ainfo[i].flags & AS_AREA_EXEC)
    158189                        flags |= PF_X;
    159190
    160                 memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i - 1]));
    161                 p_hdr[i - 1].p_type = PT_LOAD;
    162                 p_hdr[i - 1].p_offset = foff;
    163                 p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;
    164                 p_hdr[i - 1].p_paddr = 0;
    165                 p_hdr[i - 1].p_filesz = ainfo[i - 1].size;
    166                 p_hdr[i - 1].p_memsz = ainfo[i - 1].size;
    167                 p_hdr[i - 1].p_flags = flags;
    168                 p_hdr[i - 1].p_align = PAGE_SIZE;
    169 
    170                 foff += ainfo[i - 1].size;
     191                memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1]));
     192                p_hdr[i + 1].p_type = PT_LOAD;
     193                p_hdr[i + 1].p_offset = foff;
     194                p_hdr[i + 1].p_vaddr = ainfo[i].start_addr;
     195                p_hdr[i + 1].p_paddr = 0;
     196                p_hdr[i + 1].p_filesz = ainfo[i].size;
     197                p_hdr[i + 1].p_memsz = ainfo[i].size;
     198                p_hdr[i + 1].p_flags = flags;
     199                p_hdr[i + 1].p_align = PAGE_SIZE;
     200
     201                foff += ainfo[i].size;
    171202        }
    172203
    173204        rc = write_all(fd, &elf_hdr, sizeof(elf_hdr));
    174         if (rc != EOK) {
     205        if (rc != sizeof(elf_hdr)) {
    175206                printf("Failed writing ELF header.\n");
    176207                free(p_hdr);
     
    180211        for (i = 0; i < n_ph; ++i) {
    181212                rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i]));
    182                 if (rc != EOK) {
     213                if (rc != sizeof(p_hdr[i])) {
    183214                        printf("Failed writing program header.\n");
    184215                        free(p_hdr);
     
    187218        }
    188219
    189         for (i = 0; i < n_ph; ++i) {
     220        if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
     221                printf("Failed writing memory data.\n");
     222                free(p_hdr);
     223                return EIO;
     224        }
     225
     226        /*
     227         * Write note header
     228         */
     229        note.namesz = str_size("CORE") + 1;
     230        note.descsz = sizeof(elf_prstatus_t);
     231        note.type = NT_PRSTATUS;
     232
     233        rc = write_all(fd, &note, sizeof(elf_note_t));
     234        if (rc != sizeof(elf_note_t)) {
     235                printf("Failed writing note header.\n");
     236                free(p_hdr);
     237                return EIO;
     238        }
     239
     240        rc = write_all(fd, "CORE", note.namesz);
     241        if (rc != (ssize_t) note.namesz) {
     242                printf("Failed writing note header.\n");
     243                free(p_hdr);
     244                return EIO;
     245        }
     246
     247        rc = align_pos(fd, word_size);
     248        if (rc != EOK) {
     249                printf("Failed writing note header.\n");
     250                free(p_hdr);
     251                return EIO;
     252        }
     253
     254        rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t));
     255        if (rc != sizeof(elf_prstatus_t)) {
     256                printf("Failed writing register data.\n");
     257                free(p_hdr);
     258                return EIO;
     259        }
     260
     261        for (i = 1; i < n_ph; ++i) {
    190262                if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    191263                        printf("Failed writing memory data.\n");
     
    193265                        return EIO;
    194266                }
    195                 if (write_mem_area(fd, &ainfo[i], sess) != EOK) {
     267                if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
    196268                        printf("Failed writing memory data.\n");
    197269                        free(p_hdr);
     
    210282        off64_t rva = vaddr % page_size;
    211283        off64_t rfo = foff % page_size;
    212        
     284
    213285        if (rva >= rfo)
    214286                return (foff + (rva - rfo));
    215        
     287
    216288        return (foff + (page_size + (rva - rfo)));
    217289}
     
    231303        size_t total;
    232304        uintptr_t addr;
    233         int rc;
     305        ssize_t rc;
    234306
    235307        addr = area->start_addr;
     
    245317
    246318                rc = write_all(fd, buffer, to_copy);
    247                 if (rc != EOK) {
     319                if (rc != (ssize_t) to_copy) {
    248320                        printf("Failed writing memory contents.\n");
    249321                        return EIO;
     
    257329}
    258330
    259 /** Write until the buffer is written in its entirety.
    260  *
    261  * This function fails if it cannot write exactly @a len bytes to the file.
    262  *
    263  * @param fd            The file to write to.
    264  * @param buf           Data, @a len bytes long.
    265  * @param len           Number of bytes to write.
    266  *
    267  * @return              EOK on error, return value from write() if writing
    268  *                      failed.
    269  */
    270 static int write_all(int fd, void *data, size_t len)
     331static int align_pos(int fd, size_t align)
    271332{
    272         int cnt = 0;
    273 
    274         do {
    275                 data += cnt;
    276                 len -= cnt;
    277                 cnt = write(fd, data, len);
    278         } while (cnt > 0 && (len - cnt) > 0);
    279 
    280         if (cnt < 0)
    281                 return cnt;
    282 
    283         if (len - cnt > 0)
    284                 return EIO;
     333        off64_t cur_pos;
     334        size_t rem, adv;
     335
     336        cur_pos = lseek(fd, 0, SEEK_CUR);
     337        if (cur_pos < 0)
     338                return -1;
     339
     340        rem = cur_pos % align;
     341        adv = align - rem;
     342
     343        cur_pos = lseek(fd, adv, SEEK_CUR);
     344        if (cur_pos < 0)
     345                return -1;
    285346
    286347        return EOK;
    287348}
    288349
    289 
    290350/** @}
    291351 */
  • uspace/app/taskdump/include/elf_core.h

    refcebe1 r358dc13  
    3737
    3838#include <async.h>
     39#include <elf/elf_linux.h>
     40#include <libarch/istate.h>
    3941
    4042extern int elf_core_save(const char *, as_area_info_t *, unsigned int,
    41     async_sess_t *);
     43    async_sess_t *, istate_t *);
    4244
    4345#endif
  • uspace/app/taskdump/include/symtab.h

    refcebe1 r358dc13  
    3636#define SYMTAB_H_
    3737
     38#include <elf/elf.h>
    3839#include <sys/types.h>
    39 #include <elf.h>
    4040
    4141typedef struct {
  • uspace/app/taskdump/symtab.c

    refcebe1 r358dc13  
    3636 */
    3737
     38#include <elf/elf.h>
    3839#include <stdio.h>
    3940#include <stdlib.h>
     
    4344#include <fcntl.h>
    4445
    45 #include <elf.h>
    4646#include "include/symtab.h"
    4747
     
    5050    elf_section_header_t *shdr);
    5151static int chunk_load(int fd, off64_t start, size_t size, void **ptr);
    52 static int read_all(int fd, void *buf, size_t len);
    5352
    5453/** Load symbol table from an ELF file.
     
    9089
    9190        rc = read_all(fd, &elf_hdr, sizeof(elf_header_t));
    92         if (rc != EOK) {
     91        if (rc != sizeof(elf_header_t)) {
    9392                printf("failed reading elf header\n");
    9493                free(stab);
     
    312311
    313312        rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t));
    314         if (rc != EOK)
     313        if (rc != sizeof(elf_section_header_t))
    315314                return EIO;
    316315
     
    331330static int chunk_load(int fd, off64_t start, size_t size, void **ptr)
    332331{
    333         int rc;
    334 
    335         rc = lseek(fd, start, SEEK_SET);
    336         if (rc == (off64_t) -1) {
     332        ssize_t rc;
     333        off64_t offs;
     334
     335        offs = lseek(fd, start, SEEK_SET);
     336        if (offs == (off64_t) -1) {
    337337                printf("failed seeking chunk\n");
    338338                *ptr = NULL;
     
    347347
    348348        rc = read_all(fd, *ptr, size);
    349         if (rc != EOK) {
     349        if (rc != (ssize_t) size) {
    350350                printf("failed reading chunk\n");
    351351                free(*ptr);
     
    357357}
    358358
    359 /** Read until the buffer is read in its entirety.
    360  *
    361  * This function fails if it cannot read exactly @a len bytes from the file.
    362  *
    363  * @param fd            The file to read from.
    364  * @param buf           Buffer for storing data, @a len bytes long.
    365  * @param len           Number of bytes to read.
    366  *
    367  * @return              EOK on error, EIO if file is short or return value
    368  *                      from read() if reading failed.
    369  */
    370 static int read_all(int fd, void *buf, size_t len)
    371 {
    372         int cnt = 0;
    373 
    374         do {
    375                 buf += cnt;
    376                 len -= cnt;
    377                 cnt = read(fd, buf, len);
    378         } while (cnt > 0 && (len - cnt) > 0);
    379 
    380         if (cnt < 0)
    381                 return cnt;
    382 
    383         if (len - cnt > 0)
    384                 return EIO;
    385 
    386         return EOK;
    387 }
    388 
    389359/** @}
    390360 */
  • uspace/app/taskdump/taskdump.c

    refcebe1 r358dc13  
    3434
    3535#include <async.h>
     36#include <elf/elf_linux.h>
    3637#include <stdio.h>
    3738#include <stdlib.h>
     
    7273static char *get_app_task_name(void);
    7374static char *fmt_sym_address(uintptr_t addr);
     75
     76static istate_t reg_state;
    7477
    7578int main(int argc, char *argv[])
     
    293296        if (write_core_file) {
    294297                printf("Writing core file '%s'\n", core_file_name);
    295                 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess);
     298
     299                rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess,
     300                    &reg_state);
     301
    296302                if (rc != EOK) {
    297303                        printf("Failed writing core file.\n");
     
    321327        pc = istate_get_pc(&istate);
    322328        fp = istate_get_fp(&istate);
     329
     330        /* Save register state for dumping to core file later. */
     331        reg_state = istate;
    323332
    324333        sym_pc = fmt_sym_address(pc);
  • uspace/drv/bus/usb/usbmast/bo_trans.c

    refcebe1 r358dc13  
    5858 * @param tag           Command block wrapper tag (automatically compared
    5959 *                      with answer)
    60  * @param cmd           Command block
    61  * @param cmd_size      Command block size in bytes
    62  * @param ddir          Direction in which data will be transferred
    63  * @param dbuf          Data send/receive buffer
    64  * @param dbuf_size     Size of the data buffer
    65  * @param xferred_size  Number of bytes actually transferred
     60 * @param cmd           SCSI command
    6661 *
    6762 * @return              Error code
    6863 */
    69 static int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    70     size_t cmd_size, usb_direction_t ddir, void *dbuf, size_t dbuf_size,
    71     size_t *xferred_size)
     64int usb_massstor_cmd(usbmast_fun_t *mfun, uint32_t tag, scsi_cmd_t *cmd)
    7265{
    7366        int rc;
     67        int retval = EOK;
    7468        size_t act_size;
    7569        usb_pipe_t *bulk_in_pipe = mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe;
    7670        usb_pipe_t *bulk_out_pipe = mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe;
     71        usb_direction_t ddir;
     72        void *dbuf;
     73        size_t dbuf_size;
     74
     75        if (cmd->data_out != NULL && cmd->data_in == NULL) {
     76                ddir = USB_DIRECTION_OUT;
     77                dbuf = (void *)cmd->data_out;
     78                dbuf_size = cmd->data_out_size;
     79        } else if (cmd->data_out == NULL && cmd->data_in != NULL) {
     80                ddir = USB_DIRECTION_IN;
     81                dbuf = cmd->data_in;
     82                dbuf_size = cmd->data_in_size;
     83        } else {
     84                assert(false);
     85        }
    7786
    7887        /* Prepare CBW - command block wrapper */
    7988        usb_massstor_cbw_t cbw;
    8089        usb_massstor_cbw_prepare(&cbw, tag, dbuf_size, ddir, mfun->lun,
    81             cmd_size, cmd);
     90            cmd->cdb_size, cmd->cdb);
    8291
    8392        /* Send the CBW. */
     93        MASTLOG("Sending CBW.\n");
    8494        rc = usb_pipe_write(bulk_out_pipe, &cbw, sizeof(cbw));
    8595        MASTLOG("CBW '%s' sent: %s.\n",
    8696            usb_debug_str_buffer((uint8_t *) &cbw, sizeof(cbw), 0),
    8797            str_error(rc));
    88         if (rc != EOK) {
    89                 return rc;
    90         }
    91 
     98        if (rc != EOK)
     99                return EIO;
     100
     101        MASTLOG("Transferring data.\n");
    92102        if (ddir == USB_DIRECTION_IN) {
    93103                /* Recieve data from the device. */
     
    104114        }
    105115
    106         if (rc != EOK) {
    107                 /*
    108                  * XXX If the pipe is stalled, we should clear it
    109                  * and read CSW.
    110                  */
    111                 return rc;
     116        if (rc == ESTALL) {
     117                /* Clear stall condition and continue below to read CSW. */
     118                if (ddir == USB_DIRECTION_IN) {
     119                        usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
     120                            mfun->mdev->usb_dev->pipes[BULK_IN_EP].pipe);
     121                } else {
     122                        usb_pipe_clear_halt(&mfun->mdev->usb_dev->ctrl_pipe,
     123                            mfun->mdev->usb_dev->pipes[BULK_OUT_EP].pipe);
     124                }
     125        } else if (rc != EOK) {
     126                return EIO;
    112127        }
    113128
     
    115130        usb_massstor_csw_t csw;
    116131        size_t csw_size;
     132        MASTLOG("Reading CSW.\n");
    117133        rc = usb_pipe_read(bulk_in_pipe, &csw, sizeof(csw), &csw_size);
    118134        MASTLOG("CSW '%s' received (%zu bytes): %s.\n",
     
    121137        if (rc != EOK) {
    122138                MASTLOG("rc != EOK\n");
    123                 return rc;
     139                return EIO;
    124140        }
    125141
    126142        if (csw_size != sizeof(csw)) {
    127143                MASTLOG("csw_size != sizeof(csw)\n");
    128                 return ERANGE;
     144                return EIO;
    129145        }
    130146
    131147        if (csw.dCSWTag != tag) {
    132148                MASTLOG("csw.dCSWTag != tag\n");
    133                 return EBADCHECKSUM;
     149                return EIO;
    134150        }
    135151
     
    137153         * Determine the actual return value from the CSW.
    138154         */
    139         if (csw.dCSWStatus != 0) {
    140                 MASTLOG("csw.dCSWStatus != 0\n");
    141                 // FIXME: better error code
    142                 // FIXME: distinguish 0x01 and 0x02
    143                 return EXDEV;
     155        switch (csw.dCSWStatus) {
     156        case cbs_passed:
     157                cmd->status = CMDS_GOOD;
     158                break;
     159        case cbs_failed:
     160                MASTLOG("Command failed\n");
     161                cmd->status = CMDS_FAILED;
     162                break;
     163        case cbs_phase_error:
     164                MASTLOG("Phase error\n");
     165                retval = EIO;
     166                break;
     167        default:
     168                retval = EIO;
     169                break;
    144170        }
    145171
     
    147173        if (residue > dbuf_size) {
    148174                MASTLOG("residue > dbuf_size\n");
    149                 return ERANGE;
     175                return EIO;
    150176        }
    151177
     
    158184         */
    159185
    160         if (xferred_size != NULL)
    161                 *xferred_size = dbuf_size - residue;
    162 
    163         return EOK;
    164 }
    165 
    166 /** Perform data-in command.
    167  *
    168  * @param mfun          Mass storage function
    169  * @param tag           Command block wrapper tag (automatically compared with
    170  *                      answer)
    171  * @param cmd           CDB (Command Descriptor)
    172  * @param cmd_size      CDB length in bytes
    173  * @param dbuf          Data receive buffer
    174  * @param dbuf_size     Data receive buffer size in bytes
    175  * @param proc_size     Number of bytes actually processed by device
    176  *
    177  * @return Error code
    178  */
    179 int usb_massstor_data_in(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    180     size_t cmd_size, void *dbuf, size_t dbuf_size, size_t *proc_size)
    181 {
    182         return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_IN,
    183             dbuf, dbuf_size, proc_size);
    184 }
    185 
    186 /** Perform data-out command.
    187  *
    188  * @param mfun          Mass storage function
    189  * @param tag           Command block wrapper tag (automatically compared with
    190  *                      answer)
    191  * @param cmd           CDB (Command Descriptor)
    192  * @param cmd_size      CDB length in bytes
    193  * @param data          Command data
    194  * @param data_size     Size of @a data in bytes
    195  * @param proc_size     Number of bytes actually processed by device
    196  *
    197  * @return Error code
    198  */
    199 int usb_massstor_data_out(usbmast_fun_t *mfun, uint32_t tag, const void *cmd,
    200     size_t cmd_size, const void *data, size_t data_size, size_t *proc_size)
    201 {
    202         return usb_massstor_cmd(mfun, tag, cmd, cmd_size, USB_DIRECTION_OUT,
    203             (void *) data, data_size, proc_size);
     186        if (ddir == USB_DIRECTION_IN)
     187                cmd->rcvd_size = dbuf_size - residue;
     188
     189        return retval;
    204190}
    205191
  • uspace/drv/bus/usb/usbmast/bo_trans.h

    refcebe1 r358dc13  
    4747#define BULK_OUT_EP 1
    4848
    49 extern int usb_massstor_data_in(usbmast_fun_t *, uint32_t, const void *,
    50     size_t, void *, size_t, size_t *);
    51 extern int usb_massstor_data_out(usbmast_fun_t *, uint32_t, const void *,
    52     size_t, const void *, size_t, size_t *);
     49typedef enum cmd_status {
     50        CMDS_GOOD,
     51        CMDS_FAILED
     52} cmd_status_t;
     53
     54/** SCSI command.
     55 *
     56 * Contains (a subset of) the input and output arguments of SCSI
     57 * Execute Command procedure call (see SAM-4 chapter 5.1)
     58 */
     59typedef struct {
     60        /*
     61         * Related to IN fields
     62         */
     63
     64        /** Command Descriptor Block */
     65        void *cdb;
     66        /** CDB size in bytes */
     67        size_t cdb_size;
     68
     69        /** Outgoing data */
     70        const void *data_out;
     71        /** Size of outgoing data in bytes */
     72        size_t data_out_size;
     73
     74        /*
     75         * Related to OUT fields
     76         */
     77
     78        /** Buffer for incoming data */
     79        void *data_in;
     80        /** Size of input buffer in bytes */
     81        size_t data_in_size;
     82
     83        /** Number of bytes actually received */
     84        size_t rcvd_size;
     85
     86        /** Status */
     87        cmd_status_t status;
     88} scsi_cmd_t;
     89
     90extern int usb_massstor_cmd(usbmast_fun_t *, uint32_t, scsi_cmd_t *);
    5391extern int usb_massstor_reset(usbmast_dev_t *);
    5492extern void usb_massstor_reset_recovery(usbmast_dev_t *);
  • uspace/drv/bus/usb/usbmast/cmdw.h

    refcebe1 r358dc13  
    5757} __attribute__((packed)) usb_massstor_csw_t;
    5858
     59enum cmd_block_status {
     60        cbs_passed      = 0x00,
     61        cbs_failed      = 0x01,
     62        cbs_phase_error = 0x02
     63};
     64
    5965extern void usb_massstor_cbw_prepare(usb_massstor_cbw_t *, uint32_t, uint32_t,
    6066    usb_direction_t, uint8_t, uint8_t, const uint8_t *);
  • uspace/drv/bus/usb/usbmast/scsi_ms.c

    refcebe1 r358dc13  
    6161}
    6262
     63static void usbmast_dump_sense(usbmast_fun_t *mfun)
     64{
     65        scsi_sense_data_t sense_buf;
     66        unsigned sense_key;
     67        int rc;
     68
     69        rc = usbmast_request_sense(mfun, &sense_buf, sizeof(sense_buf));
     70        if (rc == EOK) {
     71                sense_key = sense_buf.flags_key & 0x0f;
     72                printf("Got sense data. Sense key: 0x%x (%s), ASC 0x%02x, "
     73                    "ASCQ 0x%02x.\n", sense_key,
     74                    scsi_get_sense_key_str(sense_key),
     75                    sense_buf.additional_code,
     76                    sense_buf.additional_cqual);
     77        } else {
     78                printf("Failed to read sense data.\n");
     79        }
     80}
     81
    6382/** Perform SCSI Inquiry command on USB mass storage device.
    6483 *
     
    7089{
    7190        scsi_std_inquiry_data_t inq_data;
    72         size_t response_len;
     91        scsi_cmd_t cmd;
    7392        scsi_cdb_inquiry_t cdb;
    7493        int rc;
     
    7897        cdb.alloc_len = host2uint16_t_be(sizeof(inq_data));
    7998
    80         rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb,
    81             sizeof(cdb), &inq_data, sizeof(inq_data), &response_len);
     99        memset(&cmd, 0, sizeof(cmd));
     100        cmd.cdb = &cdb;
     101        cmd.cdb_size = sizeof(cdb);
     102        cmd.data_in = &inq_data;
     103        cmd.data_in_size = sizeof(inq_data);
     104
     105        rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);
    82106
    83107        if (rc != EOK) {
    84                 usb_log_error("Inquiry failed, device %s: %s.\n",
    85                    mfun->mdev->ddf_dev->name, str_error(rc));
    86                 return rc;
    87         }
    88 
    89         if (response_len < SCSI_STD_INQUIRY_DATA_MIN_SIZE) {
     108                usb_log_error("Inquiry transport failed, device %s: %s.\n",
     109                   mfun->mdev->ddf_dev->name, str_error(rc));
     110                return rc;
     111        }
     112
     113        if (cmd.status != CMDS_GOOD) {
     114                usb_log_error("Inquiry command failed, device %s.\n",
     115                   mfun->mdev->ddf_dev->name);
     116                usbmast_dump_sense(mfun);
     117                return EIO;
     118        }
     119
     120        if (cmd.rcvd_size < SCSI_STD_INQUIRY_DATA_MIN_SIZE) {
    90121                usb_log_error("SCSI Inquiry response too short (%zu).\n",
    91                     response_len);
     122                    cmd.rcvd_size);
    92123                return EIO;
    93124        }
     
    127158int usbmast_request_sense(usbmast_fun_t *mfun, void *buf, size_t size)
    128159{
     160        scsi_cmd_t cmd;
    129161        scsi_cdb_request_sense_t cdb;
    130         size_t data_len;
    131162        int rc;
    132163
     
    135166        cdb.alloc_len = min(size, SCSI_SENSE_DATA_MAX_SIZE);
    136167
    137         rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb,
    138             sizeof(cdb), buf, size, &data_len);
    139 
    140         if (rc != EOK) {
     168        memset(&cmd, 0, sizeof(cmd));
     169        cmd.cdb = &cdb;
     170        cmd.cdb_size = sizeof(cdb);
     171        cmd.data_in = buf;
     172        cmd.data_in_size = size;
     173
     174        rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);
     175
     176        if (rc != EOK || cmd.status != CMDS_GOOD) {
    141177                usb_log_error("Request Sense failed, device %s: %s.\n",
    142178                   mfun->mdev->ddf_dev->name, str_error(rc));
     
    144180        }
    145181
    146         if (data_len < SCSI_SENSE_DATA_MIN_SIZE) {
     182        if (cmd.rcvd_size < SCSI_SENSE_DATA_MIN_SIZE) {
    147183                /* The missing bytes should be considered to be zeroes. */
    148                 memset((uint8_t *)buf + data_len, 0,
    149                     SCSI_SENSE_DATA_MIN_SIZE - data_len);
     184                memset((uint8_t *)buf + cmd.rcvd_size, 0,
     185                    SCSI_SENSE_DATA_MIN_SIZE - cmd.rcvd_size);
    150186        }
    151187
     
    164200    uint32_t *block_size)
    165201{
     202        scsi_cmd_t cmd;
    166203        scsi_cdb_read_capacity_10_t cdb;
    167204        scsi_read_capacity_10_data_t data;
    168         size_t data_len;
    169205        int rc;
    170206
     
    172208        cdb.op_code = SCSI_CMD_READ_CAPACITY_10;
    173209
    174         rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb,
    175             sizeof(cdb), &data, sizeof(data), &data_len);
     210        memset(&cmd, 0, sizeof(cmd));
     211        cmd.cdb = &cdb;
     212        cmd.cdb_size = sizeof(cdb);
     213        cmd.data_in = &data;
     214        cmd.data_in_size = sizeof(data);
     215
     216        rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);
    176217
    177218        if (rc != EOK) {
    178                 usb_log_error("Read Capacity (10) failed, device %s: %s.\n",
    179                    mfun->mdev->ddf_dev->name, str_error(rc));
    180                 return rc;
    181         }
    182 
    183         if (data_len < sizeof(data)) {
     219                usb_log_error("Read Capacity (10) transport failed, device %s: %s.\n",
     220                   mfun->mdev->ddf_dev->name, str_error(rc));
     221                return rc;
     222        }
     223
     224        if (cmd.status != CMDS_GOOD) {
     225                usb_log_error("Read Capacity (10) command failed, device %s.\n",
     226                   mfun->mdev->ddf_dev->name);
     227                usbmast_dump_sense(mfun);
     228                return EIO;
     229        }
     230
     231        if (cmd.rcvd_size < sizeof(data)) {
    184232                usb_log_error("SCSI Read Capacity response too short (%zu).\n",
    185                     data_len);
     233                    cmd.rcvd_size);
    186234                return EIO;
    187235        }
     
    203251int usbmast_read(usbmast_fun_t *mfun, uint64_t ba, size_t nblocks, void *buf)
    204252{
     253        scsi_cmd_t cmd;
    205254        scsi_cdb_read_12_t cdb;
    206         size_t data_len;
    207         int rc;
    208 
    209         /* XXX Need softstate to store block size. */
     255        int rc;
    210256
    211257        if (ba > UINT32_MAX)
     
    220266        cdb.xfer_len = host2uint32_t_be(nblocks);
    221267
    222         rc = usb_massstor_data_in(mfun, 0xDEADBEEF, (uint8_t *) &cdb,
    223             sizeof(cdb), buf, nblocks * mfun->block_size, &data_len);
     268        memset(&cmd, 0, sizeof(cmd));
     269        cmd.cdb = &cdb;
     270        cmd.cdb_size = sizeof(cdb);
     271        cmd.data_in = buf;
     272        cmd.data_in_size = nblocks * mfun->block_size;
     273
     274        rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);
    224275
    225276        if (rc != EOK) {
    226                 usb_log_error("Read (12) failed, device %s: %s.\n",
    227                    mfun->mdev->ddf_dev->name, str_error(rc));
    228                 return rc;
    229         }
    230 
    231         if (data_len < nblocks * mfun->block_size) {
     277                usb_log_error("Read (12) transport failed, device %s: %s.\n",
     278                   mfun->mdev->ddf_dev->name, str_error(rc));
     279                return rc;
     280        }
     281
     282        if (cmd.status != CMDS_GOOD) {
     283                usb_log_error("Read (12) command failed, device %s.\n",
     284                   mfun->mdev->ddf_dev->name);
     285                usbmast_dump_sense(mfun);
     286                return EIO;
     287        }
     288
     289        if (cmd.rcvd_size < nblocks * mfun->block_size) {
    232290                usb_log_error("SCSI Read response too short (%zu).\n",
    233                     data_len);
     291                    cmd.rcvd_size);
    234292                return EIO;
    235293        }
     
    250308    const void *data)
    251309{
     310        scsi_cmd_t cmd;
    252311        scsi_cdb_write_12_t cdb;
    253         size_t sent_len;
    254312        int rc;
    255313
     
    265323        cdb.xfer_len = host2uint32_t_be(nblocks);
    266324
    267         rc = usb_massstor_data_out(mfun, 0xDEADBEEF, (uint8_t *) &cdb,
    268             sizeof(cdb), data, nblocks * mfun->block_size, &sent_len);
     325        memset(&cmd, 0, sizeof(cmd));
     326        cmd.cdb = &cdb;
     327        cmd.cdb_size = sizeof(cdb);
     328        cmd.data_out = data;
     329        cmd.data_out_size = nblocks * mfun->block_size;
     330
     331        rc = usb_massstor_cmd(mfun, 0xDEADBEEF, &cmd);
    269332
    270333        if (rc != EOK) {
    271                 usb_log_error("Write (12) failed, device %s: %s.\n",
    272                    mfun->mdev->ddf_dev->name, str_error(rc));
    273                 return rc;
    274         }
    275 
    276         if (sent_len < nblocks * mfun->block_size) {
    277                 usb_log_error("SCSI Write not all bytes transferred (%zu).\n",
    278                     sent_len);
     334                usb_log_error("Write (12) transport failed, device %s: %s.\n",
     335                   mfun->mdev->ddf_dev->name, str_error(rc));
     336                return rc;
     337        }
     338
     339        if (cmd.status != CMDS_GOOD) {
     340                usb_log_error("Write (12) command failed, device %s.\n",
     341                   mfun->mdev->ddf_dev->name);
     342                usbmast_dump_sense(mfun);
    279343                return EIO;
    280344        }
  • uspace/lib/c/Makefile

    refcebe1 r358dc13  
    5959-include arch/$(UARCH)/Makefile.inc
    6060
    61 EXTRA_CFLAGS += -I../../srv/loader/include
    62 
    6361GENERIC_SOURCES = \
    6462        generic/libc.c \
     
    7169        generic/device/hw_res.c \
    7270        generic/device/char_dev.c \
     71        generic/elf/elf_load.c \
    7372        generic/event.c \
    7473        generic/errno.c \
     
    134133                generic/dlfcn.c \
    135134                generic/rtld/rtld.c \
    136                 generic/rtld/elf_load.c \
    137135                generic/rtld/dynamic.c \
    138136                generic/rtld/module.c \
  • uspace/lib/c/generic/io/io.c

    refcebe1 r358dc13  
    594594                }
    595595               
    596                 buf += now;
     596                data += now;
    597597                stream->buf_head += now;
    598598                buf_free -= now;
    599599                bytes_left -= now;
    600600                total_written += now;
     601                stream->buf_state = _bs_write;
    601602               
    602603                if (buf_free == 0) {
     
    606607                }
    607608        }
    608        
    609         if (total_written > 0)
    610                 stream->buf_state = _bs_write;
    611609
    612610        if (need_flush)
  • uspace/lib/c/generic/rtld/module.c

    refcebe1 r358dc13  
    3535 */
    3636
     37#include <adt/list.h>
     38#include <elf/elf_load.h>
     39#include <fcntl.h>
     40#include <loader/pcb.h>
    3741#include <stdio.h>
    3842#include <stdlib.h>
    3943#include <unistd.h>
    40 #include <fcntl.h>
    41 #include <adt/list.h>
    42 #include <loader/pcb.h>
    4344
    4445#include <rtld/rtld.h>
     
    4748#include <rtld/rtld_arch.h>
    4849#include <rtld/module.h>
    49 #include <elf_load.h>
    5050
    5151/** (Eagerly) process all relocation tables in a module.
     
    9393module_t *module_find(const char *name)
    9494{
    95         link_t *head = &runtime_env->modules_head;
    96 
    97         link_t *cur;
    9895        module_t *m;
    9996        const char *p, *soname;
     
    110107
    111108        /* Traverse list of all modules. Not extremely fast, but simple */
    112         DPRINTF("head = %p\n", head);
    113         for (cur = head->next; cur != head; cur = cur->next) {
     109        list_foreach(runtime_env->modules, cur) {
    114110                DPRINTF("cur = %p\n", cur);
    115111                m = list_get_instance(cur, module_t, modules_link);
     
    177173
    178174        /* Insert into the list of loaded modules */
    179         list_append(&m->modules_link, &runtime_env->modules_head);
     175        list_append(&m->modules_link, &runtime_env->modules);
    180176
    181177        return m;
     
    249245void modules_process_relocs(module_t *start)
    250246{
    251         link_t *head = &runtime_env->modules_head;
    252 
    253         link_t *cur;
    254         module_t *m;
    255 
    256         for (cur = head->next; cur != head; cur = cur->next) {
     247        module_t *m;
     248
     249        list_foreach(runtime_env->modules, cur) {
    257250                m = list_get_instance(cur, module_t, modules_link);
    258251
     
    268261void modules_untag(void)
    269262{
    270         link_t *head = &runtime_env->modules_head;
    271 
    272         link_t *cur;
    273         module_t *m;
    274 
    275         for (cur = head->next; cur != head; cur = cur->next) {
     263        module_t *m;
     264
     265        list_foreach(runtime_env->modules, cur) {
    276266                m = list_get_instance(cur, module_t, modules_link);
    277267                m->bfs_tag = false;
  • uspace/lib/c/generic/rtld/rtld.c

    refcebe1 r358dc13  
    4444{
    4545        runtime_env = &rt_env_static;
    46         list_initialize(&runtime_env->modules_head);
     46        list_initialize(&runtime_env->modules);
    4747        runtime_env->next_bias = 0x2000000;
    4848        runtime_env->program = NULL;
  • uspace/lib/c/generic/rtld/symbol.c

    refcebe1 r358dc13  
    3838#include <stdlib.h>
    3939
     40#include <elf/elf.h>
    4041#include <rtld/rtld.h>
    4142#include <rtld/rtld_debug.h>
    4243#include <rtld/symbol.h>
    43 #include <elf.h>
    4444
    4545/*
     
    118118        module_t *m, *dm;
    119119        elf_symbol_t *sym, *s;
    120         link_t queue_head;
     120        list_t queue;
    121121        size_t i;
    122122
     
    132132
    133133        /* Insert root (the program) into the queue and tag it */
    134         list_initialize(&queue_head);
     134        list_initialize(&queue);
    135135        start->bfs_tag = true;
    136         list_append(&start->queue_link, &queue_head);
     136        list_append(&start->queue_link, &queue);
    137137
    138138        /* If the symbol is found, it will be stored in 'sym' */
     
    140140
    141141        /* While queue is not empty */
    142         while (!list_empty(&queue_head)) {
     142        while (!list_empty(&queue)) {
    143143                /* Pop first element from the queue */
    144                 m = list_get_instance(queue_head.next, module_t, queue_link);
     144                m = list_get_instance(list_first(&queue), module_t, queue_link);
    145145                list_remove(&m->queue_link);
    146146
     
    162162                        if (dm->bfs_tag == false) {
    163163                                dm->bfs_tag = true;
    164                                 list_append(&dm->queue_link, &queue_head);
     164                                list_append(&dm->queue_link, &queue);
    165165                        }
    166166                }
     
    168168
    169169        /* Empty the queue so that we leave it in a clean state */
    170         while (!list_empty(&queue_head))
    171                 list_remove(queue_head.next);
     170        while (!list_empty(&queue))
     171                list_remove(list_first(&queue));
    172172
    173173        if (!sym) {
  • uspace/lib/c/generic/vfs/vfs.c

    refcebe1 r358dc13  
    417417}
    418418
     419/** Read entire buffer.
     420 *
     421 * In face of short reads this function continues reading until either
     422 * the entire buffer is read or no more data is available (at end of file).
     423 *
     424 * @param fildes        File descriptor
     425 * @param buf           Buffer, @a nbytes bytes long
     426 * @param nbytes        Number of bytes to read
     427 *
     428 * @return              On success, positive number of bytes read.
     429 *                      On failure, negative error code from read().
     430 */
     431ssize_t read_all(int fildes, void *buf, size_t nbyte)
     432{
     433        ssize_t cnt = 0;
     434        size_t nread = 0;
     435        uint8_t *bp = (uint8_t *) buf;
     436
     437        do {
     438                bp += cnt;
     439                nread += cnt;
     440                cnt = read(fildes, bp, nbyte - nread);
     441        } while (cnt > 0 && (nbyte - nread - cnt) > 0);
     442
     443        if (cnt < 0)
     444                return cnt;
     445
     446        return nread + cnt;
     447}
     448
     449/** Write entire buffer.
     450 *
     451 * This function fails if it cannot write exactly @a len bytes to the file.
     452 *
     453 * @param fildes        File descriptor
     454 * @param buf           Data, @a nbytes bytes long
     455 * @param nbytes        Number of bytes to write
     456 *
     457 * @return              EOK on error, return value from write() if writing
     458 *                      failed.
     459 */
     460ssize_t write_all(int fildes, const void *buf, size_t nbyte)
     461{
     462        ssize_t cnt = 0;
     463        ssize_t nwritten = 0;
     464        const uint8_t *bp = (uint8_t *) buf;
     465
     466        do {
     467                bp += cnt;
     468                nwritten += cnt;
     469                cnt = write(fildes, bp, nbyte - nwritten);
     470        } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);
     471
     472        if (cnt < 0)
     473                return cnt;
     474
     475        if ((ssize_t)nbyte - nwritten - cnt > 0)
     476                return EIO;
     477
     478        return nbyte;
     479}
     480
    419481int fsync(int fildes)
    420482{
  • uspace/lib/c/include/rtld/elf_dyn.h

    refcebe1 r358dc13  
    3939#include <sys/types.h>
    4040
    41 #include <elf.h>
     41#include <elf/elf.h>
    4242#include <libarch/rtld/elf_dyn.h>
    4343
  • uspace/lib/c/include/rtld/rtld.h

    refcebe1 r358dc13  
    4949
    5050        /** List of all loaded modules including rtld and the program */
    51         link_t modules_head;
     51        list_t modules;
    5252
    5353        /** Temporary hack to place each module at different address. */
  • uspace/lib/c/include/rtld/symbol.h

    refcebe1 r358dc13  
    3636#define LIBC_RTLD_SYMBOL_H_
    3737
     38#include <elf/elf.h>
    3839#include <rtld/rtld.h>
    39 #include <elf.h>
    4040
    4141elf_symbol_t *symbol_bfs_find(const char *name, module_t *start, module_t **mod);
  • uspace/lib/c/include/unistd.h

    refcebe1 r358dc13  
    6363extern ssize_t read(int, void *, size_t);
    6464
     65extern ssize_t read_all(int, void *, size_t);
     66extern ssize_t write_all(int, const void *, size_t);
     67
    6568extern off64_t lseek(int, off64_t, int);
    6669extern int ftruncate(int, aoff64_t);
  • uspace/lib/scsi/include/scsi/spc.h

    refcebe1 r358dc13  
    179179        uint8_t additional_len;
    180180        /** Command-specific Information */
    181         uint8_t cmd_spec;
     181        uint32_t cmd_spec;
    182182        /** Additional Sense Code */
    183183        uint8_t additional_code;
     
    205205        SCSI_SK_ABORTED_COMMAND = 0xb,
    206206        SCSI_SK_VOLUME_OVERFLOW = 0xd,
    207         SCSI_SK_MISCOMPARE      = 0xe
     207        SCSI_SK_MISCOMPARE      = 0xe,
     208
     209        SCSI_SK_LIMIT           = 0x10
    208210};
    209211
    210212extern const char *scsi_dev_type_str[SCSI_DEV_LIMIT];
     213extern const char *scsi_sense_key_str[SCSI_SK_LIMIT];
     214
    211215extern const char *scsi_get_dev_type_str(unsigned);
     216extern const char *scsi_get_sense_key_str(unsigned);
    212217
    213218#endif
  • uspace/lib/scsi/src/spc.c

    refcebe1 r358dc13  
    4444};
    4545
     46const char *scsi_sense_key_str[SCSI_SK_LIMIT] = {
     47        [SCSI_SK_NO_SENSE]              = "No Sense",
     48        [SCSI_SK_RECOVERED_ERROR]       = "Recovered Error",
     49        [SCSI_SK_NOT_READY]             = "Not Ready",
     50        [SCSI_SK_MEDIUM_ERROR]          = "Medium Error",
     51        [SCSI_SK_HARDWARE_ERROR]        = "Hardware Error",
     52        [SCSI_SK_ILLEGAL_REQUEST]       = "Illegal Request",
     53        [SCSI_SK_UNIT_ATTENTION]        = "Unit Attention",
     54        [SCSI_SK_DATA_PROTECT]          = "Data Protect",
     55        [SCSI_SK_BLANK_CHECK]           = "Blank Check",
     56        [SCSI_SK_VENDOR_SPECIFIC]       = "Vendor-specific",
     57        [SCSI_SK_COPY_ABORTED]          = "Copy Aborted",
     58        [SCSI_SK_ABORTED_COMMAND]       = "Aborted Command",
     59        [SCSI_SK_VOLUME_OVERFLOW]       = "Volume Overflow",
     60        [SCSI_SK_MISCOMPARE]            = "Miscompare"
     61};
     62
    4663/** Get peripheral device type string.
    4764 *
     
    5370{
    5471        if (dev_type >= SCSI_DEV_LIMIT || scsi_dev_type_str[dev_type] == NULL)
    55                 return "<unknown>";
     72                return "Unknown";
    5673
    5774        return scsi_dev_type_str[dev_type];
    5875}
     76
     77/** Get sense key string.
     78 *
     79 * Return string description of SCSI sense key.
     80 * The returned string is valid indefinitely, the caller should
     81 * not attempt to free it.
     82 */
     83const char *scsi_get_sense_key_str(unsigned sense_key)
     84{
     85        if (sense_key >= SCSI_SK_LIMIT || scsi_sense_key_str[sense_key] == NULL)
     86                return "Unknown";
     87
     88        return scsi_sense_key_str[sense_key];
     89}
     90
  • uspace/srv/devman/devman.c

    refcebe1 r358dc13  
    270270        }
    271271       
    272         ssize_t read_bytes = safe_read(fd, buf, len);
     272        ssize_t read_bytes = read_all(fd, buf, len);
    273273        if (read_bytes <= 0) {
    274                 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
     274                log_msg(LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
     275                    read_bytes);
    275276                goto cleanup;
    276277        }
     
    421422        }
    422423       
    423         insert_fun_node(tree, fun, clone_string(""), NULL);
     424        insert_fun_node(tree, fun, str_dup(""), NULL);
    424425        match_id_t *id = create_match_id();
    425         id->id = clone_string("root");
     426        id->id = str_dup("root");
    426427        id->score = 100;
    427428        add_match_id(&fun->match_ids, id);
  • uspace/srv/devman/util.c

    refcebe1 r358dc13  
    9191}
    9292
    93 char *clone_string(const char *s)
    94 {
    95         size_t size = str_size(s) + 1;
    96         char *str;
    97        
    98         str = (char *) malloc(size);
    99         if (str != NULL)
    100                 str_cpy(str, size, s);
    101         return str;
    102 }
    103 
    10493void replace_char(char *str, char orig, char repl)
    10594{
     
    111100}
    112101
    113 ssize_t safe_read(int fd, void *buffer, size_t size)
    114 {
    115         if (size == 0) {
    116                 return 0;
    117         }
    118 
    119         uint8_t *buf_ptr = (uint8_t *) buffer;
    120 
    121         size_t total_read = 0;
    122         while (total_read < size) {
    123                 ssize_t bytes_read = read(fd, buf_ptr, size - total_read);
    124                 if (bytes_read < 0) {
    125                         /* Error. */
    126                         return bytes_read;
    127                 } else if (bytes_read == 0) {
    128                         /* Possibly end of file. */
    129                         break;
    130                 } else {
    131                         /* Read at least something. */
    132                         buf_ptr += bytes_read;
    133                         total_read += bytes_read;
    134                 }
    135         }
    136 
    137         return (ssize_t) total_read;
    138 }
    139 
    140102/** @}
    141103 */
  • uspace/srv/devman/util.h

    refcebe1 r358dc13  
    4444extern size_t get_nonspace_len(const char *);
    4545extern void free_not_null(const void *);
    46 extern char *clone_string(const char *);
    4746extern void replace_char(char *, char, char);
    48 
    49 extern ssize_t safe_read(int, void *, size_t);
    5047
    5148#endif
  • uspace/srv/loader/Makefile

    refcebe1 r358dc13  
    3939LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link-loader.ld
    4040
    41 EXTRA_CFLAGS = -Iinclude
    42 
    4341BINARY = loader
    4442STATIC_ONLY = y
     
    4644GENERIC_SOURCES = \
    4745        main.c \
    48         elf_load.c \
    4946        interp.s
    5047
  • uspace/srv/loader/main.c

    refcebe1 r358dc13  
    5959#include <str.h>
    6060#include <as.h>
    61 #include <elf.h>
    62 #include <elf_load.h>
     61#include <elf/elf.h>
     62#include <elf/elf_load.h>
    6363
    6464#ifdef CONFIG_RTLD
     
    348348
    349349        /* Initialize list of loaded modules */
    350         list_initialize(&runtime_env->modules_head);
    351         list_append(&prog_mod.modules_link, &runtime_env->modules_head);
     350        list_initialize(&runtime_env->modules);
     351        list_append(&prog_mod.modules_link, &runtime_env->modules);
    352352
    353353        /* Pointer to program module. Used as root of the module graph. */
Note: See TracChangeset for help on using the changeset viewer.