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