summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/tiny
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/runtime/tiny')
-rw-r--r--src/pkg/runtime/tiny/386/rt0.s8
-rw-r--r--src/pkg/runtime/tiny/386/signal.c8
-rw-r--r--src/pkg/runtime/tiny/386/sys.s18
-rwxr-xr-xsrc/pkg/runtime/tiny/README32
-rw-r--r--src/pkg/runtime/tiny/mem.c31
-rw-r--r--src/pkg/runtime/tiny/runtime_defs.go14
-rw-r--r--src/pkg/runtime/tiny/thread.c44
7 files changed, 108 insertions, 47 deletions
diff --git a/src/pkg/runtime/tiny/386/rt0.s b/src/pkg/runtime/tiny/386/rt0.s
index ff7aae7ac..524ac7664 100644
--- a/src/pkg/runtime/tiny/386/rt0.s
+++ b/src/pkg/runtime/tiny/386/rt0.s
@@ -11,18 +11,18 @@ TEXT _rt0_386_tiny(SB), 7, $0
MOVL AX, SP
// Set up memory hardware.
- CALL msetup(SB)
+ CALL runtime·msetup(SB)
// _rt0_386 expects to find argc, argv, envv on stack.
// Set up argv=["kernel"] and envv=[].
SUBL $64, SP
MOVL $1, 0(SP)
- MOVL $kernel(SB), 4(SP)
+ MOVL $runtime·kernel(SB), 4(SP)
MOVL $0, 8(SP)
MOVL $0, 12(SP)
JMP _rt0_386(SB)
-DATA kernel+0(SB)/7, $"kernel\z"
-GLOBL kernel(SB), $7
+DATA runtime·kernel(SB)/7, $"kernel\z"
+GLOBL runtime·kernel(SB), $7
diff --git a/src/pkg/runtime/tiny/386/signal.c b/src/pkg/runtime/tiny/386/signal.c
index de06ba8db..88e634e9d 100644
--- a/src/pkg/runtime/tiny/386/signal.c
+++ b/src/pkg/runtime/tiny/386/signal.c
@@ -4,16 +4,16 @@
#include "runtime.h"
-extern void ·write(int32 fd, void *v, int32 len, int32 cap); // slice, spelled out
+extern void runtime·write(int32 fd, void *v, int32 len, int32 cap); // slice, spelled out
int32
-write(int32 fd, void *v, int32 len)
+runtime·write(int32 fd, void *v, int32 len)
{
- ·write(fd, v, len, len);
+ runtime·write(fd, v, len, len);
return len;
}
void
-gettime(int64*, int32*)
+runtime·gettime(int64*, int32*)
{
}
diff --git a/src/pkg/runtime/tiny/386/sys.s b/src/pkg/runtime/tiny/386/sys.s
index c51a5ec3e..851171476 100644
--- a/src/pkg/runtime/tiny/386/sys.s
+++ b/src/pkg/runtime/tiny/386/sys.s
@@ -17,8 +17,8 @@
// Called to set up memory hardware.
// Already running in 32-bit mode thanks to boot block,
// but we need to install our new GDT that we can modify.
-TEXT msetup(SB), 7, $0
- MOVL gdtptr(SB), GDTR
+TEXT runtime·msetup(SB), 7, $0
+ MOVL runtime·gdtptr(SB), GDTR
MOVL $(1*8+0), AX
MOVW AX, DS
MOVW AX, ES
@@ -29,14 +29,14 @@ TEXT msetup(SB), 7, $0
// long jmp to cs:mret
BYTE $0xEA
- LONG $mret(SB)
+ LONG $runtime·mret(SB)
WORD $(2*8+0)
-TEXT mret(SB), 7, $0
+TEXT runtime·mret(SB), 7, $0
RET
// GDT memory
-TEXT gdt(SB), 7, $0
+TEXT runtime·gdt(SB), 7, $0
// null segment
LONG $0
LONG $0
@@ -54,14 +54,14 @@ TEXT gdt(SB), 7, $0
LONG $0
// GDT pseudo-descriptor
-TEXT gdtptr(SB), 7, $0
+TEXT runtime·gdtptr(SB), 7, $0
WORD $(4*8)
- LONG $gdt(SB)
+ LONG $runtime·gdt(SB)
// Called to establish the per-thread segment.
// Write to gdt[3] and reload the gdt register.
// setldt(int entry, int address, int limit)
-TEXT setldt(SB),7,$32
+TEXT runtime·setldt(SB),7,$32
MOVL address+4(FP), BX // aka base
MOVL limit+8(FP), CX
@@ -83,7 +83,7 @@ TEXT setldt(SB),7,$32
MOVB CX, 6(AX)
MOVB $0xF2, 5(AX) // r/w data descriptor, dpl=3, present
- MOVL gdtptr(SB), GDTR
+ MOVL runtime·gdtptr(SB), GDTR
// Compute segment selector - (entry*8+0)
MOVL $(3*8+0), AX
diff --git a/src/pkg/runtime/tiny/README b/src/pkg/runtime/tiny/README
index bbe00f3ea..cf001d1e6 100755
--- a/src/pkg/runtime/tiny/README
+++ b/src/pkg/runtime/tiny/README
@@ -6,8 +6,7 @@ for 386 and arm.
386
It is very primitive but can run go/test/sieve.go, the concurrent
-prime sieve, on a uniprocessor. It has only been tested using the
-Bochs emulator.
+prime sieve, on a uniprocessor.
To run, first build the tools by running all.bash with GOARCH=386
and GOOS set to your normal GOOS (linux, darwin). Then:
@@ -22,14 +21,41 @@ and GOOS set to your normal GOOS (linux, darwin). Then:
8l -a sieve.8 >sieve.asm # can consult sieve.asm for debugging
dd if=/dev/zero of=disk count=10000
cat bootblock 8.out | dd of=disk conv=notrunc
- bochs
Use the built-in print(text string) function to print to the
console.
+
+BOCHS
+
You may have to tweak the .bochsrc depending on your system,
and you may need to install the Bochs emulator.
+ $ cp dot-bochsrc .bochsrc
+ $ $EDITOR .bochsrc # tweak it if required
+ $ bochs
+
+
+ORACLE xVM VIRTUALBOX
+
+Install VirtualBox. Then:
+
+ Build 'disk' (described above under '386').
+
+ $ VBoxManage convertfromraw disk go-tiny.vdi
+ $ VirtualBox
+ create a new VM; as disk use the go-tiny.vdi image.
+ start the vm.
+
+
+QEMU / KVM
+
+This should work the same for qemu and kvm (really: qemu-kvm).
+
+ Build 'disk' (described above under '386').
+
+ $ qemu -hda disk
+
ARM
diff --git a/src/pkg/runtime/tiny/mem.c b/src/pkg/runtime/tiny/mem.c
index a66a4a731..7abecfba0 100644
--- a/src/pkg/runtime/tiny/mem.c
+++ b/src/pkg/runtime/tiny/mem.c
@@ -8,34 +8,43 @@
// Assume there's an arbitrary amount of memory starting at "end".
// Sizing PC memory is beyond the scope of this demo.
+static byte *allocp;
+
void*
-SysAlloc(uintptr ask)
+runtime·SysAlloc(uintptr ask)
{
- static byte *p;
extern byte end[];
byte *q;
- if(p == nil) {
- p = end;
- p += 7 & -(uintptr)p;
+ if(allocp == nil) {
+ allocp = end;
+ allocp += 7 & -(uintptr)allocp;
}
ask += 7 & -ask;
- q = p;
- p += ask;
- ·memclr(q, ask);
+ q = allocp;
+ allocp += ask;
+ runtime·memclr(q, ask);
return q;
}
void
-SysFree(void *v, uintptr n)
+runtime·SysFree(void *v, uintptr n)
{
- USED(v, n);
+ // Push pointer back if this is a free
+ // of the most recent SysAlloc.
+ n += 7 & -n;
+ if(allocp == (byte*)v+n)
+ allocp -= n;
}
void
-SysUnused(void *v, uintptr n)
+runtime·SysUnused(void *v, uintptr n)
{
USED(v, n);
}
+void
+runtime·SysMemInit(void)
+{
+}
diff --git a/src/pkg/runtime/tiny/runtime_defs.go b/src/pkg/runtime/tiny/runtime_defs.go
new file mode 100644
index 000000000..86de13316
--- /dev/null
+++ b/src/pkg/runtime/tiny/runtime_defs.go
@@ -0,0 +1,14 @@
+// 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.
+
+// OS-Specific Go definitions of internal structures. Master is runtime.h
+
+package runtime
+
+type lock struct {
+ key uint32
+ sema uint32
+}
+
+type note lock
diff --git a/src/pkg/runtime/tiny/thread.c b/src/pkg/runtime/tiny/thread.c
index e4b58256f..0572ecb77 100644
--- a/src/pkg/runtime/tiny/thread.c
+++ b/src/pkg/runtime/tiny/thread.c
@@ -7,22 +7,28 @@
int8 *goos = "tiny";
void
-minit(void)
+runtime·minit(void)
{
}
void
-osinit(void)
+runtime·osinit(void)
{
}
void
-initsig(int32 queue)
+runtime·goenvs(void)
{
+ runtime·goenvs_unix();
}
void
-exit(int32)
+runtime·initsig(int32 queue)
+{
+}
+
+void
+runtime·exit(int32)
{
for(;;);
}
@@ -31,50 +37,56 @@ exit(int32)
// so no need for real concurrency or atomicity
void
-newosproc(M *m, G *g, void *stk, void (*fn)(void))
+runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
{
USED(m, g, stk, fn);
- throw("newosproc");
+ runtime·throw("newosproc");
}
void
-lock(Lock *l)
+runtime·lock(Lock *l)
{
if(m->locks < 0)
- throw("lock count");
+ runtime·throw("lock count");
m->locks++;
if(l->key != 0)
- throw("deadlock");
+ runtime·throw("deadlock");
l->key = 1;
}
void
-unlock(Lock *l)
+runtime·unlock(Lock *l)
{
m->locks--;
if(m->locks < 0)
- throw("lock count");
+ runtime·throw("lock count");
if(l->key != 1)
- throw("unlock of unlocked lock");
+ runtime·throw("unlock of unlocked lock");
l->key = 0;
}
+void
+runtime·destroylock(Lock *l)
+{
+ // nothing
+}
+
void
-noteclear(Note *n)
+runtime·noteclear(Note *n)
{
n->lock.key = 0;
}
void
-notewakeup(Note *n)
+runtime·notewakeup(Note *n)
{
n->lock.key = 1;
}
void
-notesleep(Note *n)
+runtime·notesleep(Note *n)
{
if(n->lock.key != 1)
- throw("notesleep");
+ runtime·throw("notesleep");
}