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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get rid of C types
|
|
|
|
*/
|
|
|
|
#define unsigned XXunsigned
|
|
|
|
#define signed XXsigned
|
|
|
|
#define char XXchar
|
|
|
|
#define short XXshort
|
|
|
|
#define int XXint
|
|
|
|
#define long XXlong
|
|
|
|
#define float XXfloat
|
|
|
|
#define double XXdouble
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defined types
|
|
|
|
*/
|
|
|
|
typedef uint8 bool;
|
|
|
|
typedef uint8 byte;
|
2008-07-13 15:29:46 -06:00
|
|
|
typedef struct String *string;
|
|
|
|
typedef struct Sigs Sigs;
|
|
|
|
typedef struct Sigi Sigi;
|
|
|
|
typedef struct Map Map;
|
|
|
|
typedef struct Gobuf Gobuf;
|
|
|
|
typedef struct G G;
|
|
|
|
typedef struct M M;
|
|
|
|
typedef struct Stktop Stktop;
|
|
|
|
typedef struct Alg Alg;
|
2008-07-14 15:33:39 -06:00
|
|
|
typedef struct WaitQ WaitQ;
|
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-07-14 15:33:39 -06:00
|
|
|
Gwaiting,
|
2008-07-13 15:29:46 -06:00
|
|
|
Gdead,
|
|
|
|
};
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
true = 1,
|
|
|
|
false = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* structures
|
|
|
|
*/
|
|
|
|
struct String
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
|
|
|
int32 len;
|
|
|
|
byte str[1];
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
|
|
|
struct Sigs
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
|
|
|
byte* name;
|
|
|
|
uint32 hash;
|
|
|
|
void (*fun)(void);
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
|
|
|
struct Sigi
|
2008-06-05 20:38:39 -06:00
|
|
|
{
|
|
|
|
byte* name;
|
|
|
|
uint32 hash;
|
|
|
|
uint32 offset;
|
2008-07-13 15:29:46 -06:00
|
|
|
};
|
2008-06-05 20:38:39 -06:00
|
|
|
struct Map
|
|
|
|
{
|
|
|
|
Sigi* si;
|
|
|
|
Sigs* ss;
|
|
|
|
Map* link;
|
|
|
|
int32 bad;
|
|
|
|
int32 unused;
|
|
|
|
void (*fun[])(void);
|
|
|
|
};
|
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-14 15:33:39 -06:00
|
|
|
G* alllink; // on allq
|
|
|
|
G* qlink; // on wait q
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 status;
|
|
|
|
int32 goid;
|
2008-07-14 15:33:39 -06:00
|
|
|
byte elem[8]; // transfer element for chan
|
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-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-07-14 15:33:39 -06:00
|
|
|
struct WaitQ
|
|
|
|
{
|
|
|
|
G* first;
|
|
|
|
G* last;
|
|
|
|
};
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
M* allm;
|
|
|
|
G* allg;
|
|
|
|
int32 goidgen;
|
|
|
|
|
2008-06-30 12:50:36 -06:00
|
|
|
/*
|
|
|
|
* common functions and data
|
|
|
|
*/
|
2008-07-11 20:16:39 -06:00
|
|
|
int32 strcmp(byte*, byte*);
|
|
|
|
int32 findnull(int8*);
|
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-07-14 15:33:39 -06:00
|
|
|
G* dequeue(WaitQ*);
|
|
|
|
void enqueue(WaitQ*, G*);
|
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-06-15 21:24:30 -06:00
|
|
|
void mcpy(byte*, byte*, uint32);
|
|
|
|
void* mal(uint32);
|
2008-06-16 23:34:50 -06:00
|
|
|
uint32 cmpstring(string, string);
|
2008-06-21 16:36:23 -06:00
|
|
|
void initsig(void);
|
2008-07-11 20:16:39 -06:00
|
|
|
void traceback(uint8 *pc, uint8 *sp, G* gp);
|
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-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);
|
|
|
|
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*);
|
|
|
|
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);
|
|
|
|
void sys·ifaces2i(Sigi*, Sigs*, Map*, void*);
|
|
|
|
void sys·ifacei2i(Sigi*, Map*, void*);
|
|
|
|
void sys·ifacei2s(Sigs*, Map*, void*);
|
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);
|
|
|
|
void sys·stringtorune(string, int32, int32, int32, int32);
|