<br><br><div class="gmail_quote">2012/10/28 Fan Yang <span dir="ltr"><<a href="mailto:lljyangfan@gmail.com" target="_blank">lljyangfan@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">2012/10/27 Jun Hu <span dir="ltr"><<a href="mailto:duanshuidao@hotmail.com" target="_blank">duanshuidao@hotmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div style="font-size:14pt;font-family:'Calibri'">
<div><font size="4">Can you post out your codes ?</font></div>
<div style="font-size:small;font-style:normal;text-decoration:none;font-family:'Calibri';display:inline;font-weight:normal">
<div style="FONT:10pt tahoma">
<div> </div>
<div style="BACKGROUND:#f5f5f5">
<div><b>From:</b> <a title="lljyangfan@gmail.com" href="mailto:lljyangfan@gmail.com" target="_blank">Fan Yang</a> </div>
<div><b>Sent:</b> Wednesday, October 24, 2012 8:04 PM</div>
<div><b>To:</b> <a title="kernelnewbies@kernelnewbies.org" href="mailto:kernelnewbies@kernelnewbies.org" target="_blank">kernelnewbies@kernelnewbies.org</a>
</div>
<div><b>Subject:</b> linux segment</div></div></div>
<div> </div></div>
<div style="font-size:small;font-style:normal;text-decoration:none;font-family:'Calibri';display:inline;font-weight:normal"><div>Hi
all:
<div> I print the cs ds and ss register in the user space, and
it is same as the __USER_CS and __USER_DS which defined in kernel as 73 and 7b.
In the kernel __KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print
this two value in my kernel module, I get 60 and 7b. Why ? It should be 60 and
68, shouldn't it? <br>
<div> </div>
<div> </div></div>
</div><p>
</p><hr>
_______________________________________________<br>Kernelnewbies mailing
list<br><a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br><a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<p></p></div></div></div></div>
</blockquote></div></div></div>Hi Jun Hu<div> There is my code which run at the user space:</div><div><br></div><div><div> 1 #include<stdio.h></div><div> 2 main()</div><div> 3 {</div><div> 4 unsigned long cs, ds, ss, es, fs, gs;</div>
<div> 5 asm volatile("movl %%CS,%0\n\t":"=r"(cs));</div><div> 6 asm volatile("movl %%DS,%0\n\t":"=r"(ds));</div><div> 7 asm volatile("movl %%SS,%0\n\t":"=r"(ss));</div>
<div> 8 asm volatile("movl %%ES,%0\n\t":"=r"(es)); </div><div> 9 asm volatile("movl %%FS,%0\n\t":"=r"(fs));</div><div> 10 asm volatile("movl %%GS,%0\n\t":"=r"(gs));</div>
<div> 11 printf ("**********************************\n");</div><div> 12 printf ("cs %lx\t%ld\n", cs, cs);</div><div> 13 printf ("ds %lx\t%ld\n", ds, ds);</div><div> 14 printf ("ss %lx\t%ld\n", ss, ss);</div>
<div> 15 printf ("es %lx\t%ld\n", es, es);</div><div> 16 printf ("fs %lx\t%ld\n", fs, fs);</div><div> 17 printf ("gs %lx\t%ld\n", gs, gs);</div><div> 18 printf ("**********************************\n");</div>
<div> 19 }</div></div><div><br></div><div><br></div><div><br></div><div>and the result of the progress in my machine is </div><div><br></div><div><br></div><div><div>**********************************</div><div>cs 73<span style="white-space:pre-wrap">        </span>115</div>
<div>ds 7b<span style="white-space:pre-wrap">        </span>123</div><div>ss 7b<span style="white-space:pre-wrap">        </span>123</div><div>es 7b<span style="white-space:pre-wrap">        </span>123</div>
<div>fs 0<span style="white-space:pre-wrap">        </span>0</div><div>gs 33<span style="white-space:pre-wrap">        </span>51</div><div>**********************************</div></div><div><br></div>
<div><br></div><div>so, you can see the cs and ds register is 73 and 7b which are same as the kernel defined. And the code of the kernel module is</div><div><br></div><div><br></div><div><div> 1 #include<linux/init.h> </div>
<div> 2 #include<linux/kernel.h></div><div> 3 #include<linux/module.h></div><div> 4 </div><div> 5 static void __init print_init (void)</div><div> 6 {</div><div> 7 unsigned long cs, ds, ss, es, fs, gs,currenttime;</div>
<div> 8 asm volatile("movl %%CS,%0\n\t":"=r"(cs));</div><div> 9 asm volatile("movl %%DS,%0\n\t":"=r"(ds));</div><div> 10 asm volatile("movl %%SS,%0\n\t":"=r"(ss));</div>
<div> 11 asm volatile("movl %%ES,%0\n\t":"=r"(es));</div><div> 12 asm volatile("movl %%FS,%0\n\t":"=r"(fs));</div><div> 13 asm volatile("movl %%GS,%0\n\t":"=r"(gs));</div>
<div> 14 printk ("**********************************\n");</div><div> 15 printk ("cs %lx\t%ld\n", cs, cs);</div><div> 16 printk ("ds %lx\t%ld\n", ds, ds);</div><div> 17 printk ("ss %lx\t%ld\n", ss, ss);</div>
<div> 18 printk ("es %lx\t%ld\n", es, es);</div><div> 19 printk ("fs %lx\t%ld\n", fs, fs);</div><div> 20 printk ("gs %lx\t%ld\n", gs, gs);</div><div> 21 printk ("**********************************\n");</div>
<div> 22 </div><div> 23 }</div></div><div><div>24 </div><div> 25 static void __exit print_exit (void)</div><div> 26 {</div><div> 27 unsigned long cs, ds, ss;</div><div> 28 asm volatile("movl %%cs,%0\n\t":"=r"(cs));</div>
<div> 29 asm volatile("movl %%ds,%0\n\t":"=r"(ds));</div><div> 30 asm volatile("movl %%ss,%0\n\t":"=r"(ss));</div><div> 31 </div><div> 32 printk ("**********************************\n");</div>
<div> 33 printk ("cs %lx\t%ld\n", cs, cs);</div><div> 34 printk ("ds %lx\t%ld\n", ds, ds);</div><div> 35 printk ("ss %lx\t%ld\n", ss, ss);</div><div> 36 printk ("**********************************\n");</div>
<div> 37 printk ("*****************bye***************\n");</div><div> 38 }</div><div> 39 </div><div> 40 module_init (print_init);</div><div> 41 module_exit (print_exit); </div>
<div> 42 MODULE_LICENSE ("GPL");</div></div><div><br></div><div><br></div><div>the result of the running this module is </div><div><br></div><div><div>[root@shell--box kernel_mod]# dmesg -c</div><div>**********************************</div>
<div>cs 60<span style="white-space:pre-wrap">        </span>96</div><div>ds 7b<span style="white-space:pre-wrap">        </span>123</div><div>ss 68<span style="white-space:pre-wrap">        </span>104</div>
<div>es 7b<span style="white-space:pre-wrap">        </span>123</div><div>fs d8<span style="white-space:pre-wrap">        </span>216</div><div>gs e0<span style="white-space:pre-wrap">        </span>224</div>
<div>**********************************</div></div><div><br></div><div>The cs and ds in the kernel space is 60 and 7b. But the kernel define the KERNEL_CS as 60 and the KERNEL_DS as 7b. Where am I wrong?</div><div><br>
</div>
<div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>Fan</div>
</font></span></blockquote></div><br><div>sorry, the kernel define the KERNEL_DS as 68, but I get 7b in my machine.</div>