Nios® Vプロセッサー・ソフトウェア開発者ハンドブック

ID 743810
日付 10/31/2022
Public

このドキュメントの新しいバージョンが利用できます。お客様は次のことを行ってください。 こちらをクリック 最新バージョンに移行する。

ドキュメント目次

8.7.4.3. カスタム例外ハンドラーの追加

前のセクションの指示に従って JTAG UART でポーリング・モードを有効にすると、ロードやストアのミスアライメントなど、割り込みに関連しない例外の原因を調べるのに次の手順が役立ちます。main.cファイルに次の行を追加して、ライブラリーと次の instr_exception_handler()関数を含めます。
#include <inttypes.h>

#include <sys/alt_exceptions.h> // Provides a way to register a custom instruction exception handler

alt_exception_result instr_exception_handler(alt_exception_cause cause,
  alt_u32 epc, alt_u32 tval) {
  printf("Instruction exception!\n");
  printf(" * cause: %d\n", cause);
  printf(" * epc:   0x%"
    PRIx32 "\n", epc);
  printf(" * tval:  0x%"
    PRIx32 "\n", tval);
  while (1) {};
  return NIOSV_EXCEPTION_RETURN_REISSUE_INST; // Should not be reached.
}
次のセクションを追加して、この新しい例外処理関数をmain()関数の例外を引き起こすコードのすぐ上にレジスターします。
int main(void) {
    alt_instruction_exception_register (instr_exception_handler);  // Register custom instruction exception handler.
 
    printf("Hello world!\n");
    function_which_causes_the_exception();
   return 0;
}