v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
syscall.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #ifndef _SIFTEO_ABI_SYSCALL_H
27 #define _SIFTEO_ABI_SYSCALL_H
28 
29 #include <sifteo/abi/types.h>
30 #include <sifteo/abi/audio.h>
31 #include <sifteo/abi/events.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Low-level system call interface.
39  *
40  * System calls #0-63 are faster and smaller than normal function calls,
41  * whereas all other syscalls (#64-8191) are similar in cost to a normal
42  * call.
43  *
44  * System calls use a simplified calling convention that supports
45  * only at most 8 32-bit integer parameters, with at most one (32/64-bit)
46  * integer result.
47  *
48  * Parameters are allowed to be arbitrary-width integers, but they must
49  * not be floats. Any function that takes float parameters must explicitly
50  * bitcast them to integers.
51  *
52  * Return values must be integers, and furthermore they must be exactly
53  * 32 or 64 bits wide.
54  */
55 
56 #ifdef NOT_USERSPACE
57 # define _SC(n)
58 # define _NORET
59 #else
60 # define _SC(n) __asm__ ("_SYS_" #n)
61 # define _NORET __attribute__ ((noreturn))
62 #endif
63 
64 void _SYS_abort(void) _SC(0) _NORET;
65 void _SYS_exit(void) _SC(64) _NORET;
66 
67 void _SYS_shutdown(uint32_t flags) _SC(178);
68 void _SYS_keepAwake(void) _SC(180);
69 
70 uint32_t _SYS_getFeatures() _SC(65);
71 
72 void _SYS_yield(void) _SC(66);
73 void _SYS_paint(void) _SC(67);
74 void _SYS_finish(void) _SC(68);
75 void _SYS_paintUnlimited(void) _SC(69);
76 
77 // Lightweight event logging support: string identifier plus 0-7 integers.
78 // Tag bits: type [31:27], arity [26:24] param [23:0]
79 void _SYS_log(uint32_t tag, uintptr_t v1, uintptr_t v2, uintptr_t v3, uintptr_t v4, uintptr_t v5, uintptr_t v6, uintptr_t v7) _SC(17);
80 
81 // Compiler floating point support
82 uint32_t _SYS_add_f32(uint32_t a, uint32_t b) _SC(23);
83 uint64_t _SYS_add_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(70);
84 uint32_t _SYS_sub_f32(uint32_t a, uint32_t b) _SC(24);
85 uint64_t _SYS_sub_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(71);
86 uint32_t _SYS_mul_f32(uint32_t a, uint32_t b) _SC(27);
87 uint64_t _SYS_mul_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(36);
88 uint32_t _SYS_div_f32(uint32_t a, uint32_t b) _SC(41);
89 uint64_t _SYS_div_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(72);
90 uint64_t _SYS_fpext_f32_f64(uint32_t a) _SC(73);
91 uint32_t _SYS_fpround_f64_f32(uint32_t aL, uint32_t aH) _SC(39);
92 uint32_t _SYS_fptosint_f32_i32(uint32_t a) _SC(26);
93 uint64_t _SYS_fptosint_f32_i64(uint32_t a) _SC(74);
94 uint32_t _SYS_fptosint_f64_i32(uint32_t aL, uint32_t aH) _SC(75);
95 uint64_t _SYS_fptosint_f64_i64(uint32_t aL, uint32_t aH) _SC(76);
96 uint32_t _SYS_fptouint_f32_i32(uint32_t a) _SC(77);
97 uint64_t _SYS_fptouint_f32_i64(uint32_t a) _SC(78);
98 uint32_t _SYS_fptouint_f64_i32(uint32_t aL, uint32_t aH) _SC(79);
99 uint64_t _SYS_fptouint_f64_i64(uint32_t aL, uint32_t aH) _SC(80);
100 uint32_t _SYS_sinttofp_i32_f32(uint32_t a) _SC(30);
101 uint64_t _SYS_sinttofp_i32_f64(uint32_t a) _SC(48);
102 uint32_t _SYS_sinttofp_i64_f32(uint32_t aL, uint32_t aH) _SC(81);
103 uint64_t _SYS_sinttofp_i64_f64(uint32_t aL, uint32_t aH) _SC(82);
104 uint32_t _SYS_uinttofp_i32_f32(uint32_t a) _SC(40);
105 uint64_t _SYS_uinttofp_i32_f64(uint32_t a) _SC(83);
106 uint32_t _SYS_uinttofp_i64_f32(uint32_t aL, uint32_t aH) _SC(84);
107 uint64_t _SYS_uinttofp_i64_f64(uint32_t aL, uint32_t aH) _SC(53);
108 uint32_t _SYS_eq_f32(uint32_t a, uint32_t b) _SC(85);
109 uint32_t _SYS_eq_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(86);
110 uint32_t _SYS_lt_f32(uint32_t a, uint32_t b) _SC(38);
111 uint32_t _SYS_lt_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(87);
112 uint32_t _SYS_le_f32(uint32_t a, uint32_t b) _SC(28);
113 uint32_t _SYS_le_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(88);
114 uint32_t _SYS_ge_f32(uint32_t a, uint32_t b) _SC(33);
115 uint32_t _SYS_ge_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(89);
116 uint32_t _SYS_gt_f32(uint32_t a, uint32_t b) _SC(32);
117 uint32_t _SYS_gt_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(90);
118 uint32_t _SYS_un_f32(uint32_t a, uint32_t b) _SC(20);
119 uint32_t _SYS_un_f64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(91);
120 
121 // Compiler atomics support
122 uint32_t _SYS_fetch_and_or_4(uint32_t *p, uint32_t t) _SC(92);
123 uint32_t _SYS_fetch_and_xor_4(uint32_t *p, uint32_t t) _SC(93);
124 uint32_t _SYS_fetch_and_and_4(uint32_t *p, uint32_t t) _SC(94);
125 
126 // Compiler support for 64-bit operations
127 uint64_t _SYS_shl_i64(uint32_t aL, uint32_t aH, uint32_t b) _SC(95);
128 uint64_t _SYS_srl_i64(uint32_t aL, uint32_t aH, uint32_t b) _SC(96);
129 int64_t _SYS_sra_i64(uint32_t aL, uint32_t aH, uint32_t b) _SC(97);
130 uint64_t _SYS_mul_i64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(50);
131 int64_t _SYS_sdiv_i64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(42);
132 uint64_t _SYS_udiv_i64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(98);
133 int64_t _SYS_srem_i64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(99);
134 uint64_t _SYS_urem_i64(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(100);
135 
136 void _SYS_sincosf(uint32_t x, float *sinOut, float *cosOut) _SC(101);
137 uint32_t _SYS_fmodf(uint32_t a, uint32_t b) _SC(102);
138 uint32_t _SYS_powf(uint32_t a, uint32_t b) _SC(103);
139 uint32_t _SYS_sqrtf(uint32_t a) _SC(104);
140 uint32_t _SYS_logf(uint32_t a) _SC(105);
141 uint64_t _SYS_fmod(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(106);
142 uint64_t _SYS_pow(uint32_t aL, uint32_t aH, uint32_t bL, uint32_t bH) _SC(107);
143 uint64_t _SYS_sqrt(uint32_t aL, uint32_t aH) _SC(108);
144 uint64_t _SYS_logd(uint32_t aL, uint32_t aH) _SC(109);
145 uint32_t _SYS_sinf(uint32_t a) _SC(169);
146 uint32_t _SYS_cosf(uint32_t a) _SC(170);
147 uint32_t _SYS_tanf(uint32_t a) _SC(127);
148 uint32_t _SYS_atanf(uint32_t a) _SC(128);
149 uint32_t _SYS_atan2f(uint32_t y, uint32_t x) _SC(179);
150 
151 int32_t _SYS_tsini(uint32_t a) _SC(15);
152 int32_t _SYS_tcosi(uint32_t a) _SC(181);
153 uint32_t _SYS_tsinf(uint32_t a) _SC(182);
154 uint32_t _SYS_tcosf(uint32_t a) _SC(183);
155 
156 void _SYS_memset8(uint8_t *dest, uint8_t value, uint32_t count) _SC(44);
157 void _SYS_memset16(uint16_t *dest, uint16_t value, uint32_t count) _SC(110);
158 void _SYS_memset32(uint32_t *dest, uint32_t value, uint32_t count) _SC(49);
159 void _SYS_memcpy8(uint8_t *dest, const uint8_t *src, uint32_t count) _SC(111);
160 void _SYS_memcpy16(uint16_t *dest, const uint16_t *src, uint32_t count) _SC(112);
161 void _SYS_memcpy32(uint32_t *dest, const uint32_t *src, uint32_t count) _SC(113);
162 int32_t _SYS_memcmp8(const uint8_t *a, const uint8_t *b, uint32_t count) _SC(114);
163 uint32_t _SYS_crc32(const uint8_t *data, uint32_t count) _SC(115);
164 uint32_t _SYS_decompress_fastlz1(uint8_t *dest, uint32_t destMax, const uint8_t *src, uint32_t srcLen) _SC(116);
165 
166 uint32_t _SYS_strnlen(const char *str, uint32_t maxLen) _SC(47);
167 void _SYS_strlcpy(char *dest, const char *src, uint32_t destSize) _SC(117);
168 void _SYS_strlcat(char *dest, const char *src, uint32_t destSize) _SC(52);
169 void _SYS_strlcat_int(char *dest, int src, uint32_t destSize) _SC(118);
170 void _SYS_strlcat_int_fixed(char *dest, int src, unsigned width, unsigned lz, uint32_t destSize) _SC(119);
171 void _SYS_strlcat_int_hex(char *dest, int src, unsigned width, unsigned lz, uint32_t destSize) _SC(120);
172 int32_t _SYS_strncmp(const char *a, const char *b, uint32_t count) _SC(121);
173 
174 void _SYS_prng_init(struct _SYSPseudoRandomState *state, uint32_t seed) _SC(46);
175 uint32_t _SYS_prng_value(struct _SYSPseudoRandomState *state) _SC(57);
176 uint32_t _SYS_prng_valueBounded(struct _SYSPseudoRandomState *state, uint32_t limit) _SC(43);
177 
178 int64_t _SYS_ticks_ns(void) _SC(21);
179 
180 void _SYS_setVector(_SYSVectorID vid, void *handler, void *context) _SC(122);
181 void *_SYS_getVectorHandler(_SYSVectorID vid) _SC(123);
182 void *_SYS_getVectorContext(_SYSVectorID vid) _SC(124);
183 void _SYS_setGameMenuLabel(const char *label) _SC(174);
184 void _SYS_setPauseMenuResumeEnabled(bool enabled) _SC(187);
185 
186 // Sensors
187 uint32_t _SYS_getAccel(_SYSCubeID cid) _SC(54);
188 uint32_t _SYS_getNeighbors(_SYSCubeID cid) _SC(59);
189 uint32_t _SYS_isTouching(_SYSCubeID cid) _SC(55);
190 uint64_t _SYS_getCubeHWID(_SYSCubeID cid) _SC(130);
191 void _SYS_setMotionBuffer(_SYSCubeID cid, _SYSMotionBuffer *mbuf) _SC(175);
192 
193 // Battery information
194 uint32_t _SYS_cubeBatteryLevel(_SYSCubeID cid) _SC(129);
195 uint32_t _SYS_sysBatteryLevel() _SC(173);
196 
197 // Cube management
198 uint32_t _SYS_getConnectedCubes() _SC(16);
199 void _SYS_setCubeRange(uint32_t minimum, uint32_t maximum) _SC(125);
200 void _SYS_unpair(_SYSCubeID cid) _SC(126);
201 
202 // Version
203 uint32_t _SYS_version(void) _SC(186);
204 
205 // Audio
206 uint32_t _SYS_audio_play(const struct _SYSAudioModule *mod, _SYSAudioChannelID ch, enum _SYSAudioLoopType loop) _SC(35);
207 uint32_t _SYS_audio_isPlaying(_SYSAudioChannelID ch) _SC(131);
208 void _SYS_audio_stop(_SYSAudioChannelID ch) _SC(132);
209 void _SYS_audio_pause(_SYSAudioChannelID ch) _SC(133);
210 void _SYS_audio_resume(_SYSAudioChannelID ch) _SC(134);
211 int32_t _SYS_audio_volume(_SYSAudioChannelID ch) _SC(135);
212 void _SYS_audio_setVolume(_SYSAudioChannelID ch, int32_t volume) _SC(136);
213 void _SYS_audio_setSpeed(_SYSAudioChannelID ch, uint32_t sampleRate) _SC(137);
214 uint32_t _SYS_audio_pos(_SYSAudioChannelID ch) _SC(138);
215 uint32_t _SYS_tracker_play(const struct _SYSXMSong *song) _SC(51);
216 uint32_t _SYS_tracker_isStopped() _SC(139);
217 void _SYS_tracker_stop() _SC(63);
218 void _SYS_tracker_setVolume(int volume, _SYSAudioChannelID ch) _SC(140);
219 void _SYS_tracker_pause() _SC(141);
220 uint32_t _SYS_tracker_isPaused() _SC(142);
221 void _SYS_tracker_setTempoModifier(int modifier) _SC(184);
222 void _SYS_tracker_setPosition(uint16_t phrase, uint16_t row) _SC(185);
223 
224 // Asset group/slot management
225 uint32_t _SYS_asset_slotTilesFree(_SYSAssetSlot slot, _SYSCubeIDVector cv) _SC(143);
226 void _SYS_asset_slotErase(_SYSAssetSlot slot, _SYSCubeIDVector cv) _SC(144);
227 void _SYS_asset_loadStart(struct _SYSAssetLoader *loader, const struct _SYSAssetConfiguration *cfg, unsigned cfgSize, _SYSCubeIDVector cv) _SC(145);
228 void _SYS_asset_loadFinish(struct _SYSAssetLoader *loader) _SC(146);
229 uint32_t _SYS_asset_findInCache(struct _SYSAssetGroup *group, _SYSCubeIDVector cv) _SC(58);
230 void _SYS_asset_bindSlots(_SYSVolumeHandle volume, unsigned numSlots) _SC(147);
231 void _SYS_asset_loadCancel(struct _SYSAssetLoader *loader, _SYSCubeIDVector cv) _SC(148);
232 
233 // Video buffers
234 void _SYS_setVideoBuffer(_SYSCubeID cid, struct _SYSVideoBuffer *vbuf) _SC(61);
235 void _SYS_vbuf_init(struct _SYSVideoBuffer *vbuf) _SC(62);
236 void _SYS_vbuf_lock(struct _SYSVideoBuffer *vbuf, uint16_t addr) _SC(149);
237 void _SYS_vbuf_unlock(struct _SYSVideoBuffer *vbuf) _SC(150);
238 void _SYS_vbuf_poke(struct _SYSVideoBuffer *vbuf, uint16_t addr, uint16_t word) _SC(18);
239 void _SYS_vbuf_pokeb(struct _SYSVideoBuffer *vbuf, uint16_t addr, uint8_t byte) _SC(31);
240 void _SYS_vbuf_xorb(struct _SYSVideoBuffer *vbuf, uint16_t addr, uint8_t byte) _SC(29);
241 uint32_t _SYS_vbuf_peek(const struct _SYSVideoBuffer *vbuf, uint16_t addr) _SC(151);
242 uint32_t _SYS_vbuf_peekb(const struct _SYSVideoBuffer *vbuf, uint16_t addr) _SC(34);
243 void _SYS_vbuf_fill(struct _SYSVideoBuffer *vbuf, uint16_t addr, uint16_t word, uint16_t count) _SC(22);
244 void _SYS_vbuf_seqi(struct _SYSVideoBuffer *vbuf, uint16_t addr, uint16_t index, uint16_t count) _SC(152);
245 void _SYS_vbuf_write(struct _SYSVideoBuffer *vbuf, uint16_t addr, const uint16_t *src, uint16_t count) _SC(37);
246 void _SYS_vbuf_writei(struct _SYSVideoBuffer *vbuf, uint16_t addr, const uint16_t *src, uint16_t offset, uint16_t count) _SC(153);
247 void _SYS_vbuf_wrect(struct _SYSVideoBuffer *vbuf, uint16_t addr, const uint16_t *src, uint16_t offset, uint16_t count, uint16_t lines, uint16_t src_stride, uint16_t addr_stride) _SC(154);
248 void _SYS_vbuf_spr_resize(struct _SYSVideoBuffer *vbuf, unsigned id, unsigned width, unsigned height) _SC(155);
249 void _SYS_vbuf_spr_move(struct _SYSVideoBuffer *vbuf, unsigned id, int x, int y) _SC(156);
250 
251 // Motion buffers
252 void _SYS_motion_integrate(const struct _SYSMotionBuffer *mbuf, unsigned duration, struct _SYSInt3 *result) _SC(176);
253 void _SYS_motion_median(const struct _SYSMotionBuffer *mbuf, unsigned duration, struct _SYSMotionMedian *result) _SC(177);
254 
255 // Asset images
256 void _SYS_image_memDraw(uint16_t *dest, _SYSCubeID destCID, const struct _SYSAssetImage *im, unsigned dest_stride, unsigned frame) _SC(157);
257 void _SYS_image_memDrawRect(uint16_t *dest, _SYSCubeID destCID, const struct _SYSAssetImage *im, unsigned dest_stride, unsigned frame, struct _SYSInt2 *srcXY, struct _SYSInt2 *size) _SC(158);
258 void _SYS_image_BG0Draw(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t addr, unsigned frame) _SC(19);
259 void _SYS_image_BG0DrawRect(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t addr, unsigned frame, struct _SYSInt2 *srcXY, struct _SYSInt2 *size) _SC(45);
260 void _SYS_image_BG1Draw(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, struct _SYSInt2 *destXY, unsigned frame) _SC(25);
261 void _SYS_image_BG1DrawRect(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, struct _SYSInt2 *destXY, unsigned frame, struct _SYSInt2 *srcXY, struct _SYSInt2 *size) _SC(56);
262 void _SYS_image_BG1MaskedDraw(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t key, unsigned frame) _SC(159);
263 void _SYS_image_BG1MaskedDrawRect(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t key, unsigned frame, struct _SYSInt2 *srcXY, struct _SYSInt2 *size) _SC(160);
264 void _SYS_image_BG2Draw(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t addr, unsigned frame) _SC(161);
265 void _SYS_image_BG2DrawRect(struct _SYSAttachedVideoBuffer *vbuf, const struct _SYSAssetImage *im, uint16_t addr, unsigned frame, struct _SYSInt2 *srcXY, struct _SYSInt2 *size) _SC(162);
266 
267 // Filesystem
268 uint32_t _SYS_fs_listVolumes(unsigned volType, _SYSVolumeHandle *results, uint32_t maxResults) _SC(163);
269 void _SYS_elf_exec(_SYSVolumeHandle vol) _SC(164);
270 uint32_t _SYS_elf_map(_SYSVolumeHandle vol) _SC(165);
271 void *_SYS_elf_metadata(_SYSVolumeHandle vol, unsigned key, unsigned minSize, unsigned *actualSize) _SC(166);
272 int32_t _SYS_fs_objectRead(unsigned key, uint8_t *buffer, unsigned bufferSize, _SYSVolumeHandle parent) _SC(167);
273 int32_t _SYS_fs_objectWrite(unsigned key, const uint8_t *data, unsigned dataSize) _SC(60);
274 uint32_t _SYS_fs_runningVolume() _SC(168);
275 uint32_t _SYS_fs_previousVolume() _SC(171);
276 uint32_t _SYS_fs_info(_SYSFilesystemInfo *buffer, uint32_t bufferSize) _SC(172);
277 
278 // Bluetooth
279 uint32_t _SYS_bt_isAvailable() _SC(188);
280 uint32_t _SYS_bt_isConnected() _SC(189);
281 void _SYS_bt_advertiseState(const uint8_t *data, uint32_t length) _SC(190);
282 void _SYS_bt_setPipe(_SYSBluetoothQueue *send, _SYSBluetoothQueue *receive) _SC(191);
283 void _SYS_bt_queueWriteHint() _SC(192);
284 void _SYS_bt_queueReadHint() _SC(193);
285 uint32_t _SYS_bt_counters(_SYSBluetoothCounters *buffer, uint32_t bufferSize) _SC(194);
286 
287 // USB
288 uint32_t _SYS_usb_isConnected() _SC(195);
289 uint32_t _SYS_usb_counters(_SYSUsbCounters *buffer, uint32_t bufferSize) _SC(196);
290 void _SYS_usb_setPipe(_SYSUsbQueue *send, _SYSUsbQueue *receive) _SC(197);
291 void _SYS_usb_queueWriteHint() _SC(198);
292 
293 #ifdef __cplusplus
294 } // extern "C"
295 #endif
296 
297 #endif