[384] | 1 | /*
|
---|
| 2 | * TOPPERS/SSP Kernel
|
---|
| 3 | * Smallest Set Profile Kernel
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2018,2019 by Naoki Saito
|
---|
| 6 | * Nagoya Municipal Industrial Research Institute, JAPAN
|
---|
| 7 | *
|
---|
| 8 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 9 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 10 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 11 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 12 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 13 | * スコード中に含まれていること.
|
---|
| 14 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 15 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 16 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 17 | * の無保証規定を掲載すること.
|
---|
| 18 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 19 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 20 | * と.
|
---|
| 21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 23 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 24 | * 報告すること.
|
---|
| 25 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 26 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 27 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 28 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 29 | * 免責すること.
|
---|
| 30 | *
|
---|
| 31 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 32 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 33 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 34 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 35 | * の責任を負わない.
|
---|
| 36 | *
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /*
|
---|
| 40 | * チップ依存モジュール アセンブリ言語部(BCM2837)
|
---|
| 41 | */
|
---|
| 42 |
|
---|
| 43 | #define TOPPERS_MACRO_ONLY
|
---|
| 44 | #define UINT_C(val) (val) /* uint_t型の定数を作るマクロ */
|
---|
| 45 | #define ULONG_C(val) (val) /* ulong_t型の定数を作るマクロ */
|
---|
| 46 | #define UINT64_C(val) (val) /* uint64_t型の定数を作るマクロ */
|
---|
| 47 | #define CAST(type, val) (val) /* 型キャストを行うマクロ */
|
---|
| 48 |
|
---|
| 49 | #include "kernel_impl.h"
|
---|
| 50 |
|
---|
| 51 | /*
|
---|
| 52 | * 例外入口の操作
|
---|
| 53 | * x22: excno(0..7)
|
---|
| 54 | */
|
---|
| 55 | .text
|
---|
| 56 | .align 2
|
---|
| 57 | .global chip_exc_entry
|
---|
| 58 | chip_exc_entry:
|
---|
| 59 | mov x0, sp
|
---|
| 60 | str x22, [x0, #8] // save excno in stack
|
---|
| 61 |
|
---|
| 62 | adrp x1, current_intpri // save int priority in stack
|
---|
| 63 | add x1, x1, :lo12:current_intpri
|
---|
| 64 | ldr w2, [x1]
|
---|
| 65 | str w2, [x0]
|
---|
| 66 |
|
---|
| 67 | mov x1, x22 // arg: excno
|
---|
| 68 | bl call_exc_handler
|
---|
| 69 |
|
---|
| 70 | // 例外発生直前のIフラグまたはFフラグが1ならカーネル管理外のCPU例外とみなす
|
---|
| 71 | ldr x3, [x0, #32] // SPSR --> x1
|
---|
| 72 | tst x3, #(3 << 6)
|
---|
| 73 | b.ne ret_exc
|
---|
| 74 |
|
---|
| 75 | // カーネル管理のCPU例外の場合は割込みの出口処理と共通
|
---|
| 76 | msr daifclr, #AARCH64_DAIF_FIQ
|
---|
| 77 | b ret_int
|
---|
| 78 |
|
---|
| 79 | /*
|
---|
| 80 | * FIQの入口処理
|
---|
| 81 | */
|
---|
| 82 | .text
|
---|
| 83 | .align 2
|
---|
| 84 | .global chip_fiq_entry
|
---|
| 85 | chip_fiq_entry:
|
---|
| 86 | ldr x30, =ret_fiq // return to ret_fiq
|
---|
| 87 | b call_fiq_handler
|
---|
| 88 |
|
---|
| 89 | /*
|
---|
| 90 | * 割込み入口の操作
|
---|
| 91 | */
|
---|
| 92 | .text
|
---|
| 93 | .align 2
|
---|
| 94 | .global chip_int_entry
|
---|
| 95 | chip_int_entry:
|
---|
| 96 | mov x0, sp
|
---|
| 97 | /*
|
---|
| 98 | * 割込み要因の特定と保存
|
---|
| 99 | */
|
---|
| 100 | find_int_src_core: // find a interrupt source from core(core 0)
|
---|
| 101 | movz x1,#:abs_g1_nc:CORE0_IRQ_SRC
|
---|
| 102 | movk x1,#:abs_g0_nc:CORE0_IRQ_SRC
|
---|
| 103 | ldr w2, [x1]
|
---|
| 104 | mov x9, xzr
|
---|
| 105 | 1:
|
---|
| 106 | tst w2, #0x1
|
---|
| 107 | b.ne 2f
|
---|
| 108 | lsr w2, w2, #1
|
---|
| 109 | add w9, w9, #1
|
---|
| 110 | cmp w9, #32
|
---|
| 111 | b.ne 1b
|
---|
| 112 | 2:
|
---|
| 113 | cmp w9, #8 // pending interrupt is GPU interrupt
|
---|
| 114 | b.eq find_int_src_basic
|
---|
| 115 | cmp w9, #32 // pending interrupt is not found
|
---|
| 116 | b.eq find_int_src_basic
|
---|
| 117 | b find_int_src_exit
|
---|
| 118 |
|
---|
| 119 | find_int_src_basic: // basic pending register
|
---|
| 120 | mov w9, #32
|
---|
| 121 | movz x1,#:abs_g1_nc:IRQ_PEND_B
|
---|
| 122 | movk x1,#:abs_g0_nc:IRQ_PEND_B
|
---|
| 123 | ldr w2, [x1]
|
---|
| 124 | 1:
|
---|
| 125 | tst w2, #0x1
|
---|
| 126 | b.ne 2f
|
---|
| 127 | lsr w2, w2, #1
|
---|
| 128 | add w9, w9, #1
|
---|
| 129 | cmp w9, #64
|
---|
| 130 | b.ne 1b
|
---|
| 131 | 2:
|
---|
| 132 | cmp w9, #(32+8) // GPU pending register 1
|
---|
| 133 | b.eq find_int_src_gpu1
|
---|
| 134 | cmp w9, #(32+9) // GPU pending register 2
|
---|
| 135 | b.eq find_int_src_gpu2
|
---|
| 136 | cmp w9, #(32+10) // GPU irq 7
|
---|
| 137 | b.eq gpu_irq_7
|
---|
| 138 | cmp w9, #(32+11) // GPU irq 9
|
---|
| 139 | b.eq gpu_irq_9
|
---|
| 140 | cmp w9, #(32+12) // GPU irq 10
|
---|
| 141 | b.eq gpu_irq_10
|
---|
| 142 | cmp w9, #(32+13) // GPU irq 18
|
---|
| 143 | b.eq gpu_irq_18
|
---|
| 144 | cmp w9, #(32+14) // GPU irq 19
|
---|
| 145 | b.eq gpu_irq_19
|
---|
| 146 | cmp w9, #(32+15) // GPU irq 53
|
---|
| 147 | b.eq gpu_irq_53
|
---|
| 148 | cmp w9, #(32+16) // GPU irq 54
|
---|
| 149 | b.eq gpu_irq_54
|
---|
| 150 | cmp w9, #(32+17) // GPU irq 55
|
---|
| 151 | b.eq gpu_irq_55
|
---|
| 152 | cmp w9, #(32+18) // GPU irq 56
|
---|
| 153 | b.eq gpu_irq_56
|
---|
| 154 | cmp w9, #(32+19) // GPU irq 57
|
---|
| 155 | b.eq gpu_irq_57
|
---|
| 156 | cmp w9, #(32+20) // GPU irq 62
|
---|
| 157 | b.eq gpu_irq_62
|
---|
| 158 | cmp w9, #64 // pending interrupt is not found
|
---|
| 159 | b.eq find_int_src_gpu1
|
---|
| 160 |
|
---|
| 161 | b find_int_src_exit // others
|
---|
| 162 |
|
---|
| 163 | gpu_irq_7:
|
---|
| 164 | mov w9, #(64+7)
|
---|
| 165 | b find_int_src_exit
|
---|
| 166 | gpu_irq_9:
|
---|
| 167 | mov w9, #(64+9)
|
---|
| 168 | b find_int_src_exit
|
---|
| 169 | gpu_irq_10:
|
---|
| 170 | mov w9, #(64+10)
|
---|
| 171 | b find_int_src_exit
|
---|
| 172 | gpu_irq_18:
|
---|
| 173 | mov w9, #(64+18)
|
---|
| 174 | b find_int_src_exit
|
---|
| 175 | gpu_irq_19:
|
---|
| 176 | mov w9, #(64+19)
|
---|
| 177 | b find_int_src_exit
|
---|
| 178 | gpu_irq_53:
|
---|
| 179 | mov w9, #(64+53)
|
---|
| 180 | b find_int_src_exit
|
---|
| 181 | gpu_irq_54:
|
---|
| 182 | mov w9, #(64+54)
|
---|
| 183 | b find_int_src_exit
|
---|
| 184 | gpu_irq_55:
|
---|
| 185 | mov w9, #(64+55)
|
---|
| 186 | b find_int_src_exit
|
---|
| 187 | gpu_irq_56:
|
---|
| 188 | mov w9, #(64+56)
|
---|
| 189 | b find_int_src_exit
|
---|
| 190 | gpu_irq_57:
|
---|
| 191 | mov w9, #(64+57)
|
---|
| 192 | b find_int_src_exit
|
---|
| 193 | gpu_irq_62:
|
---|
| 194 | mov w9, #(64+62)
|
---|
| 195 | b find_int_src_exit
|
---|
| 196 |
|
---|
| 197 | find_int_src_gpu1: // GPU pending register 1
|
---|
| 198 | mov w9, #64
|
---|
| 199 | movz x1,#:abs_g1_nc:IRQ_PEND_1
|
---|
| 200 | movk x1,#:abs_g0_nc:IRQ_PEND_1
|
---|
| 201 | ldr w2, [x1]
|
---|
| 202 | 1:
|
---|
| 203 | tst w2, #0x1
|
---|
| 204 | b.ne 2f
|
---|
| 205 | lsr w2, w2, #1
|
---|
| 206 | add w9, w9, #1
|
---|
| 207 | cmp w9, #96
|
---|
| 208 | b.ne 1b
|
---|
| 209 | 2:
|
---|
| 210 | cmp w9, #96 // pending interrupt is not found
|
---|
| 211 | b.eq find_int_src_gpu2
|
---|
| 212 | b find_int_src_exit
|
---|
| 213 |
|
---|
| 214 | find_int_src_gpu2: // GPU pending register 2
|
---|
| 215 | mov w9, #96
|
---|
| 216 | movz x1,#:abs_g1_nc:IRQ_PEND_2
|
---|
| 217 | movk x1,#:abs_g0_nc:IRQ_PEND_2
|
---|
| 218 | ldr w2, [x1]
|
---|
| 219 | 1:
|
---|
| 220 | tst w2, #0x1
|
---|
| 221 | b.ne find_int_src_exit
|
---|
| 222 | lsr w2, w2, #1
|
---|
| 223 | add w9, w9, #1
|
---|
| 224 | cmp w9, #128 // pending interrupt is not found (and interrupt source is unknown)
|
---|
| 225 | b.ne 1b
|
---|
| 226 |
|
---|
| 227 | find_int_src_exit:
|
---|
| 228 | cmp w9, #128
|
---|
| 229 | b.eq ret_int
|
---|
| 230 | str w9, [x0, #8] // save intno to (sp+8)
|
---|
| 231 |
|
---|
| 232 | /*
|
---|
| 233 | * 割込み発生直前の割込み優先度(内部表現)を保存
|
---|
| 234 | */
|
---|
| 235 | adrp x1, current_intpri
|
---|
| 236 | add x1, x1, :lo12:current_intpri
|
---|
| 237 | ldr w2, [x1]
|
---|
| 238 | str w2, [x0]
|
---|
| 239 |
|
---|
| 240 | /*
|
---|
| 241 | * 割込み要因の優先度を取得
|
---|
| 242 | */
|
---|
| 243 | adrp x3, _kernel_intpri_table
|
---|
| 244 | add x3, x3, #:lo12:_kernel_intpri_table
|
---|
| 245 | ldr w4, [x3, x9, lsl #2]
|
---|
| 246 |
|
---|
| 247 | // 発生した割込みの優先度をもとに割込みをマスク
|
---|
| 248 | mov w0, w4 // arg: intpri
|
---|
| 249 | bl chip_mask_interrupt
|
---|
| 250 |
|
---|
| 251 | // D,A,F フラグをクリアしておく(CPUロック相当にする)
|
---|
| 252 | msr daifclr, #(AARCH64_DAIF_DBG | AARCH64_DAIF_SERR | AARCH64_DAIF_FIQ)
|
---|
| 253 |
|
---|
| 254 | // ハンドラ呼び出し
|
---|
| 255 | mov x0, sp
|
---|
| 256 | ldr w9, [x0, #8]
|
---|
| 257 | mov w0, w9 // arg: intno
|
---|
| 258 | bl call_int_handler
|
---|
| 259 | /* そのまま chip_ret_int へ */
|
---|
| 260 |
|
---|
| 261 | /*
|
---|
| 262 | * 割込み出口のGIC操作
|
---|
| 263 | */
|
---|
| 264 | chip_ret_int:
|
---|
| 265 | // 割込み発生前の優先度に戻す
|
---|
| 266 | mov x0, sp
|
---|
| 267 | adrp x1, current_intpri
|
---|
| 268 | add x1, x1, :lo12:current_intpri
|
---|
| 269 | ldr w2, [x0] // previous int priority
|
---|
| 270 | str w2, [x1]
|
---|
| 271 |
|
---|
| 272 | // 優先度を元に割込みのマスクを戻す
|
---|
| 273 | mov w0, w2
|
---|
| 274 | bl chip_unmask_interrupt
|
---|
| 275 |
|
---|
| 276 | b ret_int
|
---|