From: Cyrus Harmon Date: Mon, 6 Mar 2006 09:59:33 +0000 (+0000) Subject: 0.9.10.16: X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=3d2165e67f9ad1443f6e7d8ad24810000b0436e8;p=sbcl.git 0.9.10.16: x86/Darwin support ... Add Config support and ape the darwin/ppc space fixup stuff. ... Align stack to 16-bytes as per ABI in %alien-funcall, c-call and show. ... Add darwin space params. ... Use an altstack for handling signals in hopes of giving signal handlers properly aligned stacks. ... Get registers and flags out of the mcontext properly. Needed to play some games to get sys/_types included in order to get the full definition of the mcontext struct which Apple tries to hide from us. ... Moved os_get_runtime_executable_path from ppc-darwin-os.c to new file darwin-os.c. ... Fix debugging #ifdefs in runtime.h ... #define hacks to x86-assem.S to keep Apple's brain-dead assembler happy. In particular, it doesn't like things like $NIL, so I had to play some games with the precompiler to make it happy, and it wants .globl instead of .global. Also fixed a couple raw .aligns that should have used the macros ... Align stack in ppc-assem.S:call_into_c ... Added x86-darwin-os.h ... #- out debug.impure test that causes bad things to happen on darwin/ppc as it seems to cause bad things on x86/darwin as well. ... adjust fails for float tests ... LDSO stubs for x86/darwin --- diff --git a/NEWS b/NEWS index 5059228..8caf4d8 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ ;;;; -*- coding: utf-8; -*- changes in sbcl-0.9.11 relative to sbcl-0.9.10: + * new port: SBCL now works on x86/Darwin, including MacOS X 10.4.5 + on Intel. * new feature: Unicode character names are now known to the system (through CHAR-NAME and NAME-CHAR). * bug fix: as implied by AMOP, standardized classes no longer have diff --git a/make-config.sh b/make-config.sh index c117245..c8e485b 100644 --- a/make-config.sh +++ b/make-config.sh @@ -255,7 +255,7 @@ cd $original_dir if [ "$sbcl_arch" = "x86" ]; then printf ' :gencgc :stack-grows-downward-not-upward :c-stack-is-control-stack' >> $ltf printf ' :stack-allocatable-closures :alien-callbacks' >> $ltf - if [ "$sbcl_os" = "linux" ] || [ "$sbcl_os" = "freebsd" ] || [ "$sbcl_os" = "netbsd" ] || [ "$sbcl_os" = "sunos" ]; then + if [ "$sbcl_os" = "linux" ] || [ "$sbcl_os" = "freebsd" ] || [ "$sbcl_os" = "netbsd" ] || [ "$sbcl_os" = "sunos" ] || [ "$sbcl_os" = "darwin" ]; then printf ' :linkage-table' >> $ltf fi if [ "$sbcl_os" = "win32" ]; then diff --git a/src/compiler/aliencomp.lisp b/src/compiler/aliencomp.lisp index 33afd27..03de07c 100644 --- a/src/compiler/aliencomp.lisp +++ b/src/compiler/aliencomp.lisp @@ -675,11 +675,11 @@ (error "Something is broken."))) (lvar (node-lvar call)) (args args) - #!+win32 (stack-pointer (make-stack-pointer-tn))) + #!+(or (and x86 darwin) win32) (stack-pointer (make-stack-pointer-tn))) (multiple-value-bind (nsp stack-frame-size arg-tns result-tns) (make-call-out-tns type) #!+x86 (vop set-fpu-word-for-c call block) - #!+win32 (vop current-stack-pointer call block stack-pointer) + #!+(or (and x86 darwin) win32) (vop current-stack-pointer call block stack-pointer) (vop alloc-number-stack-space call block stack-frame-size nsp) (dolist (tn arg-tns) ;; On PPC, TN might be a list. This is used to indicate @@ -734,7 +734,7 @@ ((lvar-tn call block function) (reference-tn-list arg-tns nil)) ((reference-tn-list result-tns t)))) - #!-win32 (vop dealloc-number-stack-space call block stack-frame-size) - #!+win32 (vop reset-stack-pointer call block stack-pointer) + #!-(or (and darwin x86) win32) (vop dealloc-number-stack-space call block stack-frame-size) + #!+(or (and darwin x86) win32) (vop reset-stack-pointer call block stack-pointer) #!+x86 (vop set-fpu-word-for-lisp call block) (move-lvar-result call block result-tns lvar)))) diff --git a/src/compiler/x86/c-call.lisp b/src/compiler/x86/c-call.lisp index 38a8fe2..c52ce27 100644 --- a/src/compiler/x86/c-call.lisp +++ b/src/compiler/x86/c-call.lisp @@ -279,6 +279,8 @@ (unless (zerop amount) (let ((delta (logandc2 (+ amount 3) 3))) (inst sub esp-tn delta))) + ;; C stack should probably be 16 byte aligned on Darwin + #!+darwin (inst and esp-tn -16) (move result esp-tn))) (define-vop (dealloc-number-stack-space) diff --git a/src/compiler/x86/parms.lisp b/src/compiler/x86/parms.lisp index d8c61b5..f1043a6 100644 --- a/src/compiler/x86/parms.lisp +++ b/src/compiler/x86/parms.lisp @@ -236,6 +236,21 @@ (def!constant linkage-table-space-start #xA0000000) (def!constant linkage-table-space-end #xA1000000)) + +#!+darwin +(progn + (def!constant read-only-space-start #x01000000) + (def!constant read-only-space-end #x04ff8000) + + (def!constant static-space-start #x08000000) + (def!constant static-space-end #x097fff00) + + (def!constant dynamic-space-start #x10000000) + (def!constant dynamic-space-end #x6ffff000) + + (def!constant linkage-table-space-start #x0a000000) + (def!constant linkage-table-space-end #x0b000000)) + ;;; Size of one linkage-table entry in bytes. (def!constant linkage-table-entry-size 8) diff --git a/src/compiler/x86/show.lisp b/src/compiler/x86/show.lisp index 4d291f1..5fb38b9 100644 --- a/src/compiler/x86/show.lisp +++ b/src/compiler/x86/show.lisp @@ -22,11 +22,20 @@ :from :eval :to (:result 0)) eax) + #!+darwin (:temporary (:sc unsigned-reg + :offset esi-offset) + prev-stack-pointer) (:results (result :scs (descriptor-reg))) (:save-p t) (:generator 100 - (inst push object) + ;; the stack should be 16-byte aligned on Darwin + #!-darwin (inst push object) + #!+darwin (progn (inst mov prev-stack-pointer esp-tn) + (inst sub esp-tn n-word-bytes) + (inst and esp-tn -16) + (storew object esp-tn)) (inst lea eax (make-fixup "debug_print" :foreign)) (inst call (make-fixup "call_into_c" :foreign)) - (inst add esp-tn n-word-bytes) + #!-darwin (inst add esp-tn n-word-bytes) + #!+darwin (inst mov esp-tn prev-stack-pointer) (move result eax))) diff --git a/src/runtime/Config.ppc-darwin b/src/runtime/Config.ppc-darwin index f9a1db3..c7d0dec 100644 --- a/src/runtime/Config.ppc-darwin +++ b/src/runtime/Config.ppc-darwin @@ -10,7 +10,7 @@ # files for more information. CFLAGS = -g -Wall -O2 -fdollars-in-identifiers -OS_SRC = bsd-os.c ppc-darwin-os.c ppc-darwin-dlshim.c ppc-darwin-langinfo.c +OS_SRC = bsd-os.c darwin-os.c ppc-darwin-os.c ppc-darwin-dlshim.c ppc-darwin-langinfo.c OS_LIBS = -lSystem -lc OS_OBJS = ppc-darwin-rospace.o diff --git a/src/runtime/Config.x86-darwin b/src/runtime/Config.x86-darwin new file mode 100644 index 0000000..5261009 --- /dev/null +++ b/src/runtime/Config.x86-darwin @@ -0,0 +1,55 @@ +# -*- makefile -*- for the C-level run-time support for SBCL + +# This software is part of the SBCL system. See the README file for +# more information. +# +# This software is derived from the CMU CL system, which was +# written at Carnegie Mellon University and released into the +# public domain. The software is in the public domain and is +# provided with absolutely no warranty. See the COPYING and CREDITS +# files for more information. + +CFLAGS = -g -Wall -O2 -fdollars-in-identifiers +OS_SRC = bsd-os.c x86-bsd-os.c darwin-os.c ppc-darwin-dlshim.c x86-darwin-langinfo.c +OS_LIBS = -lSystem -lc -ldl +OS_OBJS = x86-darwin-rospace.o + +CC = gcc + +ASSEM_SRC = x86-assem.S ldso-stubs.S +ARCH_SRC = x86-arch.c + +CPPFLAGS += -no-cpp-precomp + +# KLUDGE: in OS X 10.3, Apple started putting the heap right where we +# expect our read-only space mapped. This hack causes the linker to +# place a zero-fill-on-demand segment in the same place and size as +# read-only-space, which is the only thing capable of keeping malloc +# out of this range. +LINKFLAGS += -dynamic `cat x86-darwin-link-flags` -twolevel_namespace -bind_at_load + +GC_SRC = gencgc.c + +OS_CLEAN_FILES += x86-darwin-mkrospace x86-darwin-fix-rospace x86-darwin-link-flags + +x86-darwin-mkrospace: x86-darwin-mkrospace.c + $(CC) -g -Wall -pedantic -o $@ $< + +x86-darwin-fix-rospace: x86-darwin-fix-rospace.c + $(CC) -g -Wall -pedantic -o $@ $< + +x86-darwin-rospace.o x86-darwin-link-flags: x86-darwin-mkrospace + ./x86-darwin-mkrospace > x86-darwin-link-flags + +.PHONY: after-grovel-headers + +# Fix the sbcl runtime to avoid Panther placing the heap where +# it wants read only space (in the first 32 megabytes, where it +# can be absolute-branched to with BA.) Must be done after +# grovel-headers, because Apple's nm is broken. +after-grovel-headers: x86-darwin-fix-rospace + ./x86-darwin-fix-rospace + +# Fortunatly make-target-1.sh does a make clean all the time. +# Otherwise we would have to make sure that sbcl gets rebuilt without +# the readonlyspace hack before groveling headers again. diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c index 0b2a338..6372c42 100644 --- a/src/runtime/bsd-os.c +++ b/src/runtime/bsd-os.c @@ -58,6 +58,10 @@ static void netbsd_init(); static void freebsd_init(); #endif /* __FreeBSD__ */ +#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) +static void x86_darwin_init(); +#endif + void os_init(char *argv[], char *envp[]) { @@ -69,6 +73,9 @@ os_init(char *argv[], char *envp[]) #ifdef __FreeBSD__ freebsd_init(); #endif /* __FreeBSD__ */ +#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) + x86_darwin_init(); +#endif } int *os_context_pc_addr(os_context_t *context) @@ -79,6 +86,8 @@ int *os_context_pc_addr(os_context_t *context) return CONTEXT_ADDR_FROM_STEM(pc); #elif defined __NetBSD__ return CONTEXT_ADDR_FROM_STEM(EIP); +#elif defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) + return CONTEXT_ADDR_FROM_STEM(eip); #elif defined LISP_FEATURE_DARWIN return &context->uc_mcontext->ss.srr0; #else @@ -92,9 +101,9 @@ os_context_sigmask_addr(os_context_t *context) /* (Unlike most of the other context fields that we access, the * signal mask field is a field of the basic, outermost context * struct itself both in FreeBSD 4.0 and in OpenBSD 2.6.) */ -#if defined __FreeBSD__ || __NetBSD__ || defined LISP_FEATURE_DARWIN +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(LISP_FEATURE_DARWIN) return &context->uc_sigmask; -#elif defined __OpenBSD__ +#elif defined (__OpenBSD__) return &context->sc_mask; #else #error unsupported BSD variant @@ -192,6 +201,13 @@ memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) os_context_t *context = arch_os_get_context(&void_context); void *fault_addr = arch_get_bad_addr(signal, siginfo, context); +#if defined(MEMORY_FAULT_DEBUG) + fprintf(stderr, "Memory fault at: %p, PC: %x\n", fault_addr, *os_context_pc_addr(context)); +#if defined(ARCH_HAS_STACK_POINTER) + fprintf(stderr, "Stack pointer: %x\n", *os_context_sp_addr(context)); +#endif +#endif + if (!gencgc_handle_wp_violation(fault_addr)) if(!handle_guard_page_triggered(context,fault_addr)) { #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK @@ -337,6 +353,19 @@ int arch_os_thread_cleanup(struct thread *thread) { } #endif +#if defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) +static void x86_darwin_init() +{ + struct sigaltstack sigstack; + sigstack.ss_sp = os_allocate(32*SIGSTKSZ); + if (sigstack.ss_sp) { + sigstack.ss_flags=0; + sigstack.ss_size = 32*SIGSTKSZ; + sigaltstack(&sigstack,0); + } +} +#endif + #ifdef LISP_FEATURE_DARWIN /* defined in ppc-darwin-os.c instead */ #elif defined(LISP_FEATURE_FREEBSD) diff --git a/src/runtime/bsd-os.h b/src/runtime/bsd-os.h index 6907482..4f72a66 100644 --- a/src/runtime/bsd-os.h +++ b/src/runtime/bsd-os.h @@ -84,8 +84,15 @@ typedef ucontext_t os_context_t; If Apple is going to break ucontext_t out of spite, I'm going to be cross with them ;) -- PRM */ +#if defined(LISP_FEATURE_X86) +#include +#include +typedef struct ucontext os_context_t; +#else #include typedef ucontext_t os_context_t; +#endif + #define SIG_MEMORY_FAULT SIGBUS #else diff --git a/src/runtime/darwin-os.c b/src/runtime/darwin-os.c new file mode 100644 index 0000000..2923a7a --- /dev/null +++ b/src/runtime/darwin-os.c @@ -0,0 +1,38 @@ +/* + * This is the Darwin incarnation of OS-dependent routines. See also + * "bsd-os.c". + */ + +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * This software is derived from the CMU CL system, which was + * written at Carnegie Mellon University and released into the + * public domain. The software is in the public domain and is + * provided with absolutely no warranty. See the COPYING and CREDITS + * files for more information. + */ + +#include "sbcl.h" +#include "globals.h" +#include "runtime.h" +#include +#include +#include +#include +#include "bsd-os.h" + +char * +os_get_runtime_executable_path() +{ + char path[PATH_MAX + 1]; + uint32_t size = sizeof(path); + + if (_NSGetExecutablePath(path, &size) == -1) + return NULL; + else + path[size] = '\0'; + + return copied_string(path); +} diff --git a/src/runtime/ppc-darwin-os.c b/src/runtime/ppc-darwin-os.c index 1a841b6..b29e447 100644 --- a/src/runtime/ppc-darwin-os.c +++ b/src/runtime/ppc-darwin-os.c @@ -114,16 +114,3 @@ os_flush_icache(os_vm_address_t address, os_vm_size_t length) ppc_flush_icache(address,length); } -char * -os_get_runtime_executable_path() -{ - char path[PATH_MAX + 1]; - uint32_t size = sizeof(path); - - if (_NSGetExecutablePath(path, &size) == -1) - return NULL; - else - path[size] = '\0'; - - return copied_string(path); -} diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 5768f8a..2fce3fd 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -37,7 +37,7 @@ * problem.. */ #define QSHOW_SIGNALS 0 -#ifdef QSHOW_SIGNALS +#if QSHOW_SIGNALS #define FSHOW_SIGNAL FSHOW #else #define FSHOW_SIGNAL(args) diff --git a/src/runtime/x86-arch.c b/src/runtime/x86-arch.c index 8f220a2..5b98eb3 100644 --- a/src/runtime/x86-arch.c +++ b/src/runtime/x86-arch.c @@ -66,6 +66,8 @@ context_eflags_addr(os_context_t *context) return &context->uc_mcontext.mc_eflags; #elif defined __OpenBSD__ return &context->sc_eflags; +#elif defined LISP_FEATURE_DARWIN + return &context->uc_mcontext->ss.eflags; #elif defined __NetBSD__ return &(context->uc_mcontext.__gregs[_REG_EFL]); #elif defined LISP_FEATURE_WIN32 @@ -257,6 +259,7 @@ sigtrap_handler(int signal, siginfo_t *info, void *void_context) * number of bytes will follow, the first is the length of the byte * arguments to follow. */ trap = *(unsigned char *)(*os_context_pc_addr(context)); + /* FSHOW((stderr, "/\n", trap, *os_context_pc_addr(context))); */ switch (trap) { case trap_PendingInterrupt: diff --git a/src/runtime/x86-assem.S b/src/runtime/x86-assem.S index e3b36c7..33820b4 100644 --- a/src/runtime/x86-assem.S +++ b/src/runtime/x86-assem.S @@ -37,6 +37,18 @@ #define GNAME(var) _##var #endif +#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun +#define GNAMEDOLLAR(var) $##var +#else +#define GNAMEDOLLAR(var) $_##var +#endif + +#if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined __sun +#define DOLLARLITERAL(var) $##var +#else +#define DOLLARLITERAL(var) $##(var) +#endif + /* Get the right type of alignment. Linux, FreeBSD and NetBSD (but not OpenBSD) * want alignment in bytes. * @@ -62,7 +74,7 @@ * that are defined to be no-ops on win32. Hopefully this still works on * other platforms. */ -#ifndef LISP_FEATURE_WIN32 +#if !defined(LISP_FEATURE_WIN32) && !defined(LISP_FEATURE_DARWIN) #define TYPE(name) .type name,@function #define SIZE(name) .size name,.-name #else @@ -70,9 +82,15 @@ #define SIZE(name) #endif +#if defined(LISP_FEATURE_DARWIN) +#define END() +#else +#define END() .end +#endif + .text - .global GNAME(foreign_function_call_active) - .global GNAME(all_threads) + .globl GNAME(foreign_function_call_active) + .globl GNAME(all_threads) /* * A call to call_into_c preserves esi, edi, and ebp. @@ -87,7 +105,7 @@ */ .text .align align_16byte,0x90 - .global GNAME(call_into_c) + .globl GNAME(call_into_c) TYPE(GNAME(call_into_c)) GNAME(call_into_c): movl $1,GNAME(foreign_function_call_active) @@ -109,6 +127,9 @@ GNAME(call_into_c): cld #endif +#ifdef LISP_FEATURE_DARWIN + andl $0xfffffff0,%esp # align stack to 16-byte boundary before calling C +#endif call *%eax # normal callout using Lisp stack movl %eax,%ecx # remember integer return value @@ -160,7 +181,7 @@ Lfp_rtn_value: .text - .global GNAME(call_into_lisp_first_time) + .globl GNAME(call_into_lisp_first_time) TYPE(GNAME(call_into_lisp_first_time)) /* The *ALIEN-STACK* pointer is set up on the first call_into_lisp when @@ -178,7 +199,7 @@ GNAME(call_into_lisp_first_time): movl THREAD_CONTROL_STACK_START_OFFSET(%eax) ,%esp /* don't think too hard about what happens if we get interrupted * here */ - addl $THREAD_CONTROL_STACK_SIZE-4,%esp + addl DOLLARLITERAL(THREAD_CONTROL_STACK_SIZE),%esp #else /* Win32 -really- doesn't like you switching stacks out from under it. */ movl GNAME(all_threads),%eax @@ -186,7 +207,7 @@ GNAME(call_into_lisp_first_time): jmp Lstack .text - .global GNAME(call_into_lisp) + .globl GNAME(call_into_lisp) TYPE(GNAME(call_into_lisp)) /* The C conventions require that ebx, esi, edi, and ebp be preserved @@ -288,7 +309,7 @@ LsingleValue: /* support for saving and restoring the NPX state from C */ .text - .global GNAME(fpu_save) + .globl GNAME(fpu_save) TYPE(GNAME(fpu_save)) .align 2,0x90 GNAME(fpu_save): @@ -297,7 +318,7 @@ GNAME(fpu_save): ret SIZE(GNAME(fpu_save)) - .global GNAME(fpu_restore) + .globl GNAME(fpu_restore) TYPE(GNAME(fpu_restore)) .align 2,0x90 GNAME(fpu_restore): @@ -311,7 +332,7 @@ GNAME(fpu_restore): */ .text .align align_4byte,0x90 - .global GNAME(undefined_tramp) + .globl GNAME(undefined_tramp) TYPE(GNAME(undefined_tramp)) .byte 0, 0, 0, SIMPLE_FUN_HEADER_WIDETAG GNAME(undefined_tramp): @@ -328,7 +349,7 @@ GNAME(undefined_tramp): */ .text .align align_4byte,0x90 - .global GNAME(closure_tramp) + .globl GNAME(closure_tramp) TYPE(GNAME(closure_tramp)) .byte 0, 0, 0, SIMPLE_FUN_HEADER_WIDETAG GNAME(closure_tramp): @@ -346,7 +367,7 @@ GNAME(closure_tramp): * fun-end breakpoint magic */ .text - .global GNAME(fun_end_breakpoint_guts) + .globl GNAME(fun_end_breakpoint_guts) .align align_4byte GNAME(fun_end_breakpoint_guts): /* Multiple Value return */ @@ -357,22 +378,22 @@ GNAME(fun_end_breakpoint_guts): movl %esp,%ebx # Setup ebx - the ofp. subl $4,%esp # Allocate one stack slot for the return value movl $4,%ecx # Setup ecx for one return value. - movl $NIL,%edi # default second value - movl $NIL,%esi # default third value + movl DOLLARLITERAL(NIL),%edi # default second value + movl DOLLARLITERAL(NIL),%esi # default third value multiple_value_return: - .global GNAME(fun_end_breakpoint_trap) + .globl GNAME(fun_end_breakpoint_trap) GNAME(fun_end_breakpoint_trap): int3 .byte trap_FunEndBreakpoint hlt # We should never return here. - .global GNAME(fun_end_breakpoint_end) + .globl GNAME(fun_end_breakpoint_end) GNAME(fun_end_breakpoint_end): - .global GNAME(do_pending_interrupt) + .globl GNAME(do_pending_interrupt) TYPE(GNAME(do_pending_interrupt)) .align align_4byte,0x90 GNAME(do_pending_interrupt): @@ -832,7 +853,7 @@ GNAME(post_signal_tramp): * This is part of the funky magic for exception handling on win32. * see sigtrap_emulator() in win32-os.c for details. */ - .global GNAME(sigtrap_trampoline) + .globl GNAME(sigtrap_trampoline) GNAME(sigtrap_trampoline): pushl %eax pushl %ebp @@ -848,7 +869,7 @@ GNAME(sigtrap_trampoline): * This is part of the funky magic for exception handling on win32. * see handle_exception() in win32-os.c for details. */ - .global GNAME(exception_trampoline) + .globl GNAME(exception_trampoline) GNAME(exception_trampoline): pushl %eax pushl %ebp @@ -865,9 +886,9 @@ GNAME(exception_trampoline): * to use. */ - .global GNAME(fast_bzero_pointer) + .globl GNAME(fast_bzero_pointer) .data - .align 4 + .align align_4byte GNAME(fast_bzero_pointer): /* Variable containing a pointer to the bzero function to use. * Initially points to a basic function. Change this variable @@ -876,7 +897,7 @@ GNAME(fast_bzero_pointer): .text .align align_8byte,0x90 - .global GNAME(fast_bzero) + .globl GNAME(fast_bzero) TYPE(GNAME(fast_bzero)) GNAME(fast_bzero): /* Indirect function call */ @@ -886,7 +907,7 @@ GNAME(fast_bzero): .text .align align_8byte,0x90 - .global GNAME(fast_bzero_detect) + .globl GNAME(fast_bzero_detect) TYPE(GNAME(fast_bzero_detect)) GNAME(fast_bzero_detect): /* Decide whether to use SSE, MMX or REP version */ @@ -906,10 +927,10 @@ GNAME(fast_bzero_detect): * for all non-SSE2 processors. */ Lbase: - movl $GNAME(fast_bzero_base), GNAME(fast_bzero_pointer) + movl GNAMEDOLLAR(fast_bzero_base), GNAME(fast_bzero_pointer) jmp Lrestore Lsse2: - movl $GNAME(fast_bzero_sse), GNAME(fast_bzero_pointer) + movl GNAMEDOLLAR(fast_bzero_sse), GNAME(fast_bzero_pointer) jmp Lrestore Lrestore: @@ -924,7 +945,7 @@ Lrestore: .text .align align_8byte,0x90 - .global GNAME(fast_bzero_sse) + .globl GNAME(fast_bzero_sse) TYPE(GNAME(fast_bzero_sse)) GNAME(fast_bzero_sse): @@ -940,7 +961,7 @@ GNAME(fast_bzero_sse): movups %xmm7, -16(%esp) /* Save XMM register */ xorps %xmm7, %xmm7 /* Zero the XMM register */ jmp Lloop_sse - .align 16 + .align align_16byte Lloop_sse: /* Copy the 16 zeroes from xmm7 to memory, 4 times. MOVNTDQ is the @@ -970,7 +991,7 @@ Lend_sse: .text .align align_8byte,0x90 - .global GNAME(fast_bzero_base) + .globl GNAME(fast_bzero_base) TYPE(GNAME(fast_bzero_base)) GNAME(fast_bzero_base): @@ -986,8 +1007,11 @@ GNAME(fast_bzero_base): shr $2, %ecx /* Amount of 4-byte blocks to copy */ jz Lend_base cld /* Set direction of STOSL to increment */ - rep stosl /* Store EAX to *EDI, ECX times, incrementing + + rep + stosl /* Store EAX to *EDI, ECX times, incrementing * EDI by 4 after each store */ + Lend_base: pop %edi /* Restore temp registers */ pop %ecx @@ -996,4 +1020,5 @@ Lend_base: SIZE(GNAME(fast_bzero_base)) - .end + END() + \ No newline at end of file diff --git a/src/runtime/x86-bsd-os.c b/src/runtime/x86-bsd-os.c index a843364..c579f6c 100644 --- a/src/runtime/x86-bsd-os.c +++ b/src/runtime/x86-bsd-os.c @@ -14,7 +14,7 @@ * entails; unfortunately, currently the situation is worse, not * better, than in the above paragraph. */ -#if defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(LISP_FEATURE_DARWIN) int * os_context_register_addr(os_context_t *context, int offset) { diff --git a/src/runtime/x86-bsd-os.h b/src/runtime/x86-bsd-os.h index 259bb01..303b7eb 100644 --- a/src/runtime/x86-bsd-os.h +++ b/src/runtime/x86-bsd-os.h @@ -11,7 +11,7 @@ static inline os_context_t *arch_os_get_context(void **void_context) { * can share a fair amount of code between different variants. */ #if defined __FreeBSD__ #define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext.mc_ ## stem -#elif defined __OpenBSD__ +#elif defined(__OpenBSD__) #define CONTEXT_ADDR_FROM_STEM(stem) &context->sc_ ## stem #elif defined __NetBSD__ #define CONTEXT_ADDR_FROM_STEM(stem) &((context)->uc_mcontext.__gregs[_REG_ ## stem]) diff --git a/src/runtime/x86-darwin-fix-rospace.c b/src/runtime/x86-darwin-fix-rospace.c new file mode 100644 index 0000000..6a84005 --- /dev/null +++ b/src/runtime/x86-darwin-fix-rospace.c @@ -0,0 +1,85 @@ +/* ppc-darwin-fix-rospace.c - fix the segment and section output by ppc-darwin-mkrospace.c to have the correct size */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sbcl.h" +#include "runtime.h" + +#include "ppc-darwin-spacelist.h" + +int main(int argc, char** argv) +{ + int fd; + int i, spacei; + struct stat filestat; + struct mach_header *header; + void* file_pointer; + size_t filesize; + size_t old_commands_size; + char* window; + size_t segments_size; + + /* Open the SBCL binary */ + fd = open("sbcl", O_RDWR, 0); /* wr unx prgrmmrs, we cn't spll */ + if (fd == -1) { + perror(argv[0]); + return -1; + } + if (fstat(fd, &filestat) == -1) { + close(fd); + perror(argv[0]); + return -1; + } + filesize = filestat.st_size; + if ((int) (file_pointer = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0)) == -1) { + perror(argv[0]); + close(fd); + return -1; + } + + segments_size = 0; + spacei = 0; + header = (struct mach_header*) file_pointer; + window = (char*) (header + 1); + for (i = 0; i < header->ncmds; i++) { + struct load_command* current_segment; + current_segment = (struct load_command*) window; + segments_size += current_segment->cmdsize; + window += current_segment->cmdsize; + if (current_segment->cmd == LC_SEGMENT) { + int is_sbcl; + struct segment_command* seg = (struct segment_command*) current_segment; + struct section* sectptr; + int j, max; + max = seg->nsects; + if (strncmp("SBCL", seg->segname, 4) == 0) { + is_sbcl = 1; + seg->vmsize = space_sizes[spacei]; + } else { + is_sbcl = 0; + } + seg++; + sectptr = (struct section*) seg; + for (j = 0; j < max; j++) { + if (is_sbcl) { + sectptr->size = space_sizes[spacei]; + spacei++; + } + sectptr++; + } + } + } + + munmap(file_pointer, filesize); + close(fd); + return 0; +} diff --git a/src/runtime/x86-darwin-langinfo.c b/src/runtime/x86-darwin-langinfo.c new file mode 100644 index 0000000..002f69f --- /dev/null +++ b/src/runtime/x86-darwin-langinfo.c @@ -0,0 +1,45 @@ +/* + * This is a minimal nl_langinfo replacement that only handles CODESET. + * By default, it returns UTF-8. It checks if LC_CTYPE or LANG are set, and + * uses LATIN-1 if it finds one set to C, or UTF-8 if it finds one set to + * anything else. + */ + +/* + * This software is part of the SBCL system. See the README file for + * more information. + * + * This software is derived from the CMU CL system, which was + * written at Carnegie Mellon University and released into the + * public domain. The software is in the public domain and is + * provided with absolutely no warranty. See the COPYING and CREDITS + * files for more information. + */ + +#include +#include "ppc-darwin-langinfo.h" + +char *nl_langinfo(nl_item item) +{ + char *nada = "", *utf8 = "UTF-8", *latin1 = "LATIN-1"; + + if (item != CODESET) { + return nada; + } else { + char *ctype = getenv ("LC_CTYPE"); + + if ((ctype != NULL) && (!strcmp(ctype, "C"))) { + return latin1; + } else if (ctype != NULL) { + return utf8; + } else { + char *lang = getenv ("LANG"); + + if ((lang != NULL) && (!strcmp(lang, "C"))) { + return latin1; + } else { + return utf8; + } + } + } +} diff --git a/src/runtime/x86-darwin-mkrospace.c b/src/runtime/x86-darwin-mkrospace.c new file mode 100644 index 0000000..014f4f9 --- /dev/null +++ b/src/runtime/x86-darwin-mkrospace.c @@ -0,0 +1,72 @@ +/* x86-darwin-mkrospace.c - write a .o which makes sure we get our desired address range */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sbcl.h" +#include "runtime.h" + +#include "x86-darwin-spacelist.h" + +struct simple_object_file +{ + struct segment_command thesegment; + struct section thesection; +}; + +int main(int argc, char** argv) +{ + struct mach_header *theheader; + struct simple_object_file *theobj; + int fd, i; + + /* Produce the mach header */ + theheader = (struct mach_header*) malloc(sizeof(struct mach_header)); + theheader->magic = MH_MAGIC; + theheader->cputype = CPU_TYPE_X86; + theheader->cpusubtype = CPU_SUBTYPE_I386_ALL; + theheader->filetype = MH_OBJECT; + theheader->ncmds = N_SEGMENTS_TO_PRODUCE; + theheader->sizeofcmds = N_SEGMENTS_TO_PRODUCE * (sizeof(struct segment_command) + sizeof(struct section)); + theheader->flags = MH_NOUNDEFS; + printf("-Wl"); + fd = open("x86-darwin-rospace.o", O_WRONLY | O_CREAT, 0644); + write(fd, theheader, sizeof(struct mach_header)); + + for (i = 0; i < N_SEGMENTS_TO_PRODUCE; i++) { + theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file)); + theobj->thesegment.cmd = LC_SEGMENT; + theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section); + snprintf(theobj->thesegment.segname, 7, "SBCL%d", i); + theobj->thesegment.fileoff = sizeof(struct mach_header) + i * (sizeof(struct segment_command) + sizeof(struct section)); + theobj->thesegment.vmaddr = space_start_locations[i]; + theobj->thesegment.vmsize = 0; + theobj->thesegment.maxprot = VM_PROT_ALL; + theobj->thesegment.initprot = VM_PROT_ALL; + theobj->thesegment.nsects = 1; + theobj->thesegment.flags = 0; + snprintf(theobj->thesection.sectname, 7, "sect%d", i); + snprintf(theobj->thesection.segname, 7, "SBCL%d", i); + theobj->thesection.addr = space_start_locations[i]; + theobj->thesection.size = 0; + theobj->thesection.offset = 0; + theobj->thesection.align = 0; + theobj->thesection.reloff = 0; + theobj->thesection.nreloc = 0; + theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS; + theobj->thesection.reserved1 = 0; + theobj->thesection.reserved2 = 0; + write(fd, theobj, sizeof(struct simple_object_file)); + printf(",-segaddr,SBCL%d,0x%x", i, space_start_locations[i]); + free(theobj); + } + printf("\n"); + close(fd); + return 0; +} diff --git a/src/runtime/x86-darwin-os.h b/src/runtime/x86-darwin-os.h new file mode 100644 index 0000000..8ee0e38 --- /dev/null +++ b/src/runtime/x86-darwin-os.h @@ -0,0 +1,11 @@ +#ifndef _X86_DARWIN_OS_H +#define _X86_DARWIN_OS_H + +static inline os_context_t *arch_os_get_context(void **void_context) { + return (os_context_t *) *void_context; +} + +#define CONTEXT_ADDR_FROM_STEM(stem) &context->uc_mcontext->ss.stem +#define DARWIN_FIX_CONTEXT(context) + +#endif /* _X86_DARWIN_OS_H */ diff --git a/src/runtime/x86-darwin-spacelist.h b/src/runtime/x86-darwin-spacelist.h new file mode 100644 index 0000000..c1a3026 --- /dev/null +++ b/src/runtime/x86-darwin-spacelist.h @@ -0,0 +1,30 @@ +#ifndef PPC_DARWIN_SPACELIST_H +#define PPC_DARWIN_SPACELIST_H + +#if defined(LISP_FEATURE_GENCGC) +#define N_SEGMENTS_TO_PRODUCE 4 +#else +#define N_SEGMENTS_TO_PRODUCE 5 +#endif + +unsigned int space_start_locations[N_SEGMENTS_TO_PRODUCE] = + { READ_ONLY_SPACE_START, STATIC_SPACE_START, +#if defined(LISP_FEATURE_GENCGC) + DYNAMIC_SPACE_START, +#else + DYNAMIC_0_SPACE_START, DYNAMIC_1_SPACE_START, +#endif + LINKAGE_TABLE_SPACE_START}; + +unsigned int space_sizes[N_SEGMENTS_TO_PRODUCE] = + { READ_ONLY_SPACE_END - READ_ONLY_SPACE_START, + STATIC_SPACE_END - STATIC_SPACE_START, +#if defined(LISP_FEATURE_GENCGC) + DYNAMIC_SPACE_END - DYNAMIC_SPACE_START, +#else + DYNAMIC_0_SPACE_END - DYNAMIC_0_SPACE_START, + DYNAMIC_1_SPACE_END - DYNAMIC_1_SPACE_START, +#endif + LINKAGE_TABLE_SPACE_END - LINKAGE_TABLE_SPACE_START}; + +#endif diff --git a/tests/debug.impure.lisp b/tests/debug.impure.lisp index a945291..0377334 100644 --- a/tests/debug.impure.lisp +++ b/tests/debug.impure.lisp @@ -348,7 +348,7 @@ ;;; This is not a WITH-TEST :FAILS-ON PPC DARWIN since there are ;;; suspicions that the breakpoint trace might corrupt the whole image ;;; on that platform. -#-(and ppc darwin) +#-(and (or ppc x86) darwin) (with-test (:name (trace :encapsulate nil) :fails-on '(or ppc sparc)) (let ((out (with-output-to-string (*trace-output*) diff --git a/tests/float.pure.lisp b/tests/float.pure.lisp index 1a042e5..3d50fda 100644 --- a/tests/float.pure.lisp +++ b/tests/float.pure.lisp @@ -93,7 +93,7 @@ (assert (= 0.0d0 (scale-float 1.0d0 (1- most-negative-fixnum)))) (with-test (:name (:scale-float-overflow :bug-372) - :fails-on '(or :ppc :freebsd)) ;; bug 372 + :fails-on '(or :ppc :darwin :freebsd)) ;; bug 372 (progn (assert (raises-error? (scale-float 1.0 most-positive-fixnum) floating-point-overflow)) @@ -119,7 +119,7 @@ 'double-float)) (with-test (:name (:addition-overflow :bug-372) - :fails-on '(or :ppc :mips :freebsd)) + :fails-on '(or :ppc :darwin :mips :freebsd)) (assert (typep (nth-value 1 (ignore-errors diff --git a/tools-for-build/ldso-stubs.lisp b/tools-for-build/ldso-stubs.lisp index 99c8384..0c65ace 100644 --- a/tools-for-build/ldso-stubs.lisp +++ b/tools-for-build/ldso-stubs.lisp @@ -57,7 +57,7 @@ ldso_stub__~A: ; \\ #endif .text" -#!+(or x86 x86-64) " +#!+(or (and x86 (not darwin)) x86-64) " #define LDSO_STUBIFY(fct) \\ .align 16 ; \\ .globl ldso_stub__ ## fct ; \\ @@ -112,6 +112,24 @@ ldso_stub__ ## fct ## $lazy_ptr: @\\ .indirect_symbol _ ## fct @\\ .long dyld_stub_binding_helper" +;;; darwin x86 assembler is weird and follows the ppc assembler syntax +#!+(and darwin x86) " +#define LDSO_STUBIFY(fct) \\ +.text ; \\ + .align 4 ; \\ +.globl ldso_stub___ ## fct ; \\ +ldso_stub___ ## fct: ; \\ + jmp L ## fct ## $stub ; \\ + .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 ; \\ +L ## fct ## $stub: ; \\ + .indirect_symbol _ ## fct ; \\ + hlt ; \\ + hlt ; \\ + hlt ; \\ + hlt ; \\ + hlt ; \\ + .subsections_via_symbols ; " + ;;; KLUDGE: set up the vital fifth argument, passed on the ;;; stack. Do this unconditionally, even if the stub is for a ;;; function with few arguments: it can't hurt. We only do this for diff --git a/version.lisp-expr b/version.lisp-expr index 7203eff..16174f8 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"0.9.10.15" +"0.9.10.16"