Changes in / [b366a1bc:e950803] in mainline


Ignore:
Files:
2 added
20 deleted
21 edited

Legend:

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

    rb366a1bc re950803  
    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

    rb366a1bc re950803  
    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

    rb366a1bc re950803  
    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/arch/ia32/_link.ld.in

    rb366a1bc re950803  
    4949        }
    5050       
     51#ifdef CONFIG_LINE_DEBUG
     52        .comment 0 : { *(.comment); }
     53        .debug_abbrev 0 : { *(.debug_abbrev); }
     54        .debug_aranges 0 : { *(.debug_aranges); }
     55        .debug_info 0 : { *(.debug_info); }
     56        .debug_line 0 : { *(.debug_line); }
     57        .debug_loc 0 : { *(.debug_loc); }
     58        .debug_pubnames 0 : { *(.debug_pubnames); }
     59        .debug_pubtypes 0 : { *(.debug_pubtypes); }
     60        .debug_ranges 0 : { *(.debug_ranges); }
     61        .debug_str 0 : { *(.debug_str); }
     62#endif
     63       
    5164        /DISCARD/ : {
    52                 *(.note.GNU-stack);
    53                 *(.comment);
     65                *(*);
    5466        }
    5567       
  • kernel/arch/mips32/src/mm/tlb.c

    rb366a1bc re950803  
    557557        entry_hi_t hi, hi_save;
    558558        tlb_index_t index;
    559 
    560         ASSERT(asid != ASID_INVALID);
     559       
     560        if (asid == ASID_INVALID)
     561                return;
    561562
    562563        hi_save.value = cp0_entry_hi_read();
  • kernel/generic/include/mm/as.h

    rb366a1bc re950803  
    115115       
    116116        /**
    117          * Number of processors on wich is this address space active.
    118          * Protected by asidlock.
     117         * Number of processors on which this
     118         * address space is active. Protected by
     119         * asidlock.
    119120         */
    120121        size_t cpu_refcount;
    121122       
    122         /**
    123          * Address space identifier.
    124          * Constant on architectures that do not support ASIDs.
    125          * Protected by asidlock.
     123        /** Address space identifier.
     124         *
     125         * Constant on architectures that do not
     126         * support ASIDs. Protected by asidlock.
     127         *
    126128         */
    127129        asid_t asid;
    128130       
    129         /** Number of references (i.e tasks that reference this as). */
     131        /** Number of references (i.e. tasks that reference this as). */
    130132        atomic_t refcount;
    131133       
     
    199201typedef struct {
    200202        mutex_t lock;
     203       
    201204        /** Containing address space. */
    202205        as_t *as;
    203206       
    204         /**
    205          * Flags related to the memory represented by the address space area.
    206          */
     207        /** Memory flags. */
    207208        unsigned int flags;
    208209       
    209         /** Attributes related to the address space area itself. */
     210        /** Address space area attributes. */
    210211        unsigned int attributes;
    211         /** Size of this area in multiples of PAGE_SIZE. */
     212       
     213        /** Number of pages in the area. */
    212214        size_t pages;
     215       
     216        /** Number of resident pages in the area. */
     217        size_t resident;
     218       
    213219        /** Base address of this area. */
    214220        uintptr_t base;
     221       
    215222        /** Map of used space. */
    216223        btree_t used_space;
    217224       
    218225        /**
    219          * If the address space area has been shared, this pointer will
    220          * reference the share info structure.
     226         * If the address space area is shared. this is
     227         * a reference to the share info structure.
    221228         */
    222229        share_info_t *sh_info;
     
    261268extern bool as_area_check_access(as_area_t *, pf_access_t);
    262269extern size_t as_area_get_size(uintptr_t);
    263 extern int used_space_insert(as_area_t *, uintptr_t, size_t);
    264 extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    265 
     270extern bool used_space_insert(as_area_t *, uintptr_t, size_t);
     271extern bool used_space_remove(as_area_t *, uintptr_t, size_t);
    266272
    267273/* Interface to be implemented by architectures. */
  • kernel/generic/src/console/cmd.c

    rb366a1bc re950803  
    553553        for (i = 0; basic_commands[i]; i++) {
    554554                cmd_initialize(basic_commands[i]);
    555                 if (!cmd_register(basic_commands[i]))
    556                         printf("Cannot register command %s\n", basic_commands[i]->name);
     555        }
     556
     557        for (i = 0; basic_commands[i]; i++) {
     558                if (!cmd_register(basic_commands[i])) {
     559                        printf("Cannot register command %s\n",
     560                            basic_commands[i]->name);
     561                }
    557562        }
    558563}
  • kernel/generic/src/lib/elf.c

    rb366a1bc re950803  
    157157        case PT_NULL:
    158158        case PT_PHDR:
     159        case PT_NOTE:
    159160                break;
    160161        case PT_LOAD:
     
    173174                break;
    174175        case PT_SHLIB:
    175         case PT_NOTE:
    176176        case PT_LOPROC:
    177177        case PT_HIPROC:
  • kernel/generic/src/mm/as.c

    rb366a1bc re950803  
    8686 * Each architecture decides what functions will be used to carry out
    8787 * address space operations such as creating or locking page tables.
    88  *
    8988 */
    9089as_operations_t *as_operations = NULL;
    9190
    92 /**
    93  * Slab for as_t objects.
     91/** Slab for as_t objects.
    9492 *
    9593 */
    9694static slab_cache_t *as_slab;
    9795
    98 /**
    99  * This lock serializes access to the ASID subsystem.
    100  * It protects:
     96/** ASID subsystem lock.
     97 *
     98 * This lock protects:
    10199 * - inactive_as_with_asid_head list
    102100 * - as->asid for each as of the as_t type
     
    107105
    108106/**
    109  * This list contains address spaces that are not active on any
    110  * processor and that have valid ASID.
    111  *
     107 * Inactive address spaces (on all processors)
     108 * that have valid ASID.
    112109 */
    113110LIST_INITIALIZE(inactive_as_with_asid_head);
     
    123120        mutex_initialize(&as->lock, MUTEX_PASSIVE);
    124121       
    125         int rc = as_constructor_arch(as, flags);
    126        
    127         return rc;
     122        return as_constructor_arch(as, flags);
    128123}
    129124
    130125NO_TRACE static size_t as_destructor(void *obj)
    131126{
    132         as_t *as = (as_t *) obj;
    133         return as_destructor_arch(as);
     127        return as_destructor_arch((as_t *) obj);
    134128}
    135129
     
    146140                panic("Cannot create kernel address space.");
    147141       
    148         /* Make sure the kernel address space
     142        /*
     143         * Make sure the kernel address space
    149144         * reference count never drops to zero.
    150145         */
     
    195190{
    196191        DEADLOCK_PROBE_INIT(p_asidlock);
    197 
     192       
    198193        ASSERT(as != AS);
    199194        ASSERT(atomic_get(&as->refcount) == 0);
     
    203198         * lock its mutex.
    204199         */
    205 
     200       
    206201        /*
    207202         * We need to avoid deadlock between TLB shootdown and asidlock.
     
    210205         * disabled to prevent nested context switches. We also depend on the
    211206         * fact that so far no spinlocks are held.
    212          *
    213207         */
    214208        preemption_disable();
     
    235229        spinlock_unlock(&asidlock);
    236230        interrupts_restore(ipl);
    237 
     231       
    238232       
    239233        /*
     
    241235         * The B+tree must be walked carefully because it is
    242236         * also being destroyed.
    243          *
    244237         */
    245238        bool cond = true;
     
    268261/** Hold a reference to an address space.
    269262 *
    270  * Holding a reference to an address space prevents destruction of that address
    271  * space.
     263 * Holding a reference to an address space prevents destruction
     264 * of that address space.
    272265 *
    273266 * @param as Address space to be held.
     
    281274/** Release a reference to an address space.
    282275 *
    283  * The last one to release a reference to an address space destroys the address
    284  * space.
     276 * The last one to release a reference to an address space
     277 * destroys the address space.
    285278 *
    286279 * @param asAddress space to be released.
     
    310303        /*
    311304         * We don't want any area to have conflicts with NULL page.
    312          *
    313305         */
    314306        if (overlaps(va, size, (uintptr_t) NULL, PAGE_SIZE))
     
    321313         * record in the left neighbour, the leftmost record in the right
    322314         * neighbour and all records in the leaf node itself.
    323          *
    324315         */
    325316        btree_node_t *leaf;
     
    382373         * So far, the area does not conflict with other areas.
    383374         * Check if it doesn't conflict with kernel address space.
    384          *
    385375         */
    386376        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
     
    437427        area->attributes = attrs;
    438428        area->pages = SIZE2FRAMES(size);
     429        area->resident = 0;
    439430        area->base = base;
    440431        area->sh_info = NULL;
     
    479470         * to find out whether this is a miss or va belongs to an address
    480471         * space area found there.
    481          *
    482472         */
    483473       
     
    499489         * Second, locate the left neighbour and test its last record.
    500490         * Because of its position in the B+tree, it must have base < va.
    501          *
    502491         */
    503492        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     
    534523        /*
    535524         * Locate the area.
    536          *
    537525         */
    538526        as_area_t *area = find_area_and_lock(as, address);
     
    546534                 * Remapping of address space areas associated
    547535                 * with memory mapped devices is not supported.
    548                  *
    549536                 */
    550537                mutex_unlock(&area->lock);
     
    557544                 * Remapping of shared address space areas
    558545                 * is not supported.
    559                  *
    560546                 */
    561547                mutex_unlock(&area->lock);
     
    568554                /*
    569555                 * Zero size address space areas are not allowed.
    570                  *
    571556                 */
    572557                mutex_unlock(&area->lock);
     
    581566                 * Shrinking the area.
    582567                 * No need to check for overlaps.
    583                  *
    584568                 */
    585569               
     
    588572                /*
    589573                 * Start TLB shootdown sequence.
    590                  *
    591574                 */
    592575                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
     
    599582                 * is also the right way to remove part of the used_space
    600583                 * B+tree leaf list.
    601                  *
    602584                 */
    603585                bool cond = true;
     
    623605                                                 * completely in the resized
    624606                                                 * address space area.
    625                                                  *
    626607                                                 */
    627608                                                break;
     
    632613                                         * to b and c overlaps with the resized
    633614                                         * address space area.
    634                                          *
    635615                                         */
    636616                                       
     
    673653                /*
    674654                 * Finish TLB shootdown sequence.
    675                  *
    676655                 */
    677656               
     
    681660                /*
    682661                 * Invalidate software translation caches (e.g. TSB on sparc64).
    683                  *
    684662                 */
    685663                as_invalidate_translation_cache(as, area->base +
     
    692670                 * Growing the area.
    693671                 * Check for overlaps with other address space areas.
    694                  *
    695672                 */
    696673                if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
     
    813790        /*
    814791         * Finish TLB shootdown sequence.
    815          *
    816792         */
    817793       
     
    821797         * Invalidate potential software translation caches (e.g. TSB on
    822798         * sparc64).
    823          *
    824799         */
    825800        as_invalidate_translation_cache(as, area->base, area->pages);
     
    839814        /*
    840815         * Remove the empty area from address space.
    841          *
    842816         */
    843817        btree_remove(&as->as_area_btree, base, NULL);
     
    881855                /*
    882856                 * Could not find the source address space area.
    883                  *
    884857                 */
    885858                mutex_unlock(&src_as->lock);
     
    891864                 * There is no backend or the backend does not
    892865                 * know how to share the area.
    893                  *
    894866                 */
    895867                mutex_unlock(&src_area->lock);
     
    918890         * First, prepare the area for sharing.
    919891         * Then it will be safe to unlock it.
    920          *
    921892         */
    922893        share_info_t *sh_info = src_area->sh_info;
     
    930901                /*
    931902                 * Call the backend to setup sharing.
    932                  *
    933903                 */
    934904                src_area->backend->share(src_area);
     
    949919         * The flags of the source area are masked against dst_flags_mask
    950920         * to support sharing in less privileged mode.
    951          *
    952921         */
    953922        as_area_t *dst_area = as_area_create(dst_as, dst_flags_mask, src_size,
     
    966935         * fully initialized. Clear the AS_AREA_ATTR_PARTIAL
    967936         * attribute and set the sh_info.
    968          *
    969937         */
    970938        mutex_lock(&dst_as->lock);
     
    989957NO_TRACE bool as_area_check_access(as_area_t *area, pf_access_t access)
    990958{
     959        ASSERT(mutex_locked(&area->lock));
     960       
    991961        int flagmap[] = {
    992962                [PF_ACCESS_READ] = AS_AREA_READ,
     
    994964                [PF_ACCESS_EXEC] = AS_AREA_EXEC
    995965        };
    996 
    997         ASSERT(mutex_locked(&area->lock));
    998966       
    999967        if (!(area->flags & flagmap[access]))
     
    10661034        /*
    10671035         * Compute total number of used pages in the used_space B+tree
    1068          *
    10691036         */
    10701037        size_t used_pages = 0;
     
    10881055        /*
    10891056         * Start TLB shootdown sequence.
    1090          *
    10911057         */
    10921058        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
     
    10961062         * Remove used pages from page tables and remember their frame
    10971063         * numbers.
    1098          *
    10991064         */
    11001065        size_t frame_idx = 0;
     
    11271092        /*
    11281093         * Finish TLB shootdown sequence.
    1129          *
    11301094         */
    11311095       
     
    11351099         * Invalidate potential software translation caches (e.g. TSB on
    11361100         * sparc64).
    1137          *
    11381101         */
    11391102        as_invalidate_translation_cache(as, area->base, area->pages);
     
    12171180                 * No area contained mapping for 'page'.
    12181181                 * Signal page fault to low-level handler.
    1219                  *
    12201182                 */
    12211183                mutex_unlock(&AS->lock);
     
    12371199                 * The address space area is not backed by any backend
    12381200                 * or the backend cannot handle page faults.
    1239                  *
    12401201                 */
    12411202                mutex_unlock(&area->lock);
     
    12491210         * To avoid race condition between two page faults on the same address,
    12501211         * we need to make sure the mapping has not been already inserted.
    1251          *
    12521212         */
    12531213        pte_t *pte;
     
    12671227        /*
    12681228         * Resort to the backend page fault handler.
    1269          *
    12701229         */
    12711230        if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     
    13221281                 * preemption is disabled. We should not be
    13231282                 * holding any other lock.
    1324                  *
    13251283                 */
    13261284                (void) interrupts_enable();
     
    13421300                         * list of inactive address spaces with assigned
    13431301                         * ASID.
    1344                          *
    13451302                         */
    13461303                        ASSERT(old_as->asid != ASID_INVALID);
     
    13531310                 * Perform architecture-specific tasks when the address space
    13541311                 * is being removed from the CPU.
    1355                  *
    13561312                 */
    13571313                as_deinstall_arch(old_as);
     
    13601316        /*
    13611317         * Second, prepare the new address space.
    1362          *
    13631318         */
    13641319        if ((new_as->cpu_refcount++ == 0) && (new_as != AS_KERNEL)) {
     
    13761331         * Perform architecture-specific steps.
    13771332         * (e.g. write ASID to hardware register etc.)
    1378          *
    13791333         */
    13801334        as_install_arch(new_as);
     
    13951349{
    13961350        ASSERT(mutex_locked(&area->lock));
    1397 
     1351       
    13981352        return area_flags_to_page_flags(area->flags);
    13991353}
     
    15161470 * @param count Number of page to be marked.
    15171471 *
    1518  * @return Zero on failure and non-zero on success.
    1519  *
    1520  */
    1521 int used_space_insert(as_area_t *area, uintptr_t page, size_t count)
     1472 * @return False on failure or true on success.
     1473 *
     1474 */
     1475bool used_space_insert(as_area_t *area, uintptr_t page, size_t count)
    15221476{
    15231477        ASSERT(mutex_locked(&area->lock));
     
    15301484                /*
    15311485                 * We hit the beginning of some used space.
    1532                  *
    1533                  */
    1534                 return 0;
     1486                 */
     1487                return false;
    15351488        }
    15361489       
    15371490        if (!leaf->keys) {
    15381491                btree_insert(&area->used_space, page, (void *) count, leaf);
    1539                 return 1;
     1492                goto success;
    15401493        }
    15411494       
     
    15511504                 * somewhere between the rightmost interval of
    15521505                 * the left neigbour and the first interval of the leaf.
    1553                  *
    15541506                 */
    15551507               
     
    15591511                    left_cnt * PAGE_SIZE)) {
    15601512                        /* The interval intersects with the left interval. */
    1561                         return 0;
     1513                        return false;
    15621514                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    15631515                    right_cnt * PAGE_SIZE)) {
    15641516                        /* The interval intersects with the right interval. */
    1565                         return 0;
     1517                        return false;
    15661518                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    15671519                    (page + count * PAGE_SIZE == right_pg)) {
     
    15691521                         * The interval can be added by merging the two already
    15701522                         * present intervals.
    1571                          *
    15721523                         */
    15731524                        node->value[node->keys - 1] += count + right_cnt;
    15741525                        btree_remove(&area->used_space, right_pg, leaf);
    1575                         return 1;
     1526                        goto success;
    15761527                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    15771528                        /*
    15781529                         * The interval can be added by simply growing the left
    15791530                         * interval.
    1580                          *
    15811531                         */
    15821532                        node->value[node->keys - 1] += count;
    1583                         return 1;
     1533                        goto success;
    15841534                } else if (page + count * PAGE_SIZE == right_pg) {
    15851535                        /*
     
    15871537                         * the right interval down and increasing its size
    15881538                         * accordingly.
    1589                          *
    15901539                         */
    15911540                        leaf->value[0] += count;
    15921541                        leaf->key[0] = page;
    1593                         return 1;
     1542                        goto success;
    15941543                } else {
    15951544                        /*
    15961545                         * The interval is between both neigbouring intervals,
    15971546                         * but cannot be merged with any of them.
    1598                          *
    15991547                         */
    16001548                        btree_insert(&area->used_space, page, (void *) count,
    16011549                            leaf);
    1602                         return 1;
     1550                        goto success;
    16031551                }
    16041552        } else if (page < leaf->key[0]) {
     
    16091557                 * Investigate the border case in which the left neighbour does
    16101558                 * not exist but the interval fits from the left.
    1611                  *
    16121559                 */
    16131560               
     
    16151562                    right_cnt * PAGE_SIZE)) {
    16161563                        /* The interval intersects with the right interval. */
    1617                         return 0;
     1564                        return false;
    16181565                } else if (page + count * PAGE_SIZE == right_pg) {
    16191566                        /*
     
    16211568                         * right interval down and increasing its size
    16221569                         * accordingly.
    1623                          *
    16241570                         */
    16251571                        leaf->key[0] = page;
    16261572                        leaf->value[0] += count;
    1627                         return 1;
     1573                        goto success;
    16281574                } else {
    16291575                        /*
    16301576                         * The interval doesn't adjoin with the right interval.
    16311577                         * It must be added individually.
    1632                          *
    16331578                         */
    16341579                        btree_insert(&area->used_space, page, (void *) count,
    16351580                            leaf);
    1636                         return 1;
     1581                        goto success;
    16371582                }
    16381583        }
     
    16491594                 * somewhere between the leftmost interval of
    16501595                 * the right neigbour and the last interval of the leaf.
    1651                  *
    16521596                 */
    16531597               
     
    16571601                    left_cnt * PAGE_SIZE)) {
    16581602                        /* The interval intersects with the left interval. */
    1659                         return 0;
     1603                        return false;
    16601604                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    16611605                    right_cnt * PAGE_SIZE)) {
    16621606                        /* The interval intersects with the right interval. */
    1663                         return 0;
     1607                        return false;
    16641608                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    16651609                    (page + count * PAGE_SIZE == right_pg)) {
     
    16671611                         * The interval can be added by merging the two already
    16681612                         * present intervals.
    1669                          *
    16701613                         */
    16711614                        leaf->value[leaf->keys - 1] += count + right_cnt;
    16721615                        btree_remove(&area->used_space, right_pg, node);
    1673                         return 1;
     1616                        goto success;
    16741617                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    16751618                        /*
    16761619                         * The interval can be added by simply growing the left
    16771620                         * interval.
    1678                          *
    16791621                         */
    1680                         leaf->value[leaf->keys - 1] +=  count;
    1681                         return 1;
     1622                        leaf->value[leaf->keys - 1] += count;
     1623                        goto success;
    16821624                } else if (page + count * PAGE_SIZE == right_pg) {
    16831625                        /*
     
    16851627                         * the right interval down and increasing its size
    16861628                         * accordingly.
    1687                          *
    16881629                         */
    16891630                        node->value[0] += count;
    16901631                        node->key[0] = page;
    1691                         return 1;
     1632                        goto success;
    16921633                } else {
    16931634                        /*
    16941635                         * The interval is between both neigbouring intervals,
    16951636                         * but cannot be merged with any of them.
    1696                          *
    16971637                         */
    16981638                        btree_insert(&area->used_space, page, (void *) count,
    16991639                            leaf);
    1700                         return 1;
     1640                        goto success;
    17011641                }
    17021642        } else if (page >= leaf->key[leaf->keys - 1]) {
     
    17071647                 * Investigate the border case in which the right neighbour
    17081648                 * does not exist but the interval fits from the right.
    1709                  *
    17101649                 */
    17111650               
     
    17131652                    left_cnt * PAGE_SIZE)) {
    17141653                        /* The interval intersects with the left interval. */
    1715                         return 0;
     1654                        return false;
    17161655                } else if (left_pg + left_cnt * PAGE_SIZE == page) {
    17171656                        /*
    17181657                         * The interval can be added by growing the left
    17191658                         * interval.
    1720                          *
    17211659                         */
    17221660                        leaf->value[leaf->keys - 1] += count;
    1723                         return 1;
     1661                        goto success;
    17241662                } else {
    17251663                        /*
    17261664                         * The interval doesn't adjoin with the left interval.
    17271665                         * It must be added individually.
    1728                          *
    17291666                         */
    17301667                        btree_insert(&area->used_space, page, (void *) count,
    17311668                            leaf);
    1732                         return 1;
     1669                        goto success;
    17331670                }
    17341671        }
     
    17381675         * only between two other intervals of the leaf. The two border cases
    17391676         * were already resolved.
    1740          *
    17411677         */
    17421678        btree_key_t i;
     
    17501686                        /*
    17511687                         * The interval fits between left_pg and right_pg.
    1752                          *
    17531688                         */
    17541689                       
     
    17581693                                 * The interval intersects with the left
    17591694                                 * interval.
    1760                                  *
    17611695                                 */
    1762                                 return 0;
     1696                                return false;
    17631697                        } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    17641698                            right_cnt * PAGE_SIZE)) {
     
    17661700                                 * The interval intersects with the right
    17671701                                 * interval.
    1768                                  *
    17691702                                 */
    1770                                 return 0;
     1703                                return false;
    17711704                        } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    17721705                            (page + count * PAGE_SIZE == right_pg)) {
     
    17741707                                 * The interval can be added by merging the two
    17751708                                 * already present intervals.
    1776                                  *
    17771709                                 */
    17781710                                leaf->value[i - 1] += count + right_cnt;
    17791711                                btree_remove(&area->used_space, right_pg, leaf);
    1780                                 return 1;
     1712                                goto success;
    17811713                        } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    17821714                                /*
    17831715                                 * The interval can be added by simply growing
    17841716                                 * the left interval.
    1785                                  *
    17861717                                 */
    17871718                                leaf->value[i - 1] += count;
    1788                                 return 1;
     1719                                goto success;
    17891720                        } else if (page + count * PAGE_SIZE == right_pg) {
    17901721                                /*
     
    17921723                                 * base of the right interval down and
    17931724                                 * increasing its size accordingly.
    1794                                  *
    17951725                                 */
    17961726                                leaf->value[i] += count;
    17971727                                leaf->key[i] = page;
    1798                                 return 1;
     1728                                goto success;
    17991729                        } else {
    18001730                                /*
     
    18021732                                 * intervals, but cannot be merged with any of
    18031733                                 * them.
    1804                                  *
    18051734                                 */
    18061735                                btree_insert(&area->used_space, page,
    18071736                                    (void *) count, leaf);
    1808                                 return 1;
     1737                                goto success;
    18091738                        }
    18101739                }
     
    18131742        panic("Inconsistency detected while adding %zu pages of used "
    18141743            "space at %p.", count, (void *) page);
     1744       
     1745success:
     1746        area->resident += count;
     1747        return true;
    18151748}
    18161749
     
    18231756 * @param count Number of page to be marked.
    18241757 *
    1825  * @return Zero on failure and non-zero on success.
    1826  *
    1827  */
    1828 int used_space_remove(as_area_t *area, uintptr_t page, size_t count)
     1758 * @return False on failure or true on success.
     1759 *
     1760 */
     1761bool used_space_remove(as_area_t *area, uintptr_t page, size_t count)
    18291762{
    18301763        ASSERT(mutex_locked(&area->lock));
     
    18371770                /*
    18381771                 * We are lucky, page is the beginning of some interval.
    1839                  *
    18401772                 */
    18411773                if (count > pages) {
    1842                         return 0;
     1774                        return false;
    18431775                } else if (count == pages) {
    18441776                        btree_remove(&area->used_space, page, leaf);
    1845                         return 1;
     1777                        goto success;
    18461778                } else {
    18471779                        /*
    18481780                         * Find the respective interval.
    18491781                         * Decrease its size and relocate its start address.
    1850                          *
    18511782                         */
    18521783                        btree_key_t i;
     
    18551786                                        leaf->key[i] += count * PAGE_SIZE;
    18561787                                        leaf->value[i] -= count;
    1857                                         return 1;
     1788                                        goto success;
    18581789                                }
    18591790                        }
     1791                       
    18601792                        goto error;
    18611793                }
     
    18761808                                 * removed by updating the size of the bigger
    18771809                                 * interval.
    1878                                  *
    18791810                                 */
    18801811                                node->value[node->keys - 1] -= count;
    1881                                 return 1;
     1812                                goto success;
    18821813                        } else if (page + count * PAGE_SIZE <
    18831814                            left_pg + left_cnt*PAGE_SIZE) {
     
    18881819                                 * the original interval and also inserting a
    18891820                                 * new interval.
    1890                                  *
    18911821                                 */
    18921822                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     
    18951825                                btree_insert(&area->used_space, page +
    18961826                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    1897                                 return 1;
     1827                                goto success;
    18981828                        }
    18991829                }
    1900                 return 0;
     1830               
     1831                return false;
    19011832        } else if (page < leaf->key[0])
    1902                 return 0;
     1833                return false;
    19031834       
    19041835        if (page > leaf->key[leaf->keys - 1]) {
     
    19141845                                 * interval of the leaf and can be removed by
    19151846                                 * updating the size of the bigger interval.
    1916                                  *
    19171847                                 */
    19181848                                leaf->value[leaf->keys - 1] -= count;
    1919                                 return 1;
     1849                                goto success;
    19201850                        } else if (page + count * PAGE_SIZE < left_pg +
    19211851                            left_cnt * PAGE_SIZE) {
     
    19261856                                 * original interval and also inserting a new
    19271857                                 * interval.
    1928                                  *
    19291858                                 */
    19301859                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     
    19331862                                btree_insert(&area->used_space, page +
    19341863                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    1935                                 return 1;
     1864                                goto success;
    19361865                        }
    19371866                }
    1938                 return 0;
     1867               
     1868                return false;
    19391869        }
    19401870       
    19411871        /*
    19421872         * The border cases have been already resolved.
    1943          * Now the interval can be only between intervals of the leaf. 
     1873         * Now the interval can be only between intervals of the leaf.
    19441874         */
    19451875        btree_key_t i;
     
    19621892                                         * be removed by updating the size of
    19631893                                         * the bigger interval.
    1964                                          *
    19651894                                         */
    19661895                                        leaf->value[i - 1] -= count;
    1967                                         return 1;
     1896                                        goto success;
    19681897                                } else if (page + count * PAGE_SIZE <
    19691898                                    left_pg + left_cnt * PAGE_SIZE) {
     
    19831912                                            count * PAGE_SIZE, (void *) new_cnt,
    19841913                                            leaf);
    1985                                         return 1;
     1914                                        goto success;
    19861915                                }
    19871916                        }
    1988                         return 0;
     1917                       
     1918                        return false;
    19891919                }
    19901920        }
     
    19931923        panic("Inconsistency detected while removing %zu pages of used "
    19941924            "space from %p.", count, (void *) page);
     1925       
     1926success:
     1927        area->resident -= count;
     1928        return true;
    19951929}
    19961930
  • kernel/generic/src/sysinfo/stats.c

    rb366a1bc re950803  
    160160static size_t get_task_virtmem(as_t *as)
    161161{
    162         size_t result = 0;
    163 
    164162        /*
    165          * We are holding some spinlocks here and therefore are not allowed to
    166          * block. Only attempt to lock the address space and address space area
    167          * mutexes conditionally. If it is not possible to lock either object,
    168          * allow the statistics to be inexact by skipping the respective object.
    169          *
    170          * Note that it may be infinitely better to let the address space
    171          * management code compute these statistics as it proceeds instead of
    172          * having them calculated over and over again here.
     163         * We are holding spinlocks here and therefore are not allowed to
     164         * block. Only attempt to lock the address space and address space
     165         * area mutexes conditionally. If it is not possible to lock either
     166         * object, return inexact statistics by skipping the respective object.
    173167         */
    174 
     168       
    175169        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    176                 return result * PAGE_SIZE;
     170                return 0;
     171       
     172        size_t pages = 0;
    177173       
    178174        /* Walk the B+ tree and count pages */
    179         link_t *cur;
    180         for (cur = as->as_area_btree.leaf_head.next;
    181             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
    182                 btree_node_t *node =
    183                     list_get_instance(cur, btree_node_t, leaf_link);
    184                
    185                 unsigned int i;
    186                 for (i = 0; i < node->keys; i++) {
    187                         as_area_t *area = node->value[i];
    188                        
    189                         if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    190                                 continue;
    191                         result += area->pages;
    192                         mutex_unlock(&area->lock);
    193                 }
    194         }
    195        
    196         mutex_unlock(&as->lock);
    197        
    198         return result * PAGE_SIZE;
    199 }
    200 
    201 /** Get the resident (used) size of a virtual address space
    202  *
    203  * @param as Address space.
    204  *
    205  * @return Size of the resident (used) virtual address space (bytes).
    206  *
    207  */
    208 static size_t get_task_resmem(as_t *as)
    209 {
    210         size_t result = 0;
    211        
    212         /*
    213          * We are holding some spinlocks here and therefore are not allowed to
    214          * block. Only attempt to lock the address space and address space area
    215          * mutexes conditionally. If it is not possible to lock either object,
    216          * allow the statistics to be inexact by skipping the respective object.
    217          *
    218          * Note that it may be infinitely better to let the address space
    219          * management code compute these statistics as it proceeds instead of
    220          * having them calculated over and over again here.
    221          */
    222        
    223         if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    224                 return result * PAGE_SIZE;
    225        
    226         /* Walk the B+ tree of AS areas */
    227175        link_t *cur;
    228176        for (cur = as->as_area_btree.leaf_head.next;
     
    238186                                continue;
    239187                       
    240                         /* Walk the B+ tree of resident pages */
    241                         link_t *rcur;
    242                         for (rcur = area->used_space.leaf_head.next;
    243                             rcur != &area->used_space.leaf_head; rcur = rcur->next) {
    244                                 btree_node_t *rnode =
    245                                     list_get_instance(rcur, btree_node_t, leaf_link);
    246                                
    247                                 unsigned int j;
    248                                 for (j = 0; j < rnode->keys; j++)
    249                                         result += (size_t) rnode->value[i];
    250                         }
    251                        
     188                        pages += area->pages;
    252189                        mutex_unlock(&area->lock);
    253190                }
     
    256193        mutex_unlock(&as->lock);
    257194       
    258         return result * PAGE_SIZE;
     195        return (pages << PAGE_WIDTH);
     196}
     197
     198/** Get the resident (used) size of a virtual address space
     199 *
     200 * @param as Address space.
     201 *
     202 * @return Size of the resident (used) virtual address space (bytes).
     203 *
     204 */
     205static size_t get_task_resmem(as_t *as)
     206{
     207        /*
     208         * We are holding spinlocks here and therefore are not allowed to
     209         * block. Only attempt to lock the address space and address space
     210         * area mutexes conditionally. If it is not possible to lock either
     211         * object, return inexact statistics by skipping the respective object.
     212         */
     213       
     214        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     215                return 0;
     216       
     217        size_t pages = 0;
     218       
     219        /* Walk the B+ tree and count pages */
     220        link_t *cur;
     221        for (cur = as->as_area_btree.leaf_head.next;
     222            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     223                btree_node_t *node =
     224                    list_get_instance(cur, btree_node_t, leaf_link);
     225               
     226                unsigned int i;
     227                for (i = 0; i < node->keys; i++) {
     228                        as_area_t *area = node->value[i];
     229                       
     230                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     231                                continue;
     232                       
     233                        pages += area->resident;
     234                        mutex_unlock(&area->lock);
     235                }
     236        }
     237       
     238        mutex_unlock(&as->lock);
     239       
     240        return (pages << PAGE_WIDTH);
    259241}
    260242
  • uspace/Makefile.common

    rb366a1bc re950803  
    135135endif
    136136
     137ifeq ($(CONFIG_LINE_DEBUG),y)
     138        GCC_CFLAGS += -g
     139        ICC_CFLAGS += -g
     140        SUNCC_CFLAGS += -g
     141        CLANG_CFLAGS += -g
     142endif
     143
    137144## Setup platform configuration
    138145#
  • uspace/drv/test2/test2.c

    rb366a1bc re950803  
    103103        if (dev->parent == NULL) {
    104104                fid_t postpone = fibril_create(postponed_birth, dev);
     105                if (postpone == 0) {
     106                        printf(NAME ": fibril_create() error\n");
     107                        return ENOMEM;
     108                }
    105109                fibril_add_ready(postpone);
    106110        } else {
  • uspace/lib/c/arch/amd64/_link.ld.in

    rb366a1bc re950803  
    55        text PT_LOAD FLAGS(5);
    66        data PT_LOAD FLAGS(6);
     7        debug PT_NOTE;
    78}
    89
     
    1314                *(.init);
    1415        } :text
     16       
    1517        .text : {
    1618                *(.text);
    1719                *(.rodata*);
    1820        } :text
    19 
     21       
    2022        . = . + 0x1000;
    21 
     23       
    2224        .data : {
    2325                *(.data);
    2426        } :data
     27       
    2528        .tdata : {
    2629                _tdata_start = .;
     
    3134                _tbss_end = .;
    3235        } :data
     36       
    3337        _tls_alignment = ALIGNOF(.tdata);
     38       
    3439        .bss : {
    3540                *(COMMON);
    3641                *(.bss);
    3742        } :data
    38 
     43       
    3944        . = ALIGN(0x1000);
    4045        _heap = .;
     46       
     47#ifdef CONFIG_LINE_DEBUG
     48        .comment 0 : { *(.comment); } :debug
     49        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     50        .debug_aranges 0 : { *(.debug_aranges); } :debug
     51        .debug_info 0 : { *(.debug_info); } :debug
     52        .debug_line 0 : { *(.debug_line); } :debug
     53        .debug_loc 0 : { *(.debug_loc); } :debug
     54        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     55        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     56        .debug_ranges 0 : { *(.debug_ranges); } :debug
     57        .debug_str 0 : { *(.debug_str); } :debug
     58#endif
    4159       
    4260        /DISCARD/ : {
  • uspace/lib/c/arch/ia32/_link.ld.in

    rb366a1bc re950803  
    55        text PT_LOAD FLAGS(5);
    66        data PT_LOAD FLAGS(6);
     7        debug PT_NOTE;
    78}
    89
     
    4344       
    4445        . = ALIGN(0x1000);
     46        _heap = .;
    4547       
    46         _heap = .;
     48#ifdef CONFIG_LINE_DEBUG
     49        .comment 0 : { *(.comment); } :debug
     50        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     51        .debug_aranges 0 : { *(.debug_aranges); } :debug
     52        .debug_info 0 : { *(.debug_info); } :debug
     53        .debug_line 0 : { *(.debug_line); } :debug
     54        .debug_loc 0 : { *(.debug_loc); } :debug
     55        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     56        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     57        .debug_ranges 0 : { *(.debug_ranges); } :debug
     58        .debug_str 0 : { *(.debug_str); } :debug
     59#endif
    4760       
    4861        /DISCARD/ : {
  • uspace/lib/c/generic/async.c

    rb366a1bc re950803  
    430430       
    431431        fid_t fid = fibril_create(notification_fibril, msg);
     432        if (fid == 0) {
     433                free(msg);
     434                futex_up(&async_futex);
     435                return false;
     436        }
     437       
    432438        fibril_add_ready(fid);
    433439       
     
    681687        conn->wdata.fid = fibril_create(connection_fibril, conn);
    682688       
    683         if (!conn->wdata.fid) {
     689        if (conn->wdata.fid == 0) {
    684690                free(conn);
     691               
    685692                if (callid)
    686693                        ipc_answer_0(callid, ENOMEM);
     694               
    687695                return (uintptr_t) NULL;
    688696        }
     
    853861{
    854862        fid_t fid = fibril_create(async_manager_fibril, NULL);
    855         fibril_add_manager(fid);
     863        if (fid != 0)
     864                fibril_add_manager(fid);
    856865}
    857866
  • uspace/srv/bd/ata_bd/ata_bd.c

    rb366a1bc re950803  
    5555#include <as.h>
    5656#include <fibril_synch.h>
     57#include <stdint.h>
    5758#include <str.h>
    5859#include <devmap.h>
     
    6162#include <errno.h>
    6263#include <bool.h>
     64#include <byteorder.h>
    6365#include <task.h>
    6466#include <macros.h>
     
    7375#define LEGACY_CTLS 4
    7476
    75 /** Physical block size. Should be always 512. */
    76 static const size_t block_size = 512;
     77/**
     78 * Size of data returned from Identify Device or Identify Packet Device
     79 * command.
     80 */
     81static const size_t identify_data_size = 512;
    7782
    7883/** Size of the communication area. */
     
    105110static int ata_bd_write_blocks(int disk_id, uint64_t ba, size_t cnt,
    106111    const void *buf);
    107 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t cnt,
     112static int ata_rcmd_read(int disk_id, uint64_t ba, size_t cnt,
    108113    void *buf);
    109 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     114static int ata_rcmd_write(int disk_id, uint64_t ba, size_t cnt,
    110115    const void *buf);
    111116static int disk_init(disk_t *d, int disk_id);
    112117static int drive_identify(int drive_id, void *buf);
     118static int identify_pkt_dev(int dev_idx, void *buf);
     119static int ata_cmd_packet(int dev_idx, const void *cpkt, size_t cpkt_size,
     120    void *obuf, size_t obuf_size);
     121static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size);
     122static int ata_pcmd_read_12(int dev_idx, uint64_t ba, size_t cnt,
     123    void *obuf, size_t obuf_size);
    113124static void disk_print_summary(disk_t *d);
    114125static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc);
     
    203214        printf("%s: ", d->model);
    204215
    205         switch (d->amode) {
    206         case am_chs:
    207                 printf("CHS %u cylinders, %u heads, %u sectors",
    208                     disk->geom.cylinders, disk->geom.heads, disk->geom.sectors);
    209                 break;
    210         case am_lba28:
    211                 printf("LBA-28");
    212                 break;
    213         case am_lba48:
    214                 printf("LBA-48");
    215                 break;
     216        if (d->dev_type == ata_reg_dev) {
     217                switch (d->amode) {
     218                case am_chs:
     219                        printf("CHS %u cylinders, %u heads, %u sectors",
     220                            disk->geom.cylinders, disk->geom.heads,
     221                            disk->geom.sectors);
     222                        break;
     223                case am_lba28:
     224                        printf("LBA-28");
     225                        break;
     226                case am_lba48:
     227                        printf("LBA-48");
     228                        break;
     229                }
     230        } else {
     231                printf("PACKET");
    216232        }
    217233
     
    313329                            IPC_GET_ARG2(call));
    314330                        cnt = IPC_GET_ARG3(call);
    315                         if (cnt * block_size > comm_size) {
     331                        if (cnt * disk[disk_id].block_size > comm_size) {
    316332                                retval = ELIMIT;
    317333                                break;
     
    323339                            IPC_GET_ARG2(call));
    324340                        cnt = IPC_GET_ARG3(call);
    325                         if (cnt * block_size > comm_size) {
     341                        if (cnt * disk[disk_id].block_size > comm_size) {
    326342                                retval = ELIMIT;
    327343                                break;
     
    330346                        break;
    331347                case BD_GET_BLOCK_SIZE:
    332                         async_answer_1(callid, EOK, block_size);
     348                        async_answer_1(callid, EOK, disk[disk_id].block_size);
    333349                        continue;
    334350                case BD_GET_NUM_BLOCKS:
     
    353369        identify_data_t idata;
    354370        uint8_t model[40];
     371        ata_inquiry_data_t inq_data;
    355372        uint16_t w;
    356373        uint8_t c;
     
    359376        unsigned i;
    360377
     378        d->present = false;
     379        fibril_mutex_initialize(&d->lock);
     380
     381        /* Try identify command. */
    361382        rc = drive_identify(disk_id, &idata);
    362         if (rc != EOK) {
    363                 d->present = false;
    364                 return rc;
    365         }
    366 
    367         if ((idata.caps & cap_lba) == 0) {
     383        if (rc == EOK) {
     384                /* Success. It's a register (non-packet) device. */
     385                printf("ATA register-only device found.\n");
     386                d->dev_type = ata_reg_dev;
     387        } else if (rc == EIO) {
     388                /*
     389                 * There is something, but not a register device.
     390                 * It could be a packet device.
     391                 */
     392                rc = identify_pkt_dev(disk_id, &idata);
     393                if (rc == EOK) {
     394                        /* We have a packet device. */
     395                        d->dev_type = ata_pkt_dev;
     396                } else {
     397                        /* Nope. Something's there, but not recognized. */
     398                        return EIO;
     399                }
     400        } else {
     401                /* Operation timed out. That means there is no device there. */
     402                return EIO;
     403        }
     404
     405        printf("device caps: 0x%04x\n", idata.caps);
     406        if (d->dev_type == ata_pkt_dev) {
     407                /* Packet device */
     408                d->amode = 0;
     409
     410                d->geom.cylinders = 0;
     411                d->geom.heads = 0;
     412                d->geom.sectors = 0;
     413
     414                d->blocks = 0;
     415        } else if ((idata.caps & rd_cap_lba) == 0) {
    368416                /* Device only supports CHS addressing. */
    369417                d->amode = am_chs;
     
    422470        d->model[pos] = '\0';
    423471
     472        if (d->dev_type == ata_pkt_dev) {
     473                /* Send inquiry. */
     474                rc = ata_pcmd_inquiry(0, &inq_data, sizeof(inq_data));
     475                if (rc != EOK) {
     476                        printf("Device inquiry failed.\n");
     477                        d->present = false;
     478                        return EIO;
     479                }
     480
     481                /* Check device type. */
     482                if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM)
     483                        printf("Warning: Peripheral device type is not CD-ROM.\n");
     484
     485                /* Assume 2k block size for now. */
     486                d->block_size = 2048;
     487        } else {
     488                /* Assume register Read always uses 512-byte blocks. */
     489                d->block_size = 512;
     490        }
     491
    424492        d->present = true;
    425         fibril_mutex_initialize(&d->lock);
    426 
    427493        return EOK;
    428494}
     
    435501
    436502        while (cnt > 0) {
    437                 rc = ata_bd_read_block(disk_id, ba, 1, buf);
     503                if (disk[disk_id].dev_type == ata_reg_dev)
     504                        rc = ata_rcmd_read(disk_id, ba, 1, buf);
     505                else
     506                        rc = ata_pcmd_read_12(disk_id, ba, 1, buf,
     507                            disk[disk_id].block_size);
     508
    438509                if (rc != EOK)
    439510                        return rc;
     
    441512                ++ba;
    442513                --cnt;
    443                 buf += block_size;
     514                buf += disk[disk_id].block_size;
    444515        }
    445516
     
    453524        int rc;
    454525
     526        if (disk[disk_id].dev_type != ata_reg_dev)
     527                return ENOTSUP;
     528
    455529        while (cnt > 0) {
    456                 rc = ata_bd_write_block(disk_id, ba, 1, buf);
     530                rc = ata_rcmd_write(disk_id, ba, 1, buf);
    457531                if (rc != EOK)
    458532                        return rc;
     
    460534                ++ba;
    461535                --cnt;
    462                 buf += block_size;
     536                buf += disk[disk_id].block_size;
    463537        }
    464538
     
    473547 * @param disk_id       Device ID, 0 or 1.
    474548 * @param buf           Pointer to a 512-byte buffer.
     549 *
     550 * @return              ETIMEOUT on timeout (this can mean the device is
     551 *                      not present). EIO if device responds with error.
    475552 */
    476553static int drive_identify(int disk_id, void *buf)
     
    484561
    485562        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    486                 return EIO;
     563                return ETIMEOUT;
    487564
    488565        pio_write_8(&cmd->drive_head, drv_head);
     
    493570         */
    494571        if (wait_status(SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
    495                 return EIO;
     572                return ETIMEOUT;
    496573
    497574        pio_write_8(&cmd->command, CMD_IDENTIFY_DRIVE);
    498575
    499576        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)
    500                 return EIO;
     577                return ETIMEOUT;
    501578
    502579        /* Read data from the disk buffer. */
    503580
    504581        if ((status & SR_DRQ) != 0) {
    505                 for (i = 0; i < block_size / 2; i++) {
     582                for (i = 0; i < identify_data_size / 2; i++) {
    506583                        data = pio_read_16(&cmd->data_port);
    507584                        ((uint16_t *) buf)[i] = data;
     
    509586        }
    510587
     588        if ((status & SR_ERR) != 0) {
     589                return EIO;
     590        }
     591
     592        return EOK;
     593}
     594
     595/** Issue Identify Packet Device command.
     596 *
     597 * Reads @c identify data into the provided buffer. This is used to detect
     598 * whether an ATAPI device is present and if so, to determine its parameters.
     599 *
     600 * @param dev_idx       Device index, 0 or 1.
     601 * @param buf           Pointer to a 512-byte buffer.
     602 */
     603static int identify_pkt_dev(int dev_idx, void *buf)
     604{
     605        uint16_t data;
     606        uint8_t status;
     607        uint8_t drv_head;
     608        size_t i;
     609
     610        drv_head = ((dev_idx != 0) ? DHR_DRV : 0);
     611
     612        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     613                return EIO;
     614
     615        pio_write_8(&cmd->drive_head, drv_head);
     616
     617        /* For ATAPI commands we do not need to wait for DRDY. */
     618        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)
     619                return EIO;
     620
     621        pio_write_8(&cmd->command, CMD_IDENTIFY_PKT_DEV);
     622
     623        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK)
     624                return EIO;
     625
     626        /* Read data from the device buffer. */
     627
     628        if ((status & SR_DRQ) != 0) {
     629                for (i = 0; i < identify_data_size / 2; i++) {
     630                        data = pio_read_16(&cmd->data_port);
     631                        ((uint16_t *) buf)[i] = data;
     632                }
     633        }
     634
    511635        if ((status & SR_ERR) != 0)
    512636                return EIO;
     637
     638        return EOK;
     639}
     640
     641/** Issue packet command (i. e. write a command packet to the device).
     642 *
     643 * Only data-in commands are supported (e.g. inquiry, read).
     644 *
     645 * @param dev_idx       Device index (0 or 1)
     646 * @param obuf          Buffer for storing data read from device
     647 * @param obuf_size     Size of obuf in bytes
     648 *
     649 * @return EOK on success, EIO on error.
     650 */
     651static int ata_cmd_packet(int dev_idx, const void *cpkt, size_t cpkt_size,
     652    void *obuf, size_t obuf_size)
     653{
     654        size_t i;
     655        uint8_t status;
     656        uint8_t drv_head;
     657        disk_t *d;
     658        size_t data_size;
     659        uint16_t val;
     660
     661        d = &disk[dev_idx];
     662        fibril_mutex_lock(&d->lock);
     663
     664        /* New value for Drive/Head register */
     665        drv_head =
     666            ((dev_idx != 0) ? DHR_DRV : 0);
     667
     668        if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) {
     669                fibril_mutex_unlock(&d->lock);
     670                return EIO;
     671        }
     672
     673        pio_write_8(&cmd->drive_head, drv_head);
     674
     675        if (wait_status(0, ~(SR_BSY|SR_DRQ), NULL, TIMEOUT_BSY) != EOK) {
     676                fibril_mutex_unlock(&d->lock);
     677                return EIO;
     678        }
     679
     680        /* Byte count <- max. number of bytes we can read in one transfer. */
     681        pio_write_8(&cmd->cylinder_low, 0xfe);
     682        pio_write_8(&cmd->cylinder_high, 0xff);
     683
     684        pio_write_8(&cmd->command, CMD_PACKET);
     685
     686        if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
     687                fibril_mutex_unlock(&d->lock);
     688                return EIO;
     689        }
     690
     691        /* Write command packet. */
     692        for (i = 0; i < (cpkt_size + 1) / 2; i++)
     693                pio_write_16(&cmd->data_port, ((uint16_t *) cpkt)[i]);
     694
     695        if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {
     696                fibril_mutex_unlock(&d->lock);
     697                return EIO;
     698        }
     699
     700        if ((status & SR_DRQ) == 0) {
     701                fibril_mutex_unlock(&d->lock);
     702                return EIO;
     703        }
     704
     705        /* Read byte count. */
     706        data_size = (uint16_t) pio_read_8(&cmd->cylinder_low) +
     707            ((uint16_t) pio_read_8(&cmd->cylinder_high) << 8);
     708
     709        /* Check whether data fits into output buffer. */
     710        if (data_size > obuf_size) {
     711                /* Output buffer is too small to store data. */
     712                fibril_mutex_unlock(&d->lock);
     713                return EIO;
     714        }
     715
     716        /* Read data from the device buffer. */
     717        for (i = 0; i < (data_size + 1) / 2; i++) {
     718                val = pio_read_16(&cmd->data_port);
     719                ((uint16_t *) obuf)[i] = val;
     720        }
     721
     722        if (status & SR_ERR) {
     723                fibril_mutex_unlock(&d->lock);
     724                return EIO;
     725        }
     726
     727        fibril_mutex_unlock(&d->lock);
     728
     729        return EOK;
     730}
     731
     732/** Issue ATAPI Inquiry.
     733 *
     734 * @param dev_idx       Device index (0 or 1)
     735 * @param obuf          Buffer for storing inquiry data read from device
     736 * @param obuf_size     Size of obuf in bytes
     737 *
     738 * @return EOK on success, EIO on error.
     739 */
     740static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size)
     741{
     742        ata_pcmd_inquiry_t cp;
     743        int rc;
     744
     745        memset(&cp, 0, sizeof(cp));
     746
     747        cp.opcode = PCMD_INQUIRY;
     748        cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */
     749
     750        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
     751        if (rc != EOK)
     752                return rc;
     753
     754        return EOK;
     755}
     756
     757/** Issue ATAPI read(12) command.
     758 *
     759 * Output buffer must be large enough to hold the data, otherwise the
     760 * function will fail.
     761 *
     762 * @param dev_idx       Device index (0 or 1)
     763 * @param ba            Starting block address
     764 * @param cnt           Number of blocks to read
     765 * @param obuf          Buffer for storing inquiry data read from device
     766 * @param obuf_size     Size of obuf in bytes
     767 *
     768 * @return EOK on success, EIO on error.
     769 */
     770static int ata_pcmd_read_12(int dev_idx, uint64_t ba, size_t cnt,
     771    void *obuf, size_t obuf_size)
     772{
     773        ata_pcmd_read_12_t cp;
     774        int rc;
     775
     776        if (ba > UINT32_MAX)
     777                return EINVAL;
     778
     779        memset(&cp, 0, sizeof(cp));
     780
     781        cp.opcode = PCMD_READ_12;
     782        cp.ba = host2uint32_t_be(ba);
     783        cp.nblocks = host2uint32_t_be(cnt);
     784
     785        rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size);
     786        if (rc != EOK)
     787                return rc;
    513788
    514789        return EOK;
     
    524799 * @return EOK on success, EIO on error.
    525800 */
    526 static int ata_bd_read_block(int disk_id, uint64_t ba, size_t blk_cnt,
     801static int ata_rcmd_read(int disk_id, uint64_t ba, size_t blk_cnt,
    527802    void *buf)
    528803{
     
    579854                /* Read data from the device buffer. */
    580855
    581                 for (i = 0; i < block_size / 2; i++) {
     856                for (i = 0; i < disk[disk_id].block_size / 2; i++) {
    582857                        data = pio_read_16(&cmd->data_port);
    583858                        ((uint16_t *) buf)[i] = data;
     
    601876 * @return EOK on success, EIO on error.
    602877 */
    603 static int ata_bd_write_block(int disk_id, uint64_t ba, size_t cnt,
     878static int ata_rcmd_write(int disk_id, uint64_t ba, size_t cnt,
    604879    const void *buf)
    605880{
     
    655930                /* Write data to the device buffer. */
    656931
    657                 for (i = 0; i < block_size / 2; i++) {
     932                for (i = 0; i < disk[disk_id].block_size / 2; i++) {
    658933                        pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]);
    659934                }
  • uspace/srv/bd/ata_bd/ata_bd.h

    rb366a1bc re950803  
    5353};
    5454
    55 /** Block addressing mode. */
    56 enum addr_mode {
     55enum ata_dev_type {
     56        ata_reg_dev,    /* Register device (no packet feature set support) */
     57        ata_pkt_dev     /* Packet device (supports packet feature set). */
     58};
     59
     60/** Register device block addressing mode. */
     61enum rd_addr_mode {
    5762        am_chs,         /**< CHS block addressing */
    5863        am_lba28,       /**< LBA-28 block addressing */
     
    6267/** Block coordinates */
    6368typedef struct {
    64         /** Addressing mode used */
    65         enum addr_mode amode;
     69        enum rd_addr_mode amode;
    6670
    6771        union {
     
    9094typedef struct {
    9195        bool present;
    92         enum addr_mode amode;
     96
     97        /** Device type */
     98        enum ata_dev_type dev_type;
     99
     100        /** Addressing mode to use (if register device) */
     101        enum rd_addr_mode amode;
    93102
    94103        /*
     
    102111
    103112        uint64_t blocks;
     113        size_t block_size;
    104114
    105115        char model[STR_BOUNDS(40) + 1];
  • uspace/srv/bd/ata_bd/ata_hw.h

    rb366a1bc re950803  
    134134        CMD_WRITE_SECTORS       = 0x30,
    135135        CMD_WRITE_SECTORS_EXT   = 0x34,
     136        CMD_PACKET              = 0xA0,
     137        CMD_IDENTIFY_PKT_DEV    = 0xA1,
    136138        CMD_IDENTIFY_DRIVE      = 0xEC
    137139};
    138140
    139 /** Data returned from @c identify command. */
     141/** Data returned from identify device and identify packet device command. */
    140142typedef struct {
    141143        uint16_t gen_conf;
     
    159161        uint16_t max_rw_multiple;
    160162        uint16_t _res48;
    161         uint16_t caps;
     163        uint16_t caps;          /* Different meaning for packet device */
    162164        uint16_t _res50;
    163165        uint16_t pio_timing;
     
    214216} identify_data_t;
    215217
    216 enum ata_caps {
    217         cap_iordy       = 0x0800,
    218         cap_iordy_cbd   = 0x0400,
    219         cap_lba         = 0x0200,
    220         cap_dma         = 0x0100
     218/** Capability bits for register device. */
     219enum ata_regdev_caps {
     220        rd_cap_iordy            = 0x0800,
     221        rd_cap_iordy_cbd        = 0x0400,
     222        rd_cap_lba              = 0x0200,
     223        rd_cap_dma              = 0x0100
     224};
     225
     226/** Capability bits for packet device. */
     227enum ata_pktdev_caps {
     228        pd_cap_ildma            = 0x8000,
     229        pd_cap_cmdqueue         = 0x4000,
     230        pd_cap_overlap          = 0x2000,
     231        pd_cap_need_softreset   = 0x1000,       /* Obsolete (ATAPI-6) */
     232        pd_cap_iordy            = 0x0800,
     233        pd_cap_iordy_dis        = 0x0400,
     234        pd_cap_lba              = 0x0200,       /* Must be on */
     235        pd_cap_dma              = 0x0100
    221236};
    222237
     
    226241};
    227242
     243/** ATA packet command codes. */
     244enum ata_pkt_command {
     245        PCMD_INQUIRY            = 0x12,
     246        PCMD_READ_12            = 0xa8
     247};
     248
     249/** ATAPI Inquiry command */
     250typedef struct {
     251        uint8_t opcode;         /**< Operation code (PCMD_INQUIRY) */
     252        uint8_t _res0;
     253        uint8_t _res1;
     254        uint8_t _res2;
     255        uint8_t alloc_len;      /**< Allocation length */
     256        uint8_t _res3;
     257        uint8_t _res4;
     258        uint8_t _res5;
     259        uint32_t _res6;
     260} __attribute__ ((packed)) ata_pcmd_inquiry_t;
     261
     262/** ATAPI Read(12) command */
     263typedef struct {
     264        uint8_t opcode;         /**< Operation code (PCMD_READ_12) */
     265        uint8_t _res0;
     266        uint32_t ba;            /**< Starting block address */
     267        uint32_t nblocks;       /**< Number of blocks to transfer */
     268        uint8_t _res1;
     269        uint8_t _res2;
     270} __attribute__ ((packed)) ata_pcmd_read_12_t;
     271
     272/** Data returned from Inquiry command (mandatory part) */
     273typedef struct {
     274        uint8_t pdev_type;      /** Reserved, Peripheral device type */
     275        uint8_t rmb;            /** RMB, Reserved */
     276        uint8_t std_version;    /** ISO version, ECMA version, ANSI version */
     277        uint8_t atapi_ver_rdf;  /** ATAPI version, Response data format */
     278        uint8_t additional_len; /** Additional length */
     279        uint8_t _res0;
     280        uint8_t _res1;
     281        uint8_t _res2;
     282        uint8_t vendor_id[8];   /** Vendor ID */
     283        uint8_t product_id[8];  /** Product ID */
     284        uint8_t product_rev[4]; /** Product revision level */
     285} ata_inquiry_data_t;
     286
     287/** Extract value of ata_inquiry_data_t.pdev_type */
     288#define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f)
     289
     290/** Values for ata_inquiry_data_t.pdev_type */
     291enum ata_pdev_type {
     292        PDEV_TYPE_CDROM         = 0x05
     293};
     294
    228295#endif
    229296
  • uspace/srv/loader/arch/amd64/_link.ld.in

    rb366a1bc re950803  
     1/*
     2 * The difference from _link.ld.in for regular statically-linked apps
     3 * is the base address and the special interp section.
     4 */
     5
    16STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    27ENTRY(__entry)
     
    611        text PT_LOAD FLAGS(5);
    712        data PT_LOAD FLAGS(6);
     13        debug PT_NOTE;
    814}
    915
     
    1117        .interp : {
    1218                *(.interp);
    13         } : interp
    14 
    15         /* . = 0x0000700000001000;*/
     19        } :interp
     20       
     21        /* . = 0x0000700000001000; */
    1622        . = 0x70001000;
    1723       
     
    1925                *(.init);
    2026        } :text
     27       
    2128        .text : {
    2229                *(.text);
     
    2734                *(.data);
    2835        } :data
     36       
    2937        .tdata : {
    3038                _tdata_start = .;
     
    3240                _tdata_end = .;
    3341        } :data
     42       
    3443        .tbss : {
    3544                _tbss_start = .;
     
    3746                _tbss_end = .;
    3847        } :data
     48       
    3949        _tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
     50       
    4051        .bss : {
    4152                *(COMMON);
    4253                *(.bss);
    4354        } :data
    44 
     55       
    4556        . = ALIGN(0x1000);
    4657        _heap = .;
     58       
     59#ifdef CONFIG_LINE_DEBUG
     60        .comment 0 : { *(.comment); } :debug
     61        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     62        .debug_aranges 0 : { *(.debug_aranges); } :debug
     63        .debug_info 0 : { *(.debug_info); } :debug
     64        .debug_line 0 : { *(.debug_line); } :debug
     65        .debug_loc 0 : { *(.debug_loc); } :debug
     66        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     67        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     68        .debug_ranges 0 : { *(.debug_ranges); } :debug
     69        .debug_str 0 : { *(.debug_str); } :debug
     70#endif
    4771       
    4872        /DISCARD/ : {
    4973                *(*);
    5074        }
    51 
    5275}
  • uspace/srv/loader/arch/ia32/_link.ld.in

    rb366a1bc re950803  
    33 * is the base address and the special interp section.
    44 */
     5
    56STARTUP(LIBC_PREFIX/arch/UARCH/src/entry.o)
    67ENTRY(__entry)
     
    1011        text PT_LOAD FILEHDR PHDRS FLAGS(5);
    1112        data PT_LOAD FLAGS(6);
     13        debug PT_NOTE;
    1214}
    1315
     
    5355       
    5456        . = ALIGN(0x1000);
     57        _heap = .;
    5558       
    56         _heap = .;
     59#ifdef CONFIG_LINE_DEBUG
     60        .comment 0 : { *(.comment); } :debug
     61        .debug_abbrev 0 : { *(.debug_abbrev); } :debug
     62        .debug_aranges 0 : { *(.debug_aranges); } :debug
     63        .debug_info 0 : { *(.debug_info); } :debug
     64        .debug_line 0 : { *(.debug_line); } :debug
     65        .debug_loc 0 : { *(.debug_loc); } :debug
     66        .debug_pubnames 0 : { *(.debug_pubnames); } :debug
     67        .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
     68        .debug_ranges 0 : { *(.debug_ranges); } :debug
     69        .debug_str 0 : { *(.debug_str); } :debug
     70#endif
    5771       
    5872        /DISCARD/ : {
  • uspace/srv/loader/elf_load.c

    rb366a1bc re950803  
    300300        case PT_NULL:
    301301        case PT_PHDR:
     302        case PT_NOTE:
    302303                break;
    303304        case PT_LOAD:
     
    310311        case PT_DYNAMIC:
    311312        case PT_SHLIB:
    312         case PT_NOTE:
    313313        case PT_LOPROC:
    314314        case PT_HIPROC:
Note: See TracChangeset for help on using the changeset viewer.