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