diff --git a/src/pkg/runtime/netbsd/386/defs.h b/src/pkg/runtime/netbsd/386/defs.h new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/386/defs.h @@ -0,0 +1,17 @@ +// godefs defs.c + +// MACHINE GENERATED - DO NOT EDIT. + +// Constants +enum { + PROT_NONE = 0, + PROT_READ = 0x1, + PROT_WRITE = 0x2, + PROT_EXEC = 0x4, + MAP_ANON = 0x1000, + MAP_PRIVATE = 0x2, +}; + +// Types +#pragma pack on +#pragma pack off diff --git a/src/pkg/runtime/netbsd/386/rt0.s b/src/pkg/runtime/netbsd/386/rt0.s new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/386/rt0.s @@ -0,0 +1,9 @@ +// Copyright 2009, 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. + +// Darwin, FreeBSD, NetBSD and Linux use the same linkage to main + +TEXT _rt0_386_netbsd(SB),7,$0 + JMP _rt0_386(SB) + diff --git a/src/pkg/runtime/netbsd/386/signal.c b/src/pkg/runtime/netbsd/386/signal.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/386/signal.c @@ -0,0 +1,10 @@ +// Copyright 2009, 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" +#include "defs.h" +#include "signals.h" +#include "os.h" + +// REVISIT incomplete diff --git a/src/pkg/runtime/netbsd/386/sys.c b/src/pkg/runtime/netbsd/386/sys.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/386/sys.c @@ -0,0 +1,9 @@ +// Copyright 2009, 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. +// +// System calls and other sys.stuff for 386, +// NetBSD: src/sys/kern/syscalls.master for syscall numbers. +// + +// REVISIT incomplete diff --git a/src/pkg/runtime/netbsd/amd64/defs.h b/src/pkg/runtime/netbsd/amd64/defs.h new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/amd64/defs.h @@ -0,0 +1,17 @@ +// godefs -f -m64 defs.c + +// MACHINE GENERATED - DO NOT EDIT. + +// Constants +enum { + PROT_NONE = 0, + PROT_READ = 0x1, + PROT_WRITE = 0x2, + PROT_EXEC = 0x4, + MAP_ANON = 0x1000, + MAP_PRIVATE = 0x2, +}; + +// Types +#pragma pack on +#pragma pack off diff --git a/src/pkg/runtime/netbsd/amd64/rt0.s b/src/pkg/runtime/netbsd/amd64/rt0.s new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/amd64/rt0.s @@ -0,0 +1,18 @@ +// Copyright 2009,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. + +// Darwin and Linux use the same linkage to main +// NetBSD too. + +TEXT _rt0_amd64_linux(SB),7,$-8 + MOVQ initcgo(SB), AX + TESTQ AX, AX + JZ 2(PC) + CALL AX + + MOVQ $_rt0_amd64(SB), AX + MOVQ SP, DI + JMP AX + +GLOBL initcgo(SB), $8 diff --git a/src/pkg/runtime/netbsd/amd64/signal.c b/src/pkg/runtime/netbsd/amd64/signal.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/amd64/signal.c @@ -0,0 +1,10 @@ +// Copyright 2009, 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" +#include "defs.h" +#include "signals.h" +#include "os.h" + +// REVISIT incomplete diff --git a/src/pkg/runtime/netbsd/amd64/sys.c b/src/pkg/runtime/netbsd/amd64/sys.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/amd64/sys.c @@ -0,0 +1,9 @@ +// Copyright 2009, 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. +// +// System calls and other sys.stuff for 386, +// NetBSD: src/sys/kern/syscalls.master for syscall numbers. +// + +// REVISIT incomplete diff --git a/src/pkg/runtime/netbsd/defs.c b/src/pkg/runtime/netbsd/defs.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/defs.c @@ -0,0 +1,30 @@ +// Copyright 2009, 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. + +/* + * Input to godefs. + * + godefs -f -m64 defs.c >amd64/defs.h + godefs defs.c >386/defs.h + */ + +// #include +#include +// #include + +enum { + $PROT_NONE = PROT_NONE, + $PROT_READ = PROT_READ, + $PROT_WRITE = PROT_WRITE, + $PROT_EXEC = PROT_EXEC, + + $MAP_ANON = MAP_ANON, + $MAP_PRIVATE = MAP_PRIVATE, +}; + +// typedef struct _ksiginfo _ksiginfo_t; +// typedef _ksiginfo_t $Ksiginfo; +// typedef siginfo_t $Siginfo; + +// eof diff --git a/src/pkg/runtime/netbsd/mem.c b/src/pkg/runtime/netbsd/mem.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/mem.c @@ -0,0 +1,35 @@ +// Copyright 2009, 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. + +// This file was copied from the OS X and FreeBSD ports. +// The OS X (Darwin) file was probably the original. + +#include "runtime.h" +#include "defs.h" +#include "os.h" +#include "malloc.h" + +void* +SysAlloc(uintptr n) +{ + mstats.sys += n; + return runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); +} + +void +SysUnused(void *v, uintptr n) +{ + USED(v); + USED(n); + // TODO(rsc): call madvise MADV_DONTNEED +} + +void +SysFree(void *v, uintptr n) +{ + USED(v); + USED(n); + // TODO(rsc): acll munmap +} + diff --git a/src/pkg/runtime/netbsd/os.h b/src/pkg/runtime/netbsd/os.h new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/os.h @@ -0,0 +1,30 @@ +// Copyright 2009, 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. + +// +// REVISIT will need some thread stuff here. +// +// Particularly interesting will be choosing the interface to use: +// +// a) the only public interface NetBSD provides is the pthread library +// b) the private interface(s) that the pthread library use are subject +// to change +// c) only the *dynamic* pthread library provides any assurance that +// programs compiled on a particular NetBSD release will run on a +// future release; programs using the static pthread library may or +// may not work +// d) at this time, go doesn't support dynamic linking +// +// Further, I suspect that since the Darwin, FreeBSD, and Linux +// ports don't use the pthread libraries on those systems that +// pthreads is not suitable/sufficient for go. +// +// Decisions, decisions. But at least they can be postponed until +// more of the port is done. +// + +struct Sigaction; +void sigaction(uintptr, struct Sigaction*, struct Sigaction*); + +// eof diff --git a/src/pkg/runtime/netbsd/signals.h b/src/pkg/runtime/netbsd/signals.h new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/signals.h @@ -0,0 +1,50 @@ +// Copyright 2009, 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. + +#define C SigCatch +#define I SigIgnore +#define R SigRestart +#define Q SigQueue + +static SigTab sigtab[] = { + /* 0 */ 0, "SIGNONE: no trap", + /* 1 */ Q+R, "SIGHUP: terminal line hangup", + /* 2 */ Q+R, "SIGINT: interrupt program", + /* 3 */ C, "SIGQUIT: quit program", + /* 4 */ C, "SIGILL: illegal instruction", + /* 5 */ C, "SIGTRAP: trace trap", + /* 6 */ C, "SIGABRT: abort", + /* 7 */ C, "SIGEMT: emulate instrucion executed", + /* 8 */ C, "SIGFPE: floating-point exception", + /* 9 */ 0, "SIGKILL: kill program (cannot be caught or ignored)", + /* 10 */ C, "SIGBUS: bus error", + /* 11 */ C, "SIGSEGV: segmentation violation", + /* 12 */ C, "SIGSYS: invalid system call argument", + /* 13 */ I, "SIGPIPE: write to a pipe with no reader", + /* 14 */ Q+I+R, "SIGALRM: real-time timer expired", + /* 15 */ Q+R, "SIGTERM: software termination signal", + /* 16 */ Q+I+R, "SIGURG: urgent condition present on socket", + /* 17 */ 0, "SIGSTOP: stop (cannot be caught or ignored)", + /* 18 */ Q+I+R, "SIGTSTP: stop signal generated from keyboard", + /* 19 */ 0, "SIGCONT: continue after stop", + /* 20 */ Q+I+R, "SIGCHLD: child status has changed", + /* 21 */ Q+I+R, "SIGTTIN: background read attempted from control terminal", + /* 22 */ Q+I+R, "SIGTTOU: background write attempted to control terminal", + /* 23 */ Q+I+R, "SIGIO: I/O now possible on a descriptor", + /* 24 */ Q+I+R, "SIGXCPU: CPU time limit exceeded", + /* 25 */ Q+I+R, "SIGXFSZ: file size limit exceeded", + /* 26 */ Q+I+R, "SIGVTALRM: virtual time alarm", + /* 27 */ Q+I+R, "SIGPROF: profiling timer alarm", + /* 28 */ Q+I+R, "SIGWINCH: window size change", + /* 29 */ Q+I+R, "SIGINFO: status request from keyboard", + /* 30 */ Q+I+R, "SIGUSR1: user-defined signal 1", + /* 31 */ Q+I+R, "SIGUSR2: user-defined signal 2", + /* 32 */ Q+I+R, "SIGPWR: power failure/restart", +}; +#undef C +#undef I +#undef R +#undef Q + +#define NSIG 33 diff --git a/src/pkg/runtime/netbsd/thread.c b/src/pkg/runtime/netbsd/thread.c new file mode 100644 --- /dev/null +++ b/src/pkg/runtime/netbsd/thread.c @@ -0,0 +1,12 @@ +// Copyright 2009, 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. + +// REVISIT more here -- this is where mutexes are implemented. +// As I can't adopt the OS X, FreeBSD, or Linux implementations +// I'll have to figure what's the most appropriate implementation. + +// REVISIT more here -- see comments in os.h regarding choosing +// how to implement threads on NetBSD for the go runtime. + +// eof