]> Cypherpunks repositories - gostls13.git/commitdiff
src: Add support for 64-bit version of Plan 9
authorAkshat Kumar <seed@mail.nanosouffle.net>
Fri, 31 Aug 2012 17:21:13 +0000 (13:21 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 31 Aug 2012 17:21:13 +0000 (13:21 -0400)
This set of changes extends the Plan 9 support
to include the AMD64 architecture and should
work on all versions of Plan 9.

R=golang-dev, rminnich, noah.evans, rsc, minux.ma, npe
CC=akskuma, golang-dev, jfflore, noah.evans
https://golang.org/cl/6479052

18 files changed:
include/plan9/amd64/u.h [new file with mode: 0644]
src/cmd/6l/pass.c
src/pkg/runtime/asm_amd64.s
src/pkg/runtime/defs_plan9_386.h
src/pkg/runtime/defs_plan9_amd64.h [new file with mode: 0644]
src/pkg/runtime/mem_plan9.c
src/pkg/runtime/os_plan9.h
src/pkg/runtime/rt0_plan9_amd64.s [new file with mode: 0644]
src/pkg/runtime/signal_plan9_amd64.c [new file with mode: 0644]
src/pkg/runtime/sys_plan9_amd64.s [new file with mode: 0644]
src/pkg/syscall/asm_plan9_amd64.s [new file with mode: 0644]
src/pkg/syscall/syscall_plan9.go
src/pkg/syscall/syscall_plan9_386.go
src/pkg/syscall/syscall_plan9_amd64.go [new file with mode: 0644]
src/pkg/syscall/zerrors_plan9_amd64.go [new file with mode: 0644]
src/pkg/syscall/zsyscall_plan9_amd64.go [new file with mode: 0644]
src/pkg/syscall/zsysnum_plan9_amd64.go [new file with mode: 0644]
src/pkg/syscall/ztypes_plan9_amd64.go [new file with mode: 0644]

diff --git a/include/plan9/amd64/u.h b/include/plan9/amd64/u.h
new file mode 100644 (file)
index 0000000..f2430b5
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "/amd64/include/u.h"
+
+typedef char   int8;
+typedef uchar  uint8;
+typedef short  int16;
+typedef ushort uint16;
+typedef int    int32;
+typedef uint   uint32;
+typedef vlong  int64;
+typedef uvlong uint64;
index fc89fd8fc386a9536f2177e38f3e7962fd3ae77b..c2d5dc1067879a6446c21421474ecb05903e55ea 100644 (file)
@@ -310,7 +310,8 @@ patch(void)
                        }
                }
                if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
-               || HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd) {
+               || HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd
+               || HEADTYPE == Hplan9x64) {
                        // ELF uses FS instead of GS.
                        if(p->from.type == D_INDIR+D_GS)
                                p->from.type = D_INDIR+D_FS;
@@ -444,7 +445,8 @@ dostkoff(void)
                        p = appendp(p); // load g into CX
                        p->as = AMOVQ;
                        if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
-                       || HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd) // ELF uses FS
+                       || HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd
+                       || HEADTYPE == Hplan9x64)       // ELF uses FS
                                p->from.type = D_INDIR+D_FS;
                        else
                                p->from.type = D_INDIR+D_GS;
index 160c7cc41f3706a23aa00b0166b627e1f5421ec6..08133f02d2d2015d7807054a9839bd5814471ea2 100644 (file)
@@ -31,6 +31,10 @@ TEXT _rt0_amd64(SB),7,$-8
        JEQ ok
 
 needtls:
+       // skip TLS setup on Plan 9
+       CMPL    runtime·isplan9(SB), $1
+       JEQ ok
+
        LEAQ    runtime·tls0(SB), DI
        CALL    runtime·settls(SB)
 
index 58fd9d94def41dd2402693ad87bdfe71aea20dce..3874ad256a15c98eaec25105e4f901acfc798342 100644 (file)
@@ -1,2 +1,3 @@
 // nothing to see here
 #define tos_pid 48
