mksys.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. ass = ass + "\tMOVQ $"+ll[2]
  38. ass = ass + ",%r9 /* Put the system call into arg 6, which is never used on Plan 9. minimizes work on system calls */\n"
  39. ass = ass + "\tSYSCALL\n\tRET\n"
  40. err = ioutil.WriteFile(filename, []byte(ass), 0666)
  41. if err != nil {
  42. log.Fatal(err)
  43. }
  44. }
  45. }