summaryrefslogtreecommitdiffstats
path: root/v9fs.h
blob: 73e42b33740db5e1dbb8d0a1c2c2b310f4d553b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
#ifndef V9FS_H
#define V9FS_H

/* 9P protocol opcodes */
#define P9_TLERROR 6
#define P9_RLERROR 7
#define P9_TSTATFS 8
#define P9_RSTATFS 9
#define P9_TLOPEN 12
#define P9_RLOPEN 13
#define P9_TLCREATE 14
#define P9_RLCREATE 15
#define P9_TSYMLINK 16
#define P9_RSYMLINK 17
#define P9_TMKNOD 18
#define P9_RMKNOD 19
#define P9_TRENAME 20
#define P9_RRENAME 21
#define P9_TREADLINK 22
#define P9_RREADLINK 23
#define P9_TGETATTR 24
#define P9_RGETATTR 25
#define P9_TSETATTR 26
#define P9_RSETATTR 27
#define P9_TXATTRWALK 30
#define P9_RXATTRWALK 31
#define P9_TXATTRCREATE 32
#define P9_RXATTRCREATE 33
#define P9_TREADDIR 40
#define P9_RREADDIR 41
#define P9_TFSYNC 50
#define P9_RFSYNC 51
#define P9_TLOCK 52
#define P9_RLOCK 53
#define P9_TGETLOCK 54
#define P9_RGETLOCK 55
#define P9_TLINK 70
#define P9_RLINK 71
#define P9_TMKDIR 72
#define P9_RMKDIR 73
#define P9_TRENAMEAT 74
#define P9_RRENAMEAT 75
#define P9_TUNLINKAT 76
#define P9_RUNLINKAT 77
#define P9_TVERSION 100
#define P9_RVERSION 101
#define P9_TAUTH 102
#define P9_RAUTH 103
#define P9_TATTACH 104
#define P9_RATTACH 105
#define P9_TERROR 106
#define P9_RERROR 107
#define P9_TFLUSH 108
#define P9_RFLUSH 109
#define P9_TWALK 110
#define P9_RWALK 111
#define P9_TOPEN 112
#define P9_ROPEN 113
#define P9_TCREATE 114
#define P9_RCREATE 115
#define P9_TREAD 116
#define P9_RREAD 117
#define P9_TWRITE 118
#define P9_RWRITE 119
#define P9_TCLUNK 120
#define P9_RCLUNK 121
#define P9_TREMOVE 122
#define P9_RREMOVE 123
#define P9_TSTAT 124
#define P9_RSTAT 125
#define P9_TWSTAT 126
#define P9_RWSTAT 127

/* 9P QID types */
#define P9_QTDIR 0x80
#define P9_QTAPPEND 0x40
#define P9_QTEXCL 0x20
#define P9_QTMOUNT 0x10
#define P9_QTAUTH 0x08
#define P9_QTTMP 0x04
#define P9_QTSYMLINK 0x02
#define P9_QTLINK 0x01
#define P9_QTFILE 0x00

/* FID numbers we use */
#define FID_ROOT	2

/* Invocation frame assuming prev_stack is loaded into gs:bp */
#define F_GS	%gs:(%bp)
#define F_FS	%gs:2(%bp)
#define F_ES	%gs:4(%bp)
#define F_DS	%gs:6(%bp)
#define F_EDI	%gs:8(%bp)
#define F_DI	%gs:8(%bp)
#define F_ESI	%gs:12(%bp)
#define F_SI	%gs:12(%bp)
#define F_EBP	%gs:16(%bp)
#define F_BP	%gs:16(%bp)
#define F_ESP	%gs:20(%bp)
#define F_SP	%gs:20(%bp)
#define F_EBX	%gs:24(%bp)
#define F_BX	%gs:24(%bp)
#define F_BL	%gs:24(%bp)
#define F_BH	%gs:25(%bp)
#define F_EDX	%gs:28(%bp)
#define F_DX	%gs:28(%bp)
#define F_DL	%gs:28(%bp)
#define F_DH	%gs:29(%bp)
#define F_ECX	%gs:32(%bp)
#define F_CX	%gs:32(%bp)
#define F_CL	%gs:32(%bp)
#define F_CH	%gs:33(%bp)
#define F_EAX	%gs:36(%bp)
#define F_AX	%gs:36(%bp)
#define F_AL	%gs:36(%bp)
#define F_AH	%gs:37(%bp)
#define F_IP	%gs:40(%bp)
#define F_CS	%gs:42(%bp)
#define F_FLAGS	%gs:44(%bp)

/* Magic number we store in the CDS */
#define CDS_MAGIC	0xe882

/*
 * Macros to print out a message and an error
 */
	.macro printmsg msg
	.pushsection ".rodata.str","a",@progbits
101:	.ascii "\msg"
	.byte 0
	.popsection
	pushw $101b
	call puts
	.endm

	.macro printerr msg
	.pushsection ".rodata.str","a",@progbits
101:	.ascii "\msg"
	.byte 0
	.popsection
	pushw $101b
	call puterr
	.endm

