Wed Aug 11 10:54:01 BST 2010  rmcilroy@microsoft.com
  * Checkpoint GHC on Barrelfish work
  
  Now at the stage where we can build and run a helloworld Haskell application on Barrelfish.
  
Mon Aug  9 13:42:43 BST 2010  rmcilroy@microsoft.com
  * missing files from previous checkpoint of barrelfish port
Mon Aug  9 10:49:02 BST 2010  rmcilroy@microsoft.com
  * Checkpoint Barrelfish compatability changes
Thu Jul 29 14:53:26 BST 2010  rmcilroy@microsoft.com
  * Changes to get ghc building against Barrelfish
diff -rN -u old-ghc_bf/aclocal.m4 new-ghc_bf-2/aclocal.m4
--- old-ghc_bf/aclocal.m4	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/aclocal.m4	2010-08-11 16:01:46.000000000 +0100
@@ -1045,7 +1045,7 @@
 AC_DEFUN([FP_CHECK_TIMER_CREATE],
   [AC_CACHE_CHECK([for a working timer_create(CLOCK_REALTIME)], 
     [fptools_cv_timer_create_works],
-    [AC_TRY_RUN([
+    [AC_RUN_IFELSE([
 #include <stdio.h>
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -1160,6 +1160,7 @@
 }
      ],
      [fptools_cv_timer_create_works=yes],
+     [fptools_cv_timer_create_works=no],
      [fptools_cv_timer_create_works=no])
   ])
 case $fptools_cv_timer_create_works in
@@ -1344,7 +1345,7 @@
     $2="linux"
     ;;
   # As far as I'm aware, none of these have relevant variants
-  freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
+  freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku|barrelfish)
     $2="$1"
     ;;
   *)
diff -rN -u old-ghc_bf/compiler/main/DriverPipeline.hs new-ghc_bf-2/compiler/main/DriverPipeline.hs
--- old-ghc_bf/compiler/main/DriverPipeline.hs	2010-08-11 16:01:45.000000000 +0100
+++ new-ghc_bf-2/compiler/main/DriverPipeline.hs	2010-08-11 16:01:46.000000000 +0100
@@ -1551,7 +1551,7 @@
 
     let
         thread_opts | WayThreaded `elem` ways = [
-#if !defined(mingw32_TARGET_OS) && !defined(freebsd_TARGET_OS) && !defined(haiku_TARGET_OS)
+#if !defined(mingw32_TARGET_OS) && !defined(freebsd_TARGET_OS) && !defined(haiku_TARGET_OS) && !defined(barrelfish_TARGET_OS)
                         "-lpthread"
 #endif
 #if defined(osf3_TARGET_OS)
diff -rN -u old-ghc_bf/config.sub new-ghc_bf-2/config.sub
--- old-ghc_bf/config.sub	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/config.sub	2010-08-11 16:01:46.000000000 +0100
@@ -4,7 +4,7 @@
 #   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 #   Free Software Foundation, Inc.
 
-timestamp='2008-09-08'
+timestamp='2010-07-22'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -1407,6 +1407,9 @@
 	-dicos*)
 		os=-dicos
 		;;
+	-barrelfish*)
+		os=-barrelfish
+		;;
 	-none)
 		;;
 	*)
diff -rN -u old-ghc_bf/configure.ac new-ghc_bf-2/configure.ac
--- old-ghc_bf/configure.ac	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/configure.ac	2010-08-11 16:01:46.000000000 +0100
@@ -351,7 +351,7 @@
 
 checkOS() {
     case $1 in
-    linux|freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku)
+    linux|freebsd|netbsd|openbsd|dragonfly|osf1|osf3|hpux|linuxaout|kfreebsdgnu|freebsd2|solaris2|cygwin32|mingw32|darwin|gnu|nextstep2|nextstep3|sunos4|ultrix|irix|aix|haiku|barrelfish)
         ;;
     *)
         echo "Unknown OS '$1'"
@@ -746,7 +746,7 @@
 dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
 AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity setlocale])
 
-AC_TRY_RUN([
+AC_RUN_IFELSE([
 #include <sys/types.h>
 #include <sys/time.h>
 int main(void) {
@@ -756,7 +756,7 @@
   tval.it_interval = tval.it_value;
   return setitimer(ITIMER_VIRTUAL, &tval, (void*)0) != 0;
 }
-],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [1], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])])
+],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [1], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [0], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])],[AC_DEFINE([HAVE_SETITIMER_VIRTUAL], [0], [Define to 1 if setitimer accepts ITIMER_VIRTUAL, 0 else.])])
 
 dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
 dnl ** _POSIX_C_SOURCE is defined
diff -rN -u old-ghc_bf/configure.bf new-ghc_bf-2/configure.bf
--- old-ghc_bf/configure.bf	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/configure.bf	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,3 @@
+#! /bin/bash
+
+./configure --build=x86_64-unknown-linux --host=x86_64-unknown-barrelfish --target=x86_64-unknown-barrelfish --x-includes=/home/rmcilroy/barrelfish.ghc/include/ --x-libraries=/home/rmcilroy/barrelfish.ghc/build/x86_64/lib/ CFLAGS="-fno-builtin -nostdinc -m64 -mno-red-zone -fPIE -fno-stack-protector -U__linux__ -imacros ${BF_ROOT}/include/deputy/nodeputy.h -DBARRELFISH -DMAX_CPUS=64 -DCONFIG_INTERCONNECT_DRIVER_LMP -DCONFIG_INTERCONNECT_DRIVER_UMP -DCONFIG_FLOUNDER_BACKEND_LMP -DCONFIG_FLOUNDER_BACKEND_UMP -g  -I${BF_ROOT}/include -I${BF_ROOT}/include/arch/x86_64 -I${BF_BUILD_DIR}/include " CPPFLAGS="-fno-builtin -nostdinc -m64 -mno-red-zone -fPIE -fno-stack-protector -U__linux__ -imacros ${BF_ROOT}/include/deputy/nodeputy.h -DBARRELFISH -DMAX_CPUS=64 -DCONFIG_INTERCONNECT_DRIVER_LMP -DCONFIG_INTERCONNECT_DRIVER_UMP -DCONFIG_FLOUNDER_BACKEND_LMP -DCONFIG_FLOUNDER_BACKEND_UMP -g  -I${BF_ROOT}/include -I${BF_ROOT}/include/arch/x86_64 -I${BF_BUILD_DIR}/include " LDFLAGS="${BF_BUILD_DIR}/lib/crt0.o  ${BF_BUILD_DIR}/errors/errno.o -Wl,-section-start,.data.rel.ro=0x800000 -Wl,-z,max-page-size=0x1000 -fno-builtin -nostdlib -m64 -L${BF_BUILD_DIR}/lib/ -Wl,--start-group -lmsun -lposixcompat -lvfs -lnfs -llwip -ltimer -lbarrelfish -lc" 
diff -rN -u old-ghc_bf/ghc/ghc.mk new-ghc_bf-2/ghc/ghc.mk
--- old-ghc_bf/ghc/ghc.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/ghc/ghc.mk	2010-08-11 16:01:46.000000000 +0100
@@ -70,8 +70,10 @@
 ghc_stage1_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage1_VERSION)
 ghc_stage2_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage2_VERSION)
 ghc_stage3_HC_OPTS += -package $(compiler_PACKAGE)-$(compiler_stage3_VERSION)
+ifneq "$(HostOS_CPP)" "barrelfish"
 ghc_stage2_HC_OPTS += -package haskeline
 ghc_stage3_HC_OPTS += -package haskeline
+endif
 
 ghc_language_extension_flags = -XCPP \
                                -XPatternGuards \
diff -rN -u old-ghc_bf/ghc/ghc.wrapper new-ghc_bf-2/ghc/ghc.wrapper
--- old-ghc_bf/ghc/ghc.wrapper	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/ghc/ghc.wrapper	2010-08-11 16:01:46.000000000 +0100
@@ -1 +1 @@
-exec "$executablename" -B"$topdir" -pgmc "$pgmgcc" ${1+"$@"}
+exec "$executablename" -B"$topdir" -pgmc "$pgmgcc" $builtInArgs ${1+"$@"}
diff -rN -u old-ghc_bf/ghc.mk new-ghc_bf-2/ghc.mk
--- old-ghc_bf/ghc.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/ghc.mk	2010-08-11 16:01:46.000000000 +0100
@@ -338,9 +338,11 @@
 $(eval $(call addPackage,utf8-string))
 $(eval $(call addPackage,xhtml))
 
+ifneq "$(HostOS_CPP)" "barrelfish"
 $(eval $(call addPackage,terminfo,($$(Windows),NO)))
 
 $(eval $(call addPackage,haskeline))
+endif
 
 $(foreach pkg,$(EXTRA_PACKAGES),$(eval $(call addPackage,$(pkg))))
 
