Changeset 9974


Ignore:
Timestamp:
Jul 10, 2008, 9:38:32 AM (11 years ago)
Author:
gb
Message:

Changes from trunk: early Windows stuff, "natural" stack sizes,
os version check, paging_info stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lisp-kernel/pmcl-kernel.c

    r7668 r9974  
    3131#include <stdio.h>
    3232#include <stdlib.h>
     33#ifndef WINDOWS
    3334#include <sys/mman.h>
     35#endif
    3436#include <fcntl.h>
    3537#include <signal.h>
     38#include <errno.h>
     39#ifndef WINDOWS
     40#include <sys/utsname.h>
    3641#include <unistd.h>
    37 #include <errno.h>
    38 #include <sys/utsname.h>
     42#endif
    3943
    4044#ifdef LINUX
     
    106110
    107111#include <ctype.h>
     112#ifndef WINDOWS
    108113#include <sys/select.h>
     114#endif
    109115#include "Threads.h"
     116
     117#include <fenv.h>
    110118
    111119#ifndef MAP_NORESERVE
     
    141149{
    142150  void * cache_start = (void *) p;
    143   unsigned long ncacheflush = (unsigned long) q - (unsigned long) p;
     151  natural ncacheflush = (natural) q - (natural) p;
    144152
    145153  xMakeDataExecutable(cache_start, ncacheflush); 
     
    149157ensure_stack_limit(size_t stack_size)
    150158{
     159#ifdef WINDOWS
     160#else
    151161  struct rlimit limits;
    152162  rlim_t cur_stack_limit, max_stack_limit;
     
    168178    }
    169179  }
     180#endif
    170181  return stack_size;
    171182}
     
    177188
    178189BytePtr
    179 allocate_lisp_stack(unsigned useable,
     190allocate_lisp_stack(natural useable,
    180191                    unsigned softsize,
    181192                    unsigned hardsize,
     
    187198                    protected_area_ptr *hardp)
    188199{
    189   void *allocate_stack(unsigned);
     200  void *allocate_stack(natural);
    190201  void free_stack(void *);
    191   unsigned size = useable+softsize+hardsize;
    192   unsigned overhead;
     202  natural size = useable+softsize+hardsize;
     203  natural overhead;
    193204  BytePtr base, softlimit, hardlimit;
    194   OSErr err;
    195205  Ptr h = allocate_stack(size+4095);
    196206  protected_area_ptr hprotp = NULL, sprotp;
     
    228238  }
    229239  if (base_p) *base_p = base;
    230   return (BytePtr) ((unsigned long)(base+size));
     240  return (BytePtr) ((natural)(base+size));
    231241}
    232242
     
    237247area *
    238248allocate_lisp_stack_area(area_code stack_type,
    239                          unsigned useable,
     249                         natural usable,
    240250                         unsigned softsize,
    241251                         unsigned hardsize,
     
    249259  protected_area_ptr soft_area=NULL, hard_area=NULL;
    250260
    251   bottom = allocate_lisp_stack(useable,
     261  bottom = allocate_lisp_stack(usable,
    252262                               softsize,
    253263                               hardsize,
     
    277287register_cstack_holding_area_lock(BytePtr bottom, natural size)
    278288{
    279   BytePtr lowlimit = (BytePtr) (((((unsigned long)bottom)-size)+4095)&~4095);
     289  BytePtr lowlimit = (BytePtr) (((((natural)bottom)-size)+4095)&~4095);
    280290  area *a = new_area((BytePtr) bottom-size, bottom, AREA_CSTACK);
    281291  a->hardlimit = lowlimit+CSTACK_HARDPROT;
     
    290300
    291301area*
    292 allocate_vstack_holding_area_lock(unsigned usable)
     302allocate_vstack_holding_area_lock(natural usable)
    293303{
    294304  return allocate_lisp_stack_area(AREA_VSTACK,
     
    302312
    303313area *
    304 allocate_tstack_holding_area_lock(unsigned usable)
     314allocate_tstack_holding_area_lock(natural usable)
    305315{
    306316  return allocate_lisp_stack_area(AREA_TSTACK,
     
    351361#endif
    352362#endif
     363#ifdef WINDOWS
     364#define MAXIMUM_MAPPABLE_MEMORY (512<<30LL)
     365#endif
    353366#else
    354367#ifdef DARWIN
     
    408421*/
    409422
     423#ifdef WINDOWS
     424void
     425uncommit_pages(void *start, size_t len)
     426{
     427}
     428#else
    410429void
    411430uncommit_pages(void *start, size_t len)
     
    425444  }
    426445}
     446#endif
    427447
    428448#define TOUCH_PAGES_ON_COMMIT 0
     
    446466}
    447467
     468#ifdef WINDOWS
    448469Boolean
    449470commit_pages(void *start, size_t len)
    450471{
     472}
     473#else
     474Boolean
     475commit_pages(void *start, size_t len)
     476{
    451477  if (len != 0) {
    452     int i, err;
     478    int i;
    453479    void *addr;
    454480
     
    476502    return false;
    477503  }
    478 }
     504  return true;
     505}
     506#endif
    479507
    480508area *
     
    491519}
    492520
     521#ifdef WINDOWS
     522area *
     523extend_readonly_area(unsigned more)
     524{
     525}
     526#else
    493527area *
    494528extend_readonly_area(unsigned more)
     
    498532  BytePtr new_start, new_end;
    499533
    500   if (a = find_readonly_area()) {
     534  if ((a = find_readonly_area()) != NULL) {
    501535    if ((a->active + more) > a->high) {
    502536      return NULL;
    503537    }
    504     mask = ((unsigned long)a->active) & (page_size-1);
     538    mask = ((natural)a->active) & (page_size-1);
    505539    if (mask) {
    506540      UnProtectMemory(a->active-mask, page_size);
     
    520554  return NULL;
    521555}
     556#endif
    522557
    523558LispObj image_base=0;
     
    587622
    588623
    589 
     624#ifdef WINDOWS
    590625area *
    591 create_reserved_area(unsigned long totalsize)
    592 {
    593   OSErr err;
     626create_reserved_area(natural totalsize)
     627{
     628}
     629#else
     630area *
     631create_reserved_area(natural totalsize)
     632{
    594633  Ptr h;
    595   natural base, n;
     634  natural base;
    596635  BytePtr
    597636    end,
    598637    lastbyte,
    599638    start,
    600     protstart,
    601     p,
    602     want = (BytePtr)IMAGE_BASE_ADDRESS,
    603     try2;
     639    want = (BytePtr)IMAGE_BASE_ADDRESS;
    604640  area *reserved;
    605641  Boolean fixed_map_ok = false;
     
    649685               totalsize + heap_segment_size,
    650686               PROT_NONE,
    651                MAP_PRIVATE | MAP_ANON | (fixed_map_ok ? MAP_FIXED : 0, MAP_NORESERVE),
     687               MAP_PRIVATE | MAP_ANON | (fixed_map_ok ? MAP_FIXED : 0) | MAP_NORESERVE,
    652688               -1,
    653689               0);
     
    659695  if (start != want) {
    660696    munmap(start, totalsize+heap_segment_size);
    661     start = (void *)((((unsigned long)start)+heap_segment_size-1) & ~(heap_segment_size-1));
     697    start = (void *)((((natural)start)+heap_segment_size-1) & ~(heap_segment_size-1));
    662698    if(mmap(start, totalsize, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE, -1, 0) != start) {
    663699      return NULL;
     
    667703
    668704  h = (Ptr) start;
    669   base = (unsigned long) start;
     705  base = (natural) start;
    670706  image_base = base;
    671707  lastbyte = (BytePtr) (start+totalsize);
     
    681717  */
    682718  end = lastbyte;
    683   end = (BytePtr) ((unsigned long)((((unsigned long)end) - ((totalsize+63)>>6)) & ~4095));
     719  end = (BytePtr) ((natural)((((natural)end) - ((totalsize+63)>>6)) & ~4095));
    684720
    685721  global_mark_ref_bits = (bitvector)end;
    686   end = (BytePtr) ((unsigned long)((((unsigned long)end) - ((totalsize+63) >> 6)) & ~4095));
     722  end = (BytePtr) ((natural)((((natural)end) - ((totalsize+63) >> 6)) & ~4095));
    687723  global_reloctab = (LispObj *) end;
    688724  reserved = new_area(start, end, AREA_VOID);
     
    693729  return reserved;
    694730}
    695 
     731#endif
    696732
    697733void *
     
    722758  natural
    723759    ndnodes = area_dnode(lisp_global(HEAP_END),lisp_global(HEAP_START)),
    724     npages = (lisp_global(HEAP_END)-lisp_global(HEAP_START)) >> log2_page_size,
    725760    markbits_size = (3*sizeof(LispObj))+((ndnodes+7)>>3),
    726761    reloctab_size = (sizeof(LispObj)*(((ndnodes+((1<<bitmap_shift)-1))>>bitmap_shift)+1));
     
    762797  a->softprot = NULL;
    763798  a->hardprot = NULL;
     799  lisp_global(HEAP_START) = ptr_to_lispobj(a->low);
     800  lisp_global(HEAP_END) = ptr_to_lispobj(a->high);
    764801  ensure_gc_structures_writable();
    765802  return a;
     
    835872register_sigint_handler()
    836873{
     874  extern void install_signal_handler(int, void*);
    837875  install_signal_handler(SIGINT, (void *)sigint_handler);
    838876}
     
    848886    p += (1+strlen(p));
    849887  }
    850   return (BytePtr)((((unsigned long) p) +4095) & ~4095);
     888  return (BytePtr)((((natural) p) +4095) & ~4095);
    851889}
    852890
     
    908946  }
    909947  work = base;
    910   while (c = *work) {
     948  while ((c = *work) != '\0') {
    911949    if (islower(c)) {
    912950      *work++ = toupper(c);
     
    10781116      } else if ((flag = (strncmp(arg, "-R", 2) == 0)) ||
    10791117                 (strcmp(arg, "--heap-reserve") == 0)) {
    1080         natural reserved_size;
     1118        natural reserved_size = reserved_area_size;
    10811119
    10821120        if (flag && arg[2]) {
     
    11541192           thread_stack_size = stack_size;
    11551193          }
    1156           if (thread_stack_size >= (1L<<((WORD_SIZE-fixnumshift)-1))) {
    1157             thread_stack_size = (1L<<((WORD_SIZE-fixnumshift)-1))-1;
     1194          if (thread_stack_size >= (1LL<<((WORD_SIZE-fixnumshift)-1))) {
     1195            thread_stack_size = (1LL<<((WORD_SIZE-fixnumshift)-1))-1;
    11581196          }
    11591197         
     
    11891227}
    11901228
     1229#ifdef WINDOWS
     1230void
     1231terminate_lisp()
     1232{
     1233}
     1234#else
    11911235pid_t main_thread_pid = (pid_t)0;
    11921236
     
    11971241  _exit(-1);
    11981242}
     1243#endif
    11991244
    12001245#ifdef DARWIN
     
    12671312
    12681313#ifdef X8664
     1314#ifdef WINDOWS
    12691315void
    12701316remap_spjump()
    12711317{
     1318}
     1319#else
     1320void
     1321remap_spjump()
     1322{
    12721323  extern opcode spjump_start;
    1273   pc new = mmap((pc) 0x5000,
     1324  pc new = mmap((pc) 0x15000,
    12741325                0x1000,
    12751326                PROT_READ | PROT_WRITE | PROT_EXEC,
     
    12851336}
    12861337#endif
     1338#endif
     1339
    12871340
    12881341void
    12891342check_os_version(char *progname)
    12901343{
     1344#ifdef WINDOWS
     1345#else
    12911346  struct utsname uts;
     1347  long got, want;
     1348  char *got_end,*want_end;
     1349  want = strtoul(min_os_version,&want_end,10);
    12921350
    12931351  uname(&uts);
    1294   if (strcmp(uts.release, min_os_version) < 0) {
     1352  got = strtoul(uts.release,&got_end,10);
     1353
     1354  while (got == want) {
     1355    if (*want_end == '.') {
     1356      want = strtoul(want_end+1,&want_end,10);
     1357      got = 0;
     1358      if (*got_end == '.') {
     1359        got = strtoul(got_end+1,&got_end,10);
     1360      } else {
     1361        break;
     1362      }
     1363    } else {
     1364      break;
     1365    }
     1366  }
     1367
     1368  if (got < want) {
    12951369    fprintf(stderr, "\n%s requires %s version %s or later; the current version is %s.\n", progname, uts.sysname, min_os_version, uts.release);
    12961370    exit(1);
     
    13081382#endif
    13091383#endif
     1384#endif
    13101385}
    13111386
     
    13151390  probably complain if we don't have (at least) SSE2.
    13161391*/
    1317 extern int cpuid(int, int*, int*, int*);
     1392extern int cpuid(natural, natural*, natural*, natural*);
    13181393
    13191394#define X86_FEATURE_CMOV    (1<<15)
     
    13281403check_x86_cpu()
    13291404{
    1330   int eax, ebx, ecx, edx;
     1405  natural eax, ebx, ecx, edx;
    13311406 
    13321407  eax = cpuid(0, &ebx, &ecx, &edx);
     
    13821457#endif
    13831458
     1459Boolean
     1460bogus_fp_exceptions = false;
     1461
     1462typedef
     1463float (*float_arg_returns_float)(float);
     1464
     1465float
     1466fcallf(float_arg_returns_float fun, float arg)
     1467{
     1468  return fun(arg);
     1469}
     1470
     1471void
     1472check_bogus_fp_exceptions()
     1473{
     1474#ifdef X8664
     1475  float asinf(float),result;
     1476   
     1477
     1478  natural save_mxcsr = get_mxcsr(), post_mxcsr;
     1479  set_mxcsr(0x1f80);
     1480
     1481  result = fcallf(asinf, 1.0);
     1482  post_mxcsr = get_mxcsr();
     1483  set_mxcsr(save_mxcsr);
     1484  if (post_mxcsr & (FE_ALL_EXCEPT & (~FE_INEXACT))) {
     1485    bogus_fp_exceptions = true;
     1486  }
     1487#endif
     1488}
     1489
     1490
     1491int
    13841492main(int argc, char *argv[], char *envp[], void *aux)
    13851493{
     
    13901498#endif
    13911499  extern LispObj load_image(char *);
    1392   long resp;
    1393   BytePtr stack_end;
    13941500  area *a;
    13951501  BytePtr stack_base, current_sp = (BytePtr) current_stack_pointer();
    13961502  TCR *tcr;
    1397   int i;
    13981503
    13991504  check_os_version(argv[0]);
     
    14011506  page_size = getpagesize();
    14021507
     1508  check_bogus_fp_exceptions();
    14031509#ifdef LINUX
    14041510#ifdef X8664
     
    14691575#endif
    14701576
     1577#ifndef WINDOWS
    14711578  main_thread_pid = getpid();
     1579#endif
    14721580  tcr_area_lock = (void *)new_recursive_lock();
    14731581
     
    14971605  lisp_global(TCR_AREA_LOCK) = ptr_to_lispobj(tcr_area_lock);
    14981606
     1607#ifdef X8664
     1608  lisp_global(SUBPRIMS_BASE) = (LispObj)((1<<16)+(5<<10));
     1609#else
    14991610  lisp_global(SUBPRIMS_BASE) = (LispObj)(5<<10);
     1611#endif
    15001612  lisp_global(RET1VALN) = (LispObj)&ret1valn;
    15011613  lisp_global(LEXPR_RETURN) = (LispObj)&nvalret;
     
    15751687#endif
    15761688  tcr->prev = tcr->next = tcr;
     1689#ifndef WINDOWS
    15771690  lisp_global(INTERRUPT_SIGNAL) = (LispObj) box_fixnum(SIGNAL_FOR_PROCESS_INTERRUPT);
     1691#endif
    15781692  tcr->vs_area->active -= node_size;
    15791693  *(--tcr->save_vsp) = nrs_TOPLFUNC.vcell;
     
    16061720{
    16071721  extern void flush_cache_lines();
    1608   unsigned long ustart = (unsigned long) start, base, end;
     1722  natural ustart = (natural) start, base, end;
    16091723 
    16101724  base = (ustart) & ~(cache_block_size-1);
     
    16311745
    16321746#ifndef DARWIN
     1747#ifdef WINDOWS
    16331748void *
    16341749xGetSharedLibrary(char *path, int mode)
    16351750{
     1751}
     1752#else
     1753void *
     1754xGetSharedLibrary(char *path, int mode)
     1755{
    16361756  return dlopen(path, mode);
    16371757}
     1758#endif
    16381759#else
    16391760void *
     
    17631884}
    17641885
     1886#ifdef WINDOWS
    17651887int
    17661888do_fd_is_set(int fd, fd_set *fdsetp)
    17671889{
     1890}
     1891#else
     1892int
     1893do_fd_is_set(int fd, fd_set *fdsetp)
     1894{
    17681895  return FD_ISSET(fd,fdsetp);
    17691896}
     1897#endif
    17701898
    17711899void
     
    18121940  }
    18131941  if (image_nil == 0) {
    1814     fprintf(stderr, "Couldn't load lisp heap image from %s\n", path);
     1942    fprintf(stderr, "Couldn't load lisp heap image from %s:\n%s\n", path, strerror(errno));
    18151943    exit(-1);
    18161944  }
     
    18802008
    18812009
     2010#ifdef DARWIN
     2011void
     2012sample_paging_info(paging_info *stats)
     2013{
     2014  mach_msg_type_number_t count = TASK_EVENTS_INFO_COUNT;
     2015
     2016  task_info(mach_task_self(),
     2017            TASK_EVENTS_INFO,
     2018            (task_info_t)stats,
     2019            &count);
     2020}
     2021
     2022void
     2023report_paging_info_delta(FILE *out, paging_info *start, paging_info *stop)
     2024{
     2025  fprintf(out,";;; %d soft faults, %d faults, %d pageins\n\n",
     2026          stop->cow_faults-start->cow_faults,
     2027          stop->faults-start->faults,
     2028          stop->pageins-start->pageins);
     2029}
     2030
     2031#else
     2032#ifdef WINDOWS
     2033void
     2034sample_paging_info(paging_info *stats)
     2035{
     2036}
     2037
     2038void
     2039report_paging_info_delta(FILE *out, paging_info *start, paging_info *stop)
     2040{
     2041}
     2042#else
     2043void
     2044sample_paging_info(paging_info *stats)
     2045{
     2046  getrusage(RUSAGE_SELF, stats);
     2047}
     2048
     2049void
     2050report_paging_info_delta(FILE *out, paging_info *start, paging_info *stop)
     2051{
     2052  fprintf(out,";;; %ld soft faults, %ld faults, %ld pageins\n\n",
     2053          stop->ru_minflt-start->ru_minflt,
     2054          stop->ru_majflt-start->ru_majflt,
     2055          stop->ru_nswap-start->ru_nswap);
     2056}
     2057
     2058#endif
     2059#endif
Note: See TracChangeset for help on using the changeset viewer.