/*
    start.S, Copyright (c) by Silvio Dragone & David Reist,
    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.
*/


#include "asm.h"
#include "cpu.h"
#include "MemoryLayout.h"

.text

/* __start: the starting point, the address where the Cygmon jumps to */
ENTRY(__start)

	b			__start2
	.org 0x10
LABEL(__segmap)
	.asciz  "TOPSYixp2400"     // MARKER for PATCHING
	.org 0x20

	nop	
	nop
	nop
	nop				
	/* make sure there is enough room for information storage
	the Topsy Header is 128 bytes long */
	.org    0x90    

__start2:
	mov	ip, #0
	mcr	p15, 0, ip, c7, c7, 0		// flush I & D cache
	mcr	p15, 0, ip, c7, c10, 4		// drain WB
	mcr	p15, 0, ip, c8, c7, 0		// flush I & D TLBs
	mrc	p15, 0, ip, c1, c0, 0		// ctrl register
	bic	ip, ip, #0x000f			// ..xi...s....wcam
	bic	ip, ip, #0x3100			// ..xi...s........
	mcr	p15, 0, ip, c1, c0, 0		// ctrl register
	nop
	nop
	mrs	ip, cpsr	// get CPSR
	orr	ip, ip, #0xC0	// disable interrupts FIQ & IRQ
	orr	ip, ip, #0x1F	// get into system mode
	msr	cpsr_cxsf, ip
	nop
	
	ldr	sp, =BOOTSTACKTOP	// initialize the sp to the bootstack !
	sub sp, sp, #32

	b	StartMeFirst
	nop
	
