#!/bin/sh global in := $1 global out := $2 proc syscall_macro { global abi := $1 global nr := $2 global entry := $3 # Entry can be either just a function name or "function/qualifier" global real_entry := $(entry%%/*) global qualifier := $(entry:${#real_entry}) # Strip the function name global qualifier := $(qualifier:1) # Strip the slash, if any echo "__SYSCALL_$(abi)($nr, $real_entry, $qualifier)" } proc emit { global abi := $1 global nr := $2 global entry := $3 global compat := $4 if test $abi == "64" -a -n $compat { echo "a compat entry for a 64-bit syscall makes no sense" > !2 exit 1 } if test -z $compat { if test -n $entry { syscall_macro $abi $nr $entry } } else { echo "#ifdef CONFIG_X86_32" if test -n $entry { syscall_macro $abi $nr $entry } echo "#else" syscall_macro $abi $nr $compat echo "#endif" } } grep '^[0-9]' $in | sort -n | shell { while read nr abi name entry compat { global abi := $[echo $abi | tr '[a-z]' '[A-Z]] if test $abi == "COMMON" -o $abi == "64" { # COMMON is the same as 64, except that we don't expect X32 # programs to use it. Our expectation has nothing to do with # any generated code, so treat them the same. emit 64 $nr $entry $compat } elif test $abi == "X32" { # X32 is equivalent to 64 on an X32-compatible kernel. echo "#ifdef CONFIG_X86_X32_ABI" emit 64 $nr $entry $compat echo "#endif" } elif test $abi == "I386" { emit $abi $nr $entry $compat } else { echo "Unknown abi $abi" > !2 exit 1 } } } > "$out" (CommandList children: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:in) op:Equal rhs:{(DQ ($ VSub_Number "$1"))} spids:[4])] spids: [4] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:out) op:Equal rhs:{(DQ ($ VSub_Number "$2"))} spids:[9])] spids: [9] ) (FuncDef name: syscall_macro body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:abi) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [22] ) ] spids: [22] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nr) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [28] ) ] spids: [28] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:entry) op: Equal rhs: {(DQ ($ VSub_Number "$3"))} spids: [34] ) ] spids: [34] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:real_entry) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{(Lit_Slash /) ("*")}) spids: [47 52] ) ) } spids: [45] ) ] spids: [45] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:qualifier) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound spids: [61 64] ) } ) ) spids: [58 65] ) ) } spids: [56] ) ] spids: [56] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:qualifier) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (Slice begin:(ArithWord w:{(Lit_Digits 1)})) spids: [74 78] ) ) } spids: [72] ) ] spids: [72] ) (C {(echo)} { (DQ (__SYSCALL_) (${ VSub_Name abi) ("(") ($ VSub_Name "$nr") (", ") ($ VSub_Name "$real_entry") (", ") ($ VSub_Name "$qualifier") (")") ) } ) ] spids: [19] ) spids: [15 18] ) (FuncDef name: emit body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:abi) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [112] ) ] spids: [112] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:nr) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [118] ) ] spids: [118] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:entry) op: Equal rhs: {(DQ ($ VSub_Number "$3"))} spids: [124] ) ] spids: [124] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:compat) op: Equal rhs: {(DQ ($ VSub_Number "$4"))} spids: [130] ) ] spids: [130] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$abi"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (64))} {(-a)} {(-n)} {(DQ ($ VSub_Name "$compat"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("a compat entry for a 64-bit syscall makes no sense"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[172])] ) (C {(exit)} {(1)}) ] spids: [-1 163] ) ] spids: [-1 181] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$compat"))} {(Lit_Other "]")}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$entry"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(syscall_macro)} {(DQ ($ VSub_Name "$abi"))} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$entry"))} ) ] spids: [-1 214] ) ] spids: [-1 232] ) ] spids: [-1 198] ) ] else_action: [ (C {(echo)} {(DQ ("#ifdef CONFIG_X86_32"))}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$entry"))} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(syscall_macro)} {(DQ ($ VSub_Name "$abi"))} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$entry"))} ) ] spids: [-1 258] ) ] spids: [-1 276] ) (C {(echo)} {(DQ ("#else"))}) (C {(syscall_macro)} {(DQ ($ VSub_Name "$abi"))} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$compat"))} ) (C {(echo)} {(DQ ("#endif"))}) ] spids: [235 308] ) ] spids: [109] ) spids: [105 108] ) (Pipeline children: [ (C {(grep)} {(SQ <"^[0-9]">)} {(DQ ($ VSub_Name "$in"))}) (C {(sort)} {(-n)}) (Subshell child: (While cond: [ (Sentence child: (C {(read)} {(nr)} {(abi)} {(name)} {(entry)} {(compat)}) terminator: ) ] body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:abi) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$abi"))}) (C {(tr)} {(SQ <"[a-z]">)} {(SQ <"[A-Z]">)}) ] negated: False ) ] ) left_token: spids: [353 371] ) } spids: [352] ) ] spids: [352] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$abi"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (COMMON))} {(-o)} {(DQ ($ VSub_Name "$abi"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (64))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(emit)} {(64)} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$entry"))} {(DQ ($ VSub_Name "$compat"))} ) ] spids: [-1 405] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$abi"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (X32))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("#ifdef CONFIG_X86_X32_ABI"))}) (C {(emit)} {(64)} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$entry"))} {(DQ ($ VSub_Name "$compat"))} ) (C {(echo)} {(DQ ("#endif"))}) ] spids: [437 455] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$abi"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (I386))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(emit)} {(DQ ($ VSub_Name "$abi"))} {(DQ ($ VSub_Name "$nr"))} {(DQ ($ VSub_Name "$entry"))} {(DQ ($ VSub_Name "$compat"))} ) ] spids: [493 511] ) ] else_action: [ (SimpleCommand words: [{(echo)} {(DQ ("Unknown abi ") ($ VSub_Name "$abi"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[543])] ) (C {(exit)} {(1)}) ] spids: [533 552] ) ] spids: [349 555] ) ) redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$out"))} spids: [559] ) ] spids: [331 557] ) ] negated: False ) ] )