diff -rN -u old-ghc_bf/includes/DerivedConstants.h.bf new-ghc_bf-2/includes/DerivedConstants.h.bf
--- old-ghc_bf/includes/DerivedConstants.h.bf	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/includes/DerivedConstants.h.bf	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,454 @@
+/* This file is created automatically.  Do not edit by hand.*/
+
+#define STD_HDR_SIZE   1
+#define PROF_HDR_SIZE  2
+#define BLOCK_SIZE   4096
+#define MBLOCK_SIZE   1048576
+
+
+#define OFFSET_StgRegTable_rR1 0
+#define OFFSET_StgRegTable_rR2 8
+#define OFFSET_StgRegTable_rR3 16
+#define OFFSET_StgRegTable_rR4 24
+#define OFFSET_StgRegTable_rR5 32
+#define OFFSET_StgRegTable_rR6 40
+#define OFFSET_StgRegTable_rR7 48
+#define OFFSET_StgRegTable_rR8 56
+#define OFFSET_StgRegTable_rR9 64
+#define OFFSET_StgRegTable_rR10 72
+#define OFFSET_StgRegTable_rF1 80
+#define OFFSET_StgRegTable_rF2 84
+#define OFFSET_StgRegTable_rF3 88
+#define OFFSET_StgRegTable_rF4 92
+#define OFFSET_StgRegTable_rD1 96
+#define OFFSET_StgRegTable_rD2 104
+#define OFFSET_StgRegTable_rL1 112
+#define OFFSET_StgRegTable_rSp 120
+#define OFFSET_StgRegTable_rSpLim 128
+#define OFFSET_StgRegTable_rHp 136
+#define OFFSET_StgRegTable_rHpLim 144
+#define OFFSET_StgRegTable_rCurrentTSO 152
+#define OFFSET_StgRegTable_rCurrentNursery 168
+#define OFFSET_StgRegTable_rHpAlloc 184
+#define OFFSET_StgRegTable_rRet 192
+#define REP_StgRegTable_rRet b64
+#define StgRegTable_rRet(__ptr__)  REP_StgRegTable_rRet[__ptr__+OFFSET_StgRegTable_rRet]
+#define OFFSET_StgRegTable_rNursery 160
+#define REP_StgRegTable_rNursery b64
+#define StgRegTable_rNursery(__ptr__)  REP_StgRegTable_rNursery[__ptr__+OFFSET_StgRegTable_rNursery]
+#define OFFSET_stgEagerBlackholeInfo 18446744073709551592
+#define OFFSET_stgGCEnter1 18446744073709551600
+#define OFFSET_stgGCFun 18446744073709551608
+#define OFFSET_Capability_r 24
+#define OFFSET_Capability_lock 312
+#define OFFSET_Capability_mut_lists 272
+#define REP_Capability_mut_lists b64
+#define Capability_mut_lists(__ptr__)  REP_Capability_mut_lists[__ptr__+OFFSET_Capability_mut_lists]
+#define OFFSET_Capability_context_switch 296
+#define REP_Capability_context_switch b32
+#define Capability_context_switch(__ptr__)  REP_Capability_context_switch[__ptr__+OFFSET_Capability_context_switch]
+#define OFFSET_Capability_sparks 368
+#define REP_Capability_sparks b64
+#define Capability_sparks(__ptr__)  REP_Capability_sparks[__ptr__+OFFSET_Capability_sparks]
+#define OFFSET_bdescr_start 0
+#define REP_bdescr_start b64
+#define bdescr_start(__ptr__)  REP_bdescr_start[__ptr__+OFFSET_bdescr_start]
+#define OFFSET_bdescr_free 8
+#define REP_bdescr_free b64
+#define bdescr_free(__ptr__)  REP_bdescr_free[__ptr__+OFFSET_bdescr_free]
+#define OFFSET_bdescr_blocks 48
+#define REP_bdescr_blocks b32
+#define bdescr_blocks(__ptr__)  REP_bdescr_blocks[__ptr__+OFFSET_bdescr_blocks]
+#define OFFSET_bdescr_gen_no 52
+#define REP_bdescr_gen_no b16
+#define bdescr_gen_no(__ptr__)  REP_bdescr_gen_no[__ptr__+OFFSET_bdescr_gen_no]
+#define OFFSET_bdescr_link 16
+#define REP_bdescr_link b64
+#define bdescr_link(__ptr__)  REP_bdescr_link[__ptr__+OFFSET_bdescr_link]
+#define SIZEOF_generation 312
+#define OFFSET_generation_mut_list 48
+#define REP_generation_mut_list b64
+#define generation_mut_list(__ptr__)  REP_generation_mut_list[__ptr__+OFFSET_generation_mut_list]
+#define OFFSET_generation_n_new_large_blocks 36
+#define REP_generation_n_new_large_blocks b32
+#define generation_n_new_large_blocks(__ptr__)  REP_generation_n_new_large_blocks[__ptr__+OFFSET_generation_n_new_large_blocks]
+#define SIZEOF_CostCentreStack 88
+#define OFFSET_CostCentreStack_ccsID 0
+#define REP_CostCentreStack_ccsID b64
+#define CostCentreStack_ccsID(__ptr__)  REP_CostCentreStack_ccsID[__ptr__+OFFSET_CostCentreStack_ccsID]
+#define OFFSET_CostCentreStack_mem_alloc 56
+#define REP_CostCentreStack_mem_alloc b64
+#define CostCentreStack_mem_alloc(__ptr__)  REP_CostCentreStack_mem_alloc[__ptr__+OFFSET_CostCentreStack_mem_alloc]
+#define OFFSET_CostCentreStack_scc_count 32
+#define REP_CostCentreStack_scc_count b64
+#define CostCentreStack_scc_count(__ptr__)  REP_CostCentreStack_scc_count[__ptr__+OFFSET_CostCentreStack_scc_count]
+#define OFFSET_CostCentreStack_prevStack 16
+#define REP_CostCentreStack_prevStack b64
+#define CostCentreStack_prevStack(__ptr__)  REP_CostCentreStack_prevStack[__ptr__+OFFSET_CostCentreStack_prevStack]
+#define OFFSET_CostCentre_ccID 0
+#define REP_CostCentre_ccID b64
+#define CostCentre_ccID(__ptr__)  REP_CostCentre_ccID[__ptr__+OFFSET_CostCentre_ccID]
+#define OFFSET_CostCentre_link 48
+#define REP_CostCentre_link b64
+#define CostCentre_link(__ptr__)  REP_CostCentre_link[__ptr__+OFFSET_CostCentre_link]
+#define OFFSET_StgHeader_info 0
+#define REP_StgHeader_info b64
+#define StgHeader_info(__ptr__)  REP_StgHeader_info[__ptr__+OFFSET_StgHeader_info]
+#define OFFSET_StgHeader_ccs 8
+#define REP_StgHeader_ccs b64
+#define StgHeader_ccs(__ptr__)  REP_StgHeader_ccs[__ptr__+OFFSET_StgHeader_ccs]
+#define OFFSET_StgHeader_ldvw 16
+#define REP_StgHeader_ldvw b64
+#define StgHeader_ldvw(__ptr__)  REP_StgHeader_ldvw[__ptr__+OFFSET_StgHeader_ldvw]
+#define SIZEOF_StgSMPThunkHeader 8
+#define OFFSET_StgClosure_payload 0
+#define StgClosure_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgClosure_payload + WDS(__ix__)]
+#define OFFSET_StgEntCounter_allocs 48
+#define REP_StgEntCounter_allocs b64
+#define StgEntCounter_allocs(__ptr__)  REP_StgEntCounter_allocs[__ptr__+OFFSET_StgEntCounter_allocs]
+#define OFFSET_StgEntCounter_registeredp 0
+#define REP_StgEntCounter_registeredp b64
+#define StgEntCounter_registeredp(__ptr__)  REP_StgEntCounter_registeredp[__ptr__+OFFSET_StgEntCounter_registeredp]
+#define OFFSET_StgEntCounter_link 56
+#define REP_StgEntCounter_link b64
+#define StgEntCounter_link(__ptr__)  REP_StgEntCounter_link[__ptr__+OFFSET_StgEntCounter_link]
+#define OFFSET_StgEntCounter_entry_count 40
+#define REP_StgEntCounter_entry_count b64
+#define StgEntCounter_entry_count(__ptr__)  REP_StgEntCounter_entry_count[__ptr__+OFFSET_StgEntCounter_entry_count]
+#define SIZEOF_StgUpdateFrame_NoHdr 8
+#define SIZEOF_StgUpdateFrame (SIZEOF_StgHeader+8)
+#define SIZEOF_StgCatchFrame_NoHdr 16
+#define SIZEOF_StgCatchFrame (SIZEOF_StgHeader+16)
+#define SIZEOF_StgStopFrame_NoHdr 0
+#define SIZEOF_StgStopFrame (SIZEOF_StgHeader+0)
+#define SIZEOF_StgMutArrPtrs_NoHdr 16
+#define SIZEOF_StgMutArrPtrs (SIZEOF_StgHeader+16)
+#define OFFSET_StgMutArrPtrs_ptrs 0
+#define REP_StgMutArrPtrs_ptrs b64
+#define StgMutArrPtrs_ptrs(__ptr__)  REP_StgMutArrPtrs_ptrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutArrPtrs_ptrs]
+#define OFFSET_StgMutArrPtrs_size 8
+#define REP_StgMutArrPtrs_size b64
+#define StgMutArrPtrs_size(__ptr__)  REP_StgMutArrPtrs_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutArrPtrs_size]
+#define SIZEOF_StgArrWords_NoHdr 8
+#define SIZEOF_StgArrWords (SIZEOF_StgHeader+8)
+#define OFFSET_StgArrWords_bytes 0
+#define REP_StgArrWords_bytes b64
+#define StgArrWords_bytes(__ptr__)  REP_StgArrWords_bytes[__ptr__+SIZEOF_StgHeader+OFFSET_StgArrWords_bytes]
+#define OFFSET_StgArrWords_payload 8
+#define StgArrWords_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgArrWords_payload + WDS(__ix__)]
+#define OFFSET_StgTSO__link 0
+#define REP_StgTSO__link b64
+#define StgTSO__link(__ptr__)  REP_StgTSO__link[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO__link]
+#define OFFSET_StgTSO_global_link 8
+#define REP_StgTSO_global_link b64
+#define StgTSO_global_link(__ptr__)  REP_StgTSO_global_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_global_link]
+#define OFFSET_StgTSO_what_next 24
+#define REP_StgTSO_what_next b16
+#define StgTSO_what_next(__ptr__)  REP_StgTSO_what_next[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_what_next]
+#define OFFSET_StgTSO_why_blocked 26
+#define REP_StgTSO_why_blocked b16
+#define StgTSO_why_blocked(__ptr__)  REP_StgTSO_why_blocked[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_why_blocked]
+#define OFFSET_StgTSO_block_info 32
+#define REP_StgTSO_block_info b64
+#define StgTSO_block_info(__ptr__)  REP_StgTSO_block_info[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_block_info]
+#define OFFSET_StgTSO_blocked_exceptions 72
+#define REP_StgTSO_blocked_exceptions b64
+#define StgTSO_blocked_exceptions(__ptr__)  REP_StgTSO_blocked_exceptions[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_blocked_exceptions]
+#define OFFSET_StgTSO_id 40
+#define REP_StgTSO_id b32
+#define StgTSO_id(__ptr__)  REP_StgTSO_id[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_id]
+#define OFFSET_StgTSO_cap 56
+#define REP_StgTSO_cap b64
+#define StgTSO_cap(__ptr__)  REP_StgTSO_cap[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_cap]
+#define OFFSET_StgTSO_saved_errno 44
+#define REP_StgTSO_saved_errno b32
+#define StgTSO_saved_errno(__ptr__)  REP_StgTSO_saved_errno[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_saved_errno]
+#define OFFSET_StgTSO_trec 64
+#define REP_StgTSO_trec b64
+#define StgTSO_trec(__ptr__)  REP_StgTSO_trec[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_trec]
+#define OFFSET_StgTSO_flags 28
+#define REP_StgTSO_flags b32
+#define StgTSO_flags(__ptr__)  REP_StgTSO_flags[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_flags]
+#define OFFSET_StgTSO_dirty 16
+#define REP_StgTSO_dirty b64
+#define StgTSO_dirty(__ptr__)  REP_StgTSO_dirty[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_dirty]
+#define OFFSET_StgTSO_bq 80
+#define REP_StgTSO_bq b64
+#define StgTSO_bq(__ptr__)  REP_StgTSO_bq[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_bq]
+#define OFFSET_StgTSO_CCCS 88
+#define REP_StgTSO_CCCS b64
+#define StgTSO_CCCS(__ptr__)  REP_StgTSO_CCCS[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_CCCS]
+#define REP_StgTSO_sp b64
+#define OFFSET_StgTSO_sp 96
+#define TSO_OFFSET_StgTSO_sp (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_sp)
+#define StgTSO_sp(__ptr__)  REP_StgTSO_sp[__ptr__+TSO_OFFSET_StgTSO_sp]
+#define OFFSET_StgTSO_stack 104
+#define TSO_OFFSET_StgTSO_stack (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_stack)
+#define REP_StgTSO_stack_size b32
+#define OFFSET_StgTSO_stack_size 88
+#define TSO_OFFSET_StgTSO_stack_size (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_stack_size)
+#define StgTSO_stack_size(__ptr__)  REP_StgTSO_stack_size[__ptr__+TSO_OFFSET_StgTSO_stack_size]
+#define SIZEOF_StgTSOProfInfo 8
+#ifdef PROFILING
+#define SIZEOF_OPT_StgTSOProfInfo SIZEOF_StgTSOProfInfo
+#else
+#define SIZEOF_OPT_StgTSOProfInfo 0
+#endif
+
+#define OFFSET_StgUpdateFrame_updatee 0
+#define REP_StgUpdateFrame_updatee b64
+#define StgUpdateFrame_updatee(__ptr__)  REP_StgUpdateFrame_updatee[__ptr__+SIZEOF_StgHeader+OFFSET_StgUpdateFrame_updatee]
+#define OFFSET_StgCatchFrame_handler 8
+#define REP_StgCatchFrame_handler b64
+#define StgCatchFrame_handler(__ptr__)  REP_StgCatchFrame_handler[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchFrame_handler]
+#define OFFSET_StgCatchFrame_exceptions_blocked 0
+#define REP_StgCatchFrame_exceptions_blocked b64
+#define StgCatchFrame_exceptions_blocked(__ptr__)  REP_StgCatchFrame_exceptions_blocked[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchFrame_exceptions_blocked]
+#define SIZEOF_StgPAP_NoHdr 16
+#define SIZEOF_StgPAP (SIZEOF_StgHeader+16)
+#define OFFSET_StgPAP_n_args 4
+#define REP_StgPAP_n_args b32
+#define StgPAP_n_args(__ptr__)  REP_StgPAP_n_args[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_n_args]
+#define OFFSET_StgPAP_fun 8
+#define REP_StgPAP_fun gcptr
+#define StgPAP_fun(__ptr__)  REP_StgPAP_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_fun]
+#define OFFSET_StgPAP_arity 0
+#define REP_StgPAP_arity b32
+#define StgPAP_arity(__ptr__)  REP_StgPAP_arity[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_arity]
+#define OFFSET_StgPAP_payload 16
+#define StgPAP_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_payload + WDS(__ix__)]
+#define SIZEOF_StgAP_NoThunkHdr 16
+#define SIZEOF_StgAP_NoHdr 24
+#define SIZEOF_StgAP (SIZEOF_StgHeader+24)
+#define OFFSET_StgAP_n_args 12
+#define REP_StgAP_n_args b32
+#define StgAP_n_args(__ptr__)  REP_StgAP_n_args[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_n_args]
+#define OFFSET_StgAP_fun 16
+#define REP_StgAP_fun gcptr
+#define StgAP_fun(__ptr__)  REP_StgAP_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_fun]
+#define OFFSET_StgAP_payload 24
+#define StgAP_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_payload + WDS(__ix__)]
+#define SIZEOF_StgAP_STACK_NoThunkHdr 16
+#define SIZEOF_StgAP_STACK_NoHdr 24
+#define SIZEOF_StgAP_STACK (SIZEOF_StgHeader+24)
+#define OFFSET_StgAP_STACK_size 8
+#define REP_StgAP_STACK_size b64
+#define StgAP_STACK_size(__ptr__)  REP_StgAP_STACK_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_size]
+#define OFFSET_StgAP_STACK_fun 16
+#define REP_StgAP_STACK_fun gcptr
+#define StgAP_STACK_fun(__ptr__)  REP_StgAP_STACK_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_fun]
+#define OFFSET_StgAP_STACK_payload 24
+#define StgAP_STACK_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_payload + WDS(__ix__)]
+#define SIZEOF_StgSelector_NoThunkHdr 8
+#define SIZEOF_StgSelector_NoHdr 16
+#define SIZEOF_StgSelector (SIZEOF_StgHeader+16)
+#define OFFSET_StgInd_indirectee 0
+#define REP_StgInd_indirectee gcptr
+#define StgInd_indirectee(__ptr__)  REP_StgInd_indirectee[__ptr__+SIZEOF_StgHeader+OFFSET_StgInd_indirectee]
+#define SIZEOF_StgMutVar_NoHdr 8
+#define SIZEOF_StgMutVar (SIZEOF_StgHeader+8)
+#define OFFSET_StgMutVar_var 0
+#define REP_StgMutVar_var b64
+#define StgMutVar_var(__ptr__)  REP_StgMutVar_var[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutVar_var]
+#define SIZEOF_StgAtomicallyFrame_NoHdr 24
+#define SIZEOF_StgAtomicallyFrame (SIZEOF_StgHeader+24)
+#define OFFSET_StgAtomicallyFrame_code 0
+#define REP_StgAtomicallyFrame_code b64
+#define StgAtomicallyFrame_code(__ptr__)  REP_StgAtomicallyFrame_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_code]
+#define OFFSET_StgAtomicallyFrame_next_invariant_to_check 8
+#define REP_StgAtomicallyFrame_next_invariant_to_check b64
+#define StgAtomicallyFrame_next_invariant_to_check(__ptr__)  REP_StgAtomicallyFrame_next_invariant_to_check[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_next_invariant_to_check]
+#define OFFSET_StgAtomicallyFrame_result 16
+#define REP_StgAtomicallyFrame_result b64
+#define StgAtomicallyFrame_result(__ptr__)  REP_StgAtomicallyFrame_result[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_result]
+#define OFFSET_StgInvariantCheckQueue_invariant 0
+#define REP_StgInvariantCheckQueue_invariant b64
+#define StgInvariantCheckQueue_invariant(__ptr__)  REP_StgInvariantCheckQueue_invariant[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_invariant]
+#define OFFSET_StgInvariantCheckQueue_my_execution 8
+#define REP_StgInvariantCheckQueue_my_execution b64
+#define StgInvariantCheckQueue_my_execution(__ptr__)  REP_StgInvariantCheckQueue_my_execution[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_my_execution]
+#define OFFSET_StgInvariantCheckQueue_next_queue_entry 16
+#define REP_StgInvariantCheckQueue_next_queue_entry b64
+#define StgInvariantCheckQueue_next_queue_entry(__ptr__)  REP_StgInvariantCheckQueue_next_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_next_queue_entry]
+#define OFFSET_StgAtomicInvariant_code 0
+#define REP_StgAtomicInvariant_code b64
+#define StgAtomicInvariant_code(__ptr__)  REP_StgAtomicInvariant_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicInvariant_code]
+#define OFFSET_StgTRecHeader_enclosing_trec 0
+#define REP_StgTRecHeader_enclosing_trec b64
+#define StgTRecHeader_enclosing_trec(__ptr__)  REP_StgTRecHeader_enclosing_trec[__ptr__+SIZEOF_StgHeader+OFFSET_StgTRecHeader_enclosing_trec]
+#define SIZEOF_StgCatchSTMFrame_NoHdr 16
+#define SIZEOF_StgCatchSTMFrame (SIZEOF_StgHeader+16)
+#define OFFSET_StgCatchSTMFrame_handler 8
+#define REP_StgCatchSTMFrame_handler b64
+#define StgCatchSTMFrame_handler(__ptr__)  REP_StgCatchSTMFrame_handler[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchSTMFrame_handler]
+#define OFFSET_StgCatchSTMFrame_code 0
+#define REP_StgCatchSTMFrame_code b64
+#define StgCatchSTMFrame_code(__ptr__)  REP_StgCatchSTMFrame_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchSTMFrame_code]
+#define SIZEOF_StgCatchRetryFrame_NoHdr 24
+#define SIZEOF_StgCatchRetryFrame (SIZEOF_StgHeader+24)
+#define OFFSET_StgCatchRetryFrame_running_alt_code 0
+#define REP_StgCatchRetryFrame_running_alt_code b32
+#define StgCatchRetryFrame_running_alt_code(__ptr__)  REP_StgCatchRetryFrame_running_alt_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_running_alt_code]
+#define OFFSET_StgCatchRetryFrame_first_code 8
+#define REP_StgCatchRetryFrame_first_code b64
+#define StgCatchRetryFrame_first_code(__ptr__)  REP_StgCatchRetryFrame_first_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_first_code]
+#define OFFSET_StgCatchRetryFrame_alt_code 16
+#define REP_StgCatchRetryFrame_alt_code b64
+#define StgCatchRetryFrame_alt_code(__ptr__)  REP_StgCatchRetryFrame_alt_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_alt_code]
+#define OFFSET_StgTVarWatchQueue_closure 0
+#define REP_StgTVarWatchQueue_closure b64
+#define StgTVarWatchQueue_closure(__ptr__)  REP_StgTVarWatchQueue_closure[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_closure]
+#define OFFSET_StgTVarWatchQueue_next_queue_entry 8
+#define REP_StgTVarWatchQueue_next_queue_entry b64
+#define StgTVarWatchQueue_next_queue_entry(__ptr__)  REP_StgTVarWatchQueue_next_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_next_queue_entry]
+#define OFFSET_StgTVarWatchQueue_prev_queue_entry 16
+#define REP_StgTVarWatchQueue_prev_queue_entry b64
+#define StgTVarWatchQueue_prev_queue_entry(__ptr__)  REP_StgTVarWatchQueue_prev_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_prev_queue_entry]
+#define OFFSET_StgTVar_current_value 0
+#define REP_StgTVar_current_value b64
+#define StgTVar_current_value(__ptr__)  REP_StgTVar_current_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVar_current_value]
+#define SIZEOF_StgWeak_NoHdr 40
+#define SIZEOF_StgWeak (SIZEOF_StgHeader+40)
+#define OFFSET_StgWeak_link 32
+#define REP_StgWeak_link b64
+#define StgWeak_link(__ptr__)  REP_StgWeak_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_link]
+#define OFFSET_StgWeak_key 8
+#define REP_StgWeak_key b64
+#define StgWeak_key(__ptr__)  REP_StgWeak_key[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_key]
+#define OFFSET_StgWeak_value 16
+#define REP_StgWeak_value b64
+#define StgWeak_value(__ptr__)  REP_StgWeak_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_value]
+#define OFFSET_StgWeak_finalizer 24
+#define REP_StgWeak_finalizer b64
+#define StgWeak_finalizer(__ptr__)  REP_StgWeak_finalizer[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_finalizer]
+#define OFFSET_StgWeak_cfinalizer 0
+#define REP_StgWeak_cfinalizer b64
+#define StgWeak_cfinalizer(__ptr__)  REP_StgWeak_cfinalizer[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_cfinalizer]
+#define SIZEOF_StgDeadWeak_NoHdr 8
+#define SIZEOF_StgDeadWeak (SIZEOF_StgHeader+8)
+#define OFFSET_StgDeadWeak_link 0
+#define REP_StgDeadWeak_link b64
+#define StgDeadWeak_link(__ptr__)  REP_StgDeadWeak_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgDeadWeak_link]
+#define SIZEOF_StgMVar_NoHdr 24
+#define SIZEOF_StgMVar (SIZEOF_StgHeader+24)
+#define OFFSET_StgMVar_head 0
+#define REP_StgMVar_head b64
+#define StgMVar_head(__ptr__)  REP_StgMVar_head[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_head]
+#define OFFSET_StgMVar_tail 8
+#define REP_StgMVar_tail b64
+#define StgMVar_tail(__ptr__)  REP_StgMVar_tail[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_tail]
+#define OFFSET_StgMVar_value 16
+#define REP_StgMVar_value b64
+#define StgMVar_value(__ptr__)  REP_StgMVar_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_value]
+#define SIZEOF_StgMVarTSOQueue_NoHdr 16
+#define SIZEOF_StgMVarTSOQueue (SIZEOF_StgHeader+16)
+#define OFFSET_StgMVarTSOQueue_link 0
+#define REP_StgMVarTSOQueue_link b64
+#define StgMVarTSOQueue_link(__ptr__)  REP_StgMVarTSOQueue_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVarTSOQueue_link]
+#define OFFSET_StgMVarTSOQueue_tso 8
+#define REP_StgMVarTSOQueue_tso b64
+#define StgMVarTSOQueue_tso(__ptr__)  REP_StgMVarTSOQueue_tso[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVarTSOQueue_tso]
+#define SIZEOF_StgBCO_NoHdr 32
+#define SIZEOF_StgBCO (SIZEOF_StgHeader+32)
+#define OFFSET_StgBCO_instrs 0
+#define REP_StgBCO_instrs b64
+#define StgBCO_instrs(__ptr__)  REP_StgBCO_instrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_instrs]
+#define OFFSET_StgBCO_literals 8
+#define REP_StgBCO_literals b64
+#define StgBCO_literals(__ptr__)  REP_StgBCO_literals[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_literals]
+#define OFFSET_StgBCO_ptrs 16
+#define REP_StgBCO_ptrs b64
+#define StgBCO_ptrs(__ptr__)  REP_StgBCO_ptrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_ptrs]
+#define OFFSET_StgBCO_arity 24
+#define REP_StgBCO_arity b32
+#define StgBCO_arity(__ptr__)  REP_StgBCO_arity[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_arity]
+#define OFFSET_StgBCO_size 28
+#define REP_StgBCO_size b32
+#define StgBCO_size(__ptr__)  REP_StgBCO_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_size]
+#define OFFSET_StgBCO_bitmap 32
+#define StgBCO_bitmap(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_bitmap + WDS(__ix__)]
+#define SIZEOF_StgStableName_NoHdr 8
+#define SIZEOF_StgStableName (SIZEOF_StgHeader+8)
+#define OFFSET_StgStableName_sn 0
+#define REP_StgStableName_sn b64
+#define StgStableName_sn(__ptr__)  REP_StgStableName_sn[__ptr__+SIZEOF_StgHeader+OFFSET_StgStableName_sn]
+#define SIZEOF_StgBlockingQueue_NoHdr 32
+#define SIZEOF_StgBlockingQueue (SIZEOF_StgHeader+32)
+#define OFFSET_StgBlockingQueue_bh 8
+#define REP_StgBlockingQueue_bh b64
+#define StgBlockingQueue_bh(__ptr__)  REP_StgBlockingQueue_bh[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_bh]
+#define OFFSET_StgBlockingQueue_owner 16
+#define REP_StgBlockingQueue_owner b64
+#define StgBlockingQueue_owner(__ptr__)  REP_StgBlockingQueue_owner[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_owner]
+#define OFFSET_StgBlockingQueue_queue 24
+#define REP_StgBlockingQueue_queue b64
+#define StgBlockingQueue_queue(__ptr__)  REP_StgBlockingQueue_queue[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_queue]
+#define OFFSET_StgBlockingQueue_link 0
+#define REP_StgBlockingQueue_link b64
+#define StgBlockingQueue_link(__ptr__)  REP_StgBlockingQueue_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_link]
+#define SIZEOF_MessageBlackHole_NoHdr 24
+#define SIZEOF_MessageBlackHole (SIZEOF_StgHeader+24)
+#define OFFSET_MessageBlackHole_link 0
+#define REP_MessageBlackHole_link b64
+#define MessageBlackHole_link(__ptr__)  REP_MessageBlackHole_link[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_link]
+#define OFFSET_MessageBlackHole_tso 8
+#define REP_MessageBlackHole_tso b64
+#define MessageBlackHole_tso(__ptr__)  REP_MessageBlackHole_tso[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_tso]
+#define OFFSET_MessageBlackHole_bh 16
+#define REP_MessageBlackHole_bh b64
+#define MessageBlackHole_bh(__ptr__)  REP_MessageBlackHole_bh[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_bh]
+#define OFFSET_RtsFlags_ProfFlags_showCCSOnException 224
+#define REP_RtsFlags_ProfFlags_showCCSOnException b32
+#define RtsFlags_ProfFlags_showCCSOnException(__ptr__)  REP_RtsFlags_ProfFlags_showCCSOnException[__ptr__+OFFSET_RtsFlags_ProfFlags_showCCSOnException]
+#define OFFSET_RtsFlags_DebugFlags_apply 176
+#define REP_RtsFlags_DebugFlags_apply b32
+#define RtsFlags_DebugFlags_apply(__ptr__)  REP_RtsFlags_DebugFlags_apply[__ptr__+OFFSET_RtsFlags_DebugFlags_apply]
+#define OFFSET_RtsFlags_DebugFlags_sanity 160
+#define REP_RtsFlags_DebugFlags_sanity b32
+#define RtsFlags_DebugFlags_sanity(__ptr__)  REP_RtsFlags_DebugFlags_sanity[__ptr__+OFFSET_RtsFlags_DebugFlags_sanity]
+#define OFFSET_RtsFlags_DebugFlags_weak 144
+#define REP_RtsFlags_DebugFlags_weak b32
+#define RtsFlags_DebugFlags_weak(__ptr__)  REP_RtsFlags_DebugFlags_weak[__ptr__+OFFSET_RtsFlags_DebugFlags_weak]
+#define OFFSET_RtsFlags_GcFlags_initialStkSize 16
+#define REP_RtsFlags_GcFlags_initialStkSize b32
+#define RtsFlags_GcFlags_initialStkSize(__ptr__)  REP_RtsFlags_GcFlags_initialStkSize[__ptr__+OFFSET_RtsFlags_GcFlags_initialStkSize]
+#define OFFSET_RtsFlags_MiscFlags_tickInterval 112
+#define REP_RtsFlags_MiscFlags_tickInterval b32
+#define RtsFlags_MiscFlags_tickInterval(__ptr__)  REP_RtsFlags_MiscFlags_tickInterval[__ptr__+OFFSET_RtsFlags_MiscFlags_tickInterval]
+#define SIZEOF_StgFunInfoExtraFwd 32
+#define OFFSET_StgFunInfoExtraFwd_slow_apply 24
+#define REP_StgFunInfoExtraFwd_slow_apply b64
+#define StgFunInfoExtraFwd_slow_apply(__ptr__)  REP_StgFunInfoExtraFwd_slow_apply[__ptr__+OFFSET_StgFunInfoExtraFwd_slow_apply]
+#define OFFSET_StgFunInfoExtraFwd_fun_type 0
+#define REP_StgFunInfoExtraFwd_fun_type b32
+#define StgFunInfoExtraFwd_fun_type(__ptr__)  REP_StgFunInfoExtraFwd_fun_type[__ptr__+OFFSET_StgFunInfoExtraFwd_fun_type]
+#define OFFSET_StgFunInfoExtraFwd_arity 4
+#define REP_StgFunInfoExtraFwd_arity b32
+#define StgFunInfoExtraFwd_arity(__ptr__)  REP_StgFunInfoExtraFwd_arity[__ptr__+OFFSET_StgFunInfoExtraFwd_arity]
+#define OFFSET_StgFunInfoExtraFwd_bitmap 16
+#define REP_StgFunInfoExtraFwd_bitmap b64
+#define StgFunInfoExtraFwd_bitmap(__ptr__)  REP_StgFunInfoExtraFwd_bitmap[__ptr__+OFFSET_StgFunInfoExtraFwd_bitmap]
+#define SIZEOF_StgFunInfoExtraRev 32
+#define OFFSET_StgFunInfoExtraRev_slow_apply_offset 0
+#define REP_StgFunInfoExtraRev_slow_apply_offset b32
+#define StgFunInfoExtraRev_slow_apply_offset(__ptr__)  REP_StgFunInfoExtraRev_slow_apply_offset[__ptr__+OFFSET_StgFunInfoExtraRev_slow_apply_offset]
+#define OFFSET_StgFunInfoExtraRev_fun_type 24
+#define REP_StgFunInfoExtraRev_fun_type b32
+#define StgFunInfoExtraRev_fun_type(__ptr__)  REP_StgFunInfoExtraRev_fun_type[__ptr__+OFFSET_StgFunInfoExtraRev_fun_type]
+#define OFFSET_StgFunInfoExtraRev_arity 28
+#define REP_StgFunInfoExtraRev_arity b32
+#define StgFunInfoExtraRev_arity(__ptr__)  REP_StgFunInfoExtraRev_arity[__ptr__+OFFSET_StgFunInfoExtraRev_arity]
+#define OFFSET_StgFunInfoExtraRev_bitmap 8
+#define REP_StgFunInfoExtraRev_bitmap b64
+#define StgFunInfoExtraRev_bitmap(__ptr__)  REP_StgFunInfoExtraRev_bitmap[__ptr__+OFFSET_StgFunInfoExtraRev_bitmap]
+#define OFFSET_StgLargeBitmap_size 0
+#define REP_StgLargeBitmap_size b64
+#define StgLargeBitmap_size(__ptr__)  REP_StgLargeBitmap_size[__ptr__+OFFSET_StgLargeBitmap_size]
+#define OFFSET_StgLargeBitmap_bitmap 8
+#define SIZEOF_snEntry 32
+#define OFFSET_snEntry_sn_obj 24
+#define REP_snEntry_sn_obj b64
+#define snEntry_sn_obj(__ptr__)  REP_snEntry_sn_obj[__ptr__+OFFSET_snEntry_sn_obj]
+#define OFFSET_snEntry_addr 0
+#define REP_snEntry_addr b64
+#define snEntry_addr(__ptr__)  REP_snEntry_addr[__ptr__+OFFSET_snEntry_addr]
diff -rN -u old-ghc_bf/includes/GHCConstants.h.bf new-ghc_bf-2/includes/GHCConstants.h.bf
--- old-ghc_bf/includes/GHCConstants.h.bf	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/includes/GHCConstants.h.bf	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,493 @@
+oFFSET_StgRegTable_rR1 :: Int
+oFFSET_StgRegTable_rR1 = 0
+oFFSET_StgRegTable_rR2 :: Int
+oFFSET_StgRegTable_rR2 = 8
+oFFSET_StgRegTable_rR3 :: Int
+oFFSET_StgRegTable_rR3 = 16
+oFFSET_StgRegTable_rR4 :: Int
+oFFSET_StgRegTable_rR4 = 24
+oFFSET_StgRegTable_rR5 :: Int
+oFFSET_StgRegTable_rR5 = 32
+oFFSET_StgRegTable_rR6 :: Int
+oFFSET_StgRegTable_rR6 = 40
+oFFSET_StgRegTable_rR7 :: Int
+oFFSET_StgRegTable_rR7 = 48
+oFFSET_StgRegTable_rR8 :: Int
+oFFSET_StgRegTable_rR8 = 56
+oFFSET_StgRegTable_rR9 :: Int
+oFFSET_StgRegTable_rR9 = 64
+oFFSET_StgRegTable_rR10 :: Int
+oFFSET_StgRegTable_rR10 = 72
+oFFSET_StgRegTable_rF1 :: Int
+oFFSET_StgRegTable_rF1 = 80
+oFFSET_StgRegTable_rF2 :: Int
+oFFSET_StgRegTable_rF2 = 84
+oFFSET_StgRegTable_rF3 :: Int
+oFFSET_StgRegTable_rF3 = 88
+oFFSET_StgRegTable_rF4 :: Int
+oFFSET_StgRegTable_rF4 = 92
+oFFSET_StgRegTable_rD1 :: Int
+oFFSET_StgRegTable_rD1 = 96
+oFFSET_StgRegTable_rD2 :: Int
+oFFSET_StgRegTable_rD2 = 104
+oFFSET_StgRegTable_rL1 :: Int
+oFFSET_StgRegTable_rL1 = 112
+oFFSET_StgRegTable_rSp :: Int
+oFFSET_StgRegTable_rSp = 120
+oFFSET_StgRegTable_rSpLim :: Int
+oFFSET_StgRegTable_rSpLim = 128
+oFFSET_StgRegTable_rHp :: Int
+oFFSET_StgRegTable_rHp = 136
+oFFSET_StgRegTable_rHpLim :: Int
+oFFSET_StgRegTable_rHpLim = 144
+oFFSET_StgRegTable_rCurrentTSO :: Int
+oFFSET_StgRegTable_rCurrentTSO = 152
+oFFSET_StgRegTable_rCurrentNursery :: Int
+oFFSET_StgRegTable_rCurrentNursery = 168
+oFFSET_StgRegTable_rHpAlloc :: Int
+oFFSET_StgRegTable_rHpAlloc = 184
+oFFSET_StgRegTable_rRet :: Int
+oFFSET_StgRegTable_rRet = 192
+#define StgRegTable_rRet(__ptr__)  REP_StgRegTable_rRet[__ptr__+OFFSET_StgRegTable_rRet]
+oFFSET_StgRegTable_rNursery :: Int
+oFFSET_StgRegTable_rNursery = 160
+#define StgRegTable_rNursery(__ptr__)  REP_StgRegTable_rNursery[__ptr__+OFFSET_StgRegTable_rNursery]
+oFFSET_stgEagerBlackholeInfo :: Int
+oFFSET_stgEagerBlackholeInfo = 18446744073709551592
+oFFSET_stgGCEnter1 :: Int
+oFFSET_stgGCEnter1 = 18446744073709551600
+oFFSET_stgGCFun :: Int
+oFFSET_stgGCFun = 18446744073709551608
+oFFSET_Capability_r :: Int
+oFFSET_Capability_r = 24
+oFFSET_Capability_lock :: Int
+oFFSET_Capability_lock = 312
+oFFSET_Capability_mut_lists :: Int
+oFFSET_Capability_mut_lists = 272
+#define Capability_mut_lists(__ptr__)  REP_Capability_mut_lists[__ptr__+OFFSET_Capability_mut_lists]
+oFFSET_Capability_context_switch :: Int
+oFFSET_Capability_context_switch = 296
+#define Capability_context_switch(__ptr__)  REP_Capability_context_switch[__ptr__+OFFSET_Capability_context_switch]
+oFFSET_Capability_sparks :: Int
+oFFSET_Capability_sparks = 368
+#define Capability_sparks(__ptr__)  REP_Capability_sparks[__ptr__+OFFSET_Capability_sparks]
+oFFSET_bdescr_start :: Int
+oFFSET_bdescr_start = 0
+#define bdescr_start(__ptr__)  REP_bdescr_start[__ptr__+OFFSET_bdescr_start]
+oFFSET_bdescr_free :: Int
+oFFSET_bdescr_free = 8
+#define bdescr_free(__ptr__)  REP_bdescr_free[__ptr__+OFFSET_bdescr_free]
+oFFSET_bdescr_blocks :: Int
+oFFSET_bdescr_blocks = 48
+#define bdescr_blocks(__ptr__)  REP_bdescr_blocks[__ptr__+OFFSET_bdescr_blocks]
+oFFSET_bdescr_gen_no :: Int
+oFFSET_bdescr_gen_no = 52
+#define bdescr_gen_no(__ptr__)  REP_bdescr_gen_no[__ptr__+OFFSET_bdescr_gen_no]
+oFFSET_bdescr_link :: Int
+oFFSET_bdescr_link = 16
+#define bdescr_link(__ptr__)  REP_bdescr_link[__ptr__+OFFSET_bdescr_link]
+sIZEOF_generation :: Int
+sIZEOF_generation = 312
+oFFSET_generation_mut_list :: Int
+oFFSET_generation_mut_list = 48
+#define generation_mut_list(__ptr__)  REP_generation_mut_list[__ptr__+OFFSET_generation_mut_list]
+oFFSET_generation_n_new_large_blocks :: Int
+oFFSET_generation_n_new_large_blocks = 36
+#define generation_n_new_large_blocks(__ptr__)  REP_generation_n_new_large_blocks[__ptr__+OFFSET_generation_n_new_large_blocks]
+sIZEOF_CostCentreStack :: Int
+sIZEOF_CostCentreStack = 88
+oFFSET_CostCentreStack_ccsID :: Int
+oFFSET_CostCentreStack_ccsID = 0
+#define CostCentreStack_ccsID(__ptr__)  REP_CostCentreStack_ccsID[__ptr__+OFFSET_CostCentreStack_ccsID]
+oFFSET_CostCentreStack_mem_alloc :: Int
+oFFSET_CostCentreStack_mem_alloc = 56
+#define CostCentreStack_mem_alloc(__ptr__)  REP_CostCentreStack_mem_alloc[__ptr__+OFFSET_CostCentreStack_mem_alloc]
+oFFSET_CostCentreStack_scc_count :: Int
+oFFSET_CostCentreStack_scc_count = 32
+#define CostCentreStack_scc_count(__ptr__)  REP_CostCentreStack_scc_count[__ptr__+OFFSET_CostCentreStack_scc_count]
+oFFSET_CostCentreStack_prevStack :: Int
+oFFSET_CostCentreStack_prevStack = 16
+#define CostCentreStack_prevStack(__ptr__)  REP_CostCentreStack_prevStack[__ptr__+OFFSET_CostCentreStack_prevStack]
+oFFSET_CostCentre_ccID :: Int
+oFFSET_CostCentre_ccID = 0
+#define CostCentre_ccID(__ptr__)  REP_CostCentre_ccID[__ptr__+OFFSET_CostCentre_ccID]
+oFFSET_CostCentre_link :: Int
+oFFSET_CostCentre_link = 48
+#define CostCentre_link(__ptr__)  REP_CostCentre_link[__ptr__+OFFSET_CostCentre_link]
+oFFSET_StgHeader_info :: Int
+oFFSET_StgHeader_info = 0
+#define StgHeader_info(__ptr__)  REP_StgHeader_info[__ptr__+OFFSET_StgHeader_info]
+oFFSET_StgHeader_ccs :: Int
+oFFSET_StgHeader_ccs = 8
+#define StgHeader_ccs(__ptr__)  REP_StgHeader_ccs[__ptr__+OFFSET_StgHeader_ccs]
+oFFSET_StgHeader_ldvw :: Int
+oFFSET_StgHeader_ldvw = 16
+#define StgHeader_ldvw(__ptr__)  REP_StgHeader_ldvw[__ptr__+OFFSET_StgHeader_ldvw]
+sIZEOF_StgSMPThunkHeader :: Int
+sIZEOF_StgSMPThunkHeader = 8
+oFFSET_StgClosure_payload :: Int
+oFFSET_StgClosure_payload = 0
+#define StgClosure_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgClosure_payload + WDS(__ix__)]
+oFFSET_StgEntCounter_allocs :: Int
+oFFSET_StgEntCounter_allocs = 48
+#define StgEntCounter_allocs(__ptr__)  REP_StgEntCounter_allocs[__ptr__+OFFSET_StgEntCounter_allocs]
+oFFSET_StgEntCounter_registeredp :: Int
+oFFSET_StgEntCounter_registeredp = 0
+#define StgEntCounter_registeredp(__ptr__)  REP_StgEntCounter_registeredp[__ptr__+OFFSET_StgEntCounter_registeredp]
+oFFSET_StgEntCounter_link :: Int
+oFFSET_StgEntCounter_link = 56
+#define StgEntCounter_link(__ptr__)  REP_StgEntCounter_link[__ptr__+OFFSET_StgEntCounter_link]
+oFFSET_StgEntCounter_entry_count :: Int
+oFFSET_StgEntCounter_entry_count = 40
+#define StgEntCounter_entry_count(__ptr__)  REP_StgEntCounter_entry_count[__ptr__+OFFSET_StgEntCounter_entry_count]
+sIZEOF_StgUpdateFrame_NoHdr :: Int
+sIZEOF_StgUpdateFrame_NoHdr = 8
+sIZEOF_StgCatchFrame_NoHdr :: Int
+sIZEOF_StgCatchFrame_NoHdr = 16
+sIZEOF_StgStopFrame_NoHdr :: Int
+sIZEOF_StgStopFrame_NoHdr = 0
+sIZEOF_StgMutArrPtrs_NoHdr :: Int
+sIZEOF_StgMutArrPtrs_NoHdr = 16
+oFFSET_StgMutArrPtrs_ptrs :: Int
+oFFSET_StgMutArrPtrs_ptrs = 0
+#define StgMutArrPtrs_ptrs(__ptr__)  REP_StgMutArrPtrs_ptrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutArrPtrs_ptrs]
+oFFSET_StgMutArrPtrs_size :: Int
+oFFSET_StgMutArrPtrs_size = 8
+#define StgMutArrPtrs_size(__ptr__)  REP_StgMutArrPtrs_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutArrPtrs_size]
+sIZEOF_StgArrWords_NoHdr :: Int
+sIZEOF_StgArrWords_NoHdr = 8
+oFFSET_StgArrWords_bytes :: Int
+oFFSET_StgArrWords_bytes = 0
+#define StgArrWords_bytes(__ptr__)  REP_StgArrWords_bytes[__ptr__+SIZEOF_StgHeader+OFFSET_StgArrWords_bytes]
+oFFSET_StgArrWords_payload :: Int
+oFFSET_StgArrWords_payload = 8
+#define StgArrWords_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgArrWords_payload + WDS(__ix__)]
+oFFSET_StgTSO__link :: Int
+oFFSET_StgTSO__link = 0
+#define StgTSO__link(__ptr__)  REP_StgTSO__link[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO__link]
+oFFSET_StgTSO_global_link :: Int
+oFFSET_StgTSO_global_link = 8
+#define StgTSO_global_link(__ptr__)  REP_StgTSO_global_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_global_link]
+oFFSET_StgTSO_what_next :: Int
+oFFSET_StgTSO_what_next = 24
+#define StgTSO_what_next(__ptr__)  REP_StgTSO_what_next[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_what_next]
+oFFSET_StgTSO_why_blocked :: Int
+oFFSET_StgTSO_why_blocked = 26
+#define StgTSO_why_blocked(__ptr__)  REP_StgTSO_why_blocked[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_why_blocked]
+oFFSET_StgTSO_block_info :: Int
+oFFSET_StgTSO_block_info = 32
+#define StgTSO_block_info(__ptr__)  REP_StgTSO_block_info[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_block_info]
+oFFSET_StgTSO_blocked_exceptions :: Int
+oFFSET_StgTSO_blocked_exceptions = 72
+#define StgTSO_blocked_exceptions(__ptr__)  REP_StgTSO_blocked_exceptions[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_blocked_exceptions]
+oFFSET_StgTSO_id :: Int
+oFFSET_StgTSO_id = 40
+#define StgTSO_id(__ptr__)  REP_StgTSO_id[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_id]
+oFFSET_StgTSO_cap :: Int
+oFFSET_StgTSO_cap = 56
+#define StgTSO_cap(__ptr__)  REP_StgTSO_cap[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_cap]
+oFFSET_StgTSO_saved_errno :: Int
+oFFSET_StgTSO_saved_errno = 44
+#define StgTSO_saved_errno(__ptr__)  REP_StgTSO_saved_errno[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_saved_errno]
+oFFSET_StgTSO_trec :: Int
+oFFSET_StgTSO_trec = 64
+#define StgTSO_trec(__ptr__)  REP_StgTSO_trec[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_trec]
+oFFSET_StgTSO_flags :: Int
+oFFSET_StgTSO_flags = 28
+#define StgTSO_flags(__ptr__)  REP_StgTSO_flags[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_flags]
+oFFSET_StgTSO_dirty :: Int
+oFFSET_StgTSO_dirty = 16
+#define StgTSO_dirty(__ptr__)  REP_StgTSO_dirty[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_dirty]
+oFFSET_StgTSO_bq :: Int
+oFFSET_StgTSO_bq = 80
+#define StgTSO_bq(__ptr__)  REP_StgTSO_bq[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_bq]
+oFFSET_StgTSO_CCCS :: Int
+oFFSET_StgTSO_CCCS = 88
+#define StgTSO_CCCS(__ptr__)  REP_StgTSO_CCCS[__ptr__+SIZEOF_StgHeader+OFFSET_StgTSO_CCCS]
+oFFSET_StgTSO_sp :: Int
+oFFSET_StgTSO_sp = 96
+#define TSO_OFFSET_StgTSO_sp (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_sp)
+#define StgTSO_sp(__ptr__)  REP_StgTSO_sp[__ptr__+TSO_OFFSET_StgTSO_sp]
+oFFSET_StgTSO_stack :: Int
+oFFSET_StgTSO_stack = 104
+#define TSO_OFFSET_StgTSO_stack (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_stack)
+oFFSET_StgTSO_stack_size :: Int
+oFFSET_StgTSO_stack_size = 88
+#define TSO_OFFSET_StgTSO_stack_size (SIZEOF_StgHeader+SIZEOF_OPT_StgTSOProfInfo+OFFSET_StgTSO_stack_size)
+#define StgTSO_stack_size(__ptr__)  REP_StgTSO_stack_size[__ptr__+TSO_OFFSET_StgTSO_stack_size]
+sIZEOF_StgTSOProfInfo :: Int
+sIZEOF_StgTSOProfInfo = 8
+#ifdef PROFILING
+#define SIZEOF_OPT_StgTSOProfInfo SIZEOF_StgTSOProfInfo
+#else
+#define SIZEOF_OPT_StgTSOProfInfo 0
+#endif
+
+oFFSET_StgUpdateFrame_updatee :: Int
+oFFSET_StgUpdateFrame_updatee = 0
+#define StgUpdateFrame_updatee(__ptr__)  REP_StgUpdateFrame_updatee[__ptr__+SIZEOF_StgHeader+OFFSET_StgUpdateFrame_updatee]
+oFFSET_StgCatchFrame_handler :: Int
+oFFSET_StgCatchFrame_handler = 8
+#define StgCatchFrame_handler(__ptr__)  REP_StgCatchFrame_handler[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchFrame_handler]
+oFFSET_StgCatchFrame_exceptions_blocked :: Int
+oFFSET_StgCatchFrame_exceptions_blocked = 0
+#define StgCatchFrame_exceptions_blocked(__ptr__)  REP_StgCatchFrame_exceptions_blocked[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchFrame_exceptions_blocked]
+sIZEOF_StgPAP_NoHdr :: Int
+sIZEOF_StgPAP_NoHdr = 16
+oFFSET_StgPAP_n_args :: Int
+oFFSET_StgPAP_n_args = 4
+#define StgPAP_n_args(__ptr__)  REP_StgPAP_n_args[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_n_args]
+oFFSET_StgPAP_fun :: Int
+oFFSET_StgPAP_fun = 8
+#define StgPAP_fun(__ptr__)  REP_StgPAP_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_fun]
+oFFSET_StgPAP_arity :: Int
+oFFSET_StgPAP_arity = 0
+#define StgPAP_arity(__ptr__)  REP_StgPAP_arity[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_arity]
+oFFSET_StgPAP_payload :: Int
+oFFSET_StgPAP_payload = 16
+#define StgPAP_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgPAP_payload + WDS(__ix__)]
+sIZEOF_StgAP_NoThunkHdr :: Int
+sIZEOF_StgAP_NoThunkHdr = 16
+sIZEOF_StgAP_NoHdr :: Int
+sIZEOF_StgAP_NoHdr = 24
+oFFSET_StgAP_n_args :: Int
+oFFSET_StgAP_n_args = 12
+#define StgAP_n_args(__ptr__)  REP_StgAP_n_args[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_n_args]
+oFFSET_StgAP_fun :: Int
+oFFSET_StgAP_fun = 16
+#define StgAP_fun(__ptr__)  REP_StgAP_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_fun]
+oFFSET_StgAP_payload :: Int
+oFFSET_StgAP_payload = 24
+#define StgAP_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_payload + WDS(__ix__)]
+sIZEOF_StgAP_STACK_NoThunkHdr :: Int
+sIZEOF_StgAP_STACK_NoThunkHdr = 16
+sIZEOF_StgAP_STACK_NoHdr :: Int
+sIZEOF_StgAP_STACK_NoHdr = 24
+oFFSET_StgAP_STACK_size :: Int
+oFFSET_StgAP_STACK_size = 8
+#define StgAP_STACK_size(__ptr__)  REP_StgAP_STACK_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_size]
+oFFSET_StgAP_STACK_fun :: Int
+oFFSET_StgAP_STACK_fun = 16
+#define StgAP_STACK_fun(__ptr__)  REP_StgAP_STACK_fun[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_fun]
+oFFSET_StgAP_STACK_payload :: Int
+oFFSET_StgAP_STACK_payload = 24
+#define StgAP_STACK_payload(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgAP_STACK_payload + WDS(__ix__)]
+sIZEOF_StgSelector_NoThunkHdr :: Int
+sIZEOF_StgSelector_NoThunkHdr = 8
+sIZEOF_StgSelector_NoHdr :: Int
+sIZEOF_StgSelector_NoHdr = 16
+oFFSET_StgInd_indirectee :: Int
+oFFSET_StgInd_indirectee = 0
+#define StgInd_indirectee(__ptr__)  REP_StgInd_indirectee[__ptr__+SIZEOF_StgHeader+OFFSET_StgInd_indirectee]
+sIZEOF_StgMutVar_NoHdr :: Int
+sIZEOF_StgMutVar_NoHdr = 8
+oFFSET_StgMutVar_var :: Int
+oFFSET_StgMutVar_var = 0
+#define StgMutVar_var(__ptr__)  REP_StgMutVar_var[__ptr__+SIZEOF_StgHeader+OFFSET_StgMutVar_var]
+sIZEOF_StgAtomicallyFrame_NoHdr :: Int
+sIZEOF_StgAtomicallyFrame_NoHdr = 24
+oFFSET_StgAtomicallyFrame_code :: Int
+oFFSET_StgAtomicallyFrame_code = 0
+#define StgAtomicallyFrame_code(__ptr__)  REP_StgAtomicallyFrame_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_code]
+oFFSET_StgAtomicallyFrame_next_invariant_to_check :: Int
+oFFSET_StgAtomicallyFrame_next_invariant_to_check = 8
+#define StgAtomicallyFrame_next_invariant_to_check(__ptr__)  REP_StgAtomicallyFrame_next_invariant_to_check[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_next_invariant_to_check]
+oFFSET_StgAtomicallyFrame_result :: Int
+oFFSET_StgAtomicallyFrame_result = 16
+#define StgAtomicallyFrame_result(__ptr__)  REP_StgAtomicallyFrame_result[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicallyFrame_result]
+oFFSET_StgInvariantCheckQueue_invariant :: Int
+oFFSET_StgInvariantCheckQueue_invariant = 0
+#define StgInvariantCheckQueue_invariant(__ptr__)  REP_StgInvariantCheckQueue_invariant[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_invariant]
+oFFSET_StgInvariantCheckQueue_my_execution :: Int
+oFFSET_StgInvariantCheckQueue_my_execution = 8
+#define StgInvariantCheckQueue_my_execution(__ptr__)  REP_StgInvariantCheckQueue_my_execution[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_my_execution]
+oFFSET_StgInvariantCheckQueue_next_queue_entry :: Int
+oFFSET_StgInvariantCheckQueue_next_queue_entry = 16
+#define StgInvariantCheckQueue_next_queue_entry(__ptr__)  REP_StgInvariantCheckQueue_next_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgInvariantCheckQueue_next_queue_entry]
+oFFSET_StgAtomicInvariant_code :: Int
+oFFSET_StgAtomicInvariant_code = 0
+#define StgAtomicInvariant_code(__ptr__)  REP_StgAtomicInvariant_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgAtomicInvariant_code]
+oFFSET_StgTRecHeader_enclosing_trec :: Int
+oFFSET_StgTRecHeader_enclosing_trec = 0
+#define StgTRecHeader_enclosing_trec(__ptr__)  REP_StgTRecHeader_enclosing_trec[__ptr__+SIZEOF_StgHeader+OFFSET_StgTRecHeader_enclosing_trec]
+sIZEOF_StgCatchSTMFrame_NoHdr :: Int
+sIZEOF_StgCatchSTMFrame_NoHdr = 16
+oFFSET_StgCatchSTMFrame_handler :: Int
+oFFSET_StgCatchSTMFrame_handler = 8
+#define StgCatchSTMFrame_handler(__ptr__)  REP_StgCatchSTMFrame_handler[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchSTMFrame_handler]
+oFFSET_StgCatchSTMFrame_code :: Int
+oFFSET_StgCatchSTMFrame_code = 0
+#define StgCatchSTMFrame_code(__ptr__)  REP_StgCatchSTMFrame_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchSTMFrame_code]
+sIZEOF_StgCatchRetryFrame_NoHdr :: Int
+sIZEOF_StgCatchRetryFrame_NoHdr = 24
+oFFSET_StgCatchRetryFrame_running_alt_code :: Int
+oFFSET_StgCatchRetryFrame_running_alt_code = 0
+#define StgCatchRetryFrame_running_alt_code(__ptr__)  REP_StgCatchRetryFrame_running_alt_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_running_alt_code]
+oFFSET_StgCatchRetryFrame_first_code :: Int
+oFFSET_StgCatchRetryFrame_first_code = 8
+#define StgCatchRetryFrame_first_code(__ptr__)  REP_StgCatchRetryFrame_first_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_first_code]
+oFFSET_StgCatchRetryFrame_alt_code :: Int
+oFFSET_StgCatchRetryFrame_alt_code = 16
+#define StgCatchRetryFrame_alt_code(__ptr__)  REP_StgCatchRetryFrame_alt_code[__ptr__+SIZEOF_StgHeader+OFFSET_StgCatchRetryFrame_alt_code]
+oFFSET_StgTVarWatchQueue_closure :: Int
+oFFSET_StgTVarWatchQueue_closure = 0
+#define StgTVarWatchQueue_closure(__ptr__)  REP_StgTVarWatchQueue_closure[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_closure]
+oFFSET_StgTVarWatchQueue_next_queue_entry :: Int
+oFFSET_StgTVarWatchQueue_next_queue_entry = 8
+#define StgTVarWatchQueue_next_queue_entry(__ptr__)  REP_StgTVarWatchQueue_next_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_next_queue_entry]
+oFFSET_StgTVarWatchQueue_prev_queue_entry :: Int
+oFFSET_StgTVarWatchQueue_prev_queue_entry = 16
+#define StgTVarWatchQueue_prev_queue_entry(__ptr__)  REP_StgTVarWatchQueue_prev_queue_entry[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVarWatchQueue_prev_queue_entry]
+oFFSET_StgTVar_current_value :: Int
+oFFSET_StgTVar_current_value = 0
+#define StgTVar_current_value(__ptr__)  REP_StgTVar_current_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgTVar_current_value]
+sIZEOF_StgWeak_NoHdr :: Int
+sIZEOF_StgWeak_NoHdr = 40
+oFFSET_StgWeak_link :: Int
+oFFSET_StgWeak_link = 32
+#define StgWeak_link(__ptr__)  REP_StgWeak_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_link]
+oFFSET_StgWeak_key :: Int
+oFFSET_StgWeak_key = 8
+#define StgWeak_key(__ptr__)  REP_StgWeak_key[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_key]
+oFFSET_StgWeak_value :: Int
+oFFSET_StgWeak_value = 16
+#define StgWeak_value(__ptr__)  REP_StgWeak_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_value]
+oFFSET_StgWeak_finalizer :: Int
+oFFSET_StgWeak_finalizer = 24
+#define StgWeak_finalizer(__ptr__)  REP_StgWeak_finalizer[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_finalizer]
+oFFSET_StgWeak_cfinalizer :: Int
+oFFSET_StgWeak_cfinalizer = 0
+#define StgWeak_cfinalizer(__ptr__)  REP_StgWeak_cfinalizer[__ptr__+SIZEOF_StgHeader+OFFSET_StgWeak_cfinalizer]
+sIZEOF_StgDeadWeak_NoHdr :: Int
+sIZEOF_StgDeadWeak_NoHdr = 8
+oFFSET_StgDeadWeak_link :: Int
+oFFSET_StgDeadWeak_link = 0
+#define StgDeadWeak_link(__ptr__)  REP_StgDeadWeak_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgDeadWeak_link]
+sIZEOF_StgMVar_NoHdr :: Int
+sIZEOF_StgMVar_NoHdr = 24
+oFFSET_StgMVar_head :: Int
+oFFSET_StgMVar_head = 0
+#define StgMVar_head(__ptr__)  REP_StgMVar_head[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_head]
+oFFSET_StgMVar_tail :: Int
+oFFSET_StgMVar_tail = 8
+#define StgMVar_tail(__ptr__)  REP_StgMVar_tail[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_tail]
+oFFSET_StgMVar_value :: Int
+oFFSET_StgMVar_value = 16
+#define StgMVar_value(__ptr__)  REP_StgMVar_value[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVar_value]
+sIZEOF_StgMVarTSOQueue_NoHdr :: Int
+sIZEOF_StgMVarTSOQueue_NoHdr = 16
+oFFSET_StgMVarTSOQueue_link :: Int
+oFFSET_StgMVarTSOQueue_link = 0
+#define StgMVarTSOQueue_link(__ptr__)  REP_StgMVarTSOQueue_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVarTSOQueue_link]
+oFFSET_StgMVarTSOQueue_tso :: Int
+oFFSET_StgMVarTSOQueue_tso = 8
+#define StgMVarTSOQueue_tso(__ptr__)  REP_StgMVarTSOQueue_tso[__ptr__+SIZEOF_StgHeader+OFFSET_StgMVarTSOQueue_tso]
+sIZEOF_StgBCO_NoHdr :: Int
+sIZEOF_StgBCO_NoHdr = 32
+oFFSET_StgBCO_instrs :: Int
+oFFSET_StgBCO_instrs = 0
+#define StgBCO_instrs(__ptr__)  REP_StgBCO_instrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_instrs]
+oFFSET_StgBCO_literals :: Int
+oFFSET_StgBCO_literals = 8
+#define StgBCO_literals(__ptr__)  REP_StgBCO_literals[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_literals]
+oFFSET_StgBCO_ptrs :: Int
+oFFSET_StgBCO_ptrs = 16
+#define StgBCO_ptrs(__ptr__)  REP_StgBCO_ptrs[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_ptrs]
+oFFSET_StgBCO_arity :: Int
+oFFSET_StgBCO_arity = 24
+#define StgBCO_arity(__ptr__)  REP_StgBCO_arity[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_arity]
+oFFSET_StgBCO_size :: Int
+oFFSET_StgBCO_size = 28
+#define StgBCO_size(__ptr__)  REP_StgBCO_size[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_size]
+oFFSET_StgBCO_bitmap :: Int
+oFFSET_StgBCO_bitmap = 32
+#define StgBCO_bitmap(__ptr__,__ix__)  W_[__ptr__+SIZEOF_StgHeader+OFFSET_StgBCO_bitmap + WDS(__ix__)]
+sIZEOF_StgStableName_NoHdr :: Int
+sIZEOF_StgStableName_NoHdr = 8
+oFFSET_StgStableName_sn :: Int
+oFFSET_StgStableName_sn = 0
+#define StgStableName_sn(__ptr__)  REP_StgStableName_sn[__ptr__+SIZEOF_StgHeader+OFFSET_StgStableName_sn]
+sIZEOF_StgBlockingQueue_NoHdr :: Int
+sIZEOF_StgBlockingQueue_NoHdr = 32
+oFFSET_StgBlockingQueue_bh :: Int
+oFFSET_StgBlockingQueue_bh = 8
+#define StgBlockingQueue_bh(__ptr__)  REP_StgBlockingQueue_bh[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_bh]
+oFFSET_StgBlockingQueue_owner :: Int
+oFFSET_StgBlockingQueue_owner = 16
+#define StgBlockingQueue_owner(__ptr__)  REP_StgBlockingQueue_owner[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_owner]
+oFFSET_StgBlockingQueue_queue :: Int
+oFFSET_StgBlockingQueue_queue = 24
+#define StgBlockingQueue_queue(__ptr__)  REP_StgBlockingQueue_queue[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_queue]
+oFFSET_StgBlockingQueue_link :: Int
+oFFSET_StgBlockingQueue_link = 0
+#define StgBlockingQueue_link(__ptr__)  REP_StgBlockingQueue_link[__ptr__+SIZEOF_StgHeader+OFFSET_StgBlockingQueue_link]
+sIZEOF_MessageBlackHole_NoHdr :: Int
+sIZEOF_MessageBlackHole_NoHdr = 24
+oFFSET_MessageBlackHole_link :: Int
+oFFSET_MessageBlackHole_link = 0
+#define MessageBlackHole_link(__ptr__)  REP_MessageBlackHole_link[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_link]
+oFFSET_MessageBlackHole_tso :: Int
+oFFSET_MessageBlackHole_tso = 8
+#define MessageBlackHole_tso(__ptr__)  REP_MessageBlackHole_tso[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_tso]
+oFFSET_MessageBlackHole_bh :: Int
+oFFSET_MessageBlackHole_bh = 16
+#define MessageBlackHole_bh(__ptr__)  REP_MessageBlackHole_bh[__ptr__+SIZEOF_StgHeader+OFFSET_MessageBlackHole_bh]
+oFFSET_RtsFlags_ProfFlags_showCCSOnException :: Int
+oFFSET_RtsFlags_ProfFlags_showCCSOnException = 224
+#define RtsFlags_ProfFlags_showCCSOnException(__ptr__)  REP_RtsFlags_ProfFlags_showCCSOnException[__ptr__+OFFSET_RtsFlags_ProfFlags_showCCSOnException]
+oFFSET_RtsFlags_DebugFlags_apply :: Int
+oFFSET_RtsFlags_DebugFlags_apply = 176
+#define RtsFlags_DebugFlags_apply(__ptr__)  REP_RtsFlags_DebugFlags_apply[__ptr__+OFFSET_RtsFlags_DebugFlags_apply]
+oFFSET_RtsFlags_DebugFlags_sanity :: Int
+oFFSET_RtsFlags_DebugFlags_sanity = 160
+#define RtsFlags_DebugFlags_sanity(__ptr__)  REP_RtsFlags_DebugFlags_sanity[__ptr__+OFFSET_RtsFlags_DebugFlags_sanity]
+oFFSET_RtsFlags_DebugFlags_weak :: Int
+oFFSET_RtsFlags_DebugFlags_weak = 144
+#define RtsFlags_DebugFlags_weak(__ptr__)  REP_RtsFlags_DebugFlags_weak[__ptr__+OFFSET_RtsFlags_DebugFlags_weak]
+oFFSET_RtsFlags_GcFlags_initialStkSize :: Int
+oFFSET_RtsFlags_GcFlags_initialStkSize = 16
+#define RtsFlags_GcFlags_initialStkSize(__ptr__)  REP_RtsFlags_GcFlags_initialStkSize[__ptr__+OFFSET_RtsFlags_GcFlags_initialStkSize]
+oFFSET_RtsFlags_MiscFlags_tickInterval :: Int
+oFFSET_RtsFlags_MiscFlags_tickInterval = 112
+#define RtsFlags_MiscFlags_tickInterval(__ptr__)  REP_RtsFlags_MiscFlags_tickInterval[__ptr__+OFFSET_RtsFlags_MiscFlags_tickInterval]
+sIZEOF_StgFunInfoExtraFwd :: Int
+sIZEOF_StgFunInfoExtraFwd = 32
+oFFSET_StgFunInfoExtraFwd_slow_apply :: Int
+oFFSET_StgFunInfoExtraFwd_slow_apply = 24
+#define StgFunInfoExtraFwd_slow_apply(__ptr__)  REP_StgFunInfoExtraFwd_slow_apply[__ptr__+OFFSET_StgFunInfoExtraFwd_slow_apply]
+oFFSET_StgFunInfoExtraFwd_fun_type :: Int
+oFFSET_StgFunInfoExtraFwd_fun_type = 0
+#define StgFunInfoExtraFwd_fun_type(__ptr__)  REP_StgFunInfoExtraFwd_fun_type[__ptr__+OFFSET_StgFunInfoExtraFwd_fun_type]
+oFFSET_StgFunInfoExtraFwd_arity :: Int
+oFFSET_StgFunInfoExtraFwd_arity = 4
+#define StgFunInfoExtraFwd_arity(__ptr__)  REP_StgFunInfoExtraFwd_arity[__ptr__+OFFSET_StgFunInfoExtraFwd_arity]
+oFFSET_StgFunInfoExtraFwd_bitmap :: Int
+oFFSET_StgFunInfoExtraFwd_bitmap = 16
+#define StgFunInfoExtraFwd_bitmap(__ptr__)  REP_StgFunInfoExtraFwd_bitmap[__ptr__+OFFSET_StgFunInfoExtraFwd_bitmap]
+sIZEOF_StgFunInfoExtraRev :: Int
+sIZEOF_StgFunInfoExtraRev = 32
+oFFSET_StgFunInfoExtraRev_slow_apply_offset :: Int
+oFFSET_StgFunInfoExtraRev_slow_apply_offset = 0
+#define StgFunInfoExtraRev_slow_apply_offset(__ptr__)  REP_StgFunInfoExtraRev_slow_apply_offset[__ptr__+OFFSET_StgFunInfoExtraRev_slow_apply_offset]
+oFFSET_StgFunInfoExtraRev_fun_type :: Int
+oFFSET_StgFunInfoExtraRev_fun_type = 24
+#define StgFunInfoExtraRev_fun_type(__ptr__)  REP_StgFunInfoExtraRev_fun_type[__ptr__+OFFSET_StgFunInfoExtraRev_fun_type]
+oFFSET_StgFunInfoExtraRev_arity :: Int
+oFFSET_StgFunInfoExtraRev_arity = 28
+#define StgFunInfoExtraRev_arity(__ptr__)  REP_StgFunInfoExtraRev_arity[__ptr__+OFFSET_StgFunInfoExtraRev_arity]
+oFFSET_StgFunInfoExtraRev_bitmap :: Int
+oFFSET_StgFunInfoExtraRev_bitmap = 8
+#define StgFunInfoExtraRev_bitmap(__ptr__)  REP_StgFunInfoExtraRev_bitmap[__ptr__+OFFSET_StgFunInfoExtraRev_bitmap]
+oFFSET_StgLargeBitmap_size :: Int
+oFFSET_StgLargeBitmap_size = 0
+#define StgLargeBitmap_size(__ptr__)  REP_StgLargeBitmap_size[__ptr__+OFFSET_StgLargeBitmap_size]
+oFFSET_StgLargeBitmap_bitmap :: Int
+oFFSET_StgLargeBitmap_bitmap = 8
+sIZEOF_snEntry :: Int
+sIZEOF_snEntry = 32
+oFFSET_snEntry_sn_obj :: Int
+oFFSET_snEntry_sn_obj = 24
+#define snEntry_sn_obj(__ptr__)  REP_snEntry_sn_obj[__ptr__+OFFSET_snEntry_sn_obj]
+oFFSET_snEntry_addr :: Int
+oFFSET_snEntry_addr = 0
+#define snEntry_addr(__ptr__)  REP_snEntry_addr[__ptr__+OFFSET_snEntry_addr]
diff -rN -u old-ghc_bf/includes/ghc.mk new-ghc_bf-2/includes/ghc.mk
--- old-ghc_bf/includes/ghc.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/includes/ghc.mk	2010-08-11 16:01:46.000000000 +0100
@@ -126,6 +126,9 @@
 
 includes_dist-derivedconstants_C_SRCS = mkDerivedConstants.c
 includes_dist-derivedconstants_PROG   = mkDerivedConstants$(exeext)
