/*
    userStart.S, Copyright  (c) by Lukas Ruf, lr@lpr.ch,
    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/User/ia32/userStart.S,v $
 	Author(s):             Lukas Ruf, lr@lpr.ch
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 3044 $
 	Creation Date:         
 	Last Date of Change:   $Date: 2007-07-04 22:16:17 +0200 (Mit, 04 Jul 2007) $      by: $Author: sryffel $
*/

#include "asm.h"
#include "headerLayout.h"

.section .init
.align  4,0x9090
.org    0x00000000

        jmp __start             // jump to start
// start of topsyheader
        .org ORG_MARKER
	      .asciz  "TOPSYia32"     // MARKER for PATCHING
        .org ORG_TEXT_SIZE
_textsize:
        .org ORG_DATA_SIZE
_datasize:
        .org ORG_BSS__SIZE
_bsssize:
        .org ORG_PLATFORM_EXTENSIONS
_tracktoread:
			  /* make sure there is enough room for information storage
				 * the Topsy Header is 128 bytes long
			   */
	      .org    ORG_CODE_START    


        
        .align  4,0x9090
        
ASM_PROC_FRAME(__start)
        nop             // make sure, the disassembler is able to synchronize...
        nop             // this is only inserted here, as all disassemblers
        nop             // to not really know about -- how could they... 
        nop             // this would not be used for execution but for readability,
        nop             // I'm still human :-)
        nop
        nop
        nop
        
store_patched_values:   
        movl    _tracktoread,%eax       // save on stack
        movl    %eax,_lkernel           // save in data segment
        
        movl    _textsize,%eax          // save on stack
        movl    %eax,_ltexts            // save in data segment
        
        movl    _datasize,%eax          // .... and
        movl    _bsssize,%ebx
        addl    %ebx,%eax               // datasize = datasize + bsssize
        movl    %eax,_ldatas            // save in data segment

        jmp     StartMeFirstUser        // and now GO !!


//****************************************************************************//
//***  Support Functions to report correct "sizes"                         ***//
//****************************************************************************//
        .section .sasm
        .align  4,0x9090
//ulong __getTextSize();        
// return size of .text as pachted by KernelPatch 
ASM_PROC_FRAME(__getTextSize)
        ENTER
        movl    _ltexts,%eax
        LEAVE

//ulong __getDataSize();        
// return size of .data as pachted by KernelPatch 
ASM_PROC_FRAME(__getDataSize)
        ENTER
        movl    _ldatas,%eax
        LEAVE

//ulong __getKernelSize();      
// return size of .data as pachted by KernelPatch 
ASM_PROC_FRAME(__getKernelSize)
        ENTER
        movl    _lkernel,%eax
        LEAVE

//****************************************************************************//
//***  Startup Messages (just to say "I'm alive"                           ***//
//****************************************************************************//

        .data
        .align  4,0x9090
_ltexts:
        .long   0x00000000
_ldatas:
        .long   0X00000000
_lkernel:
        .long   0X00000000
        


