mksys.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. package main
  10. import (
  11. "fmt"
  12. "io/ioutil"
  13. "log"
  14. "strings"
  15. )
  16. func main() {
  17. s, err := ioutil.ReadFile("sys.h")
  18. if err != nil {
  19. log.Fatal(err)
  20. }
  21. lines := strings.Split(string(s), "\n")
  22. for _, line := range lines {
  23. ass := ".globl "
  24. ll := strings.Fields(line)
  25. if len(ll) < 3 {
  26. continue
  27. }
  28. name := strings.ToLower(ll[1])
  29. if name == "exits" {
  30. name = "_" + name
  31. }
  32. filename := name + ".s"
  33. if name == "seek" {
  34. name = "_" + name
  35. }
  36. ass = ass + fmt.Sprintf("%v\n%v: ", name, name)
  37. // linux system call args. di si dx r10 r8 r0
  38. // rcx is not used because it is needed for sysenter
  39. ass = ass + "\tMOVQ %rcx, %r10 /* rcx gets smashed by systenter. Use r10.*/\n"
  40. ass = ass + "\tMOVQ $" + ll[2]
  41. ass = ass + ",%r9 /* Put the system call into arg 6, which is never used on Plan 9. minimizes work on system calls */\n"
  42. ass = ass + "\tSYSCALL\n\tRET\n"
  43. err = ioutil.WriteFile(filename, []byte(ass), 0666)
  44. if err != nil {
  45. log.Fatal(err)
  46. }
  47. }
  48. }