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

  免費注冊 查看新帖 |

Chinaunix

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

為什么用戶態(tài)和內(nèi)核態(tài)讀取任務(wù)寄存器(tr)結(jié)果不一樣 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-11-06 01:47 |只看該作者 |倒序瀏覽
根據(jù)intel的volume3的7.2.4對任務(wù)寄存器的描述:
The STR (store task register) instruction stores the visible portion of the task register
in a general-purpose register or memory. This instruction can be executed by code
running at any privilege level in order to identify the currently running task. However,
it is normally used only by operating system software.


str指令在用戶態(tài)也可以使用,可是用戶態(tài)和內(nèi)核態(tài)讀取的結(jié)果不一樣,內(nèi)核態(tài)得到的結(jié)果與預(yù)期一致。
用戶態(tài)代碼如下:
  1. #include <stdio.h>

  2. #define store_tr(tr) __asm__ ("str %0":"=mr" (tr))

  3. int main(void)
  4. {
  5.     unsigned short tr = 0;
  6.     store_tr(tr);
  7.     printf("tr=0x%x\n", tr);
  8.     return 0;
  9. }
復(fù)制代碼
結(jié)果為:tr=0x4000

內(nèi)核模塊代碼:
  1. #include <linux/module.h>
  2. #include <linux/moduleparam.h>
  3. #include <linux/init.h>

  4. #include <linux/kernel.h>       /* printk() */

  5. #define store_tr(tr) __asm__ ("str %0":"=mr" (tr))

  6. static int
  7. tr_module_init(void)
  8. {
  9.     unsigned short tr = 0;

  10.     printk(KERN_WARNING "tr_module_init\n");

  11.     store_tr(tr);
  12.     printk(KERN_WARNING "tr=0x%x\n", tr);
  13.     return 0;
  14. }

  15. static void
  16. tr_module_exit(void)
  17. {
  18.     printk(KERN_WARNING "tr_module_exit\n");
  19. }


  20. MODULE_AUTHOR("nobody");
  21. MODULE_LICENSE("Dual BSD/GPL");

  22. module_init(tr_module_init);
  23. module_exit(tr_module_exit);
復(fù)制代碼
結(jié)果為tr=0x80

我的環(huán)境是CENTOS5,內(nèi)核為2.6.18. 根據(jù)arch/i386/kernel/head.S中的全局段描述符的定義:
  1. ENTRY(cpu_gdt_table)
  2.         .quad 0x0000000000000000        /* NULL descriptor */
  3.         .quad 0x0000000000000000        /* 0x0b reserved */
  4.         .quad 0x0000000000000000        /* 0x13 reserved */
  5.         .quad 0x0000000000000000        /* 0x1b reserved */
  6.         .quad 0x0000000000000000        /* 0x20 unused */
  7.         .quad 0x0000000000000000        /* 0x28 unused */
  8.         .quad 0x0000000000000000        /* 0x33 TLS entry 1 */
  9.         .quad 0x0000000000000000        /* 0x3b TLS entry 2 */
  10.         .quad 0x0000000000000000        /* 0x43 TLS entry 3 */
  11.         .quad 0x0000000000000000        /* 0x4b reserved */
  12.         .quad 0x0000000000000000        /* 0x53 reserved */
  13.         .quad 0x0000000000000000        /* 0x5b reserved */

  14.         .quad 0x00cf9a000000ffff        /* 0x60 kernel 4GB code at 0x00000000 */
  15.         .quad 0x00cf92000000ffff        /* 0x68 kernel 4GB data at 0x00000000 */
  16.         .quad 0x00cffa000000ffff        /* 0x73 user 4GB code at 0x00000000 */
  17.         .quad 0x00cff2000000ffff        /* 0x7b user 4GB data at 0x00000000 */

  18.         .quad 0x0000000000000000        /* 0x80 TSS descriptor */
  19.         .quad 0x0000000000000000        /* 0x88 LDT descriptor */

  20.         /*
  21.          * Segments used for calling PnP BIOS have byte granularity.
  22.          * They code segments and data segments have fixed 64k limits,
  23.          * the transfer segment sizes are set at run time.
  24.          */
  25.         .quad 0x00409a000000ffff        /* 0x90 32-bit code */
  26.         .quad 0x00009a000000ffff        /* 0x98 16-bit code */
  27.         .quad 0x000092000000ffff        /* 0xa0 16-bit data */
  28.         .quad 0x0000920000000000        /* 0xa8 16-bit data */
  29.         .quad 0x0000920000000000        /* 0xb0 16-bit data */
  30. ...
復(fù)制代碼
TSS descriptor是第16個entry,每個entry是8bytes,所以tr中的段選擇子為16*8=128=0x80.

請教各位大牛為什么同樣的指令在用戶態(tài)得到的結(jié)果不對呢?

小弟為內(nèi)核菜鳥,請各位前輩多多賜教

論壇徽章:
0
2 [報告]
發(fā)表于 2011-11-06 01:55 |只看該作者
自己頂一個

論壇徽章:
0
3 [報告]
發(fā)表于 2011-11-07 13:56 |只看該作者
本帖最后由 wangjianchangdx 于 2011-11-07 13:58 編輯
The STR instruction is useful only in operating-system software. It can only be
executed in protected mode.


FROM intel manual volume 2b: STR

具體在用戶態(tài)獲取的值是如何生成的,不得而知。
您需要登錄后才可以回帖 登錄 | 注冊

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP