From 5e663a91d873face8bd4ea78e19794366650bb05 Mon Sep 17 00:00:00 2001 From: "U-C4\\Administrator" Date: Sun, 23 Sep 2007 23:52:58 -0500 Subject: [PATCH 1/3] Try to get Windows NT bootstrapping with the latest compiler changes SEH is broken --- vm/os-windows-nt.c | 53 +++++++++++++++++++++++++++------------------- vm/os-windows.c | 8 +------ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/vm/os-windows-nt.c b/vm/os-windows-nt.c index 2a87a85223..6f816f4625 100644 --- a/vm/os-windows-nt.c +++ b/vm/os-windows-nt.c @@ -23,31 +23,40 @@ DEFINE_PRIMITIVE(cd) SetCurrentDirectory(unbox_u16_string()); } -void seh_call(void (*func)(), exception_handler_t *handler) +long exception_handler(PEXCEPTION_RECORD rec, void *frame, void *ctx, void *dispatch) +{ + CONTEXT *c = (CONTEXT*)ctx; + void *esp = NULL; + if(in_code_heap_p(c->Eip)) + esp = (void*)c->Esp; + printf("ExceptionCode = 0x%08x\n", rec->ExceptionCode); + printf("AccessViolationCode = 0x%08x\n", EXCEPTION_ACCESS_VIOLATION); + printf("DivideByZeroCode1 = 0x%08x\n", EXCEPTION_FLT_DIVIDE_BY_ZERO); + printf("DivideByZeroCode2 = 0x%08x\n", EXCEPTION_INT_DIVIDE_BY_ZERO); + printf("addr=0x%08x\n", rec->ExceptionInformation[1]); + printf("eax=0x%08x\n", c->Eax); + printf("eax=0x%08x\n", c->Ebx); + printf("eip=0x%08x\n", c->Eip); + printf("esp=0x%08x\n", c->Esp); + + printf("calculated esp: 0x%08x\n", esp); + + if(rec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) + memory_protection_error(rec->ExceptionInformation[1], esp); + else if(rec->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO + || rec->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO) + general_error(ERROR_DIVIDE_BY_ZERO,F,F,esp); + else + signal_error(11,esp); + return -1; /* unreachable */ +} + +void c_to_factor_toplevel(CELL quot) { exception_record_t record; asm volatile("mov %%fs:0, %0" : "=r" (record.next_handler)); asm volatile("mov %0, %%fs:0" : : "r" (&record)); - record.handler_func = handler; - func(); + record.handler_func = exception_handler; + c_to_factor(quot); asm volatile("mov %0, %%fs:0" : "=r" (record.next_handler)); } - -long exception_handler(PEXCEPTION_RECORD rec, void *frame, void *ctx, void *dispatch) -{ - if(rec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) - memory_protection_error( - rec->ExceptionInformation[1], - native_stack_pointer()); - else if(rec->ExceptionCode == EXCEPTION_FLT_DIVIDE_BY_ZERO - || rec->ExceptionCode == EXCEPTION_INT_DIVIDE_BY_ZERO) - general_error(ERROR_DIVIDE_BY_ZERO,F,F,false,(void*)rec->ExceptionInformation[1]); - else - signal_error(11,(void*)rec->ExceptionInformation[1]); - return -1; /* unreachable */ -} - -void run_toplevel(void) -{ - seh_call(run, exception_handler); -} diff --git a/vm/os-windows.c b/vm/os-windows.c index 823fd7e9d0..479f60a4fa 100644 --- a/vm/os-windows.c +++ b/vm/os-windows.c @@ -51,7 +51,7 @@ void ffi_dlopen (F_DLL *dll, bool error) { dll->dll = NULL; if(error) - general_error(ERROR_FFI,F, + general_error(ERROR_FFI,F,F, tag_object(get_error_message())); else return; @@ -204,9 +204,3 @@ void sleep_millis(DWORD msec) { Sleep(msec); } - -void run(void) -{ - interpreter(); -} - From 709968d7125dcd6fd8c90a775f95758023ae1b7d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 24 Sep 2007 00:02:43 -0500 Subject: [PATCH 2/3] Installer script initial checkin. Works on Mac, needs testing on cygwin and linux and other platforms --- misc/install.sh | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 misc/install.sh diff --git a/misc/install.sh b/misc/install.sh new file mode 100755 index 0000000000..e7d822f6c9 --- /dev/null +++ b/misc/install.sh @@ -0,0 +1,108 @@ +#!/bin/bash -e + +# Programs returning != 0 will not cause script to exit +set +e + +# Case insensitive string comparison +shopt -s nocaseglob + +ensure_program_installed() { + echo -n "Checking for $1..." + result=`type -p $1` + if ! [[ -n $result ]] ; then + echo "not found!" + echo "Install $1 and try again." + exit 1 + fi + echo "found!" +} + +check_ret() { + RET=$? + if [[ $RET -ne 0 ]] ; then + echo $1 failed + exit 5 + fi +} + +ensure_program_installed uname +ensure_program_installed git +ensure_program_installed wget +ensure_program_installed gcc +ensure_program_installed make + +GCC_VERSION=`gcc --version` +if [[ $GCC_VERSION == *3.3.* ]] ; then + echo "You have a known buggy version of gcc (3.3)" + echo "Install gcc 3.4 or higher and try again." + exit 1 +fi + +# OS +OS= +uname_s=`uname -s` +case $uname_s in + CYGWIN_NT-5.2-WOW64) OS=windows-nt;; + *CYGWIN_NT*) OS=windows-nt;; + *darwin*) OS=macosx;; + *linux*) OS=linux;; +esac + +# Architecture +ARCH= +uname_m=`uname -m` +case $uname_m in + i386) ARCH=x86;; + i686) ARCH=x86;; + *86) ARCH=x86;; + "Power Macintosh") ARCH=ppc;; +esac + +WORD= +C_WORD=factor-word-size +# Word size +echo "#include " > $C_WORD.c +echo "int main() { printf(\"%d\", 8*sizeof(long)); return 0; }" >> $C_WORD.c +gcc -o $C_WORD $C_WORD.c +WORD=$(./$C_WORD) +check_ret $C_WORD +rm -f $C_WORD* + +case $OS in + windows-nt) FACTOR_BINARY=factor-nt;; + macosx) FACTOR_BINARY=./Factor.app/Contents/MacOS/factor;; + *) FACTOR_BINARY=factor;; +esac + +MAKE_TARGET=$OS-$ARCH-$WORD +BOOT_IMAGE=boot.$ARCH.$WORD.image + +echo OS=$OS +echo ARCH=$ARCH +echo WORD=$WORD +echo FACTOR_BINARY=$FACTOR_BINARY +echo MAKE_TARGET=$MAKE_TARGET +echo BOOT_IMAGE=$BOOT_IMAGE + +if ! [[ -n $OS && -n $ARCH && -n $WORD ]] ; then + echo "OS, ARCH, or WORD is empty. Please report this" + exit 4 +fi + +echo "Downloading the git repository from factorcode.org..." +git clone git://factorcode.org/git/factor.git +check_ret git + +cd factor +check_ret cd + +make $MAKE_TARGET +check_ret make + +echo "Deleting old images..." +rm $BOOT_IMAGE > /dev/null 2>&1 +rm $BOOT_IMAGE.* > /dev/null 2>&1 +wget http://factorcode.org/images/latest/$BOOT_IMAGE +check_ret wget + +./$FACTOR_BINARY -i=$BOOT_IMAGE From 05dd0ce8f554cb397a9949a6361a5a1395401b2b Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 24 Sep 2007 13:22:03 -0500 Subject: [PATCH 3/3] Improve install.sh -- shopt -s nocasematch is not portable, try it and variant nocaseglob --- misc/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/install.sh b/misc/install.sh index e7d822f6c9..10c0bfc0df 100755 --- a/misc/install.sh +++ b/misc/install.sh @@ -5,6 +5,7 @@ set +e # Case insensitive string comparison shopt -s nocaseglob +shopt -s nocasematch ensure_program_installed() { echo -n "Checking for $1..." @@ -44,6 +45,7 @@ uname_s=`uname -s` case $uname_s in CYGWIN_NT-5.2-WOW64) OS=windows-nt;; *CYGWIN_NT*) OS=windows-nt;; + *CYGWIN*) OS=windows-nt;; *darwin*) OS=macosx;; *linux*) OS=linux;; esac