Changeset 60898b6 in mainline


Ignore:
Timestamp:
2010-11-05T16:17:48Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08042bd
Parents:
a63ff7d (diff), a66e2993 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Files:
8 added
61 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    ra63ff7d r60898b6  
    106106        $(USPACE_PATH)/srv/net/tl/tcp/tcp \
    107107        $(USPACE_PATH)/srv/net/net/net \
    108         $(USPACE_PATH)/srv/devman/devman \
    109         $(USPACE_PATH)/srv/drivers/root/root
     108        $(USPACE_PATH)/srv/devman/devman
    110109       
    111110RD_DRVS = \
  • boot/arch/amd64/Makefile.inc

    ra63ff7d r60898b6  
    3434RD_SRVS_NON_ESSENTIAL += \
    3535        $(USPACE_PATH)/srv/bd/ata_bd/ata_bd \
    36         $(USPACE_PATH)/srv/hw/bus/pci/pci \
    3736        $(USPACE_PATH)/srv/hid/char_mouse/char_ms
    3837
  • contrib/arch/hadlbppp.py

    ra63ff7d r60898b6  
    4242        "Print usage syntax"
    4343       
    44         print "%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname
    45         print
    46         print "--bp   Dump original Behavior Protocols (dChecker, BPSlicer)"
    47         print "--ebp  Dump Extended Behavior Protocols (bp2promela)"
    48         print "--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)"
    49         print "--dot  Dump Dot architecture diagram (GraphViz)"
    50         print "--nop  Do not dump anything (just input files syntax check)"
    51         print
     44        print("%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname)
     45        print()
     46        print("--bp   Dump original Behavior Protocols (dChecker, BPSlicer)")
     47        print("--ebp  Dump Extended Behavior Protocols (bp2promela)")
     48        print("--adl  Dump Architecture Description Language (modified SOFA ADL/CDL)")
     49        print("--dot  Dump Dot architecture diagram (GraphViz)")
     50        print("--nop  Do not dump anything (just input files syntax check)")
     51        print()
    5252
    5353def tabs(cnt):
     
    163163                                                result.append(tokens[i])
    164164                                else:
    165                                         print "%s: Syntax error in tentative statement" % name
     165                                        print("%s: Syntax error in tentative statement" % name)
    166166                        else:
    167                                 print "%s: Expected '{' for tentative statement" % name
     167                                print("%s: Expected '{' for tentative statement" % name)
    168168                else:
    169169                        result.append(tokens[i])
     
    231231                                                                result.append(tokens[i])
    232232                                                else:
    233                                                         print "%s: Syntax error in alternative statement" % name
     233                                                        print("%s: Syntax error in alternative statement" % name)
    234234                                        else:
    235                                                 print "%s: Expected '{' for alternative statement body" % name
     235                                                print("%s: Expected '{' for alternative statement body" % name)
    236236                                else:
    237                                         print "%s: At least one pattern and one replacement required for alternative statement" % name
     237                                        print("%s: At least one pattern and one replacement required for alternative statement" % name)
    238238                        else:
    239                                 print "%s: Expected '(' for alternative statement head" % name
     239                                print("%s: Expected '(' for alternative statement head" % name)
    240240                else:
    241241                        result.append(tokens[i])
     
    269269                                        result.append(tokens[i])
    270270                        else:
    271                                 print "%s: Unexpected end of protocol" % name
     271                                print("%s: Unexpected end of protocol" % name)
    272272               
    273273                i += 1
     
    349349                elif (token == ")"):
    350350                        if (indent < base_indent):
    351                                 print "%s: Too many parentheses" % name
     351                                print("%s: Too many parentheses" % name)
    352352                       
    353353                        indent -= 1
     
    358358                elif (token == "}"):
    359359                        if (indent < base_indent):
    360                                 print "%s: Too many parentheses" % name
     360                                print("%s: Too many parentheses" % name)
    361361                       
    362362                        indent -= 1
     
    370370       
    371371        if (indent > base_indent):
    372                 print "%s: Missing parentheses" % name
     372                print("%s: Missing parentheses" % name)
    373373       
    374374        output = output.strip()
     
    405405                        result.extend(inherited_protocols(supiface))
    406406                else:
    407                         print "%s: Extends unknown interface '%s'" % (iface['name'], iface['extends'])
     407                        print("%s: Extends unknown interface '%s'" % (iface['name'], iface['extends']))
    408408       
    409409        return result
     
    459459                                                protocols.append(proto)
    460460                        else:
    461                                 print "%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface'])
     461                                print("%s: Provided interface '%s' is undefined" % (frame['name'], provides['iface']))
    462462       
    463463        if (opt_bp):
    464                 outf = file(outname, "w")
     464                outf = open(outname, "w")
    465465                outf.write(parse_bp(outname, merge_bp(initialization, finalization, protocols), 0))
    466466                outf.close()
    467467       
    468468        if (opt_ebp):
    469                 outf = file(outname, "w")
     469                outf = open(outname, "w")
    470470                outf.write(parse_ebp(frame['name'], outname, merge_bp(initialization, finalization, protocols), 0))
    471471                outf.close()
     
    514514       
    515515        if (opt_bp):
    516                 outf = file(outname, "w")
     516                outf = open(outname, "w")
    517517                outf.write("NULL")
    518518                outf.close()
    519519       
    520520        if (opt_ebp):
    521                 outf = file(outname, "w")
     521                outf = open(outname, "w")
    522522                outf.write("component null {\n\tbehavior {\n\t\tNULL\n\t}\n}")
    523523                outf.close()
     
    587587                                        insts.append({'var': "%s_%s" % (prefix, inst['var']), 'frame': subframe})
    588588                                else:
    589                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     589                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    590590       
    591591        if ('bind' in arch):
     
    612612       
    613613        if (arch is None):
    614                 print "Unable to find system architecture"
     614                print("Unable to find system architecture")
    615615                return
    616616       
     
    634634                                        insts.append({'var': inst['var'], 'frame': subframe})
    635635                                else:
    636                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     636                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    637637       
    638638        if ('bind' in arch):
     
    642642        if ('delegate' in arch):
    643643                for delegate in arch['delegate']:
    644                         print "Unable to delegate interface in system architecture"
     644                        print("Unable to delegate interface in system architecture")
    645645                        break
    646646       
    647647        if ('subsume' in arch):
    648648                for subsume in arch['subsume']:
    649                         print "Unable to subsume interface in system architecture"
     649                        print("Unable to subsume interface in system architecture")
    650650                        break
    651651       
     
    654654        outname = os.path.join(outdir, "%s.archbp" % arch['name'])
    655655        if ((opt_bp) or (opt_ebp)):
    656                 outf = file(outname, "w")
     656                outf = open(outname, "w")
    657657        else:
    658658                outf = None
     
    709709               
    710710                if (not os.path.isfile(path)):
    711                         print "%s: Unable to include file %s" % (inname, path)
     711                        print("%s: Unable to include file %s" % (inname, path))
    712712                        return ""
    713713        else:
     
    716716                nested_root = root
    717717       
    718         inf = file(path, "r")
     718        inf = open(path, "r")
    719719       
    720720        raw = preproc_adl(inf.read(), inarg)
     
    733733                if (POST_INC in context):
    734734                        if (token != "]"):
    735                                 print "%s: Expected ]" % inname
     735                                print("%s: Expected ]" % inname)
    736736                       
    737737                        context.remove(POST_INC)
     
    774774                        if (NULL in context):
    775775                                if (token != ";"):
    776                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     776                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    777777                                else:
    778778                                        output += "%s\n" % token
     
    798798                                               
    799799                                                if ('finalization' in frame_properties[frame]):
    800                                                         print "%s: Finalization protocol for frame '%s' already defined" % (inname, frame)
     800                                                        print("%s: Finalization protocol for frame '%s' already defined" % (inname, frame))
    801801                                                else:
    802802                                                        frame_properties[frame]['finalization'] = bp
     
    832832                                               
    833833                                                if ('initialization' in frame_properties[frame]):
    834                                                         print "%s: Initialization protocol for frame '%s' already defined" % (inname, frame)
     834                                                        print("%s: Initialization protocol for frame '%s' already defined" % (inname, frame))
    835835                                                else:
    836836                                                        frame_properties[frame]['initialization'] = bp
     
    866866                                               
    867867                                                if ('protocol' in frame_properties[frame]):
    868                                                         print "%s: Protocol for frame '%s' already defined" % (inname, frame)
     868                                                        print("%s: Protocol for frame '%s' already defined" % (inname, frame))
    869869                                                else:
    870870                                                        frame_properties[frame]['protocol'] = bp
     
    889889                                        if (FIN in context):
    890890                                                if (token != ";"):
    891                                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     891                                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    892892                                                else:
    893893                                                        output += "%s" % token
     
    898898                                        if (VAR in context):
    899899                                                if (not identifier(token)):
    900                                                         print "%s: Variable name expected in frame '%s'" % (inname, frame)
     900                                                        print("%s: Variable name expected in frame '%s'" % (inname, frame))
    901901                                                else:
    902902                                                        if (not frame in frame_properties):
     
    919919                                        else:
    920920                                                if (not identifier(token)):
    921                                                         print "%s: Interface name expected in frame '%s'" % (inname, frame)
     921                                                        print("%s: Interface name expected in frame '%s'" % (inname, frame))
    922922                                                else:
    923923                                                        arg0 = token
     
    930930                                        if (FIN in context):
    931931                                                if (token != ";"):
    932                                                         print "%s: Expected ';' in frame '%s'" % (inname, frame)
     932                                                        print("%s: Expected ';' in frame '%s'" % (inname, frame))
    933933                                                else:
    934934                                                        output += "%s" % token
     
    939939                                        if (VAR in context):
    940940                                                if (not identifier(token)):
    941                                                         print "%s: Variable name expected in frame '%s'" % (inname, frame)
     941                                                        print("%s: Variable name expected in frame '%s'" % (inname, frame))
    942942                                                else:
    943943                                                        if (not frame in frame_properties):
     
    960960                                        else:
    961961                                                if (not identifier(token)):
    962                                                         print "%s: Interface name expected in frame '%s'" % (inname, frame)
     962                                                        print("%s: Interface name expected in frame '%s'" % (inname, frame))
    963963                                                else:
    964964                                                        arg0 = token
     
    970970                                if (token == "}"):
    971971                                        if (indent != 2):
    972                                                 print "%s: Wrong number of parentheses in frame '%s'" % (inname, frame)
     972                                                print("%s: Wrong number of parentheses in frame '%s'" % (inname, frame))
    973973                                        else:
    974974                                                indent = 0
     
    10101010                                        continue
    10111011                               
    1012                                 print "%s: Unknown token '%s' in frame '%s'" % (inname, token, frame)
     1012                                print("%s: Unknown token '%s' in frame '%s'" % (inname, token, frame))
    10131013                                continue
    10141014                       
     
    10271027                                        continue
    10281028                               
    1029                                 print "%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame)
     1029                                print("%s: Unknown token '%s' in frame head '%s'" % (inname, token, frame))
    10301030                               
    10311031                                continue
    10321032                       
    10331033                        if (not identifier(token)):
    1034                                 print "%s: Expected frame name" % inname
     1034                                print("%s: Expected frame name" % inname)
    10351035                        else:
    10361036                                frame = token
     
    10501050                        if (NULL in context):
    10511051                                if (token != ";"):
    1052                                         print "%s: Expected ';' in interface '%s'" % (inname, interface)
     1052                                        print("%s: Expected ';' in interface '%s'" % (inname, interface))
    10531053                                else:
    10541054                                        output += "%s\n" % token
     
    10741074                                               
    10751075                                                if ('protocol' in iface_properties[interface]):
    1076                                                         print "%s: Protocol for interface '%s' already defined" % (inname, interface)
     1076                                                        print("%s: Protocol for interface '%s' already defined" % (inname, interface))
    10771077                                                else:
    10781078                                                        iface_properties[interface]['protocol'] = bp
     
    10941094                                        if (FIN in context):
    10951095                                                if (token != ";"):
    1096                                                         print "%s: Expected ';' in interface '%s'" % (inname, interface)
     1096                                                        print("%s: Expected ';' in interface '%s'" % (inname, interface))
    10971097                                                else:
    10981098                                                        output += "%s" % token
     
    11241124                                        if (PAR_LEFT in context):
    11251125                                                if (token != "("):
    1126                                                         print "%s: Expected '(' in interface '%s'" % (inname, interface)
     1126                                                        print("%s: Expected '(' in interface '%s'" % (inname, interface))
    11271127                                                else:
    11281128                                                        output += "%s" % token
     
    11331133                                       
    11341134                                        if (not identifier(token)):
    1135                                                 print "%s: Method identifier expected in interface '%s'" % (inname, interface)
     1135                                                print("%s: Method identifier expected in interface '%s'" % (inname, interface))
    11361136                                        else:
    11371137                                                output += "%s" % token
     
    11421142                                if (token == "}"):
    11431143                                        if (indent != 2):
    1144                                                 print "%s: Wrong number of parentheses in interface '%s'" % (inname, interface)
     1144                                                print("%s: Wrong number of parentheses in interface '%s'" % (inname, interface))
    11451145                                        else:
    11461146                                                indent = 0
     
    11631163                                        continue
    11641164                               
    1165                                 print "%s: Unknown token '%s' in interface '%s'" % (inname, token, interface)
     1165                                print("%s: Unknown token '%s' in interface '%s'" % (inname, token, interface))
    11661166                                continue
    11671167                       
     
    11831183                                                continue
    11841184                                               
    1185                                         print "%s: Expected '{' or ';' in interface head '%s'" % (inname, interface)
     1185                                        print("%s: Expected '{' or ';' in interface head '%s'" % (inname, interface))
    11861186                                        continue
    11871187                               
    11881188                                if (EXTENDS in context):
    11891189                                        if (not identifier(token)):
    1190                                                 print "%s: Expected inherited interface name in interface head '%s'" % (inname, interface)
     1190                                                print("%s: Expected inherited interface name in interface head '%s'" % (inname, interface))
    11911191                                        else:
    11921192                                                output += "%s " % token
     
    12181218                                        continue
    12191219                               
    1220                                 print "%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface)
     1220                                print("%s: Expected 'extends', '{' or ';' in interface head '%s'" % (inname, interface))
    12211221                                continue
    12221222                       
    12231223                        if (not identifier(token)):
    1224                                 print "%s: Expected interface name" % inname
     1224                                print("%s: Expected interface name" % inname)
    12251225                        else:
    12261226                                interface = token
     
    12401240                        if (NULL in context):
    12411241                                if (token != ";"):
    1242                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1242                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    12431243                                else:
    12441244                                        output += "%s\n" % token
     
    12541254                                        if (FIN in context):
    12551255                                                if (token != ";"):
    1256                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1256                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    12571257                                                else:
    12581258                                                        output += "%s" % token
     
    12641264                                        if (VAR in context):
    12651265                                                if (not descriptor(token)):
    1266                                                         print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1266                                                        print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    12671267                                                else:
    12681268                                                        if (not architecture in arch_properties):
     
    12831283                                        if (TO in context):
    12841284                                                if (token != "to"):
    1285                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1285                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    12861286                                                else:
    12871287                                                        output += "%s " % token
     
    12921292                                       
    12931293                                        if (not identifier(token)):
    1294                                                 print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     1294                                                print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
    12951295                                        else:
    12961296                                                output += "%s " % token
     
    13031303                                        if (FIN in context):
    13041304                                                if (token != ";"):
    1305                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1305                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    13061306                                                else:
    13071307                                                        output += "%s" % token
     
    13131313                                        if (VAR in context):
    13141314                                                if (not identifier(token)):
    1315                                                         print "%s: Expected interface name in architecture '%s'" % (inname, architecture)
     1315                                                        print("%s: Expected interface name in architecture '%s'" % (inname, architecture))
    13161316                                                else:
    13171317                                                        if (not architecture in arch_properties):
     
    13321332                                        if (TO in context):
    13331333                                                if (token != "to"):
    1334                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1334                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    13351335                                                else:
    13361336                                                        output += "%s " % token
     
    13411341                                       
    13421342                                        if (not descriptor(token)):
    1343                                                 print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1343                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    13441344                                        else:
    13451345                                                output += "%s " % token
     
    13521352                                        if (FIN in context):
    13531353                                                if (token != ";"):
    1354                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1354                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    13551355                                                else:
    13561356                                                        output += "%s" % token
     
    13621362                                        if (VAR in context):
    13631363                                                if (not descriptor(token)):
    1364                                                         print "%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture)
     1364                                                        print("%s: Expected second interface descriptor in architecture '%s'" % (inname, architecture))
    13651365                                                else:
    13661366                                                        if (not architecture in arch_properties):
     
    13811381                                        if (TO in context):
    13821382                                                if (token != "to"):
    1383                                                         print "%s: Expected 'to' in architecture '%s'" % (inname, architecture)
     1383                                                        print("%s: Expected 'to' in architecture '%s'" % (inname, architecture))
    13841384                                                else:
    13851385                                                        output += "%s " % token
     
    13901390                                       
    13911391                                        if (not descriptor(token)):
    1392                                                 print "%s: Expected interface descriptor in architecture '%s'" % (inname, architecture)
     1392                                                print("%s: Expected interface descriptor in architecture '%s'" % (inname, architecture))
    13931393                                        else:
    13941394                                                output += "%s " % token
     
    14011401                                        if (FIN in context):
    14021402                                                if (token != ";"):
    1403                                                         print "%s: Expected ';' in architecture '%s'" % (inname, architecture)
     1403                                                        print("%s: Expected ';' in architecture '%s'" % (inname, architecture))
    14041404                                                else:
    14051405                                                        output += "%s" % token
     
    14111411                                        if (VAR in context):
    14121412                                                if (not identifier(token)):
    1413                                                         print "%s: Expected instance name in architecture '%s'" % (inname, architecture)
     1413                                                        print("%s: Expected instance name in architecture '%s'" % (inname, architecture))
    14141414                                                else:
    14151415                                                        if (not architecture in arch_properties):
     
    14291429                                       
    14301430                                        if (not identifier(token)):
    1431                                                 print "%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture)
     1431                                                print("%s: Expected frame/architecture type in architecture '%s'" % (inname, architecture))
    14321432                                        else:
    14331433                                                output += "%s " % token
     
    14391439                                if (token == "}"):
    14401440                                        if (indent != 1):
    1441                                                 print "%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture)
     1441                                                print("%s: Wrong number of parentheses in architecture '%s'" % (inname, architecture))
    14421442                                        else:
    14431443                                                indent -= 1
     
    14681468                                        continue
    14691469                               
    1470                                 print "%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture)
     1470                                print("%s: Unknown token '%s' in architecture '%s'" % (inname, token, architecture))
    14711471                                continue
    14721472                       
     
    14871487                               
    14881488                                if (not word(token)):
    1489                                         print "%s: Expected word in architecture head '%s'" % (inname, architecture)
     1489                                        print("%s: Expected word in architecture head '%s'" % (inname, architecture))
    14901490                                else:
    14911491                                        output += "%s " % token
     
    14941494                       
    14951495                        if (not identifier(token)):
    1496                                 print "%s: Expected architecture name" % inname
     1496                                print("%s: Expected architecture name" % inname)
    14971497                        else:
    14981498                                architecture = token
     
    15141514                if (SYSTEM in context):
    15151515                        if (token != "architecture"):
    1516                                 print "%s: Expected 'architecture'" % inname
     1516                                print("%s: Expected 'architecture'" % inname)
    15171517                        else:
    15181518                                output += "%s " % token
     
    15411541                        continue
    15421542               
    1543                 print "%s: Unknown token '%s'" % (inname, token)
     1543                print("%s: Unknown token '%s'" % (inname, token))
    15441544       
    15451545        inf.close()
     
    15751575       
    15761576        if ((output != "") and (opt_adl)):
    1577                 outf = file(outname, "w")
     1577                outf = open(outname, "w")
    15781578                outf.write(output)
    15791579                outf.close()
     
    16331633                                        merge_dot_frame("%s_%s" % (prefix, inst['var']), inst['var'], subframe, outf, indent + 1)
    16341634                                else:
    1635                                         print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     1635                                        print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    16361636       
    16371637        if ('bind' in arch):
     
    17281728       
    17291729        if (arch is None):
    1730                 print "Unable to find system architecture"
     1730                print("Unable to find system architecture")
    17311731                return
    17321732       
    17331733        if (opt_dot):
    17341734                outname = os.path.join(outdir, "%s.dot" % arch['name'])
    1735                 outf = file(outname, "w")
     1735                outf = open(outname, "w")
    17361736               
    17371737                outf.write("digraph {\n")
     
    17521752                                                merge_dot_frame("%s" % inst['var'], inst['var'], subframe, outf, 1)
    17531753                                        else:
    1754                                                 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
     1754                                                print("%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']))
    17551755               
    17561756                if ('bind' in arch):
     
    17841784                if ('delegate' in arch):
    17851785                        for delegate in arch['delegate']:
    1786                                 print "Unable to delegate interface in system architecture"
     1786                                print("Unable to delegate interface in system architecture")
    17871787                                break
    17881788               
    17891789                if ('subsume' in arch):
    17901790                        for subsume in arch['subsume']:
    1791                                 print "Unable to subsume interface in system architecture"
     1791                                print("Unable to subsume interface in system architecture")
    17921792                                break
    17931793               
     
    18261826                        pass
    18271827                else:
    1828                         print "Error: Unknown command line option '%s'" % arg
     1828                        print("Error: Unknown command line option '%s'" % arg)
    18291829                        return
    18301830       
    18311831        if ((opt_bp) and (opt_ebp)):
    1832                 print "Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols"
     1832                print("Error: Cannot dump both original Behavior Protocols and Extended Behavior Protocols")
    18331833                return
    18341834       
    18351835        path = os.path.abspath(sys.argv[-1])
    18361836        if (not os.path.isdir(path)):
    1837                 print "Error: <OUTPUT> is not a directory"
     1837                print("Error: <OUTPUT> is not a directory")
    18381838                return
    18391839       
  • kernel/arch/abs32le/include/interrupt.h

    ra63ff7d r60898b6  
    3737
    3838#include <typedefs.h>
    39 #include <verify.h>
    40 #include <trace.h>
     39#include <arch/istate.h>
    4140
    4241#define IVT_ITEMS  0
     
    4544#define VECTOR_TLB_SHOOTDOWN_IPI  0
    4645
    47 /*
    48  * On real hardware this stores the registers which
    49  * need to be preserved during interupts.
    50  */
    51 typedef struct istate {
    52         uintptr_t ip;
    53         uintptr_t fp;
    54         uint32_t stack[];
    55 } istate_t;
    56 
    57 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    58     REQUIRES_EXTENT_MUTABLE(istate)
    59 {
    60         /* On real hardware this checks whether the interrupted
    61            context originated from user space. */
    62        
    63         return !(istate->ip & 0x80000000);
    64 }
    65 
    66 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    67     uintptr_t retaddr)
    68     WRITES(&istate->ip)
    69 {
    70         /* On real hardware this sets the instruction pointer. */
    71        
    72         istate->ip = retaddr;
    73 }
    74 
    75 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    76     REQUIRES_EXTENT_MUTABLE(istate)
    77 {
    78         /* On real hardware this returns the instruction pointer. */
    79        
    80         return istate->ip;
    81 }
    82 
    83 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    84     REQUIRES_EXTENT_MUTABLE(istate)
    85 {
    86         /* On real hardware this returns the frame pointer. */
    87        
    88         return istate->fp;
    89 }
    90 
    9146#endif
    9247
  • kernel/arch/amd64/include/interrupt.h

    ra63ff7d r60898b6  
    3737
    3838#include <typedefs.h>
     39#include <arch/istate.h>
    3940#include <arch/pm.h>
    40 #include <trace.h>
    4141
    4242#define IVT_ITEMS  IDT_ITEMS
     
    7171#define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
    7272
    73 /** This is passed to interrupt handlers */
    74 typedef struct istate {
    75         uint64_t rax;
    76         uint64_t rbx;
    77         uint64_t rcx;
    78         uint64_t rdx;
    79         uint64_t rsi;
    80         uint64_t rdi;
    81         uint64_t rbp;
    82         uint64_t r8;
    83         uint64_t r9;
    84         uint64_t r10;
    85         uint64_t r11;
    86         uint64_t r12;
    87         uint64_t r13;
    88         uint64_t r14;
    89         uint64_t r15;
    90         uint64_t alignment;     /* align rbp_frame on multiple of 16 */
    91         uint64_t rbp_frame;     /* imitation of frame pointer linkage */
    92         uint64_t rip_frame;     /* imitation of return address linkage */
    93         uint64_t error_word;    /* real or fake error word */
    94         uint64_t rip;
    95         uint64_t cs;
    96         uint64_t rflags;
    97         uint64_t rsp;           /* only if istate_t is from uspace */
    98         uint64_t ss;            /* only if istate_t is from uspace */
    99 } istate_t;
    100 
    101 /** Return true if exception happened while in userspace */
    102 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    103 {
    104         return !(istate->rip & 0x8000000000000000);
    105 }
    106 
    107 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    108     uintptr_t retaddr)
    109 {
    110         istate->rip = retaddr;
    111 }
    112 
    113 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    114 {
    115         return istate->rip;
    116 }
    117 
    118 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    119 {
    120         return istate->rbp;
    121 }
    122 
    12373extern void (* disable_irqs_function)(uint16_t);
    12474extern void (* enable_irqs_function)(uint16_t);
  • kernel/arch/amd64/src/asm.S

    ra63ff7d r60898b6  
    9595memcpy_from_uspace_failover_address:
    9696memcpy_to_uspace_failover_address:
    97         xorq %rax, %rax         /* return 0, failure */
     97        xorl %eax, %eax         /* return 0, failure */
    9898        ret
    9999
     
    143143
    144144set_efer_flag:
    145         movq $0xc0000080, %rcx
     145        movl $0xc0000080, %ecx
    146146        rdmsr
    147147        btsl %edi, %eax
     
    150150
    151151read_efer_flag:
    152         movq $0xc0000080, %rcx
     152        movl $0xc0000080, %ecx
    153153        rdmsr
    154154        ret
     
    243243         * Stop stack traces here if we came from userspace.
    244244         */
    245         xorq %rdx, %rdx
     245        xorl %edx, %edx
    246246        cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)
    247247        cmovnzq %rdx, %rbp
     
    386386        movq ISTATE_OFFSET_RSP(%rsp), %rsp
    387387
     388        /*
     389         * Clear the rest of the scratch registers to prevent information leak.
     390         * The 32-bit XOR on the low GPRs actually clears the entire 64-bit
     391         * register and the instruction is shorter.
     392         */
     393        xorl %edx, %edx
     394        xorl %esi, %esi
     395        xorl %edi, %edi
     396        xorq %r8, %r8
     397        xorq %r9, %r9
     398        xorq %r10, %r10
     399
    388400        sysretq
    389401
     
    413425        movq %rdi, %rsi
    414426        movq $(PA2KA(0xb8000)), %rdi  /* base of EGA text mode memory */
    415         xorq %rax, %rax
     427        xorl %eax, %eax
    416428       
    417429        /* Read bits 8 - 15 of the cursor address */
     
    493505                movq $(PA2KA(0xb80a0)), %rsi
    494506                movq $(PA2KA(0xb8000)), %rdi
    495                 movq $480, %rcx
     507                movl $480, %ecx
    496508                rep movsq
    497509               
    498510                /* Clear the 24th row */
    499                 xorq %rax, %rax
    500                 movq $20, %rcx
     511                xorl %eax, %eax
     512                movl $20, %ecx
    501513                rep stosq
    502514               
  • kernel/arch/amd64/src/boot/boot.S

    ra63ff7d r60898b6  
    516516                movq $(PA2KA(0xb80a0)), %rsi
    517517                movq $(PA2KA(0xb8000)), %rdi
    518                 movq $480, %rcx
     518                movl $480, %ecx
    519519                rep movsq
    520520               
    521521                /* Clear the 24th row */
    522                 xorq %rax, %rax
    523                 movq $20, %rcx
     522                xorl %eax, %eax
     523                movl $20, %ecx
    524524                rep stosq
    525525               
  • kernel/arch/amd64/src/context.S

    ra63ff7d r60898b6  
    4545        CONTEXT_SAVE_ARCH_CORE %rdi %rdx
    4646       
    47         xorq %rax, %rax       # context_save returns 1
    48         incq %rax
     47        xorl %eax, %eax       # context_save returns 1
     48        incl %eax
    4949        ret
    5050
     
    6060        movq %rdx, (%rsp)
    6161       
    62         xorq %rax, %rax       # context_restore returns 0
     62        xorl %eax, %eax       # context_restore returns 0
    6363        ret
  • kernel/arch/arm32/include/exception.h

    ra63ff7d r60898b6  
    3939
    4040#include <typedefs.h>
    41 #include <arch/regutils.h>
    42 #include <trace.h>
     41#include <arch/istate.h>
    4342
    4443/** If defined, forces using of high exception vectors. */
     
    8584extern uintptr_t exc_stack;
    8685
    87 /** Struct representing CPU state saved when an exception occurs. */
    88 typedef struct istate {
    89         uint32_t spsr;
    90         uint32_t sp;
    91         uint32_t lr;
    92        
    93         uint32_t r0;
    94         uint32_t r1;
    95         uint32_t r2;
    96         uint32_t r3;
    97         uint32_t r4;
    98         uint32_t r5;
    99         uint32_t r6;
    100         uint32_t r7;
    101         uint32_t r8;
    102         uint32_t r9;
    103         uint32_t r10;
    104         uint32_t fp;
    105         uint32_t r12;
    106        
    107         uint32_t pc;
    108 } istate_t;
    109 
    110 /** Set Program Counter member of given istate structure.
    111  *
    112  * @param istate  istate structure
    113  * @param retaddr new value of istate's PC member
    114  *
    115  */
    116 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    117     uintptr_t retaddr)
    118 {
    119         istate->pc = retaddr;
    120 }
    121 
    122 /** Return true if exception happened while in userspace. */
    123 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    124 {
    125         return (istate->spsr & STATUS_REG_MODE_MASK) == USER_MODE;
    126 }
    127 
    128 /** Return Program Counter member of given istate structure. */
    129 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    130 {
    131         return istate->pc;
    132 }
    133 
    134 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    135 {
    136         return istate->fp;
    137 }
    138 
    13986extern void install_exception_handlers(void);
    14087extern void exception_init(void);
  • kernel/arch/ia32/include/interrupt.h

    ra63ff7d r60898b6  
    3737
    3838#include <typedefs.h>
     39#include <arch/istate.h>
    3940#include <arch/pm.h>
    40 #include <trace.h>
    4141
    4242#define IVT_ITEMS  IDT_ITEMS
     
    7171#define VECTOR_DEBUG_IPI          (IVT_FREEBASE + 2)
    7272
    73 typedef struct istate {
    74         /*
    75          * The strange order of the GPRs is given by the requirement to use the
    76          * istate structure for both regular interrupts and exceptions as well
    77          * as for syscall handlers which use this order as an optimization.
    78          */
    79         uint32_t edx;
    80         uint32_t ecx;
    81         uint32_t ebx;
    82         uint32_t esi;
    83         uint32_t edi;
    84         uint32_t ebp;
    85         uint32_t eax;
    86        
    87         uint32_t ebp_frame;  /* imitation of frame pointer linkage */
    88         uint32_t eip_frame;  /* imitation of return address linkage */
    89        
    90         uint32_t gs;
    91         uint32_t fs;
    92         uint32_t es;
    93         uint32_t ds;
    94        
    95         uint32_t error_word;  /* real or fake error word */
    96         uint32_t eip;
    97         uint32_t cs;
    98         uint32_t eflags;
    99         uint32_t esp;         /* only if istate_t is from uspace */
    100         uint32_t ss;          /* only if istate_t is from uspace */
    101 } istate_t;
    102 
    103 /** Return true if exception happened while in userspace */
    104 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    105 {
    106         return !(istate->eip & 0x80000000);
    107 }
    108 
    109 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    110     uintptr_t retaddr)
    111 {
    112         istate->eip = retaddr;
    113 }
    114 
    115 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    116 {
    117         return istate->eip;
    118 }
    119 
    120 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    121 {
    122         return istate->ebp;
    123 }
    124 
    12573extern void (* disable_irqs_function)(uint16_t);
    12674extern void (* enable_irqs_function)(uint16_t);
  • kernel/arch/ia64/include/interrupt.h

    ra63ff7d r60898b6  
    3737
    3838#include <typedefs.h>
    39 #include <arch/register.h>
    40 #include <trace.h>
     39#include <arch/istate.h>
    4140
    4241/** ia64 has 256 INRs. */
     
    7473#define EOI  0  /**< The actual value doesn't matter. */
    7574
    76 typedef struct istate {
    77         uint128_t f2;
    78         uint128_t f3;
    79         uint128_t f4;
    80         uint128_t f5;
    81         uint128_t f6;
    82         uint128_t f7;
    83         uint128_t f8;
    84         uint128_t f9;
    85         uint128_t f10;
    86         uint128_t f11;
    87         uint128_t f12;
    88         uint128_t f13;
    89         uint128_t f14;
    90         uint128_t f15;
    91         uint128_t f16;
    92         uint128_t f17;
    93         uint128_t f18;
    94         uint128_t f19;
    95         uint128_t f20;
    96         uint128_t f21;
    97         uint128_t f22;
    98         uint128_t f23;
    99         uint128_t f24;
    100         uint128_t f25;
    101         uint128_t f26;
    102         uint128_t f27;
    103         uint128_t f28;
    104         uint128_t f29;
    105         uint128_t f30;
    106         uint128_t f31;
    107        
    108         uintptr_t ar_bsp;
    109         uintptr_t ar_bspstore;
    110         uintptr_t ar_bspstore_new;
    111         uint64_t ar_rnat;
    112         uint64_t ar_ifs;
    113         uint64_t ar_pfs;
    114         uint64_t ar_rsc;
    115         uintptr_t cr_ifa;
    116         cr_isr_t cr_isr;
    117         uintptr_t cr_iipa;
    118         psr_t cr_ipsr;
    119         uintptr_t cr_iip;
    120         uint64_t pr;
    121         uintptr_t sp;
    122        
    123         /*
    124          * The following variables are defined only for break_instruction
    125          * handler.
    126          */
    127         uint64_t in0;
    128         uint64_t in1;
    129         uint64_t in2;
    130         uint64_t in3;
    131         uint64_t in4;
    132         uint64_t in5;
    133         uint64_t in6;
    134 } istate_t;
    135 
    13675extern void *ivt;
    137 
    138 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    139     uintptr_t retaddr)
    140 {
    141         istate->cr_iip = retaddr;
    142         istate->cr_ipsr.ri = 0;    /* return to instruction slot #0 */
    143 }
    144 
    145 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    146 {
    147         return istate->cr_iip;
    148 }
    149 
    150 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    151 {
    152         /* FIXME */
    153        
    154         return 0;
    155 }
    156 
    157 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    158 {
    159         return (istate->cr_iip) < 0xe000000000000000ULL;
    160 }
    16176
    16277extern void general_exception(uint64_t, istate_t *);
  • kernel/arch/ia64/include/register.h

    ra63ff7d r60898b6  
    142142#ifndef __ASM__
    143143
     144#ifdef KERNEL
    144145#include <typedefs.h>
     146#else
     147#include <sys/types.h>
     148#endif
    145149
    146150/** Processor Status Register. */
  • kernel/arch/mips32/include/cp0.h

    ra63ff7d r60898b6  
    3636#define KERN_mips32_CP0_H_
    3737
     38#ifdef KERNEL
    3839#include <typedefs.h>
     40#else
     41#include <sys/types.h>
     42#endif
    3943
    4044#define cp0_status_ie_enabled_bit     (1 << 0)
  • kernel/arch/mips32/include/exception.h

    ra63ff7d r60898b6  
    3737
    3838#include <typedefs.h>
    39 #include <arch/cp0.h>
    40 #include <trace.h>
     39#include <arch/istate.h>
    4140
    4241#define EXC_Int    0
     
    5958#define EXC_VCED   31
    6059
    61 typedef struct istate {
    62         /*
    63          * The first seven registers are arranged so that the istate structure
    64          * can be used both for exception handlers and for the syscall handler.
    65          */
    66         uint32_t a0;    /* arg1 */
    67         uint32_t a1;    /* arg2 */
    68         uint32_t a2;    /* arg3 */
    69         uint32_t a3;    /* arg4 */
    70         uint32_t t0;    /* arg5 */
    71         uint32_t t1;    /* arg6 */
    72         uint32_t v0;    /* arg7 */
    73         uint32_t v1;
    74         uint32_t at;
    75         uint32_t t2;
    76         uint32_t t3;
    77         uint32_t t4;
    78         uint32_t t5;
    79         uint32_t t6;
    80         uint32_t t7;
    81         uint32_t s0;
    82         uint32_t s1;
    83         uint32_t s2;
    84         uint32_t s3;
    85         uint32_t s4;
    86         uint32_t s5;
    87         uint32_t s6;
    88         uint32_t s7;
    89         uint32_t t8;
    90         uint32_t t9;
    91         uint32_t kt0;
    92         uint32_t kt1;   /* We use it as thread-local pointer */
    93         uint32_t gp;
    94         uint32_t sp;
    95         uint32_t s8;
    96         uint32_t ra;
    97        
    98         uint32_t lo;
    99         uint32_t hi;
    100        
    101         uint32_t status;        /* cp0_status */
    102         uint32_t epc;           /* cp0_epc */
    103 
    104         uint32_t alignment;     /* to make sizeof(istate_t) a multiple of 8 */
    105 } istate_t;
    106 
    107 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    108     uintptr_t retaddr)
    109 {
    110         istate->epc = retaddr;
    111 }
    112 
    113 /** Return true if exception happened while in userspace */
    114 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    115 {
    116         return istate->status & cp0_status_um_bit;
    117 }
    118 
    119 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    120 {
    121         return istate->epc;
    122 }
    123 
    124 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    125 {
    126         return istate->sp;
    127 }
    128 
    12960extern void exception(istate_t *istate);
    13061extern void tlb_refill_entry(void);
  • kernel/arch/sparc64/include/interrupt.h

    ra63ff7d r60898b6  
    3838
    3939#include <typedefs.h>
    40 #include <arch/regdef.h>
    41 #include <trace.h>
     40#include <arch/istate.h>
    4241
    4342#define IVT_ITEMS  15
     
    5150};
    5251
    53 typedef struct istate {
    54         uint64_t tnpc;
    55         uint64_t tpc;
    56         uint64_t tstate;
    57 } istate_t;
    58 
    59 NO_TRACE static inline void istate_set_retaddr(istate_t *istate,
    60     uintptr_t retaddr)
    61 {
    62         istate->tpc = retaddr;
    63 }
    64 
    65 NO_TRACE static inline int istate_from_uspace(istate_t *istate)
    66 {
    67         return !(istate->tstate & TSTATE_PRIV_BIT);
    68 }
    69 
    70 NO_TRACE static inline unative_t istate_get_pc(istate_t *istate)
    71 {
    72         return istate->tpc;
    73 }
    74 
    75 NO_TRACE static inline unative_t istate_get_fp(istate_t *istate)
    76 {
    77         /* TODO */
    78        
    79         return 0;
    80 }
    81 
    8252#endif
    8353
  • kernel/generic/src/ipc/kbox.c

    ra63ff7d r60898b6  
    107107                /* Terminate debugging session (if any). */
    108108                LOG("Terminate debugging session.");
    109                 irq_spinlock_lock(&TASK->lock, true);
     109                mutex_lock(&TASK->udebug.lock);
    110110                udebug_task_cleanup(TASK);
    111                 irq_spinlock_unlock(&TASK->lock, true);
     111                mutex_unlock(&TASK->udebug.lock);
    112112        } else {
    113113                LOG("Was not debugger.");
  • kernel/tools/amd64/decpt.py

    ra63ff7d r60898b6  
    77def main():
    88    if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
    9         print "%s 0x..." % sys.argv[0]
     9        print("%s 0x..." % sys.argv[0])
    1010        sys.exit(1)
    1111   
     
    1616    ptl1 = (address >> 30) & 0x1ff
    1717    ptl0 = (address >> 39) & 0x1ff
    18     print "Ptl0:   %3d" % ptl0
    19     print "Ptl1:   %3d" % ptl1
    20     print "Ptl2:   %3d" % ptl2
    21     print "Ptl3:   %3d" % ptl3
    22     print "Offset: 0x%x" % offset
     18    print("Ptl0:   %3d" % ptl0)
     19    print("Ptl1:   %3d" % ptl1)
     20    print("Ptl2:   %3d" % ptl2)
     21    print("Ptl3:   %3d" % ptl3)
     22    print("Offset: 0x%x" % offset)
    2323
    2424if __name__ == '__main__':
  • kernel/tools/genmap.py

    ra63ff7d r60898b6  
    8686        obdump = read_obdump(obmapf)
    8787       
    88         def sorter(x,y):
    89                 return cmp(x[0],y[0])
     88        def key_sorter(x):
     89                return x[0]
    9090       
    9191        for line in kmapf:
     
    9393                res = startfile.match(line)
    9494               
    95                 if ((res) and (obdump[res.group(1)].has_key(res.group(3)))):
     95                if ((res) and (res.group(3) in obdump[res.group(1)])):
    9696                        offset = int(res.group(2), 16)
    9797                        fname = res.group(3)
    9898                        symbols = obdump[res.group(1)][fname]
    99                         symbols.sort(sorter)
     99                        symbols.sort(key = key_sorter)
    100100                        for addr, symbol in symbols:
    101101                                value = fname + ':' + symbol
     
    107107def main():
    108108        if (len(sys.argv) != 4):
    109                 print "Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0]
     109                print("Usage: %s <kernel.map> <nm dump> <output.bin>" % sys.argv[0])
    110110                return 1
    111111       
    112112        kmapf = open(sys.argv[1], 'r')
    113113        obmapf = open(sys.argv[2], 'r')
    114         out = open(sys.argv[3], 'w')
     114        out = open(sys.argv[3], 'wb')
    115115       
    116116        generate(kmapf, obmapf, out)
  • kernel/tools/ia32/decpt.py

    ra63ff7d r60898b6  
    77def main():
    88    if len(sys.argv) != 2 or not sys.argv[1].startswith('0x'):
    9         print "%s 0x..." % sys.argv[0]
     9        print("%s 0x..." % sys.argv[0])
    1010        sys.exit(1)
    1111   
     
    1414    ptl1 = (address >> 12) & 0x3ff
    1515    ptl0 = (address >> 22) & 0x3ff
    16     print "Ptl0:   %3d" % ptl0
    17     print "Ptl1:   %3d" % ptl1
    18     print "Offset: 0x%x" % offset
     16    print("Ptl0:   %3d" % ptl0)
     17    print("Ptl1:   %3d" % ptl1)
     18    print("Offset: 0x%x" % offset)
    1919
    2020if __name__ == '__main__':
  • tools/autotool.py

    ra63ff7d r60898b6  
    7575        "Read HelenOS build configuration"
    7676       
    77         inf = file(fname, 'r')
     77        inf = open(fname, 'r')
    7878       
    7979        for line in inf:
     
    191191        check_common(common, "CC")
    192192       
    193         outf = file(PROBE_SOURCE, 'w')
     193        outf = open(PROBE_SOURCE, 'w')
    194194        outf.write(PROBE_HEAD)
    195195       
     
    212212        if (not os.path.isfile(PROBE_OUTPUT)):
    213213                sys.stderr.write("failed\n")
    214                 print output[1]
     214                print(output[1])
    215215                print_error(["Error executing \"%s\"." % " ".join(args),
    216216                             "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
     
    221221        sys.stderr.write("ok\n")
    222222       
    223         inf = file(PROBE_OUTPUT, 'r')
     223        inf = open(PROBE_OUTPUT, 'r')
    224224        lines = inf.readlines()
    225225        inf.close()
     
    343343        "Create makefile output"
    344344       
    345         outmk = file(mkname, 'w')
     345        outmk = open(mkname, 'w')
    346346       
    347347        outmk.write('#########################################\n')
     
    357357        "Create header output"
    358358       
    359         outhd = file(hdname, 'w')
     359        outhd = open(hdname, 'w')
    360360       
    361361        outhd.write('/***************************************\n')
  • tools/checkers/clang.py

    ra63ff7d r60898b6  
    4242def usage(prname):
    4343        "Print usage syntax"
    44         print prname + " <ROOT>"
     44        print(prname + " <ROOT>")
    4545
    4646def clang(root, job):
     
    5050       
    5151        if (not os.path.isfile(inname)):
    52                 print "Unable to open %s" % inname
    53                 print "Did you run \"make precheck\" on the source tree?"
     52                print("Unable to open %s" % inname)
     53                print("Did you run \"make precheck\" on the source tree?")
    5454                return False
    5555       
    56         inf = file(inname, "r")
     56        inf = open(inname, "r")
    5757        records = inf.read().splitlines()
    5858        inf.close()
     
    6464               
    6565                if (len(arg) < 6):
    66                         print "Not enought jobfile record arguments"
     66                        print("Not enough jobfile record arguments")
    6767                        return False
    6868               
     
    7676                srcfqname = os.path.join(base, srcfname)
    7777                if (not os.path.isfile(srcfqname)):
    78                         print "Source %s not found" % srcfqname
     78                        print("Source %s not found" % srcfqname)
    7979                        return False
    8080               
     
    108108       
    109109        if (not os.path.isfile(config)):
    110                 print "%s not found." % config
    111                 print "Please specify the path to HelenOS build tree root as the first argument."
     110                print("%s not found." % config)
     111                print("Please specify the path to HelenOS build tree root as the first argument.")
    112112                return
    113113       
     
    115115                if (not clang(rootdir, job)):
    116116                        print
    117                         print "Failed job: %s" % job
     117                        print("Failed job: %s" % job)
    118118                        return
    119119       
    120120        print
    121         print "All jobs passed"
     121        print("All jobs passed")
    122122
    123123if __name__ == '__main__':
  • tools/checkers/jobfile.py

    ra63ff7d r60898b6  
    5454                                nil = True
    5555                        else:
    56                                 print "Unexpected '%s'" % record[i]
     56                                print("Unexpected '%s'" % record[i])
    5757                                return False
    5858               
  • tools/checkers/stanse.py

    ra63ff7d r60898b6  
    4343def usage(prname):
    4444        "Print usage syntax"
    45         print prname + " <ROOT>"
     45        print(prname + " <ROOT>")
    4646
    4747def stanse(root, job):
     
    5454       
    5555        if (not os.path.isfile(inname)):
    56                 print "Unable to open %s" % inname
    57                 print "Did you run \"make precheck\" on the source tree?"
     56                print("Unable to open %s" % inname)
     57                print("Did you run \"make precheck\" on the source tree?")
    5858                return False
    5959       
    60         inf = file(inname, "r")
     60        inf = open(inname, "r")
    6161        records = inf.read().splitlines()
    6262        inf.close()
     
    6969               
    7070                if (len(arg) < 6):
    71                         print "Not enought jobfile record arguments"
     71                        print("Not enough jobfile record arguments")
    7272                        return False
    7373               
     
    8181                srcfqname = os.path.join(base, srcfname)
    8282                if (not os.path.isfile(srcfqname)):
    83                         print "Source %s not found" % srcfqname
     83                        print("Source %s not found" % srcfqname)
    8484                        return False
    8585               
     
    9090                output.append([srcfname, tgtfname, base, options])
    9191       
    92         outf = file(outname, "w")
     92        outf = open(outname, "w")
    9393        for record in output:
    9494                outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
     
    121121       
    122122        if (not os.path.isfile(config)):
    123                 print "%s not found." % config
    124                 print "Please specify the path to HelenOS build tree root as the first argument."
     123                print("%s not found." % config)
     124                print("Please specify the path to HelenOS build tree root as the first argument.")
    125125                return
    126126       
     
    128128                if (not stanse(rootdir, job)):
    129129                        print
    130                         print "Failed job: %s" % job
     130                        print("Failed job: %s" % job)
    131131                        return
    132132       
    133133        print
    134         print "All jobs passed"
     134        print("All jobs passed")
    135135
    136136if __name__ == '__main__':
  • tools/checkers/vcc.py

    ra63ff7d r60898b6  
    4949def usage(prname):
    5050        "Print usage syntax"
    51         print prname + " <ROOT> [VCC_PATH]"
     51        print(prname + " <ROOT> [VCC_PATH]")
    5252
    5353def cygpath(upath):
     
    7272        preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
    7373       
    74         tmpf = file(tmpfname, "w")
     74        tmpf = open(tmpfname, "w")
    7575        tmpf.write(specification)
    7676       
     
    108108       
    109109        if (not os.path.isfile(inname)):
    110                 print "Unable to open %s" % inname
    111                 print "Did you run \"make precheck\" on the source tree?"
     110                print("Unable to open %s" % inname)
     111                print("Did you run \"make precheck\" on the source tree?")
    112112                return False
    113113       
    114         inf = file(inname, "r")
     114        inf = open(inname, "r")
    115115        records = inf.read().splitlines()
    116116        inf.close()
     
    122122               
    123123                if (len(arg) < 6):
    124                         print "Not enought jobfile record arguments"
     124                        print("Not enough jobfile record arguments")
    125125                        return False
    126126               
     
    134134                srcfqname = os.path.join(base, srcfname)
    135135                if (not os.path.isfile(srcfqname)):
    136                         print "Source %s not found" % srcfqname
     136                        print("Source %s not found" % srcfqname)
    137137                        return False
    138138               
     
    153153               
    154154                # Run Vcc
    155                 print " -- %s --" % srcfname           
     155                print(" -- %s --" % srcfname)
    156156                retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
    157157               
     
    182182       
    183183        if (not os.path.isfile(vcc_path)):
    184                 print "%s is not a binary." % vcc_path
    185                 print "Please supply the full Cygwin path to Vcc as the second argument."
     184                print("%s is not a binary." % vcc_path)
     185                print("Please supply the full Cygwin path to Vcc as the second argument.")
    186186                return
    187187       
     
    189189       
    190190        if (not os.path.isfile(config)):
    191                 print "%s not found." % config
    192                 print "Please specify the path to HelenOS build tree root as the first argument."
     191                print("%s not found." % config)
     192                print("Please specify the path to HelenOS build tree root as the first argument.")
    193193                return
    194194       
    195195        specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
    196196        if (not os.path.isfile(specpath)):
    197                 print "%s not found." % config
     197                print("%s not found." % config)
    198198                return
    199199       
     
    205205                if (not vcc(vcc_path, rootdir, job)):
    206206                        print
    207                         print "Failed job: %s" % job
     207                        print("Failed job: %s" % job)
    208208                        return
    209209       
    210210        print
    211         print "All jobs passed"
     211        print("All jobs passed")
    212212
    213213if __name__ == '__main__':
  • tools/config.py

    ra63ff7d r60898b6  
    4848        "Read saved values from last configuration run"
    4949       
    50         inf = file(fname, 'r')
     50        inf = open(fname, 'r')
    5151       
    5252        for line in inf:
     
    103103                condval = res.group(3)
    104104               
    105                 if (not defaults.has_key(condname)):
     105                if (not condname in defaults):
    106106                        varval = ''
    107107                else:
     
    131131        "Parse configuration file"
    132132       
    133         inf = file(fname, 'r')
     133        inf = open(fname, 'r')
    134134       
    135135        name = ''
     
    219219                        continue
    220220               
    221                 if (not defaults.has_key(varname)):
     221                if (not varname in defaults):
    222222                        return False
    223223       
     
    232232       
    233233        try:
    234                 version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].split(':')
     234                version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].decode().split(':')
    235235                sys.stderr.write("ok\n")
    236236        except:
     
    246246                revision = None
    247247       
    248         outmk = file(mkname, 'w')
    249         outmc = file(mcname, 'w')
     248        outmk = open(mkname, 'w')
     249        outmc = open(mcname, 'w')
    250250       
    251251        outmk.write('#########################################\n')
     
    263263                        continue
    264264               
    265                 if (not defaults.has_key(varname)):
     265                if (not varname in defaults):
    266266                        default = ''
    267267                else:
     
    368368                        # Cancel out all defaults which have to be deduced
    369369                        for varname, vartype, name, choices, cond in ask_names:
    370                                 if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')):
     370                                if ((vartype == 'y') and (varname in defaults) and (defaults[varname] == '*')):
    371371                                        defaults[varname] = None
    372372                       
     
    385385                                        position = cnt
    386386                               
    387                                 if (not defaults.has_key(varname)):
     387                                if (not varname in defaults):
    388388                                        default = None
    389389                                else:
     
    428428                                cnt += 1
    429429                       
    430                         if (position >= options):
     430                        if (position != None) and (position >= len(options)):
    431431                                position = None
    432432                       
     
    449449                       
    450450                        position = None
    451                         if (not opt2row.has_key(value)):
     451                        if (not value in opt2row):
    452452                                raise RuntimeError("Error selecting value: %s" % value)
    453453                       
    454454                        (selname, seltype, name, choices) = opt2row[value]
    455455                       
    456                         if (not defaults.has_key(selname)):
     456                        if (not selname in defaults):
    457457                                        default = None
    458458                        else:
  • tools/jobfile.py

    ra63ff7d r60898b6  
    3838def usage(prname):
    3939        "Print usage syntax"
    40         print prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]"
     40        print(prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]")
    4141
    4242def main():
     
    5353        options = " ".join(sys.argv[6:])
    5454       
    55         jobfile = file(jobfname, "a")
     55        jobfile = open(jobfname, "a")
    5656        fcntl.lockf(jobfile, fcntl.LOCK_EX)
    5757        jobfile.write("{%s},{%s},{%s},{%s},{%s},{%s}\n" % (srcfname, tgtfname, toolname, category, cwd, options))
  • tools/mkfat.py

    ra63ff7d r60898b6  
    4646                return size
    4747       
    48         return (((size / alignment) + 1) * alignment)
     48        return ((size // alignment) + 1) * alignment
    4949
    5050def subtree_size(root, cluster_size, dirent_size):
     
    7979        first = 0
    8080       
    81         inf = file(path, "r")
     81        inf = open(path, "rb")
    8282        rd = 0;
    8383        while (rd < size):
     
    9292                prev = empty_cluster
    9393               
    94                 data = inf.read(cluster_size);
     94                data = bytes(inf.read(cluster_size));
    9595                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    9696                outf.write(data)
     
    120120                prev = empty_cluster
    121121               
    122                 data = ''
     122                data = bytes()
    123123                data_len = 0
    124124                while ((i < length) and (data_len < cluster_size)):
     
    343343def usage(prname):
    344344        "Print usage syntax"
    345         print prname + " <EXTRA_BYTES> <PATH> <IMAGE>"
     345        print(prname + " <EXTRA_BYTES> <PATH> <IMAGE>")
    346346
    347347def main():
     
    351351       
    352352        if (not sys.argv[1].isdigit()):
    353                 print "<EXTRA_BYTES> must be a number"
     353                print("<EXTRA_BYTES> must be a number")
    354354                return
    355355       
     
    358358        path = os.path.abspath(sys.argv[2])
    359359        if (not os.path.isdir(path)):
    360                 print "<PATH> must be a directory"
     360                print("<PATH> must be a directory")
    361361                return
    362362       
     
    370370        reserved_clusters = 2
    371371       
    372         # Make sure the filesystem is large enought for FAT16
     372        # Make sure the filesystem is large enough for FAT16
    373373        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
    374         while (size / cluster_size < fat16_clusters):
     374        while (size // cluster_size < fat16_clusters):
    375375                if (cluster_size > sector_size):
    376                         cluster_size /= 2
     376                        cluster_size = cluster_size // 2
    377377                        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
    378378                else:
     
    381381        root_size = align_up(root_entries(path) * dirent_size, cluster_size)
    382382       
    383         fat_size = align_up(align_up(size, cluster_size) / cluster_size * fatent_size, sector_size)
    384        
    385         sectors = (cluster_size + fat_count * fat_size + root_size + size) / sector_size
     383        fat_size = align_up(align_up(size, cluster_size) // cluster_size * fatent_size, sector_size)
     384       
     385        sectors = (cluster_size + fat_count * fat_size + root_size + size) // sector_size
    386386        root_start = cluster_size + fat_count * fat_size
    387387        data_start = root_start + root_size
    388388       
    389         outf = file(sys.argv[3], "w")
     389        outf = open(sys.argv[3], "wb")
    390390       
    391391        boot_sector = xstruct.create(BOOT_SECTOR)
    392392        boot_sector.jmp = [0xEB, 0x3C, 0x90]
    393         boot_sector.oem = "MSDOS5.0"
     393        boot_sector.oem = b'MSDOS5.0'
    394394        boot_sector.sector = sector_size
    395         boot_sector.cluster = cluster_size / sector_size
    396         boot_sector.reserved = cluster_size / sector_size
     395        boot_sector.cluster = cluster_size // sector_size
     396        boot_sector.reserved = cluster_size // sector_size
    397397        boot_sector.fats = fat_count
    398         boot_sector.rootdir = root_size / dirent_size
     398        boot_sector.rootdir = root_size // dirent_size
    399399        if (sectors <= 65535):
    400400                boot_sector.sectors = sectors
     
    402402                boot_sector.sectors = 0
    403403        boot_sector.descriptor = 0xF8
    404         boot_sector.fat_sectors = fat_size / sector_size
     404        boot_sector.fat_sectors = fat_size // sector_size
    405405        boot_sector.track_sectors = 63
    406406        boot_sector.heads = 6
     
    414414        boot_sector.extboot_signature = 0x29
    415415        boot_sector.serial = random.randint(0, 0x7fffffff)
    416         boot_sector.label = "HELENOS"
    417         boot_sector.fstype = "FAT16   "
     416        boot_sector.label = b'HELENOS'
     417        boot_sector.fstype = b'FAT16   '
    418418        boot_sector.boot_signature = [0x55, 0xAA]
    419419       
     
    423423       
    424424        # Reserved sectors
    425         for i in range(1, cluster_size / sector_size):
     425        for i in range(1, cluster_size // sector_size):
    426426                outf.write(empty_sector.pack())
    427427       
    428428        # FAT tables
    429429        for i in range(0, fat_count):
    430                 for j in range(0, fat_size / sector_size):
     430                for j in range(0, fat_size // sector_size):
    431431                        outf.write(empty_sector.pack())
    432432       
    433433        # Root directory
    434         for i in range(0, root_size / sector_size):
     434        for i in range(0, root_size // sector_size):
    435435                outf.write(empty_sector.pack())
    436436       
    437437        # Data
    438         for i in range(0, size / sector_size):
     438        for i in range(0, size // sector_size):
    439439                outf.write(empty_sector.pack())
    440440       
    441         fat = array.array('L', [0] * (fat_size / fatent_size))
     441        fat = array.array('L', [0] * (fat_size // fatent_size))
    442442        fat[0] = 0xfff8
    443443        fat[1] = 0xffff
     
    449449        for i in range(0, fat_count):
    450450                outf.seek(cluster_size + i * fat_size)
    451                 for j in range(0, fat_size / fatent_size):
     451                for j in range(0, fat_size // fatent_size):
    452452                        fat_entry.next = fat[j]
    453453                        outf.write(fat_entry.pack())
  • tools/mkhord.py

    ra63ff7d r60898b6  
    5252def usage(prname):
    5353        "Print usage syntax"
    54         print prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>"
     54        print(prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>")
    5555
    5656def main():
     
    6060       
    6161        if (not sys.argv[1].isdigit()):
    62                 print "<ALIGNMENT> must be a number"
     62                print("<ALIGNMENT> must be a number")
    6363                return
    6464       
    6565        align = int(sys.argv[1], 0)
    6666        if (align <= 0):
    67                 print "<ALIGNMENT> must be positive"
     67                print("<ALIGNMENT> must be positive")
    6868                return
    6969       
    7070        fs_image = os.path.abspath(sys.argv[2])
    7171        if (not os.path.isfile(fs_image)):
    72                 print "<FS_IMAGE> must be a file"
     72                print("<FS_IMAGE> must be a file")
    7373                return
    7474       
    75         inf = file(fs_image, "rb")
    76         outf = file(sys.argv[3], "wb")
     75        inf = open(fs_image, "rb")
     76        outf = open(sys.argv[3], "wb")
    7777       
    7878        header = xstruct.create(HEADER)
  • tools/mktmpfs.py

    ra63ff7d r60898b6  
    6666def usage(prname):
    6767        "Print usage syntax"
    68         print prname + " <PATH> <IMAGE>"
     68        print(prname + " <PATH> <IMAGE>")
    6969
    7070def recursion(root, outf):
     
    8585                        outf.write(dentry.pack())
    8686                       
    87                         inf = file(canon, "r")
     87                        inf = open(canon, "rb")
    8888                        rd = 0;
    8989                        while (rd < size):
     
    116116        path = os.path.abspath(sys.argv[1])
    117117        if (not os.path.isdir(path)):
    118                 print "<PATH> must be a directory"
     118                print("<PATH> must be a directory")
    119119                return
    120120       
    121         outf = file(sys.argv[2], "w")
     121        outf = open(sys.argv[2], "wb")
    122122       
    123123        header = xstruct.create(HEADER)
  • tools/mkuimage.py

    ra63ff7d r60898b6  
    7272                        start_addr = (int)(optarg, 0)
    7373                else:
    74                         print base_name + ": Unrecognized option."
     74                        print(base_name + ": Unrecognized option.")
    7575                        print_syntax(cmd_name)
    7676                        return
    7777
    7878        if len(args) < 2:
    79                 print base_name + ": Argument missing."
     79                print(base_name + ": Argument missing.")
    8080                print_syntax(cmd_name)
    8181                return
     
    9191
    9292def mkuimage(inf_name, outf_name, image_name, load_addr, start_addr):
    93         inf = file(inf_name, 'rb')
    94         outf = file(outf_name, 'wb')
     93        inf = open(inf_name, 'rb')
     94        outf = open(outf_name, 'wb')
    9595
    9696        header = xstruct.create(UIMAGE_HEADER)
     
    140140        signed_crc = zlib.crc32(byteseq, 0)
    141141        if signed_crc < 0:
    142                 return (long(signed_crc) + 4294967296L) # 2^32L
     142                return (long(signed_crc) + (long(2) ** long(32))) # 2^32L
    143143        else:
    144144                return signed_crc
     
    147147#
    148148def print_syntax(cmd):
    149         print "syntax: " + cmd + " [<options>] <raw_image> <uImage>"
     149        print("syntax: " + cmd + " [<options>] <raw_image> <uImage>")
    150150        print
    151         print "\traw_image\tInput image name (raw binary data)"
    152         print "\tuImage\t\tOutput uImage name (U-Boot image)"
     151        print("\traw_image\tInput image name (raw binary data)")
     152        print("\tuImage\t\tOutput uImage name (U-Boot image)")
    153153        print
    154         print "options:"
    155         print "\t-name <name>\tImage name (default: 'Noname')"
    156         print "\t-laddr <name>\tLoad address (default: 0x00000000)"
    157         print "\t-saddr <name>\tStart address (default: 0x00000000)"
     154        print("options:")
     155        print("\t-name <name>\tImage name (default: 'Noname')")
     156        print("\t-laddr <name>\tLoad address (default: 0x00000000)")
     157        print("\t-saddr <name>\tStart address (default: 0x00000000)")
    158158
    159159if __name__ == '__main__':
  • tools/pack.py

    ra63ff7d r60898b6  
    4343def usage(prname):
    4444        "Print usage syntax"
    45         print "%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname
     45        print("%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname)
    4646
    4747def deflate(data):
     
    110110                symbol = "_binary_%s" % basename.replace(".", "_")
    111111               
    112                 print "%s -> %s" % (component, obj)
     112                print("%s -> %s" % (component, obj))
    113113               
    114                 comp_in = file(component, "rb")
    115                 comp_data = comp_in.read();
     114                comp_in = open(component, "rb")
     115                comp_data = comp_in.read()
    116116                comp_in.close()
    117117               
     
    121121               
    122122                try:
    123                         comp_out = file(basename, "wb")
     123                        comp_out = open(basename, "wb")
    124124                        comp_out.write(comp_deflate)
    125125                        comp_out.close()
     
    151151                cnt += 1
    152152       
    153         header = file(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
     153        header = open(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
    154154       
    155155        header.write('/***************************************\n')
     
    173173        header.close()
    174174       
    175         data = file(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
     175        data = open(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
    176176       
    177177        data.write('/***************************************\n')
     
    187187        data.close()
    188188       
    189         link_in = file(os.path.join(arch_path, "%s.in" % LINK), "r")
     189        link_in = open(os.path.join(arch_path, "%s.in" % LINK), "r")
    190190        template = link_in.read()
    191191        link_in.close()
    192192       
    193         link_out = file(os.path.join(arch_path, "%s.comp" % LINK), "w")
     193        link_out = open(os.path.join(arch_path, "%s.comp" % LINK), "w")
    194194        link_out.write(template.replace("[[COMPONENTS]]", "\n".join(link_ctx)))
    195195        link_out.close()
  • uspace/drv/ns8250/ns8250.c

    ra63ff7d r60898b6  
    123123static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
    124124{
    125         if (NULL != data)
     125        if (data != NULL)
    126126                free(data);
    127127}
     
    251251static void ns8250_dev_cleanup(device_t *dev)
    252252{
    253         if (NULL != dev->driver_data) {
     253        if (dev->driver_data != NULL) {
    254254                delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data);
    255255                dev->driver_data = NULL;
     
    332332        /* Allocate driver data for the device. */
    333333        ns8250_dev_data_t *data = create_ns8250_dev_data();
    334         if (NULL == data)
     334        if (data == NULL)
    335335                return ENOMEM;
    336336        dev->driver_data = data;
     
    436436        /* Enable interrupt globally. */
    437437        res = interrupt_enable(data->irq);
    438         if (EOK != res)
     438        if (res != EOK)
    439439                return res;
    440440       
     
    480480        uint8_t div_low, div_high;
    481481       
    482         if (50 > baud_rate || 0 != MAX_BAUD_RATE % baud_rate) {
     482        if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
    483483                printf(NAME ": error - somebody tried to set invalid baud rate "
    484484                    "%d\n", baud_rate);
     
    534534 * @param stop_bits     The number of stop bits used (one or two).
    535535 */
    536 static void
    537 ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
     536static void ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
    538537    unsigned int *word_length, unsigned int *stop_bits)
    539538{
     
    572571 *                      is invalid.
    573572 */
    574 static int
    575 ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
     573static int ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
    576574    unsigned int word_length, unsigned int stop_bits)
    577575{
     
    691689 * @param dev           The serial port device.
    692690 */
    693 static inline void
    694 ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
     691static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid,
     692    ipc_call_t *icall)
    695693{
    696694        ns8250_read_from_device(dev);
     
    726724 * @param dev           The serial port device.
    727725 */
    728 static int ns8250_add_device(device_t *dev) 
     726static int ns8250_add_device(device_t *dev)
    729727{
    730728        printf(NAME ": ns8250_add_device %s (handle = %d)\n",
     
    732730       
    733731        int res = ns8250_dev_initialize(dev);
    734         if (EOK != res)
     732        if (res != EOK)
    735733                return res;
    736734       
     
    750748       
    751749        /* Register interrupt handler. */
    752         if (EOK != ns8250_register_interrupt_handler(dev)) {
     750        if (ns8250_register_interrupt_handler(dev) != EOK) {
    753751                printf(NAME ": failed to register interrupt handler.\n");
    754752                ns8250_dev_cleanup(dev);
     
    758756        /* Enable interrupt. */
    759757        res = ns8250_interrupt_enable(dev);
    760         if (EOK != res) {
     758        if (res != EOK) {
    761759                printf(NAME ": failed to enable the interrupt. Error code = "
    762760                    "%d.\n", res);
     
    859857 * @param stop_bits     The number of stop bits to be used.
    860858 */
    861 static int
    862 ns8250_set_props(device_t *dev, unsigned int baud_rate, unsigned int parity,
    863     unsigned int word_length, unsigned int stop_bits)
     859static int ns8250_set_props(device_t *dev, unsigned int baud_rate,
     860    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
    864861{
    865862        printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
     
    874871        ns8250_port_interrupts_disable(port);
    875872        ret = ns8250_port_set_baud_rate(port, baud_rate);
    876         if (EOK == ret)
     873        if (ret == EOK)
    877874                ret = ns8250_port_set_com_props(port, parity, word_length, stop_bits);
    878875        ns8250_port_interrupts_enable(port);
     
    887884 * Configure the parameters of the serial communication.
    888885 */
    889 static void
    890 ns8250_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
     886static void ns8250_default_handler(device_t *dev, ipc_callid_t callid,
     887    ipc_call_t *call)
    891888{
    892889        ipcarg_t method = IPC_GET_METHOD(*call);
  • uspace/drv/pciintel/pci.c

    ra63ff7d r60898b6  
    6565        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    6666       
    67         if (NULL == dev_data)
     67        if (dev_data == NULL)
    6868                return NULL;
    6969        return &dev_data->hw_resources;
     
    109109       
    110110        bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
    111         if (NULL != bus_data) {
     111        if (bus_data != NULL) {
    112112                memset(bus_data, 0, sizeof(pci_bus_data_t));
    113113                fibril_mutex_initialize(&bus_data->conf_mutex);
    114114        }
     115
    115116        return bus_data;
    116117}
     
    123124static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
    124125{
    125         assert(NULL != dev->parent);
     126        assert(dev->parent != NULL);
    126127       
    127128        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    153154static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
    154155{
    155         assert(NULL != dev->parent);
     156        assert(dev->parent != NULL);
    156157       
    157158        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     
    224225       
    225226        match_id = create_match_id();
    226         if (NULL != match_id) {
     227        if (match_id != NULL) {
    227228                asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
    228229                    dev_data->vendor_id, dev_data->device_id);
     
    230231                match_id->score = 90;
    231232                add_match_id(&dev->match_ids, match_id);
    232         }       
     233        }
     234
    233235        /* TODO add more ids (with subsys ids, using class id etc.) */
    234236}
     
    242244        size_t count = hw_res_list->count;
    243245       
    244         assert(NULL != hw_resources);
     246        assert(hw_resources != NULL);
    245247        assert(count < PCI_MAX_HW_RES);
    246248       
     
    275277        bool io;
    276278        /* 64-bit wide address */
    277         bool w64;
     279        bool addrw64;
    278280       
    279281        /* Size of the io or memory range specified by the BAR */
     
    287289        io = (bool) (val & 1);
    288290        if (io) {
    289                 w64 = false;
     291                addrw64 = false;
    290292        } else {
    291293                switch ((val >> 1) & 3) {
    292294                case 0:
    293                         w64 = false;
     295                        addrw64 = false;
    294296                        break;
    295297                case 2:
    296                         w64 = true;
     298                        addrw64 = true;
    297299                        break;
    298300                default:
     
    312314        range_size = pci_bar_mask_to_size(mask);
    313315       
    314         if (w64) {
     316        if (addrw64) {
    315317                range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
    316318                    (val & 0xfffffff0);
     
    319321        }
    320322       
    321         if (0 != range_addr) {
     323        if (range_addr != 0) {
    322324                printf(NAME ": device %s : ", dev->name);
    323325                printf("address = %x", range_addr);
     
    327329        pci_add_range(dev, range_addr, range_size, io);
    328330       
    329         if (w64)
     331        if (addrw64)
    330332                return addr + 8;
    331333       
     
    354356{
    355357        uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
    356         if (0xff != irq)
     358        if (irq != 0xff)
    357359                pci_add_interrupt(dev, irq);
    358360}
     
    415417                        create_pci_match_ids(dev);
    416418                       
    417                         if (EOK != child_device_register(dev, parent)) {
     419                        if (child_device_register(dev, parent) != EOK) {
    418420                                pci_clean_resource_list(dev);
    419421                                clean_match_ids(&dev->match_ids);
     
    424426                       
    425427                        if (header_type == PCI_HEADER_TYPE_BRIDGE ||
    426                             header_type == PCI_HEADER_TYPE_CARDBUS ) {
     428                            header_type == PCI_HEADER_TYPE_CARDBUS) {
    427429                                child_bus = pci_conf_read_8(dev,
    428430                                    PCI_BRIDGE_SEC_BUS_NUM);
    429431                                printf(NAME ": device is pci-to-pci bridge, "
    430432                                    "secondary bus number = %d.\n", bus_num);
    431                                 if(child_bus > bus_num)
     433                                if (child_bus > bus_num)
    432434                                        pci_bus_scan(parent, child_bus);
    433435                        }
     
    453455       
    454456        pci_bus_data_t *bus_data = create_pci_bus_data();
    455         if (NULL == bus_data) {
     457        if (bus_data == NULL) {
    456458                printf(NAME ": pci_add_device allocation failed.\n");
    457459                return ENOMEM;
     
    513515}
    514516
     517pci_dev_data_t *create_pci_dev_data(void)
     518{
     519        pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
     520       
     521        if (res != NULL)
     522                memset(res, 0, sizeof(pci_dev_data_t));
     523        return res;
     524}
     525
     526void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
     527{
     528        dev_data->bus = bus;
     529        dev_data->dev = dev;
     530        dev_data->fn = fn;
     531}
     532
     533void delete_pci_dev_data(pci_dev_data_t *dev_data)
     534{
     535        if (dev_data != NULL) {
     536                clean_hw_resource_list(&dev_data->hw_resources);
     537                free(dev_data);
     538        }
     539}
     540
     541void create_pci_dev_name(device_t *dev)
     542{
     543        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     544        char *name = NULL;
     545       
     546        asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
     547            dev_data->fn);
     548        dev->name = name;
     549}
     550
     551bool pci_alloc_resource_list(device_t *dev)
     552{
     553        pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
     554       
     555        dev_data->hw_resources.resources =
     556            (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
     557        return dev_data->hw_resources.resources != NULL;
     558}
     559
     560void pci_clean_resource_list(device_t *dev)
     561{
     562        pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
     563       
     564        if (dev_data->hw_resources.resources != NULL) {
     565                free(dev_data->hw_resources.resources);
     566                dev_data->hw_resources.resources = NULL;
     567        }
     568}
     569
     570/** Read the base address registers (BARs) of the device and adds the addresses
     571 * to its hw resource list.
     572 *
     573 * @param dev the pci device.
     574 */
     575void pci_read_bars(device_t *dev)
     576{
     577        /*
     578         * Position of the BAR in the PCI configuration address space of the
     579         * device.
     580         */
     581        int addr = PCI_BASE_ADDR_0;
     582       
     583        while (addr <= PCI_BASE_ADDR_5)
     584                addr = pci_read_bar(dev, addr);
     585}
     586
     587size_t pci_bar_mask_to_size(uint32_t mask)
     588{
     589        return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     590}
     591
    515592int main(int argc, char *argv[])
    516593{
  • uspace/drv/pciintel/pci.h

    ra63ff7d r60898b6  
    6969extern void pci_bus_scan(device_t *, int);
    7070
    71 static inline pci_dev_data_t *create_pci_dev_data(void)
    72 {
    73         pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
    74        
    75         if (NULL != res)
    76                 memset(res, 0, sizeof(pci_dev_data_t));
    77         return res;
    78 }
     71extern pci_dev_data_t *create_pci_dev_data(void);
     72extern void init_pci_dev_data(pci_dev_data_t *, int, int, int);
     73extern void delete_pci_dev_data(pci_dev_data_t *);
     74extern void create_pci_dev_name(device_t *);
    7975
    80 static inline void
    81 init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn)
    82 {
    83         d->bus = bus;
    84         d->dev = dev;
    85         d->fn = fn;
    86 }
     76extern bool pci_alloc_resource_list(device_t *);
     77extern void pci_clean_resource_list(device_t *);
    8778
    88 static inline void delete_pci_dev_data(pci_dev_data_t *d)
    89 {
    90         if (NULL != d) {
    91                 clean_hw_resource_list(&d->hw_resources);
    92                 free(d);
    93         }
    94 }
    95 
    96 static inline void create_pci_dev_name(device_t *dev)
    97 {
    98         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    99         char *name = NULL;
    100        
    101         asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
    102             dev_data->fn);
    103         dev->name = name;
    104 }
    105 
    106 static inline bool pci_alloc_resource_list(device_t *dev)
    107 {
    108         pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
    109        
    110         dev_data->hw_resources.resources =
    111             (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
    112         return dev_data->hw_resources.resources != NULL;
    113 }
    114 
    115 static inline void pci_clean_resource_list(device_t *dev)
    116 {
    117         pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
    118        
    119         if (NULL != dev_data->hw_resources.resources) {
    120                 free(dev_data->hw_resources.resources);
    121                 dev_data->hw_resources.resources = NULL;
    122         }
    123 }
    124 
    125 /** Read the base address registers (BARs) of the device and adds the addresses
    126  * to its hw resource list.
    127  *
    128  * @param dev the pci device.
    129  */
    130 static inline  void pci_read_bars(device_t *dev)
    131 {
    132         /*
    133          * Position of the BAR in the PCI configuration address space of the
    134          * device.
    135          */
    136         int addr = PCI_BASE_ADDR_0;
    137        
    138         while (addr <= PCI_BASE_ADDR_5)
    139                 addr = pci_read_bar(dev, addr);
    140 }
    141 
    142 static inline size_t pci_bar_mask_to_size(uint32_t mask)
    143 {
    144         return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
    145 }
     79extern void pci_read_bars(device_t *);
     80extern size_t pci_bar_mask_to_size(uint32_t);
    14681
    14782#endif
  • uspace/lib/c/arch/abs32le/include/fibril.h

    ra63ff7d r60898b6  
    4444                (ctx)->pc = (uintptr_t) (_pc); \
    4545                (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
     46                (ctx)->fp = 0; \
    4647                (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
    4748        } while (0)
     
    5354typedef struct {
    5455        uintptr_t sp;
     56        uintptr_t fp;
    5557        uintptr_t pc;
    5658        uintptr_t tls;
    5759} context_t;
     60
     61static inline uintptr_t context_get_fp(context_t *ctx)
     62{
     63        /* On real hardware, this function returns the frame pointer. */
     64        return ctx->fp;
     65}
    5866
    5967#endif
  • uspace/lib/c/arch/abs32le/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_abs32le__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * On real hardware this stores the registers which
    43  * need to be preserved during interupts.
    44  */
    45 typedef struct istate {
    46         uintptr_t ip;
    47         uintptr_t fp;
    48         uint32_t stack[];
    49 } istate_t;
    50 
    51 static inline uintptr_t istate_get_pc(istate_t *istate)
    52 {
    53         return istate->ip;
    54 }
    55 
    56 static inline uintptr_t istate_get_fp(istate_t *istate)
    57 {
    58         return istate->fp;
    59 }
     38#include <arch/istate.h>
    6039
    6140#endif
  • uspace/lib/c/arch/amd64/include/fibril.h

    ra63ff7d r60898b6  
    5656 */
    5757typedef struct {
    58     uint64_t sp;
    59     uint64_t pc;
    60    
    61     uint64_t rbx;
    62     uint64_t rbp;
     58        uint64_t sp;
     59        uint64_t pc;
    6360
    64     uint64_t r12;
    65     uint64_t r13;
    66     uint64_t r14;
    67     uint64_t r15;
     61        uint64_t rbx;
     62        uint64_t rbp;
    6863
    69     uint64_t tls;
     64        uint64_t r12;
     65        uint64_t r13;
     66        uint64_t r14;
     67        uint64_t r15;
     68
     69        uint64_t tls;
    7070} context_t;
     71
     72static inline uintptr_t context_get_fp(context_t *ctx)
     73{
     74        return ctx->rbp;
     75}
    7176
    7277#endif
  • uspace/lib/c/arch/amd64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_amd64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint64_t rax;
    46         uint64_t rcx;
    47         uint64_t rdx;
    48         uint64_t rsi;
    49         uint64_t rdi;
    50         uint64_t r8;
    51         uint64_t r9;
    52         uint64_t r10;
    53         uint64_t r11;
    54         uint64_t rbp;
    55         uint64_t error_word;
    56         uint64_t rip;
    57         uint64_t cs;
    58         uint64_t rflags;
    59         uint64_t stack[]; /* Additional data on stack */
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->rip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->rbp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/amd64/src/entry.s

    ra63ff7d r60898b6  
    4242        #
    4343        pushq $0
    44         mov %rsp, %rbp
     44        movq %rsp, %rbp
    4545       
    4646        # %rdi was deliberately chosen as the first argument is also in %rdi
  • uspace/lib/c/arch/amd64/src/fibril.S

    ra63ff7d r60898b6  
    4949        movq %rax, OFFSET_TLS(%rdi)
    5050               
    51         xorq %rax,%rax          # context_save returns 1
    52         incq %rax
     51        xorl %eax, %eax         # context_save returns 1
     52        incl %eax
    5353        ret
    5454
     
    6767        # Set thread local storage
    6868        movq OFFSET_TLS(%rdi), %rdi   # Set arg1 to TLS addr
    69         movq $1, %rax           # SYS_TLS_SET
     69        movl $1, %eax           # SYS_TLS_SET
    7070        syscall
    7171
    72         xorq %rax,%rax          # context_restore returns 0
     72        xorl %eax, %eax         # context_restore returns 0
    7373        ret
  • uspace/lib/c/arch/arm32/include/fibril.h

    ra63ff7d r60898b6  
    8686} context_t;
    8787
     88static inline uintptr_t context_get_fp(context_t *ctx)
     89{
     90        return ctx->fp;
     91}
     92
    8893
    8994#endif
  • uspace/lib/c/arch/arm32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_arm32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t spsr;
    46         uint32_t sp;
    47         uint32_t lr;
    48 
    49         uint32_t r0;
    50         uint32_t r1;
    51         uint32_t r2;
    52         uint32_t r3;
    53         uint32_t r4;
    54         uint32_t r5;
    55         uint32_t r6;
    56         uint32_t r7;
    57         uint32_t r8;
    58         uint32_t r9;
    59         uint32_t r10;
    60         uint32_t fp;
    61         uint32_t r12;
    62 
    63         uint32_t pc;
    64 } istate_t;
    65 
    66 static inline uintptr_t istate_get_pc(istate_t *istate)
    67 {
    68         return istate->pc;
    69 }
    70 
    71 static inline uintptr_t istate_get_fp(istate_t *istate)
    72 {
    73         return istate->fp;
    74 }
     38#include <arch/istate.h>
    7539
    7640#endif
  • uspace/lib/c/arch/ia32/include/fibril.h

    ra63ff7d r60898b6  
    6767} context_t;
    6868
     69static inline uintptr_t context_get_fp(context_t *ctx)
     70{
     71        return ctx->ebp;
     72}
     73
    6974#endif
    7075
  • uspace/lib/c/arch/ia32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_ia32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t eax;
    46         uint32_t ecx;
    47         uint32_t edx;
    48         uint32_t ebp;
    49 
    50         uint32_t gs;
    51         uint32_t fs;
    52         uint32_t es;
    53         uint32_t ds;
    54 
    55         uint32_t error_word;
    56         uint32_t eip;
    57         uint32_t cs;
    58         uint32_t eflags;
    59         uint32_t stack[];
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->eip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->ebp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/ia64/include/fibril.h

    ra63ff7d r60898b6  
    130130} context_t;
    131131
     132static inline uintptr_t context_get_fp(context_t *ctx)
     133{
     134        return 0;       /* FIXME */
     135}
     136
    132137#endif
    133138
  • uspace/lib/c/arch/ia64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_ia64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/arch/mips32/include/fibril.h

    ra63ff7d r60898b6  
    8585} context_t;
    8686
     87static inline uintptr_t context_get_fp(context_t *ctx)
     88{
     89        return ctx->sp;
     90}
     91
    8792#endif
    8893
  • uspace/lib/c/arch/mips32/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_mips32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t at;
    46         uint32_t v0;
    47         uint32_t v1;
    48         uint32_t a0;
    49         uint32_t a1;
    50         uint32_t a2;
    51         uint32_t a3;
    52         uint32_t t0;
    53         uint32_t t1;
    54         uint32_t t2;
    55         uint32_t t3;
    56         uint32_t t4;
    57         uint32_t t5;
    58         uint32_t t6;
    59         uint32_t t7;
    60         uint32_t t8;
    61         uint32_t t9;
    62         uint32_t gp;
    63         uint32_t sp;
    64         uint32_t ra;
    65 
    66         uint32_t lo;
    67         uint32_t hi;
    68 
    69         uint32_t status; /* cp0_status */
    70         uint32_t epc; /* cp0_epc */
    71         uint32_t k1; /* We use it as thread-local pointer */
    72 } istate_t;
    73 
    74 static inline uintptr_t istate_get_pc(istate_t *istate)
    75 {
    76         return istate->epc;
    77 }
    78 
    79 static inline uintptr_t istate_get_fp(istate_t *istate)
    80 {
    81         /* TODO */
    82         return 0;
    83 }
     38#include <arch/istate.h>
    8439
    8540#endif
  • uspace/lib/c/arch/ppc32/include/fibril.h

    ra63ff7d r60898b6  
    7878} __attribute__ ((packed)) context_t;
    7979
     80static inline uintptr_t context_get_fp(context_t *ctx)
     81{
     82        return ctx->sp;
     83}
     84
    8085#endif
    8186
  • uspace/lib/c/arch/sparc64/include/fibril.h

    ra63ff7d r60898b6  
    7777} context_t;
    7878
     79static inline uintptr_t context_get_fp(context_t *ctx)
     80{
     81        return ctx->sp + STACK_BIAS;
     82}
     83
    7984#endif
    8085
  • uspace/lib/c/arch/sparc64/include/istate.h

    ra63ff7d r60898b6  
    3636#define LIBC_sparc64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/generic/fibril.c

    ra63ff7d r60898b6  
    275275        fibril->func = func;
    276276        fibril->arg = arg;
     277
     278        fibril->waits_for = NULL;
    277279       
    278280        context_save(&fibril->ctx);
  • uspace/lib/c/generic/fibril_synch.c

    ra63ff7d r60898b6  
    4242#include <errno.h>
    4343#include <assert.h>
     44#include <stacktrace.h>
     45#include <stdlib.h>
    4446
    4547static void optimize_execution_power(void)
     
    5658}
    5759
     60static void print_deadlock(fibril_owner_info_t *oi)
     61{
     62        fibril_t *f = (fibril_t *) fibril_get_id();
     63
     64        printf("Deadlock detected.\n");
     65        stacktrace_print();
     66
     67        printf("Fibril %p waits for primitive %p.\n", f, oi);
     68
     69        while (oi && oi->owned_by) {
     70                printf("Primitive %p is owned by fibril %p.\n",
     71                    oi, oi->owned_by);
     72                if (oi->owned_by == f)
     73                        break;
     74                stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),
     75                    oi->owned_by->ctx.pc);
     76                printf("Fibril %p waits for primitive %p.\n",
     77                     oi->owned_by, oi->owned_by->waits_for);
     78                oi = oi->owned_by->waits_for;
     79        }
     80}
     81
     82
     83static void check_for_deadlock(fibril_owner_info_t *oi)
     84{
     85        while (oi && oi->owned_by) {
     86                if (oi->owned_by == (fibril_t *) fibril_get_id()) {
     87                        print_deadlock(oi);
     88                        abort();
     89                }
     90                oi = oi->owned_by->waits_for;
     91        }
     92}
     93
     94
    5895void fibril_mutex_initialize(fibril_mutex_t *fm)
    5996{
     97        fm->oi.owned_by = NULL;
    6098        fm->counter = 1;
    6199        list_initialize(&fm->waiters);
     
    64102void fibril_mutex_lock(fibril_mutex_t *fm)
    65103{
     104        fibril_t *f = (fibril_t *) fibril_get_id();
     105
    66106        futex_down(&async_futex);
    67107        if (fm->counter-- <= 0) {
     
    73113                link_initialize(&wdata.wu_event.link);
    74114                list_append(&wdata.wu_event.link, &fm->waiters);
     115                check_for_deadlock(&fm->oi);
     116                f->waits_for = &fm->oi;
    75117                fibril_switch(FIBRIL_TO_MANAGER);
    76118        } else {
     119                fm->oi.owned_by = f;
    77120                futex_up(&async_futex);
    78121        }
     
    86129        if (fm->counter > 0) {
    87130                fm->counter--;
     131                fm->oi.owned_by = (fibril_t *) fibril_get_id();
    88132                locked = true;
    89133        }
     
    99143                link_t *tmp;
    100144                awaiter_t *wdp;
     145                fibril_t *f;
    101146       
    102147                assert(!list_empty(&fm->waiters));
     
    105150                wdp->active = true;
    106151                wdp->wu_event.inlist = false;
     152
     153                f = (fibril_t *) wdp->fid;
     154                fm->oi.owned_by = f;
     155                f->waits_for = NULL;
     156
    107157                list_remove(&wdp->wu_event.link);
    108158                fibril_add_ready(wdp->fid);
    109159                optimize_execution_power();
     160        } else {
     161                fm->oi.owned_by = NULL;
    110162        }
    111163}
     
    120172void fibril_rwlock_initialize(fibril_rwlock_t *frw)
    121173{
     174        frw->oi.owned_by = NULL;
    122175        frw->writers = 0;
    123176        frw->readers = 0;
     
    138191                f->flags &= ~FIBRIL_WRITER;
    139192                list_append(&wdata.wu_event.link, &frw->waiters);
     193                check_for_deadlock(&frw->oi);
     194                f->waits_for = &frw->oi;
    140195                fibril_switch(FIBRIL_TO_MANAGER);
    141196        } else {
     
    147202void fibril_rwlock_write_lock(fibril_rwlock_t *frw)
    148203{
     204        fibril_t *f = (fibril_t *) fibril_get_id();
     205       
    149206        futex_down(&async_futex);
    150207        if (frw->writers || frw->readers) {
    151                 fibril_t *f = (fibril_t *) fibril_get_id();
    152208                awaiter_t wdata;
    153209
     
    158214                f->flags |= FIBRIL_WRITER;
    159215                list_append(&wdata.wu_event.link, &frw->waiters);
     216                check_for_deadlock(&frw->oi);
     217                f->waits_for = &frw->oi;
    160218                fibril_switch(FIBRIL_TO_MANAGER);
    161219        } else {
     220                frw->oi.owned_by = f;
    162221                frw->writers++;
    163222                futex_up(&async_futex);
     
    177236       
    178237        assert(!frw->readers && !frw->writers);
     238       
     239        frw->oi.owned_by = NULL;
    179240       
    180241        while (!list_empty(&frw->waiters)) {
     
    185246                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    186247                f = (fibril_t *) wdp->fid;
     248               
     249                f->waits_for = NULL;
    187250               
    188251                if (f->flags & FIBRIL_WRITER) {
     
    194257                        fibril_add_ready(wdp->fid);
    195258                        frw->writers++;
     259                        frw->oi.owned_by = f;
    196260                        optimize_execution_power();
    197261                        break;
  • uspace/lib/c/include/fibril.h

    ra63ff7d r60898b6  
    4848#define FIBRIL_WRITER      2
    4949
     50struct fibril;
     51
     52typedef struct {
     53        struct fibril *owned_by;
     54} fibril_owner_info_t;
     55
    5056typedef enum {
    5157        FIBRIL_PREEMPT,
     
    6874        int retval;
    6975        int flags;
     76
     77        fibril_owner_info_t *waits_for;
    7078} fibril_t;
    7179
  • uspace/lib/c/include/fibril_synch.h

    ra63ff7d r60898b6  
    4343
    4444typedef struct {
     45        fibril_owner_info_t oi;         /* Keep this the first thing. */
    4546        int counter;
    4647        link_t waiters;
     
    4950#define FIBRIL_MUTEX_INITIALIZER(name) \
    5051        { \
     52                .oi = { \
     53                        .owned_by = NULL \
     54                }, \
    5155                .counter = 1, \
    5256                .waiters = { \
     
    6064
    6165typedef struct {
     66        fibril_owner_info_t oi; /* Keep this the first thing. */
    6267        unsigned writers;
    6368        unsigned readers;
     
    6772#define FIBRIL_RWLOCK_INITIALIZER(name) \
    6873        { \
     74                .oi = { \
     75                        .owned_by = NULL \
     76                }, \
    6977                .readers = 0, \
    7078                .writers = 0, \
  • uspace/srv/devman/devman.c

    ra63ff7d r60898b6  
    7676        .remove_callback = devices_remove_callback
    7777};
     78
     79/**
     80 * Initialize the list of device driver's.
     81 *
     82 * @param drv_list the list of device driver's.
     83 *
     84 */
     85void init_driver_list(driver_list_t *drv_list)
     86{
     87        assert(drv_list != NULL);
     88       
     89        list_initialize(&drv_list->drivers);
     90        fibril_mutex_initialize(&drv_list->drivers_mutex);
     91}
    7892
    7993/** Allocate and initialize a new driver structure.
     
    548562}
    549563
     564/** Initialize device driver structure.
     565 *
     566 * @param drv           The device driver structure.
     567 */
     568void init_driver(driver_t *drv)
     569{
     570        assert(drv != NULL);
     571
     572        memset(drv, 0, sizeof(driver_t));
     573        list_initialize(&drv->match_ids.ids);
     574        list_initialize(&drv->devices);
     575        fibril_mutex_initialize(&drv->driver_mutex);
     576}
     577
     578/** Device driver structure clean-up.
     579 *
     580 * @param drv           The device driver structure.
     581 */
     582void clean_driver(driver_t *drv)
     583{
     584        assert(drv != NULL);
     585
     586        free_not_null(drv->name);
     587        free_not_null(drv->binary_path);
     588
     589        clean_match_ids(&drv->match_ids);
     590
     591        init_driver(drv);
     592}
     593
     594/** Delete device driver structure.
     595 *
     596 * @param drv           The device driver structure.
     597 */
     598void delete_driver(driver_t *drv)
     599{
     600        assert(drv != NULL);
     601       
     602        clean_driver(drv);
     603        free(drv);
     604}
    550605
    551606/** Create devmap path and name for the device. */
     
    685740}
    686741
     742/* Device nodes */
     743
     744/** Create a new device node.
     745 *
     746 * @return              A device node structure.
     747 */
     748node_t *create_dev_node(void)
     749{
     750        node_t *res = malloc(sizeof(node_t));
     751       
     752        if (res != NULL) {
     753                memset(res, 0, sizeof(node_t));
     754                list_initialize(&res->children);
     755                list_initialize(&res->match_ids.ids);
     756                list_initialize(&res->classes);
     757        }
     758       
     759        return res;
     760}
     761
     762/** Delete a device node.
     763 *
     764 * @param node          The device node structure.
     765 */
     766void delete_dev_node(node_t *node)
     767{
     768        assert(list_empty(&node->children));
     769        assert(node->parent == NULL);
     770        assert(node->drv == NULL);
     771       
     772        clean_match_ids(&node->match_ids);
     773        free_not_null(node->name);
     774        free_not_null(node->pathname);
     775        free(node);
     776}
     777
     778/** Find the device node structure of the device witch has the specified handle.
     779 *
     780 * Device tree's rwlock should be held at least for reading.
     781 *
     782 * @param tree          The device tree where we look for the device node.
     783 * @param handle        The handle of the device.
     784 * @return              The device node.
     785 */
     786node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     787{
     788        unsigned long key = handle;
     789        link_t *link = hash_table_find(&tree->devman_devices, &key);
     790        return hash_table_get_instance(link, node_t, devman_link);
     791}
     792
     793/** Find the device node structure of the device witch has the specified handle.
     794 *
     795 * @param tree          The device tree where we look for the device node.
     796 * @param handle        The handle of the device.
     797 * @return              The device node.
     798 */
     799node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
     800{
     801        node_t *node = NULL;
     802       
     803        fibril_rwlock_read_lock(&tree->rwlock);
     804        node = find_dev_node_no_lock(tree, handle);
     805        fibril_rwlock_read_unlock(&tree->rwlock);
     806       
     807        return node;
     808}
     809
     810
    687811/** Create and set device's full path in device tree.
    688812 *
     
    825949        return NULL;
    826950}
     951
     952/* Device classes */
     953
     954/** Create device class.
     955 *
     956 * @return      Device class.
     957 */
     958dev_class_t *create_dev_class(void)
     959{
     960        dev_class_t *cl;
     961       
     962        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
     963        if (cl != NULL) {
     964                memset(cl, 0, sizeof(dev_class_t));
     965                list_initialize(&cl->devices);
     966                fibril_mutex_initialize(&cl->mutex);
     967        }
     968       
     969        return cl;
     970}
     971
     972/** Create device class info.
     973 *
     974 * @return              Device class info.
     975 */
     976dev_class_info_t *create_dev_class_info(void)
     977{
     978        dev_class_info_t *info;
     979       
     980        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
     981        if (info != NULL)
     982                memset(info, 0, sizeof(dev_class_info_t));
     983       
     984        return info;
     985}
     986
     987size_t get_new_class_dev_idx(dev_class_t *cl)
     988{
     989        size_t dev_idx;
     990       
     991        fibril_mutex_lock(&cl->mutex);
     992        dev_idx = ++cl->curr_dev_idx;
     993        fibril_mutex_unlock(&cl->mutex);
     994       
     995        return dev_idx;
     996}
     997
    827998
    828999/** Create unique device name within the class.
     
    9211092}
    9221093
     1094void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     1095{
     1096        list_append(&cl->link, &class_list->classes);
     1097}
     1098
    9231099void init_class_list(class_list_t *class_list)
    9241100{
     
    9301106
    9311107
    932 /* devmap devices */
     1108/* Devmap devices */
    9331109
    9341110node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
     
    9671143}
    9681144
     1145void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1146{
     1147        unsigned long key = (unsigned long) cli->devmap_handle;
     1148       
     1149        fibril_rwlock_write_lock(&class_list->rwlock);
     1150        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1151        fibril_rwlock_write_unlock(&class_list->rwlock);
     1152}
     1153
     1154void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     1155{
     1156        unsigned long key = (unsigned long) node->devmap_handle;
     1157        fibril_rwlock_write_lock(&tree->rwlock);
     1158        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1159        fibril_rwlock_write_unlock(&tree->rwlock);
     1160}
     1161
    9691162/** @}
    9701163 */
  • uspace/srv/devman/devman.h

    ra63ff7d r60898b6  
    283283/* Drivers */
    284284
    285 /**
    286  * Initialize the list of device driver's.
    287  *
    288  * @param drv_list the list of device driver's.
    289  *
    290  */
    291 static inline void init_driver_list(driver_list_t *drv_list)
    292 {
    293         assert(drv_list != NULL);
    294        
    295         list_initialize(&drv_list->drivers);
    296         fibril_mutex_initialize(&drv_list->drivers_mutex);
    297 }
    298 
     285extern void init_driver_list(driver_list_t *);
    299286extern driver_t *create_driver(void);
    300287extern bool get_driver_info(const char *, const char *, driver_t *);
     
    311298extern driver_t *find_driver(driver_list_t *, const char *);
    312299extern void set_driver_phone(driver_t *, ipcarg_t);
    313 void initialize_running_driver(driver_t *, dev_tree_t *);
    314 
    315 /** Initialize device driver structure.
    316  *
    317  * @param drv           The device driver structure.
    318  */
    319 static inline void init_driver(driver_t *drv)
    320 {
    321         assert(drv != NULL);
    322 
    323         memset(drv, 0, sizeof(driver_t));
    324         list_initialize(&drv->match_ids.ids);
    325         list_initialize(&drv->devices);
    326         fibril_mutex_initialize(&drv->driver_mutex);
    327 }
    328 
    329 /** Device driver structure clean-up.
    330  *
    331  * @param drv           The device driver structure.
    332  */
    333 static inline void clean_driver(driver_t *drv)
    334 {
    335         assert(drv != NULL);
    336 
    337         free_not_null(drv->name);
    338         free_not_null(drv->binary_path);
    339 
    340         clean_match_ids(&drv->match_ids);
    341 
    342         init_driver(drv);
    343 }
    344 
    345 /** Delete device driver structure.
    346  *
    347  * @param drv           The device driver structure.
    348  */
    349 static inline void delete_driver(driver_t *drv)
    350 {
    351         assert(drv != NULL);
    352        
    353         clean_driver(drv);
    354         free(drv);
    355 }
    356 
     300extern void initialize_running_driver(driver_t *, dev_tree_t *);
     301
     302extern void init_driver(driver_t *);
     303extern void clean_driver(driver_t *);
     304extern void delete_driver(driver_t *);
    357305
    358306/* Device nodes */
    359307
    360 /** Create a new device node.
    361  *
    362  * @return              A device node structure.
    363  */
    364 static inline node_t *create_dev_node(void)
    365 {
    366         node_t *res = malloc(sizeof(node_t));
    367        
    368         if (res != NULL) {
    369                 memset(res, 0, sizeof(node_t));
    370                 list_initialize(&res->children);
    371                 list_initialize(&res->match_ids.ids);
    372                 list_initialize(&res->classes);
    373         }
    374        
    375         return res;
    376 }
    377 
    378 /** Delete a device node.
    379  *
    380  * @param node          The device node structure.
    381  */
    382 static inline void delete_dev_node(node_t *node)
    383 {
    384         assert(list_empty(&node->children));
    385         assert(node->parent == NULL);
    386         assert(node->drv == NULL);
    387        
    388         clean_match_ids(&node->match_ids);
    389         free_not_null(node->name);
    390         free_not_null(node->pathname);
    391         free(node);
    392 }
    393 
    394 /** Find the device node structure of the device witch has the specified handle.
    395  *
    396  * Device tree's rwlock should be held at least for reading.
    397  *
    398  * @param tree          The device tree where we look for the device node.
    399  * @param handle        The handle of the device.
    400  * @return              The device node.
    401  */
    402 static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
    403     device_handle_t handle)
    404 {
    405         unsigned long key = handle;
    406         link_t *link = hash_table_find(&tree->devman_devices, &key);
    407         return hash_table_get_instance(link, node_t, devman_link);
    408 }
    409 
    410 /** Find the device node structure of the device witch has the specified handle.
    411  *
    412  * @param tree          The device tree where we look for the device node.
    413  * @param handle        The handle of the device.
    414  * @return              The device node.
    415  */
    416 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
    417 {
    418         node_t *node = NULL;
    419        
    420         fibril_rwlock_read_lock(&tree->rwlock);
    421         node = find_dev_node_no_lock(tree, handle);
    422         fibril_rwlock_read_unlock(&tree->rwlock);
    423        
    424         return node;
    425 }
    426 
     308extern node_t *create_dev_node(void);
     309extern void delete_dev_node(node_t *node);
     310extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
     311    device_handle_t handle);
     312extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle);
    427313extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
    428314extern node_t *find_node_child(node_t *, const char *);
    429 
    430315
    431316/* Device tree */
     
    435320extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
    436321
    437 
    438322/* Device classes */
    439323
    440 /** Create device class.
    441  *
    442  * @return      Device class.
    443  */
    444 static inline dev_class_t *create_dev_class(void)
    445 {
    446         dev_class_t *cl;
    447        
    448         cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    449         if (cl != NULL) {
    450                 memset(cl, 0, sizeof(dev_class_t));
    451                 list_initialize(&cl->devices);
    452                 fibril_mutex_initialize(&cl->mutex);
    453         }
    454        
    455         return cl;
    456 }
    457 
    458 /** Create device class info.
    459  *
    460  * @return              Device class info.
    461  */
    462 static inline dev_class_info_t *create_dev_class_info(void)
    463 {
    464         dev_class_info_t *info;
    465        
    466         info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    467         if (info != NULL)
    468                 memset(info, 0, sizeof(dev_class_info_t));
    469        
    470         return info;
    471 }
    472 
    473 static inline size_t get_new_class_dev_idx(dev_class_t *cl)
    474 {
    475         size_t dev_idx;
    476        
    477         fibril_mutex_lock(&cl->mutex);
    478         dev_idx = ++cl->curr_dev_idx;
    479         fibril_mutex_unlock(&cl->mutex);
    480        
    481         return dev_idx;
    482 }
    483 
     324extern dev_class_t *create_dev_class(void);
     325extern dev_class_info_t *create_dev_class_info(void);
     326extern size_t get_new_class_dev_idx(dev_class_t *);
    484327extern char *create_dev_name_for_class(dev_class_t *, const char *);
    485328extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
     
    490333extern dev_class_t *get_dev_class(class_list_t *, char *);
    491334extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
    492 
    493 static inline void add_dev_class_no_lock(class_list_t *class_list,
    494     dev_class_t *cl)
    495 {
    496         list_append(&cl->link, &class_list->classes);
    497 }
    498 
     335extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    499336
    500337/* Devmap devices */
     
    503340extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
    504341
    505 static inline void class_add_devmap_device(class_list_t *class_list,
    506     dev_class_info_t *cli)
    507 {
    508         unsigned long key = (unsigned long) cli->devmap_handle;
    509        
    510         fibril_rwlock_write_lock(&class_list->rwlock);
    511         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
    512         fibril_rwlock_write_unlock(&class_list->rwlock);
    513 }
    514 
    515 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    516 {
    517         unsigned long key = (unsigned long) node->devmap_handle;
    518         fibril_rwlock_write_lock(&tree->rwlock);
    519         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
    520         fibril_rwlock_write_unlock(&tree->rwlock);
    521 }
     342extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
     343extern void tree_add_devmap_device(dev_tree_t *, node_t *);
    522344
    523345#endif
  • uspace/srv/devman/main.c

    ra63ff7d r60898b6  
    6666static driver_t *devman_driver_register(void)
    6767{
     68        ipc_call_t icall;
     69        ipc_callid_t iid;
     70        driver_t *driver = NULL;
     71
    6872        printf(NAME ": devman_driver_register \n");
    6973       
    70         ipc_call_t icall;
    71         ipc_callid_t iid = async_get_call(&icall);
    72         driver_t *driver = NULL;
    73        
     74        iid = async_get_call(&icall);
    7475        if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    7576                ipc_answer_0(iid, EREFUSED);
     
    8586                return NULL;
    8687        }
     88
    8789        printf(NAME ": the %s driver is trying to register by the service.\n",
    8890            drv_name);
     
    9193        driver = find_driver(&drivers_list, drv_name);
    9294       
    93         if (NULL == driver) {
     95        if (driver == NULL) {
    9496                printf(NAME ": no driver named %s was found.\n", drv_name);
    9597                free(drv_name);
     
    146148        }
    147149       
    148         if (NULL == match_id) {
     150        if (match_id == NULL) {
    149151                printf(NAME ": ERROR: devman_receive_match_id - failed to "
    150152                    "allocate match id.\n");
     
    160162        rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
    161163        match_id->id = match_id_str;
    162         if (EOK != rc) {
     164        if (rc != EOK) {
    163165                delete_match_id(match_id);
    164166                printf(NAME ": devman_receive_match_id - failed to receive "
     
    181183 * @return              Zero on success, negative error code otherwise.
    182184 */
    183 static int
    184 devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
     185static int devman_receive_match_ids(ipcarg_t match_count,
     186    match_id_list_t *match_ids)
    185187{
    186188        int ret = EOK;
     
    205207       
    206208        fibril_rwlock_write_lock(&tree->rwlock);
    207         node_t *parent =  find_dev_node_no_lock(&device_tree, parent_handle);
    208        
    209         if (NULL == parent) {
     209        node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
     210       
     211        if (parent == NULL) {
    210212                fibril_rwlock_write_unlock(&tree->rwlock);
    211213                ipc_answer_0(callid, ENOENT);
    212214                return;
    213         }       
     215        }
    214216       
    215217        char *dev_name = NULL;
    216218        int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
    217         if (EOK != rc) {
     219        if (rc != EOK) {
    218220                fibril_rwlock_write_unlock(&tree->rwlock);
    219221                ipc_answer_0(callid, rc);
     
    227229                ipc_answer_0(callid, ENOMEM);
    228230                return;
    229         }       
     231        }
     232
    230233        fibril_rwlock_write_unlock(&tree->rwlock);
    231234       
     
    245248        /* Create devmap path and name for the device. */
    246249        char *devmap_pathname = NULL;
     250
    247251        asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    248252            cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    249         if (NULL == devmap_pathname)
     253        if (devmap_pathname == NULL)
    250254                return;
    251255       
     
    279283       
    280284        node_t *dev = find_dev_node(&device_tree, handle);
    281         if (NULL == dev) {
     285        if (dev == NULL) {
    282286                ipc_answer_0(callid, ENOENT);
    283287                return;
     
    318322       
    319323        driver_t *driver = devman_driver_register();
    320         if (NULL == driver)
     324        if (driver == NULL)
    321325                return;
    322326       
     
    373377        free(pathname);
    374378
    375         if (NULL == dev) {
     379        if (dev == NULL) {
    376380                ipc_answer_0(iid, ENOENT);
    377381                return;
     
    404408                                ipc_answer_0(callid, ENOENT);
    405409                }
    406         }       
    407 }
    408 
    409 static void
    410 devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
     410        }
     411}
     412
     413static void devman_forward(ipc_callid_t iid, ipc_call_t *icall,
     414    bool drv_to_parent)
    411415{
    412416        device_handle_t handle = IPC_GET_ARG2(*icall);
    413417       
    414418        node_t *dev = find_dev_node(&device_tree, handle);
    415         if (NULL == dev) {
     419        if (dev == NULL) {
    416420                printf(NAME ": devman_forward error - no device with handle %x "
    417421                    "was found.\n", handle);
     
    423427       
    424428        if (drv_to_parent) {
    425                 if (NULL != dev->parent)
     429                if (dev->parent != NULL)
    426430                        driver = dev->parent->drv;
    427         } else if (DEVICE_USABLE == dev->state) {
     431        } else if (dev->state == DEVICE_USABLE) {
    428432                driver = dev->drv;
    429                 assert(NULL != driver);
    430         }
    431        
    432         if (NULL == driver) {
     433                assert(driver != NULL);
     434        }
     435       
     436        if (driver == NULL) {
    433437                printf(NAME ": devman_forward error - the device is not in "
    434438                    "usable state.\n", handle);
     
    450454                return;
    451455        }
     456
    452457        printf(NAME ": devman_forward: forward connection to device %s to "
    453458            "driver %s.\n", dev->pathname, driver->name);
     
    460465{
    461466        dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
    462        
    463         node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
    464         if (NULL == dev)
     467        node_t *dev;
     468
     469        dev = find_devmap_tree_device(&device_tree, devmap_handle);
     470        if (dev == NULL)
    465471                dev = find_devmap_class_device(&class_list, devmap_handle);
    466472       
    467         if (NULL == dev || NULL == dev->drv) {
     473        if (dev == NULL || dev->drv == NULL) {
    468474                ipc_answer_0(iid, ENOENT);
    469475                return;
    470476        }
    471477       
    472         if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
     478        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    473479                ipc_answer_0(iid, EINVAL);
    474480                return;
     
    493499         * passes device handle to the driver as an ipc method.)
    494500         */
    495         if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))
     501        if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
    496502                devman_connection_devmapper(iid, icall);
    497503
     
    531537        /* Initialize list of available drivers. */
    532538        init_driver_list(&drivers_list);
    533         if (0 == lookup_available_drivers(&drivers_list,
    534             DRIVER_DEFAULT_STORE)) {
     539        if (lookup_available_drivers(&drivers_list,
     540            DRIVER_DEFAULT_STORE) == 0) {
    535541                printf(NAME " no drivers found.");
    536542                return false;
    537543        }
     544
    538545        printf(NAME ": devman_init  - list of drivers has been initialized.\n");
    539546
  • uspace/srv/devman/match.c

    ra63ff7d r60898b6  
    5555                match_id_t *tmp_ma_id;
    5656       
    57                 if (0 == str_cmp(drv_id->id, dev_id->id)) {
     57                if (str_cmp(drv_id->id, dev_id->id) == 0) {
    5858                        /*
    5959                         * We found a match.
     
    6767                 * list of match ids.
    6868                 */
    69                 if (drv_head != drv_link->next) {
     69                if (drv_link->next != drv_head) {
    7070                        tmp_ma_id = list_get_instance(drv_link->next,
    7171                            match_id_t, link);
     
    7979                 * list of match ids.
    8080                 */
    81                 if (dev_head != dev_link->next) {
     81                if (dev_link->next != dev_head) {
    8282                        tmp_ma_id = list_get_instance(dev_link->next,
    8383                            match_id_t, link);
     
    9999                }
    100100               
    101         } while (drv_head != drv_link->next && dev_head != dev_link->next);
     101        } while (drv_link->next != drv_head && dev_link->next != dev_head);
    102102       
    103103        return 0;
  • uspace/srv/devman/util.c

    ra63ff7d r60898b6  
    6161char *get_path_elem_end(char *path)
    6262{
    63         while (0 != *path && '/' != *path)
     63        while (*path != '\0' && *path != '/')
    6464                path++;
    6565        return path;
    6666}
    6767
     68bool skip_spaces(char **buf)
     69{
     70        while (isspace(**buf))
     71                (*buf)++;
     72        return *buf != 0;
     73}
     74
     75size_t get_nonspace_len(const char *str)
     76{
     77        size_t len = 0;
     78       
     79        while(*str != '\0' && !isspace(*str)) {
     80                len++;
     81                str++;
     82        }
     83
     84        return len;
     85}
     86
     87void free_not_null(const void *ptr)
     88{
     89        if (ptr != NULL)
     90                free(ptr);
     91}
     92
     93char *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
     104void replace_char(char *str, char orig, char repl)
     105{
     106        while (*str) {
     107                if (*str == orig)
     108                        *str = repl;
     109                str++;
     110        }
     111}
     112
    68113/** @}
    69114 */
  • uspace/srv/devman/util.h

    ra63ff7d r60898b6  
    4141extern char *get_path_elem_end(char *);
    4242
    43 static inline bool skip_spaces(char **buf)
    44 {
    45         while (isspace(**buf))
    46                 (*buf)++;
    47         return *buf != 0;
    48 }
    49 
    50 static inline size_t get_nonspace_len(const char *str)
    51 {
    52         size_t len = 0;
    53        
    54         while(*str != 0 && !isspace(*str)) {
    55                 len++;
    56                 str++;
    57         }
    58         return len;
    59 }
    60 
    61 static inline void free_not_null(const void *ptr)
    62 {
    63         if (NULL != ptr)
    64                 free(ptr);
    65 }
    66 
    67 static inline char *clone_string(const char *s)
    68 {
    69         size_t size = str_size(s) + 1;
    70         char *str;
    71        
    72         str = (char *) malloc(size);
    73         if (NULL != str)
    74                 str_cpy(str, size, s);
    75         return str;
    76 }
    77 
    78 static inline void replace_char(char *str, char orig, char repl)
    79 {
    80         while (*str) {
    81                 if (orig == *str)
    82                         *str = repl;
    83                 str++;
    84         }
    85 }
     43extern bool skip_spaces(char **);
     44extern size_t get_nonspace_len(const char *);
     45extern void free_not_null(const void *);
     46extern char *clone_string(const char *);
     47extern void replace_char(char *, char, char);
    8648
    8749#endif
Note: See TracChangeset for help on using the changeset viewer.