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