{"id":3350,"date":"2014-12-10T19:55:42","date_gmt":"2014-12-10T19:55:42","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=3350"},"modified":"2014-12-10T19:55:42","modified_gmt":"2014-12-10T19:55:42","slug":"nios-ii-internals","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=3350","title":{"rendered":"NIOS II: Internals"},"content":{"rendered":"<h3>Internals<\/h3>\n<pre class=\"brush: plain; first-line: 85; title: alt_irq_entry.S; notranslate\" title=\"alt_irq_entry.S\">\r\n.section .exceptions.irqhandler, &quot;xa&quot;\r\n\/*\r\n * Now that all necessary registers have been preserved, call \r\n * alt_irq_handler() to process the interrupts.\r\n *\/\r\n\r\ncall alt_irq_handler\r\n<\/pre>\n<pre class=\"brush: plain; first-line: 168; title: alt_exception_entry.S; notranslate\" title=\"alt_exception_entry.S\">\r\n\/*\r\n * Prepare to service unimplemtned instructions or traps,\r\n * each of which is optionally inked into section .exceptions.soft,\r\n * which will preceed .exceptions.unknown below.\r\n *\r\n * Unlike interrupts, we want to skip the exception-causing instructon\r\n * upon completion, so we write ea (address of instruction *after*\r\n * the one where the exception occured) into 72(sp). The actual\r\n * instruction that caused the exception is written in r2, which these\r\n * handlers will utilize.\r\n *\/\r\nstw   ea,  72(sp)  \/* Don't re-issue *\/\r\nldw   r2, -4(ea)   \/* Instruction that caused exception *\/\r\n<\/pre>\n<pre class=\"brush: plain; first-line: 203; title: alt_exception_entry.S; notranslate\" title=\"alt_exception_entry.S\">\r\n\/*\r\n * The C-based HAL routine alt_instruction_exception_entry() will\r\n * attempt to service the exception by calling a user-registered\r\n * exception handler using alt_instruction_exception_register().\r\n * If no handler was registered it will either break (if the\r\n * debugger is present) or go into an infinite loop since the\r\n * handling behavior is undefined; in that case we will not return here.\r\n *\/\r\n\r\n\/* Load exception-causing address as first argument (r4) *\/\r\naddi   r4, ea, -4\r\n\r\n\/* Call the instruction-exception entry *\/\r\ncall   alt_instruction_exception_entry\r\n<\/pre>\n<pre class=\"brush: cpp; first-line: 56; title: alt_instruction_exception_entry.c; notranslate\" title=\"alt_instruction_exception_entry.c\">\r\n\/*\r\n * This is the entry point for instruction-generated exceptions handling.\r\n * This routine will be called by alt_exceptions_entry.S, after it determines\r\n * that an exception could not be handled by handlers that preceed that\r\n * of instruction-generated exceptions (such as interrupts).\r\n *\r\n * For this to function properly, you must register an exception handler\r\n * using alt_instruction_exception_register(). This routine will call\r\n * that handler if it has been registered. Absent a handler, it will\r\n * break break or hang as discussed below.\r\n *\/\r\nint alt_instruction_exception_entry (alt_u32 exception_pc)\r\n{\r\n  alt_u32 cause, badaddr;\r\n<\/pre>\n<pre class=\"brush: cpp; title: exception register example; notranslate\" title=\"exception register example\">\r\n\/*\r\n * Catch any unhandled exception from the HAL layer.\r\n *\/\r\n\r\n#include &lt;stdint.h&gt;\r\n\r\n#include &lt;system.h&gt;\r\n#include &lt;sys\/alt_exceptions.h&gt;\r\n\r\n#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API\r\n\r\nunsigned int spurious_ints;\r\n\r\nstatic alt_exception_result\r\nunhandled_exception (alt_exception_cause cause,\r\n                     uint32_t exception_pc,\r\n                     uint32_t bad_addr)\r\n{\r\n  ++spurious_ints;\r\n  return NIOS2_EXCEPTION_RETURN_REISSUE_INST;\r\n}\r\n\r\n#endif\r\n\r\nvoid\r\ninit_uhe (void)\r\n{\r\n#ifdef ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API\r\n  alt_instruction_exception_register (unhandled_exception);\r\n#endif\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Internals .section .exceptions.irqhandler, &quot;xa&quot; \/* * Now that all necessary registers have been preserved, call * alt_irq_handler() to process the interrupts. *\/ call alt_irq_handler \/* * Prepare to service unimplemtned instructions or traps, * each of which is optionally inked into section .exceptions.soft, * which will preceed .exceptions.unknown below. * * Unlike interrupts, we want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3350","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/3350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3350"}],"version-history":[{"count":1,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/3350\/revisions"}],"predecessor-version":[{"id":3351,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/3350\/revisions\/3351"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}