+ifeq "$(HOSTPLATFORM)" "x86_64-unknown-barrelfish"
+includes_dist-derivedconstants_LD_OPTS = -lbarrelfish -lc 
+endif
 
 $(eval $(call build-prog,includes,dist-derivedconstants,1))
 
@@ -133,9 +136,14 @@
 includes/dist-derivedconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
 
 ifneq "$(BINDIST)" "YES"
+ifeq "$(HOSTPLATFORM)" "x86_64-unknown-barrelfish"
+$(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext)	
+	$(if $(includes_DERIVEDCONSTANTS),touch $(includes_DERIVEDCONSTANTS), @echo "Compiling for Barrelfish - please run mkDerivedConstants in Barrelfish and copy result to includes/DerivedConstants.h"; @exit 1)
+else
 $(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext)
 	./$< >$@
 endif
+endif
 
 endif
 
@@ -155,6 +163,9 @@
 includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
 includes_dist-ghcconstants_PROG   = mkGHCConstants$(exeext)
 includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL
+ifeq "$(HOSTPLATFORM)" "x86_64-unknown-barrelfish"
+includes_dist-ghcconstants_LD_OPTS = -lbarrelfish -lc 
+endif
 
 $(eval $(call build-prog,includes,dist-ghcconstants,1))
 
