-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransprt.h
1292 lines (1275 loc) · 49.8 KB
/
transprt.h
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*--------------------------------------------------------------------------*/
/* File name: TRANSPRT.H Revision date: 2010.01.31 */
/* Revised by: Miro Kropacek Revision start: 2010.01.31 */
/* Revised by: Ulf Ronald Andersson Revision start: 1999.09.21 */
/* Created by: Peter Rottengatter Creation date: 1996.xx.xx */
/*--------------------------------------------------------------------------*/
/* Header file for all STinG related source files, except those of kernel. */
/*--------------------------------------------------------------------------*/
#ifndef STING_TRANSPRT_H
#define STING_TRANSPRT_H
/*--------------------------------------------------------------------------*/
/* NB: For readability, use a tab size of 4 when viewing this file. */
/*--------------------------------------------------------------------------*/
/* Here follows a section where you can add tests for compiler type, and */
/* use this to read in any extra header files that may be needed to give */
/* STinG applications some useful system types. */
/*--------------------------------------------------------------------------*/
/* NB: Only use advanced compiler or preprocessor features in conditional */
/* clauses, after identifying a compiler that supports those features. */
/*--------------------------------------------------------------------------*/
#if defined __TURBOC__ /* NB: This is set both for TurboC and for PureC */
#include <TOS.H>
#elif defined __GNUC__
#include <mint/basepage.h>
#include <compiler.h>
#define BASPAG BASEPAGE
#elif defined LATTICE
#include <basepage.h>
#define BASPAG BASEPAGE
#endif
/*--------------------------------------------------------------------------*/
/* Definitions of data types used throughout STinG for portability. */
/*--------------------------------------------------------------------------*/
typedef signed char int8; /* Signed 8 bit */
typedef unsigned char uint8; /* Unsigned 8 bit */
typedef signed short int16; /* Signed 16 bit */
typedef unsigned short uint16; /* Unsigned 16 bit */
typedef signed long int32; /* Signed 32 bit */
typedef unsigned long uint32; /* Unsigned 32 bit */
/*--------------------------------------------------------------------------*/
/* Definitions of data types useful when 'porting' network software. */
/*--------------------------------------------------------------------------*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef ntohs
#define ntohs(x) (x)
#endif
#ifndef ntohl
#define ntohl(x) (x)
#endif
#ifndef htons
#define htons(x) (x)
#endif
#ifndef htonl
#define htonl(x) (x)
#endif
/*--------------------------------------------------------------------------*/
/* The last 4 may look silly, but are used a lot by lots of sources, so it */
/* easier to declare them this way than to edit them out of those sources. */
/*--------------------------------------------------------------------------*/
/* The following macro is to cater to compilers that like/dislike 'cdecl'. */
/* Add more tests for other compilers as and when needed. The default is */
/* to make 'cdecl' transparent, to accomodate ANSI compatible compilers. */
/*--------------------------------------------------------------------------*/
#ifndef cdecl
#if defined(__PUREC__)
#elif defined(__TURBOC__)
#elif defined(LATTICE)
#define cdecl __stdargs
#elif defined(__GNUC__)
#define cdecl //__cdecl
#else
#define cdecl
#endif
#endif
/*--------------------------------------------------------------------------*/
/* STiK/STinG driver access structure / functions. */
/*--------------------------------------------------------------------------*/
#define MAGIC "STiKmagic" /* Magic for DRV_LIST.magic */
#define CJTAG "STiK" /* Cookie Jar tag */
typedef struct drv_header
{ /* Header part of TPL structure */
char *module; /* Specific string that can be searched for */
char *author; /* Any string */
char *version; /* Format `00.00' Version:Revision */
} DRV_HDR;
typedef struct drv_list
{
char magic[10]; /* Magic string, defd as MAGIC */
DRV_HDR *cdecl (*get_dftab) (char *); /* Get Driver Function Table */
int16 cdecl (*ETM_exec) (char *); /* Execute a STinG module */
void *cfg; /* Config structure */
BASPAG *sting_basepage; /* STinG basepage address */
} DRV_LIST;
extern DRV_LIST *drivers;
#define get_dftab(x) (*drivers->get_dftab)(x)
#define ETM_exec(x) (*drivers->ETM_exec)(x)
#define TRANSPORT_DRIVER "TRANSPORT_TCPIP"
#define TCP_DRIVER_VERSION "01.00"
/*----------------------------------*/
/* TCP and UDP port escape flags. */
/*----------------------------------*/
#define TCP_ACTIVE 0x0000 /* Initiate active connection */
#define TCP_PASSIVE 0xffff /* Initiate passive connection */
#define UDP_EXTEND 0x0000 /* Extended addressing scheme */
/*----------------------------------*/
/* TCP miscellaneous flags. */
/*----------------------------------*/
#define TCP_URGENT ((void *) -1) /* Mark urgent position */
#define TCP_HALFDUPLEX (-1) /* TCP_close() half duplex */
#define TCP_IMMEDIATE (0) /* TCP_close() immediate */
/*----------------------------------*/
/* TCP connection states. */
/*----------------------------------*/
#define TCLOSED 0 /* No connection. Null, void, absent, ... */
#define TLISTEN 1 /* Wait for remote request */
#define TSYN_SENT 2 /* Connect request sent, await matching request */
#define TSYN_RECV 3 /* Wait for connection ack */
#define TESTABLISH 4 /* Connection established, handshake completed */
#define TFIN_WAIT1 5 /* Await termination request or ack */
#define TFIN_WAIT2 6 /* Await termination request */
#define TCLOSE_WAIT 7 /* Await termination request from local user */
#define TCLOSING 8 /* Await termination ack from remote TCP */
#define TLAST_ACK 9 /* Await ack of terminate request sent */
#define TTIME_WAIT 10 /* Delay, ensures remote has received term' ack */
/*----------------------------------*/
/* UDP connection pseudo states. */
/*----------------------------------*/
#define UCLOSED 0 /* No connection. Null, void, absent, ... */
#define ULISTEN 1 /* Wait for remote request */
#define UESTABLISH 4 /* Connection established, packet received/sent */
/*--------------------------------------------------------------------------*/
/* TCP information block. */
/*--------------------------------------------------------------------------*/
typedef struct tcpib
{ uint32 request; /* 32 bit flags requesting various info (following) */
uint16 state; /* current TCP state */
uint32 unacked; /* unacked outgoing sequence length (incl SYN/FIN) */
uint32 srtt; /* smoothed round trip time of this connection */
} TCPIB;
#define TCPI_state 0x00000001L /* request current TCP state */
#define TCPI_unacked 0x00000002L /* request length of unacked sequence */
#define TCPI_srtt 0x00000004L /* request smoothed round trip time */
#define TCPI_defer 0x00000008L /* request switch to DEFER mode */
#define TCPI_bits 4 /* The number of bits which are defined */
#define TCPI_mask 0x0000000FL /* current sum of defined request bits */
/*--------------------------------------------------------------------------*/
/* NB: A TCP_info request using undefined bits will result in E_PARAMETER. */
/* else the return value will be TCPI_bits, so user knows what we have. */
/* Future additions will use rising bits in sequence, and additions to */
/* the TCPIB struct will always be made at its previous end. */
/*--------------------------------------------------------------------------*/
/* !!! By TCP_info with TCPI_defer, connection is switched to 'DEFER' mode. */
/* This means that all situations where internal looping would occur */
/* will instead lead to exit to the caller with return value E_LOCKED. */
/* Using this mode constitutes agreement to always check for that error */
/* code, which is mainly used for connections using DEFER mode. It may */
/* also be used in some other instances, where a function is blocked in */
/* such a way that internal looping is not possible. */
/*--------------------------------------------------------------------------*/
/* UDP information block. */
/*--------------------------------------------------------------------------*/
typedef struct udpib
{ uint32 request; /* 32 bit flags requesting various info (following) */
uint16 state; /* current UDP pseudo state */
uint32 reserve1; /* reserved */
uint32 reserve2; /* reserved */
} UDPIB;
#define UDPI_state 0x00000001L /* request current UDP pseudo state */
#define UDPI_reserve1 0x00000002L /* reserved */
#define UDPI_reserve2 0x00000004L /* reserved */
#define UDPI_defer 0x00000008L /* request switch to DEFER mode */
#define UDPI_bits 4 /* The number of bits which are defined */
#define UDPI_mask 0x0000000FL /* current sum of defined request bits */
/*--------------------------------------------------------------------------*/
/* NB: A UDP_info request using undefined bits will result in E_PARAMETER. */
/* else the return value will be UDPI_bits, so user knows what we have. */
/* Future additions will use rising bits in sequence, and additions to */
/* the UDPIB struct will always be made at its previous end. */
/*--------------------------------------------------------------------------*/
/* !!! By UDP_info with UDPI_defer, connection is switched to 'DEFER' mode. */
/* This means that all situations where internal looping would occur */
/* will instead lead to exit to the caller with return value E_LOCKED. */
/* Using this mode constitutes agreement to always check for that error */
/* code, which is mainly used for connections using DEFER mode. It may */
/* also be used in some other instances, where a function is blocked in */
/* such a way that internal looping is not possible. */
/*--------------------------------------------------------------------------*/
/* Buffer for inquiring port names. */
/*--------------------------------------------------------------------------*/
typedef struct pnta
{ uint32 opaque; /* Kernel internal data */
int16 name_len; /* Length of port name buffer */
char *port_name; /* Buffer address */
} PNTA;
/*--------------------------------------------------------------------------*/
/* Command opcodes for cntrl_port(). */
/*--------------------------------------------------------------------------*/
#define CTL_KERN_FIRST_PORT (('K' << 8) | 'F') /* Kernel */
#define CTL_KERN_NEXT_PORT (('K' << 8) | 'N') /* Kernel */
#define CTL_KERN_FIND_PORT (('K' << 8) | 'G') /* Kernel */
#define CTL_GENERIC_SET_IP (('G' << 8) | 'H') /* Kernel, all ports */
#define CTL_GENERIC_GET_IP (('G' << 8) | 'I') /* Kernel, all ports */
#define CTL_GENERIC_SET_MASK (('G' << 8) | 'L') /* Kernel, all ports */
#define CTL_GENERIC_GET_MASK (('G' << 8) | 'M') /* Kernel, all ports */
#define CTL_GENERIC_SET_MTU (('G' << 8) | 'N') /* Kernel, all ports */
#define CTL_GENERIC_GET_MTU (('G' << 8) | 'O') /* Kernel, all ports */
#define CTL_GENERIC_GET_MMTU (('G' << 8) | 'P') /* Kernel, all ports */
#define CTL_GENERIC_GET_TYPE (('G' << 8) | 'T') /* Kernel, all ports */
#define CTL_GENERIC_GET_STAT (('G' << 8) | 'S') /* Kernel, all ports */
#define CTL_GENERIC_CLR_STAT (('G' << 8) | 'C') /* Kernel, all ports */
#define CTL_SERIAL_SET_PRTCL (('S' << 8) | 'P') /* Serial Driver */
#define CTL_SERIAL_GET_PRTCL (('S' << 8) | 'Q') /* Serial Driver */
#define CTL_SERIAL_SET_LOGBUFF ('S' << 8 | 'L') /* Serial Driver */
#define CTL_SERIAL_SET_LOGGING ('S' << 8 | 'F') /* Serial Driver */
#define CTL_SERIAL_SET_AUTH (('S' << 8) | 'A') /* Serial Driver */
#define CTL_SERIAL_SET_PAP (('S' << 8) | 'B') /* Serial Driver */
#define CTL_SERIAL_INQ_STATE (('S' << 8) | 'S') /* Serial Driver */
#define CTL_ETHER_SET_MAC (('E' << 8) | 'M') /* EtherNet */
#define CTL_ETHER_GET_MAC (('E' << 8) | 'N') /* EtherNet */
#define CTL_ETHER_INQ_SUPPTYPE (('E' << 8) | 'Q') /* EtherNet */
#define CTL_ETHER_SET_TYPE (('E' << 8) | 'T') /* EtherNet */
#define CTL_ETHER_GET_TYPE (('E' << 8) | 'U') /* EtherNet */
#define CTL_MASQUE_SET_PORT (('M' << 8) | 'P') /* Masquerade */
#define CTL_MASQUE_GET_PORT (('M' << 8) | 'Q') /* Masquerade */
#define CTL_MASQUE_SET_MASKIP (('M' << 8) | 'M') /* Masquerade */
#define CTL_MASQUE_GET_MASKIP (('M' << 8) | 'N') /* Masquerade */
#define CTL_MASQUE_GET_REALIP (('M' << 8) | 'R') /* Masquerade */
/*--------------------------------------------------------------------------*/
/* Handler flag values. */
/*--------------------------------------------------------------------------*/
#define HNDLR_SET 0 /* Set new handler if space */
#define HNDLR_FORCE 1 /* Force new handler to be set */
#define HNDLR_REMOVE 2 /* Remove handler entry */
#define HNDLR_QUERY 3 /* Inquire about handler entry */
/*--------------------------------------------------------------------------*/
/* IP packet header. */
/*--------------------------------------------------------------------------*/
typedef struct ip_header
{ unsigned version : 4; /* IP Version */
unsigned hd_len : 4; /* Internet Header Length */
unsigned tos : 8; /* Type of Service */
uint16 length; /* Total of all header, options and data */
uint16 ident; /* Identification for fragmentation */
unsigned reserved : 1; /* Reserved : Must be zero */
unsigned dont_frg : 1; /* Don't fragment flag */
unsigned more_frg : 1; /* More fragments flag */
unsigned frag_ofst : 13; /* Fragment offset */
uint8 ttl; /* Time to live */
uint8 protocol; /* Protocol */
uint16 hdr_chksum; /* Header checksum */
uint32 ip_src; /* Source IP address */
uint32 ip_dest; /* Destination IP address */
} IP_HDR;
/*--------------------------------------------------------------------------*/
/* Internal IP packet representation. */
/*--------------------------------------------------------------------------*/
typedef struct ip_packet
{ IP_HDR hdr; /* Header of IP packet */
void *options; /* Options data block */
int16 opt_length; /* Length of options data block */
void *pkt_data; /* IP packet data block */
int16 pkt_length; /* Length of IP packet data block */
uint32 timeout; /* Timeout of packet life */
uint32 ip_gateway; /* Gateway for forwarding this packet */
void *recvd; /* Receiving port */
struct ip_packet *next; /* Next IP packet in IP packet queue */
} IP_DGRAM;
/*--------------------------------------------------------------------------*/
/* Values for protocol field in IP headers */
/*--------------------------------------------------------------------------*/
#define P_ICMP 1 /* IP assigned number for ICMP */
#define P_TCP 6 /* IP assigned number for TCP */
#define P_UDP 17 /* IP assigned number for UDP */
/*--------------------------------------------------------------------------*/
/* Input queue structure. */
/*--------------------------------------------------------------------------*/
typedef struct ndb /* Network Data Block. For data delivery */
{ char *ptr; /* Pointer to base of block. (For KRfree();) */
char *ndata; /* Pointer to next data to deliver */
uint16 len; /* Length of remaining data */
struct ndb *next; /* Next NDB in chain or NULL */
} NDB;
/*--------------------------------------------------------------------------*/
/* Addressing information block. */
/*--------------------------------------------------------------------------*/
typedef struct cab
{ uint16 lport; /* TCP local port (ie: local machine) */
uint16 rport; /* TCP remote port (ie: remote machine) */
uint32 rhost; /* TCP remote IP addr (ie: remote machine) */
uint32 lhost; /* TCP local IP addr (ie: local machine) */
} CAB;
/*--------------------------------------------------------------------------*/
/* Connection information block. */
/*--------------------------------------------------------------------------*/
typedef struct cib /* Connection Information Block */
{ uint16 protocol; /* TCP or UDP or ... 0 means CIB is not in use */
CAB address; /* Adress information */
uint16 status; /* Net status. 0 means normal */
} CIB;
/*--------------------------------------------------------------------------*/
/* Transport structure / functions. */
/*--------------------------------------------------------------------------*/
typedef struct tpl
{ char * module; /* Specific string that can be searched for */
char * author; /* Any string */
char * version; /* Format `00.00' Version:Revision */
void * cdecl (* KRmalloc) (int32);
void cdecl (* KRfree) (void *);
int32 cdecl (* KRgetfree) (int16);
void * cdecl (* KRrealloc) (void *, int32);
char * cdecl (* get_err_text) (int16);
char * cdecl (* getvstr) (char *);
int16 cdecl (* carrier_detect) (void);
int16 cdecl (* TCP_open) (uint32, uint16, uint16, uint16);
int16 cdecl (* TCP_close) (int16, int16, int16 *);
int16 cdecl (* TCP_send) (int16, void *, int16);
int16 cdecl (* TCP_wait_state) (int16, int16, int16);
int16 cdecl (* TCP_ack_wait) (int16, int16);
int16 cdecl (* UDP_open) (uint32, uint16);
int16 cdecl (* UDP_close) (int16);
int16 cdecl (* UDP_send) (int16, void *, int16);
int16 cdecl (* CNkick) (int16);
int16 cdecl (* CNbyte_count) (int16);
int16 cdecl (* CNget_char) (int16);
NDB * cdecl (* CNget_NDB) (int16);
int16 cdecl (* CNget_block) (int16, void *, int16);
void cdecl (* housekeep) (void);
int16 cdecl (* resolve) (char *, char **, uint32 *, int16);
void cdecl (* ser_disable) (void);
void cdecl (* ser_enable) (void);
int16 cdecl (* set_flag) (int16);
void cdecl (* clear_flag) (int16);
CIB * cdecl (* CNgetinfo) (int16);
int16 cdecl (* on_port) (char *);
void cdecl (* off_port) (char *);
int16 cdecl (* setvstr) (char *, char *);
int16 cdecl (* query_port) (char *);
int16 cdecl (* CNgets) (int16, char *, int16, char);
int16 cdecl (* ICMP_send) (uint32, uint8, uint8, void *, uint16);
int16 cdecl (* ICMP_handler) (int16 cdecl (*) (IP_DGRAM *), int16);
void cdecl (* ICMP_discard) (IP_DGRAM *);
int16 cdecl (* TCP_info) (int16, TCPIB *);
int16 cdecl (* cntrl_port) (char *, uint32, int16);
int16 cdecl (* UDP_info) (int16, UDPIB *);
int16 cdecl (* RAW_open)(uint32);
int16 cdecl (* RAW_close)(int16);
int16 cdecl (* RAW_out)(int16, void *, int16, uint32);
int16 cdecl (* CN_setopt)(int16, int16, const void *, int16);
int16 cdecl (* CN_getopt)(int16, int16, void *, int16 *);
void cdecl (* CNfree_NDB)(int16, NDB *);
} TPL;
extern TPL *tpl;
/*--------------------------------------------------------------------------*/
/* Definitions of internal submacros needed for macros further below. */
/*--------------------------------------------------------------------------*/
#ifndef __GNUC__
/*--------------------------------------------------------------------------*/
/* The macros in this clause are for Pure_C and other normal compilers that */
/* are aware of the Atari standard of passing arguments in fitting sizes on */
/* stack, so a short int will use a single 16 bit word, even if the default */
/* 'int' size for that compiler is set to 32-bit length. */
/* Those are different things, and should be separately controlled options. */
/*--------------------------------------------------------------------------*/
#define STinG_vf_v(func) ((func)())
#define STinG_wf_v(func) ((func)())
#define STinG_vf_p(func, x) ((func)(x))
#define STinG_vf_s(func, x) ((func)(x))
#define STinG_vf_D(func, x) ((func)(x))
#define STinG_wf_w(func, x) ((func)(x))
#define STinG_wf_L(func, x) ((func)(x))
#define STinG_Cf_w(func, x) ((func)(x))
#define STinG_Nf_w(func, x) ((func)(x))
#define STinG_wf_s(func, x) ((func)(x))
#define STinG_lf_w(func, x) ((func)(x))
#define STinG_sf_w(func, x) ((func)(x))
#define STinG_sf_s(func, x) ((func)(x))
#define STinG_pf_l(func, x) ((func)(x))
#define STinG_vf_wN(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_ww(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_wy(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_wz(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_xw(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_LW(func, x1,x2) ((func)((x1),(x2)))
#define STinG_wf_ss(func, x1,x2) ((func)((x1),(x2)))
#define STinG_pf_pl(func, x1, x2) ((func)((x1),(x2)))
#define STinG_wf_www(func, x1,x2,x3) ((func)((x1),(x2),(x3)))
#define STinG_wf_wwP(func, x1,x2,x3) ((func)((x1),(x2),(x3)))
#define STinG_wf_wpw(func, x1,x2,x3) ((func)((x1),(x2),(x3)))
#define STinG_wf_sLw(func, x1,x2,x3) ((func)((x1),(x2),(x3)))
#define STinG_wf_LWWW(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_wswb(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_sSRw(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_wwpw(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_wwpW(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_wpwl(func, x1,x2,x3,x4) ((func)((x1),(x2),(x3),(x4)))
#define STinG_wf_LBBpW(func, x1,x2,x3,x4,x5) ((func)((x1),(x2),(x3),(x4),(x5)))
/*--------------------------------------------------------------------------*/
#else /* else __GNUC__ is defined */
/*--------------------------------------------------------------------------*/
/* The macros below allow Gnu C to function with STinG API regardless of */
/* whether default 'int' size is 16 or 32 bits, despite the fact that the */
/* latter setting normally causes Gnu C to pass short arguments wrongly. */
/* (As defined by the standards set by Atari for TOS compatible systems.) */
/*--------------------------------------------------------------------------*/
#ifndef AND_MEMORY /* because 'osbind.h' uses similar methods... */
#if ((__GNUC__ > 2) && (__GNUC_MINOR__ > 5))
#define AND_MEMORY , "memory"
#else /* else for ancient compiler versions */
#define AND_MEMORY
#define __extension__
#endif
#endif
/*--------------------------------------------------------------------------*/
/* The macros below allow Gnu C to function with STinG API regardless of */
/* whether default 'int' size is 16 or 32 bits, despite the fact that the */
/* latter setting normally causes Gnu C to pass short arguments wrongly. */
/* (As defined by the standards set by Atari for TOS compatible systems.) */
/*--------------------------------------------------------------------------*/
#define STinG_vf_v(func) \
__extension__ \
({ __asm__ volatile \
( \
"movl %0,a0\n\t" \
"jsr a0@" \
/* end of code */ \
: /* no outputs */ \
: "g" (func) \
: "d0","d1","d2","a0","a1" \
AND_MEMORY \
); \
; /* This makes value 'void' */ \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_v(func) \
__extension__ \
({ register int16 retv __asm__("d0"); \
__asm__ volatile \
( \
"movl %1,a0\n\t" \
"jsr a0@" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_vf_p(func, arg1) \
__extension__ \
({ void *_arg1 = (void *)(arg1); \
__asm__ volatile \
( \
"movl %1,sp@-\n\t" \
"movl %0,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: /* no outputs */ \
: "g" (func) \
, "r" (_arg1) \
: "d0","d1","d2","a0","a1" \
AND_MEMORY \
); \
; /* This makes value 'void' */ \
})
/*--------------------------------------------------------------------------*/
#define STinG_vf_s(func, arg1) \
__extension__ \
({ char *_arg1 = (char *)(arg1); \
__asm__ volatile \
( \
"movl %1,sp@-\n\t" \
"movl %0,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: /* no outputs */ \
: "g" (func) \
, "r" (_arg1) \
: "d0","d1","d2","a0","a1" \
AND_MEMORY \
); \
; /* This makes value 'void' */ \
})
/*--------------------------------------------------------------------------*/
#define STinG_vf_D(func, arg1) \
__extension__ \
({ IP_DGRAM *_arg1 = (IP_DGRAM *)(arg1); \
__asm__ volatile \
( \
"movl %1,sp@-\n\t" \
"movl %0,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: /* no outputs */ \
: "g" (func) \
, "r" (_arg1) \
: "d0","d1","d2","a0","a1" \
AND_MEMORY \
); \
; /* This makes value 'void' */ \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_w(func, arg1) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
__asm__ volatile \
( \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #2,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_L(func, arg1) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int32 _arg1 = (int32)(arg1); \
__asm__ volatile \
( \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_Cf_w(func, arg1) \
__extension__ \
({ register CIB *retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
__asm__ volatile \
( \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #2,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_Nf_w(func, arg1) \
__extension__ \
({ register NDB *retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
__asm__ volatile \
( \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #2,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_s(func, arg1) \
__extension__ \
({ register int16 retv __asm__("d0"); \
char *_arg1 = (char *)(arg1); \
__asm__ volatile \
( \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_lf_w(func, arg1) \
__extension__ \
({ register int32 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
__asm__ volatile \
( \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #2,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_sf_w(func, arg1) \
__extension__ \
({ register char *retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
__asm__ volatile \
( \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #2,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_sf_s(func, arg1) \
__extension__ \
({ register char *retv __asm__("d0"); \
char *_arg1 = (char *)(arg1); \
__asm__ volatile \
( \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_pf_l(func, arg1) \
__extension__ \
({ register void* retv __asm__("d0"); \
int32 _arg1 = (int32)(arg1); \
__asm__ volatile \
( \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_vf_wN(func, arg1,arg2) \
__extension__ \
({ int16 _arg1 = (int16)(arg1); \
NDB *_arg2 = (NDB *)(arg2); \
__asm__ volatile \
( \
"movl %2,sp@-\n\t" \
"movw %1,sp@-\n\t" \
"movl %0,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: /* no outputs */ \
: "g" (func) \
, "r" (_arg1) \
, "r" (_arg2) \
: "d0","d1","d2","a0","a1" \
AND_MEMORY \
); \
; /* This makes value 'void' */ \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_ww(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
int16 _arg2 = (int16)(arg2); \
__asm__ volatile \
( \
"movw %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #4,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_wy(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
TCPIB *_arg2 = (TCPIB *)(arg2); \
__asm__ volatile \
( \
"movl %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_wz(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
UDPIB *_arg2 = (UDPIB *)(arg2); \
__asm__ volatile \
( \
"movl %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_xw(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 cdecl (*) (IP_DGRAM *) _arg1 = (int16 cdecl (*) (IP_DGRAM *))(arg1); \
int16 _arg2 = (int16)(arg2); \
__asm__ volatile \
( \
"movw %3,sp@-\n\t" \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_LW(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
uint32 _arg1 = (uint32)(arg1); \
uint16 _arg2 = (uint16)(arg2); \
__asm__ volatile \
( \
"movw %3,sp@-\n\t" \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_ss(func, arg1,arg2) \
__extension__ \
({ register int16 retv __asm__("d0"); \
char *_arg1 = (char *)(arg1); \
char *_arg2 = (char *)(arg2); \
__asm__ volatile \
( \
"movl %3,sp@-\n\t" \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #8,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_pf_pl(func, arg1, arg2) \
__extension__ \
({ register void* retv __asm__("d0"); \
void *_arg1 = (void *)(arg1); \
int32 _arg2 = (int32)(arg2); \
__asm__ volatile \
( \
"movl %3,sp@-\n\t" \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #8,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_www(func, arg1,arg2,arg3) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
int16 _arg2 = (int16)(arg2); \
int16 _arg3 = (int16)(arg3); \
__asm__ volatile \
( \
"movw %4,sp@-\n\t" \
"movw %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #6,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
, "r" (_arg3) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_wwP(func, arg1,arg2,arg3) \
__extension__ \
({ register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
int16 _arg2 = (int16)(arg2); \
int16 *_arg3 = (int16 *)(arg3); \
__asm__ volatile \
( \
"movl %4,sp@-\n\t" \
"movw %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #8,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
, "r" (_arg3) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_wpw(func, arg1,arg2,arg3) \
__extension__ \
({ \
register int16 retv __asm__("d0"); \
int16 _arg1 = (int16)(arg1); \
void *_arg2 = (void *)(arg2); \
int16 _arg3 = (int16)(arg3); \
__asm__ volatile \
( \
"movw %4,sp@-\n\t" \
"movl %3,sp@-\n\t" \
"movw %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"addql #8,sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
, "r" (_arg3) /* in */ \
: __CLOBBER_RETURN("d0") "d1", "d2", "a0", "a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_sLw(func, arg1,arg2,arg3) \
__extension__ \
({ register int16 retv __asm__("d0"); \
char *_arg1 = (char *)(arg1); \
uint32 _arg2 = (uint32)(arg2); \
int16 _arg3 = (int16)(arg3); \
__asm__ volatile \
( \
"movw %4,sp@-\n\t" \
"movl %3,sp@-\n\t" \
"movl %2,sp@-\n\t" \
"movl %1,a0\n\t" \
"jsr a0@\n\t" \
"lea sp@(10),sp" \
/* end of code */ \
: "=r" (retv) /* out */ \
: "g" (func) /* in */ \
, "r" (_arg1) /* in */ \
, "r" (_arg2) /* in */ \
, "r" (_arg3) /* in */ \
: __CLOBBER_RETURN("d0") "d1","d2","a0","a1" \
AND_MEMORY \
); \
retv; \
})
/*--------------------------------------------------------------------------*/
#define STinG_wf_LWWW(func, arg1,arg2,arg3,arg4) \
__extension__ \
({ register int16 retv __asm__("d0"); \
uint32 _arg1 = (uint32)(arg1); \