blob: 1e89a4578056b47553926712d8ccd21e0cb30c97 [file] [log] [blame]
Ken Thompsonbbb20732008-06-05 19:38:39 -07001// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Ken Thompsonbbb20732008-06-05 19:38:39 -07005/*
6 * basic types
7 */
8typedef signed char int8;
9typedef unsigned char uint8;
10typedef signed short int16;
11typedef unsigned short uint16;
12typedef signed int int32;
13typedef unsigned int uint32;
14typedef signed long long int int64;
15typedef unsigned long long int uint64;
16typedef float float32;
17typedef double float64;
Russ Cox0d3a0432009-03-30 00:01:07 -070018
19#ifdef _64BIT
Russ Cox75647d22008-11-17 12:32:35 -080020typedef uint64 uintptr;
Russ Cox0d3a0432009-03-30 00:01:07 -070021#else
22typedef uint32 uintptr;
23#endif
Ken Thompsonbbb20732008-06-05 19:38:39 -070024
25/*
26 * get rid of C types
Russ Cox3aa063d2008-11-23 17:08:55 -080027 * the / / / forces a syntax error immediately,
28 * which will show "last name: XXunsigned".
Ken Thompsonbbb20732008-06-05 19:38:39 -070029 */
Russ Cox3aa063d2008-11-23 17:08:55 -080030#define unsigned XXunsigned / / /
31#define signed XXsigned / / /
32#define char XXchar / / /
33#define short XXshort / / /
34#define int XXint / / /
35#define long XXlong / / /
36#define float XXfloat / / /
37#define double XXdouble / / /
Ken Thompsonbbb20732008-06-05 19:38:39 -070038
39/*
40 * defined types
41 */
42typedef uint8 bool;
43typedef uint8 byte;
Ken Thompson594175d2008-07-13 14:29:46 -070044typedef struct Alg Alg;
Russ Cox3aa063d2008-11-23 17:08:55 -080045typedef struct Func Func;
46typedef struct G G;
47typedef struct Gobuf Gobuf;
Russ Coxd28acc42008-08-04 16:43:49 -070048typedef struct Lock Lock;
Russ Cox3aa063d2008-11-23 17:08:55 -080049typedef struct M M;
Russ Coxd28acc42008-08-04 16:43:49 -070050typedef struct Mem Mem;
Russ Cox3aa063d2008-11-23 17:08:55 -080051typedef union Note Note;
Rob Pike87f22082009-08-25 15:54:25 -070052typedef struct Slice Slice;
Russ Cox3aa063d2008-11-23 17:08:55 -080053typedef struct Stktop Stktop;
Ken Thompson36570612009-04-09 18:16:21 -070054typedef struct String String;
Russ Cox3aa063d2008-11-23 17:08:55 -080055typedef struct Usema Usema;
Russ Coxc3077f72008-12-19 17:11:54 -080056typedef struct SigTab SigTab;
57typedef struct MCache MCache;
58typedef struct Iface Iface;
Russ Coxc7513ea2009-07-07 11:02:54 -070059typedef struct Itab Itab;
Russ Cox2da50222009-05-20 14:57:55 -070060typedef struct Eface Eface;
Russ Coxc7513ea2009-07-07 11:02:54 -070061typedef struct Type Type;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -080062typedef struct Defer Defer;
Russ Cox764b6ec2009-07-08 13:55:57 -070063typedef struct hash Hmap;
Russ Cox5ddaf9a2009-07-08 15:00:54 -070064typedef struct Hchan Hchan;
Ken Thompson594175d2008-07-13 14:29:46 -070065
66/*
Rob Piked08f0062009-08-11 13:30:35 -070067 * per-cpu declaration.
68 * "extern register" is a special storage class implemented by 6c, 8c, etc.
69 * on machines with lots of registers, it allocates a register that will not be
70 * used in generated code. on the x86, it allocates a slot indexed by a
71 * segment register.
72 *
73 * amd64: allocated downwards from R15
74 * x86: allocated upwards from 0(FS)
75 * arm: allocated upwards from R9
Russ Cox653cef12009-08-26 10:47:18 -070076 *
Rob Piked08f0062009-08-11 13:30:35 -070077 * every C file linked into a Go program must include runtime.h
78 * so that the C compiler knows to avoid other uses of these registers.
79 * the Go compilers know to avoid them.
Ken Thompson594175d2008-07-13 14:29:46 -070080 */
Rob Piked08f0062009-08-11 13:30:35 -070081extern register G* g;
82extern register M* m;
Ken Thompson594175d2008-07-13 14:29:46 -070083
84/*
85 * defined constants
86 */
87enum
88{
89 // G status
90 Gidle,
91 Grunnable,
Russ Coxd28acc42008-08-04 16:43:49 -070092 Grunning,
Russ Cox3f8aa662008-12-05 15:24:18 -080093 Gsyscall,
Ken Thompson52620032008-07-14 14:33:39 -070094 Gwaiting,
Russ Cox96824002008-08-05 14:18:47 -070095 Gmoribund,
Ken Thompson594175d2008-07-13 14:29:46 -070096 Gdead,
97};
98enum
99{
100 true = 1,
101 false = 0,
102};
103
104/*
105 * structures
106 */
Russ Coxd28acc42008-08-04 16:43:49 -0700107struct Lock
108{
109 uint32 key;
Russ Cox376898c2008-09-09 11:50:14 -0700110 uint32 sema; // for OS X
Russ Coxd28acc42008-08-04 16:43:49 -0700111};
Russ Cox5ff12f82008-09-24 10:25:28 -0700112struct Usema
113{
114 uint32 u;
115 uint32 k;
116};
Russ Cox376898c2008-09-09 11:50:14 -0700117union Note
Russ Coxd28acc42008-08-04 16:43:49 -0700118{
Russ Cox376898c2008-09-09 11:50:14 -0700119 struct { // Linux
120 Lock lock;
121 };
122 struct { // OS X
123 int32 wakeup;
Russ Cox5ff12f82008-09-24 10:25:28 -0700124 Usema sema;
Russ Cox376898c2008-09-09 11:50:14 -0700125 };
Russ Coxd28acc42008-08-04 16:43:49 -0700126};
Ken Thompson594175d2008-07-13 14:29:46 -0700127struct String
Ken Thompsonbbb20732008-06-05 19:38:39 -0700128{
Ken Thompson36570612009-04-09 18:16:21 -0700129 byte* str;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700130 int32 len;
Ken Thompson594175d2008-07-13 14:29:46 -0700131};
Russ Coxc3077f72008-12-19 17:11:54 -0800132struct Iface
133{
Russ Coxc7513ea2009-07-07 11:02:54 -0700134 Itab* tab;
Ken Thompson36570612009-04-09 18:16:21 -0700135 void* data;
Russ Coxc3077f72008-12-19 17:11:54 -0800136};
Russ Cox2da50222009-05-20 14:57:55 -0700137struct Eface
138{
Russ Coxc7513ea2009-07-07 11:02:54 -0700139 Type* type;
Russ Cox2da50222009-05-20 14:57:55 -0700140 void* data;
141};
Ken Thompson66a603c2008-08-27 17:28:30 -0700142
Rob Pike87f22082009-08-25 15:54:25 -0700143struct Slice
Ken Thompson66a603c2008-08-27 17:28:30 -0700144{ // must not move anything
145 byte* array; // actual data
Rob Pike87f22082009-08-25 15:54:25 -0700146 uint32 len; // number of elements
Russ Cox75647d22008-11-17 12:32:35 -0800147 uint32 cap; // allocated number of elements
Ken Thompson66a603c2008-08-27 17:28:30 -0700148};
Ken Thompson751ce3a2008-07-11 19:16:39 -0700149struct Gobuf
150{
Russ Cox38020092009-06-17 16:31:02 -0700151 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700152 byte* sp;
153 byte* pc;
154 G* g;
Kai Backman111005d2009-06-25 11:26:10 -0700155 uintptr r0; // used on arm
Ken Thompson751ce3a2008-07-11 19:16:39 -0700156};
Ken Thompson7b454bb2008-07-09 11:35:26 -0700157struct G
Ken Thompson45288542008-07-08 17:19:17 -0700158{
Russ Cox38020092009-06-17 16:31:02 -0700159 byte* stackguard; // cannot move - also known to linker, libmach
160 byte* stackbase; // cannot move - also known to libmach
Russ Cox7343e032009-06-17 15:12:16 -0700161 Defer* defer;
Russ Cox38020092009-06-17 16:31:02 -0700162 Gobuf sched; // cannot move - also known to libmach
Ken Thompsone7d549f2008-07-16 13:50:23 -0700163 byte* stack0; // first stack segment
Russ Cox7343e032009-06-17 15:12:16 -0700164 byte* entry; // initial function
Rob Pike3835e012008-07-28 11:29:41 -0700165 G* alllink; // on allg
Ken Thompsone963cba2008-07-25 15:55:12 -0700166 void* param; // passed parameter on wakeup
167 int16 status;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700168 int32 goid;
Ken Thompsone963cba2008-07-25 15:55:12 -0700169 int32 selgen; // valid sudog pointer
Russ Cox96824002008-08-05 14:18:47 -0700170 G* schedlink;
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800171 bool readyonstop;
Russ Cox7343e032009-06-17 15:12:16 -0700172 M* m; // for debuggers, but offset not hard-coded
Russ Cox218c3932009-07-13 17:28:39 -0700173 M* lockedm;
Russ Coxd28acc42008-08-04 16:43:49 -0700174};
175struct Mem
176{
177 uint8* hunk;
178 uint32 nhunk;
179 uint64 nmmap;
180 uint64 nmal;
Ken Thompson45288542008-07-08 17:19:17 -0700181};
Ken Thompson45288542008-07-08 17:19:17 -0700182struct M
183{
Russ Cox38020092009-06-17 16:31:02 -0700184 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700185 G* g0; // goroutine with scheduling stack
186 void (*morepc)(void);
Russ Coxbba278a2009-07-08 18:16:09 -0700187 void* morefp; // frame pointer for more stack
Russ Cox7343e032009-06-17 15:12:16 -0700188 Gobuf morebuf; // gobuf arg to morestack
189
Russ Cox38020092009-06-17 16:31:02 -0700190 // Fields not known to debuggers.
Russ Cox7343e032009-06-17 15:12:16 -0700191 uint32 moreframe; // size arguments to morestack
192 uint32 moreargs;
193 uintptr cret; // return value from C
194 uint64 procid; // for debuggers, but offset not hard-coded
195 G* gsignal; // signal-handling G
196 uint32 tls[8]; // thread-local storage (for 386 extern register)
197 Gobuf sched; // scheduling stack
198 G* curg; // current running goroutine
Russ Coxefc86a72008-11-25 16:48:10 -0800199 int32 id;
Russ Coxda0a7d72008-12-19 03:13:39 -0800200 int32 mallocing;
Russ Cox8c357ce2009-06-15 21:31:56 -0700201 int32 gcing;
Russ Cox1ce17912009-01-26 17:37:05 -0800202 int32 locks;
Russ Cox218c3932009-07-13 17:28:39 -0700203 int32 waitnextg;
Russ Cox96824002008-08-05 14:18:47 -0700204 Note havenextg;
205 G* nextg;
206 M* schedlink;
Russ Coxd28acc42008-08-04 16:43:49 -0700207 Mem mem;
Russ Cox376898c2008-09-09 11:50:14 -0700208 uint32 machport; // Return address for Mach IPC (OS X)
Russ Coxe29ce172008-12-18 15:42:28 -0800209 MCache *mcache;
Russ Cox218c3932009-07-13 17:28:39 -0700210 G* lockedg;
Ken Thompson751ce3a2008-07-11 19:16:39 -0700211};
Ken Thompson52620032008-07-14 14:33:39 -0700212struct Stktop
Ken Thompson594175d2008-07-13 14:29:46 -0700213{
Russ Cox38020092009-06-17 16:31:02 -0700214 // The offsets of these fields are known to (hard-coded in) libmach.
Russ Cox7343e032009-06-17 15:12:16 -0700215 uint8* stackguard;
216 uint8* stackbase;
217 Gobuf gobuf;
218 uint32 args;
Russ Coxbba278a2009-07-08 18:16:09 -0700219
220 // Frame pointer: where args start in old frame.
221 // fp == gobuf.sp except in the case of a reflected
222 // function call, which uses an off-stack argument frame.
223 uint8* fp;
Ken Thompson45288542008-07-08 17:19:17 -0700224};
Ken Thompson594175d2008-07-13 14:29:46 -0700225struct Alg
Ken Thompson751ce3a2008-07-11 19:16:39 -0700226{
Russ Coxa52fb812009-06-04 21:09:06 -0700227 uintptr (*hash)(uint32, void*);
Ken Thompson594175d2008-07-13 14:29:46 -0700228 uint32 (*equal)(uint32, void*, void*);
229 void (*print)(uint32, void*);
230 void (*copy)(uint32, void*, void*);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700231};
Ken Thompson594175d2008-07-13 14:29:46 -0700232struct SigTab
Ken Thompsonbbb20732008-06-05 19:38:39 -0700233{
Russ Coxdfa58932008-12-03 14:21:28 -0800234 int32 flags;
Ken Thompson594175d2008-07-13 14:29:46 -0700235 int8 *name;
Ken Thompsonbbb20732008-06-05 19:38:39 -0700236};
Russ Coxdfa58932008-12-03 14:21:28 -0800237enum
238{
239 SigCatch = 1<<0,
240 SigIgnore = 1<<1,
241 SigRestart = 1<<2,
242};
Ken Thompsonbbb20732008-06-05 19:38:39 -0700243
Russ Cox3aa063d2008-11-23 17:08:55 -0800244// (will be) shared with go; edit ../cmd/6g/sys.go too.
245// should move out of sys.go eventually.
246// also eventually, the loaded symbol table should
247// be closer to this form.
248struct Func
249{
Ken Thompson36570612009-04-09 18:16:21 -0700250 String name;
251 String type; // go type string
252 String src; // src file name
Russ Coxa5433362008-11-25 09:23:36 -0800253 uint64 entry; // entry pc
254 int64 frame; // stack frame size
Rob Pike87f22082009-08-25 15:54:25 -0700255 Slice pcln; // pc/ln tab for this func
Russ Coxa5433362008-11-25 09:23:36 -0800256 int64 pc0; // starting pc, ln for table
257 int32 ln0;
Russ Coxefc86a72008-11-25 16:48:10 -0800258 int32 args; // number of 32-bit in/out args
259 int32 locals; // number of 32-bit locals
Russ Cox3aa063d2008-11-23 17:08:55 -0800260};
261
Ken Thompsonbbb20732008-06-05 19:38:39 -0700262/*
263 * defined macros
264 * you need super-goru privilege
265 * to add this list.
266 */
267#define nelem(x) (sizeof(x)/sizeof((x)[0]))
268#define nil ((void*)0)
269
270/*
Russ Coxeee50ae2008-12-19 12:05:22 -0800271 * known to compiler
272 */
273enum
274{
Russ Coxa7f6d402009-01-26 09:56:42 -0800275 AMEM,
276 ANOEQ,
Russ Coxeee50ae2008-12-19 12:05:22 -0800277 ASTRING,
Russ Coxeee50ae2008-12-19 12:05:22 -0800278 AINTER,
Russ Cox2da50222009-05-20 14:57:55 -0700279 ANILINTER,
Russ Cox9b6d3852009-01-26 12:36:21 -0800280 AFAKE,
Russ Coxa7f6d402009-01-26 09:56:42 -0800281 Amax
Russ Coxeee50ae2008-12-19 12:05:22 -0800282};
283
Russ Cox29aa3ff2009-07-02 21:25:46 -0700284
285enum {
286 Structrnd = sizeof(uintptr)
287};
288
Russ Coxeee50ae2008-12-19 12:05:22 -0800289/*
Ken Thompson47ab1c12009-01-27 13:23:28 -0800290 * deferred subroutine calls
Ken Thompson1e1cc4e2009-01-27 12:03:53 -0800291 */
292struct Defer
293{
294 int32 siz;
295 byte* sp;
296 byte* fn;
297 Defer* link;
298 byte args[8]; // padded to actual size
299};
300
301/*
Ken Thompson594175d2008-07-13 14:29:46 -0700302 * external data
303 */
Russ Coxa7f6d402009-01-26 09:56:42 -0800304extern Alg algarray[Amax];
Ken Thompson36570612009-04-09 18:16:21 -0700305extern String emptystring;
Ken Thompson594175d2008-07-13 14:29:46 -0700306G* allg;
307int32 goidgen;
Russ Coxd28acc42008-08-04 16:43:49 -0700308extern int32 gomaxprocs;
Rob Pike6e8dbc22008-09-12 09:44:41 -0700309extern int32 panicking;
Ken Thompson79fbbe32008-11-05 21:50:28 -0800310extern int32 maxround;
Ken Thompson594175d2008-07-13 14:29:46 -0700311
312/*
Rob Pike8e82a672008-06-30 11:50:36 -0700313 * common functions and data
314 */
Ken Thompson751ce3a2008-07-11 19:16:39 -0700315int32 strcmp(byte*, byte*);
Russ Cox3aa063d2008-11-23 17:08:55 -0800316int32 findnull(byte*);
Rob Pike8e82a672008-06-30 11:50:36 -0700317void dump(byte*, int32);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700318int32 runetochar(byte*, int32);
Rob Pike54ec7192009-04-12 17:01:17 -0700319int32 charntorune(int32*, uint8*, int32);
Rob Pike8e82a672008-06-30 11:50:36 -0700320
Rob Pike8e82a672008-06-30 11:50:36 -0700321/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700322 * very low level c-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700323 */
Russ Cox7343e032009-06-17 15:12:16 -0700324void gogo(Gobuf*, uintptr);
325void gogocall(Gobuf*, void(*)(void));
326uintptr gosave(Gobuf*);
327void sys·lessstack(void);
Russ Cox36096242009-01-16 14:58:14 -0800328void goargs(void);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700329void FLUSH(void*);
Rob Piked3204ef2008-06-30 14:39:47 -0700330void* getu(void);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700331void throw(int8*);
Ken Thompson594175d2008-07-13 14:29:46 -0700332uint32 rnd(uint32, uint32);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700333void prints(int8*);
Russ Coxefc86a72008-11-25 16:48:10 -0800334void printf(int8*, ...);
Russ Cox3aa063d2008-11-23 17:08:55 -0800335byte* mchr(byte*, byte, byte*);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700336void mcpy(byte*, byte*, uint32);
Russ Cox9b6d3852009-01-26 12:36:21 -0800337int32 mcmp(byte*, byte*, uint32);
Ken Thompsonbc0b4f02008-11-13 10:35:44 -0800338void mmov(byte*, byte*, uint32);
Ken Thompsone1a06cc2008-06-15 20:24:30 -0700339void* mal(uint32);
Ken Thompson36570612009-04-09 18:16:21 -0700340uint32 cmpstring(String, String);
341String gostring(byte*);
Rob Pikeaeb43982008-06-21 15:36:23 -0700342void initsig(void);
Russ Coxfb40f882008-09-22 13:47:53 -0700343int32 gotraceback(void);
Ken Thompson751ce3a2008-07-11 19:16:39 -0700344void traceback(uint8 *pc, uint8 *sp, G* gp);
Rob Pike3835e012008-07-28 11:29:41 -0700345void tracebackothers(G*);
Rob Pikec870ac22008-07-14 20:54:55 -0700346int32 open(byte*, int32, ...);
Rob Pikec870ac22008-07-14 20:54:55 -0700347int32 write(int32, void*, int32);
Russ Coxd28acc42008-08-04 16:43:49 -0700348bool cas(uint32*, uint32, uint32);
Russ Coxaa3222d82009-06-02 23:02:12 -0700349void jmpdefer(byte*, void*);
Russ Coxd28acc42008-08-04 16:43:49 -0700350void exit1(int32);
351void ready(G*);
352byte* getenv(int8*);
353int32 atoi(byte*);
Russ Cox96824002008-08-05 14:18:47 -0700354void newosproc(M *m, G *g, void *stk, void (*fn)(void));
Russ Coxa67258f2008-09-18 15:56:46 -0700355void signalstack(byte*, int32);
356G* malg(int32);
357void minit(void);
Russ Cox0d3a0432009-03-30 00:01:07 -0700358Func* findfunc(uintptr);
Russ Coxa5433362008-11-25 09:23:36 -0800359int32 funcline(Func*, uint64);
Russ Cox79e1db22008-12-04 08:30:54 -0800360void* stackalloc(uint32);
361void stackfree(void*);
Russ Coxe29ce172008-12-18 15:42:28 -0800362MCache* allocmcache(void);
363void mallocinit(void);
Russ Coxa7f6d402009-01-26 09:56:42 -0800364bool ifaceeq(Iface, Iface);
Russ Cox2da50222009-05-20 14:57:55 -0700365bool efaceeq(Eface, Eface);
Russ Coxa52fb812009-06-04 21:09:06 -0700366uintptr ifacehash(Iface);
367uintptr efacehash(Eface);
368uintptr nohash(uint32, void*);
Russ Coxa7f6d402009-01-26 09:56:42 -0800369uint32 noequal(uint32, void*, void*);
Russ Cox1ce17912009-01-26 17:37:05 -0800370void* malloc(uintptr size);
371void* mallocgc(uintptr size);
372void free(void *v);
Russ Cox918afd942009-05-08 15:21:41 -0700373void exit(int32);
374void breakpoint(void);
375void gosched(void);
376void goexit(void);
Russ Coxd28acc42008-08-04 16:43:49 -0700377
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800378#pragma varargck argpos printf 1
379
380#pragma varargck type "d" int32
381#pragma varargck type "d" uint32
382#pragma varargck type "D" int64
383#pragma varargck type "D" uint64
384#pragma varargck type "x" int32
385#pragma varargck type "x" uint32
386#pragma varargck type "X" int64
387#pragma varargck type "X" uint64
388#pragma varargck type "p" void*
Russ Cox0d3a0432009-03-30 00:01:07 -0700389#pragma varargck type "p" uintptr
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800390#pragma varargck type "s" int8*
391#pragma varargck type "s" uint8*
Ken Thompson36570612009-04-09 18:16:21 -0700392#pragma varargck type "S" String
Russ Cox5bb0c4f2008-12-15 10:50:33 -0800393
Russ Cox3f8aa662008-12-05 15:24:18 -0800394// TODO(rsc): Remove. These are only temporary,
395// for the mark and sweep collector.
396void stoptheworld(void);
397void starttheworld(void);
398
Russ Coxd28acc42008-08-04 16:43:49 -0700399/*
400 * mutual exclusion locks. in the uncontended case,
401 * as fast as spin locks (just a few user-level instructions),
402 * but on the contention path they sleep in the kernel.
Russ Cox96824002008-08-05 14:18:47 -0700403 * a zeroed Lock is unlocked (no need to initialize each lock).
Russ Coxd28acc42008-08-04 16:43:49 -0700404 */
405void lock(Lock*);
406void unlock(Lock*);
Russ Coxd28acc42008-08-04 16:43:49 -0700407
408/*
Russ Cox96824002008-08-05 14:18:47 -0700409 * sleep and wakeup on one-time events.
Russ Coxf7f63292008-08-05 14:21:42 -0700410 * before any calls to notesleep or notewakeup,
Russ Cox96824002008-08-05 14:18:47 -0700411 * must call noteclear to initialize the Note.
412 * then, any number of threads can call notesleep
413 * and exactly one thread can call notewakeup (once).
414 * once notewakeup has been called, all the notesleeps
415 * will return. future notesleeps will return immediately.
Russ Coxd28acc42008-08-04 16:43:49 -0700416 */
Russ Cox96824002008-08-05 14:18:47 -0700417void noteclear(Note*);
418void notesleep(Note*);
419void notewakeup(Note*);
Ken Thompson4e8142c2008-06-16 22:34:50 -0700420
421/*
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800422 * Redefine methods for the benefit of gcc, which does not support
423 * UTF-8 characters in identifiers.
424 */
425#ifndef __GNUC__
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800426#define sys_memclr sys·memclr
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800427#define sys_getcallerpc sys·getcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800428#define sys_mmap sys·mmap
Rob Pike87f22082009-08-25 15:54:25 -0700429#define sys_printslice sys·printslice
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800430#define sys_printbool sys·printbool
431#define sys_printfloat sys·printfloat
432#define sys_printhex sys·printhex
433#define sys_printint sys·printint
Russ Cox2da50222009-05-20 14:57:55 -0700434#define sys_printiface sys·printiface
435#define sys_printeface sys·printeface
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800436#define sys_printpc sys·printpc
437#define sys_printpointer sys·printpointer
438#define sys_printstring sys·printstring
439#define sys_printuint sys·printuint
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800440#define sys_setcallerpc sys·setcallerpc
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800441#endif
442
443/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800444 * low level go-called
Ken Thompson4e8142c2008-06-16 22:34:50 -0700445 */
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800446uint8* sys_mmap(byte*, uint32, int32, int32, int32, uint32);
447void sys_memclr(byte*, uint32);
448void sys_setcallerpc(void*, void*);
449void* sys_getcallerpc(void*);
Ken Thompsonbbb20732008-06-05 19:38:39 -0700450
451/*
Ken Thompson4e8142c2008-06-16 22:34:50 -0700452 * runtime go-called
Ken Thompsonbbb20732008-06-05 19:38:39 -0700453 */
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800454void sys_printbool(bool);
455void sys_printfloat(float64);
456void sys_printint(int64);
Russ Cox2da50222009-05-20 14:57:55 -0700457void sys_printiface(Iface);
458void sys_printeface(Eface);
Ken Thompson36570612009-04-09 18:16:21 -0700459void sys_printstring(String);
Ian Lance Taylor9b8da822009-01-13 09:55:24 -0800460void sys_printpc(void*);
461void sys_printpointer(void*);
462void sys_printuint(uint64);
463void sys_printhex(uint64);
Rob Pike87f22082009-08-25 15:54:25 -0700464void sys_printslice(Slice);
Rob Pike6db99de2008-07-08 10:36:43 -0700465
466/*
Russ Cox1f8a40d2009-01-22 16:23:44 -0800467 * wrapped for go users
Rob Pike6db99de2008-07-08 10:36:43 -0700468 */
Russ Cox1f8a40d2009-01-22 16:23:44 -0800469float64 Inf(int32 sign);
470float64 NaN(void);
471float32 float32frombits(uint32 i);
472uint32 float32tobits(float32 f);
473float64 float64frombits(uint64 i);
474uint64 float64tobits(float64 f);
475float64 frexp(float64 d, int32 *ep);
476bool isInf(float64 f, int32 sign);
477bool isNaN(float64 f);
478float64 ldexp(float64 d, int32 e);
479float64 modf(float64 d, float64 *ip);
480void semacquire(uint32*);
481void semrelease(uint32*);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700482
Russ Cox764b6ec2009-07-08 13:55:57 -0700483void mapassign(Hmap*, byte*, byte*);
484void mapaccess(Hmap*, byte*, byte*, bool*);
485struct hash_iter* mapiterinit(Hmap*);
486void mapiternext(struct hash_iter*);
487bool mapiterkey(struct hash_iter*, void*);
488void mapiterkeyvalue(struct hash_iter*, void*, void*);
489Hmap* makemap(uint32, uint32, uint32, uint32, uint32);
Russ Cox5ddaf9a2009-07-08 15:00:54 -0700490
491Hchan* makechan(uint32, uint32, uint32);
492void chansend(Hchan*, void*, bool*);
493void chanrecv(Hchan*, void*, bool*);
Russ Cox653cef12009-08-26 10:47:18 -0700494void chanclose(Hchan*);
495bool chanclosed(Hchan*);
Russ Cox92e92572009-07-10 16:32:26 -0700496
497void ifaceE2I(struct InterfaceType*, Eface, Iface*);