c.m4.mipsy 15.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
divert(-1)

dnl Copyright (C) 1996-1998 by the Board of Trustees
dnl   of Leland Stanford Junior University.
dnl 
dnl This file is part of the SimOS distribution. 
dnl See LICENSE file for terms of the license. 

dnl --------------------------------------------------------------------
dnl  c.m4.mipsy:  m4 macro definitions for use with Solo Mipsy or IRIX.
dnl  This file implements a high-level synchronization model for "C".
dnl 
dnl  Steve Herrod
dnl  10/19/95
dnl --------------------------------------------------------------------

dnl ----------------------------------------------------------------------
dnl ENVIRONMENT SETUP
dnl ----------------------------------------------------------------------

define(MAIN_ENV, `
#include <stdlib.h>
#include <stdarg.h>
#include "solo_interface.h"

int _in_solo_mode;
int _num_procs = 1;


')

define(EXTERN_ENV, `
#include <stdlib.h>
#include "solo_interface.h"

extern int _in_solo_mode;
extern int _num_procs;
')

dnl ----------------------------------------------------------------------
dnl INITIALIZATION CALLS
dnl ----------------------------------------------------------------------

define(MAIN_INITENV, `INITENV($1,$2)')

dnl -----------------------------------------------------------------------
dnl We use a system call hack to determine if the application is
dnl running directly on irix or on top of solo mipsy. Based on the 
dnl return value, we initialize the communication area appropriately.
dnl -----------------------------------------------------------------------

define(INITENV, `
    if (_CheckPlatform() == 51071) {
       _in_solo_mode = 1;
       CommAreaPtr->SetupCommArea();
       CommAreaPtr->libcStart = &LibcStart;
       fprintf(stderr, "M: Running on top of solo mipsy\n");
    } else {
       _in_solo_mode = 0;
       IrixSetupCommArea();
       fprintf(stderr, "M: Running on an IRIX machine\n");       
    }
')



dnl ----------------------------------------------------------------------
dnl INSTRUCTION REPLACEMENTS
dnl
dnl We can't get ld, sd, or sync to compile in quite yet, so we use these
dnl calls to the support library. These routines should be made into
dnl asm() calls so that the compiler can deal with them better.
dnl ----------------------------------------------------------------------
define(SYNC_OP, `_Sync();')

define(LD, `_LoadDouble((unsigned long long *)($1));')

define(SD, `_StoreDouble((unsigned long long *)($1),
        (unsigned long long)($2));')


dnl ----------------------------------------------------------------
dnl NON-SYNCHRONIZATION CALLS
dnl ----------------------------------------------------------------

define(CLOCK, `$1 = CommAreaPtr->CurrentTime();')

define(MAIN_END, `{
  fflush(stdout); 
  fflush(stderr); 
  SYNC_OP();
  _Exit();
}')

define(CREATE, `{
  SYNC_OP; 
  CommAreaPtr->Create((Func) $1);
  _num_procs++;
}')

define(GET_PID, `$1 = CommAreaPtr->GetCPUNum();')

define(RESET_STATS, `CommAreaPtr->ResetStats();')

define(AUG_ON,  `
  fprintf(stderr, "M: aug on command is not supported\n");
')

define(AUG_OFF, `
fprintf(stderr, "M: aug off command is not supported\n");
')

dnl ----------------------------------------------------------------
dnl CACHE-RELATED CALLS
dnl ----------------------------------------------------------------
define(CACHE_ON,  `CommAreaPtr->TurnOnCaches(); ')

define(CACHE_OFF, `CommAreaPtr->TurnOffCaches(); ')

dnl FLUSH_LINE will spin until it succeeds, to allow it to be
dnl preempted if necessary.

define(FLUSH_LINE, `while (!CommAreaPtr->Flush((void *) ($1)));');

dnl ----------------------------------------------------------------
dnl SYNCHRONIZATION CALLS
dnl ----------------------------------------------------------------

dnl -------------------------------------------------------------------------
dnl LOCK implementation 
dnl THESE NEED TO BE DEFINED FIRST SO IT EXPANDS CORRECTLY!
dnl -------------------------------------------------------------------------

dnl -----------------------------
dnl        _FAKELOCK MACROS
dnl
dnl This is a pure magic lock implementation: No application caching occurs
dnl for these locks, but it also avoids problems where the application
dnl mistakenly caches lock data structures, in conflict with backdoor calls.
dnl
dnl -----------------------------

define(_FAKELOCKDEC, `void * $1;')
define(_FAKELOCKINIT, `$1 = CommAreaPtr->LockInit();')
dnl The lock MUST be set by the RETURN VALUE of this call.  That's because
dnl we want the lock POINTER to be cached by the user, but the user
dnl should never dereference this pointer!!

define(_FAKELOCK, `CommAreaPtr->LockEnter(); while (!CommAreaPtr->Lock($1)) ;')
define(_FAKEUNLOCK, `SYNC_OP  CommAreaPtr->Unlock($1);')

dnl -----------------------------
dnl        _REALLOCK MACROS
dnl
dnl Real LL/SC locks. 
dnl -----------------------------

define(_REALLOCKDEC, `
      struct { 
          int _pad1[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];
          unsigned int lock; 
          int _pad2[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];
      } $1; ')

define(_REALLOCKDEC_UNPADDED, `
      struct { 
          unsigned int lock; 
      } $1; ')

define(_REALLOCKINIT, `$1.lock = 0;')

define(_REALLOCK, `_LockEnter(&($1.lock));')
define(_REALUNLOCK, `_Unlock(&($1.lock));')

define(LOCKDEC, 
    `
#ifdef FAKE_LOCKS
     _FAKELOCKDEC($1)
#else
#ifndef NO_PADDED_LOCKS
     _REALLOCKDEC($1)
#else
     _REALLOCKDEC_UNPADDED($1)
#endif
#endif
    ')

define(LOCKDEC_UNPADDED, 
    `
#ifdef FAKE_LOCKS
     _FAKELOCKDEC($1)
#else
     _REALLOCKDEC_UNPADDED($1)
#endif
    ')

define(LOCKINIT, 
    `
#ifdef FAKE_LOCKS
     _FAKELOCKINIT($1)
#else
     _REALLOCKINIT($1)
#endif
    ')
define(LOCK, 
    `
#ifdef FAKE_LOCKS
     _FAKELOCK($1)
#else
     _REALLOCK($1)
#endif
    ')
define(UNLOCK, 
    `
#ifdef FAKE_LOCKS
     _FAKEUNLOCK($1)
#else
     _REALUNLOCK($1)
#endif
    ')

define(_FAKEALOCKDEC, `_FAKELOCKDEC($1[$2])')
define(_FAKEALOCKINIT, 
  `{
      int _soloi;
      for(_soloi = 0; _soloi < $2; _soloi++) {
        _FAKELOCKINIT($1[_soloi])
      }
   }')
define(_FAKEALOCK, `_FAKELOCK($1[$2])')
define(_FAKEAULOCK, `_FAKEUNLOCK($1[$2])')

define(_REALALOCKDEC, `
        struct {
             int _pad1[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];      
             struct {
                unsigned int lock;
                int _pad1[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];      
             } _alock[$2];
        } $1; ')

define(_REALALOCKDEC_UNPADDED, `
        struct {
             struct {
                unsigned int lock;
             } _alock[$2];
        } $1; ')


define(_REALALOCKINIT, 
  `{
      int _soloi;
      for(_soloi = 0; _soloi < $2; _soloi++) {
       $1._alock[_soloi].lock = 0;
      }
   }')


define(_REALALOCK, `_LockEnter(&$1._alock[$2].lock);')
define(_REALAULOCK, `_Unlock(&$1._alock[$2].lock);')


define(ALOCKDEC, 
    `
#ifdef FAKE_LOCKS
     _FAKEALOCKDEC($1,$2)
#else
#ifndef NO_PADDED_LOCKS
     _REALALOCKDEC_UNPADDED($1,$2)
#else
     _REALALOCKDEC($1,$2)
#endif
#endif
    ')

define(ALOCKDEC_UNPADDED, 
    `
#ifdef FAKE_LOCKS
     _FAKEALOCKDEC($1,$2)
#else
     _REALALOCKDEC_UNPADDED($1,$2)
#endif
    ')

define(ALOCKINIT, 
    `
#ifdef FAKE_LOCKS
     _FAKEALOCKINIT($1,$2)
#else
     _REALALOCKINIT($1,$2)
#endif
    ')
define(ALOCK, 
    `
#ifdef FAKE_LOCKS
     _FAKEALOCK($1,$2)
#else
     _REALALOCK($1,$2)
#endif
    ')
define(AULOCK, 
    `
#ifdef FAKE_LOCKS
     _FAKEAULOCK($1,$2)
#else
     _REALAULOCK($1,$2)
#endif
    ')


dnl ----------------------------------------------------------------------
dnl BARRIER implementations.
dnl ----------------------------------------------------------------------

dnl -----------------------------
dnl       SLOW BARRIER MACROS
dnl
dnl This barrier works fine, since LOCK (the field itself) is never modified
dnl backdoor. This other information can be done in this way just fine.
dnl -----------------------------
define(_SLOWBARDEC, `
  struct $1_BARRIER_TYP {
    LOCKDEC(lock)
    volatile int count;
    volatile int spin;
    volatile int inuse;
  } $1;
')

define(_SLOWBARINIT, 
`{
	LOCKINIT($1.lock)
	$1.count = 0;
	$1.spin  = 1;
	$1.inuse = 0;
}')


define(_SLOWBARRIER, 
`{
   SYNC_OP
   CommAreaPtr->BarEnter();
   while ($1.inuse)
     ;
   LOCK($1.lock)
   if ($1.count++ < ($2 - 1)) {
     UNLOCK($1.lock)
     while($1.spin)
       ;
     LOCK($1.lock)
   } else { 
     $1.inuse = 1;
     $1.spin  = 0;
   }
   if (--$1.count == 0) {
    $1.spin  = 1;
    $1.inuse = 0;
   }
   UNLOCK($1.lock)
   CommAreaPtr->BarExit();
}')



dnl -----------------------------
dnl       REAL BARRIER MACROS
dnl
dnl -----------------------------
define(_REALBARDEC, `
  struct $1_BARRIER_TYP {
    long long _pad1[(SOLO_CACHE_LINE_SIZE/sizeof(long long))-1];
    unsigned int count;
    unsigned int prefetch_loc;
    int _pad2[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];
    unsigned int generationNumber;
    int _pad3[(SOLO_CACHE_LINE_SIZE/sizeof(int))-1];           
  } $1;
')

define(_REALBARINIT, 
`{
	$1.count = 0;
	$1.generationNumber  = 0;
}')

define(_REALBARRIER, `_Barrier(&$1.count,$2);')

define(BARDEC, 
   `
#ifdef SLOW_BARRIER
     _SLOWBARDEC($1)
#else
     _REALBARDEC($1)
#endif
    ')

define(BARINIT, 
   `
#ifdef SLOW_BARRIER
     _SLOWBARINIT($1)
#else
     _REALBARINIT($1)
#endif
    ')

define(BARRIER,
   `
#ifdef SLOW_BARRIER
     _SLOWBARRIER($1,$2)
#else
     _REALBARRIER($1,$2)
#endif
    ')


dnl -----------------------------
dnl    PREFETCH MACROS
dnl
define(PREFETCH, `_Prefetch($1);')
define(PREFETCHX, `_PrefetchX($1);')

dnl -----------------------------
dnl    PLACEMENT MACROS
dnl
define(sys_place_range, `CommAreaPtr->PlaceRange((unsigned)($1),
	(unsigned)($2), (unsigned)($3));')
define(SYS_PLACE_RANGE, `{sys_place_range($1, $2, $3);}')

dnl -----------------------------
dnl    MALLOC MACROS
dnl
dnl renamed functions:

define(G_MALLOC, `malloc($1);')
define(P_MALLOC, `$1 = G_MALLOC($2);
	CommAreaPtr->PlaceRange((unsigned)($1),
                                (unsigned)($1) + (unsigned)($2),
				 CommAreaPtr->GetCPUNum())
');


dnl -----------------------------
dnl     PAUSE stuff
dnl -----------------------------

define(PAUSEDEC, `
struct $1_PAUSE_STRUCT {
  LOCKDEC(lock)
  volatile  int flag;
} $1;
')

define(PAUSEINIT, `
{ 
  $1.flag = 0;
  LOCKINIT($1.lock)
}
');

define(CLEARPAUSE, `
  $1.flag = 0;
');

define(SETPAUSE, `
{
  LOCK($1.lock)
  $1.flag = 1;
  UNLOCK($1.lock)
}
');

define(WAITPAUSE, `
{
  while (($1.flag) == 0);
}
');



dnl -----------------------------
dnl    MSG/IO MAPPING MACROS
dnl -----------------------------

define(IO_MAP, `CommAreaPtr->IOMap((unsigned) $1,$2);')
dnl Usage: IO_MAP(VA, PA);
dnl VA that is passed can be used in the future directly to access the
dnl   requested PA range. Be sure VA goes in page aligned!!
dnl PA BETTER BE long long, or WATCH OUT!!

dnl NOTE: 6/96 IOMapAccelerated isn't yet implemented in the CommArea vector
define(IO_MAP_ACCELERATED, `CommAreaPtr->IOMapAccelerated((unsigned) $1,$2);')
dnl Usage: IO_MAP_ACCELERATED(VA, PA);
dnl VA that is passed can be used in the future directly to access the
dnl   requested PA range. Be sure VA goes in page aligned!!
dnl PA BETTER BE long long, or WATCH OUT!!

define(IO_MAP_GENERAL, `CommAreaPtr->IOMapGeneral((unsigned) $1,$2,$3);')
dnl JH: This allows all the parameters to be set from the application level,
dnl    to let me set a range of functions without specific macros for each.
dnl    This effectively obsoletes the macros above, but I'll keep them for
dnl    backward compatbility.
dnl Usage: IO_MAP(VA, details, PA);
dnl 
dnl details == IO_MAP_UNCACHED | IO_MAP_ACCELERATED | space
dnl   where UNCACHED and ACCELERATED are flags present as appropriate
dnl
dnl Be sure VA goes in page aligned!!
dnl PA BETTER BE long long, or WATCH OUT!!


define(MSG_SPACE, `((void *) ((int)($1) | 0x80000000))')
dnl
dnl This is an expression macro...to use it, you'd say:
dnl *(MSG_SPACE_FLAG(pointer)) = value
dnl to issue an uncached write in the message space for a particular
dnl VA.  This dynamically creates a mapping, if required.

dnl **********************************************************************
dnl FIXTHIS: functions below here are poorly or incorrectly implemented
dnl **********************************************************************

define(WAIT_FOR_END, `

      if (_in_solo_mode) {
        int active;

        active = CommAreaPtr->ActiveProcs();
        while (active != (_num_procs - ($1))) {
          active = CommAreaPtr->ActiveProcs(); 
        }
      } else {
        CommAreaPtr->WaitForEnd(1);
      }
')

define(ENDLAB, 1000)
define(AUG_STACK, 0)

define(ST_LOG, `;')

dnl **********************************************************************
dnl FIXTHIS: functions below here are not currently provided
dnl **********************************************************************

dnl  define(AUG_ON, 
dnl  `define(`AUG_STACK',incr(AUG_STACK))ifelse(AUG_STACK,1,`@@aug_ON@@')ifelse(AUG_STACK,0,`
dnl #ifdef AUG
dnl aug_on_();
dnl #endif
dnl ')')
dnl define(AUG_OFF, `define(`AUG_STACK',eval(AUG_STACK-1))ifelse(AUG_STACK,-1,`
dnl #ifdef AUG
dnl aug_off_();
dnl #endif
dnl ')')
dnl 
dnl define(AUG_DELAY, `{AUG_OFF SYS_THREAD_PTR->clock+=($1);AUG_ON}')
dnl define(DECVAR, `struct $1TYP{sys_mon_t mon;$4}$1[ifelse($3,,1,$3)];')
dnl define(GET_PID_F, `(SYS_THREAD_PTR->user_pid)')
dnl 
dnl 
dnl 
dnl define(NU_MALLOC_F, `sim_malloc($1,$2,__LINE__,__FILE__)')
dnl define(NU_MALLOC, `NU_MALLOC_F($1,$2);')
dnl define(ST_LOG, `{AUG_OFF sim_sync_event($1,ifelse($2,,-1,(int)($2)),ifelse($3,,-1,(int)($3)),ifelse($4,,-1,(int)($4)),ifelse($5,,-1,(int)($5)),__LINE__,__FILE__);AUG_ON}')
dnl 
dnl define(G_MALLOC_F, `NU_MALLOC_F($1,PAGE_GENERIC)')
dnl define(G_FREE, `NU_FREE($1)')
dnl 
dnl 
dnl define(GET_HOME, `{int sys_r,sys_a=(int)($2);
dnl   ST_LOG(ST_GET_PAGETYPE,&sys_r,sys_a)($1)=sys_r;}')
dnl 
dnl 
dnl define(NU_FREE, `{int sys_a=(int)($1);ST_LOG(ST_GFREE,sys_a)}')
dnl define(SET_HOME, `{int sys_a=(int)&($1),sys_b=(int)($2);
dnl   ST_LOG(ST_SET_PAGETYPE,sys_a,sys_b)}')
dnl 
dnl define(MONINIT, `{unsigned sys_i;int sys_b=(int)($2);
dnl   for(sys_i=0;sys_i<(ifelse($3,,1,$3));sys_i++){int sys_a=(int)&(($1)[sys_i]);
dnl     ST_LOG(ST_MONINIT,sys_a,sys_b)}}')
dnl define(MENTER, `{int sys_a=(int)&(($1)[ifelse($2,,0,$2)]);
dnl   ST_LOG(ST_MENTER,sys_a)}')
dnl define(DELAY, `{int sys_a=(int)&(($1)[ifelse($3,,0,$3)]),sys_b=(int)(ifelse($2,,0,$2));
dnl   ST_LOG(ST_DELAY,sys_a,sys_b)}')
dnl define(CONTINUE, `{int sys_a=(int)&(($1)[ifelse($3,,0,$3)]),sys_b=(int)(ifelse($2,,0,$2));
dnl   ST_LOG(ST_CONTINUE,sys_a,sys_b)if(sys_t())goto `L'ENDLAB;}')
dnl define(MEXIT, `{int sys_a=(int)&(($1)[ifelse($2,,0,$2)]);
dnl   ST_LOG(ST_MEXIT,sys_a)`L'ENDLAB:define(`ENDLAB',incr(ENDLAB));}')
dnl 
dnl define(SEMDEC, `sys_sem_t ($1)[ifelse($2,,1,$2)];')
dnl define(SEMINIT, `{unsigned sys_k;int sys_a,sys_b=(int)($2);
dnl   for(sys_k=0;sys_k<(ifelse($3,,1,$3));sys_k++){
dnl     sys_a=(int)&(($1)[sys_k]);ST_LOG(ST_SEM_INIT,sys_a,sys_b)}}')
dnl define(SEMP, `{int sys_a=(int)&(($1)[ifelse($2,,0,$2)]);
dnl   ST_LOG(ST_SEM_OP,sys_a,-1)}')
dnl define(SEMV, `{int sys_a=(int)&(($1)[ifelse($2,,0,$2)]);
dnl   ST_LOG(ST_SEM_OP,sys_a,1)}')
dnl 
dnl define(GSDEC, `sys_gs_t ($1)[ifelse($2,,1,$2)];')
dnl define(GSINIT, `{unsigned sys_k;
dnl   for(sys_k=0;sys_k<(ifelse($2,,1,$2));sys_k++){
dnl     int sys_a=(int)&(($1)[sys_k]);ST_LOG(ST_GS_INIT,sys_a)}}')
dnl define(GETSUB, `{
dnl   int sys_a=(int)&(($1)[ifelse($5,,0,$5)]),sys_b=(int)&($2),sys_c=(int)($3),sys_d=(int)($4);
dnl   ST_LOG(ST_GS_ENTER,sys_a,sys_b,sys_c,sys_d)}')
dnl define(WEAKGETSUB, `{
dnl   int sys_a=(int)&(($1)[ifelse($4,,0,$4)]),sys_b=(int)&($2),sys_c=(int)($3);
dnl   ST_LOG(ST_GS_EXIT,sys_a,sys_b,sys_c)}')
dnl 
dnl 
dnl 
dnl define(NLOCKDEC, `LOCKDEC($1,$2)')
dnl define(NLOCKINIT, `LOCKINIT($1,$2)')
dnl define(NLOCK, `LOCK($1,$2)')
dnl define(NUNLOCK, `UNLOCK($1,$2)')
dnl 


divert(0)