@@ -163,9 +174,14 @@
 
 includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
 
+ifeq "$(HOSTPLATFORM)" "x86_64-unknown-barrelfish"
+$(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext)	
+	$(if $(includes_GHCCONSTANTS), touch $(includes_GHCCONSTANTS), @echo "Compiling for Barrelfish - please run mkGHCConstants in Barrelfish and copy result to includes/GHCConstants.h"; @exit 1)
+else
 $(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext)
 	./$< >$@
 endif
+endif
 
 endif
 
diff -rN -u old-ghc_bf/includes/rts/Config.h new-ghc_bf-2/includes/rts/Config.h
--- old-ghc_bf/includes/rts/Config.h	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/includes/rts/Config.h	2010-08-11 16:01:46.000000000 +0100
@@ -38,7 +38,9 @@
    Signals - supported on non-PAR versions of the runtime.  See RtsSignals.h.
    -------------------------------------------------------------------------- */
 
+#ifndef BARRELFISH
 #define RTS_USER_SIGNALS 1
+#endif
 
 /* Profile spin locks */
 
diff -rN -u old-ghc_bf/includes/rts/FileLock.h new-ghc_bf-2/includes/rts/FileLock.h
--- old-ghc_bf/includes/rts/FileLock.h	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/includes/rts/FileLock.h	2010-08-11 16:01:46.000000000 +0100
@@ -18,7 +18,11 @@
 #include <sys/types.h>
 #endif
 
+#ifndef barrelfish_HOST_OS
+
 int  lockFile(int fd, dev_t dev, ino_t ino, int for_writing);
 int  unlockFile(int fd);
 
+#endif
+
 #endif /* RTS_FILELOCK_H */
diff -rN -u old-ghc_bf/includes/rts/OSThreads.h new-ghc_bf-2/includes/rts/OSThreads.h
--- old-ghc_bf/includes/rts/OSThreads.h	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/includes/rts/OSThreads.h	2010-08-11 16:01:46.000000000 +0100
@@ -17,7 +17,53 @@
 
 #if defined(THREADED_RTS) /* to the end */
 
-# if defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS)
+# if defined(barrelfish_HOST_OS)
+
+#if CMINUSMINUS
+
+#define ACQUIRE_LOCK(mutex) foreign "C" thread_mutex_lock(mutex)
+#define RELEASE_LOCK(mutex) foreign "C" thread_mutex_unlock(mutex)
+#define ASSERT_LOCK_HELD(mutex) /* nothing */
+
+#else
+
+#include <barrelfish/barrelfish.h>
+#include <barrelfish/threads.h>
+#include <errno.h>
+
+typedef struct thread_cond    Condition;
+typedef struct thread_mutex   Mutex;
+typedef struct thread *       OSThreadId;
+typedef int                   ThreadLocalKey;
+
+#define OSThreadProcAttr /* nothing */
+
+#define OSThreadNullId NULL
+
+#define INIT_COND_VAR       THREAD_COND_INITIALIZER
+
+#ifdef LOCK_DEBUG
+#define LOCK_DEBUG_BELCH(what, mutex) \
+  debugBelch("%s(0x%p) %s %d\n", what, mutex, __FILE__, __LINE__)
+#else
+#define LOCK_DEBUG_BELCH(what, mutex) /* nothing */
+#endif
+
+/* Always check the result of lock and unlock. */
+#define ACQUIRE_LOCK(mutex) \
+  LOCK_DEBUG_BELCH("ACQUIRE_LOCK", mutex); \
+  thread_mutex_lock(mutex)
+
+#define RELEASE_LOCK(mutex) \
+  LOCK_DEBUG_BELCH("RELEASE_LOCK", mutex); \
+  thread_mutex_unlock(mutex)
+
+// Can't do this yet as pthreads in BF don't return anything yet
+#define ASSERT_LOCK_HELD(mutex) 
+
+#endif // CMINUSMINUS
+
+# elif defined(HAVE_PTHREAD_H) && !defined(WANT_NATIVE_WIN32_THREADS)
 
 #if CMINUSMINUS
 
@@ -37,6 +83,8 @@
 
 #define OSThreadProcAttr /* nothing */
 
+#define OSThreadNullId 0
+
 #define INIT_COND_VAR       PTHREAD_COND_INITIALIZER
 
 #ifdef LOCK_DEBUG
@@ -59,12 +107,7 @@
     barf("RELEASE_LOCK: I do not own this lock: %s %d", __FILE__,__LINE__); \
   }
 
-// Note: this assertion calls pthread_mutex_lock() on a mutex that
-// is already held by the calling thread.  The mutex should therefore
-// have been created with PTHREAD_MUTEX_ERRORCHECK, otherwise this
-// assertion will hang.  We always initialise mutexes with
-// PTHREAD_MUTEX_ERRORCHECK when DEBUG is on (see rts/posix/OSThreads.h).
-#define ASSERT_LOCK_HELD(mutex) ASSERT(pthread_mutex_lock(mutex) == EDEADLK)
+#define ASSERT_LOCK_HELD(mutex) /* can't do this on barrelfish yet */
 
 #endif // CMINUSMINUS
 
@@ -91,6 +134,8 @@
 
 #define OSThreadProcAttr __stdcall
 
+#define OSThreadNullId 
+
 #define INIT_COND_VAR  0
 
 // We have a choice for implementing Mutexes on Windows.  Standard
diff -rN -u old-ghc_bf/includes/Rts.h new-ghc_bf-2/includes/Rts.h
--- old-ghc_bf/includes/Rts.h	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/includes/Rts.h	2010-08-11 16:01:46.000000000 +0100
@@ -223,7 +223,7 @@
 
 void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
 
-#ifndef mingw32_HOST_OS
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 int stg_sig_install (int, int, void *);
 #endif
 
diff -rN -u old-ghc_bf/libffi/bfish.patch new-ghc_bf-2/libffi/bfish.patch
--- old-ghc_bf/libffi/bfish.patch	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/libffi/bfish.patch	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,108 @@
+diff -Nur build_old/src/closures.c build/src/closures.c
+--- build_old/src/closures.c	2010-08-03 11:41:04.924917426 +0100
++++ build/src/closures.c	2010-08-03 12:33:32.397267337 +0100
+@@ -99,14 +100,16 @@
+ 
+ #include <sys/types.h>
+ #include <sys/stat.h>
++#ifndef BARRELFISH
+ #include <fcntl.h>
++#endif
+ #include <errno.h>
+ #ifndef _MSC_VER
+ #include <unistd.h>
+ #endif
+ #include <string.h>
+ #include <stdio.h>
+-#if !defined(X86_WIN32) && !defined(X86_WIN64)
++#if !defined(X86_WIN32) && !defined(X86_WIN64) && !defined(BARRELFISH)
+ #ifdef HAVE_MNTENT
+ #include <mntent.h>
+ #endif /* HAVE_MNTENT */
+@@ -116,6 +119,7 @@
+ /* We don't want sys/mman.h to be included after we redefine mmap and
+    dlmunmap.  */
+ #include <sys/mman.h>
++
+ #define LACKS_SYS_MMAN_H 1
+ 
+ #if FFI_MMAP_EXEC_SELINUX
+@@ -193,7 +197,7 @@
+ static size_t dlmalloc_usable_size(void*) MAYBE_UNUSED;
+ static void dlmalloc_stats(void) MAYBE_UNUSED;
+ 
+-#if !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__)
++#if !(defined(X86_WIN32) || defined(X86_WIN64) || defined(BARRELFISH)) || defined (__CYGWIN__)
+ /* Use these for mmap and munmap within dlmalloc.c.  */
+ static void *dlmmap(void *, size_t, int, int, int, off_t);
+ static int dlmunmap(void *, size_t);
+@@ -487,6 +491,9 @@
+ 	int flags, int fd, off_t offset)
+ {
+   
++#ifdef BARRELFISH
++    return NULL;
++#else
+   assert (start == NULL && length % malloc_getpagesize == 0
+ 	  && prot == (PROT_READ | PROT_WRITE)
+ 	  && flags == (MAP_PRIVATE | MAP_ANONYMOUS)
+@@ -497,6 +504,7 @@
+ #endif
+   
+   return mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
++#endif
+ }
+ 
+ #endif
+diff -Nur build_old/src/dlmalloc.c build/src/dlmalloc.c
+--- build_old/src/dlmalloc.c	2010-08-03 11:41:04.936929160 +0100
++++ build/src/dlmalloc.c	2010-08-03 12:20:30.873310373 +0100
+@@ -459,6 +459,18 @@
+ #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
+ #endif  /* WIN32 */
+ 
++#ifdef BARRELFISH
++#define HAVE_MMAP 0
++#define HAVE_MORECORE 1
++#define LACKS_UNISTD_H
++#define LACKS_SYS_PARAM_H
++#define LACKS_SYS_MMAN_H
++#define LACKS_STRING_H
++#define LACKS_STRINGS_H
++#define LACKS_SYS_TYPES_H
++#define LACKS_ERRNO_H
++#endif
++
+ #if defined(DARWIN) || defined(_DARWIN)
+ /* Mac OSX docs advise not to use sbrk; it seems better to use mmap */
+ #ifndef HAVE_MORECORE
+@@ -1387,7 +1399,28 @@
+     unique mparams values are initialized only once.
+ */
+ 
+-#ifndef WIN32
++#ifdef BARRELFISH
++#include <barrelfish/barrelfish.h>
++#define MLOCK_T struct thread_mutex
++static inline int thread_mutex_lock_wrapper(struct thread_mutex* l) {
++    thread_mutex_lock(l);
++    return 0;
++}
++static inline int thread_mutex_unlock_wrapper(struct thread_mutex* l) {
++    thread_mutex_unlock(l);
++    return 0;
++}
++#define INITIAL_LOCK(l)      thread_mutex_init(l)
++#define ACQUIRE_LOCK(l)      thread_mutex_lock_wrapper(l)
++#define RELEASE_LOCK(l)      thread_mutex_unlock_wrapper(l)
++
++#if HAVE_MORECORE
++static MLOCK_T morecore_mutex = THREAD_MUTEX_INITIALIZER;
++#endif /* HAVE_MORECORE */
++
++static MLOCK_T magic_init_mutex = THREAD_MUTEX_INITIALIZER;
++
++#elif !defined(WIN32)
+ /* By default use posix locks */
+ #include <pthread.h>
+ #define MLOCK_T pthread_mutex_t
diff -rN -u old-ghc_bf/libffi/ghc.mk new-ghc_bf-2/libffi/ghc.mk
--- old-ghc_bf/libffi/ghc.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/libffi/ghc.mk	2010-08-11 16:01:46.000000000 +0100
@@ -34,7 +34,8 @@
 #
 # We use libffi's own configuration stuff.
 
-PLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
+FFI_BUILDPLATFORM := $(shell echo $(BUILDPLATFORM) | sed 's/i[567]86/i486/g')
+FFI_HOSTPLATFORM := $(shell echo $(HOSTPLATFORM) | sed 's/i[567]86/i486/g')
 
 # 2007-07-05
 # Passing
@@ -105,6 +106,10 @@
 	cat ghc-tarballs/libffi/libffi*.tar.gz | $(GZIP_CMD) -d | { cd libffi && $(TAR_CMD) -xf - ; }
 	mv libffi/libffi-* libffi/build
 	chmod +x libffi/ln
+ifeq "$(HostOS_CPP)" "barrelfish"
+	cp config.sub libffi/build/config.sub
+	(cd libffi; patch -p0  < bfish.patch)
+endif
 
 # Because -Werror may be in SRC_CC_OPTS/SRC_LD_OPTS, we need to turn
 # warnings off or the compilation of libffi might fail due to warnings
@@ -116,12 +121,12 @@
 	    LD=$(LD) \
 	    AR=$(AR) \
 	    NM=$(NM) \
-        CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS) -w" \
-        LDFLAGS="$(SRC_LD_OPTS) $(CONF_LD_OPTS) -w" \
+        CFLAGS="$(SRC_CC_OPTS) $(CONF_CC_OPTS) $(STAGE_1_CC_OPTS)  -w" \
+        LDFLAGS="$(SRC_LD_OPTS) $(CONF_LD_OPTS) $(LIBFFI_LD_OPTS) -w" \
         "$(SHELL)" configure \
 	          --enable-static=yes \
-	          --enable-shared=$(libffi_EnableShared) \
-	          --host=$(PLATFORM) --build=$(PLATFORM)
+	          --enable-shared=no \
+	          --host=$(FFI_HOSTPLATFORM) --build=$(FFI_BUILDPLATFORM)
 
 	# libffi.so needs to be built with the correct soname.
 	# NOTE: this builds libffi_convience.so with the incorrect
diff -rN -u old-ghc_bf/mk/build.mk.bf new-ghc_bf-2/mk/build.mk.bf
--- old-ghc_bf/mk/build.mk.bf	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/mk/build.mk.bf	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,49 @@
+# -----------------------------------------------------------------------------
+# A Sample build.mk
+#
+# Uncomment one of the following BuildFlavour settings to get the desired
+# overall build type, and then tweak the options in the relevant section
+# below.
+
+# Uncomment one of these to select a build profile below:
+
+# Fast build with barrelfish support
+BuildFlavour = bf
+
+
+# -------- A Fast build with optimised libs ----------------------------------
+
+ifeq "$(BuildFlavour)" "bf"
+
+# TODO - Not hard code these...
+BF_ROOT            = ${HOME}/barrelfish.ghc/
+BF_BUILD_DIR       = ${BF_ROOT}/build/x86_64/
+
+STAGE_1_CC_OPTS    = -fno-builtin -nostdinc -m64 -mno-red-zone -fPIE -fno-stack-protector -U__linux__ -imacros ${BF_ROOT}/include/deputy/nodeputy.h -DBARRELFISH -DMAX_CPUS=64 -DCONFIG_INTERCONNECT_DRIVER_LMP -DCONFIG_INTERCONNECT_DRIVER_UMP -DCONFIG_FLOUNDER_BACKEND_LMP -DCONFIG_FLOUNDER_BACKEND_UMP -g  -I${BF_ROOT}/include -I${BF_ROOT}/include/arch/x86_64 -I${BF_BUILD_DIR}/include
+STAGE_2_CC_OPTS    = ${STAGE_1_CC_OPTS}
+
+STAGE_1_LD_OPTS    = -static ${BF_BUILD_DIR}/lib/crt0.o  ${BF_BUILD_DIR}/errors/errno.o -Wl,-section-start,.data.rel.ro=0x800000 -Wl,-z,max-page-size=0x1000 -fno-builtin -nostdlib -m64 -L${BF_BUILD_DIR}/lib/ -Wl,--start-group -lmsun -lposixcompat -lvfs -lnfs -llwip -ltimer -lbarrelfish -lc
+#endif 
+STAGE_2_LD_OPTS    = ${STAGE_1_LD_OPTS}
+
+LIBFFI_LD_OPTS     = -static -Wl,-section-start,.data.rel.ro=0x800000 -Wl,-z,max-page-size=0x1000 -fno-builtin -nostdlib -m64 -L${BF_BUILD_DIR}/lib/ -lbarrelfish -lc
+
+BUILTIN_HC_OPTS    = $(addprefix -optc, $(STAGE_1_CC_OPTS)) $(addprefix -optl, $(STAGE_1_LD_OPTS)) -opta-m64
+
+SRC_HC_OPTS        = -H64m -O0 -fasm
+GhcStage1HcOpts    = -O -fasm
+GhcLibHcOpts       = -O -fasm
+GhcLibWays         = v
+GhcRTSWays         = v thr
+SplitObjs          = NO
+HADDOCK_DOCS       = NO
+BUILD_DOCBOOK_HTML = NO
+BUILD_DOCBOOK_PS   = NO
+BUILD_DOCBOOK_PDF  = NO
+INTEGER_LIBRARY    = integer-simple
+
+endif
+
+# NoFib settings
+NoFibWays =
+STRIP_CMD = :
diff -rN -u old-ghc_bf/mk/project.mk.in new-ghc_bf-2/mk/project.mk.in
--- old-ghc_bf/mk/project.mk.in	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/mk/project.mk.in	2010-08-11 16:01:46.000000000 +0100
@@ -135,3 +135,9 @@
 Windows=NO
 endif
 
+ifneq "$(findstring $(HostOS_CPP), barrelfish)" ""
+Barrelfish=YES
+else
+Barrelfish=NO
+endif
+
diff -rN -u old-ghc_bf/rts/barrelfish/GetTime.c new-ghc_bf-2/rts/barrelfish/GetTime.c
--- old-ghc_bf/rts/barrelfish/GetTime.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/GetTime.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,42 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team 2005
+ *
+ * Machine-dependent time measurement functions
+ *
+ * ---------------------------------------------------------------------------*/
+
+// Not POSIX, due to use of ru_majflt in getPageFaults()
+// #include "PosixSource.h"
+
+#include "Rts.h"
+#include "GetTime.h"
+
+Ticks getProcessCPUTime(void)
+{
+    printf("NYI getProcessCPUTime\n");
+    return -1;
+}
+
+Ticks getProcessElapsedTime(void)
+{
+    printf("NYI getProcessElapsedTime\n");
+    return -1;
+}
+
+void getProcessTimes(Ticks *user, Ticks *elapsed)
+{
+    *user    = getProcessCPUTime();
+    *elapsed = getProcessElapsedTime();
+}
+
+Ticks getThreadCPUTime(void)
+{
+    return getProcessCPUTime();
+}
+nat
+getPageFaults(void)
+{
+    return 0;
+}
+
diff -rN -u old-ghc_bf/rts/barrelfish/Itimer.c new-ghc_bf-2/rts/barrelfish/Itimer.c
--- old-ghc_bf/rts/barrelfish/Itimer.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/Itimer.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,34 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1995-2007
+ *
+ * Interval timer for profiling and pre-emptive scheduling.
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "Rts.h"
+
+#include "Ticker.h"
+
+/* TODO */
+
+void
+initTicker (nat ms, TickProc handle_tick)
+{
+}
+
+void
+startTicker(void)
+{
+}
+
+void
+stopTicker(void)
+{
+}
+
+void
+exitTicker (rtsBool wait STG_UNUSED)
+{
+}
+
diff -rN -u old-ghc_bf/rts/barrelfish/OSMem.c new-ghc_bf-2/rts/barrelfish/OSMem.c
--- old-ghc_bf/rts/barrelfish/OSMem.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/OSMem.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,223 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The University of Glasgow 2006-2007
+ *
+ * OS-specific memory management
+ *
+ * ---------------------------------------------------------------------------*/
+
+// This is non-posix compliant.
+// #include "PosixSource.h"
+
+#include "Rts.h"
+#include "barrelfish/barrelfish.h"
+
+#include "RtsUtils.h"
+#include "sm/OSMem.h"
+
+#include <errno.h>
+
+#define MAP_FLAGS VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_EXECUTE
+
+/* alloc_rec keeps the info we need to have matching mmap and unmap calls. */
+typedef struct alloc_rec_ {
+    char* base;     /* non-aligned base address, directly from mmap */
+    int size;       /* Size in bytes */
+    struct alloc_rec_* next;
+} alloc_rec;
+
+typedef struct block_rec_ {
+    char* base;         /* base address, non-MBLOCK-aligned */
+    int size;           /* size in bytes */
+    struct block_rec_* next;
+} block_rec;
+
+static alloc_rec* allocs = NULL;
+static block_rec* free_blocks = NULL;
+
+void
+osMemInit(void)
+{
+    allocs = NULL;
+    free_blocks = NULL;
+}
+
+static
+alloc_rec*
+allocNew(nat n) {
+    alloc_rec* rec;
+    rec = (alloc_rec*)stgMallocBytes(sizeof(alloc_rec),"getMBlocks: allocNew");
+    rec->size = (n+1)*MBLOCK_SIZE;
+    struct capref frame;
+
+    errval_t err = frame_alloc(&frame, rec->size, NULL);
+    if(err_is_fail(err)) {
+        DEBUG_ERR(err, "OS_Mem, frame create");
+        exit(-1);
+    }
+
+    struct memobj * memobj;
+    struct vregion * vregion;
+    err = vspace_map_one_frame_attr(
+                                    (void **)&rec->base, rec->size, frame,
+                        MAP_FLAGS, &memobj, &vregion);
+    if(err_is_fail(err) || rec->base==0) {
+        stgFree((void*)rec);
+        rec=0;
+        DEBUG_ERR(err, "OS_Mem, map one frame");
+        errorBelch("vspace_map_one_frame failed");
+    } else {
+        alloc_rec temp;
+        temp.base=0; temp.size=0; temp.next=allocs;
+
+        alloc_rec* it;
+        it=&temp;
+        for(; it->next!=0 && it->next->base<rec->base; it=it->next) ;
+        rec->next=it->next;
+        it->next=rec;
+        allocs=temp.next;
+    }
+    return rec;
+}
+
+static
+void
+insertFree(char* alloc_base, int alloc_size) {
+    block_rec temp;
+    block_rec* it;
+    block_rec* prev;
+
+    temp.base=0; temp.size=0; temp.next=free_blocks;
+    it = free_blocks;
+    prev = &temp;
+    for( ; it!=0 && it->base<alloc_base; prev=it, it=it->next) {}
+
+    if(it!=0 && alloc_base+alloc_size == it->base) {
+        if(prev->base + prev->size == alloc_base) {        /* Merge it, alloc, prev */
+            prev->size += alloc_size + it->size;
+            prev->next = it->next;
+            stgFree(it);
+        } else {                                            /* Merge it, alloc */
+            it->base = alloc_base;
+            it->size += alloc_size;
+        }
+    } else if(prev->base + prev->size == alloc_base) {     /* Merge alloc, prev */
+        prev->size += alloc_size;
+    } else {                                                /* Merge none */
+        block_rec* rec;
+        rec = (block_rec*)stgMallocBytes(sizeof(block_rec),"getMBlocks: insertFree");
+        rec->base=alloc_base;
+        rec->size=alloc_size;
+        rec->next = it;
+        prev->next=rec;
+    }
+    free_blocks=temp.next;
+}
+
+static
+void*
+findFreeBlocks(nat n) {
+    void* ret=0;
+    block_rec* it;
+    block_rec temp;
+    block_rec* prev;
+
+    int required_size;
+    it=free_blocks;
+    required_size = n*MBLOCK_SIZE;
+    temp.next=free_blocks; temp.base=0; temp.size=0;
+    prev=&temp;
+    /* TODO: Don't just take first block, find smallest sufficient block */
+    for( ; it!=0 && it->size<required_size; prev=it, it=it->next ) {}
+    if(it!=0) {
+        if( (((unsigned long)it->base) & MBLOCK_MASK) == 0) { /* MBlock aligned */
+            ret = (void*)it->base;
+            if(it->size==required_size) {
+                prev->next=it->next;
+                stgFree(it);
+            } else {
+                it->base += required_size;
+                it->size -=required_size;
+            }
+        } else {
+            char* need_base;
+            block_rec* next;
+            int new_size;
+            need_base = (char*)(((unsigned long)it->base) & ((unsigned long)~MBLOCK_MASK)) + MBLOCK_SIZE;
+            next = (block_rec*)stgMallocBytes(
+                    sizeof(block_rec)
+                    , "getMBlocks: findFreeBlocks: splitting");
+            new_size = need_base - it->base;
+            next->base = need_base +required_size;
+            next->size = it->size - (new_size+required_size);
+            it->size = new_size;
+            next->next = it->next;
+            it->next = next;
+            ret=(void*)need_base;
+        }
+    }
+    free_blocks=temp.next;
+    return ret;
+}
+
+void *
+osGetMBlocks(nat n) {
+    void* ret;
+    ret = findFreeBlocks(n);
+    if(ret==0) {
+        alloc_rec* alloc;
+        alloc = allocNew(n);
+        /* We already belch in allocNew if it fails */
+	if (alloc == 0) {
+	    stg_exit(EXIT_FAILURE);
+	} else {
+            insertFree(alloc->base, alloc->size);
+            ret = findFreeBlocks(n);
+	}
+    }
+
+    return ret;
+}
+
+void
+osFreeAllMBlocks(void)
+{
+    {
+        block_rec* next;
+        block_rec* it;
+        next=0;
+        it = free_blocks;
+        for(; it!=0; ) {
+            next = it->next;
+            stgFree(it);
+            it=next;
+        }
+    }
+    {
+        alloc_rec* next;
+        alloc_rec* it;
+        next=0;
+        it=allocs;
+        for(; it!=0; ) {
+            if(err_is_fail(vspace_unmap((void*)it->base))) {
+                sysErrorBelch("freeAllMBlocks: vspace_unmap failed");
+		stg_exit(EXIT_FAILURE);
+            }
+            next = it->next;
+            stgFree(it);
+            it=next;
+        }
+    }
+}
+
+lnat getPageSize (void)
+{
+    return BASE_PAGE_SIZE;
+}
+
+void setExecutable (void *p, lnat len, rtsBool exec)
+{
+    // TODO - at the moment we just map all memory as executable, once
+    // we can do the equivalent of mprotect in barrelfish we should 
+    // revisit this
+}
diff -rN -u old-ghc_bf/rts/barrelfish/OSThreads.c new-ghc_bf-2/rts/barrelfish/OSThreads.c
--- old-ghc_bf/rts/barrelfish/OSThreads.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/OSThreads.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,173 @@
+/* ---------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 2001-2005
+ *
+ * Accessing OS threads functionality in a (mostly) OS-independent
+ * manner. 
+ *
+ * --------------------------------------------------------------------------*/
+
+#include "PosixSource.h"
+#include "Rts.h"
+
+#if defined(THREADED_RTS)
+#include "barrelfish/barrelfish.h"
+
+void
+initCondition( Condition* pCond )
+{
+  thread_cond_init(pCond);
+  return;
+}
+
+void
+closeCondition( Condition* pCond )
+{
+  // TODO what do we do here?
+  return;
+}
+
+rtsBool
+broadcastCondition ( Condition* pCond )
+{
+  thread_cond_broadcast(pCond);
+  return true;
+}
+
+rtsBool
+signalCondition ( Condition* pCond )
+{
+  thread_cond_signal(pCond);
+  return true;
+}
+
+rtsBool
+waitCondition ( Condition* pCond, Mutex* pMut )
+{
+    thread_cond_wait(pCond, pMut);
+  return true;
+}
+
+void
+yieldThread()
+{
+  thread_yield();
+  return;
+}
+
+void
+shutdownThread()
+{
+  thread_exit();
+}
+
+int
+createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
+{
+  printf("Creating Thread\n");
+  *pId = thread_create(startProc, param);  // TODO - start on right core!!
+  return 0;
+}
+
+OSThreadId
+osThreadId()
+{
+  return thread_self();
+}
+
+rtsBool
+osThreadIsAlive(OSThreadId id STG_UNUSED)
+{
+    // no good way to implement this on POSIX, AFAICT.  Returning true
+    // is safe.
+    return true;
+}
+
+void
+initMutex(Mutex* pMut)
+{
+    thread_mutex_init(pMut);
+    return;
+}
+void
+closeMutex(Mutex* pMut)
+{
+    // how do we do this?
+}
+
+void
+newThreadLocalKey (ThreadLocalKey *key)
+{
+    static int curr_key = 1;
+    *key = curr_key++; 
+}
+
+void *
+getThreadLocalVar (ThreadLocalKey *key)
+{
+    if (*key != 1) printf("Error, invalid thread local key\n");
+    return thread_self()->tls;
+}
+
+void
+setThreadLocalVar (ThreadLocalKey *key, void *value)
+{
+    if (*key != 1) printf("Error, invalid thread local key\n");
+    thread_self()->tls = value;
+}
+
+void
+freeThreadLocalKey (ThreadLocalKey *key)
+{
+    // TODO
+}
+
+int
+forkOS_createThread ( HsStablePtr entry )
+{
+    printf("NYI forkOS_createThread\n");
+    exit(-1);
+}
+
+nat
+getNumberOfProcessors (void)
+{
+    static nat nproc = 0;
+
+    if (nproc == 0) {
+        // todo - move num_cores request to a blocking rpc
+        printf("NYI getNumberOfProcessors\n");
+        exit(-1);
+    }
+
+    return nproc;
+}
+
+#if defined(HAVE_SCHED_SETAFFINITY)
+// Schedules the thread to run on CPU n of m.  m may be less than the
+// number of physical CPUs, in which case, the thread will be allowed
+// to run on CPU n, n+m, n+2m etc.
+void
+setThreadAffinity (nat n, nat m)
+{
+    printf("NYI setThreadAffinity\n");
+    exit(-1);
+}
+
+#else
+void
+setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__), 
+		   nat m GNUC3_ATTRIBUTE(__unused__))
+{
+}
+#endif
+
+#else /* !defined(THREADED_RTS) */
+
+int
+forkOS_createThread ( HsStablePtr entry STG_UNUSED )
+{
+    return -1;
+}
+
+#endif /* !defined(THREADED_RTS) */
diff -rN -u old-ghc_bf/rts/barrelfish/Select.c new-ghc_bf-2/rts/barrelfish/Select.c
--- old-ghc_bf/rts/barrelfish/Select.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/Select.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,21 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team 1995-2002
+ *
+ * Support for concurrent non-blocking I/O and thread waiting.
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "Rts.h"
+
+#if !defined(THREADED_RTS)
+
+
+
+void
+awaitEvent(rtsBool wait)
+{
+    printf("NYI awateEvent\n");
+}
+
+#endif /* THREADED_RTS */
diff -rN -u old-ghc_bf/rts/barrelfish/Select.h new-ghc_bf-2/rts/barrelfish/Select.h
--- old-ghc_bf/rts/barrelfish/Select.h	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/Select.h	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,17 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team 1998-2005
+ *
+ * Prototypes for functions in Select.c
+ *
+ * -------------------------------------------------------------------------*/
+
+#ifndef POSIX_SELECT_H
+#define POSIX_SELECT_H
+
+#if !defined(THREADED_RTS)
+/* In Select.c */
+extern lnat timestamp;
+#endif
+
+#endif /* POSIX_SELECT_H */
diff -rN -u old-ghc_bf/rts/barrelfish/Signals.c new-ghc_bf-2/rts/barrelfish/Signals.c
--- old-ghc_bf/rts/barrelfish/Signals.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/Signals.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,167 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2005
+ *
+ * Signal processing / handling.
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "PosixSource.h" 
+#include "Rts.h"
+
+#include "Schedule.h"
+#include "RtsSignals.h"
+#include "Signals.h"
+#include "RtsUtils.h"
+#include "Prelude.h"
+#include "Stable.h"
+
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+# include <errno.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+
+static void
+more_handlers(int sig)
+{
+    printf("NYI more_handlers\n");
+    exit(-1);
+}
+
+void
+setIOManagerPipe (int fd)
+{
+    printf("NYI setIOManagerPipe\n");
+    exit(-1);
+}
+
+void
+ioManagerWakeup (void)
+{
+    printf("NYI ioManagerWakeup\n");
+    exit(-1);
+}
+
+void
+ioManagerSync (void)
+{
+    printf("NYI ioManagerSync\n");
+    exit(-1);
+}
+
+#if defined(THREADED_RTS)
+void
+ioManagerDie (void)
+{
+    printf("NYI ioManagerDie\n");
+    exit(-1);
+}
+
+Capability *
+ioManagerStartCap (Capability *cap)
+{
+    return rts_evalIO(cap,&base_GHCziConc_ensureIOManagerIsRunning_closure,NULL);
+}
+
+void
+ioManagerStart (void)
+{
+    // Make sure the IO manager thread is running
+    Capability *cap;
+    cap = rts_lock();
+    cap = ioManagerStartCap(cap);
+    rts_unlock(cap);
+}
+#endif
+
+/* -----------------------------------------------------------------------------
+ * Blocking/Unblocking of the user signals
+ * -------------------------------------------------------------------------- */
+
+void
+initUserSignals(void)
+{
+    printf("NYI initUserSignals\n");
+    exit(-1);
+}
+
+void
+blockUserSignals(void)
+{
+    printf("NYI blockUserSignals\n");
+    exit(-1);
+}
+
+void
+unblockUserSignals(void)
+{
+    printf("NYI unblockUserSignals\n");
+    exit(-1);
+}
+
+rtsBool
+anyUserHandlers(void)
+{
+    printf("NYI unblockUserSignals\n");
+    exit(-1);
+}
+
+#if !defined(THREADED_RTS)
+void
+awaitUserSignals(void)
+{
+    printf("NYI awaitUserSignals\n");
+    exit(-1);
+}
+#endif
+
+/* -----------------------------------------------------------------------------
+ * Install a Haskell signal handler.
+ *
+ * We should really do this in Haskell in GHC.Conc, and share the
+ * signal_handlers array with the one there.
+ *
+ * -------------------------------------------------------------------------- */
+
+int
+stg_sig_install(int sig, int spi, void *mask)
+{
+    printf("NYI stg_sig_install\n");
+    exit(-1);
+}
+
+/* -----------------------------------------------------------------------------
+ * Creating new threads for signal handlers.
+ * -------------------------------------------------------------------------- */
+
+#if !defined(THREADED_RTS)
+void
+startSignalHandlers(Capability *cap)
+{
+    printf("NYI stg_sig_install\n");
+    exit(-1);
+}
+#endif
+
+/* ----------------------------------------------------------------------------
+ * Mark signal handlers during GC.
+ * -------------------------------------------------------------------------- */
+
+void
+markSignalHandlers (evac_fn evac STG_UNUSED, void *user STG_UNUSED)
+{
+    // nothing to do
+}
+
+void
+resetDefaultHandlers(void)
+{
+    return;
+}
diff -rN -u old-ghc_bf/rts/barrelfish/Signals.h new-ghc_bf-2/rts/barrelfish/Signals.h
--- old-ghc_bf/rts/barrelfish/Signals.h	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/Signals.h	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,27 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2005
+ *
+ * Signal processing / handling.
+ *
+ * ---------------------------------------------------------------------------*/
+
+#ifndef BFISH_SIGNALS_H
+#define BFISH_SIGNALS_H
+
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
+#include "BeginPrivate.h"
+
+rtsBool anyUserHandlers(void);
+
+Capability *ioManagerStartCap (Capability *cap);
+
+extern StgInt *signal_handlers;
+
+#include "EndPrivate.h"
+
+#endif /* BFISH_SIGNALS_H */
+
diff -rN -u old-ghc_bf/rts/barrelfish/TTY.c new-ghc_bf-2/rts/barrelfish/TTY.c
--- old-ghc_bf/rts/barrelfish/TTY.c	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/TTY.c	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,65 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2009
+ *
+ * TTY-related functionality
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "PosixSource.h"
+#include "Rts.h"
+
+#include "RtsUtils.h" // __hscore_get/set prototypes
+#include "TTY.h"
+
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+// Here we save the terminal settings on the standard file
+// descriptors, if we need to change them (eg. to support NoBuffering
+// input).
+static void *saved_termios[3] = {NULL,NULL,NULL};
+
+void*
+__hscore_get_saved_termios(int fd)
+{
+  return (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) ?
+    saved_termios[fd] : NULL;
+}
+
+void
+__hscore_set_saved_termios(int fd, void* ts)
+{
+  if (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) {
+    saved_termios[fd] = ts;
+  }
+}
+
+void
+resetTerminalSettings (void)
+{
+#if HAVE_TERMIOS_H
+    // Reset the terminal settings on the standard file descriptors,
+    // if we changed them.  See System.Posix.Internals.tcSetAttr for
+    // more details, including the reason we termporarily disable
+    // SIGTTOU here.
+    { 
+	int fd;
+	sigset_t sigset, old_sigset;
+	sigemptyset(&sigset);
+	sigaddset(&sigset, SIGTTOU);
+	sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
+	for (fd = 0; fd <= 2; fd++) {
+	    struct termios* ts = (struct termios*)__hscore_get_saved_termios(fd);
+	    if (ts != NULL) {
+		tcsetattr(fd,TCSANOW,ts);
+	    }
+	}
+	sigprocmask(SIG_SETMASK, &old_sigset, NULL);
+    }
+#endif
+}
diff -rN -u old-ghc_bf/rts/barrelfish/TTY.h new-ghc_bf-2/rts/barrelfish/TTY.h
--- old-ghc_bf/rts/barrelfish/TTY.h	1970-01-01 01:00:00.000000000 +0100
+++ new-ghc_bf-2/rts/barrelfish/TTY.h	2010-08-11 16:01:46.000000000 +0100
@@ -0,0 +1,14 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2009
+ *
+ * TTY-related functionality
+ *
+ * ---------------------------------------------------------------------------*/
+
+#ifndef POSIX_TTY_H
+#define POSIX_TTY_H
+
+RTS_PRIVATE void resetTerminalSettings (void);
+
+#endif /* POSIX_TTY_H */
diff -rN -u old-ghc_bf/rts/ghc.mk new-ghc_bf-2/rts/ghc.mk
--- old-ghc_bf/rts/ghc.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/ghc.mk	2010-08-11 16:01:46.000000000 +0100
@@ -31,9 +31,13 @@
 
 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 ALL_DIRS += win32
