亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 13569 | 回復(fù): 3
打印 上一主題 下一主題

ud2是什么指令? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-06-20 20:58 |只看該作者 |倒序?yàn)g覽
#define BUG()                                \
__asm__ __volatile__(        "ud2\n"                \
                        "\t.word %c0\n"        \
                        "\t.long %c1\n"        \
                         : : "i" (__LINE__), "i" (__FILE__))


ud2是什么指令?機(jī)器碼好像是0f 0b ?
BUG()能造成系統(tǒng)停機(jī)么?

%0、%1是占位符號(hào),那么前面的修飾符'c'是什么含意?(%c0、%c1)
除了'c'還有哪些修飾符?在哪里可以查到這些修飾符的信息?

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2007-06-21 10:06 |只看該作者
undefined, 故意讓CPU出錯(cuò)的 -- 記得是這樣,F(xiàn)IXME

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2007-06-22 09:46 |只看該作者
albcamus 說得沒錯(cuò),

查了一下手冊(cè), UD2是一種讓CPU產(chǎn)生invalid opcode exception的軟件指令.  內(nèi)核發(fā)現(xiàn)CPU出現(xiàn)這個(gè)異常, 會(huì)立即停止運(yùn)行.

'c' 在gcc中, 叫做operand code, c只能用在常量變量(就是constraint是'i')和條件判斷指令中. 作用是將這個(gè)常量值打印在指令中.
這段代碼:

  1. #define BUG()                                                                \
  2.         do {                                                                \
  3.                 asm volatile("1:\tud2\n"                                \
  4.                              ".pushsection __bug_table,\"a\"\n"                \
  5.                              "2:\t.long 1b, %c0\n"                        \
  6.                              "\t.word %c1, 0\n"                                \
  7.                              "\t.org 2b+%c2\n"                                \
  8.                              ".popsection"                                \
  9.                              : : "i" (__FILE__), "i" (__LINE__),        \
  10.                              "i" (sizeof(struct bug_entry)));                \
  11.                 for(;;) ;                                                \
  12.         } while(0)
復(fù)制代碼

編譯后的代碼為:

  1. .LC0:
  2.         .string "asm.c"
  3.         .text
  4. .....

  5. #APP
  6.         1:      ud2
  7. .pushsection __bug_table,"a"
  8. 2:      .long 1b, .LC0
  9.         .word 18, 0
  10.         .org 2b+4
  11. .popsection
  12. #NO_APP
復(fù)制代碼

其實(shí)除了ud2這條指令, 其他都是assembler directives.

如果沒有'c'這個(gè)operand code, 產(chǎn)生的指令是:

  1. .LC0:
  2.         .string "asm.c"
  3.         .text

  4. #APP
  5.         1:      ud2
  6. .pushsection __bug_table,"a"
  7. 2:      .long 1b, $.LC0
  8.         .word $18, 0
  9.         .org 2b+$4
  10. .popsection
  11. #NO_APP
復(fù)制代碼

這段代碼對(duì)于assembler directives(GAS的輸入)來說, 可能是不能正常工作的.

i386的operand code可以在gcc源代碼的gcc/config/i386.c中查詢到, 我也是很久以前移植過一種CPU ARCH才記得有這么個(gè)東西.
   L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
   C -- print opcode suffix for set/cmov insn.
   c -- like C, but print reversed condition
   F,f -- likewise, but for floating-point.
   O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
        otherwise nothing
   R -- print the prefix for register names.
   z -- print the opcode suffix for the size of the current operand.
   * -- print a star (in certain assembler syntax)
   A -- print an absolute memory reference.
   w -- print the operand as if it's a "word" (HImode) even if it isn't.
   s -- print a shift double count, followed by the assemblers argument
        delimiter.
   b -- print the QImode name of the register for the indicated operand.
        %b0 would print %al if operands[0] is reg 0.
   w --  likewise, print the HImode name of the register.
   k --  likewise, print the SImode name of the register.
   q --  likewise, print the DImode name of the register.
   h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
   y -- print "st(0)" instead of "st" as a register.
   D -- print condition for SSE cmp instruction.
   P -- if PIC, print an @PLT suffix.
   X -- don't print any sort of PIC '@' suffix for a symbol.
   & -- print some in-use local-dynamic symbol name.


ps. 較新的內(nèi)核代碼都已經(jīng)將BUG()的實(shí)現(xiàn)做了一些修改, 改成了我上面提到的那種, 這可以讓出錯(cuò)的指令直接在棧頂, 便于調(diào)試.

論壇徽章:
20
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-08-17 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-07-16 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-07-18 06:20:00每日論壇發(fā)貼之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16賽季CBA聯(lián)賽之江蘇
日期:2017-06-26 11:05:5615-16賽季CBA聯(lián)賽之上海
日期:2017-07-21 18:12:5015-16賽季CBA聯(lián)賽之青島
日期:2017-09-04 17:32:0515-16賽季CBA聯(lián)賽之吉林
日期:2018-03-26 10:02:16程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2016-07-15 06:20:0015-16賽季CBA聯(lián)賽之江蘇
日期:2016-07-07 18:37:512015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-08-17 12:21:08
4 [報(bào)告]
發(fā)表于 2015-12-04 10:13 |只看該作者
終于找到這個(gè)老帖子了。

https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Extended-Asm.html
6.43.2.7 x86 Operand Modifiers
c  Require a constant operand and print the constant expression with no punctuation

void f1()
{
        asm("nop");
        asm (".word %0"::"i"(0xff));   => 生成0x00 0x00 => link error: undefined reference to `$255'
        asm("nop");
        asm (".word %c0"::"i"(0xff));  => 生成0xff 0x00
}
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP