Một số thông tin thêm ...
Một trong GCC của builtins là
void __builtin_trap (void)
Chức năng này khiến chương trình thoát bất thường. GCC thực hiện chức năng này bằng cách sử dụng một cơ chế phụ thuộc vào mục tiêu (như cố ý thực hiện một lệnh bất hợp pháp) hoặc bằng cách gọi hủy bỏ. Cơ chế được sử dụng có thể khác nhau từ bản phát hành đến bản phát hành, do đó bạn không nên dựa vào bất kỳ triển khai cụ thể nào.
implementation for ARMv7 is của nó:
(define_insn "trap"
[(trap_if (const_int 1) (const_int 0))]
""
"*
if (TARGET_ARM)
return \".inst\\t0xe7f000f0\";
else
return \".inst\\t0xdeff\";
"
[(set (attr "length")
(if_then_else (eq_attr "is_thumb" "yes")
(const_int 2)
(const_int 4)))
(set_attr "type" "trap")
(set_attr "conds" "unconditional")]
)
Vì vậy, cho ARM chế độ gcc sẽ tạo 0x7f000f0 (f0 00 f0 07)
và cho các chế độ khác 0xdeff (ff de)
(đi kèm tiện dụng khi tháo/gỡ lỗi).
Also note that:
these encodings match the UDF instruction that is defined in the most
recent edition of the ARM architecture reference manual.
Thumb: 0xde00 | imm8 (we chose 0xff for the imm8)
ARM: 0xe7f000f0 | (imm12 << 8) | imm4 (we chose to use 0 for both imms)
Đối LLVM__builtin_trap
giá trị được tạo ra là 0xe7ffdefe
và 0xdefe
:
case ARM::TRAP: {
// Non-Darwin binutils don't yet support the "trap" mnemonic.
// FIXME: Remove this special case when they do.
if (!Subtarget->isTargetDarwin()) {
//.long 0xe7ffdefe @ trap
uint32_t Val = 0xe7ffdefeUL;
OutStreamer.AddComment("trap");
OutStreamer.EmitIntValue(Val, 4);
return;
}
break;
}
case ARM::tTRAP: {
// Non-Darwin binutils don't yet support the "trap" mnemonic.
// FIXME: Remove this special case when they do.
if (!Subtarget->isTargetDarwin()) {
//.short 57086 @ trap
uint16_t Val = 0xdefe;
OutStreamer.AddComment("trap");
OutStreamer.EmitIntValue(Val, 2);
return;
}
break;
}
Theo http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0337e/I1010015.html BLX từ thumb16 không được hỗ trợ bởi M3 và "luôn luôn lỗi". –