source: trunk/src/libc.i@ 4

Last change on this file since 4 was 4, checked in by root, 15 years ago

initial checkin of CM's code

File size: 12.0 KB
RevLine 
[4]1#line 1 "libc.c"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#line 1 "os2ahci.h"
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
301typedef unsigned char u8;
302typedef unsigned short u16;
303typedef unsigned long u32;
304
305
306typedef struct {
307 u32 options;
308 u32 status;
309 u32 tbl_addr;
310 u32 tbl_addr_high;
311 u32 reserved[4];
312} AHCI_CMD_HDR;
313
314
315typedef struct {
316 u32 addr;
317 u32 addr_hi;
318 u32 reserved;
319 u32 flags_size;
320} AHCI_SG;
321
322
323
324
325
326typedef struct {
327 u16 vendor;
328 u16 device;
329 u16 subvendor;
330 u16 subdevice;
331 u32 class;
332 u32 class_mask;
333 u32 board;
334} PCI_ID;
335
336
337typedef struct D_INFO {
338 struct D_INFO *next;
339 char vendor[8];
340 char product[8];
341 char revision[8];
342 u32 sectors;
343};
344
345
346typedef struct P_INFO {
347 struct P_INFO *p_info;
348} P_INFO;
349
350
351typedef struct AD_INFO {
352 struct AD_INFO *next;
353 PCI_ID *pci_id;
354 P_INFO ports[32];
355 int intr;
356 u8 *mmio;
357 u8 *dma_buf;
358} AD_INFO;
359
360
361
362
363
364
365extern int debug;
366
367extern PCI_ID pci_ids[];
368extern AD_INFO *ai_root;
369
370#line 23 "libc.c"
371
372#line 1 "i:/c600/include\\stdarg.h"
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387#line 16 "i:/c600/include\\stdarg.h"
388
389
390
391
392
393#line 22 "i:/c600/include\\stdarg.h"
394
395
396
397
398
399
400
401
402
403
404#line 33 "i:/c600/include\\stdarg.h"
405#line 34 "i:/c600/include\\stdarg.h"
406
407
408typedef char *va_list;
409
410#line 39 "i:/c600/include\\stdarg.h"
411
412
413
414
415#line 25 "libc.c"
416#line 1 "i:/c600/include\\stdio.h"
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431#line 16 "i:/c600/include\\stdio.h"
432
433
434
435
436
437#line 22 "i:/c600/include\\stdio.h"
438
439
440typedef unsigned int size_t;
441
442#line 27 "i:/c600/include\\stdio.h"
443
444
445
446
447
448
449
450
451
452
453
454
455
456#line 41 "i:/c600/include\\stdio.h"
457
458
459
460struct _iobuf {
461 char *_ptr;
462 int _cnt;
463 char *_base;
464 char _flag;
465 char _file;
466 };
467typedef struct _iobuf FILE;
468
469#line 54 "i:/c600/include\\stdio.h"
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
519extern FILE _near _cdecl _iob[];
520#line 105 "i:/c600/include\\stdio.h"
521#line 106 "i:/c600/include\\stdio.h"
522
523
524
525
526
527typedef long fpos_t;
528
529#line 114 "i:/c600/include\\stdio.h"
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
558int _cdecl _filbuf(FILE *);
559int _cdecl _flsbuf(int, FILE *);
560FILE * _cdecl _fsopen(const char *,
561 const char *, int);
562void _cdecl clearerr(FILE *);
563int _cdecl fclose(FILE *);
564int _cdecl fcloseall(void);
565FILE * _cdecl fdopen(int, const char *);
566int _cdecl feof(FILE *);
567int _cdecl ferror(FILE *);
568int _cdecl fflush(FILE *);
569int _cdecl fgetc(FILE *);
570int _cdecl fgetchar(void);
571int _cdecl fgetpos(FILE *, fpos_t *);
572char * _cdecl fgets(char *, int, FILE *);
573int _cdecl fileno(FILE *);
574int _cdecl flushall(void);
575FILE * _cdecl fopen(const char *,
576 const char *);
577int _cdecl fprintf(FILE *, const char *, ...);
578int _cdecl fputc(int, FILE *);
579int _cdecl fputchar(int);
580int _cdecl fputs(const char *, FILE *);
581size_t _cdecl fread(void *, size_t, size_t, FILE *);
582FILE * _cdecl freopen(const char *,
583 const char *, FILE *);
584int _cdecl fscanf(FILE *, const char *, ...);
585int _cdecl fsetpos(FILE *, const fpos_t *);
586int _cdecl fseek(FILE *, long, int);
587long _cdecl ftell(FILE *);
588size_t _cdecl fwrite(const void *, size_t, size_t,
589 FILE *);
590int _cdecl getc(FILE *);
591int _cdecl getchar(void);
592char * _cdecl gets(char *);
593int _cdecl getw(FILE *);
594void _cdecl perror(const char *);
595int _cdecl _pclose(FILE *);
596FILE * _cdecl _popen(const char *,
597 const char *);
598int _cdecl printf(const char *, ...);
599int _cdecl putc(int, FILE *);
600int _cdecl putchar(int);
601int _cdecl puts(const char *);
602int _cdecl putw(int, FILE *);
603int _cdecl remove(const char *);
604int _cdecl rename(const char *, const char *);
605void _cdecl rewind(FILE *);
606int _cdecl rmtmp(void);
607int _cdecl scanf(const char *, ...);
608void _cdecl setbuf(FILE *, char *);
609int _cdecl setvbuf(FILE *, char *, int, size_t);
610int _cdecl sprintf(char *, const char *, ...);
611int _cdecl sscanf(const char *, const char *, ...);
612char * _cdecl tempnam(char *, char *);
613FILE * _cdecl tmpfile(void);
614char * _cdecl tmpnam(char *);
615int _cdecl ungetc(int, FILE *);
616int _cdecl unlink(const char *);
617int _cdecl vfprintf(FILE *, const char *, va_list);
618int _cdecl vprintf(const char *, va_list);
619int _cdecl vsprintf(char *, const char *, va_list);
620
621#line 206 "i:/c600/include\\stdio.h"
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641#line 26 "libc.c"
642#line 1 "i:/c600/include\\string.h"
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657#line 16 "i:/c600/include\\string.h"
658
659
660
661
662
663#line 22 "i:/c600/include\\string.h"
664
665
666
667
668
669
670
671
672void * _cdecl memccpy(void *, const void *,
673 int, unsigned int);
674void * _cdecl memchr(const void *, int, size_t);
675int _cdecl memcmp(const void *, const void *,
676 size_t);
677int _cdecl memicmp(const void *, const void *,
678 unsigned int);
679void * _cdecl memcpy(void *, const void *,
680 size_t);
681void * _cdecl memmove(void *, const void *,
682 size_t);
683void * _cdecl memset(void *, int, size_t);
684void _cdecl movedata(unsigned int, unsigned int, unsigned int,
685 unsigned int, unsigned int);
686char * _cdecl strcat(char *, const char *);
687char * _cdecl strchr(const char *, int);
688int _cdecl strcmp(const char *, const char *);
689int _cdecl strcmpi(const char *, const char *);
690int _cdecl strcoll(const char *, const char *);
691int _cdecl stricmp(const char *, const char *);
692char * _cdecl strcpy(char *, const char *);
693size_t _cdecl strcspn(const char *, const char *);
694char * _cdecl strdup(const char *);
695char * _cdecl _strerror(const char *);
696char * _cdecl strerror(int);
697size_t _cdecl strlen(const char *);
698char * _cdecl strlwr(char *);
699char * _cdecl strncat(char *, const char *,
700 size_t);
701int _cdecl strncmp(const char *, const char *,
702 size_t);
703int _cdecl strnicmp(const char *, const char *,
704 size_t);
705char * _cdecl strncpy(char *, const char *,
706 size_t);
707char * _cdecl strnset(char *, int, size_t);
708char * _cdecl strpbrk(const char *,
709 const char *);
710char * _cdecl strrchr(const char *, int);
711char * _cdecl strrev(char *);
712char * _cdecl strset(char *, int);
713size_t _cdecl strspn(const char *, const char *);
714char * _cdecl strstr(const char *,
715 const char *);
716char * _cdecl strtok(char *, const char *);
717char * _cdecl strupr(char *);
718size_t _cdecl strxfrm (char *, const char *,
719 size_t);
720
721
722
723void _far * _far _cdecl _fmemccpy(void _far *, const void _far *,
724 int, unsigned int);
725void _far * _far _cdecl _fmemchr(const void _far *, int, size_t);
726int _far _cdecl _fmemcmp(const void _far *, const void _far *,
727 size_t);
728void _far * _far _cdecl _fmemcpy(void _far *, const void _far *,
729 size_t);
730int _far _cdecl _fmemicmp(const void _far *, const void _far *,
731 unsigned int);
732void _far * _far _cdecl _fmemmove(void _far *, const void _far *,
733 size_t);
734void _far * _far _cdecl _fmemset(void _far *, int, size_t);
735char _far * _far _cdecl _fstrcat(char _far *, const char _far *);
736char _far * _far _cdecl _fstrchr(const char _far *, int);
737int _far _cdecl _fstrcmp(const char _far *, const char _far *);
738int _far _cdecl _fstricmp(const char _far *, const char _far *);
739char _far * _far _cdecl _fstrcpy(char _far *, const char _far *);
740size_t _far _cdecl _fstrcspn(const char _far *, const char _far *);
741char _far * _far _cdecl _fstrdup(const char _far *);
742char _near * _far _cdecl _nstrdup(const char _far *);
743size_t _far _cdecl _fstrlen(const char _far *);
744char _far * _far _cdecl _fstrlwr(char _far *);
745char _far * _far _cdecl _fstrncat(char _far *, const char _far *,
746 size_t);
747int _far _cdecl _fstrncmp(const char _far *, const char _far *,
748 size_t);
749int _far _cdecl _fstrnicmp(const char _far *, const char _far *,
750 size_t);
751char _far * _far _cdecl _fstrncpy(char _far *, const char _far *,
752 size_t);
753char _far * _far _cdecl _fstrnset(char _far *, int, size_t);
754char _far * _far _cdecl _fstrpbrk(const char _far *,
755 const char _far *);
756char _far * _far _cdecl _fstrrchr(const char _far *, int);
757char _far * _far _cdecl _fstrrev(char _far *);
758char _far * _far _cdecl _fstrset(char _far *, int);
759size_t _far _cdecl _fstrspn(const char _far *, const char _far *);
760char _far * _far _cdecl _fstrstr(const char _far *,
761 const char _far *);
762char _far * _far _cdecl _fstrtok(char _far *, const char _far *);
763char _far * _far _cdecl _fstrupr(char _far *);
764#line 27 "libc.c"
765
766
767
768
769
770
771
772static void long_to_asc(long val, char *buf, int radix);
773
774
775
776static char hex_digits[] = "0123456789abcdef";
777
778
779
780
781
782
783
784
785int vsprintf(char *buf, const char *fmt, va_list va)
786{
787 char *orig = buf;
788 char *s;
789 int lmod;
790
791 for (; *fmt != '\0'; fmt++) {
792 switch (*fmt) {
793
794 case '%':
795 lmod = (fmt[1] == 'l') ? 1 : 0;
796 fmt += lmod;
797 switch (fmt[1]) {
798
799 case 's':
800 if ((s = ((char * *)(va += sizeof(char *)))[-1]) == ((void *)0))
801 s = "[null]";
802 while ((*buf = *(s++)) != '\0')
803 buf++;
804 break;
805
806 case 'd':
807 long_to_asc((lmod) ? ((long *)(va += sizeof(long)))[-1] : ((int *)(va += sizeof(int)))[-1], buf, 10);
808 buf += strlen(buf);
809 break;
810
811 case 'x':
812 long_to_asc((lmod) ? ((long *)(va += sizeof(long)))[-1] : ((int *)(va += sizeof(int)))[-1], buf, 16);
813 buf += strlen(buf);
814 break;
815
816 default:
817 *(buf++) = *fmt;
818 break;
819 }
820
821 case '\n':
822 *(buf++) = '\r';
823 *(buf++) = '\n';
824 break;
825
826 default:
827 *(buf++) = *fmt;
828 break;
829
830 }
831 }
832
833 *buf = '\0';
834 return((size_t) (buf - orig));
835}
836
837
838
839
840int sprintf(char *buf, const char *fmt, ...)
841{
842 va_list va;
843
844 va = (va_list)&fmt + sizeof(fmt);
845 return(vsprintf(buf, fmt, va));
846}
847
848
849
850
851
852
853
854void dprintf(const char *fmt, ...)
855{
856 static long mutex;
857 static char buf[1024];
858 va_list va;
859 char *s;
860
861 if (!debug) {
862 return;
863 }
864
865 DevHelp_SemRequest(&mutex, -1L);
866
867 va = (va_list)&fmt + sizeof(fmt);
868 vsprintf(buf, fmt, va);
869
870
871 for (s = buf; *s != '\0'; s++) {
872 while (!inp(0x3fd) & 0x40);
873 outp(0x3f8, *s);
874 }
875
876 DevHelp_SemClear(&mutex);
877}
878
879
880
881
882void *memmove(void *v_dst, void *v_src, size_t len)
883{
884 char *dst = (char *) v_dst;
885 char *src = (char *) v_src;
886 void *orig = dst;
887
888 if (dst <= src || dst > src + len) {
889
890 while (len--) {
891 *(dst++) = *(src++);
892 }
893
894 } else {
895
896
897
898 src += len;
899 dst += len;
900 while (len--) {
901 *(--dst) = *(--src);
902 }
903 }
904
905 return(orig);
906}
907
908
909
910
911size_t strlen(const char *s)
912{
913 size_t len = 0;
914
915 while (*(s++) != '\0') {
916 len++;
917 }
918 return(len);
919}
920
921
922
923
924char *strcpy(char *dst, const char *src)
925{
926 char *orig = dst;
927
928 while ((*(dst++) = *(src++)) != '\0');
929 return(orig);
930}
931
932
933
934
935static void long_to_asc(long val, char *buf, int radix)
936{
937 char tmp[80];
938 char *s;
939
940 if (radix > 16) {
941 sprintf(buf, "n/a");
942 }
943
944 tmp[sizeof(tmp) - 1] = '\0';
945
946 for (s = tmp + sizeof(tmp) - 2; s > tmp; s--) {
947 *s = hex_digits[val % radix];
948 if ((val /= radix) == 0) {
949 break;
950 }
951 }
952
953 strcpy(buf, s);
954}
955
Note: See TracBrowser for help on using the repository browser.