-
Notifications
You must be signed in to change notification settings - Fork 1
/
standalone.diff
2444 lines (2187 loc) · 68.4 KB
/
standalone.diff
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
diff -urN ghc-6.2.orig/configure.ac ghc-6.2/configure.ac
--- ghc-6.2.orig/configure.ac 2003-11-20 11:09:33.000000000 +0100
+++ ghc-6.2/configure.ac 2004-02-27 15:33:05.000000000 +0100
@@ -575,6 +575,17 @@
)
AC_SUBST(ThreadedRts)
+dnl ** Enable system-independent RTS?
+dnl --------------------------------------------------------------
+AC_ARG_ENABLE(standalone-rts,
+[ --enable-standalone-rts
+ Generate system-independent RTS.
+],
+[StandaloneRts=YES],
+[StandaloneRts=NO]
+)
+AC_SUBST(StandaloneRts)
+
dnl ** Enable the construction of Win32 DLLs?
dnl --------------------------------------------------------------
dnl
@@ -838,6 +849,8 @@
dnl ### program checking section ends here ###
dnl --------------------------------------------------
+if test "StandaloneRts" = "NO"; then
+
dnl --------------------------------------------------
dnl * Platform header file and syscall feature tests
dnl ### checking the state of the local header files and syscalls ###
@@ -1189,6 +1202,13 @@
AC_DEFINE([HAVE_READLINE_4_2], [0], [Define to 1 if readline has version >= 4.2.])
fi
+dnl ** check for wide-char classifications
+dnl FreeBSD has an emtpy wctype.h, so test one of the affected
+dnl functions if it's really there.
+AC_CHECK_HEADERS(wctype.h,
+ [AC_CHECK_FUNCS(iswspace)]
+)
+
dnl ** check for math library
FPTOOLS_CHECK_LIBM()
AC_SUBST(LIBM)
@@ -1437,4 +1457,129 @@
AC_DEFINE([HAVE_SC_GETPW_R_SIZE_MAX], [1], [Define to 1 if <unistd.h> defines _SC_GETPW_R_SIZE_MAX.])],
[AC_MSG_RESULT([no])])
+else
+dnl Standalone RTS has pretty much everything hardwired.
+
+dnl ** does #! work?
+AC_SYS_INTERPRETER()
+
+dnl ** look for `perl', but only in /bin on Windows
+case $HostOS_CPP in
+cygwin32|mingw32)
+ AC_CHECK_PROG(PerlCmd,perl,/bin/perl,,/bin)
+ if test -z "$PerlCmd"; then
+ echo "You must install the version of Perl shipped with GHC"
+ echo "(or a compatible one) in /bin."
+ exit 1
+ fi
+ ;;
+*)
+ AC_PATH_PROG(PerlCmd,perl)
+ if test -z "$PerlCmd"; then
+ echo "You must install perl before you can continue"
+ echo "Perhaps it is already installed, but not in your PATH?"
+ exit 1
+ else
+ FPTOOLS_CHECK_PERL_VERSION
+ fi
+ ;;
+esac
+
+AC_DEFINE([STANDALONE], [1], [Define to 1 for standalone RTS.])
+
+dnl ** check for math library
+FPTOOLS_CHECK_LIBM()
+AC_SUBST(LIBM)
+
+dnl ** check whether this machine has gmp3 installed
+AC_CHECK_LIB(gmp, __gmpz_fdiv_qr, HaveLibGmp=YES; LibGmp=gmp,
+ AC_CHECK_LIB(gmp3, __gmpz_fdiv_qr, HaveLibGmp=YES; LibGmp=gmp3,
+ HaveLibGmp=NO; LibGmp=not-installed))
+AC_SUBST(HaveLibGmp)
+AC_SUBST(LibGmp)
+
+dnl ** do we have long longs?
+AC_CHECK_TYPES([long long])
+
+dnl ** what are the sizes of various types
+AC_CHECK_SIZEOF(char, 1)
+AC_CHECK_SIZEOF(double, 8)
+AC_CHECK_SIZEOF(float, 4)
+AC_CHECK_SIZEOF(int, 4)
+AC_CHECK_SIZEOF(long, 4)
+if test "$ac_cv_type_long_long" = yes; then
+AC_CHECK_SIZEOF(long long, 8)
+fi
+AC_CHECK_SIZEOF(short, 2)
+AC_CHECK_SIZEOF(unsigned char, 1)
+AC_CHECK_SIZEOF(unsigned int, 4)
+AC_CHECK_SIZEOF(unsigned long, 4)
+if test "$ac_cv_type_long_long" = yes; then
+AC_CHECK_SIZEOF(unsigned long long, 8)
+fi
+AC_CHECK_SIZEOF(unsigned short, 2)
+AC_CHECK_SIZEOF(void *, 4)
+
+dnl ** what are alignment constraints on various types
+FP_CHECK_ALIGNMENT(char)
+FP_CHECK_ALIGNMENT(double)
+FP_CHECK_ALIGNMENT(float)
+FP_CHECK_ALIGNMENT(int)
+FP_CHECK_ALIGNMENT(long)
+if test "$ac_cv_type_long_long" = yes; then
+FP_CHECK_ALIGNMENT(long long)
+fi
+FP_CHECK_ALIGNMENT(short)
+FP_CHECK_ALIGNMENT(unsigned char)
+FP_CHECK_ALIGNMENT(unsigned int)
+FP_CHECK_ALIGNMENT(unsigned long)
+if test "$ac_cv_type_long_long" = yes; then
+FP_CHECK_ALIGNMENT(unsigned long long)
+fi
+FP_CHECK_ALIGNMENT(unsigned short)
+FP_CHECK_ALIGNMENT(void *)
+
+dnl ** map standard C types and ISO types to Haskell types
+FPTOOLS_CHECK_HTYPE(char)
+FPTOOLS_CHECK_HTYPE(signed char)
+FPTOOLS_CHECK_HTYPE(unsigned char)
+FPTOOLS_CHECK_HTYPE(short)
+FPTOOLS_CHECK_HTYPE(unsigned short)
+FPTOOLS_CHECK_HTYPE(int)
+FPTOOLS_CHECK_HTYPE(unsigned int)
+FPTOOLS_CHECK_HTYPE(long)
+FPTOOLS_CHECK_HTYPE(unsigned long)
+if test "$ac_cv_type_long_long" = yes; then
+FPTOOLS_CHECK_HTYPE(long long)
+FPTOOLS_CHECK_HTYPE(unsigned long long)
+fi
+FPTOOLS_CHECK_HTYPE(float)
+FPTOOLS_CHECK_HTYPE(double)
+FPTOOLS_CHECK_HTYPE(ptrdiff_t)
+FPTOOLS_CHECK_HTYPE(size_t)
+FPTOOLS_CHECK_HTYPE(wchar_t)
+
+dnl ** determine whether or not const works
+AC_C_CONST
+
+dnl ** are we big endian?
+AC_C_BIGENDIAN
+
+dnl ** check for leading underscores in symbol names
+FPTOOLS_UNDERSCORE
+
+dnl ** check for ld, and whether ld has -x option
+AC_PATH_PROG(LdCmdRaw, ld)
+LdCmd=${LdCmdRaw}
+AC_SUBST(LdCmd)
+FPTOOLS_LD_X
+
+dnl ** check for more functions
+AC_CHECK_FUNCS(strcasecmp _stricmp stricmp strcmpi)
+AC_CHECK_FUNCS(strcmp)
+AC_CHECK_FUNCS(vsnprintf _vsnprintf)
+AC_CHECK_FUNCS(snprintf _snprintf )
+
+fi
+
AC_OUTPUT(mk/config.mk, echo timestamp > mk/stamp-h )
diff -urN ghc-6.2.orig/ghc/compiler/Makefile ghc-6.2/ghc/compiler/Makefile
--- ghc-6.2.orig/ghc/compiler/Makefile 2003-09-08 13:52:24.000000000 +0200
+++ ghc-6.2/ghc/compiler/Makefile 2004-03-05 15:36:44.000000000 +0100
@@ -274,12 +274,14 @@
ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
# Yes, include the interepreter, readline, and Template Haskell extensions
SRC_HC_OPTS += -DGHCI -package haskell-src
+ifneq "$(STANDALONE)" ""
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
SRC_HC_OPTS += -package unix
ifeq "$(GhcLibsWithReadline)" "YES"
SRC_HC_OPTS += -package readline
endif
endif
+endif
ALL_DIRS += ghci
else
# No interpreter, so exclude Template Haskell modules
diff -urN ghc-6.2.orig/ghc/compiler/prelude/primops.txt.pp ghc-6.2/ghc/compiler/prelude/primops.txt.pp
--- ghc-6.2.orig/ghc/compiler/prelude/primops.txt.pp 2003-11-10 13:07:25.000000000 +0100
+++ ghc-6.2/ghc/compiler/prelude/primops.txt.pp 2004-05-21 17:21:58.000000000 +0200
@@ -1685,6 +1685,36 @@
------------------------------------------------------------------------
+------------------------------------------------------------------------
+section "hOp"
+------------------------------------------------------------------------
+#ifdef STANDALONE
+
+primop InbOp "inb#" GenPrimOp
+ Word# -> State# RealWorld -> (# State# RealWorld, Word# #)
+ with
+ has_side_effects = True
+ out_of_line = True
+
+primop OutbOp "outb#" GenPrimOp
+ Word# -> Word# -> State# RealWorld -> State# RealWorld
+ with
+ has_side_effects = True
+ out_of_line = True
+
+primop RegisterForIRQ "registerForIRQ#" GenPrimOp
+ Word# -> State# RealWorld -> State# RealWorld
+ with
+ has_side_effects = True
+ out_of_line = True
+
+primop WaitNextInterrupt "waitNextInterrupt#" GenPrimOp
+ Word# -> State# RealWorld -> State# RealWorld
+ with
+ has_side_effects = True
+ out_of_line = True
+
+#endif
------------------------------------------------------------------------
--- ---
diff -urN ghc-6.2.orig/ghc/includes/PrimOps.h ghc-6.2/ghc/includes/PrimOps.h
--- ghc-6.2.orig/ghc/includes/PrimOps.h 2003-11-10 13:07:34.000000000 +0100
+++ ghc-6.2/ghc/includes/PrimOps.h 2004-05-21 17:23:49.000000000 +0200
@@ -315,6 +315,19 @@
#endif
/* -----------------------------------------------------------------------------
+ hOp
+ -------------------------------------------------------------------------- */
+
+#ifdef STANDALONE
+
+EXTFUN_RTS(inbzh_fast);
+EXTFUN_RTS(outbzh_fast);
+EXTFUN_RTS(registerForIRQzh_fast);
+EXTFUN_RTS(waitNextInterruptzh_fast);
+
+#endif
+
+/* -----------------------------------------------------------------------------
BCOs and BCO linkery
-------------------------------------------------------------------------- */
diff -urN ghc-6.2.orig/ghc/includes/TSO.h ghc-6.2/ghc/includes/TSO.h
--- ghc-6.2.orig/ghc/includes/TSO.h 2003-11-10 13:01:51.000000000 +0100
+++ ghc-6.2/ghc/includes/TSO.h 2004-05-21 18:45:15.000000000 +0200
@@ -139,6 +139,9 @@
BlockedOnRead,
BlockedOnWrite,
BlockedOnDelay
+#ifdef STANDALONE
+ , BlockedWaitingInterrupts
+#endif
#if defined(mingw32_TARGET_OS)
, BlockedOnDoProc
#endif
@@ -194,7 +197,9 @@
StgTSOBlockInfo block_info;
struct StgTSO_* blocked_exceptions;
StgThreadID id;
+#ifndef STANDALONE
int saved_errno;
+#endif
StgTSOTickyInfo ticky;
StgTSOProfInfo prof;
diff -urN ghc-6.2.orig/ghc/rts/Interpreter.c ghc-6.2/ghc/rts/Interpreter.c
--- ghc-6.2.orig/ghc/rts/Interpreter.c 2003-12-16 17:58:25.000000000 +0100
+++ ghc-6.2/ghc/rts/Interpreter.c 2004-03-06 12:37:10.000000000 +0100
@@ -1177,8 +1177,10 @@
memcpy(arguments, Sp, sizeof(W_) * stk_offset);
#endif
+#ifndef STANDALONE
// Restore the Haskell thread's current value of errno
errno = cap->r.rCurrentTSO->saved_errno;
+#endif
// There are a bunch of non-ptr words on the stack (the
// ccall args, the ccall fun address and space for the
@@ -1216,8 +1218,10 @@
LOAD_STACK_POINTERS;
Sp += ret_dyn_size;
+#ifndef STANDALONE
// Save the Haskell thread's current value of errno
cap->r.rCurrentTSO->saved_errno = errno;
+#endif
#ifdef RTS_SUPPORTS_THREADS
// Threaded RTS:
diff -urN ghc-6.2.orig/ghc/rts/Itimer.c ghc-6.2/ghc/rts/Itimer.c
--- ghc-6.2.orig/ghc/rts/Itimer.c 2003-12-16 17:58:25.000000000 +0100
+++ ghc-6.2/ghc/rts/Itimer.c 2004-02-27 15:33:05.000000000 +0100
@@ -7,6 +7,8 @@
*
* ---------------------------------------------------------------------------*/
+#ifndef STANDALONE
+
/*
* The interval timer is used for profiling and for context switching in the
* threaded build. Though POSIX 1003.1b includes a standard interface for
@@ -172,3 +174,5 @@
tv.tv_usec * TICK_FREQUENCY / 1000000);
}
+#endif /* ! STANDALONE */
+
diff -urN ghc-6.2.orig/ghc/rts/LdvProfile.c ghc-6.2/ghc/rts/LdvProfile.c
--- ghc-6.2.orig/ghc/rts/LdvProfile.c 2003-12-16 17:58:25.000000000 +0100
+++ ghc-6.2/ghc/rts/LdvProfile.c 2004-03-06 12:28:40.000000000 +0100
@@ -8,7 +8,7 @@
*
* ---------------------------------------------------------------------------*/
-#ifdef PROFILING
+#if !defined(STANDALONE) && defined(PROFILING)
#include "Stg.h"
#include "Rts.h"
@@ -405,4 +405,4 @@
LdvCensusForDead(RtsFlags.GcFlags.generations - 1);
}
-#endif /* PROFILING */
+#endif /* !STANDALONE && PROFILING */
diff -urN ghc-6.2.orig/ghc/rts/Linker.c ghc-6.2/ghc/rts/Linker.c
--- ghc-6.2.orig/ghc/rts/Linker.c 2003-12-16 17:58:26.000000000 +0100
+++ ghc-6.2/ghc/rts/Linker.c 2004-05-21 18:46:12.000000000 +0200
@@ -6,6 +6,7 @@
* RTS Object Linker
*
* ---------------------------------------------------------------------------*/
+#ifndef STANDALONE
#if 0
#include "PosixSource.h"
@@ -3579,3 +3580,5 @@
}
#endif
+
+#endif /* !STANDALONE */
diff -urN ghc-6.2.orig/ghc/rts/MBlock.c ghc-6.2/ghc/rts/MBlock.c
--- ghc-6.2.orig/ghc/rts/MBlock.c 2003-12-16 17:58:26.000000000 +0100
+++ ghc-6.2/ghc/rts/MBlock.c 2004-02-27 15:33:05.000000000 +0100
@@ -61,6 +61,38 @@
Allocate new mblock(s)
-------------------------------------------------------------------------- */
+#ifdef STANDALONE
+
+static void* next_mblock;
+static void* end_of_memory;
+
+void MBlock_init(void * heap, void * limit) {
+ memset(mblock_map, 0, MBLOCK_MAP_SIZE);
+ next_mblock = (void*)(((StgWord32)heap + MBLOCK_SIZE - 1) & ~(MBLOCK_SIZE - 1));
+ end_of_memory = limit;
+}
+
+void *
+getMBlocks(unsigned n) {
+ void * p = next_mblock;
+ unsigned i = 0;
+ next_mblock += MBLOCK_SIZE * n;
+ if (next_mblock > end_of_memory)
+ perror("Haskell heap exhausted\n");
+ mblocks_allocated += n;
+ for (i = 0; i < n; i++) {
+ MARK_HEAP_ALLOCED( p + i * MBLOCK_SIZE );
+ }
+ return p;
+}
+
+void *
+getMBlock(void) {
+ return getMBlocks(1);
+}
+
+#else /* !STANDALONE */
+
void *
getMBlock(void)
{
@@ -364,3 +396,5 @@
#endif
#endif
+
+#endif /* !STANDALONE */
diff -urN ghc-6.2.orig/ghc/rts/OSThreads.h ghc-6.2/ghc/rts/OSThreads.h
--- ghc-6.2.orig/ghc/rts/OSThreads.h 2003-12-16 17:58:27.000000000 +0100
+++ ghc-6.2/ghc/rts/OSThreads.h 2004-03-12 12:23:28.000000000 +0100
@@ -72,6 +72,11 @@
extern void yieldThread ( void );
extern int createOSThread ( OSThreadId* tid,
void (*startProc)(void) );
+#elif STANDALONE
+
+#define ACQUIRE_LOCK(l) __asm__("cli")
+#define RELEASE_LOCK(l) __asm__("sti")
+
#else
#define ACQUIRE_LOCK(l)
diff -urN ghc-6.2.orig/ghc/rts/PrimOps.hc ghc-6.2/ghc/rts/PrimOps.hc
--- ghc-6.2.orig/ghc/rts/PrimOps.hc 2003-12-16 17:58:27.000000000 +0100
+++ ghc-6.2/ghc/rts/PrimOps.hc 2004-05-21 17:26:55.000000000 +0200
@@ -1747,3 +1747,75 @@
}
#endif
+/* -----------------------------------------------------------------------------
+ hOp
+ -------------------------------------------------------------------------- */
+
+#ifdef STANDALONE
+
+#define inb(dx) ({StgWord8 r; __asm__ __volatile__("inb %%dx, %%al":"=a"(r):"d"(dx)); r;})
+
+#define outb(dx,al) {StgWord8 r; __asm__ __volatile__("outb %%al, %%dx;jmp 1f;1:"::"a"(al),"d"(dx));} while (0)
+
+FN_(inbzh_fast)
+{
+ /* args: R1 = IO port to read */
+ W_ port, data;
+ FB_
+ port = R1.w;
+ data = inb(port);
+ /* returns (# s#, Word# #) */
+ TICK_RET_UNBOXED_TUP(1);
+ RET_P(data);
+ FE_
+}
+
+FN_(outbzh_fast)
+{
+ /* args: R1 = IO port to write, R2 = data */
+ W_ port, data;
+ FB_
+ port = R1.w;
+ data = R2.w;
+ outb(port, data);
+ JMP_(ENTRY_CODE(Sp[0]));
+ FE_
+}
+
+FN_(registerForIRQzh_fast)
+{
+ StgStablePtr sp;
+
+ /* args: R1 = irq number */
+ FB_
+ sp = RET_STGCALL1(StgStablePtr,getStablePtr,CurrentTSO);
+ irqHandlerThreads[R1.w] = sp;
+ ASSERT(CurrentTSO->why_blocked == NotBlocked);
+ CurrentTSO->why_blocked = BlockedWaitingInterrupts;
+ /* Enable IRQ */
+ if (R1.w < 8) {
+ outb(0x21, inb(0x21) & ~(R1.w + 1));
+ } else {
+ outb(0xA1, inb(0xA1) & ~(R1.w - 7));
+ }
+ JMP_(stg_block_noregs);
+ FE_
+}
+
+FN_(waitNextInterruptzh_fast)
+{
+ /* args: R1 = irq number */
+ FB_
+ ASSERT(CurrentTSO->why_blocked == NotBlocked);
+ CurrentTSO->why_blocked = BlockedWaitingInterrupts;
+ /* EOI */
+ if (R1.w < 8) {
+ outb(0x20, 0x60 | R1.w);
+ } else {
+ outb(0xA0, 0x60 | (R1.w - 8));
+ }
+ JMP_(stg_block_noregs);
+ FE_
+}
+
+#endif /* STANDALONE */
\ No newline at end of file
diff -urN ghc-6.2.orig/ghc/rts/ProfHeap.c ghc-6.2/ghc/rts/ProfHeap.c
--- ghc-6.2.orig/ghc/rts/ProfHeap.c 2003-12-16 17:58:28.000000000 +0100
+++ ghc-6.2/ghc/rts/ProfHeap.c 2004-03-06 12:46:35.000000000 +0100
@@ -7,13 +7,13 @@
*
* ---------------------------------------------------------------------------*/
-#if defined(DEBUG) && !defined(PROFILING)
+#if defined(DEBUG) && !defined(PROFILING) && !defined(STANDALONE)
#define DEBUG_HEAP_PROF
#else
#undef DEBUG_HEAP_PROF
#endif
-#if defined(PROFILING) || defined(DEBUG_HEAP_PROF)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG_HEAP_PROF))
#include "PosixSource.h"
#include "Rts.h"
@@ -1089,5 +1089,5 @@
#endif
}
-#endif /* PROFILING || DEBUG_HEAP_PROF */
+#endif /* !STANDALONE && (PROFILING || DEBUG_HEAP_PROF) */
diff -urN ghc-6.2.orig/ghc/rts/Profiling.c ghc-6.2/ghc/rts/Profiling.c
--- ghc-6.2.orig/ghc/rts/Profiling.c 2003-12-16 17:58:28.000000000 +0100
+++ ghc-6.2/ghc/rts/Profiling.c 2004-03-06 12:24:58.000000000 +0100
@@ -7,7 +7,7 @@
*
* ---------------------------------------------------------------------------*/
-#ifdef PROFILING
+#if !defined(STANDALONE) && defined(PROFILING)
#include "PosixSource.h"
#include "Rts.h"
@@ -918,4 +918,4 @@
fprintf(f,">");
}
-#endif /* PROFILING */
+#endif /* !STANDALONE && PROFILING */
diff -urN ghc-6.2.orig/ghc/rts/Profiling.h ghc-6.2/ghc/rts/Profiling.h
--- ghc-6.2.orig/ghc/rts/Profiling.h 2003-12-16 17:58:28.000000000 +0100
+++ ghc-6.2/ghc/rts/Profiling.h 2004-03-06 12:35:35.000000000 +0100
@@ -7,7 +7,7 @@
*
* ---------------------------------------------------------------------------*/
-#if defined(PROFILING) || defined(DEBUG)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG))
void initProfiling1 ( void );
void initProfiling2 ( void );
void endProfiling ( void );
diff -urN ghc-6.2.orig/ghc/rts/Proftimer.c ghc-6.2/ghc/rts/Proftimer.c
--- ghc-6.2.orig/ghc/rts/Proftimer.c 2003-12-16 17:58:28.000000000 +0100
+++ ghc-6.2/ghc/rts/Proftimer.c 2004-03-06 12:26:37.000000000 +0100
@@ -7,7 +7,7 @@
*
* ---------------------------------------------------------------------------*/
-#if defined (PROFILING)
+#if defined(PROFILING) && !defined(STANDALONE)
#include "PosixSource.h"
@@ -85,4 +85,4 @@
}
}
-#endif /* PROFILING */
+#endif /* !STANDALONE && PROFILING */
diff -urN ghc-6.2.orig/ghc/rts/RetainerProfile.c ghc-6.2/ghc/rts/RetainerProfile.c
--- ghc-6.2.orig/ghc/rts/RetainerProfile.c 2003-12-16 17:58:29.000000000 +0100
+++ ghc-6.2/ghc/rts/RetainerProfile.c 2004-03-06 12:25:54.000000000 +0100
@@ -8,7 +8,7 @@
*
* ---------------------------------------------------------------------------*/
-#ifdef PROFILING
+#if defined(PROFILING) && !defined(STANDALONE)
// Turn off inlining when debugging - it obfuscates things
#ifdef DEBUG
@@ -2382,4 +2382,4 @@
}
#endif // DEBUG_RETAINER
-#endif /* PROFILING */
+#endif /* !STANDALNONE && PROFILING */
diff -urN ghc-6.2.orig/ghc/rts/RetainerSet.c ghc-6.2/ghc/rts/RetainerSet.c
--- ghc-6.2.orig/ghc/rts/RetainerSet.c 2003-12-16 17:58:29.000000000 +0100
+++ ghc-6.2/ghc/rts/RetainerSet.c 2004-03-06 12:27:08.000000000 +0100
@@ -8,7 +8,7 @@
*
* ---------------------------------------------------------------------------*/
-#ifdef PROFILING
+#if !defined(STANDALONE) && defined(PROFILING)
#include <stdlib.h>
@@ -497,4 +497,4 @@
}
#endif // SECOND_APPROACH
-#endif /* PROFILING */
+#endif /* !STANDALONE && PROFILING */
diff -urN ghc-6.2.orig/ghc/rts/RtsFlags.c ghc-6.2/ghc/rts/RtsFlags.c
--- ghc-6.2.orig/ghc/rts/RtsFlags.c 2003-12-16 17:58:30.000000000 +0100
+++ ghc-6.2/ghc/rts/RtsFlags.c 2004-05-21 18:47:12.000000000 +0200
@@ -7,7 +7,6 @@
* Functions for parsing the argument list.
*
* ---------------------------------------------------------------------------*/
-
//@menu
//* Includes::
//* Constants::
@@ -107,6 +106,8 @@
#endif /* PAR */
+#if !defined(STANDALONE) || defined(DEBUG)
+
//@node Static function decls, Command-line option parsing routines, Constants
//@subsection Static function decls
@@ -135,6 +136,8 @@
static void help_par_debug_options(nat n);
#endif
+#endif /* !STANDALONE || DEBUG /*
+
//@node Command-line option parsing routines, GranSim specific options, Static function decls
//@subsection Command-line option parsing routines
@@ -317,6 +320,19 @@
#endif
}
+#ifdef DEBUG
+
+# ifdef STANDALONE
+
+/* These functions are available in support libraries. */
+
+extern int iswblank(wint_t wc);
+extern double atof_hop(const char *nptr);
+# define isspace(X) iswblank(X)
+# define atof atof_hop
+
+# endif
+
static const char *
usage_text[] = {
"",
@@ -574,6 +590,7 @@
// Process RTS (rts_argv) part: mainly to determine statsfile
for (arg = 0; arg < *rts_argc; arg++) {
+ fprintf(stderr, "\nrts_arg: %s\n", rts_argv[arg]);
if (rts_argv[arg][0] != '-') {
fflush(stdout);
prog_belch("unexpected RTS argument: %s", rts_argv[arg]);
@@ -2157,3 +2174,5 @@
prog_belch("bad RTS option: %s", s);
stg_exit(EXIT_FAILURE);
}
+
+#endif /* !STANDALONE || DEBUG */
diff -urN ghc-6.2.orig/ghc/rts/RtsStartup.c ghc-6.2/ghc/rts/RtsStartup.c
--- ghc-6.2.orig/ghc/rts/RtsStartup.c 2003-12-16 17:58:31.000000000 +0100
+++ ghc-6.2/ghc/rts/RtsStartup.c 2004-03-06 13:13:17.000000000 +0100
@@ -31,7 +31,7 @@
#include "FrontPanel.h"
#endif
-#if defined(PROFILING) || defined(DEBUG)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG))
# include "Profiling.h"
# include "ProfHeap.h"
# include "RetainerProfile.h"
@@ -120,12 +120,14 @@
/* Call the user hook to reset defaults, if present */
defaultsHook();
+#if !defined(STANDALONE) || defined(DEBUG)
/* Parse the flags, separating the RTS flags from the programs args */
if (argc != NULL && argv != NULL) {
setupRtsFlags(argc, *argv, &rts_argc, rts_argv);
prog_argc = *argc;
prog_argv = *argv;
}
+#endif
#if defined(PAR)
/* NB: this really must be done after processing the RTS flags */
@@ -158,7 +160,7 @@
/* initialise thread label table (tso->char*) */
initThreadLabelTable();
-#if defined(PROFILING) || defined(DEBUG)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG))
initProfiling1();
#endif
@@ -185,9 +187,11 @@
}
#endif
+#ifndef STANDALONE
#ifdef HAVE_LOCALE_H
setlocale(LC_ALL,"");
#endif
+#endif
/* Record initialization times */
stat_endInit();
@@ -285,7 +289,7 @@
freeGroup(bd);
-#if defined(PROFILING) || defined(DEBUG)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG))
// This must be done after module initialisation.
// ToDo: make this work in the presence of multiple hs_add_root()s.
initProfiling2();
@@ -328,6 +332,7 @@
/* stop the ticker */
stopTimer();
+#ifndef STANDALONE
/* reset the standard file descriptors to blocking mode */
resetNonBlockingFd(0);
resetNonBlockingFd(1);
@@ -352,6 +357,7 @@
sigprocmask(SIG_SETMASK, &old_sigset, NULL);
}
#endif
+#endif /* !STANDALONE */
#if defined(PAR)
/* controlled exit; good thread! */
@@ -379,7 +385,7 @@
reportCCSProfiling();
#endif
-#if defined(PROFILING) || defined(DEBUG)
+#if !defined(STANDALONE) && (defined(PROFILING) || defined(DEBUG))
endProfiling();
#endif
diff -urN ghc-6.2.orig/ghc/rts/RtsUtils.c ghc-6.2/ghc/rts/RtsUtils.c
--- ghc-6.2.orig/ghc/rts/RtsUtils.c 2003-12-16 17:58:31.000000000 +0100
+++ ghc-6.2/ghc/rts/RtsUtils.c 2004-03-06 12:13:13.000000000 +0100
@@ -39,6 +39,7 @@
void
barf(char *s, ...)
{
+#ifndef STANDALONE
va_list ap;
va_start(ap,s);
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
@@ -53,11 +54,16 @@
fflush(stderr);
stg_exit(EXIT_INTERNAL_ERROR);
va_end(ap);
+#else
+ (void) kprintf(s, (int *)(&s + 1));
+ abort();
+#endif
}
void
prog_belch(char *s, ...)
{
+#ifndef STANDALONE
va_list ap;
va_start(ap,s);
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
@@ -67,17 +73,24 @@
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
+#else
+ kprintf(s, (int *)(&s + 1));
+#endif
}
void
belch(char *s, ...)
{
+#ifndef STANDALONE
va_list ap;
va_start(ap,s);
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
va_end(ap);
+#else
+ kprintf(s, (int *)(&s + 1));
+#endif
}
/* result-checking malloc wrappers. */
@@ -130,10 +143,15 @@
void
_stgAssert (char *filename, unsigned int linenum)
{
+#ifndef STANDALONE
fflush(stdout);
fprintf(stderr, "ASSERTION FAILED: file %s, line %u\n", filename, linenum);
fflush(stderr);
abort();
+#else
+ kprintf("ASSERTION FAILED: file %s, line %u\n", filename, linenum);
+ abort();
+#endif
}
/* -----------------------------------------------------------------------------
@@ -205,8 +223,8 @@
/* -----------------------------------------------------------------------------
Get the current time as a string. Used in profiling reports.
-------------------------------------------------------------------------- */
-
-#if defined(PROFILING) || defined(DEBUG) || defined(PAR) || defined(GRAN)
+#if (defined(PROFILING) || defined(DEBUG) || defined(PAR) || defined(GRAN)) \
+ && !defined(STANDALONE)
char *
time_str(void)
{
@@ -229,7 +247,7 @@
* clean up for us.
* -------------------------------------------------------------------------- */
-#if !defined(mingw32_TARGET_OS)
+#if !defined(mingw32_TARGET_OS) && !defined(STANDALONE)
void
resetNonBlockingFd(int fd)
{
@@ -298,6 +316,7 @@
}
#endif /* PAR */
+#ifndef STANDALONE
/* -----------------------------------------------------------------------------
Print large numbers, with punctuation.
-------------------------------------------------------------------------- */
@@ -324,7 +343,7 @@
(lnat)((x)%(ullong)1000));
return s;
}
-
+#endif
// Can be used as a breakpoint to set on every heap check failure.
#ifdef DEBUG
diff -urN ghc-6.2.orig/ghc/rts/RtsUtils.h ghc-6.2/ghc/rts/RtsUtils.h
--- ghc-6.2.orig/ghc/rts/RtsUtils.h 2003-12-16 17:58:31.000000000 +0100
+++ ghc-6.2/ghc/rts/RtsUtils.h 2004-03-06 11:51:05.000000000 +0100
@@ -39,3 +39,7 @@
#ifdef DEBUG
extern void heapCheckFail( void );
#endif
+
+#ifdef STANDALONE
+extern void kprintf(const char *fmt, ...);
+#endif
diff -urN ghc-6.2.orig/ghc/rts/Schedule.c ghc-6.2/ghc/rts/Schedule.c
--- ghc-6.2.orig/ghc/rts/Schedule.c 2003-12-16 18:07:50.000000000 +0100
+++ ghc-6.2/ghc/rts/Schedule.c 2004-05-21 18:48:11.000000000 +0200
@@ -707,6 +707,19 @@
if ( !EMPTY_RUN_QUEUE() ) { goto not_deadlocked; }
+#ifdef STANDALONE
+ /* Standalone means that we have interrupt handlers.
+ * We should then just wait for the next interrupt to arrive.
+ */
+ IF_DEBUG(scheduler,
+ sched_belch("still deadlocked, waiting next interrupt..."));
+ while ( !EMPTY_RUN_QUEUE() ) {
+ __asm__("hlt");
+ /* FIXME: Does that make sense ? */
+ goto not_deadlocked;
+ }
+#endif
+
IF_DEBUG(scheduler,
sched_belch("still deadlocked, checking for black holes..."));
detectBlackHoles();
@@ -1205,9 +1218,13 @@
ret = ThreadFinished;
break;
case ThreadRunGHC:
+#ifndef STANDALONE
errno = t->saved_errno;
+#endif
ret = StgRun((StgFunPtr) stg_returnToStackTop, &cap->r);
+#ifndef STANDALONE
t->saved_errno = errno;
+#endif
break;
case ThreadInterpret:
ret = interpretBCO(cap);
@@ -1639,7 +1656,7 @@
StgInt
forkProcess(HsStablePtr *entry)
{
-#ifndef mingw32_TARGET_OS
+#if !defined(mingw32_TARGET_OS) && !defined(STANDALONE)
pid_t pid;
StgTSO* t,*next;
StgMainThread *m;
@@ -1753,7 +1770,9 @@
{
nat tok;
Capability *cap;
+#ifndef STANDALONE
int saved_errno = errno;
+#endif
/* assume that *reg is a pointer to the StgRegTable part
* of a Capability.
@@ -1801,7 +1820,9 @@
THREAD_RUNNABLE();
RELEASE_LOCK(&sched_mutex);
+#ifndef STANDALONE
errno = saved_errno;
+#endif
return tok;
}
@@ -1811,7 +1832,9 @@
{
StgTSO *tso, **prev;
Capability *cap;
+#ifndef STANDALONE
int saved_errno = errno;
+#endif
#if defined(RTS_SUPPORTS_THREADS)
/* Wait for permission to re-enter the RTS with the result. */
@@ -1853,7 +1876,9 @@
#if defined(RTS_SUPPORTS_THREADS)
RELEASE_LOCK(&sched_mutex);
#endif
+#ifndef STANDALONE
errno = saved_errno;
+#endif
return &cap->r;
}
@@ -1982,7 +2007,9 @@
tso->why_blocked = NotBlocked;
tso->blocked_exceptions = NULL;
+#ifndef STANDALONE
tso->saved_errno = 0;
+#endif
tso->stack_size = stack_size;
tso->max_stack_size = round_to_mblocks(RtsFlags.GcFlags.maxStkSize)
@@ -2949,7 +2976,10 @@
}
#else /* !GRAN && !PAR */
-static StgTSO *
+#ifndef STANDALONE
+static
+#endif
+StgTSO *
unblockOneLocked(StgTSO *tso)
{
StgTSO *next;
@@ -3233,6 +3262,9 @@
case BlockedOnRead:
case BlockedOnWrite:
+#ifdef STANDALONE
+ case BlockedWaitingInterrupts:
+#endif
#if defined(mingw32_TARGET_OS)
case BlockedOnDoProc:
#endif
@@ -3363,6 +3394,9 @@
case BlockedOnRead:
case BlockedOnWrite:
+#ifdef STANDALONE
+ case BlockedWaitingInterrupts:
+#endif
#if defined(mingw32_TARGET_OS)
case BlockedOnDoProc:
#endif
@@ -3775,8 +3809,13 @@