sysreg_helpers.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /*
  2. * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * Neither the name of ARM nor the names of its contributors may be used
  15. * to endorse or promote products derived from this software without specific
  16. * prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include <arch_helpers.h>
  31. #include <asm_macros.S>
  32. .globl read_vbar_el1
  33. .globl read_vbar_el2
  34. .globl read_vbar_el3
  35. .globl write_vbar_el1
  36. .globl write_vbar_el2
  37. .globl write_vbar_el3
  38. .globl read_sctlr_el1
  39. .globl read_sctlr_el2
  40. .globl read_sctlr_el3
  41. .globl write_sctlr_el1
  42. .globl write_sctlr_el2
  43. .globl write_sctlr_el3
  44. .globl read_actlr_el1
  45. .globl read_actlr_el2
  46. .globl read_actlr_el3
  47. .globl write_actlr_el1
  48. .globl write_actlr_el2
  49. .globl write_actlr_el3
  50. .globl read_esr_el1
  51. .globl read_esr_el2
  52. .globl read_esr_el3
  53. .globl write_esr_el1
  54. .globl write_esr_el2
  55. .globl write_esr_el3
  56. .globl read_afsr0_el1
  57. .globl read_afsr0_el2
  58. .globl read_afsr0_el3
  59. .globl write_afsr0_el1
  60. .globl write_afsr0_el2
  61. .globl write_afsr0_el3
  62. .globl read_afsr1_el1
  63. .globl read_afsr1_el2
  64. .globl read_afsr1_el3
  65. .globl write_afsr1_el1
  66. .globl write_afsr1_el2
  67. .globl write_afsr1_el3
  68. .globl read_far_el1
  69. .globl read_far_el2
  70. .globl read_far_el3
  71. .globl write_far_el1
  72. .globl write_far_el2
  73. .globl write_far_el3
  74. .globl read_mair_el1
  75. .globl read_mair_el2
  76. .globl read_mair_el3
  77. .globl write_mair_el1
  78. .globl write_mair_el2
  79. .globl write_mair_el3
  80. .globl read_amair_el1
  81. .globl read_amair_el2
  82. .globl read_amair_el3
  83. .globl write_amair_el1
  84. .globl write_amair_el2
  85. .globl write_amair_el3
  86. .globl read_rvbar_el1
  87. .globl read_rvbar_el2
  88. .globl read_rvbar_el3
  89. .globl read_rmr_el1
  90. .globl read_rmr_el2
  91. .globl read_rmr_el3
  92. .globl write_rmr_el1
  93. .globl write_rmr_el2
  94. .globl write_rmr_el3
  95. .globl read_tcr_el1
  96. .globl read_tcr_el2
  97. .globl read_tcr_el3
  98. .globl write_tcr_el1
  99. .globl write_tcr_el2
  100. .globl write_tcr_el3
  101. .globl read_cptr_el2
  102. .globl read_cptr_el3
  103. .globl write_cptr_el2
  104. .globl write_cptr_el3
  105. .globl read_ttbr0_el1
  106. .globl read_ttbr0_el2
  107. .globl read_ttbr0_el3
  108. .globl write_ttbr0_el1
  109. .globl write_ttbr0_el2
  110. .globl write_ttbr0_el3
  111. .globl read_ttbr1_el1
  112. .globl read_ttbr1_el2
  113. .globl write_ttbr1
  114. .globl write_ttbr1_el1
  115. .globl write_ttbr1_el2
  116. .globl read_cpacr
  117. .globl write_cpacr
  118. .globl read_cntfrq
  119. .globl write_cntfrq
  120. .globl read_cpuectlr
  121. .globl write_cpuectlr
  122. .globl read_cnthctl_el2
  123. .globl write_cnthctl_el2
  124. .globl read_cntfrq_el0
  125. .globl write_cntfrq_el0
  126. .globl read_scr
  127. .globl write_scr
  128. .globl read_hcr
  129. .globl write_hcr
  130. .globl read_midr
  131. .globl read_mpidr
  132. .globl read_current_el
  133. .globl read_id_pfr1_el1
  134. .globl read_id_aa64pfr0_el1
  135. #if SUPPORT_VFP
  136. .globl enable_vfp
  137. .globl read_fpexc
  138. .globl write_fpexc
  139. #endif
  140. func read_current_el
  141. mrs x0, CurrentEl
  142. ret
  143. func read_id_pfr1_el1
  144. mrs x0, id_pfr1_el1
  145. ret
  146. func read_id_aa64pfr0_el1
  147. mrs x0, id_aa64pfr0_el1
  148. ret
  149. /* -----------------------------------------------------
  150. * VBAR accessors
  151. * -----------------------------------------------------
  152. */
  153. func read_vbar_el1
  154. mrs x0, vbar_el1
  155. ret
  156. func read_vbar_el2
  157. mrs x0, vbar_el2
  158. ret
  159. func read_vbar_el3
  160. mrs x0, vbar_el3
  161. ret
  162. func write_vbar_el1
  163. msr vbar_el1, x0
  164. isb
  165. ret
  166. func write_vbar_el2
  167. msr vbar_el2, x0
  168. isb
  169. ret
  170. func write_vbar_el3
  171. msr vbar_el3, x0
  172. isb
  173. ret
  174. /* -----------------------------------------------------
  175. * AFSR0 accessors
  176. * -----------------------------------------------------
  177. */
  178. func read_afsr0_el1
  179. mrs x0, afsr0_el1
  180. ret
  181. func read_afsr0_el2
  182. mrs x0, afsr0_el2
  183. ret
  184. func read_afsr0_el3
  185. mrs x0, afsr0_el3
  186. ret
  187. func write_afsr0_el1
  188. msr afsr0_el1, x0
  189. isb
  190. ret
  191. func write_afsr0_el2
  192. msr afsr0_el2, x0
  193. isb
  194. ret
  195. func write_afsr0_el3
  196. msr afsr0_el3, x0
  197. isb
  198. ret
  199. /* -----------------------------------------------------
  200. * FAR accessors
  201. * -----------------------------------------------------
  202. */
  203. func read_far_el1
  204. mrs x0, far_el1
  205. ret
  206. func read_far_el2
  207. mrs x0, far_el2
  208. ret
  209. func read_far_el3
  210. mrs x0, far_el3
  211. ret
  212. func write_far_el1
  213. msr far_el1, x0
  214. isb
  215. ret
  216. func write_far_el2
  217. msr far_el2, x0
  218. isb
  219. ret
  220. func write_far_el3
  221. msr far_el3, x0
  222. isb
  223. ret
  224. /* -----------------------------------------------------
  225. * MAIR accessors
  226. * -----------------------------------------------------
  227. */
  228. func read_mair_el1
  229. mrs x0, mair_el1
  230. ret
  231. func read_mair_el2
  232. mrs x0, mair_el2
  233. ret
  234. func read_mair_el3
  235. mrs x0, mair_el3
  236. ret
  237. func write_mair_el1
  238. msr mair_el1, x0
  239. isb
  240. ret
  241. func write_mair_el2
  242. msr mair_el2, x0
  243. isb
  244. ret
  245. func write_mair_el3
  246. msr mair_el3, x0
  247. isb
  248. ret
  249. /* -----------------------------------------------------
  250. * AMAIR accessors
  251. * -----------------------------------------------------
  252. */
  253. func read_amair_el1
  254. mrs x0, amair_el1
  255. ret
  256. func read_amair_el2
  257. mrs x0, amair_el2
  258. ret
  259. func read_amair_el3
  260. mrs x0, amair_el3
  261. ret
  262. func write_amair_el1
  263. msr amair_el1, x0
  264. isb
  265. ret
  266. func write_amair_el2
  267. msr amair_el2, x0
  268. isb
  269. ret
  270. func write_amair_el3
  271. msr amair_el3, x0
  272. isb
  273. ret
  274. /* -----------------------------------------------------
  275. * RVBAR accessors
  276. * -----------------------------------------------------
  277. */
  278. func read_rvbar_el1
  279. mrs x0, rvbar_el1
  280. ret
  281. func read_rvbar_el2
  282. mrs x0, rvbar_el2
  283. ret
  284. func read_rvbar_el3
  285. mrs x0, rvbar_el3
  286. ret
  287. /* -----------------------------------------------------
  288. * RMR accessors
  289. * -----------------------------------------------------
  290. */
  291. func read_rmr_el1
  292. mrs x0, rmr_el1
  293. ret
  294. func read_rmr_el2
  295. mrs x0, rmr_el2
  296. ret
  297. func read_rmr_el3
  298. mrs x0, rmr_el3
  299. ret
  300. func write_rmr_el1
  301. msr rmr_el1, x0
  302. isb
  303. ret
  304. func write_rmr_el2
  305. msr rmr_el2, x0
  306. isb
  307. ret
  308. func write_rmr_el3
  309. msr rmr_el3, x0
  310. isb
  311. ret
  312. /* -----------------------------------------------------
  313. * AFSR1 accessors
  314. * -----------------------------------------------------
  315. */
  316. func read_afsr1_el1
  317. mrs x0, afsr1_el1
  318. ret
  319. func read_afsr1_el2
  320. mrs x0, afsr1_el2
  321. ret
  322. func read_afsr1_el3
  323. mrs x0, afsr1_el3
  324. ret
  325. func write_afsr1_el1
  326. msr afsr1_el1, x0
  327. isb
  328. ret
  329. func write_afsr1_el2
  330. msr afsr1_el2, x0
  331. isb
  332. ret
  333. func write_afsr1_el3
  334. msr afsr1_el3, x0
  335. isb
  336. ret
  337. /* -----------------------------------------------------
  338. * SCTLR accessors
  339. * -----------------------------------------------------
  340. */
  341. func read_sctlr_el1
  342. mrs x0, sctlr_el1
  343. ret
  344. func read_sctlr_el2
  345. mrs x0, sctlr_el2
  346. ret
  347. func read_sctlr_el3
  348. mrs x0, sctlr_el3
  349. ret
  350. func write_sctlr_el1
  351. msr sctlr_el1, x0
  352. dsb sy
  353. isb
  354. ret
  355. func write_sctlr_el2
  356. msr sctlr_el2, x0
  357. dsb sy
  358. isb
  359. ret
  360. func write_sctlr_el3
  361. msr sctlr_el3, x0
  362. dsb sy
  363. isb
  364. ret
  365. /* -----------------------------------------------------
  366. * ACTLR accessors
  367. * -----------------------------------------------------
  368. */
  369. func read_actlr_el1
  370. mrs x0, actlr_el1
  371. ret
  372. func read_actlr_el2
  373. mrs x0, actlr_el2
  374. ret
  375. func read_actlr_el3
  376. mrs x0, actlr_el3
  377. ret
  378. func write_actlr_el1
  379. msr actlr_el1, x0
  380. dsb sy
  381. isb
  382. ret
  383. func write_actlr_el2
  384. msr actlr_el2, x0
  385. dsb sy
  386. isb
  387. ret
  388. func write_actlr_el3
  389. msr actlr_el3, x0
  390. dsb sy
  391. isb
  392. ret
  393. /* -----------------------------------------------------
  394. * ESR accessors
  395. * -----------------------------------------------------
  396. */
  397. func read_esr_el1
  398. mrs x0, esr_el1
  399. ret
  400. func read_esr_el2
  401. mrs x0, esr_el2
  402. ret
  403. func read_esr_el3
  404. mrs x0, esr_el3
  405. ret
  406. func write_esr_el1
  407. msr esr_el1, x0
  408. dsb sy
  409. isb
  410. ret
  411. func write_esr_el2
  412. msr esr_el2, x0
  413. dsb sy
  414. isb
  415. ret
  416. func write_esr_el3
  417. msr esr_el3, x0
  418. dsb sy
  419. isb
  420. ret
  421. /* -----------------------------------------------------
  422. * TCR accessors
  423. * -----------------------------------------------------
  424. */
  425. func read_tcr_el1
  426. mrs x0, tcr_el1
  427. ret
  428. func read_tcr_el2
  429. mrs x0, tcr_el2
  430. ret
  431. func read_tcr_el3
  432. mrs x0, tcr_el3
  433. ret
  434. func write_tcr_el1
  435. msr tcr_el1, x0
  436. dsb sy
  437. isb
  438. ret
  439. func write_tcr_el2
  440. msr tcr_el2, x0
  441. dsb sy
  442. isb
  443. ret
  444. func write_tcr_el3
  445. msr tcr_el3, x0
  446. dsb sy
  447. isb
  448. ret
  449. /* -----------------------------------------------------
  450. * CPTR accessors
  451. * -----------------------------------------------------
  452. */
  453. func read_cptr_el1
  454. b read_cptr_el1
  455. ret
  456. func read_cptr_el2
  457. mrs x0, cptr_el2
  458. ret
  459. func read_cptr_el3
  460. mrs x0, cptr_el3
  461. ret
  462. func write_cptr_el1
  463. b write_cptr_el1
  464. func write_cptr_el2
  465. msr cptr_el2, x0
  466. dsb sy
  467. isb
  468. ret
  469. func write_cptr_el3
  470. msr cptr_el3, x0
  471. dsb sy
  472. isb
  473. ret
  474. /* -----------------------------------------------------
  475. * TTBR0 accessors
  476. * -----------------------------------------------------
  477. */
  478. func read_ttbr0_el1
  479. mrs x0, ttbr0_el1
  480. ret
  481. func read_ttbr0_el2
  482. mrs x0, ttbr0_el2
  483. ret
  484. func read_ttbr0_el3
  485. mrs x0, ttbr0_el3
  486. ret
  487. func write_ttbr0_el1
  488. msr ttbr0_el1, x0
  489. isb
  490. ret
  491. func write_ttbr0_el2
  492. msr ttbr0_el2, x0
  493. isb
  494. ret
  495. func write_ttbr0_el3
  496. msr ttbr0_el3, x0
  497. isb
  498. ret
  499. /* -----------------------------------------------------
  500. * TTBR1 accessors
  501. * -----------------------------------------------------
  502. */
  503. func read_ttbr1_el1
  504. mrs x0, ttbr1_el1
  505. ret
  506. func read_ttbr1_el2
  507. b read_ttbr1_el2
  508. func read_ttbr1_el3
  509. b read_ttbr1_el3
  510. func write_ttbr1_el1
  511. msr ttbr1_el1, x0
  512. isb
  513. ret
  514. func write_ttbr1_el2
  515. b write_ttbr1_el2
  516. func write_ttbr1_el3
  517. b write_ttbr1_el3
  518. func read_hcr
  519. mrs x0, hcr_el2
  520. ret
  521. func write_hcr
  522. msr hcr_el2, x0
  523. dsb sy
  524. isb
  525. ret
  526. func read_cpacr
  527. mrs x0, cpacr_el1
  528. ret
  529. func write_cpacr
  530. msr cpacr_el1, x0
  531. ret
  532. func read_cntfrq_el0
  533. mrs x0, cntfrq_el0
  534. ret
  535. func write_cntfrq_el0
  536. msr cntfrq_el0, x0
  537. ret
  538. func read_cpuectlr
  539. mrs x0, CPUECTLR_EL1
  540. ret
  541. func write_cpuectlr
  542. msr CPUECTLR_EL1, x0
  543. dsb sy
  544. isb
  545. ret
  546. func read_cnthctl_el2
  547. mrs x0, cnthctl_el2
  548. ret
  549. func write_cnthctl_el2
  550. msr cnthctl_el2, x0
  551. ret
  552. func read_cntfrq
  553. mrs x0, cntfrq_el0
  554. ret
  555. func write_cntfrq
  556. msr cntfrq_el0, x0
  557. ret
  558. func write_scr
  559. msr scr_el3, x0
  560. dsb sy
  561. isb
  562. ret
  563. func read_scr
  564. mrs x0, scr_el3
  565. ret
  566. func read_midr
  567. mrs x0, midr_el1
  568. ret
  569. func read_mpidr
  570. mrs x0, mpidr_el1
  571. ret
  572. #if SUPPORT_VFP
  573. func enable_vfp
  574. mrs x0, cpacr_el1
  575. orr x0, x0, #CPACR_VFP_BITS
  576. msr cpacr_el1, x0
  577. mrs x0, cptr_el3
  578. mov x1, #AARCH64_CPTR_TFP
  579. bic x0, x0, x1
  580. msr cptr_el3, x0
  581. ret
  582. func read_fpexc
  583. b read_fpexc
  584. ret
  585. func write_fpexc
  586. b write_fpexc
  587. ret
  588. #endif