Commit c0aac20e authored by Kai Backman's avatar Kai Backman Committed by Russ Cox

combined pchw and embedded into tiny. added section on arm to README

R=rsc
CC=golang-dev
https://golang.org/cl/194151
parent c3fa32c7
small embedded target for arm
define the c function write to make debug output work
// 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"
#include "malloc.h"
// Assume there's an arbitrary amount of memory starting at "end".
void*
SysAlloc(uintptr ask)
{
static byte *p;
extern byte end[];
byte *q;
if(p == nil) {
p = end;
p += 7 & -(uintptr)p;
}
ask += 7 & -ask;
q = p;
p += ask;
·memclr(q, ask);
return q;
}
void
SysFree(void *v, uintptr n)
{
USED(v, n);
}
void
SysUnused(void *v, uintptr n)
{
USED(v, n);
}
// 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"
int8 *goos = "pchw";
extern void ·write(int32 fd, void *v, int32 len, int32 cap); // slice, spelled out
int32
write(int32 fd, void *v, int32 len)
{
·write(fd, v, len, len);
return len;
}
void
minit(void)
{
}
void
osinit(void)
{
}
void
initsig(void)
{
}
void
exit(int32)
{
for(;;);
}
// single processor, no interrupts,
// so no need for real concurrency or atomicity
void
newosproc(M *m, G *g, void *stk, void (*fn)(void))
{
USED(m, g, stk, fn);
throw("newosproc");
}
void
lock(Lock *l)
{
if(m->locks < 0)
throw("lock count");
m->locks++;
if(l->key != 0)
throw("deadlock");
l->key = 1;
}
void
unlock(Lock *l)
{
m->locks--;
if(m->locks < 0)
throw("lock count");
if(l->key != 1)
throw("unlock of unlocked lock");
l->key = 0;
}
void
noteclear(Note *n)
{
n->lock.key = 0;
}
void
notewakeup(Note *n)
{
n->lock.key = 1;
}
void
notesleep(Note *n)
{
if(n->lock.key != 1)
throw("notesleep");
}
// just the write function
extern void ·write(int32 fd, void *v, int32 len, int32 cap); // slice, spelled out
int32
write(int32 fd, void *v, int32 len)
{
·write(fd, v, len, len);
return len;
}
This directory contains a simple example of how one might This directory contains a simple example of how one might
start Go running on bare hardware. It is very primitive but start Go running on bare hardware. There is currently code
can run go/test/sieve.go, the concurrent prime sieve, on a for 386 and arm.
uniprocessor. It has only been tested using the Bochs emulator.
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.
To run, first build the tools by running all.bash with GOARCH=386 To run, first build the tools by running all.bash with GOARCH=386
and GOOS set to your normal GOOS (linux, darwin). Then: and GOOS set to your normal GOOS (linux, darwin). Then:
export GOOS=pchw export GOOS=tiny
cd $GOROOT/src/pkg/runtime cd $GOROOT/src/pkg/runtime
make clean make clean
make install make install
cd pchw cd tiny
8g $GOROOT/test/sieve.go 8g $GOROOT/test/sieve.go
8l sieve.8 8l sieve.8
8l -a sieve.8 >sieve.asm # can consult sieve.asm for debugging 8l -a sieve.8 >sieve.asm # can consult sieve.asm for debugging
...@@ -22,8 +28,43 @@ You may have to tweak the .bochsrc depending on your system, ...@@ -22,8 +28,43 @@ You may have to tweak the .bochsrc depending on your system,
and you may need to install the Bochs emulator. and you may need to install the Bochs emulator.
ARM
First build the toolchain using GOARCH=arm and GOOS=linux. When
you build your embedded code set GOARCH=tiny.
export GOOS=tiny
cd $GOROOT/src/pkg/runtime
make clean
make install
On arm the tiny runtime doesn't define a low level write function. You can either
define a stub if you don't need debug output, or more usefully, define it to
print to some debug serial port. Here is a sample function that prints to
the DBGU on an at91sam7s:
#define DBGU_CSR ((uint32*) 0xFFFFF214) // (DBGU) Channel Status Register
#define US_TXRDY ((uint32) 0x1 << 1) // (DBGU) TXRDY Interrupt
#define DBGU_THR ((uint32*) 0xFFFFF21C) // (DBGU) Transmitter Holding Register
int32
write(int32 fd, void* b, int32 n)
{
uint32 i;
uint8* s = (uint8*)b;
for (i = 0; i < n; i++) {
while ((*DBGU_CSR & US_TXRDY) == 0) {
}
*DBGU_THR = *s;
s++;
}
return n;
}
The bootblock is from MIT's xv6 project and carries this notice: The 386 bootblock is from MIT's xv6 project and carries this notice:
The xv6 software is: The xv6 software is:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "runtime.h" #include "runtime.h"
int8 *goos = "embedded"; int8 *goos = "tiny";
void void
minit(void) minit(void)
......
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