2008-06-05 20:38:39 -06:00
|
|
|
// Copyright 2009 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.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* basic types
|
|
|
|
*/
|
|
|
|
typedef signed char int8;
|
|
|
|
typedef unsigned char uint8;
|
|
|
|
typedef signed short int16;
|
|
|
|
typedef unsigned short uint16;
|
|
|
|
typedef signed int int32;
|
|
|
|
typedef unsigned int uint32;
|
|
|
|
typedef signed long long int int64;
|
|
|
|
typedef unsigned long long int uint64;
|
|
|
|
typedef float float32;
|
|
|
|
typedef double float64;
|
2008-11-17 13:32:35 -07:00
|
|
|
typedef uint64 uintptr;
|
2008-06-05 20:38:39 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get rid of C types
|
2008-11-23 18:08:55 -07:00
|
|
|
* the / / / forces a syntax error immediately,
|
|
|
|
* which will show "last name: XXunsigned".
|
2008-06-05 20:38:39 -06:00
|
|
|
*/
|
2008-11-23 18:08:55 -07:00
|
|
|
#define unsigned XXunsigned / / /
|
|
|
|
#define signed XXsigned / / /
|
|
|
|
#define char XXchar / / /
|
|
|
|
#define short XXshort / / /
|
|
|
|
#define int XXint / / /
|
|
|
|
#define long XXlong / / /
|
|
|
|
#define float XXfloat / / /
|
|
|
|
#define double XXdouble / / /
|
2008-06-05 20:38:39 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* defined types
|
|
|
|
*/
|
|
|
|
typedef uint8 bool;
|
|
|
|
typedef uint8 byte;
|
2008-11-23 18:08:55 -07:00
|
|
|
typedef struct Alg Alg;
|
2008-08-27 18:28:30 -06:00
|
|
|
typedef struct Array Array;
|
2008-11-23 18:08:55 -07:00
|
|
|
typedef struct Func Func;
|
2008-07-13 15:29:46 -06:00
|
|
|
typedef struct G G;
|
2008-11-23 18:08:55 -07:00
|
|
|
typedef struct Gobuf Gobuf;
|
2008-08-04 17:43:49 -06:00
|
|
|
typedef struct Lock Lock;
|
2008-11-23 18:08:55 -07:00
|
|
|
typedef struct M M;
|
2008-08-04 17:43:49 -06:00
|
|
|
typedef struct Mem Mem;
|
2008-11-23 18:08:55 -07:00
|
|
|
typedef union Note Note;
|
|
|
|
typedef struct Stktop Stktop;
|
|
|
|
typedef struct String *string;
|
|
|
|
typedef struct Usema Usema;
|
2008-07-13 15:29:46 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* per cpu declaration
|
|
|
|
*/
|
|
|
|
extern register G* g; // R15
|
|
|
|
extern register M* m; // R14
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defined constants
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// G status
|
|
|
|
Gidle,
|
|
|
|
Grunnable,
|
2008-08-04 17:43:49 -06:00
|
|
|
Grunning,
|
2008-07-14 15:33:39 -06:00
|
|
|
Gwaiting,
|
2008-08-05 15:18:47 -06:00
|
|
|
Gmoribund,
|
2008-07-13 15:29:46 -06:00
|
|
|
Gdead,
|
|
|
|
};
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
true = 1,
|
|
|
|
false = 0,
|
|
|
|
};
|
2008-11-17 13:32:35 -07:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SmallFreeClasses = 168, // number of small free lists in malloc
|
|
|
|
};
|
2008-07-13 15:29:46 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* structures
|
|
|
|
*/
|
2008-08-04 17:43:49 -06:00
|
|
|
struct Lock
|
|
|
|
{
|
|
|
|
uint32 key;
|
2008-09-09 12:50:14 -06:00
|
|
|
uint32 sema; // for OS X
|
2008-08-04 17:43:49 -06:00
|
|
|
};
|
2008-09-24 11:25:28 -06:00
|
|
|
struct Usema
|
|
|
|
{
|
|
|
|
uint32 u;
|
|
|
|
uint32 k;
|
|
|
|
};
|
2008-09-09 12:50:14 -06:00
|
|
|
union Note
|
2008-08-04 17:43:49 -06:00
|
|
|
{
|
2008-09-09 12:50:14 -06:00
|
|
|
struct { // Linux
|
|
|
|
Lock lock;
|
|
|
|
};
|
|
|
|
struct { // OS X
|
|
|
|
int32 wakeup;
|
2008-09-24 11:25:28 -06:00
|
|
|
Usema sema;
|
2008-09-09 12:50:14 -06:00
|
|
|
};
|
2008-08-04 17:43:49 -06:00
|
|
|
};
|
2008-07-13 15:29:46 -06:00
|
|
|
struct String
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
|
|
|
int32 len;
|
|
|
|
byte str[1];
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
2008-08-27 18:28:30 -06:00
|
|
|
|
|
|
|
struct Array
|
|
|
|
{ // must not move anything
|
|
|
|
byte* array; // actual data
|
|
|
|
uint32 nel; // number of elements
|
2008-11-17 13:32:35 -07:00
|
|
|
uint32 cap; // allocated number of elements
|
2008-08-27 18:28:30 -06:00
|
|
|
byte b[8]; // actual array - may not be contig
|
|
|
|
};
|
2008-07-11 20:16:39 -06:00
|
|
|
struct Gobuf
|
|
|
|
{
|
|
|
|
byte* SP;
|
|
|
|
byte* PC;
|
|
|
|
};
|
2008-07-09 12:35:26 -06:00
|
|
|
struct G
|
2008-07-08 18:19:17 -06:00
|
|
|
{
|
|
|
|
byte* stackguard; // must not move
|
|
|
|
byte* stackbase; // must not move
|
2008-07-16 14:50:23 -06:00
|
|
|
byte* stack0; // first stack segment
|
2008-07-11 20:16:39 -06:00
|
|
|
Gobuf sched;
|
2008-07-28 12:29:41 -06:00
|
|
|
G* alllink; // on allg
|
2008-07-25 16:55:12 -06:00
|
|
|
void* param; // passed parameter on wakeup
|
|
|
|
int16 status;
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 goid;
|
2008-07-25 16:55:12 -06:00
|
|
|
int32 selgen; // valid sudog pointer
|
2008-08-05 15:18:47 -06:00
|
|
|
G* schedlink;
|
2008-09-24 15:13:07 -06:00
|
|
|
bool readyonstop;
|
2008-08-04 17:43:49 -06:00
|
|
|
M* m; // for debuggers
|
|
|
|
};
|
|
|
|
struct Mem
|
|
|
|
{
|
|
|
|
uint8* hunk;
|
|
|
|
uint32 nhunk;
|
|
|
|
uint64 nmmap;
|
|
|
|
uint64 nmal;
|
2008-07-08 18:19:17 -06:00
|
|
|
};
|
|
|
|
struct M
|
|
|
|
{
|
2008-07-11 20:16:39 -06:00
|
|
|
G* g0; // g0 w interrupt stack - must not move
|
|
|
|
uint64 morearg; // arg to morestack - must not move
|
2008-07-16 14:50:23 -06:00
|
|
|
uint64 cret; // return value from C - must not move
|
2008-09-09 12:50:14 -06:00
|
|
|
uint64 procid; // for debuggers - must not move
|
2008-09-18 16:56:46 -06:00
|
|
|
G* gsignal; // signal-handling G - must not move
|
2008-07-11 20:16:39 -06:00
|
|
|
G* curg; // current running goroutine
|
2008-07-16 14:50:23 -06:00
|
|
|
G* lastg; // last running goroutine - to emulate fifo
|
2008-07-11 20:16:39 -06:00
|
|
|
Gobuf sched;
|
|
|
|
Gobuf morestack;
|
|
|
|
byte* moresp;
|
|
|
|
int32 siz1;
|
|
|
|
int32 siz2;
|
2008-11-25 17:48:10 -07:00
|
|
|
int32 id;
|
2008-08-05 15:18:47 -06:00
|
|
|
Note havenextg;
|
|
|
|
G* nextg;
|
|
|
|
M* schedlink;
|
2008-08-04 17:43:49 -06:00
|
|
|
Mem mem;
|
2008-09-09 12:50:14 -06:00
|
|
|
uint32 machport; // Return address for Mach IPC (OS X)
|
2008-11-17 13:32:35 -07:00
|
|
|
void* freelist[SmallFreeClasses];
|
2008-07-11 20:16:39 -06:00
|
|
|
};
|
2008-07-14 15:33:39 -06:00
|
|
|
struct Stktop
|
2008-07-13 15:29:46 -06:00
|
|
|
{
|
2008-07-11 20:16:39 -06:00
|
|
|
uint8* oldbase;
|
|
|
|
uint8* oldsp;
|
|
|
|
uint64 magic;
|
|
|
|
uint8* oldguard;
|
2008-07-08 18:19:17 -06:00
|
|
|
};
|
2008-07-13 15:29:46 -06:00
|
|
|
struct Alg
|
2008-07-11 20:16:39 -06:00
|
|
|
{
|
2008-07-13 15:29:46 -06:00
|
|
|
uint64 (*hash)(uint32, void*);
|
|
|
|
uint32 (*equal)(uint32, void*, void*);
|
|
|
|
void (*print)(uint32, void*);
|
|
|
|
void (*copy)(uint32, void*, void*);
|
2008-07-11 20:16:39 -06:00
|
|
|
};
|
2008-07-13 15:29:46 -06:00
|
|
|
struct SigTab
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
2008-07-13 15:29:46 -06:00
|
|
|
int32 catch;
|
|
|
|
int8 *name;
|
2008-06-05 20:38:39 -06:00
|
|
|
};
|
|
|
|
|
2008-11-23 18:08:55 -07:00
|
|
|
// (will be) shared with go; edit ../cmd/6g/sys.go too.
|
|
|
|
// should move out of sys.go eventually.
|
|
|
|
// also eventually, the loaded symbol table should
|
|
|
|
// be closer to this form.
|
|
|
|
struct Func
|
|
|
|
{
|
|
|
|
string name;
|
use pc/ln table to print source lines in traceback
r45=; 6.out
oops
panic PC=0x400316
0x400316?zi /home/rsc/go/src/runtime/rt0_amd64_linux.s:83
main·g(4195177, 0, 4205661, ...)
main·g(0x400369, 0x402c5d, 0x403e49, ...)
0x40034c?zi /home/rsc/go/src/runtime/x.go:24
main·f(4205661, 0, 4210249, ...)
main·f(0x402c5d, 0x403e49, 0x1, ...)
0x400368?zi /home/rsc/go/src/runtime/x.go:37
main·main(4210249, 0, 1, ...)
main·main(0x403e49, 0x1, 0x7fff9d894bd8, ...)
0x402c5c?zi /home/rsc/go/src/runtime/rt0_amd64.s:70
mainstart(1, 0, 2643020760, ...)
mainstart(0x1, 0x7fff9d894bd8, 0x0, ...)
r45=;
R=r
DELTA=251 (198 added, 25 deleted, 28 changed)
OCL=19965
CL=19979
2008-11-25 10:23:36 -07:00
|
|
|
string type; // go type string
|
|
|
|
string src; // src file name
|
|
|
|
uint64 entry; // entry pc
|
|
|
|
int64 frame; // stack frame size
|
|
|
|
Array pcln; // pc/ln tab for this func
|
|
|
|
int64 pc0; // starting pc, ln for table
|
|
|
|
int32 ln0;
|
2008-11-25 17:48:10 -07:00
|
|
|
int32 args; // number of 32-bit in/out args
|
|
|
|
int32 locals; // number of 32-bit locals
|
2008-11-23 18:08:55 -07:00
|
|
|
};
|
|
|
|
|
2008-06-05 20:38:39 -06:00
|
|
|
/*
|
|
|
|
* defined macros
|
|
|
|
* you need super-goru privilege
|
|
|
|
* to add this list.
|
|
|
|
*/
|
|
|
|
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
|
#define nil ((void*)0)
|
|
|
|
|
2008-07-13 15:29:46 -06:00
|
|
|
/*
|
|
|
|
* external data
|
|
|
|
*/
|
|
|
|
extern Alg algarray[3];
|
|
|
|
extern string emptystring;
|
|
|
|
G* allg;
|
|
|
|
int32 goidgen;
|
2008-08-04 17:43:49 -06:00
|
|
|
extern int32 gomaxprocs;
|
2008-09-12 10:44:41 -06:00
|
|
|
extern int32 panicking;
|
2008-11-05 22:50:28 -07:00
|
|
|
extern int32 maxround;
|
2008-07-13 15:29:46 -06:00
|
|
|
|
2008-06-30 12:50:36 -06:00
|
|
|
/*
|
|
|
|
* common functions and data
|
|
|
|
*/
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 strcmp(byte*, byte*);
|
2008-11-23 18:08:55 -07:00
|
|
|
int32 findnull(byte*);
|
2008-06-30 12:50:36 -06:00
|
|
|
void dump(byte*, int32);
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 runetochar(byte*, int32);
|
|
|
|
int32 chartorune(uint32*, byte*);
|
2008-06-30 12:50:36 -06:00
|
|
|
|
2008-06-05 20:38:39 -06:00
|
|
|
/*
|
2008-06-16 23:34:50 -06:00
|
|
|
* very low level c-called
|
2008-06-05 20:38:39 -06:00
|
|
|
*/
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 gogo(Gobuf*);
|
|
|
|
int32 gosave(Gobuf*);
|
2008-07-12 12:30:53 -06:00
|
|
|
int32 gogoret(Gobuf*, uint64);
|
|
|
|
void retfromnewstack(void);
|
2008-07-11 20:16:39 -06:00
|
|
|
void setspgoto(byte*, void(*)(void), void(*)(void));
|
2008-06-05 20:38:39 -06:00
|
|
|
void FLUSH(void*);
|
2008-06-30 15:39:47 -06:00
|
|
|
void* getu(void);
|
2008-06-16 23:34:50 -06:00
|
|
|
void throw(int8*);
|
2008-07-13 15:29:46 -06:00
|
|
|
uint32 rnd(uint32, uint32);
|
2008-06-05 20:38:39 -06:00
|
|
|
void prints(int8*);
|
2008-11-25 17:48:10 -07:00
|
|
|
void printf(int8*, ...);
|
2008-11-23 18:08:55 -07:00
|
|
|
byte* mchr(byte*, byte, byte*);
|
2008-06-15 21:24:30 -06:00
|
|
|
void mcpy(byte*, byte*, uint32);
|
2008-11-13 11:35:44 -07:00
|
|
|
void mmov(byte*, byte*, uint32);
|
2008-06-15 21:24:30 -06:00
|
|
|
void* mal(uint32);
|
2008-06-16 23:34:50 -06:00
|
|
|
uint32 cmpstring(string, string);
|
2008-11-23 18:08:55 -07:00
|
|
|
string gostring(byte*);
|
2008-06-21 16:36:23 -06:00
|
|
|
void initsig(void);
|
2008-09-22 14:47:53 -06:00
|
|
|
int32 gotraceback(void);
|
2008-07-11 20:16:39 -06:00
|
|
|
void traceback(uint8 *pc, uint8 *sp, G* gp);
|
2008-07-28 12:29:41 -06:00
|
|
|
void tracebackothers(G*);
|
2008-07-14 21:54:55 -06:00
|
|
|
int32 open(byte*, int32, ...);
|
2008-06-26 15:09:26 -06:00
|
|
|
int32 read(int32, void*, int32);
|
2008-07-14 21:54:55 -06:00
|
|
|
int32 write(int32, void*, int32);
|
2008-06-26 15:09:26 -06:00
|
|
|
void close(int32);
|
|
|
|
int32 fstat(int32, void*);
|
2008-08-04 17:43:49 -06:00
|
|
|
bool cas(uint32*, uint32, uint32);
|
|
|
|
void exit1(int32);
|
|
|
|
void ready(G*);
|
|
|
|
byte* getenv(int8*);
|
|
|
|
int32 atoi(byte*);
|
2008-08-05 15:18:47 -06:00
|
|
|
void newosproc(M *m, G *g, void *stk, void (*fn)(void));
|
2008-09-18 16:56:46 -06:00
|
|
|
void sigaltstack(void*, void*);
|
|
|
|
void signalstack(byte*, int32);
|
|
|
|
G* malg(int32);
|
|
|
|
void minit(void);
|
2008-11-23 18:08:55 -07:00
|
|
|
Func* findfunc(uint64);
|
use pc/ln table to print source lines in traceback
r45=; 6.out
oops
panic PC=0x400316
0x400316?zi /home/rsc/go/src/runtime/rt0_amd64_linux.s:83
main·g(4195177, 0, 4205661, ...)
main·g(0x400369, 0x402c5d, 0x403e49, ...)
0x40034c?zi /home/rsc/go/src/runtime/x.go:24
main·f(4205661, 0, 4210249, ...)
main·f(0x402c5d, 0x403e49, 0x1, ...)
0x400368?zi /home/rsc/go/src/runtime/x.go:37
main·main(4210249, 0, 1, ...)
main·main(0x403e49, 0x1, 0x7fff9d894bd8, ...)
0x402c5c?zi /home/rsc/go/src/runtime/rt0_amd64.s:70
mainstart(1, 0, 2643020760, ...)
mainstart(0x1, 0x7fff9d894bd8, 0x0, ...)
r45=;
R=r
DELTA=251 (198 added, 25 deleted, 28 changed)
OCL=19965
CL=19979
2008-11-25 10:23:36 -07:00
|
|
|
int32 funcline(Func*, uint64);
|
2008-08-04 17:43:49 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mutual exclusion locks. in the uncontended case,
|
|
|
|
* as fast as spin locks (just a few user-level instructions),
|
|
|
|
* but on the contention path they sleep in the kernel.
|
2008-08-05 15:18:47 -06:00
|
|
|
* a zeroed Lock is unlocked (no need to initialize each lock).
|
2008-08-04 17:43:49 -06:00
|
|
|
*/
|
|
|
|
void lock(Lock*);
|
|
|
|
void unlock(Lock*);
|
|
|
|
|
|
|
|
/*
|
2008-08-05 15:18:47 -06:00
|
|
|
* sleep and wakeup on one-time events.
|
2008-08-05 15:21:42 -06:00
|
|
|
* before any calls to notesleep or notewakeup,
|
2008-08-05 15:18:47 -06:00
|
|
|
* must call noteclear to initialize the Note.
|
|
|
|
* then, any number of threads can call notesleep
|
|
|
|
* and exactly one thread can call notewakeup (once).
|
|
|
|
* once notewakeup has been called, all the notesleeps
|
|
|
|
* will return. future notesleeps will return immediately.
|
2008-08-04 17:43:49 -06:00
|
|
|
*/
|
2008-08-05 15:18:47 -06:00
|
|
|
void noteclear(Note*);
|
|
|
|
void notesleep(Note*);
|
|
|
|
void notewakeup(Note*);
|
2008-06-16 23:34:50 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* low level go -called
|
|
|
|
*/
|
2008-07-11 20:16:39 -06:00
|
|
|
void sys·goexit(void);
|
|
|
|
void sys·gosched(void);
|
2008-06-24 18:16:06 -06:00
|
|
|
void sys·exit(int32);
|
|
|
|
void sys·write(int32, void*, int32);
|
|
|
|
void sys·breakpoint(void);
|
|
|
|
uint8* sys·mmap(byte*, uint32, int32, int32, int32, uint32);
|
|
|
|
void sys·memclr(byte*, uint32);
|
2008-07-24 16:57:30 -06:00
|
|
|
void sys·setcallerpc(void*, void*);
|
2008-06-24 18:16:06 -06:00
|
|
|
void* sys·getcallerpc(void*);
|
|
|
|
void sys·sigaction(int64, void*, void*);
|
|
|
|
void sys·rt_sigaction(int64, void*, void*, uint64);
|
2008-06-05 20:38:39 -06:00
|
|
|
|
|
|
|
/*
|
2008-06-16 23:34:50 -06:00
|
|
|
* runtime go-called
|
2008-06-05 20:38:39 -06:00
|
|
|
*/
|
2008-06-24 18:16:06 -06:00
|
|
|
void sys·printbool(bool);
|
|
|
|
void sys·printfloat(float64);
|
|
|
|
void sys·printint(int64);
|
|
|
|
void sys·printstring(string);
|
2008-06-30 12:50:36 -06:00
|
|
|
void sys·printpc(void*);
|
2008-06-24 18:16:06 -06:00
|
|
|
void sys·printpointer(void*);
|
2008-11-25 17:48:10 -07:00
|
|
|
void sys·printuint(uint64);
|
|
|
|
void sys·printhex(uint64);
|
2008-06-24 18:16:06 -06:00
|
|
|
void sys·catstring(string, string, string);
|
|
|
|
void sys·cmpstring(string, string, int32);
|
|
|
|
void sys·slicestring(string, int32, int32, string);
|
|
|
|
void sys·indexstring(string, int32, byte);
|
|
|
|
void sys·intstring(int64, string);
|
2008-11-10 15:54:10 -07:00
|
|
|
bool isInf(float64, int32);
|
|
|
|
bool isNaN(float64);
|
2008-07-08 11:36:43 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User go-called
|
|
|
|
*/
|
2008-06-26 15:09:26 -06:00
|
|
|
void sys·readfile(string, string, bool);
|
2008-07-08 11:36:43 -06:00
|
|
|
void sys·bytestorune(byte*, int32, int32, int32, int32);
|
2008-10-07 11:03:34 -06:00
|
|
|
void sys·stringtorune(string, int32, int32, int32);
|