NanoPayload

stage2/handlers.S

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