Commit 528ccdc5 authored by Anthony Martin's avatar Anthony Martin Committed by Russ Cox

runtime: fix Plan 9 build

This change adds the osyield and usleep
functions and code to read the number of
processors from /dev/sysstat.

I also changed SysAlloc to return nil
when brk fails (it was returning -1).

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5177049
parent 319dba47
......@@ -14,9 +14,21 @@ TEXT runtime·open(SB),7,$0
INT $64
RET
// TODO(ality): remove use of deprecated system calls
TEXT runtime·read(SB),7,$0
MOVL $15, AX
INT $64
RET
TEXT runtime·write(SB),7,$0
MOVL $20, AX
INT $64
MOVL $20, AX
INT $64
RET
TEXT runtime·close(SB),7,$0
MOVL $4, AX
INT $64
RET
TEXT runtime·exits(SB),7,$0
......@@ -29,6 +41,11 @@ TEXT runtime·brk_(SB),7,$0
INT $64
RET
TEXT runtime·sleep(SB),7,$0
MOVL $17, AX
INT $64
RET
TEXT runtime·plan9_semacquire(SB),7,$0
MOVL $37, AX
INT $64
......
......@@ -26,7 +26,7 @@ runtime·SysAlloc(uintptr nbytes)
bl = ((uintptr)bloc + Round) & ~Round;
if(runtime·brk_((void*)(bl + nbytes)) < 0) {
runtime·unlock(&memlock);
return (void*)-1;
return nil;
}
bloc = (byte*)bl + nbytes;
runtime·unlock(&memlock);
......
......@@ -2,9 +2,16 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
extern int32 runtime·write(int32 fd, void* buffer, int32 nbytes);
extern void runtime·exits(int8* msg);
extern int32 runtime·brk_(void*);
// Plan 9-specific system calls
int32 runtime·open(uint8 *file, int32 mode);
int32 runtime·read(int32 fd, void *buf, int32 nbytes);
int32 runtime·close(int32 fd);
void runtime·exits(int8* msg);
int32 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);
int32 runtime·plan9_semrelease(uint32 *addr, int32 count);
/* open */
enum
......@@ -52,6 +59,3 @@ struct Tos {
/* top of stack is here */
};
extern int32 runtime·rfork(int32 flags, void *stk, M *m, G *g, void (*fn)(void));
extern int32 runtime·plan9_semacquire(uint32 *addr, int32 block);
extern int32 runtime·plan9_semrelease(uint32 *addr, int32 count);
......@@ -12,9 +12,33 @@ runtime·minit(void)
{
}
static int32
getproccount(void)
{
int32 fd, i, n, ncpu;
byte buf[2048];
fd = runtime·open((byte*)"/dev/sysstat", OREAD);
if(fd < 0)
return 1;
ncpu = 0;
for(;;) {
n = runtime·read(fd, buf, sizeof buf);
if(n <= 0)
break;
for(i = 0; i < n; i++) {
if(buf[i] == '\n')
ncpu++;
}
}
runtime·close(fd);
return ncpu > 0 ? ncpu : 1;
}
void
runtime·osinit(void)
{
runtime·ncpu = getproccount();
}
void
......@@ -23,8 +47,25 @@ runtime·goenvs(void)
}
void
runtime·initsig(int32 queue)
runtime·initsig(int32)
{
}
void
runtime·osyield(void)
{
runtime·sleep(0);
}
void
runtime·usleep(uint32 µs)
{
uint32 ms;
ms = µs/1000;
if(ms == 0)
ms = 1;
runtime·sleep(ms);
}
extern Tos *_tos;
......@@ -68,7 +109,7 @@ runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
stk, m, g, fn, runtime·rfork, m->id, m->tls[0], &m);
}
if (runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, m, g, fn) < 0 )
if(runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, m, g, fn) < 0)
runtime·throw("newosproc: rfork failed");
}
......
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