NanoPayload

Annotated stage2/handlers.S

133:7981e27344ab
2016-02-26 Paul Boddie Added elements of a task switching mechanism.
paul@68 1
/*
paul@68 2
 * Handler routines.
paul@68 3
 *
paul@91 4
 * Copyright (C) 2015 Nicholas FitzRoy-Dale <wzdd.code@lardcave.net>
paul@110 5
 * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
paul@68 6
 *
paul@68 7
 * This program is free software: you can redistribute it and/or modify
paul@68 8
 * it under the terms of the GNU General Public License as published by
paul@68 9
 * the Free Software Foundation, either version 3 of the License, or
paul@68 10
 * (at your option) any later version.
paul@68 11
 *
paul@68 12
 * This program is distributed in the hope that it will be useful,
paul@68 13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@68 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@68 15
 * GNU General Public License for more details.
paul@68 16
 *
paul@68 17
 * You should have received a copy of the GNU General Public License
paul@68 18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
paul@68 19
 */
paul@68 20
paul@68 21
.text
paul@114 22
.extern tlb_handle
paul@68 23
.extern irq_handle
paul@133 24
.extern current_stack_pointer
paul@133 25
.extern current_task
paul@114 26
.globl tlb_handler
paul@86 27
.globl interrupt_handler
paul@68 28
.set noreorder
paul@68 29
.set noat
paul@68 30
paul@114 31
tlb_handler:
paul@127 32
	/* gp should have been set in the entrypoint. */
paul@127 33
paul@114 34
	jal save_state
paul@114 35
	nop
paul@114 36
paul@114 37
	/* Invoke the handler. */
paul@114 38
paul@114 39
	jal tlb_handle
paul@114 40
	nop
paul@114 41
paul@114 42
	j load_and_return
paul@114 43
	nop
paul@114 44
paul@86 45
interrupt_handler:
paul@127 46
	/* gp should have been set in the entrypoint. */
paul@127 47
paul@114 48
	jal save_state
paul@114 49
	nop
paul@114 50
paul@133 51
	/* Record the stack pointer. */
paul@133 52
paul@133 53
	la $k0, current_stack_pointer
paul@133 54
	sw $sp, 0($k0)
paul@133 55
paul@114 56
	/* Invoke the handler. */
paul@114 57
paul@114 58
	jal irq_handle
paul@114 59
	nop
paul@114 60
paul@133 61
	/* Switch the stack pointer. */
paul@133 62
paul@133 63
	la $k0, current_stack_pointer
paul@133 64
	lw $sp, 0($k0)
paul@133 65
paul@133 66
	/* Set the current task ASID. */
paul@133 67
paul@133 68
	la $k0, current_task
paul@133 69
	lw $k1, 0($k0)
paul@133 70
	mtc0 $k1, $10 /* CP0_ENTRYHI */
paul@133 71
	nop
paul@133 72
paul@114 73
	j load_and_return
paul@114 74
	nop
paul@114 75
paul@114 76
save_state:
paul@86 77
	sw $at, -4($sp)
paul@86 78
	sw $v0, -8($sp)
paul@86 79
	sw $v1, -12($sp)
paul@86 80
	sw $a0, -16($sp)
paul@86 81
	sw $a1, -20($sp)
paul@86 82
	sw $a2, -24($sp)
paul@86 83
	sw $a3, -28($sp)
paul@86 84
	sw $t0, -32($sp)
paul@86 85
	sw $t1, -36($sp)
paul@86 86
	sw $t2, -40($sp)
paul@86 87
	sw $t3, -44($sp)
paul@86 88
	sw $t4, -48($sp)
paul@86 89
	sw $t5, -52($sp)
paul@86 90
	sw $t6, -56($sp)
paul@86 91
	sw $t7, -60($sp)
paul@86 92
	sw $s0, -64($sp)
paul@86 93
	sw $s1, -68($sp)
paul@86 94
	sw $s2, -72($sp)
paul@86 95
	sw $s3, -76($sp)
paul@86 96
	sw $s4, -80($sp)
paul@86 97
	sw $s5, -84($sp)
paul@86 98
	sw $s6, -88($sp)
paul@86 99
	sw $s7, -92($sp)
paul@86 100
	sw $t8, -96($sp)
paul@127 101
	/* sw $t9, -100($sp) */
paul@127 102
	/* sw $gp, -104($sp) */
paul@86 103
	sw $fp, -108($sp)
paul@114 104
	/* sw $ra, -112($sp) */
paul@68 105
paul@110 106
	mfc0 $k0, $14 /* CP0_EPC */
paul@110 107
	nop
paul@110 108
	sw $k0, -116($sp)
paul@110 109
paul@110 110
	addi $sp, $sp, -120
paul@114 111
	j $ra
paul@114 112
	nop
paul@71 113
paul@114 114
load_and_return:
paul@68 115
paul@110 116
	addi $sp, $sp, 120
paul@68 117
paul@86 118
	lw $at, -4($sp)
paul@86 119
	lw $v0, -8($sp)
paul@86 120
	lw $v1, -12($sp)
paul@86 121
	lw $a0, -16($sp)
paul@86 122
	lw $a1, -20($sp)
paul@86 123
	lw $a2, -24($sp)
paul@86 124
	lw $a3, -28($sp)
paul@86 125
	lw $t0, -32($sp)
paul@86 126
	lw $t1, -36($sp)
paul@86 127
	lw $t2, -40($sp)
paul@86 128
	lw $t3, -44($sp)
paul@86 129
	lw $t4, -48($sp)
paul@86 130
	lw $t5, -52($sp)
paul@86 131
	lw $t6, -56($sp)
paul@86 132
	lw $t7, -60($sp)
paul@86 133
	lw $s0, -64($sp)
paul@86 134
	lw $s1, -68($sp)
paul@86 135
	lw $s2, -72($sp)
paul@86 136
	lw $s3, -76($sp)
paul@86 137
	lw $s4, -80($sp)
paul@86 138
	lw $s5, -84($sp)
paul@86 139
	lw $s6, -88($sp)
paul@86 140
	lw $s7, -92($sp)
paul@86 141
	lw $t8, -96($sp)
paul@86 142
	lw $t9, -100($sp)
paul@86 143
	lw $gp, -104($sp)
paul@86 144
	lw $fp, -108($sp)
paul@86 145
	lw $ra, -112($sp)
paul@86 146
paul@110 147
	lw $k0, -116($sp)
paul@110 148
	mtc0 $k0, $14 /* CP0_EPC */
paul@110 149
	nop
paul@110 150
paul@110 151
	lw $k0, -120($sp)
paul@110 152
	mtc0 $k0, $12 /* CP0_STATUS */
paul@110 153
	nop
paul@110 154
paul@86 155
	eret
paul@86 156
	nop
paul@68 157
paul@68 158
.set reorder
paul@68 159
.set at