Пример #1
0
void Clock_exit( void )
{
  /* shutdown the periodic interrupt */
  *PICR = (unsigned short int)
    ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );
  /*     ^^ zero disables interrupt */

  /* do not restore old vector */
}
Пример #2
0
void Install_clock(
  rtems_isr_entry clock_isr
)
{
  Clock_driver_ticks = 0;
  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;

  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );

  /* enable 1mS interrupts */
  *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */
  *PICR = (unsigned short int)                     /* enable interrupt */
    ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );

  atexit( Clock_exit );
}
Пример #3
0
bool_t SAM(divisor& x, const divisor& a, const ZZ& n)
     // Square and multiply
     // cf. Pg 146, Alg. 9.1 of HOEHCC
{
  assert(a.is_valid_divisor());

  bool_t OK = TRUE;

  long nbits;

  divisor b;

  if (n < 0) { // n < 0
    OK = OK && SAM(x, a, -n);
    OK = OK && dnegate(x, x);
    return OK;
  }

  // n >= 0
  nbits = NumBits(n);
  b.set_unit(); // Set x = unit

  for( --nbits; nbits >= 0; --nbits) {
    OK = OK && add(b, b, b);

    if ( bit(n, nbits) ) 
      OK = OK && add(b, a, b);
  }

  assert(b.is_valid_divisor());

  x = b;  

#if DEBUG_LEVEL > 1
  cout << "SAM visited" << endl;
#endif

  return OK;

}
/**@brief Main routine of L-Galaxies*/
int main(int argc, char **argv)
{
  int filenr, *FileToProcess, *TaskToProcess, nfiles;
  char buf[1000];
  time_t start, current;


#ifdef PARALLEL
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
#else
  NTask = 1;
  ThisTask = 0;
#endif //PARALLEL

#ifdef MCMC
  time(&global_starting_time);
#endif


  if(ThisTask==0)
    {
 	  printf("\n\n\n");
 	  printf("**************************************************************************\n");
 	  printf("*                                                                        *\n");
 	  printf("*                   Copyright (C) <2016>  <L-Galaxies>                   *\n");
 	  printf("*                                                                        *\n");
 	  printf("*  This program is free software: you can redistribute it and/or modify  *\n");
 	  printf("*  it under the terms of the GNU General Public License as published by  *\n");
 	  printf("*  the Free Software Foundation, either version 3 of the License, or     *\n");
 	  printf("*  (at your option) any later version.                                   *\n");
 	  printf("*                                                                        *\n");
 	  printf("*  This program is distributed in the hope that it will be useful,       *\n");
 	  printf("*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *\n");
 	  printf("*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *\n");
 	  printf("*  GNU General Public License for more details.                          *\n");
 	  printf("*                                                                        *\n");
 	  printf("*  You should have received a copy of the GNU General Public License     *\n");
 	  printf("*  along with this program.  If not, see <http://www.gnu.org/licenses/>  *\n");
 	  printf("*                                                                        *\n");
 	  printf("**************************************************************************\n\n\n");
    }

  if(argc > 3 || argc<2)
    {
	  printf("\n  Wrong number of runtime arguments\n\n");
      printf("\n  usage: ./L-Galaxies <parameterfile>\n\n");
      endrun(0);
    }

 if (ThisTask == 0)
   printf("%s\n",COMPILETIMESETTINGS); 

 /* check compatibility of some Makefile Options*/
  check_options();

  /*Reads the parameter file, given as an argument at run time. */
  read_parameter_file(argv[1]);

#ifdef MR_PLUS_MRII
  //Start with MR files and later change to MRII
  LastDarkMatterSnapShot=LastDarkMatterSnapShot_MR;
  sprintf(FileWithZList, "%s", FileWithZList_MR);
  sprintf(FileWithZList_OriginalCosm, "%s", FileWithZList_OriginalCosm_MR);
#endif

  mymalloc_init();

  sprintf(FinalOutputDir, "%s", OutputDir);
#ifndef MCMC
  if(argc == 3)
	sprintf(OutputDir, "%s", argv[2]);
#else
  FirstChainNumber=0;
  if(argc == 3)
  	FirstChainNumber=atoi(argv[2]);
#endif

  //time(&start);


#ifdef COMPUTE_SPECPHOT_PROPERTIES
  //for dust_model
  mu_seed = -150;
#endif

  init();

#ifdef STAR_FORMATION_HISTORY
#ifdef PARALLEL
  if(ThisTask == 0)
#endif
    write_sfh_bins();
#endif



#ifndef MCMC
  nfiles=get_nr_files_to_process(ThisTask);
  FileToProcess=mymalloc("FileToProcess", sizeof(int) * nfiles);
  TaskToProcess=mymalloc("TaskToProcess", sizeof(int) * nfiles);
  assign_files_to_tasks(FileToProcess, TaskToProcess, ThisTask, NTask, nfiles);

  int file;
  for(file = 0; file < nfiles; file++)
    {
	  if(ThisTask==TaskToProcess[file])
		  filenr=FileToProcess[file];
	  else
		  continue;
#else //MCMC
  /* In MCMC mode only one file is loaded into memory
   * and the sampling for all the steps is done on it */
	sprintf(SimulationDir, "%s/", SimulationDir);
  for(filenr = MCMCTreeSampleFile; filenr <= MCMCTreeSampleFile; filenr++)
	{
#endif //MCMC
	  time(&start);

	  #ifdef PARALLEL
#ifndef MCMC
	  time_t current;
	  do
	  	time(&current);
	  //while(difftime(current, start) < 5.0 * ThisTask);
	  while(difftime(current, start) < 1.0 * ThisTask);

#endif
#endif

	  load_tree_table(filenr);
#ifdef MCMC
      Senna(); // run the model in MCMC MODE
#else
      SAM(filenr); // run the model in NORMAL MODE
#endif

#ifdef MCMC
      break;	//break loop on files since the MCMC is done on a single file
#else
      time(&current);
      printf("\ndone tree file %d in %ldmin and %lds\n\n", filenr, (current - start)/60, (current - start)%60);

#endif //MCMC
      free_tree_table();
      //if temporary directory given as argument
       if(argc == 3)
         {
#ifdef GALAXYTREE
    	   sprintf(buf, "mv %s/%s_galtree_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir);
#else
    	   sprintf(buf, "mv %s/%s_z*_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir);
#endif
    	   system(buf);
         }
    }

#ifndef MCMC
  myfree(TaskToProcess);
  myfree(FileToProcess);
#endif

#ifdef PARALLEL
  MPI_Finalize();
#endif
  return 0;

}

/**@brief SAM() loops on trees and calls construct_galaxies.*/
#ifdef MCMC
double SAM(int filenr)
#else
void SAM(int filenr)
#endif
{
  int treenr, halonr;

#ifdef MCMC
  int ii;
  MCMC_GAL = mymalloc("MCMC_Gal", sizeof(struct MCMC_GALAXY) * MCMCAllocFactor);
  for(ii=0;ii<NOUT;ii++)
  	  TotMCMCGals[ii] = 0;

#ifdef MR_PLUS_MRII
  change_dark_matter_sim("MR");
#else
  if(CurrentMCMCStep==1)
  	read_sample_info();
#ifdef HALOMODEL
  else
    {
      int snap, ii;
      for(snap=0;snap<NOUT;snap++)
	for(ii=0;ii<NFofsInSample[snap];ii++)
	  MCMC_FOF[ii].NGalsInFoF[snap]=0;
    }
#endif //HALOMODEL
#endif //MR_PLUS_MRII
#endif //MCMC

  //to be used when we have tables for the scaling in any cosmology
  //read_scaling_parameters();

#ifndef MCMC
#ifdef GALAXYTREE
  create_galaxy_tree_file(filenr);
#else
  create_galaxy_files(filenr);
#endif
#endif

#ifdef GALAXYTREE
  FILE *fdg = fopen("treengal.dat", "w");
#endif

//***************************************************************************************
//***************************************************************************************

  //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++)
  for(treenr = 0; treenr < Ntrees; treenr++)
  {
  //printf("doing tree %d of %d\n", treenr, Ntrees);
#ifdef MR_PLUS_MRII
  	if(treenr == NTrees_Switch_MR_MRII)
  		change_dark_matter_sim("MRII");
#endif

  	load_tree(treenr);
#ifdef MCMC
#ifdef PRELOAD_TREES
      if(CurrentMCMCStep==1)
#endif
#endif
        scale_cosmology(TreeNHalos[treenr]);

      gsl_rng_set(random_generator, filenr * 100000 + treenr);
      NumMergers = 0;
      NHaloGal = 0;
#ifdef GALAXYTREE
      NGalTree = 0;
      IndexStored = 0;
#endif
      int snapnum;
      //LastSnapShotNr is the highest output snapshot
      /* we process the snapshots now in temporal order 
       * (as a means to reduce peak memory usage) */
      for(snapnum = 0; snapnum <= LastSnapShotNr; snapnum++)
      {
#ifdef MCMC
    	  /* read the appropriate parameter list for current snapnum
    	   * into the parameter variables to be used in construct_galaxies */
    	  read_mcmc_par(snapnum);
#ifdef HALOMODEL
          //because we need halo masses even for FOFs
          //with no galaxies it needs to be done here
          assign_FOF_masses(snapnum, treenr);
#endif
#endif
    	  for(halonr = 0; halonr < TreeNHalos[treenr]; halonr++)
    	  	if(HaloAux[halonr].DoneFlag == 0 && Halo[halonr].SnapNum == snapnum)
    	  		construct_galaxies(filenr, treenr, halonr);
      }

      /* output remaining galaxies as needed */
      while(NHaloGal)
      	output_galaxy(treenr, 0);


#ifndef MCMC
#ifdef GALAXYTREE
      save_galaxy_tree_finalize(filenr, treenr);
#ifndef PARALLEL
      if((treenr/100)*100==treenr) printf("treenr=%d  TotGalCount=%d\n", treenr, TotGalCount);
#endif
      fflush(stdout);
      fprintf(fdg, "%d\n", NGalTree);
#endif
#else//ifdef MCMC
#endif
      free_galaxies_and_tree();
  }//loop on trees

#ifdef MCMC
  double lhood = get_likelihood();

#ifdef MR_PLUS_MRII
  free(MCMC_FOF);
#else
  if(CurrentMCMCStep==ChainLength)
  	free(MCMC_FOF);
#endif

  myfree(MCMC_GAL);
  return lhood;

#else //MCMC

#ifdef GALAXYTREE
  close_galaxy_tree_file();
#else
  close_galaxy_files();
#endif

  return;
#endif
}
Пример #5
0
/**@brief Main routine of L-Galaxies*/
int main(int argc, char **argv)
{
  int filenr, *FileToProcess, *TaskToProcess, nfiles;
  char buf[1000];
  time_t start, current;

  //Catch floating point exceptions
#ifdef DEBUG
#endif

#ifdef PARALLEL
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
  MPI_Comm_size(MPI_COMM_WORLD, &NTask);
#else
  NTask = 1;
  ThisTask = 0;
#endif //PARALLEL

#ifdef MCMC
  time(&global_starting_time);
#endif

  if(argc > 3)
    {
      printf("\n  usage: L-Galaxies <parameterfile>\n\n");
      endrun(0);
    }

 if (ThisTask == 0)
   printf("%s\n",COMPILETIMESETTINGS); 

  /*Reads the parameter file, given as an argument at run time. */
  read_parameter_file(argv[1]);

#ifdef MR_PLUS_MRII
  //Start with MR files and later change to MRII
  LastDarkMatterSnapShot=LastDarkMatterSnapShot_MR;
  sprintf(FileWithZList, "%s", FileWithZList_MR);
  sprintf(FileWithZList_OriginalCosm, "%s", FileWithZList_OriginalCosm_MR);
#endif

  mymalloc_init();

  sprintf(FinalOutputDir, "%s", OutputDir);
  if(argc == 3)
	sprintf(OutputDir, "%s", argv[2]);

  //time(&start);

  /* check compatibility of some Makefile Options*/
  check_options();

#ifdef COMPUTE_SPECPHOT_PROPERTIES
  //for dust_model
  mu_seed = -150;
#endif
  init();

#ifdef STAR_FORMATION_HISTORY
#ifdef PARALLEL
  if(ThisTask == 0)
#endif
    write_sfh_bins();
#endif

#ifdef MCMC
#ifdef PARALLEL
 /* a small delay to avoid all processors reading trees at the same time*/
  time(&start);
  do
    time(&current);
  while(difftime(current, start) < 10.0 * ThisTask);
#endif
#endif

#ifndef MCMC
  nfiles=get_nr_files_to_process(ThisTask);
  FileToProcess=mymalloc("FileToProcess", sizeof(int) * nfiles);
  TaskToProcess=mymalloc("TaskToProcess", sizeof(int) * nfiles);
  assign_files_to_tasks(FileToProcess, TaskToProcess, ThisTask, NTask, nfiles);

  int file;
  for(file = 0; file < nfiles; file++)
    {
	  if(ThisTask==TaskToProcess[file])
		  filenr=FileToProcess[file];
	  else
		  continue;
#else //MCMC
  /* In MCMC mode only one file is loaded into memory
   * and the sampling for all the steps is done on it */
	sprintf(SimulationDir, "%s/MergerTrees_%d/", SimulationDir, ThisTask);
  for(filenr = MCMCTreeSampleFile; filenr <= MCMCTreeSampleFile; filenr++)
	{
#endif //MCMC
	  time(&start);

#ifdef READXFRAC
      get_xfrac_mesh();
#endif 

      load_tree_table(filenr);

      /* Read in mesh dimensions */

#ifdef MCMC
#ifdef PARALLEL
      time_t start, start2;
 /* a small delay to reset processors to the same time*/
      time(&start2);
      do
      	time(&current);
      while(difftime(current, start2) < 10.0 * (NTask-ThisTask));
#endif
      Senna(); // run the model in MCMC MODE
#else
      SAM(filenr); // run the model in NORMAL MODE
#endif



#ifdef MCMC
      break;	//break loop on files since the MCMC is done on a single file
#else
      time(&current);
      printf("\ndone tree file %d in %ldmin and %lds\n\n", filenr, (current - start)/60, (current - start)%60);

#endif //MCMC
      free_tree_table();
      //if temporary directory given as argument
       if(argc == 3)
         {
#ifdef GALAXYTREE
    	   sprintf(buf, "mv %s/%s_galtree_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir);
#else
    	   sprintf(buf, "mv %s/%s_z*_%d %s", OutputDir,FileNameGalaxies, filenr, FinalOutputDir);
#endif
    	   system(buf);
         }
    }

#ifndef MCMC
  myfree(TaskToProcess);
  myfree(FileToProcess);
#endif

#ifdef PARALLEL
  MPI_Barrier(MPI_COMM_WORLD);  
  MPI_Finalize();
#endif
  return 0;

}

/**@brief SAM() loops on trees and calls construct_galaxies.*/
#ifdef MCMC
  double SAM(int filenr)
#else
  void SAM(int filenr)
#endif
  {
    int treenr, halonr;
    time_t t_mark_a, t_mark_b;
#ifdef MCMC
    int ii;
    MCMC_GAL = mymalloc("MCMC_Gal", sizeof(struct MCMC_GALAXY) * MCMCAllocFactor);

    for(ii=0;ii<NOUT;ii++)
      TotMCMCGals[ii] = 0;

    if(Sample_Cosmological_Parameters==1)
      {
	reset_cosmology ();
#ifdef HALOMODEL
	initialize_halomodel();
#endif
      }

#ifdef MR_PLUS_MRII
    change_dark_matter_sim("MR");
#else
    if(Sample_Cosmological_Parameters==1 || CurrentMCMCStep==1)
      read_sample_info();
    else
      {
        int snap, ii;
        for(snap=0;snap<NOUT;snap++)
	  for(ii=0;ii<NFofsInSample[snap];ii++)
	    MCMC_FOF[ii].NGalsInFoF[snap]=0;
      }
#endif
#endif

    //to be used when we have tables for the scaling in any cosmology
    //read_scaling_parameters();

#ifndef MCMC
#ifdef GALAXYTREE
    create_galaxy_tree_file(filenr);
#else
    create_galaxy_files(filenr);
#endif
#ifdef ALL_SKY_LIGHTCONE
    int nr;
    for ( nr = 0; nr < NCONES; nr++)
      create_galaxy_lightcone_files(filenr, nr);
#endif
#endif

#ifdef GALAXYTREE
    FILE *fdg = fopen("treengal.dat", "w");
#endif

    //***************************************************************************************
    //***************************************************************************************


    //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++)
    //for(treenr = NTrees_Switch_MR_MRII; treenr < Ntrees; treenr++)

    /* Scan through all trees snapshot by snapshot */
    int snapnum;


    //for(treenr = 0; treenr < NTrees_Switch_MR_MRII; treenr++)
    //for(treenr = NTrees_Switch_MR_MRII; treenr < Ntrees; treenr++)
    for(treenr = 0; treenr < Ntrees; treenr++)
      //for(treenr = 0; treenr < 1;treenr++)
      {
	//printf("doing tree %d of %d\n", treenr, Ntrees);

#ifdef MR_PLUS_MRII
	if(treenr == NTrees_Switch_MR_MRII)
	  change_dark_matter_sim("MRII");
#endif

	load_tree(treenr);

#ifdef MCMC
#ifdef PRELOAD_TREES
	if(Sample_Cosmological_Parameters==1 || CurrentMCMCStep==0)
#endif
#endif
	  scale_cosmology(TreeNHalos[treenr]);

	gsl_rng_set(random_generator, filenr * 100000 + treenr);
	NumMergers = 0;
	NHaloGal = 0;

#ifdef GALAXYTREE
	NGalTree = 0;
	IndexStored = 0;
#endif
	//LastSnapShotNr is the highest output snapshot
	/* we process the snapshots now in temporal order
	 * (as a means to reduce peak memory usage) */
	for(snapnum = 0; snapnum <= LastSnapShotNr; snapnum++)
	  //for(snapnum = 0; snapnum <= 30; snapnum++)
	  {
#ifdef MCMC
	    /* read the appropriate parameter list for current snapnum
	     * into the parameter variables to be used in construct_galaxies */
	    read_mcmc_par(snapnum);
#else
	    //used to allow parameter values to vary with redshift
	    //re_set_parameters(snapnum);
#endif
	    //printf("doing snap=%d\n",snapnum);
	    for(halonr = 0; halonr < TreeNHalos[treenr]; halonr++)
	      if(HaloAux[halonr].DoneFlag == 0 && Halo[halonr].SnapNum == snapnum)
		construct_galaxies(filenr, treenr, halonr);
	  }

	/* output remaining galaxies as needed */
	while(NHaloGal)
	  output_galaxy(treenr, 0);


#ifndef MCMC
#ifdef GALAXYTREE
	save_galaxy_tree_finalize(filenr, treenr);
#ifndef PARALLEL
	if((treenr/100)*100==treenr) printf("treenr=%d TotGalCount=%d\n", treenr, TotGalCount);
#endif
	fflush(stdout);
	fprintf(fdg, "%d\n", NGalTree);
#endif
#else//ifdef MCMC
#ifdef PRELOAD_TREES
	if(Sample_Cosmological_Parameters==1)
	  un_scale_cosmology(TreeNHalos[treenr]);
#endif
#endif
	free_galaxies_and_tree();
      }





#ifdef MCMC
    double lhood = get_likelihood();

#ifdef MR_PLUS_MRII
    free(MCMC_FOF);
#else
    if(Sample_Cosmological_Parameters==1 ||  CurrentMCMCStep==ChainLength)
      free(MCMC_FOF);
#endif

#ifdef HALOMODEL
    if (Sample_Cosmological_Parameters==1) {
      gsl_spline_free(FofSpline);
      gsl_interp_accel_free(FofAcc);
      gsl_spline_free(SigmaSpline);
      gsl_interp_accel_free(SigmaAcc);
      gsl_spline_free(ellipSpline);
      gsl_interp_accel_free(ellipAcc);
      gsl_spline_free(PowSpline);
    } //if
#endif

    myfree(MCMC_GAL);
    return lhood;

#else //MCMC

#ifdef GALAXYTREE
    close_galaxy_tree_file();
#else
    close_galaxy_files();
#endif
#ifdef ALL_SKY_LIGHTCONE
    for (nr = 0; nr < NCONES; nr++)
      close_galaxy_lightcone_files(nr);
#endif

    return;
#endif
  }
Пример #6
0
void
easycap_testcard(struct easycap *peasycap, int field)
{
	int total;
	int y, u, v, r, g, b;
	unsigned char uyvy[4];
	int i1, line, k, m, n, more, much, barwidth, barheight;
	unsigned char bfbar[TESTCARD_BYTESPERLINE / 8], *p1, *p2;
	struct data_buffer *pfield_buffer;

	if (!peasycap) {
		SAY("ERROR: peasycap is NULL\n");
		return;
	}
	JOM(8, "%i=field\n", field);
	switch (peasycap->width) {
	case 720:
	case 360: {
		barwidth = (2 * 720) / 8;
		break;
	}
	case 704:
	case 352: {
		barwidth = (2 * 704) / 8;
		break;
	}
	case 640:
	case 320: {
		barwidth = (2 * 640) / 8;
		break;
	}
	default: {
		SAM("ERROR:  cannot set barwidth\n");
		return;
	}
	}
	if (TESTCARD_BYTESPERLINE < barwidth) {
		SAM("ERROR: barwidth is too large\n");
		return;
	}
	switch (peasycap->height) {
	case 576:
	case 288: {
		barheight = 576;
		break;
	}
	case 480:
	case 240: {
		barheight = 480;
		break;
	}
	default: {
		SAM("ERROR: cannot set barheight\n");
		return;
	}
	}
	total = 0;
	k = field;
	m = 0;
	n = 0;

	for (line = 0;  line < (barheight / 2);  line++) {
		for (i1 = 0;  i1 < 8;  i1++) {
			r = (i1 * 256)/8;
			g = (i1 * 256)/8;
			b = (i1 * 256)/8;

			y =  299*r/1000 + 587*g/1000 + 114*b/1000 ;
			u = -147*r/1000 - 289*g/1000 + 436*b/1000 ;
			u = u + 128;
			v =  615*r/1000 - 515*g/1000 - 100*b/1000 ;
			v = v + 128;

			uyvy[0] =  0xFF & u ;
			uyvy[1] =  0xFF & y ;
			uyvy[2] =  0xFF & v ;
			uyvy[3] =  0xFF & y ;

			p1 = &bfbar[0];
			while (p1 < &bfbar[barwidth]) {
				*p1++ = uyvy[0] ;
				*p1++ = uyvy[1] ;
				*p1++ = uyvy[2] ;
				*p1++ = uyvy[3] ;
				total += 4;
			}

			p1 = &bfbar[0];
			more = barwidth;

			while (more) {
				if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) {
					SAM("ERROR:  bad m reached\n");
					return;
				}
				if (PAGE_SIZE < n) {
					SAM("ERROR:  bad n reached\n");
					return;
				}

				if (0 > more) {
					SAM("ERROR:  internal fault\n");
					return;
				}

				much = PAGE_SIZE - n;
				if (much > more)
					much = more;
				pfield_buffer = &peasycap->field_buffer[k][m];
				p2 = pfield_buffer->pgo + n;
				memcpy(p2, p1, much);

				p1 += much;
				n += much;
				more -= much;
				if (PAGE_SIZE == n) {
					m++;
					n = 0;
				}
			}
		}
	}
	return;
}
void start_c(void) {

  /* Synthesizer Control Register */
  /*    see section(s) 4.8 */
  /* end include in ram_init.S */
  *SYNCR = (unsigned short int)
    ( SAM(MRM_W,15,VCO) | SAM(0x0,14,PRESCALE) | SAM(MRM_Y,8,COUNTER) );
  while (! (*SYNCR & SLOCK));	/* protect from clock overshoot */
  /* include in ram_init.S */
  *SYNCR = (unsigned short int)
    ( SAM(MRM_W,15,VCO) | SAM(MRM_X,14,PRESCALE) | SAM(MRM_Y,8,COUNTER) );

  /* System Protection Control Register */
  /*    !!! can only write to once after reset !!! */
  /*    see section 3.8.4 of the SIM Reference Manual */
  *SYPCR = (unsigned char)( HME | BME );

  /* Periodic Interrupr Control Register */
  /*    see section 3.8.2 of the SIM Reference Manual */
  *PICR = (unsigned short int)
    ( SAM(0,8,PIRQL) | SAM(MRM_PIV,0,PIV) );
  /*     ^^^ zero disables interrupt, don't enable here or ram_init will
	 be wrong. It's enabled below. */

  /* Periodic Interrupt Timer Register */
  /*    see section 3.8.3 of the SIM Reference Manual */
  *PITR = (unsigned short int)( SAM(0x09,0,PITM) );
  /*    1.098mS interrupt, assuming 32.768 KHz input clock */

  /* Port C Data */
  /*    load values before enabled */
  *PORTC = (unsigned char) 0x0;

  /* Port E and F Data Register */
  /*    see section 9 of the SIM Reference Manual */
  *PORTE0 = (unsigned char) 0;
  *PORTF0 = (unsigned char) 0;

  /* Port E and F Data Direction Register */
  /*    see section 9 of the SIM Reference Manual */
  *DDRE = (unsigned char) 0xff;
  *DDRF = (unsigned char) 0xfd;

  /* Port E and F Pin Assignment Register */
  /*    see section 9 of the SIM Reference Manual */
  *PEPAR = (unsigned char) 0;
  *PFPAR = (unsigned char) 0;

  /* end of SIM initalization code */
  /* end include in ram_init.S */

  /*
   * Initialize RAM by copying the .data section out of ROM (if
   * needed) and "zero-ing" the .bss section.
   */
  {
    register char *src = _etext;
    register char *dst = _copy_start;

    if (_copy_data_from_rom)
      /* ROM has data at end of text; copy it. */
      while (dst < _edata)
	*dst++ = *src++;

    /* Zero bss */
    for (dst = _clear_start; dst< end; dst++)
      {
	*dst = 0;
      }
  }

  /*
   * Initialize vector table.
   */
  {
    m68k_isr_entry *monitors_vector_table;

    m68k_get_vbr(monitors_vector_table);

    M68Kvec[  4 ] = monitors_vector_table[  4 ];   /* breakpoints vector */
    M68Kvec[  9 ] = monitors_vector_table[  9 ];   /* trace vector */
    M68Kvec[ 31 ] = monitors_vector_table[ 31 ];   /* level 7 interrupt */
    M68Kvec[ 47 ] = monitors_vector_table[ 47 ];   /* system call vector */
    M68Kvec[ 66 ] = monitors_vector_table[ 66 ];   /* user defined */

    m68k_set_vbr(&M68Kvec);
  }

  /*
   * Initalize the board.
   */

  /* Spurious should be called in the predriver hook */
  /* Spurious_Initialize(); */
  /*console_init(); */

  /*
   * Execute main with arguments argc and agrv.
   */
  boot_card((void*)0);
  reboot();

}