Commit e5c884f7 authored by Kai Backman's avatar Kai Backman

some progress on arm linux syscall interface. ztypes_linux_arm

still has problems with godefs.

R=rsc
APPROVED=rsc
DELTA=801  (134 added, 235 deleted, 432 changed)
OCL=35189
CL=35211
parent 8fd53f47
......@@ -21,7 +21,7 @@ chmod +x $GOBIN/quietgcc
# TODO(kaib): converge with normal build
#for i in lib9 libbio libmach libregexp cmd pkg cmd/ebnflint cmd/godoc cmd/gofmt
for i in lib9 libbio libmach libregexp cmd pkg/runtime pkg/sync
for i in lib9 libbio libmach libregexp cmd pkg/runtime pkg/sync pkg/once pkg/syscall
#for i in lib9 libbio libmach libregexp cmd pkg/runtime pkg/sync pkg/once pkg/malloc pkg/sort pkg/unicode
# pkg/hash
# pkg/math
......
......@@ -112,6 +112,14 @@ nacl_386)
mktypes="godefs -gsyscall -f-m32 -f-I$NACLSDK/include -f-I$NACL"
mkerrors="mkerrors_nacl.sh $NACLRUN/include/sys/errno.h"
;;
linux_arm)
ARM="/home/kaib/public/linux-2.6.28"
mksyscall="mksyscall.sh -l32"
mksysnum="mksysnum_linux.sh $ARM/arch/arm/include/asm/unistd.h"
// mktypes="godefs -gsyscall -carm-gcc -f-I$ARM/arch/arm/include -f-I$ARM/include -f-D__deprecated='' -f-I$ARM/arch/arm/mach-at91/include -f-DCONFIG_ARCH_AT91SAM9260 "
mktypes="godefs -gsyscall -carm-gcc"
mkerrors="mkerrors.sh"
;;
*)
echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
exit 1
......
......@@ -2,3 +2,56 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// System calls for arm, Linux
//
#define SYS_BASE 0x00900000
#define SYS_syscall (SYS_BASE+113);
// TODO(kaib): handle error returns
// func Syscall(syscall uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr);
TEXT syscall·Syscall(SB),7,$0
BL sys·entersyscall(SB)
MOVW 4(SP), R7
MOVW 8(SP), R0
MOVW 12(SP), R1
MOVW 16(SP), R2
SWI $SYS_syscall
MOVW R0, 20(SP) // r1
MOVW R1, 24(SP) // r2
MOVW $0, 28(SP) // errno
BL sys·exitsyscall(SB)
RET
// func Syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
// Actually Syscall5 but the rest of the code expects it to be named Syscall6.
TEXT syscall·Syscall6(SB),7,$0
BL sys·entersyscall(SB)
MOVW 4(SP), R7 // syscall entry
MOVW 8(SP), R0
MOVW 12(SP), R1
MOVW 16(SP), R2
MOVW 20(SP), R3
MOVW 24(SP), R4
MOVW 28(SP), R5
SWI $SYS_syscall
MOVW R0, 32(SP) // r1
MOVW R1, 36(SP) // r2
MOVW $0, 40(SP) // errno
BL sys·exitsyscall(SB)
RET
// func RawSyscall(trap uintptr, a1, a2, a3 uintptr) (r1, r2, err uintptr);
TEXT syscall·RawSyscall(SB),7,$0
MOVW 4(SP), R7 // syscall entry
MOVW 8(SP), R0
MOVW 12(SP), R1
MOVW 16(SP), R2
SWI $SYS_syscall
MOVW R0, 20(SP) // r1
MOVW R1, 24(SP) // r2
MOVW $0, 28(SP) // errno
RET
......@@ -7,18 +7,27 @@
# and signal values (SIGALRM etc). They're unrelated except
# that we use the same method for finding them.
case "$GOARCH" in
arm)
GCC=arm-gcc
;;
*)
GCC=gcc
;;
esac
errors=$(
echo '#include <errno.h>' |
# The gcc command line prints all the #defines
# it encounters while processing the input
gcc -x c - -E -dM |
$GCC -x c - -E -dM |
egrep -h '#define E[A-Z0-9_]+ ' $files |
sed 's/#define //; s/ .*//'
)
signals=$(
echo '#include <sys/signal.h>' |
gcc -x c - -E -dM |
$GCC -x c - -E -dM |
egrep -h '#define SIG[^_]' |
egrep -v '#define (SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))' |
sed 's/#define //; s/ .*//'
......
......@@ -4,26 +4,12 @@
package syscall
import "unsafe"
func Getpagesize() int {
return 4096
}
func TimespecToNsec(ts Timespec) int64 {
return int64(ts.Sec)*1e9 + int64(ts.Nsec);
}
func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9);
ts.Nsec = int32(nsec % 1e9);
return;
}
func TimevalToNsec(tv Timeval) int64 {
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3;
}
func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999; // round up to microsecond
tv.Sec = int32(nsec/1e9);
......@@ -31,108 +17,15 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
return;
}
// 64-bit file system and 32-bit uid calls
// (386 default is 32-bit file system and 16-bit uid).
//sys Chown(path string, uid int, gid int) (errno int) = SYS_CHOWN32
//sys Fchown(fd int, uid int, gid int) (errno int) = SYS_FCHOWN32
//sys Fstat(fd int, stat *Stat_t) (errno int) = SYS_FSTAT64
//sys Fstatfs(fd int, buf *Statfs_t) (errno int) = SYS_FSTATFS64
//sys Getegid() (egid int) = SYS_GETEGID32
//sys Geteuid() (euid int) = SYS_GETEUID32
//sys Getgid() (gid int) = SYS_GETGID32
//sys Getuid() (uid int) = SYS_GETUID32
//sys Lchown(path string, uid int, gid int) (errno int) = SYS_LCHOWN32
//sys Lstat(path string, stat *Stat_t) (errno int) = SYS_LSTAT64
//sys Setfsgid(gid int) (errno int) = SYS_SETFSGID32
//sys Setfsuid(uid int) (errno int) = SYS_SETFSUID32
//sys Setgid(gid int) (errno int) = SYS_SETGID32
//sys Setregid(rgid int, egid int) (errno int) = SYS_SETREGID32
//sys Setresgid(rgid int, egid int, sgid int) (errno int) = SYS_SETRESGID32
//sys Setresuid(ruid int, euid int, suid int) (errno int) = SYS_SETRESUID32
//sys Setreuid(ruid int, euid int) (errno int) = SYS_SETREUID32
//sys Stat(path string, stat *Stat_t) (errno int) = SYS_STAT64
//sys Statfs(path string, buf *Statfs_t) (errno int) = SYS_STATFS64
//sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int)
//sys bind(s int, addr uintptr, addrlen _Socklen) (errno int)
//sys connect(s int, addr uintptr, addrlen _Socklen) (errno int)
//sys getgroups(n int, list *_Gid_t) (nn int, errno int) = SYS_GETGROUPS32
//sys setgroups(n int, list *_Gid_t) (errno int) = SYS_SETGROUPS32
//sys setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int)
//sys socket(domain int, typ int, proto int) (fd int, errno int)
//sys getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sys getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int)
//sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, errno int) = SYS__NEWSELECT
// Underlying system call writes to newoffset via pointer.
// Implemented in assembly to avoid allocation.
func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
// On x86 Linux, all the socket calls go through an extra indirection,
// I think because the 5-register system call interface can't handle
// the 6-argument calls like sendto and recvfrom. Instead the
// arguments to the underlying system call are the number below
// and a pointer to an array of uintptr. We hide the pointer in the
// socketcall assembly to avoid allocation on every system call.
const (
// see linux/net.h
_SOCKET = 1;
_BIND = 2;
_CONNECT = 3;
_LISTEN = 4;
_ACCEPT = 5;
_GETSOCKNAME = 6;
_GETPEERNAME = 7;
_SOCKETPAIR = 8;
_SEND = 9;
_RECV = 10;
_SENDTO = 11;
_RECVFROM = 12;
_SHUTDOWN = 13;
_SETSOCKOPT = 14;
_GETSOCKOPT = 15;
_SENDMSG = 16;
_RECVMSG = 17;
)
func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (n int, errno int)
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int) {
fd, errno = socketcall(_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0);
return;
}
func getsockname(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int) {
var _ int;
_, errno = socketcall(_GETSOCKNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0);
return;
}
func getpeername(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (errno int) {
var _ int;
_, errno = socketcall(_GETPEERNAME, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), 0, 0, 0);
return;
}
func bind(s int, addr uintptr, addrlen _Socklen) (errno int) {
var _ int;
_, errno = socketcall(_BIND, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0);
return;
}
func connect(s int, addr uintptr, addrlen _Socklen) (errno int) {
var _ int;
_, errno = socketcall(_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen), 0, 0, 0);
return;
}
func socket(domain int, typ int, proto int) (fd int, errno int) {
fd, errno = socketcall(_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto), 0, 0, 0);
return;
}
func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
var _ int;
_, errno = socketcall(_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0);
return;
}
func Listen(s int, n int) (errno int) {
var _ int;
_, errno = socketcall(_LISTEN, uintptr(s), uintptr(n), 0, 0, 0, 0);
return;
}
......@@ -30,6 +30,7 @@ const (
ETXTBSY = 0x1a;
ENOMEM = 0xc;
EINPROGRESS = 0x73;
ENOTEMPTY = 0x27;
ENOTBLK = 0xf;
EPROTOTYPE = 0x5b;
ERESTART = 0x55;
......@@ -58,9 +59,7 @@ const (
EXFULL = 0x36;
EBADSLT = 0x39;
ENOTNAM = 0x76;
ELIBEXEC = 0x53;
ENOCSI = 0x32;
ENOTEMPTY = 0x27;
EADDRINUSE = 0x62;
ENETRESET = 0x66;
EISDIR = 0x15;
......@@ -74,7 +73,6 @@ const (
EKEYREJECTED = 0x81;
ELIBSCN = 0x51;
ENAVAIL = 0x77;
ENOSTR = 0x3c;
EOVERFLOW = 0x4b;
EUCLEAN = 0x75;
ENOMEDIUM = 0x7b;
......@@ -86,11 +84,13 @@ const (
ELIBACC = 0x4f;
E2BIG = 0x7;
EDEADLK = 0x23;
ENOTDIR = 0x14;
ECONNRESET = 0x68;
ENXIO = 0x6;
EBADRQC = 0x38;
ENAMETOOLONG = 0x24;
ESOCKTNOSUPPORT = 0x5e;
ELIBEXEC = 0x53;
EDOTDOT = 0x49;
EADDRNOTAVAIL = 0x63;
ETIME = 0x3e;
......@@ -105,6 +105,7 @@ const (
ENOEXEC = 0x8;
EMSGSIZE = 0x5a;
EDOM = 0x21;
ENOSTR = 0x3c;
EFBIG = 0x1b;
ESRCH = 0x3;
ECHRNG = 0x2c;
......@@ -139,7 +140,6 @@ const (
EHOSTUNREACH = 0x71;
ENOTUNIQ = 0x4c;
EOPNOTSUPP = 0x5f;
ENOTDIR = 0x14;
EMEDIUMTYPE = 0x7c;
SIGBUS = 0x7;
SIGTTIN = 0x15;
......@@ -150,11 +150,10 @@ const (
SIGSTKFLT = 0x10;
SIGUSR1 = 0xa;
SIGURG = 0x17;
SIGIO = 0x1d;
SIGQUIT = 0x3;
SIGCLD = 0x11;
SIGIO = 0x1d;
SIGABRT = 0x6;
SIGUSR2 = 0xc;
SIGTRAP = 0x5;
SIGVTALRM = 0x1a;
SIGPOLL = 0x1d;
......@@ -167,6 +166,7 @@ const (
SIGSYS = 0x1f;
SIGSTOP = 0x13;
SIGALRM = 0xe;
SIGUSR2 = 0xc;
SIGTSTP = 0x14;
SIGKILL = 0x9;
SIGXCPU = 0x18;
......@@ -204,6 +204,7 @@ var errors = [...]string {
26: "text file busy",
12: "cannot allocate memory",
115: "operation now in progress",
39: "directory not empty",
15: "block device required",
91: "protocol wrong type for socket",
85: "interrupted system call should be restarted",
......@@ -232,9 +233,7 @@ var errors = [...]string {
54: "exchange full",
57: "invalid slot",
118: "not a XENIX named type file",
83: "cannot exec a shared library directly",
50: "no CSI structure available",
39: "directory not empty",
98: "address already in use",
102: "network dropped connection on reset",
21: "is a directory",
......@@ -248,7 +247,6 @@ var errors = [...]string {
129: "key was rejected by service",
81: ".lib section in a.out corrupted",
119: "no XENIX semaphores available",
60: "device not a stream",
75: "value too large for defined data type",
117: "structure needs cleaning",
123: "no medium found",
......@@ -260,11 +258,13 @@ var errors = [...]string {
79: "can not access a needed shared library",
7: "argument list too long",
35: "resource deadlock avoided",
20: "not a directory",
104: "connection reset by peer",
6: "no such device or address",
56: "invalid request code",
36: "file name too long",
94: "socket type not supported",
83: "cannot exec a shared library directly",
73: "RFS specific error",
99: "cannot assign requested address",
62: "timer expired",
......@@ -279,6 +279,7 @@ var errors = [...]string {
8: "exec format error",
90: "message too long",
33: "numerical argument out of domain",
60: "device not a stream",
27: "file too large",
3: "no such process",
44: "channel number out of range",
......@@ -310,7 +311,6 @@ var errors = [...]string {
128: "key has been revoked",
113: "no route to host",
76: "name not unique on network",
20: "not a directory",
124: "wrong medium type",
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment