[BACK]Return to loader.S CVS log [TXT][DIR] Up to [local] / funnyos / arch / testarm / boot

File: [local] / funnyos / arch / testarm / boot / loader.S (download)

Revision 1.5, Fri Nov 23 13:37:42 2007 UTC (16 years, 5 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +9 -1 lines

basic roundrobin multitasking support in FunnyOS!
_vector_irq saves Sys_mode context (which is treated as struct pcb) in stack and
passes sp to irq_trampoline() which then sets global iframep pointer to point to pcb of interrupted task.

"task" given by u_task (set by user at compile-time) and k_task which is dynamically allocated by the kernel.
scheduler uses list of k_task (circularly linked list) with one constant task "idle".
idle discarded in sched_init() with status TASK_NOSCHED and will not be scheduled after first sched_tick().

tasks created in task/ directory and should implement void ttt_enter(void) to start execution from.
tasks added by inserting new elements in config_tasklist[].

please note that current *ugly* design causes strange behavior if tasks printf something w/out delays..
also, we do not save task's CPSR yet..

/*
 * $Id: loader.S,v 1.5 2007/11/23 13:37:42 nbrk Exp $
 */
/*
 *	FunnyOS loader
 *	for gxemul test arm machines.
 */
.text
.global _start
.global main

_start:
b 	_vector_reset		/* reset */
bl 	_vector_undef		/* undefined insn */
bl 	_vector_swi			/* software intr handler */
bl 	_vector_dataabrt	/* data abort */
bl 	_vector_prefabrt	/* prefetch abort */
.word 0x00000000		/* [reserved] */
b 	_vector_irq			/* IRQ */
bl 	_vector_fiq			/* Fast Interrupt Request */

_vector_reset:
	/*
	 *	Will enter here just right after RESET.
	 *	Set up stack and call main.
	 */

	/*
	 * Setup an IRQ stack
	 */
	/* switch into irq mode with interrupts disabled */
	msr cpsr_c, #(0x12 | 0x80) 

	/* set sp (sp is banked) */
	ldr sp, Airqstack

	/*
	 * Setup system stack
	 */
	/* switch into system mode (interrupts turned off) */
	msr cpsr_c, #(0x1f | 0x80)

	/* set system stack pointer */
	ldr sp, Asysstack

	b main
	/* NOTREACHED */

_vector_undef:
	/* Undefined insn handler */
	mov pc, r14

_vector_swi:
	mov pc, r14

_vector_dataabrt:
	/* XXX fatal */
	nop

_vector_prefabrt:
	nop

_vector_irq:
	/* decrement pc by one insn */
	sub lr, lr, #4

	/* store all system mode registers */
	stmdb sp!, {r0-r12, lr}

	/* store sys_mode's cpsr */
//	mrs r1, spsr
//	stmdb sp!, {r1}

	/* pass sp (which now contains struct pcb of interrupted task) to irq_trampoline */
	mov r0, sp

	bl irq_trampoline

	/* load r0-r12 and pc from the stack */
	/* note ^ that copies SPSR into CPSR */
	/** here we may return to different task (if pcb was changed in the stack memory) **/
	ldmia sp!, {r0-r12, pc}^

_vector_fiq:
	nop

/* last word of the physical memory */
Asysstack:
.word 	0x01fffffc
Airqstack:
.word 	0x01fff000