+else 
+ifeq "$(HOSTPLATFORM)" "x86_64-unknown-barrelfish"
+ALL_DIRS += barrelfish
 else
 ALL_DIRS += posix
 endif
+endif
 
 EXCLUDED_SRCS += rts/Main.c
 EXCLUDED_SRCS += rts/parallel/SysMan.c
@@ -274,6 +278,8 @@
 rts_CC_OPTS += -DBE_CONSERVATIVE
 endif
 
+rts_CC_OPTS += $(STAGE_1_CC_OPTS)
+
 #-----------------------------------------------------------------------------
 # Flags for compiling specific files
 
diff -rN -u old-ghc_bf/rts/Linker.c new-ghc_bf-2/rts/Linker.c
--- old-ghc_bf/rts/Linker.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/Linker.c	2010-08-11 16:01:46.000000000 +0100
@@ -29,7 +29,7 @@
 #include "StgPrimFloat.h" // for __int_encodeFloat etc.
 #include "Stable.h"
 
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 #include "posix/Signals.h"
 #endif
 
@@ -240,7 +240,7 @@
       				SymI_HasProto(stg_makeStableNamezh)		\
       				SymI_HasProto(stg_finalizzeWeakzh)
 
-#if !defined (mingw32_HOST_OS)
+#if !defined (mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 #define RTS_POSIX_ONLY_SYMBOLS                  \
       SymI_HasProto(__hscore_get_saved_termios)	\
       SymI_HasProto(__hscore_set_saved_termios)	\
@@ -339,6 +339,9 @@
 #elif !defined(mingw32_HOST_OS)
 #define RTS_MINGW_ONLY_SYMBOLS /**/
 #define RTS_CYGWIN_ONLY_SYMBOLS /**/
+#ifdef barrelfish_HOST_OS
+#define RTS_POSIX_ONLY_SYMBOLS  /**/
+#endif
 #else /* defined(mingw32_HOST_OS) */
 #define RTS_POSIX_ONLY_SYMBOLS  /**/
 #define RTS_CYGWIN_ONLY_SYMBOLS /**/
@@ -513,6 +516,9 @@
 # define MAIN_CAP_SYM
 #endif
 
+#ifndef RTS_USER_SIGNALS
+#define RTS_USER_SIGNALS_SYMBOLS /**/
+#else
 #if !defined(mingw32_HOST_OS)
 #define RTS_USER_SIGNALS_SYMBOLS \
    SymI_HasProto(setIOManagerPipe) \
@@ -528,6 +534,7 @@
    SymI_HasProto(getIOManagerEvent)  \
    SymI_HasProto(console_handler)
 #endif
+#endif
 
 #define RTS_LIBFFI_SYMBOLS                                  \
      SymE_NeedsProto(ffi_prep_cif)                          \
diff -rN -u old-ghc_bf/rts/package.conf.in new-ghc_bf-2/rts/package.conf.in
--- old-ghc_bf/rts/package.conf.in	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/package.conf.in	2010-08-11 16:01:46.000000000 +0100
@@ -24,6 +24,7 @@
 hs-libraries:   "HSrts"
 
 extra-libraries:
+#ifndef barrelfish_HOST_OS
 #ifdef HAVE_LIBM
                 		"m"		/* for ldexp() */
 #endif
@@ -47,6 +48,7 @@
 #if USE_PAPI
 			     , "papi"
 #endif
+#endif
 
 #ifdef INSTALLING
 include-dirs:		INCLUDE_DIR PAPI_INCLUDE_DIR
diff -rN -u old-ghc_bf/rts/PrimOps.cmm new-ghc_bf-2/rts/PrimOps.cmm
--- old-ghc_bf/rts/PrimOps.cmm	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/PrimOps.cmm	2010-08-11 16:01:46.000000000 +0100
@@ -1737,13 +1737,15 @@
 
 #ifdef THREADED_RTS
     foreign "C" barf("delay# on threaded RTS") never returns;
-#else
+#elif defined(barrelfish_HOST_OS)
+    foreign "C" barf("NYI delay");
+#else 
 
     /* args: R1 (microsecond delay amount) */
     ASSERT(StgTSO_why_blocked(CurrentTSO) == NotBlocked::I16);
     StgTSO_why_blocked(CurrentTSO) = BlockedOnDelay::I16;
 
-#ifdef mingw32_HOST_OS
+#if defined(mingw32_HOST_OS)
 
     /* could probably allocate this on the heap instead */
     ("ptr" ares) = foreign "C" stgMallocBytes(SIZEOF_StgAsyncIOResult,
diff -rN -u old-ghc_bf/rts/RtsSignals.h new-ghc_bf-2/rts/RtsSignals.h
--- old-ghc_bf/rts/RtsSignals.h	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/RtsSignals.h	2010-08-11 16:01:46.000000000 +0100
@@ -9,7 +9,7 @@
 #ifndef RTSSIGNALS_H
 #define RTSSIGNALS_H
 
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 
 #include "posix/Signals.h"
 
diff -rN -u old-ghc_bf/rts/RtsStartup.c new-ghc_bf-2/rts/RtsStartup.c
--- old-ghc_bf/rts/RtsStartup.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/RtsStartup.c	2010-08-11 16:01:46.000000000 +0100
@@ -49,7 +49,7 @@
 #include "win32/AsyncIO.h"
 #endif
 
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 #include "posix/TTY.h"
 #include "posix/FileLock.h"
 #endif
@@ -184,7 +184,7 @@
 
     getStablePtr((StgPtr)runSparks_closure);
     getStablePtr((StgPtr)ensureIOManagerIsRunning_closure);
-#ifndef mingw32_HOST_OS
+#if !defined(mingw32_HOST_OS) &&!defined(barrelfish_HOST_OS)
     getStablePtr((StgPtr)runHandlers_closure);
 #endif
 
@@ -192,7 +192,7 @@
     initGlobalStore();
 
     /* initialise file locking, if necessary */
-#if !defined(mingw32_HOST_OS)    
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)    
     initFileLocking();
 #endif
 
@@ -402,7 +402,7 @@
     exitLinker();
 
     /* free file locking tables, if necessary */
-#if !defined(mingw32_HOST_OS)    
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
     freeFileLocking();
 #endif
 
@@ -489,7 +489,7 @@
     }
 }
 
-#ifndef mingw32_HOST_OS
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 void
 shutdownHaskellAndSignal(int sig)
 {
diff -rN -u old-ghc_bf/rts/RtsUtils.c new-ghc_bf-2/rts/RtsUtils.c
--- old-ghc_bf/rts/RtsUtils.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/RtsUtils.c	2010-08-11 16:01:46.000000000 +0100
@@ -420,6 +420,9 @@
 int genericRaise(int sig) {
 #if defined(THREADED_RTS) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS))
         return pthread_kill(pthread_self(), sig);
+#elif defined(barrelfish_HOST_OS)
+	printf("NYI generic Raise\n");
+	return -1;
 #else
         return raise(sig);
 #endif
diff -rN -u old-ghc_bf/rts/Schedule.c new-ghc_bf-2/rts/Schedule.c
--- old-ghc_bf/rts/Schedule.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/Schedule.c	2010-08-11 16:01:46.000000000 +0100
@@ -107,7 +107,7 @@
 Mutex sched_mutex;
 #endif
 
-#if !defined(mingw32_HOST_OS)
+#if !defined(mingw32_HOST_OS) && !defined(barrelfish_HOST_OS)
 #define FORKPROCESS_PRIMOP_SUPPORTED
 #endif
 
diff -rN -u old-ghc_bf/rts/sm/GC.c new-ghc_bf-2/rts/sm/GC.c
--- old-ghc_bf/rts/sm/GC.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/sm/GC.c	2010-08-11 16:01:46.000000000 +0100
@@ -846,7 +846,7 @@
     gen_workspace *ws;
 
 #ifdef THREADED_RTS
-    t->id = 0;
+    t->id = OSThreadNullId;
     initSpinLock(&t->gc_spin);
     initSpinLock(&t->mut_spin);
     ACQUIRE_SPIN_LOCK(&t->gc_spin);
diff -rN -u old-ghc_bf/rts/Stats.c new-ghc_bf-2/rts/Stats.c
--- old-ghc_bf/rts/Stats.c	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rts/Stats.c	2010-08-11 16:01:46.000000000 +0100
@@ -208,15 +208,18 @@
 void
 stat_startInit(void)
 {
+#ifndef barrelfish_HOST_OS
     Ticks elapsed;
 
     elapsed = getProcessElapsedTime();
     ElapsedTimeStart = elapsed;
+#endif
 }
 
 void 
 stat_endInit(void)
 {
+#ifndef barrelfish_HOST_OS
     Ticks user, elapsed;
 
     getProcessTimes(&user, &elapsed);
@@ -238,6 +241,7 @@
     papi_is_reporting = 1;
 
 #endif
+#endif
 }
 
 /* -----------------------------------------------------------------------------
@@ -249,6 +253,7 @@
 void
 stat_startExit(void)
 {
+#ifndef barrelfish_HOST_OS
     Ticks user, elapsed;
 
     getProcessTimes(&user, &elapsed);
@@ -270,11 +275,13 @@
     papi_is_reporting = 0;
 
 #endif
+#endif
 }
 
 void
 stat_endExit(void)
 {
+#ifndef barrelfish_HOST_OS
     Ticks user, elapsed;
 
     getProcessTimes(&user, &elapsed);
@@ -287,6 +294,7 @@
     if (ExitElapsedTime < 0) {
 	ExitElapsedTime = 0;
     }
+#endif
 }
 
 /* -----------------------------------------------------------------------------
diff -rN -u old-ghc_bf/rules/build-package-data.mk new-ghc_bf-2/rules/build-package-data.mk
--- old-ghc_bf/rules/build-package-data.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rules/build-package-data.mk	2010-08-11 16:01:46.000000000 +0100
@@ -28,11 +28,15 @@
 $1_$2_CONFIGURE_OPTS += --with-hscolour="$$(HSCOLOUR_CMD)"
 endif
 
+$1_$2_CONFIGURE_OPTS += --configure-option=--build=$$(BUILDPLATFORM)
+$1_$2_CONFIGURE_OPTS += --configure-option=--host=$$(HOSTPLATFORM)
+
 # We filter out -Werror from SRC_CC_OPTS, because when configure tests
 # for a feature it may not generate warning-free C code, and thus may
 # think that the feature doesn't exist if -Werror is on.
-$1_$2_CONFIGURE_OPTS += --configure-option=CFLAGS="$$(filter-out -Werror,$$(SRC_CC_OPTS)) $$(CONF_CC_OPTS) $$($1_CC_OPTS) $$($1_$2_CC_OPTS)"
-$1_$2_CONFIGURE_OPTS += --configure-option=LDFLAGS="$$(SRC_LD_OPTS) $$($1_LD_OPTS) $$($1_$2_LD_OPTS)"
+$1_$2_CONFIGURE_OPTS += --configure-option=CFLAGS="$$(filter-out -Werror,$$(SRC_CC_OPTS)) $$(CONF_CC_OPTS) $$($1_CC_OPTS) $$($1_$2_CC_OPTS) $$(STAGE_$3_CC_OPTS)"
+$1_$2_CONFIGURE_OPTS += --configure-option=CPPFLAGS="$$(filter-out -Werror,$$(SRC_CC_OPTS)) $$(CONF_CC_OPTS) $$($1_CC_OPTS) $$($1_$2_CC_OPTS) $$(STAGE_$3_CC_OPTS)"
+$1_$2_CONFIGURE_OPTS += --configure-option=LDFLAGS="$$(SRC_LD_OPTS) $$($1_LD_OPTS) $$($1_$2_LD_OPTS) $$(STAGE_$3_LD_OPTS)"
 
 ifneq "$$(ICONV_INCLUDE_DIRS)" ""
 $1_$2_CONFIGURE_OPTS += --configure-option=--with-iconv-includes="$$(ICONV_INCLUDE_DIRS)"
diff -rN -u old-ghc_bf/rules/build-prog.mk new-ghc_bf-2/rules/build-prog.mk
--- old-ghc_bf/rules/build-prog.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rules/build-prog.mk	2010-08-11 16:01:46.000000000 +0100
@@ -128,10 +128,10 @@
 
 ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
-	"$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS)
+	"$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS)  $$(STAGE_$3_LD_OPTS) $$(LD_OPTS) $$($1_$2_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS)
 else
 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
-	"$$(CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS)
+	"$$(CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS)  $$(STAGE_$3_LD_OPTS) $$(LD_OPTS) $$($1_$2_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS)
 endif
 
 # Note [lib-depends] if this program is built with stage1 or greater, we
diff -rN -u old-ghc_bf/rules/distdir-way-opts.mk new-ghc_bf-2/rules/distdir-way-opts.mk
--- old-ghc_bf/rules/distdir-way-opts.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rules/distdir-way-opts.mk	2010-08-11 16:01:46.000000000 +0100
@@ -82,6 +82,7 @@
 endif
 
 $1_$2_DIST_CC_OPTS = \
+ $$(STAGE_$4_CC_OPTS) \
  $$(CONF_CC_OPTS) \
  $$(SRC_CC_OPTS) \
  $$($1_CC_OPTS) \
diff -rN -u old-ghc_bf/rules/shell-wrapper.mk new-ghc_bf-2/rules/shell-wrapper.mk
--- old-ghc_bf/rules/shell-wrapper.mk	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/rules/shell-wrapper.mk	2010-08-11 16:01:46.000000000 +0100
@@ -41,6 +41,7 @@
 	echo 'bindir="$$(TOP)/$$(INPLACE_BIN)"'        >> $$@
 	echo 'topdir="$$(TOP)/$$(INPLACE_TOPDIR)"'     >> $$@
 	echo 'pgmgcc="$$(WhatGccIsCalled)"'            >> $$@
+	echo 'builtInArgs="$$(BUILTIN_HC_OPTS)"'       >> $$@
 	$$($1_$2_SHELL_WRAPPER_EXTRA)
 	$$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
 	cat $$($1_$2_SHELL_WRAPPER_NAME)               >> $$@
@@ -73,6 +74,7 @@
 	echo 'bindir="$$(bindir)"'                               >> "$$(WRAPPER)"
 	echo 'topdir="$$(topdir)"'                               >> "$$(WRAPPER)"
 	echo 'pgmgcc="$$(WhatGccIsCalled)"'                      >> "$$(WRAPPER)"
+	echo 'builtInArgs="$$(BUILTIN_HC_OPTS)"'                 >> "$$(WRAPPER)"
 	$$($1_$2_SHELL_WRAPPER_EXTRA)
 	$$($1_$2_INSTALL_SHELL_WRAPPER_EXTRA)
 	cat $$($1_$2_SHELL_WRAPPER_NAME)                         >> "$$(WRAPPER)"
diff -rN -u old-ghc_bf/utils/ghc-pkg/ghc-pkg.cabal new-ghc_bf-2/utils/ghc-pkg/ghc-pkg.cabal
--- old-ghc_bf/utils/ghc-pkg/ghc-pkg.cabal	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/utils/ghc-pkg/ghc-pkg.cabal	2010-08-11 16:01:46.000000000 +0100
@@ -28,7 +28,6 @@
                    bin-package-db,
                    bytestring
     if !os(windows)
-        Build-Depends: unix,
-                       terminfo
+        Build-Depends: unix
     if os(windows)
         c-sources: CRT_noglob.c
diff -rN -u old-ghc_bf/utils/ghc-pkg/Main.hs new-ghc_bf-2/utils/ghc-pkg/Main.hs
--- old-ghc_bf/utils/ghc-pkg/Main.hs	2010-08-11 16:01:46.000000000 +0100
+++ new-ghc_bf-2/utils/ghc-pkg/Main.hs	2010-08-11 16:01:46.000000000 +0100
@@ -70,7 +70,7 @@
 import qualified System.Info(os)
 #endif
 
-#if !defined(mingw32_HOST_OS) && __GLASGOW_HASKELL__ >= 611 && !defined(BOOTSTRAPPING)
+#if !defined(mingw32_HOST_OS) &&!defined(barrelfish_HOST_OS) && __GLASGOW_HASKELL__ >= 611 && !defined(BOOTSTRAPPING)
 import System.Console.Terminfo as Terminfo
 #endif
 
@@ -854,7 +854,7 @@
 
   if simple_output then show_simple stack else do
 
-#if defined(mingw32_HOST_OS) || __GLASGOW_HASKELL__ < 611 || defined(BOOTSTRAPPING)
+#if defined(mingw32_HOST_OS) || defined(barrelfish_HOST_OS) || __GLASGOW_HASKELL__ < 611 || defined(BOOTSTRAPPING)
   mapM_ show_normal stack
 #else
   let
