/*
================================ COPYRIGHT ================================
The contents of this file are subject to the VTech Informations Ltd. License
of VT-OS Ver. 1.1 operating system (the "License"); you may not use this 
file except in compliance with the License.  
 
Software distributed under the License is distributed on an "AS IS" basis, 
WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License 
for the specific language governing rights and limitations under the License.
 
The Original Code is VT-OS Ver. 1.1 Operating System, released 
on October 1st, 1999

The Initial Developer of the Original Code is VTech Informations Ltd.  All 
codes are Copyright (C) VTech Informations Ltd. 1999.  All Rights Reserved.
===========================================================================
*/

/*
===========================================================================
File        :   appstart.s
Author(s)   :   Thomas Cheng
Company     :   VTech Informations Ltd.
Project     :   Helio 
Date:	    :   October 1st, 1999
Purpose:	:   app start running sequence
Revision    :   1.1
Note        :   None
===========================================================================
*/              

#include "pr3910.h"
#include "pr31700s.h"

#define APP_IN_FLASH
#define USER_MEM_BASE	0x10000000

	.data
	.globl	header
header:
.word	_ftext - USER_MEM_BASE
.word	etext - USER_MEM_BASE
.word	_fdata - USER_MEM_BASE
.word	edata - USER_MEM_BASE
.word	_fbss - USER_MEM_BASE
.word	ebss - USER_MEM_BASE
.word	res_data - USER_MEM_BASE
.word	0

	.text
	.globl appstart
appstart:
#ifdef APP_IN_FLASH
/*   move	$4,$0
   li	$5,0x00000063		# 99
   jal	UartPutc
	nop
/*	# clear bss
	la		v0, _fbss
	la		v1, ebss
1:	sw		$0, 0x0(v0)
	sw		$0, 0x4(v0)
	sw		$0, 0x8(v0)
	sw		$0, 0xc(v0)
	addu	v0, 16
	blt		v0, v1, 1b

	# copy .data to RAM
	# src=etext dst=_fdata stop=edata
	la	t0, etext
	la	t1, _fdata
	la	t2, edata
1:	lw	t3, 0(t0)
	sw	t3, 0(t1)
	addu	t0, 4
	addu	t1, 4
	blt	t1, t2, 1b
*/	# transfer to main program
	# reg indirect is necessary to switch segments
	la		t0, __main
    j		t0
#else
	li		t0,0x9fc30000
	jalr	t0
	# transfer to main program
	# reg indirect is necessary to switch segments
	la		t0, __main
    jal     t0
#endif