+#define PAGESIZE 0x1000
diff --git a/src/pkg/runtime/defs_plan9_amd64.h b/src/pkg/runtime/defs_plan9_amd64.h
new file mode 100644 (file)
index 0000000..8c324ea
--- /dev/null
@@ -0,0 +1,3 @@
+// nothing to see here
+#define tos_pid 64
+#define PAGESIZE 0x200000ULL
index 15cbc176b675a37876a0b1dbfcc1d88e2f598298..26ca367f11ebdd0191a1433ef7b8108fa03b3df7 100644 (file)
@@ -3,6 +3,7 @@
 // license that can be found in the LICENSE file.
 
 #include "runtime.h"
+#include "defs_GOOS_GOARCH.h"
 #include "arch_GOARCH.h"
 #include "malloc.h"
 #include "os_GOOS.h"
@@ -13,14 +14,14 @@ static Lock memlock;
 
 enum
 {
-       Round = 4095
+       Round = PAGESIZE-1
 };
 
 void*
 runtime·SysAlloc(uintptr nbytes)
 {
        uintptr bl;
-       
+
        runtime·lock(&memlock);
        mstats.sys += nbytes;
        // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
index 6f1f0bb8eb0c4bbc7b9d0b068ba3242d08cfcf97..ce746b3f3d147a35e8c5a611e30ac1c8657a739d 100644 (file)
@@ -9,7 +9,7 @@ int32   runtime·pwrite(int32 fd, void *buf, int32 nbytes, int64 offset);
 int32  runtime·read(int32 fd, void *buf, int32 nbytes);
 int32  runtime·close(int32 fd);
 void   runtime·exits(int8* msg);
-int32  runtime·brk_(void*);
+intptr runtime·brk_(void*);
 int32  runtime·sleep(int32 ms);
 int32  runtime·rfork(int32 flags, void *stk, M *m, G *g, void (*fn)(void));
 int32  runtime·plan9_semacquire(uint32 *addr, int32 block);
diff --git a/src/pkg/runtime/rt0_plan9_amd64.s b/src/pkg/runtime/rt0_plan9_amd64.s
new file mode 100644 (file)
index 0000000..499413a
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+TEXT _rt0_amd64_plan9(SB),7, $0
+       MOVQ    AX, _tos(SB)
+       MOVQ    $_rt0_amd64(SB), AX
+       MOVQ    SP, DI
+       JMP     AX
+
+DATA runtime·isplan9(SB)/4, $1
+GLOBL runtime·isplan9(SB), $4
+GLOBL _tos(SB), $8
diff --git a/src/pkg/runtime/signal_plan9_amd64.c b/src/pkg/runtime/signal_plan9_amd64.c
new file mode 100644 (file)
index 0000000..d266885
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file. 
+
+#include "runtime.h"
+
+void
+runtime·sigenable(uint32 sig)
+{
+       USED(sig);
+}
+
+void
+runtime·resetcpuprofiler(int32 hz)
+{
+       // TODO: Enable profiling interrupts.
+       
+       m->profilehz = hz;
+}
diff --git a/src/pkg/runtime/sys_plan9_amd64.s b/src/pkg/runtime/sys_plan9_amd64.s
new file mode 100644 (file)
index 0000000..cc343d1
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include "defs_GOOS_GOARCH.h"
+#include "zasm_GOOS_GOARCH.h"
+
+// setldt(int entry, int address, int limit)
+TEXT runtime·setldt(SB),7,$0
+       RET
+
+TEXT runtime·open(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $14, BP
+       SYSCALL
+       RET
+
+TEXT runtime·pread(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $50, BP
+       SYSCALL
+       RET
+
+TEXT runtime·pwrite(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $51, BP
+       SYSCALL
+       RET
+
+TEXT runtime·close(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $4, BP
+       SYSCALL
+       RET
+
+TEXT runtime·exits(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $8, BP
+       SYSCALL
+       RET
+
+TEXT runtime·brk_(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $24, BP
+       SYSCALL
+       RET
+
+TEXT runtime·sleep(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $17, BP
+       SYSCALL
+       RET
+
+TEXT runtime·plan9_semacquire(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $37, BP
+       SYSCALL
+       RET
+
+TEXT runtime·plan9_tsemacquire(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $52, BP
+       SYSCALL
+       RET
+
+TEXT runtime·notify(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $28, BP
+       SYSCALL
+       RET
+
+TEXT runtime·noted(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $29, BP
+       SYSCALL
+       RET
+       
+TEXT runtime·plan9_semrelease(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $38, BP
+       SYSCALL
+       RET
+       
+TEXT runtime·rfork(SB),7,$0
+       MOVQ    $0x8000, AX
+       MOVQ    $19, BP // rfork
+       SYSCALL
+
+       // In parent, return.
+       CMPQ    AX, $0
+       JEQ     2(PC)
+       RET
+
+       // In child on forked stack.
+       MOVQ    mm+24(SP), BX   // m
+       MOVQ    gg+32(SP), DX   // g
+       MOVQ    fn+40(SP), SI   // fn
+
+       // set SP to be on the new child stack
+       MOVQ    stack+16(SP), CX
+       MOVQ    CX, SP
+
+       // Initialize m, g.
+       get_tls(AX)
+       MOVQ    DX, g(AX)
+       MOVQ    BX, m(AX)
+
+       // Initialize AX from _tos->pid
+       MOVQ    _tos(SB), AX
+       MOVQ    tos_pid(AX), AX
+       MOVQ    AX, m_procid(BX)        // save pid as m->procid
+       
+       CALL    runtime·stackcheck(SB) // smashes AX, CX
+       
+       MOVQ    0(DX), DX       // paranoia; check they are not nil
+       MOVQ    0(BX), BX
+       
+       CALL    SI      // fn()
+       CALL    runtime·exit(SB)
+       RET
+
+// This is needed by asm_amd64.s
+TEXT runtime·settls(SB),7,$0
+       RET
diff --git a/src/pkg/syscall/asm_plan9_amd64.s b/src/pkg/syscall/asm_plan9_amd64.s
new file mode 100644 (file)
index 0000000..c046976
--- /dev/null
@@ -0,0 +1,166 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//
+// System call support for Plan 9
+//
+
+//func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err string)
+//func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err string)
+//func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
+//func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
+
+// Trap # in BP, args on stack above caller pc.
+// NxM requires that Plan 9 system calls be
+// marked with $0x8000 in AX.
+TEXT   ·Syscall(SB),7,$0
+       CALL    runtime·entersyscall(SB)
+       MOVQ    $0x8000, AX     // for NxM
+       MOVQ    8(SP), BP       // syscall entry
+       // slide args down on top of system call number
+       LEAQ    16(SP), SI
+       LEAQ    8(SP), DI
+       CLD
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       SYSCALL
+       MOVQ    AX, r1+40(SP)
+       MOVQ    $0, r2+48(SP)
+       CMPQ    AX, $-1
+       JNE     ok3
+
+       SUBQ    $16, SP
+       CALL    syscall·errstr(SB)
+       MOVQ    SP, SI
+       ADDQ    $16, SP
+       JMP     copyresult3
+       
+ok3:
+       LEAQ    runtime·emptystring(SB), SI    
+       
+copyresult3:
+       LEAQ    err+56(SP), DI
+
+       CLD
+       MOVSQ
+       MOVSQ
+
+       CALL    runtime·exitsyscall(SB)
+       RET
+
+TEXT   ·Syscall6(SB),7,$0
+       CALL    runtime·entersyscall(SB)
+       MOVQ    $0x8000, AX     // for NxM
+       MOVQ    8(SP), BP       // syscall entry
+       // slide args down on top of system call number
+       LEAQ            16(SP), SI
+       LEAQ            8(SP), DI
+       CLD
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       SYSCALL
+       MOVQ    AX, r1+64(SP)
+       MOVQ    $0, r2+72(SP)
+       CMPQ    AX, $-1
+       JNE     ok4
+       
+       SUBQ    $16, SP
+       CALL    syscall·errstr(SB)
+       MOVQ    SP, SI
+       ADDQ    $16, SP
+       JMP     copyresult4
+       
+ok4:
+       LEAQ    runtime·emptystring(SB), SI
+       
+copyresult4:
+       LEAQ    err+80(SP), DI
+
+       CLD
+       MOVSL
+       MOVSL
+
+       CALL    runtime·exitsyscall(SB)
+       RET
+
+TEXT ·RawSyscall(SB),7,$0
+       MOVQ    $0x8000, AX     // for NxM
+       MOVQ    8(SP), BP       // syscall entry
+       // slide args down on top of system call number
+       LEAQ            16(SP), SI
+       LEAQ            8(SP), DI
+       CLD
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       SYSCALL
+       MOVQ    AX, r1+40(SP)
+       MOVQ    AX, r2+48(SP)
+       MOVQ    AX, err+56(SP)
+       RET
+
+TEXT   ·RawSyscall6(SB),7,$0
+       MOVQ    $0x8000, AX     // for NxM
+       MOVQ    8(SP), BP       // syscall entry
+       // slide args down on top of system call number
+       LEAQ            16(SP), SI
+       LEAQ            8(SP), DI
+       CLD
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       MOVSQ
+       SYSCALL
+       MOVQ    AX, r1+64(SP)
+       MOVQ    AX, r2+72(SP)
+       MOVQ    AX, err+80(SP)          
+       RET
+
+#define SYS_SEEK 39    /* from zsysnum_plan9_amd64.go */
+
+//func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
+TEXT ·seek(SB),7,$0
+       LEAQ    newoffset+48(SP), AX
+       MOVQ    AX, placeholder+8(SP)
+       
+       MOVQ    $0x8000, AX     // for NxM
+       MOVQ    $SYS_SEEK, BP   // syscall entry
+       SYSCALL
+       
+       CMPQ    AX, $-1
+       JNE     ok6
+       MOVQ    AX, 48(SP)      // newoffset low
+       MOVQ    AX, 56(SP)      // newoffset high
+       
+       SUBQ    $16, SP
+       CALL    syscall·errstr(SB)
+       MOVQ    SP, SI
+       ADDQ    $16, SP 
+       JMP     copyresult6
+       
+ok6:
+       LEAQ    runtime·emptystring(SB), SI
+       
+copyresult6:
+       LEAQ    err+64(SP), DI
+
+       CLD
+       MOVSQ
+       MOVSQ
+       RET
+
+//func exit(code int)
+// Import runtime·exit for cleanly exiting.
+TEXT ·exit(SB),7,$8
+       MOVQ    code+0(FP), AX
+       MOVQ    AX, 0(SP)
+       CALL    runtime·exit(SB)
+       RET
index d81f9302d7269b866e53ce1fac62bebc6b0dc5c7..3657f7c15f526a583550e02db0f6260e2cc0fe93 100644 (file)
@@ -77,8 +77,6 @@ func errstr() string {
        return cstring(buf[:])
 }
 
-func Getpagesize() int { return 4096 }
-
 // Implemented in assembly to import from runtime.
 func exit(int)
 
index e82b540b4b64da1ef68d4cde3eb4beb73762befc..4e4c7511e5c078ea60b96b5afb3010c88360c5ad 100644 (file)
@@ -3,3 +3,5 @@
 // license that can be found in the LICENSE file.
 
 package syscall
+
+func Getpagesize() int { return 0x1000 }
diff --git a/src/pkg/syscall/syscall_plan9_amd64.go b/src/pkg/syscall/syscall_plan9_amd64.go
new file mode 100644 (file)
index 0000000..6f752f2
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+func Getpagesize() int { return 0x200000 }
diff --git a/src/pkg/syscall/zerrors_plan9_amd64.go b/src/pkg/syscall/zerrors_plan9_amd64.go
new file mode 100644 (file)
index 0000000..3d62508
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+import "errors"
+
+// Constants
+const (
+       // Invented values to support what package os expects.
+       O_CREAT    = 0x02000
+       O_APPEND   = 0x00400
+       O_NOCTTY   = 0x00000
+       O_NONBLOCK = 0x00000
+       O_SYNC     = 0x00000
+       O_ASYNC    = 0x00000
+
+       S_IFMT   = 0x1f000
+       S_IFIFO  = 0x1000
+       S_IFCHR  = 0x2000
+       S_IFDIR  = 0x4000
+       S_IFBLK  = 0x6000
+       S_IFREG  = 0x8000
+       S_IFLNK  = 0xa000
+       S_IFSOCK = 0xc000
+)
+
+// Errors
+var (
+       EINVAL       = errors.New("bad arg in system call")
+       ENOTDIR      = errors.New("not a directory")
+       ENOENT       = errors.New("file does not exist")
+       EEXIST       = errors.New("file already exists")
+       EIO          = errors.New("i/o error")
+       ENAMETOOLONG = errors.New("file name too long")
+       EPERM        = errors.New("permission denied")
+       EPLAN9       = errors.New("not supported by plan 9")
+)
diff --git a/src/pkg/syscall/zsyscall_plan9_amd64.go b/src/pkg/syscall/zsyscall_plan9_amd64.go
new file mode 100644 (file)
index 0000000..913c28f
--- /dev/null
@@ -0,0 +1,239 @@
+// mksyscall.pl -l32 -plan9 syscall_plan9.go syscall_plan9_386.go
+// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
+
+package syscall
+
+import "unsafe"
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func exits(msg *byte) {
+       Syscall(SYS_EXITS, uintptr(unsafe.Pointer(msg)), 0, 0)
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func fd2path(fd int, buf []byte) (err error) {
+       var _p0 unsafe.Pointer
+       if len(buf) > 0 {
+               _p0 = unsafe.Pointer(&buf[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func pipe(p *[2]_C_int) (err error) {
+       r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func await(s []byte) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(s) > 0 {
+               _p0 = unsafe.Pointer(&s[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
+       n = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Dup(oldfd int, newfd int) (fd int, err error) {
+       r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
+       fd = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Open(path string, mode int) (fd int, err error) {
+       r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(mode), 0)
+       fd = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Create(path string, mode int, perm uint32) (fd int, err error) {
+       r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(mode), uintptr(perm))
+       fd = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Remove(path string) (err error) {
+       r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, 0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Pread(fd int, p []byte, offset int64) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(p) > 0 {
+               _p0 = unsafe.Pointer(&p[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
+       n = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(p) > 0 {
+               _p0 = unsafe.Pointer(&p[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
+       n = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Close(fd int) (err error) {
+       r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Chdir(path string) (err error) {
+       r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, 0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Bind(name string, old string, flag int) (err error) {
+       r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(StringBytePtr(name))), uintptr(unsafe.Pointer(StringBytePtr(old))), uintptr(flag))
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
+       r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(StringBytePtr(old))), uintptr(flag), uintptr(unsafe.Pointer(StringBytePtr(aname))), 0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Stat(path string, edir []byte) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(edir) > 0 {
+               _p0 = unsafe.Pointer(&edir[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(_p0), uintptr(len(edir)))
+       n = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Fstat(fd int, edir []byte) (n int, err error) {
+       var _p0 unsafe.Pointer
+       if len(edir) > 0 {
+               _p0 = unsafe.Pointer(&edir[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
+       n = int(r0)
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Wstat(path string, edir []byte) (err error) {
+       var _p0 unsafe.Pointer
+       if len(edir) > 0 {
+               _p0 = unsafe.Pointer(&edir[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(_p0), uintptr(len(edir)))
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
+func Fwstat(fd int, edir []byte) (err error) {
+       var _p0 unsafe.Pointer
+       if len(edir) > 0 {
+               _p0 = unsafe.Pointer(&edir[0])
+       } else {
+               _p0 = unsafe.Pointer(&_zero)
+       }
+       r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
+       if int(r0) == -1 {
+               err = e1
+       }
+       return
+}
diff --git a/src/pkg/syscall/zsysnum_plan9_amd64.go b/src/pkg/syscall/zsysnum_plan9_amd64.go
new file mode 100644 (file)
index 0000000..4135b8d
--- /dev/null
@@ -0,0 +1,47 @@
+// mksysnum_plan9.sh /media/sys/src/libc/9syscall/sys.h
+// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
+
+package syscall
+
+const (
+       SYS_SYSR1      = 0
+       SYS_BIND       = 2
+       SYS_CHDIR      = 3
+       SYS_CLOSE      = 4
+       SYS_DUP        = 5
+       SYS_ALARM      = 6
+       SYS_EXEC       = 7
+       SYS_EXITS      = 8
+       SYS_FAUTH      = 10
+       SYS_SEGBRK     = 12
+       SYS_OPEN       = 14
+       SYS_OSEEK      = 16
+       SYS_SLEEP      = 17
+       SYS_RFORK      = 19
+       SYS_PIPE       = 21
+       SYS_CREATE     = 22
+       SYS_FD2PATH    = 23
+       SYS_BRK_       = 24
+       SYS_REMOVE     = 25
+       SYS_NOTIFY     = 28
+       SYS_NOTED      = 29
+       SYS_SEGATTACH  = 30
+       SYS_SEGDETACH  = 31
+       SYS_SEGFREE    = 32
+       SYS_SEGFLUSH   = 33
+       SYS_RENDEZVOUS = 34
+       SYS_UNMOUNT    = 35
+       SYS_SEMACQUIRE = 37
+       SYS_SEMRELEASE = 38
+       SYS_SEEK       = 39
+       SYS_FVERSION   = 40
+       SYS_ERRSTR     = 41
+       SYS_STAT       = 42
+       SYS_FSTAT      = 43
+       SYS_WSTAT      = 44
+       SYS_FWSTAT     = 45
+       SYS_MOUNT      = 46
+       SYS_AWAIT      = 47
+       SYS_PREAD      = 50
+       SYS_PWRITE     = 51
+)
diff --git a/src/pkg/syscall/ztypes_plan9_amd64.go b/src/pkg/syscall/ztypes_plan9_amd64.go
new file mode 100644 (file)
index 0000000..3e3a8d1
--- /dev/null
@@ -0,0 +1,75 @@
+// godefs -gsyscall -f -m32 types_plan9.c
+
+// MACHINE GENERATED - DO NOT EDIT.
+
+package syscall
+
+// Constants
+const (
+       O_RDONLY   = 0
+       O_WRONLY   = 0x1
+       O_RDWR     = 0x2
+       O_TRUNC    = 0x10
+       O_CLOEXEC  = 0x20
+       O_EXCL     = 0x1000
+       STATMAX    = 0xffff
+       ERRMAX     = 0x80
+       MORDER     = 0x3
+       MREPL      = 0
+       MBEFORE    = 0x1
+       MAFTER     = 0x2
+       MCREATE    = 0x4
+       MCACHE     = 0x10
+       MMASK      = 0x17
+       RFNAMEG    = 0x1
+       RFENVG     = 0x2
+       RFFDG      = 0x4
+       RFNOTEG    = 0x8
+       RFPROC     = 0x10
+       RFMEM      = 0x20
+       RFNOWAIT   = 0x40
+       RFCNAMEG   = 0x400
+       RFCENVG    = 0x800
+       RFCFDG     = 0x1000
+       RFREND     = 0x2000
+       RFNOMNT    = 0x4000
+       QTDIR      = 0x80
+       QTAPPEND   = 0x40
+       QTEXCL     = 0x20
+       QTMOUNT    = 0x10
+       QTAUTH     = 0x8
+       QTTMP      = 0x4
+       QTFILE     = 0
+       DMDIR      = 0x80000000
+       DMAPPEND   = 0x40000000
+       DMEXCL     = 0x20000000
+       DMMOUNT    = 0x10000000
+       DMAUTH     = 0x8000000
+       DMTMP      = 0x4000000
+       DMREAD     = 0x4
+       DMWRITE    = 0x2
+       DMEXEC     = 0x1
+       STATFIXLEN = 0x31
+)
+
+// Types
+
+type _C_int int32
+
+type Prof struct {
+       Pp    *[0]byte /* sPlink */
+       Next  *[0]byte /* sPlink */
+       Last  *[0]byte /* sPlink */
+       First *[0]byte /* sPlink */
+       Pid   uint32
+       What  uint32
+}
+
+type Tos struct {
+       Prof      Prof
+       Cyclefreq uint64
+       Kcycles   int64
+       Pcycles   int64
+       Pid       uint32
+       Clock     uint32
+}