{"id":235,"date":"2021-06-24T10:16:51","date_gmt":"2021-06-24T01:16:51","guid":{"rendered":"https:\/\/derrylab.com\/?p=235"},"modified":"2021-06-24T10:18:25","modified_gmt":"2021-06-24T01:18:25","slug":"this-makes-my-risc-v-trap-handler-does-not-work","status":"publish","type":"post","link":"https:\/\/blog.derrylab.com\/index.php\/2021\/06\/24\/this-makes-my-risc-v-trap-handler-does-not-work\/","title":{"rendered":"This Makes My RISC-V Trap Handler Does Not Work"},"content":{"rendered":"\n<p>I was working on a RISCV assembly when suddenly I got a weird issue.<br><br>The exception does not get caught in the trap handler. I thought this was a QEMU bug on the RISCV target because the trap handler works on my other code.<br><br>Then after a day of digging, I figured out that it was the <code>mtvec<\/code> needs to be aligned on 4-byte, as mentioned on the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/riscv\/riscv-isa-manual\/releases\/download\/Ratified-IMFDQC-and-Priv-v1.11\/riscv-privileged-20190608.pdf\" data-type=\"URL\" data-id=\"https:\/\/github.com\/riscv\/riscv-isa-manual\/releases\/download\/Ratified-IMFDQC-and-Priv-v1.11\/riscv-privileged-20190608.pdf\" target=\"_blank\">privileged ISA<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The value in the BASE field must always be aligned on a 4-byte boundary, and the MODE setting may impose additional alignment constraints on the value in the BASE field<\/p><\/blockquote>\n\n\n\n<p>Finally, simply by replacing the value of <code>mtvec<\/code> with a multiple of 4-bytes, the exception can be trapped by the trap handler and functioning properly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was working on a RISCV assembly when suddenly I got a weird issue. The exception does not get caught in the trap handler. I thought this was a QEMU bug on the RISCV target because the trap handler works on my other code. Then after a day of digging, I figured out that it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[100,98,101,33,86,102,103],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-programming","tag-asm","tag-assembly","tag-exception","tag-issue","tag-riscv","tag-trap-handler","tag-trap-vector"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":244,"url":"https:\/\/blog.derrylab.com\/index.php\/2021\/03\/12\/the-riscv-isa-documentation-is-better-than-riscv-green-card\/","url_meta":{"origin":235,"position":0},"title":"The RISCV ISA Documentation Is Better than RISCV Green Card","author":"derry","date":"March 12, 2021","format":false,"excerpt":"I hosted the RISCV ISA Documentation. This is really helpful if you want to learn about the assembly syntax or learning the RISCV itself. As a beginner, this documentation is more effective instead of constantly checking at the green card. :) RISCV ISA Documentation:https:\/\/blog.derrylab.com\/riscv-isa-documentation You can host it yourself, it\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":146,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/12\/29\/arty-a7-riscv-debugging-using-j-link\/","url_meta":{"origin":235,"position":1},"title":"Stuck at Debugging RISCV on Arty A7 using J-Link","author":"derry","date":"December 29, 2020","format":false,"excerpt":"Running the RISCV Processor I got an Arty A7 board coming to my desk, and I'm curious to try running a RISCV processor on it. Not long after following the tutorial from Digilent, I was able to program the RISCV processor on this board just by using a MicroUSB cable.\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/blog.derrylab.com\/index.php\/category\/programming\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":552,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/03\/15\/how-to-run-linux-on-riscv-in-arty-a7-100t-fpga\/","url_meta":{"origin":235,"position":2},"title":"How to Run Linux on RISCV in Arty A7-100T FPGA","author":"derry","date":"March 15, 2022","format":false,"excerpt":"It's been tempting for me to try running open-source software on top of open-source hardware. SiFive provides a bitstream for Arty A7 called Freedom, but it seems that the repository is dead now. The other interesting alternative to try is VexRiscv, and everyone keeps posting about Arty A7 35T while\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/03\/pexels-rone-ferreira-3690005-1-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/03\/pexels-rone-ferreira-3690005-1-scaled.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/03\/pexels-rone-ferreira-3690005-1-scaled.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/03\/pexels-rone-ferreira-3690005-1-scaled.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/03\/pexels-rone-ferreira-3690005-1-scaled.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":2242,"url":"https:\/\/blog.derrylab.com\/index.php\/2022\/10\/18\/how-to-do-buffer-overflow-attack-on-64bit-machine\/","url_meta":{"origin":235,"position":3},"title":"How to Do Buffer Overflow Attack on 64bit Machine","author":"derry","date":"October 18, 2022","format":false,"excerpt":"Professor's course material was out of date. He made an example of a buffer overflow attack several years ago. Then here I am, asked to fix the code to work on a modern machine, 64bit Kali Linux. There should be no difference with other Linux; you can practice this on\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"giant tsunami wave","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2022\/10\/pexels-photo-9156792.jpeg?fit=1200%2C737&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":120,"url":"https:\/\/blog.derrylab.com\/index.php\/2020\/11\/04\/install-xilinx-in-batch-mode\/","url_meta":{"origin":235,"position":4},"title":"How to Install Xilinx using Command Line in Four Steps","author":"derry","date":"November 4, 2020","format":false,"excerpt":"I just got some problem with Xilinx 2020.1 installation on my Pop OS. The installer was stuck and gives me an error message: ibndias@shaheen:~\/Downloads$ .\/Xilinx_Unified_2020.1_0602_1208_Lin64.bin Verifying archive integrity... All good. Uncompressing Xilinx Installer............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Exception in thread \"SPLASH_LOAD_MESSAGE\" java.lang.IllegalStateException: no splash screen available at java.desktop\/java.awt.SplashScreen.checkVisible(Unknown Source) at java.desktop\/java.awt.SplashScreen.getBounds(Unknown Source) at java.desktop\/java.awt.SplashScreen.getSize(Unknown\u2026","rel":"","context":"In &quot;linux&quot;","block_context":{"text":"linux","link":"https:\/\/blog.derrylab.com\/index.php\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":336,"url":"https:\/\/blog.derrylab.com\/index.php\/2021\/08\/10\/now-i-understand-what-is-identically-distributed-iid-random-variable\/","url_meta":{"origin":235,"position":5},"title":"Now I Understand: What is Independent and Identically Distributed (IID) Random Variable","author":"derry","date":"August 10, 2021","format":false,"excerpt":"I was working with my friend on a Random Number Generator (RNG) research paper. We need to evaluate the quality of our random bitstream result using the NIST SP800-90B entropy test. Since this is my first time working in the RNG field, I tried to gather all information about evaluating\u2026","rel":"","context":"In &quot;Understanding&quot;","block_context":{"text":"Understanding","link":"https:\/\/blog.derrylab.com\/index.php\/category\/understanding\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.derrylab.com\/wp-content\/uploads\/2021\/08\/erik-mclean-C3T8KTZxTFM-unsplash-scaled-e1628599260397.jpg?fit=512%2C341&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":7,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":307,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions\/307"}],"wp:attachment":[{"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.derrylab.com\/index.php\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}