/************************************************************************/
/* CQBBEL GNU CC Common Control Software / (C) Toshio MURAI 2011, 2012	*/
/*      This is Free Software;   You can redistribute this software     */
/*      and/or modify it under the terms of the GNU General Public      */
/*      License version 3, or (at your option) any later version.       */
/************************************************************************/

	.global	_start
	.global	_timer0
	.global	_interrupt0
	.global	_interrupt1
	.global	_interrupt2
	.global	_interrupt3
	.global	_enableInterrupt

_start:
	ldi:32 systemStack, sp

	call	initializeMemory
	call	main

_exit:	bra _exit

_enableInterrupt:
	STILM	#31	; Inerrupt Level 31 (Low)
	ORCCR	#0x10	; Interrupt Enable
	ret

_disableInterrupt:
	STILM	#0	; Inerrupt Level  (Low)
	ANDCCR	#0xEF
	ret

_timer0:
	STM0	(R0,R7)		;STM	(R0,R12)
	STM1	(R8,R12)
	st	rp, @-r15	;ST	RP,@-SP

	call	timer0Interrupt

	ld	@r15+, rp	;LD	@SP+,RP
	LDM1	(R8,R12)
	LDM0	(R0,R7)		;LDM	(R0,R12)
	RETI			;RETI

_interrupt0:
	STM0	(R0,R7)		;STM	(R0,R12)
	STM1	(R8,R12)
	st	rp, @-r15	;ST	RP,@-SP

	call	interruptRequest0

	ld	@r15+, rp	;LD	@SP+,RP
	LDM1	(R8,R12)
	LDM0	(R0,R7)		;LDM	(R0,R12)
	RETI			;RETI

_interrupt1:
	STM0	(R0,R7)		;STM	(R0,R12)
	STM1	(R8,R12)
	st	rp, @-r15	;ST	RP,@-SP

	call	interruptRequest1

	ld	@r15+, rp	;LD	@SP+,RP
	LDM1	(R8,R12)
	LDM0	(R0,R7)		;LDM	(R0,R12)
	RETI			;RETI

_interrupt2:
	STM0	(R0,R7)		;STM	(R0,R12)
	STM1	(R8,R12)
	st	rp, @-r15	;ST	RP,@-SP

	call	interruptRequest2

	ld	@r15+, rp	;LD	@SP+,RP
	LDM1	(R8,R12)
	LDM0	(R0,R7)		;LDM	(R0,R12)
	RETI			;RETI

_interrupt3:
	STM0	(R0,R7)		;STM	(R0,R12)
	STM1	(R8,R12)
	st	rp, @-r15	;ST	RP,@-SP

	call	interruptRequest3

	ld	@r15+, rp	;LD	@SP+,RP
	LDM1	(R8,R12)
	LDM0	(R0,R7)		;LDM	(R0,R12)
	RETI			;RETI
