* Added full cygwin port.
This commit is contained in:
parent
74343ba442
commit
90bf017e61
|
@ -1,5 +1,5 @@
|
|||
|
||||
CFLAGS = -I/opt/local/include -Wall -DNDEBUG -DHAS_ALT_STACK -O3
|
||||
CFLAGS = -I/opt/local/include -Wall -DNDEBUG -O3
|
||||
#CFLAGS = -I/opt/local/include -Wall -g
|
||||
LDFLAGS = -L/opt/local/lib -g -ldl -lgmp -lm
|
||||
CC = gcc
|
||||
|
@ -11,7 +11,7 @@ endif
|
|||
objects = ikarus-collect.o ikarus-runtime.o ikarus-main.o ikarus-fasl.o \
|
||||
ikarus-exec.o ikarus-print.o ikarus-enter.o ikarus-symbol-table.o \
|
||||
ikarus-weak-pairs.o ikarus-numerics.o ikarus-flonums.o \
|
||||
verify-integrity.o
|
||||
verify-integrity.o winmmap.o
|
||||
|
||||
all: ikarus
|
||||
|
||||
|
@ -54,6 +54,9 @@ ikarus-numerics.o: ikarus-numerics.c ikarus.h
|
|||
ikarus-flonums.o: ikarus-flonums.c ikarus.h
|
||||
$(CC) $(CFLAGS) -c ikarus-flonums.c
|
||||
|
||||
winmmap.o: winmmap.c winmmap.h
|
||||
$(CC) $(CFLAGS) -c winmmap.c
|
||||
|
||||
ikarus.h: ikarus-data.h
|
||||
touch ikarus.h
|
||||
|
||||
|
|
|
@ -123,3 +123,89 @@ L_set: # (label Lset)
|
|||
movl 0(%esi), %ebp # (movl (pcb-ref 'allocation-pointer) apr)
|
||||
ret # (ret)))
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
.section .drectve
|
||||
|
||||
.ascii " -export:ik_collect"
|
||||
.ascii " -export:ik_collect_vararg"
|
||||
.ascii " -export:ik_dump_dirty_vector"
|
||||
.ascii " -export:ik_dump_metatable"
|
||||
.ascii " -export:ik_error"
|
||||
.ascii " -export:ik_stack_overflow"
|
||||
.ascii " -export:ik_system"
|
||||
.ascii " -export:ik_uuid"
|
||||
.ascii " -export:ikrt_bignum_shift_left"
|
||||
.ascii " -export:ikrt_bignum_shift_right"
|
||||
.ascii " -export:ikrt_bignum_to_bytevector"
|
||||
.ascii " -export:ikrt_bnbncomp"
|
||||
.ascii " -export:ikrt_bnbndivrem"
|
||||
.ascii " -export:ikrt_bnbnlogand"
|
||||
.ascii " -export:ikrt_bnbnminus"
|
||||
.ascii " -export:ikrt_bnbnmult"
|
||||
.ascii " -export:ikrt_bnbnplus"
|
||||
.ascii " -export:ikrt_bnfxdivrem"
|
||||
.ascii " -export:ikrt_bnfxminus"
|
||||
.ascii " -export:ikrt_bvftime"
|
||||
.ascii " -export:ikrt_bytes_allocated"
|
||||
.ascii " -export:ikrt_bytes_allocated_major"
|
||||
.ascii " -export:ikrt_bytevector_to_flonum"
|
||||
.ascii " -export:ikrt_close_file"
|
||||
.ascii " -export:ikrt_delete_file"
|
||||
.ascii " -export:ikrt_environ"
|
||||
.ascii " -export:ikrt_even_bn"
|
||||
.ascii " -export:ikrt_exit"
|
||||
.ascii " -export:ikrt_file_exists"
|
||||
.ascii " -export:ikrt_fixnum_shift_left"
|
||||
.ascii " -export:ikrt_fixnum_to_flonum"
|
||||
.ascii " -export:ikrt_fl_acos"
|
||||
.ascii " -export:ikrt_fl_asin"
|
||||
.ascii " -export:ikrt_fl_atan"
|
||||
.ascii " -export:ikrt_fl_cos"
|
||||
.ascii " -export:ikrt_fl_equal"
|
||||
.ascii " -export:ikrt_fl_exp"
|
||||
.ascii " -export:ikrt_fl_invert"
|
||||
.ascii " -export:ikrt_fl_less"
|
||||
.ascii " -export:ikrt_fl_less_or_equal"
|
||||
.ascii " -export:ikrt_fl_log"
|
||||
.ascii " -export:ikrt_fl_round"
|
||||
.ascii " -export:ikrt_fl_sin"
|
||||
.ascii " -export:ikrt_fl_sqrt"
|
||||
.ascii " -export:ikrt_fl_tan"
|
||||
.ascii " -export:ikrt_flfl_expt"
|
||||
.ascii " -export:ikrt_fork"
|
||||
.ascii " -export:ikrt_fx_acos"
|
||||
.ascii " -export:ikrt_fx_asin"
|
||||
.ascii " -export:ikrt_fx_atan"
|
||||
.ascii " -export:ikrt_fx_cos"
|
||||
.ascii " -export:ikrt_fx_log"
|
||||
.ascii " -export:ikrt_fx_sin"
|
||||
.ascii " -export:ikrt_fx_sqrt"
|
||||
.ascii " -export:ikrt_fx_tan"
|
||||
.ascii " -export:ikrt_fxbnlogand"
|
||||
.ascii " -export:ikrt_fxbnminus"
|
||||
.ascii " -export:ikrt_fxbnmult"
|
||||
.ascii " -export:ikrt_fxbnplus"
|
||||
.ascii " -export:ikrt_fxfxminus"
|
||||
.ascii " -export:ikrt_fxfxmult"
|
||||
.ascii " -export:ikrt_fxfxplus"
|
||||
.ascii " -export:ikrt_fxrandom"
|
||||
.ascii " -export:ikrt_getenv"
|
||||
.ascii " -export:ikrt_intern_gensym"
|
||||
.ascii " -export:ikrt_is_weak_pair"
|
||||
.ascii " -export:ikrt_make_code"
|
||||
.ascii " -export:ikrt_open_input_file"
|
||||
.ascii " -export:ikrt_open_output_file"
|
||||
.ascii " -export:ikrt_positive_bn"
|
||||
.ascii " -export:ikrt_read"
|
||||
.ascii " -export:ikrt_register_guardian_pair"
|
||||
.ascii " -export:ikrt_set_code_annotation"
|
||||
.ascii " -export:ikrt_set_code_reloc_vector"
|
||||
.ascii " -export:ikrt_setenv"
|
||||
.ascii " -export:ikrt_stats_now"
|
||||
.ascii " -export:ikrt_string_to_symbol"
|
||||
.ascii " -export:ikrt_strings_to_gensym"
|
||||
.ascii " -export:ikrt_waitpid"
|
||||
.ascii " -export:ikrt_weak_cons"
|
||||
.ascii " -export:ikrt_write_file"
|
||||
.ascii " -export:ik_foreign_call"
|
||||
#endif
|
||||
|
|
|
@ -211,7 +211,11 @@ void
|
|||
register_handlers(){
|
||||
struct sigaction sa;
|
||||
sa.sa_sigaction = handler;
|
||||
#ifdef __CYGWIN__
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
#else
|
||||
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
|
||||
#endif
|
||||
sigemptyset(&sa.sa_mask);
|
||||
int err = sigaction(SIGINT, &sa, 0);
|
||||
if(err){
|
||||
|
@ -238,7 +242,7 @@ SYNOPSIS
|
|||
|
||||
void
|
||||
register_alt_stack(){
|
||||
#ifdef HAS_ALT_STACK
|
||||
#ifndef __CYGWIN__
|
||||
char* stk = mmap(0, SIGSTKSZ, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON, -1, 0);
|
||||
// char* stk = ik_mmap(SIGSTKSZ);
|
||||
if(stk == (char*)-1){
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef __CYGWIN__
|
||||
#include "winmmap.h"
|
||||
#endif
|
||||
|
||||
|
||||
int total_allocated_pages = 0;
|
||||
|
@ -188,6 +191,7 @@ ik_mmap(int size){
|
|||
total_allocated_pages += pages;
|
||||
int mapsize = pages * pagesize;
|
||||
assert(size == mapsize);
|
||||
#ifndef __CYGWIN__
|
||||
char* mem = mmap(
|
||||
0,
|
||||
mapsize,
|
||||
|
@ -199,6 +203,9 @@ ik_mmap(int size){
|
|||
fprintf(stderr, "Mapping failed: %s\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
#else
|
||||
char* mem = win_mmap(mapsize);
|
||||
#endif
|
||||
memset(mem, -1, mapsize);
|
||||
#ifndef NDEBUG
|
||||
fprintf(stderr, "MMAP 0x%08x .. 0x%08x\n", (int)mem,
|
||||
|
@ -214,11 +221,15 @@ ik_munmap(void* mem, int size){
|
|||
assert(size == mapsize);
|
||||
assert(((-pagesize) & (int)mem) == (int)mem);
|
||||
total_allocated_pages -= pages;
|
||||
#ifndef __CYGWIN__
|
||||
int err = munmap(mem, mapsize);
|
||||
if(err != 0){
|
||||
fprintf(stderr, "ik_munmap failed: %s\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
#else
|
||||
win_munmap(mem, mapsize);
|
||||
#endif
|
||||
#ifndef NDEBUG
|
||||
fprintf(stderr, "UNMAP 0x%08x .. 0x%08x\n", (int)mem,
|
||||
((int)(mem))+mapsize-1);
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
#ifdef __CYGWIN__
|
||||
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define pagesize 4096
|
||||
#define pageshift 12
|
||||
#define segment_size (16*pagesize)
|
||||
#define segment_shift (4+pageshift)
|
||||
#include "winmmap.h"
|
||||
|
||||
/* vim:syntax=c */
|
||||
|
||||
static unsigned short* table = 0;
|
||||
static char* ap = 0;
|
||||
static size_t as = 0;
|
||||
|
||||
static void*
|
||||
do_mmap(size_t n){
|
||||
void* x = mmap(0, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
|
||||
if(x == (void*)-1){
|
||||
fprintf(stderr, "failed to mmap: %s\n", strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
assert((((unsigned int)x) & (segment_size-1)) == 0);
|
||||
return x;
|
||||
}
|
||||
|
||||
static void
|
||||
do_munmap(void* addr, size_t size){
|
||||
int err = munmap(addr, size);
|
||||
if(err){
|
||||
fprintf(stderr, "failed to unmap\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
init_table(){
|
||||
assert(sizeof(unsigned short) == 2);
|
||||
table = do_mmap(32*pagesize);
|
||||
bzero(table, 32*pagesize);
|
||||
}
|
||||
|
||||
void
|
||||
win_munmap(char* addr, size_t size){
|
||||
while(size){
|
||||
unsigned int page = (((unsigned int) addr) >> pageshift);
|
||||
unsigned int segment_index = page / 16;
|
||||
unsigned int page_index = page & 15;
|
||||
unsigned short alloc_bits = table[segment_index];
|
||||
assert((alloc_bits & (1<<page_index)) == (1<<page_index));
|
||||
unsigned int new_bits = alloc_bits & ~ (1 << page_index);
|
||||
table[segment_index] = new_bits;
|
||||
if(new_bits == 0){
|
||||
do_munmap((void*)(segment_index*segment_size), segment_size);
|
||||
}
|
||||
size -= pagesize;
|
||||
addr += pagesize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
win_mmap(size_t size){
|
||||
if(size <= as){
|
||||
char* x = ap;
|
||||
ap += size;
|
||||
as -= size;
|
||||
return x;
|
||||
}
|
||||
if(table == 0) init_table();
|
||||
win_munmap(ap, as);
|
||||
size_t segments = ((size+segment_size-1) >> segment_shift);
|
||||
size_t aligned_size = segments << segment_shift;
|
||||
char* addr = do_mmap(aligned_size);
|
||||
unsigned int page = (((unsigned int) addr) >> pageshift);
|
||||
unsigned int segment_index = page / 16;
|
||||
int i;
|
||||
for(i=0; i<segments; i++){
|
||||
table[segment_index+i] = -1;
|
||||
}
|
||||
ap = addr + size;
|
||||
as = aligned_size - size;
|
||||
return addr;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#ifdef __CYGWIN__
|
||||
void win_munmap(char* addr, size_t size);
|
||||
|
||||
char* win_mmap(size_t size);
|
||||
#endif
|
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
Loading…
Reference in New Issue