/*
 * Macros to define data objects
 *
 * Prefix is:
 * <g>lobal or <l>ocal,
 * <r>esident or <i>nit,
 * <r>odata <d>ata or <b>ss
 */
	.macro lrrbyte name val
	.pushsection ".rrodata.byte","a",@progbits
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro lrdbyte name val
	.pushsection ".rdata.byte","aw",@progbits
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro lrbbyte name
	.pushsection ".rbss.byte","aw",@nobits
	.balign 1
\name:
	.space 1
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro lirbyte name val
	.pushsection ".rodata.byte","a",@progbits
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro lidbyte name val
	.pushsection ".data.byte","aw",@progbits
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro libbyte name
	.pushsection ".bss.byte","aw",@nobits
	.balign 1
\name:
	.space 1
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro lrrword name val
	.pushsection ".rrodata.word","a",@progbits
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro lrdword name val
	.pushsection ".rdata.word","aw",@progbits
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro lrbword name
	.pushsection ".rbss.word","aw",@nobits
	.balign 2
\name:
	.space 2
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro lirword name val
	.pushsection ".rodata.word","a",@progbits
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro lidword name val
	.pushsection ".data.word","aw",@progbits
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro libword name
	.pushsection ".bss.word","aw",@nobits
	.balign 2
\name:
	.space 2
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro lrrlong name val
	.pushsection ".rrodata.long","a",@progbits
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro lrdlong name val
	.pushsection ".rdata.long","aw",@progbits
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro lrblong name
	.pushsection ".rbss.long","aw",@nobits
	.balign 4
\name:
	.space 4
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro lirlong name val
	.pushsection ".rodata.long","a",@progbits
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro lidlong name val
	.pushsection ".data.long","aw",@progbits
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro liblong name
	.pushsection ".bss.long","aw",@nobits
	.balign 4
\name:
	.space 4
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro grrbyte name val
	.pushsection ".rrodata.byte","a",@progbits
	.globl \name
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro grdbyte name val
	.pushsection ".rdata.byte","aw",@progbits
	.globl \name
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro grbbyte name
	.pushsection ".rbss.byte","aw",@nobits
	.globl \name
	.balign 1
\name:
	.space 1
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro girbyte name val
	.pushsection ".rodata.byte","a",@progbits
	.globl \name
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro gidbyte name val
	.pushsection ".data.byte","aw",@progbits
	.globl \name
	.balign 1
\name:
	.byte \val
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro gibbyte name
	.pushsection ".bss.byte","aw",@nobits
	.globl \name
	.balign 1
\name:
	.space 1
	.size \name,1
	.type \name,@object
	.popsection
	.endm

	.macro grrword name val
	.pushsection ".rrodata.word","a",@progbits
	.globl \name
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro grdword name val
	.pushsection ".rdata.word","aw",@progbits
	.globl \name
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro grbword name
	.pushsection ".rbss.word","aw",@nobits
	.globl \name
	.balign 2
\name:
	.space 2
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro girword name val
	.pushsection ".rodata.word","a",@progbits
	.globl \name
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro gidword name val
	.pushsection ".data.word","aw",@progbits
	.globl \name
	.balign 2
\name:
	.word \val
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro gibword name
	.pushsection ".bss.word","aw",@nobits
	.globl \name
	.balign 2
\name:
	.space 2
	.size \name,2
	.type \name,@object
	.popsection
	.endm

	.macro grrlong name val
	.pushsection ".rrodata.long","a",@progbits
	.globl \name
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro grdlong name val
	.pushsection ".rdata.long","aw",@progbits
	.globl \name
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro grblong name
	.pushsection ".rbss.long","aw",@nobits
	.globl \name
	.balign 4
\name:
	.space 4
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro girlong name val
	.pushsection ".rodata.long","a",@progbits
	.globl \name
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro gidlong name val
	.pushsection ".data.long","aw",@progbits
	.globl \name
	.balign 4
\name:
	.long \val
	.size \name,4
	.type \name,@object
	.popsection
	.endm

	.macro giblong name
	.pushsection ".bss.long","aw",@nobits
	.globl \name
	.balign 4
\name:
	.space 4
	.size \name,4
	.type \name,@object
	.popsection
	.endm

/*
 * Macros to define bss buffers
 *
 * Prefix is:
 * <g>lobal or <l>ocal,
 * <r>esident or <i>nit
 */
	.macro lrbuf name len align=1
	.pushsection ".rbss","aw",@nobits
	.balign \align
\name:
	.space \len
	.size \name, .-\name
	.type \name,@object
	.popsection
	.endm

	.macro libuf name len align=1
	.pushsection ".bss","aw",@nobits
	.balign \align
\name:
	.space \len
	.size \name, .-\name
	.type \name,@object
	.popsection
	.endm

	.macro grbuf name len align=1
	.pushsection ".rbss","aw",@nobits
	.globl \name
	.balign \align
\name:
	.space \len
	.size \name, .-\name
	.type \name,@object
	.popsection
	.endm

	.macro gibuf name len align=1
	.pushsection ".bss","aw",@nobits
	.globl \name
	.balign \align
\name:
	.space \len
	.size \name, .-\name
	.type \name,@object
	.popsection
	.endm


#endif /* V9FS_H */