/*
    Startup.c, Copyright  (c) by George Fankhauser,
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
*/
/*
	
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Startup/Startup.c,v $
 	Author(s):             George Fankhauser
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 2922 $
 	Creation Date:        
 	Last Date of Change:   $Date: 2007-03-19 17:48:52 +0100 (Mon, 19 Mär 2007) $      by: $Author: baderma $
	
*/


#include "Memory.h"
#include "tm-include.h"
#include "TMHal.h"	/* needed for the ProcContext */
#include "Threads.h"
#include "IO.h"
#include "IOHal.h"
#include "Configuration.h"
#include "Version.h"
#include "Support.h"

#include "vm.h"
#include "vm_bootup.h"

#include "Startup.h"

extern Scheduler scheduler;
Thread startupThread;
ProcContext startupThreadContext;

void topsyMain(void)
{
  Address mmStack, tmStack;

  /* CJ 20011217 */
  startupThread.id = 0;
  startupThread.parentId = 0;
  startupThread.contextPtr = &startupThreadContext;
  byteCopy(startupThread.name, "(in init)", sizeof("(in init)"));
  /* NOTE: if the stack start and end address are needed then they should be
  	 set in the architecture dependent part of Startup.
  	 It would be the best if we set up a real thread control block so it
  	 is possible to merge the startup thread to the idle thread.
   */
  scheduler.running = &startupThread;


  initBasicExceptions();	/* catch traps early */
  ioConsoleInit();				/* set baud 9600 etc. */
  ioConsolePutString(topsyVersionString);	/* from Topsy/Version.h */

  printf("Stack @ %p\n", &tmStack);

  /* init mm and copy user segments */
  vm_init(&mmStack, &tmStack);
  /* startup thread init */
  tmInit(mmStack, tmStack, (Address) 0x1000);

  /* tmInit never returns */
  PANIC("init returned");

}

