Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 1 | // 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 Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 5 | /* |
| 6 | * basic types |
| 7 | */ |
| 8 | typedef signed char int8; |
| 9 | typedef unsigned char uint8; |
| 10 | typedef signed short int16; |
| 11 | typedef unsigned short uint16; |
| 12 | typedef signed int int32; |
| 13 | typedef unsigned int uint32; |
| 14 | typedef signed long long int int64; |
| 15 | typedef unsigned long long int uint64; |
| 16 | typedef float float32; |
| 17 | typedef double float64; |
Russ Cox | 75647d2 | 2008-11-17 12:32:35 -0800 | [diff] [blame] | 18 | typedef uint64 uintptr; |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * get rid of C types |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 22 | * the / / / forces a syntax error immediately, |
| 23 | * which will show "last name: XXunsigned". |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 24 | */ |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 25 | #define unsigned XXunsigned / / / |
| 26 | #define signed XXsigned / / / |
| 27 | #define char XXchar / / / |
| 28 | #define short XXshort / / / |
| 29 | #define int XXint / / / |
| 30 | #define long XXlong / / / |
| 31 | #define float XXfloat / / / |
| 32 | #define double XXdouble / / / |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * defined types |
| 36 | */ |
| 37 | typedef uint8 bool; |
| 38 | typedef uint8 byte; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 39 | typedef struct Alg Alg; |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 40 | typedef struct Array Array; |
| 41 | typedef struct Func Func; |
| 42 | typedef struct G G; |
| 43 | typedef struct Gobuf Gobuf; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 44 | typedef struct Lock Lock; |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 45 | typedef struct M M; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 46 | typedef struct Mem Mem; |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 47 | typedef union Note Note; |
| 48 | typedef struct Stktop Stktop; |
| 49 | typedef struct String *string; |
| 50 | typedef struct Usema Usema; |
Russ Cox | c3077f7 | 2008-12-19 17:11:54 -0800 | [diff] [blame] | 51 | typedef struct SigTab SigTab; |
| 52 | typedef struct MCache MCache; |
| 53 | typedef struct Iface Iface; |
| 54 | typedef struct Itype Itype; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * per cpu declaration |
| 58 | */ |
| 59 | extern register G* g; // R15 |
| 60 | extern register M* m; // R14 |
| 61 | |
| 62 | /* |
| 63 | * defined constants |
| 64 | */ |
| 65 | enum |
| 66 | { |
| 67 | // G status |
| 68 | Gidle, |
| 69 | Grunnable, |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 70 | Grunning, |
Russ Cox | 3f8aa66 | 2008-12-05 15:24:18 -0800 | [diff] [blame] | 71 | Gsyscall, |
Ken Thompson | 5262003 | 2008-07-14 14:33:39 -0700 | [diff] [blame] | 72 | Gwaiting, |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 73 | Gmoribund, |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 74 | Gdead, |
| 75 | }; |
| 76 | enum |
| 77 | { |
| 78 | true = 1, |
| 79 | false = 0, |
| 80 | }; |
| 81 | |
| 82 | /* |
| 83 | * structures |
| 84 | */ |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 85 | struct Lock |
| 86 | { |
| 87 | uint32 key; |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 88 | uint32 sema; // for OS X |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 89 | }; |
Russ Cox | 5ff12f8 | 2008-09-24 10:25:28 -0700 | [diff] [blame] | 90 | struct Usema |
| 91 | { |
| 92 | uint32 u; |
| 93 | uint32 k; |
| 94 | }; |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 95 | union Note |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 96 | { |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 97 | struct { // Linux |
| 98 | Lock lock; |
| 99 | }; |
| 100 | struct { // OS X |
| 101 | int32 wakeup; |
Russ Cox | 5ff12f8 | 2008-09-24 10:25:28 -0700 | [diff] [blame] | 102 | Usema sema; |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 103 | }; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 104 | }; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 105 | struct String |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 106 | { |
| 107 | int32 len; |
| 108 | byte str[1]; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 109 | }; |
Russ Cox | c3077f7 | 2008-12-19 17:11:54 -0800 | [diff] [blame] | 110 | struct Iface |
| 111 | { |
| 112 | Itype *type; |
Russ Cox | 484ba93 | 2009-01-09 00:17:46 -0800 | [diff] [blame] | 113 | void *data; |
Russ Cox | c3077f7 | 2008-12-19 17:11:54 -0800 | [diff] [blame] | 114 | }; |
Ken Thompson | 66a603c | 2008-08-27 17:28:30 -0700 | [diff] [blame] | 115 | |
| 116 | struct Array |
| 117 | { // must not move anything |
| 118 | byte* array; // actual data |
| 119 | uint32 nel; // number of elements |
Russ Cox | 75647d2 | 2008-11-17 12:32:35 -0800 | [diff] [blame] | 120 | uint32 cap; // allocated number of elements |
Ken Thompson | 66a603c | 2008-08-27 17:28:30 -0700 | [diff] [blame] | 121 | }; |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 122 | struct Gobuf |
| 123 | { |
| 124 | byte* SP; |
| 125 | byte* PC; |
| 126 | }; |
Ken Thompson | 7b454bb | 2008-07-09 11:35:26 -0700 | [diff] [blame] | 127 | struct G |
Ken Thompson | 4528854 | 2008-07-08 17:19:17 -0700 | [diff] [blame] | 128 | { |
| 129 | byte* stackguard; // must not move |
| 130 | byte* stackbase; // must not move |
Ken Thompson | e7d549f | 2008-07-16 13:50:23 -0700 | [diff] [blame] | 131 | byte* stack0; // first stack segment |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 132 | Gobuf sched; |
Rob Pike | 3835e01 | 2008-07-28 11:29:41 -0700 | [diff] [blame] | 133 | G* alllink; // on allg |
Ken Thompson | e963cba | 2008-07-25 15:55:12 -0700 | [diff] [blame] | 134 | void* param; // passed parameter on wakeup |
| 135 | int16 status; |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 136 | int32 goid; |
Ken Thompson | e963cba | 2008-07-25 15:55:12 -0700 | [diff] [blame] | 137 | int32 selgen; // valid sudog pointer |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 138 | G* schedlink; |
Russ Cox | a61bb95 | 2008-09-24 14:13:07 -0700 | [diff] [blame] | 139 | bool readyonstop; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 140 | M* m; // for debuggers |
| 141 | }; |
| 142 | struct Mem |
| 143 | { |
| 144 | uint8* hunk; |
| 145 | uint32 nhunk; |
| 146 | uint64 nmmap; |
| 147 | uint64 nmal; |
Ken Thompson | 4528854 | 2008-07-08 17:19:17 -0700 | [diff] [blame] | 148 | }; |
Ken Thompson | 4528854 | 2008-07-08 17:19:17 -0700 | [diff] [blame] | 149 | struct M |
| 150 | { |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 151 | G* g0; // g0 w interrupt stack - must not move |
| 152 | uint64 morearg; // arg to morestack - must not move |
Ken Thompson | e7d549f | 2008-07-16 13:50:23 -0700 | [diff] [blame] | 153 | uint64 cret; // return value from C - must not move |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 154 | uint64 procid; // for debuggers - must not move |
Russ Cox | a67258f | 2008-09-18 15:56:46 -0700 | [diff] [blame] | 155 | G* gsignal; // signal-handling G - must not move |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 156 | G* curg; // current running goroutine |
Ken Thompson | e7d549f | 2008-07-16 13:50:23 -0700 | [diff] [blame] | 157 | G* lastg; // last running goroutine - to emulate fifo |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 158 | Gobuf sched; |
| 159 | Gobuf morestack; |
| 160 | byte* moresp; |
| 161 | int32 siz1; |
| 162 | int32 siz2; |
Russ Cox | efc86a7 | 2008-11-25 16:48:10 -0800 | [diff] [blame] | 163 | int32 id; |
Russ Cox | da0a7d7 | 2008-12-19 03:13:39 -0800 | [diff] [blame] | 164 | int32 mallocing; |
Russ Cox | 1ce1791 | 2009-01-26 17:37:05 -0800 | [diff] [blame^] | 165 | int32 locks; |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 166 | Note havenextg; |
| 167 | G* nextg; |
| 168 | M* schedlink; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 169 | Mem mem; |
Russ Cox | 376898c | 2008-09-09 11:50:14 -0700 | [diff] [blame] | 170 | uint32 machport; // Return address for Mach IPC (OS X) |
Russ Cox | e29ce17 | 2008-12-18 15:42:28 -0800 | [diff] [blame] | 171 | MCache *mcache; |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 172 | }; |
Ken Thompson | 5262003 | 2008-07-14 14:33:39 -0700 | [diff] [blame] | 173 | struct Stktop |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 174 | { |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 175 | uint8* oldbase; |
| 176 | uint8* oldsp; |
| 177 | uint64 magic; |
| 178 | uint8* oldguard; |
Ken Thompson | 4528854 | 2008-07-08 17:19:17 -0700 | [diff] [blame] | 179 | }; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 180 | struct Alg |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 181 | { |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 182 | uint64 (*hash)(uint32, void*); |
| 183 | uint32 (*equal)(uint32, void*, void*); |
| 184 | void (*print)(uint32, void*); |
| 185 | void (*copy)(uint32, void*, void*); |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 186 | }; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 187 | struct SigTab |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 188 | { |
Russ Cox | dfa5893 | 2008-12-03 14:21:28 -0800 | [diff] [blame] | 189 | int32 flags; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 190 | int8 *name; |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 191 | }; |
Russ Cox | dfa5893 | 2008-12-03 14:21:28 -0800 | [diff] [blame] | 192 | enum |
| 193 | { |
| 194 | SigCatch = 1<<0, |
| 195 | SigIgnore = 1<<1, |
| 196 | SigRestart = 1<<2, |
| 197 | }; |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 198 | |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 199 | // (will be) shared with go; edit ../cmd/6g/sys.go too. |
| 200 | // should move out of sys.go eventually. |
| 201 | // also eventually, the loaded symbol table should |
| 202 | // be closer to this form. |
| 203 | struct Func |
| 204 | { |
| 205 | string name; |
Russ Cox | a543336 | 2008-11-25 09:23:36 -0800 | [diff] [blame] | 206 | string type; // go type string |
| 207 | string src; // src file name |
| 208 | uint64 entry; // entry pc |
| 209 | int64 frame; // stack frame size |
| 210 | Array pcln; // pc/ln tab for this func |
| 211 | int64 pc0; // starting pc, ln for table |
| 212 | int32 ln0; |
Russ Cox | efc86a7 | 2008-11-25 16:48:10 -0800 | [diff] [blame] | 213 | int32 args; // number of 32-bit in/out args |
| 214 | int32 locals; // number of 32-bit locals |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 215 | }; |
| 216 | |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 217 | /* |
| 218 | * defined macros |
| 219 | * you need super-goru privilege |
| 220 | * to add this list. |
| 221 | */ |
| 222 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) |
| 223 | #define nil ((void*)0) |
| 224 | |
| 225 | /* |
Russ Cox | eee50ae | 2008-12-19 12:05:22 -0800 | [diff] [blame] | 226 | * known to compiler |
| 227 | */ |
| 228 | enum |
| 229 | { |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 230 | AMEM, |
| 231 | ANOEQ, |
Russ Cox | eee50ae | 2008-12-19 12:05:22 -0800 | [diff] [blame] | 232 | ASTRING, |
Russ Cox | eee50ae | 2008-12-19 12:05:22 -0800 | [diff] [blame] | 233 | AINTER, |
Russ Cox | 9b6d385 | 2009-01-26 12:36:21 -0800 | [diff] [blame] | 234 | AFAKE, |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 235 | Amax |
Russ Cox | eee50ae | 2008-12-19 12:05:22 -0800 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | /* |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 239 | * external data |
| 240 | */ |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 241 | extern Alg algarray[Amax]; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 242 | extern string emptystring; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 243 | G* allg; |
| 244 | int32 goidgen; |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 245 | extern int32 gomaxprocs; |
Rob Pike | 6e8dbc2 | 2008-09-12 09:44:41 -0700 | [diff] [blame] | 246 | extern int32 panicking; |
Ken Thompson | 79fbbe3 | 2008-11-05 21:50:28 -0800 | [diff] [blame] | 247 | extern int32 maxround; |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 248 | |
| 249 | /* |
Rob Pike | 8e82a67 | 2008-06-30 11:50:36 -0700 | [diff] [blame] | 250 | * common functions and data |
| 251 | */ |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 252 | int32 strcmp(byte*, byte*); |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 253 | int32 findnull(byte*); |
Rob Pike | 8e82a67 | 2008-06-30 11:50:36 -0700 | [diff] [blame] | 254 | void dump(byte*, int32); |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 255 | int32 runetochar(byte*, int32); |
Rob Pike | 8e82a67 | 2008-06-30 11:50:36 -0700 | [diff] [blame] | 256 | |
Rob Pike | 8e82a67 | 2008-06-30 11:50:36 -0700 | [diff] [blame] | 257 | /* |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 258 | * very low level c-called |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 259 | */ |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 260 | int32 gogo(Gobuf*); |
| 261 | int32 gosave(Gobuf*); |
Rob Pike | 2da9783 | 2008-07-12 11:30:53 -0700 | [diff] [blame] | 262 | int32 gogoret(Gobuf*, uint64); |
| 263 | void retfromnewstack(void); |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 264 | void goargs(void); |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 265 | void setspgoto(byte*, void(*)(void), void(*)(void)); |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 266 | void FLUSH(void*); |
Rob Pike | d3204ef | 2008-06-30 14:39:47 -0700 | [diff] [blame] | 267 | void* getu(void); |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 268 | void throw(int8*); |
Ken Thompson | 594175d | 2008-07-13 14:29:46 -0700 | [diff] [blame] | 269 | uint32 rnd(uint32, uint32); |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 270 | void prints(int8*); |
Russ Cox | efc86a7 | 2008-11-25 16:48:10 -0800 | [diff] [blame] | 271 | void printf(int8*, ...); |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 272 | byte* mchr(byte*, byte, byte*); |
Ken Thompson | e1a06cc | 2008-06-15 20:24:30 -0700 | [diff] [blame] | 273 | void mcpy(byte*, byte*, uint32); |
Russ Cox | 9b6d385 | 2009-01-26 12:36:21 -0800 | [diff] [blame] | 274 | int32 mcmp(byte*, byte*, uint32); |
Ken Thompson | bc0b4f0 | 2008-11-13 10:35:44 -0800 | [diff] [blame] | 275 | void mmov(byte*, byte*, uint32); |
Ken Thompson | e1a06cc | 2008-06-15 20:24:30 -0700 | [diff] [blame] | 276 | void* mal(uint32); |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 277 | uint32 cmpstring(string, string); |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 278 | string gostring(byte*); |
Rob Pike | aeb4398 | 2008-06-21 15:36:23 -0700 | [diff] [blame] | 279 | void initsig(void); |
Russ Cox | fb40f88 | 2008-09-22 13:47:53 -0700 | [diff] [blame] | 280 | int32 gotraceback(void); |
Ken Thompson | 751ce3a | 2008-07-11 19:16:39 -0700 | [diff] [blame] | 281 | void traceback(uint8 *pc, uint8 *sp, G* gp); |
Rob Pike | 3835e01 | 2008-07-28 11:29:41 -0700 | [diff] [blame] | 282 | void tracebackothers(G*); |
Rob Pike | c870ac2 | 2008-07-14 20:54:55 -0700 | [diff] [blame] | 283 | int32 open(byte*, int32, ...); |
Rob Pike | 3e4e83a | 2008-06-26 14:09:26 -0700 | [diff] [blame] | 284 | int32 read(int32, void*, int32); |
Rob Pike | c870ac2 | 2008-07-14 20:54:55 -0700 | [diff] [blame] | 285 | int32 write(int32, void*, int32); |
Rob Pike | 3e4e83a | 2008-06-26 14:09:26 -0700 | [diff] [blame] | 286 | void close(int32); |
| 287 | int32 fstat(int32, void*); |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 288 | bool cas(uint32*, uint32, uint32); |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 289 | void exit1(int32); |
| 290 | void ready(G*); |
| 291 | byte* getenv(int8*); |
| 292 | int32 atoi(byte*); |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 293 | void newosproc(M *m, G *g, void *stk, void (*fn)(void)); |
Russ Cox | a67258f | 2008-09-18 15:56:46 -0700 | [diff] [blame] | 294 | void sigaltstack(void*, void*); |
| 295 | void signalstack(byte*, int32); |
| 296 | G* malg(int32); |
| 297 | void minit(void); |
Russ Cox | 3aa063d | 2008-11-23 17:08:55 -0800 | [diff] [blame] | 298 | Func* findfunc(uint64); |
Russ Cox | a543336 | 2008-11-25 09:23:36 -0800 | [diff] [blame] | 299 | int32 funcline(Func*, uint64); |
Russ Cox | 79e1db2 | 2008-12-04 08:30:54 -0800 | [diff] [blame] | 300 | void* stackalloc(uint32); |
| 301 | void stackfree(void*); |
Russ Cox | e29ce17 | 2008-12-18 15:42:28 -0800 | [diff] [blame] | 302 | MCache* allocmcache(void); |
| 303 | void mallocinit(void); |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 304 | bool ifaceeq(Iface, Iface); |
| 305 | uint64 ifacehash(Iface); |
| 306 | uint64 nohash(uint32, void*); |
| 307 | uint32 noequal(uint32, void*, void*); |
Russ Cox | 1ce1791 | 2009-01-26 17:37:05 -0800 | [diff] [blame^] | 308 | void* malloc(uintptr size); |
| 309 | void* mallocgc(uintptr size); |
| 310 | void free(void *v); |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 311 | |
Russ Cox | 5bb0c4f | 2008-12-15 10:50:33 -0800 | [diff] [blame] | 312 | #pragma varargck argpos printf 1 |
| 313 | |
| 314 | #pragma varargck type "d" int32 |
| 315 | #pragma varargck type "d" uint32 |
| 316 | #pragma varargck type "D" int64 |
| 317 | #pragma varargck type "D" uint64 |
| 318 | #pragma varargck type "x" int32 |
| 319 | #pragma varargck type "x" uint32 |
| 320 | #pragma varargck type "X" int64 |
| 321 | #pragma varargck type "X" uint64 |
| 322 | #pragma varargck type "p" void* |
| 323 | #pragma varargck type "p" uint64 |
| 324 | #pragma varargck type "s" int8* |
| 325 | #pragma varargck type "s" uint8* |
| 326 | #pragma varargck type "S" string |
| 327 | |
Russ Cox | 3f8aa66 | 2008-12-05 15:24:18 -0800 | [diff] [blame] | 328 | // TODO(rsc): Remove. These are only temporary, |
| 329 | // for the mark and sweep collector. |
| 330 | void stoptheworld(void); |
| 331 | void starttheworld(void); |
| 332 | |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 333 | /* |
| 334 | * mutual exclusion locks. in the uncontended case, |
| 335 | * as fast as spin locks (just a few user-level instructions), |
| 336 | * but on the contention path they sleep in the kernel. |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 337 | * a zeroed Lock is unlocked (no need to initialize each lock). |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 338 | */ |
| 339 | void lock(Lock*); |
| 340 | void unlock(Lock*); |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 341 | |
| 342 | /* |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 343 | * sleep and wakeup on one-time events. |
Russ Cox | f7f6329 | 2008-08-05 14:21:42 -0700 | [diff] [blame] | 344 | * before any calls to notesleep or notewakeup, |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 345 | * must call noteclear to initialize the Note. |
| 346 | * then, any number of threads can call notesleep |
| 347 | * and exactly one thread can call notewakeup (once). |
| 348 | * once notewakeup has been called, all the notesleeps |
| 349 | * will return. future notesleeps will return immediately. |
Russ Cox | d28acc4 | 2008-08-04 16:43:49 -0700 | [diff] [blame] | 350 | */ |
Russ Cox | 9682400 | 2008-08-05 14:18:47 -0700 | [diff] [blame] | 351 | void noteclear(Note*); |
| 352 | void notesleep(Note*); |
| 353 | void notewakeup(Note*); |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 354 | |
| 355 | /* |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 356 | * Redefine methods for the benefit of gcc, which does not support |
| 357 | * UTF-8 characters in identifiers. |
| 358 | */ |
| 359 | #ifndef __GNUC__ |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 360 | #define sys_Exit sys·Exit |
| 361 | #define sys_Gosched sys·Gosched |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 362 | #define sys_memclr sys·memclr |
| 363 | #define sys_write sys·write |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 364 | #define sys_Breakpoint sys·Breakpoint |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 365 | #define sys_catstring sys·catstring |
| 366 | #define sys_cmpstring sys·cmpstring |
| 367 | #define sys_getcallerpc sys·getcallerpc |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 368 | #define sys_Goexit sys·Goexit |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 369 | #define sys_indexstring sys·indexstring |
| 370 | #define sys_intstring sys·intstring |
| 371 | #define sys_mal sys·mal |
| 372 | #define sys_mmap sys·mmap |
| 373 | #define sys_printarray sys·printarray |
| 374 | #define sys_printbool sys·printbool |
| 375 | #define sys_printfloat sys·printfloat |
| 376 | #define sys_printhex sys·printhex |
| 377 | #define sys_printint sys·printint |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 378 | #define sys_printinter sys·printinter |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 379 | #define sys_printpc sys·printpc |
| 380 | #define sys_printpointer sys·printpointer |
| 381 | #define sys_printstring sys·printstring |
| 382 | #define sys_printuint sys·printuint |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 383 | #define sys_setcallerpc sys·setcallerpc |
| 384 | #define sys_slicestring sys·slicestring |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 385 | #endif |
| 386 | |
| 387 | /* |
Russ Cox | 1f8a40d | 2009-01-22 16:23:44 -0800 | [diff] [blame] | 388 | * low level go-called |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 389 | */ |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 390 | void sys_Goexit(void); |
| 391 | void sys_Gosched(void); |
| 392 | void sys_Exit(int32); |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 393 | void sys_write(int32, void*, int32); |
Russ Cox | 3609624 | 2009-01-16 14:58:14 -0800 | [diff] [blame] | 394 | void sys_Breakpoint(void); |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 395 | uint8* sys_mmap(byte*, uint32, int32, int32, int32, uint32); |
| 396 | void sys_memclr(byte*, uint32); |
| 397 | void sys_setcallerpc(void*, void*); |
| 398 | void* sys_getcallerpc(void*); |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 399 | |
| 400 | /* |
Ken Thompson | 4e8142c | 2008-06-16 22:34:50 -0700 | [diff] [blame] | 401 | * runtime go-called |
Ken Thompson | bbb2073 | 2008-06-05 19:38:39 -0700 | [diff] [blame] | 402 | */ |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 403 | void sys_printbool(bool); |
| 404 | void sys_printfloat(float64); |
| 405 | void sys_printint(int64); |
Russ Cox | a7f6d40 | 2009-01-26 09:56:42 -0800 | [diff] [blame] | 406 | void sys_printinter(Iface); |
Ian Lance Taylor | 9b8da82 | 2009-01-13 09:55:24 -0800 | [diff] [blame] | 407 | void sys_printstring(string); |
| 408 | void sys_printpc(void*); |
| 409 | void sys_printpointer(void*); |
| 410 | void sys_printuint(uint64); |
| 411 | void sys_printhex(uint64); |
| 412 | void sys_printarray(Array); |
| 413 | void sys_catstring(string, string, string); |
| 414 | void sys_cmpstring(string, string, int32); |
| 415 | void sys_slicestring(string, int32, int32, string); |
| 416 | void sys_indexstring(string, int32, byte); |
| 417 | void sys_intstring(int64, string); |
Rob Pike | 6db99de | 2008-07-08 10:36:43 -0700 | [diff] [blame] | 418 | |
| 419 | /* |
Russ Cox | 1f8a40d | 2009-01-22 16:23:44 -0800 | [diff] [blame] | 420 | * wrapped for go users |
Rob Pike | 6db99de | 2008-07-08 10:36:43 -0700 | [diff] [blame] | 421 | */ |
Russ Cox | 1f8a40d | 2009-01-22 16:23:44 -0800 | [diff] [blame] | 422 | float64 Inf(int32 sign); |
| 423 | float64 NaN(void); |
| 424 | float32 float32frombits(uint32 i); |
| 425 | uint32 float32tobits(float32 f); |
| 426 | float64 float64frombits(uint64 i); |
| 427 | uint64 float64tobits(float64 f); |
| 428 | float64 frexp(float64 d, int32 *ep); |
| 429 | bool isInf(float64 f, int32 sign); |
| 430 | bool isNaN(float64 f); |
| 431 | float64 ldexp(float64 d, int32 e); |
| 432 | float64 modf(float64 d, float64 *ip); |
| 433 | void semacquire(uint32*); |
| 434 | void semrelease(uint32*); |