mksyscall_aix_ppc64.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. // Copyright 2019 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build ignore
  5. /*
  6. This program reads a file containing function prototypes
  7. (like syscall_aix.go) and generates system call bodies.
  8. The prototypes are marked by lines beginning with "//sys"
  9. and read like func declarations if //sys is replaced by func, but:
  10. * The parameter lists must give a name for each argument.
  11. This includes return parameters.
  12. * The parameter lists must give a type for each argument:
  13. the (x, y, z int) shorthand is not allowed.
  14. * If the return parameter is an error number, it must be named err.
  15. * If go func name needs to be different than its libc name,
  16. * or the function is not in libc, name could be specified
  17. * at the end, after "=" sign, like
  18. //sys getsockopt(s int, level int, name int, val uintptr, vallen *_Socklen) (err error) = libsocket.getsockopt
  19. This program will generate three files and handle both gc and gccgo implementation:
  20. - zsyscall_aix_ppc64.go: the common part of each implementation (error handler, pointer creation)
  21. - zsyscall_aix_ppc64_gc.go: gc part with //go_cgo_import_dynamic and a call to syscall6
  22. - zsyscall_aix_ppc64_gccgo.go: gccgo part with C function and conversion to C type.
  23. The generated code looks like this
  24. zsyscall_aix_ppc64.go
  25. func asyscall(...) (n int, err error) {
  26. // Pointer Creation
  27. r1, e1 := callasyscall(...)
  28. // Type Conversion
  29. // Error Handler
  30. return
  31. }
  32. zsyscall_aix_ppc64_gc.go
  33. //go:cgo_import_dynamic libc_asyscall asyscall "libc.a/shr_64.o"
  34. //go:linkname libc_asyscall libc_asyscall
  35. var asyscall syscallFunc
  36. func callasyscall(...) (r1 uintptr, e1 Errno) {
  37. r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_asyscall)), "nb_args", ... )
  38. return
  39. }
  40. zsyscall_aix_ppc64_ggcgo.go
  41. // int asyscall(...)
  42. import "C"
  43. func callasyscall(...) (r1 uintptr, e1 Errno) {
  44. r1 = uintptr(C.asyscall(...))
  45. e1 = syscall.GetErrno()
  46. return
  47. }
  48. */
  49. package main
  50. import (
  51. "bufio"
  52. "flag"
  53. "fmt"
  54. "io/ioutil"
  55. "os"
  56. "regexp"
  57. "strings"
  58. )
  59. var (
  60. b32 = flag.Bool("b32", false, "32bit big-endian")
  61. l32 = flag.Bool("l32", false, "32bit little-endian")
  62. aix = flag.Bool("aix", false, "aix")
  63. tags = flag.String("tags", "", "build tags")
  64. )
  65. // cmdLine returns this programs's commandline arguments
  66. func cmdLine() string {
  67. return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ")
  68. }
  69. // buildTags returns build tags
  70. func buildTags() string {
  71. return *tags
  72. }
  73. // Param is function parameter
  74. type Param struct {
  75. Name string
  76. Type string
  77. }
  78. // usage prints the program usage
  79. func usage() {
  80. fmt.Fprintf(os.Stderr, "usage: go run mksyscall_aix_ppc64.go [-b32 | -l32] [-tags x,y] [file ...]\n")
  81. os.Exit(1)
  82. }
  83. // parseParamList parses parameter list and returns a slice of parameters
  84. func parseParamList(list string) []string {
  85. list = strings.TrimSpace(list)
  86. if list == "" {
  87. return []string{}
  88. }
  89. return regexp.MustCompile(`\s*,\s*`).Split(list, -1)
  90. }
  91. // parseParam splits a parameter into name and type
  92. func parseParam(p string) Param {
  93. ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p)
  94. if ps == nil {
  95. fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p)
  96. os.Exit(1)
  97. }
  98. return Param{ps[1], ps[2]}
  99. }
  100. func main() {
  101. flag.Usage = usage
  102. flag.Parse()
  103. if len(flag.Args()) <= 0 {
  104. fmt.Fprintf(os.Stderr, "no files to parse provided\n")
  105. usage()
  106. }
  107. endianness := ""
  108. if *b32 {
  109. endianness = "big-endian"
  110. } else if *l32 {
  111. endianness = "little-endian"
  112. }
  113. pack := ""
  114. // GCCGO
  115. textgccgo := ""
  116. cExtern := "/*\n#include <stdint.h>\n"
  117. // GC
  118. textgc := ""
  119. dynimports := ""
  120. linknames := ""
  121. var vars []string
  122. // COMMON
  123. textcommon := ""
  124. for _, path := range flag.Args() {
  125. file, err := os.Open(path)
  126. if err != nil {
  127. fmt.Fprintf(os.Stderr, err.Error())
  128. os.Exit(1)
  129. }
  130. s := bufio.NewScanner(file)
  131. for s.Scan() {
  132. t := s.Text()
  133. t = strings.TrimSpace(t)
  134. t = regexp.MustCompile(`\s+`).ReplaceAllString(t, ` `)
  135. if p := regexp.MustCompile(`^package (\S+)$`).FindStringSubmatch(t); p != nil && pack == "" {
  136. pack = p[1]
  137. }
  138. nonblock := regexp.MustCompile(`^\/\/sysnb `).FindStringSubmatch(t)
  139. if regexp.MustCompile(`^\/\/sys `).FindStringSubmatch(t) == nil && nonblock == nil {
  140. continue
  141. }
  142. // Line must be of the form
  143. // func Open(path string, mode int, perm int) (fd int, err error)
  144. // Split into name, in params, out params.
  145. f := regexp.MustCompile(`^\/\/sys(nb)? (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(?:(\w*)\.)?(\w*))?$`).FindStringSubmatch(t)
  146. if f == nil {
  147. fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t)
  148. os.Exit(1)
  149. }
  150. funct, inps, outps, modname, sysname := f[2], f[3], f[4], f[5], f[6]
  151. // Split argument lists on comma.
  152. in := parseParamList(inps)
  153. out := parseParamList(outps)
  154. inps = strings.Join(in, ", ")
  155. outps = strings.Join(out, ", ")
  156. if sysname == "" {
  157. sysname = funct
  158. }
  159. onlyCommon := false
  160. if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
  161. // This function call another syscall which is already implemented.
  162. // Therefore, the gc and gccgo part must not be generated.
  163. onlyCommon = true
  164. }
  165. // Try in vain to keep people from editing this file.
  166. // The theory is that they jump into the middle of the file
  167. // without reading the header.
  168. textcommon += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
  169. if !onlyCommon {
  170. textgccgo += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
  171. textgc += "// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT\n\n"
  172. }
  173. // Check if value return, err return available
  174. errvar := ""
  175. rettype := ""
  176. for _, param := range out {
  177. p := parseParam(param)
  178. if p.Type == "error" {
  179. errvar = p.Name
  180. } else {
  181. rettype = p.Type
  182. }
  183. }
  184. sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`)
  185. sysname = strings.ToLower(sysname) // All libc functions are lowercase.
  186. // GCCGO Prototype return type
  187. cRettype := ""
  188. if rettype == "unsafe.Pointer" {
  189. cRettype = "uintptr_t"
  190. } else if rettype == "uintptr" {
  191. cRettype = "uintptr_t"
  192. } else if regexp.MustCompile(`^_`).FindStringSubmatch(rettype) != nil {
  193. cRettype = "uintptr_t"
  194. } else if rettype == "int" {
  195. cRettype = "int"
  196. } else if rettype == "int32" {
  197. cRettype = "int"
  198. } else if rettype == "int64" {
  199. cRettype = "long long"
  200. } else if rettype == "uint32" {
  201. cRettype = "unsigned int"
  202. } else if rettype == "uint64" {
  203. cRettype = "unsigned long long"
  204. } else {
  205. cRettype = "int"
  206. }
  207. if sysname == "exit" {
  208. cRettype = "void"
  209. }
  210. // GCCGO Prototype arguments type
  211. var cIn []string
  212. for i, param := range in {
  213. p := parseParam(param)
  214. if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
  215. cIn = append(cIn, "uintptr_t")
  216. } else if p.Type == "string" {
  217. cIn = append(cIn, "uintptr_t")
  218. } else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil {
  219. cIn = append(cIn, "uintptr_t", "size_t")
  220. } else if p.Type == "unsafe.Pointer" {
  221. cIn = append(cIn, "uintptr_t")
  222. } else if p.Type == "uintptr" {
  223. cIn = append(cIn, "uintptr_t")
  224. } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil {
  225. cIn = append(cIn, "uintptr_t")
  226. } else if p.Type == "int" {
  227. if (i == 0 || i == 2) && funct == "fcntl" {
  228. // These fcntl arguments needs to be uintptr to be able to call FcntlInt and FcntlFlock
  229. cIn = append(cIn, "uintptr_t")
  230. } else {
  231. cIn = append(cIn, "int")
  232. }
  233. } else if p.Type == "int32" {
  234. cIn = append(cIn, "int")
  235. } else if p.Type == "int64" {
  236. cIn = append(cIn, "long long")
  237. } else if p.Type == "uint32" {
  238. cIn = append(cIn, "unsigned int")
  239. } else if p.Type == "uint64" {
  240. cIn = append(cIn, "unsigned long long")
  241. } else {
  242. cIn = append(cIn, "int")
  243. }
  244. }
  245. if !onlyCommon {
  246. // GCCGO Prototype Generation
  247. // Imports of system calls from libc
  248. cExtern += fmt.Sprintf("%s %s", cRettype, sysname)
  249. cIn := strings.Join(cIn, ", ")
  250. cExtern += fmt.Sprintf("(%s);\n", cIn)
  251. }
  252. // GC Library name
  253. if modname == "" {
  254. modname = "libc.a/shr_64.o"
  255. } else {
  256. fmt.Fprintf(os.Stderr, "%s: only syscall using libc are available\n", funct)
  257. os.Exit(1)
  258. }
  259. sysvarname := fmt.Sprintf("libc_%s", sysname)
  260. if !onlyCommon {
  261. // GC Runtime import of function to allow cross-platform builds.
  262. dynimports += fmt.Sprintf("//go:cgo_import_dynamic %s %s \"%s\"\n", sysvarname, sysname, modname)
  263. // GC Link symbol to proc address variable.
  264. linknames += fmt.Sprintf("//go:linkname %s %s\n", sysvarname, sysvarname)
  265. // GC Library proc address variable.
  266. vars = append(vars, sysvarname)
  267. }
  268. strconvfunc := "BytePtrFromString"
  269. strconvtype := "*byte"
  270. // Go function header.
  271. if outps != "" {
  272. outps = fmt.Sprintf(" (%s)", outps)
  273. }
  274. if textcommon != "" {
  275. textcommon += "\n"
  276. }
  277. textcommon += fmt.Sprintf("func %s(%s)%s {\n", funct, strings.Join(in, ", "), outps)
  278. // Prepare arguments tocall.
  279. var argscommon []string // Arguments in the common part
  280. var argscall []string // Arguments for call prototype
  281. var argsgc []string // Arguments for gc call (with syscall6)
  282. var argsgccgo []string // Arguments for gccgo call (with C.name_of_syscall)
  283. n := 0
  284. argN := 0
  285. for _, param := range in {
  286. p := parseParam(param)
  287. if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil {
  288. argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.Name))
  289. argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
  290. argsgc = append(argsgc, p.Name)
  291. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
  292. } else if p.Type == "string" && errvar != "" {
  293. textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
  294. textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
  295. textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
  296. argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
  297. argscall = append(argscall, fmt.Sprintf("_p%d uintptr ", n))
  298. argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
  299. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
  300. n++
  301. } else if p.Type == "string" {
  302. fmt.Fprintf(os.Stderr, path+":"+funct+" uses string arguments, but has no error return\n")
  303. textcommon += fmt.Sprintf("\tvar _p%d %s\n", n, strconvtype)
  304. textcommon += fmt.Sprintf("\t_p%d, %s = %s(%s)\n", n, errvar, strconvfunc, p.Name)
  305. textcommon += fmt.Sprintf("\tif %s != nil {\n\t\treturn\n\t}\n", errvar)
  306. argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n))
  307. argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n))
  308. argsgc = append(argsgc, fmt.Sprintf("_p%d", n))
  309. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n))
  310. n++
  311. } else if m := regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type); m != nil {
  312. // Convert slice into pointer, length.
  313. // Have to be careful not to take address of &a[0] if len == 0:
  314. // pass nil in that case.
  315. textcommon += fmt.Sprintf("\tvar _p%d *%s\n", n, m[1])
  316. textcommon += fmt.Sprintf("\tif len(%s) > 0 {\n\t\t_p%d = &%s[0]\n\t}\n", p.Name, n, p.Name)
  317. argscommon = append(argscommon, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n), fmt.Sprintf("len(%s)", p.Name))
  318. argscall = append(argscall, fmt.Sprintf("_p%d uintptr", n), fmt.Sprintf("_lenp%d int", n))
  319. argsgc = append(argsgc, fmt.Sprintf("_p%d", n), fmt.Sprintf("uintptr(_lenp%d)", n))
  320. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(_p%d)", n), fmt.Sprintf("C.size_t(_lenp%d)", n))
  321. n++
  322. } else if p.Type == "int64" && endianness != "" {
  323. fmt.Fprintf(os.Stderr, path+":"+funct+" uses int64 with 32 bits mode. Case not yet implemented\n")
  324. } else if p.Type == "bool" {
  325. fmt.Fprintf(os.Stderr, path+":"+funct+" uses bool. Case not yet implemented\n")
  326. } else if regexp.MustCompile(`^_`).FindStringSubmatch(p.Type) != nil || p.Type == "unsafe.Pointer" {
  327. argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
  328. argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
  329. argsgc = append(argsgc, p.Name)
  330. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
  331. } else if p.Type == "int" {
  332. if (argN == 0 || argN == 2) && ((funct == "fcntl") || (funct == "FcntlInt") || (funct == "FcntlFlock")) {
  333. // These fcntl arguments need to be uintptr to be able to call FcntlInt and FcntlFlock
  334. argscommon = append(argscommon, fmt.Sprintf("uintptr(%s)", p.Name))
  335. argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
  336. argsgc = append(argsgc, p.Name)
  337. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
  338. } else {
  339. argscommon = append(argscommon, p.Name)
  340. argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
  341. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  342. argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
  343. }
  344. } else if p.Type == "int32" {
  345. argscommon = append(argscommon, p.Name)
  346. argscall = append(argscall, fmt.Sprintf("%s int32", p.Name))
  347. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  348. argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
  349. } else if p.Type == "int64" {
  350. argscommon = append(argscommon, p.Name)
  351. argscall = append(argscall, fmt.Sprintf("%s int64", p.Name))
  352. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  353. argsgccgo = append(argsgccgo, fmt.Sprintf("C.longlong(%s)", p.Name))
  354. } else if p.Type == "uint32" {
  355. argscommon = append(argscommon, p.Name)
  356. argscall = append(argscall, fmt.Sprintf("%s uint32", p.Name))
  357. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  358. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uint(%s)", p.Name))
  359. } else if p.Type == "uint64" {
  360. argscommon = append(argscommon, p.Name)
  361. argscall = append(argscall, fmt.Sprintf("%s uint64", p.Name))
  362. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  363. argsgccgo = append(argsgccgo, fmt.Sprintf("C.ulonglong(%s)", p.Name))
  364. } else if p.Type == "uintptr" {
  365. argscommon = append(argscommon, p.Name)
  366. argscall = append(argscall, fmt.Sprintf("%s uintptr", p.Name))
  367. argsgc = append(argsgc, p.Name)
  368. argsgccgo = append(argsgccgo, fmt.Sprintf("C.uintptr_t(%s)", p.Name))
  369. } else {
  370. argscommon = append(argscommon, fmt.Sprintf("int(%s)", p.Name))
  371. argscall = append(argscall, fmt.Sprintf("%s int", p.Name))
  372. argsgc = append(argsgc, fmt.Sprintf("uintptr(%s)", p.Name))
  373. argsgccgo = append(argsgccgo, fmt.Sprintf("C.int(%s)", p.Name))
  374. }
  375. argN++
  376. }
  377. nargs := len(argsgc)
  378. // COMMON function generation
  379. argscommonlist := strings.Join(argscommon, ", ")
  380. callcommon := fmt.Sprintf("call%s(%s)", sysname, argscommonlist)
  381. ret := []string{"_", "_"}
  382. body := ""
  383. doErrno := false
  384. for i := 0; i < len(out); i++ {
  385. p := parseParam(out[i])
  386. reg := ""
  387. if p.Name == "err" {
  388. reg = "e1"
  389. ret[1] = reg
  390. doErrno = true
  391. } else {
  392. reg = "r0"
  393. ret[0] = reg
  394. }
  395. if p.Type == "bool" {
  396. reg = fmt.Sprintf("%s != 0", reg)
  397. }
  398. if reg != "e1" {
  399. body += fmt.Sprintf("\t%s = %s(%s)\n", p.Name, p.Type, reg)
  400. }
  401. }
  402. if ret[0] == "_" && ret[1] == "_" {
  403. textcommon += fmt.Sprintf("\t%s\n", callcommon)
  404. } else {
  405. textcommon += fmt.Sprintf("\t%s, %s := %s\n", ret[0], ret[1], callcommon)
  406. }
  407. textcommon += body
  408. if doErrno {
  409. textcommon += "\tif e1 != 0 {\n"
  410. textcommon += "\t\terr = errnoErr(e1)\n"
  411. textcommon += "\t}\n"
  412. }
  413. textcommon += "\treturn\n"
  414. textcommon += "}\n"
  415. if onlyCommon {
  416. continue
  417. }
  418. // CALL Prototype
  419. callProto := fmt.Sprintf("func call%s(%s) (r1 uintptr, e1 Errno) {\n", sysname, strings.Join(argscall, ", "))
  420. // GC function generation
  421. asm := "syscall6"
  422. if nonblock != nil {
  423. asm = "rawSyscall6"
  424. }
  425. if len(argsgc) <= 6 {
  426. for len(argsgc) < 6 {
  427. argsgc = append(argsgc, "0")
  428. }
  429. } else {
  430. fmt.Fprintf(os.Stderr, "%s: too many arguments to system call", funct)
  431. os.Exit(1)
  432. }
  433. argsgclist := strings.Join(argsgc, ", ")
  434. callgc := fmt.Sprintf("%s(uintptr(unsafe.Pointer(&%s)), %d, %s)", asm, sysvarname, nargs, argsgclist)
  435. textgc += callProto
  436. textgc += fmt.Sprintf("\tr1, _, e1 = %s\n", callgc)
  437. textgc += "\treturn\n}\n"
  438. // GCCGO function generation
  439. argsgccgolist := strings.Join(argsgccgo, ", ")
  440. callgccgo := fmt.Sprintf("C.%s(%s)", sysname, argsgccgolist)
  441. textgccgo += callProto
  442. textgccgo += fmt.Sprintf("\tr1 = uintptr(%s)\n", callgccgo)
  443. textgccgo += "\te1 = syscall.GetErrno()\n"
  444. textgccgo += "\treturn\n}\n"
  445. }
  446. if err := s.Err(); err != nil {
  447. fmt.Fprintf(os.Stderr, err.Error())
  448. os.Exit(1)
  449. }
  450. file.Close()
  451. }
  452. imp := ""
  453. if pack != "unix" {
  454. imp = "import \"golang.org/x/sys/unix\"\n"
  455. }
  456. // Print zsyscall_aix_ppc64.go
  457. err := ioutil.WriteFile("zsyscall_aix_ppc64.go",
  458. []byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)),
  459. 0644)
  460. if err != nil {
  461. fmt.Fprintf(os.Stderr, err.Error())
  462. os.Exit(1)
  463. }
  464. // Print zsyscall_aix_ppc64_gc.go
  465. vardecls := "\t" + strings.Join(vars, ",\n\t")
  466. vardecls += " syscallFunc"
  467. err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go",
  468. []byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
  469. 0644)
  470. if err != nil {
  471. fmt.Fprintf(os.Stderr, err.Error())
  472. os.Exit(1)
  473. }
  474. // Print zsyscall_aix_ppc64_gccgo.go
  475. err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go",
  476. []byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)),
  477. 0644)
  478. if err != nil {
  479. fmt.Fprintf(os.Stderr, err.Error())
  480. os.Exit(1)
  481. }
  482. }
  483. const srcTemplate1 = `// %s
  484. // Code generated by the command above; see README.md. DO NOT EDIT.
  485. // +build %s
  486. package %s
  487. import (
  488. "unsafe"
  489. )
  490. %s
  491. %s
  492. `
  493. const srcTemplate2 = `// %s
  494. // Code generated by the command above; see README.md. DO NOT EDIT.
  495. // +build %s
  496. // +build !gccgo
  497. package %s
  498. import (
  499. "unsafe"
  500. )
  501. %s
  502. %s
  503. %s
  504. type syscallFunc uintptr
  505. var (
  506. %s
  507. )
  508. // Implemented in runtime/syscall_aix.go.
  509. func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
  510. func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
  511. %s
  512. `
  513. const srcTemplate3 = `// %s
  514. // Code generated by the command above; see README.md. DO NOT EDIT.
  515. // +build %s
  516. // +build gccgo
  517. package %s
  518. %s
  519. */
  520. import "C"
  521. import (
  522. "syscall"
  523. )
  524. %s
  525. %s
  526. `