All of lore.kernel.org
 help / color / mirror / Atom feed
From: lljyangfan@gmail.com (Fan Yang)
To: kernelnewbies@lists.kernelnewbies.org
Subject: linux segment
Date: Sun, 28 Oct 2012 22:20:13 +0800	[thread overview]
Message-ID: <CAPihQtt5v1iXokcGSaBTRBLSDemxP-QrL_adsrN+vCcB7j+1DA@mail.gmail.com> (raw)
In-Reply-To: <CAPihQtuqZJ98572qnJZOgV9XHFBS_zigg+KHFogS6-nW6yZFrQ@mail.gmail.com>

2012/10/28 Fan Yang <lljyangfan@gmail.com>

>
>
> 2012/10/27 Jun Hu <duanshuidao@hotmail.com>
>
>>   Can you post out your codes ?
>>
>>  *From:* Fan Yang <lljyangfan@gmail.com>
>> *Sent:* Wednesday, October 24, 2012 8:04 PM
>> *To:* kernelnewbies at kernelnewbies.org
>> *Subject:* linux segment
>>
>> Hi all:
>>     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?
>>
>>
>>
>> ------------------------------
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>> Hi Jun Hu
>     There is my code which run at the user space:
>
>   1 #include<stdio.h>
>   2 main()
>   3 {
>   4     unsigned long cs, ds, ss, es, fs, gs;
>   5     asm volatile("movl %%CS,%0\n\t":"=r"(cs));
>   6     asm volatile("movl %%DS,%0\n\t":"=r"(ds));
>   7     asm volatile("movl %%SS,%0\n\t":"=r"(ss));
>   8     asm volatile("movl %%ES,%0\n\t":"=r"(es));
>
>   9     asm volatile("movl %%FS,%0\n\t":"=r"(fs));
>  10     asm volatile("movl %%GS,%0\n\t":"=r"(gs));
>  11     printf ("**********************************\n");
>  12     printf ("cs %lx\t%ld\n", cs, cs);
>  13     printf ("ds %lx\t%ld\n", ds, ds);
>  14     printf ("ss %lx\t%ld\n", ss, ss);
>  15     printf ("es %lx\t%ld\n", es, es);
>  16     printf ("fs %lx\t%ld\n", fs, fs);
>  17     printf ("gs %lx\t%ld\n", gs, gs);
>  18     printf ("**********************************\n");
>  19 }
>
>
>
> and the result of the progress in my machine is
>
>
> **********************************
> cs 73 115
> ds 7b 123
> ss 7b 123
> es 7b 123
> fs 0 0
> gs 33 51
> **********************************
>
>
> 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
>
>
>  1 #include<linux/init.h>
>
>   2 #include<linux/kernel.h>
>   3 #include<linux/module.h>
>   4
>   5 static void __init print_init (void)
>   6 {
>   7     unsigned long cs, ds, ss, es, fs, gs,currenttime;
>   8     asm volatile("movl %%CS,%0\n\t":"=r"(cs));
>   9     asm volatile("movl %%DS,%0\n\t":"=r"(ds));
>  10     asm volatile("movl %%SS,%0\n\t":"=r"(ss));
>  11     asm volatile("movl %%ES,%0\n\t":"=r"(es));
>  12     asm volatile("movl %%FS,%0\n\t":"=r"(fs));
>  13     asm volatile("movl %%GS,%0\n\t":"=r"(gs));
>  14     printk ("**********************************\n");
>  15     printk ("cs %lx\t%ld\n", cs, cs);
>  16     printk ("ds %lx\t%ld\n", ds, ds);
>  17     printk ("ss %lx\t%ld\n", ss, ss);
>  18     printk ("es %lx\t%ld\n", es, es);
>  19     printk ("fs %lx\t%ld\n", fs, fs);
>  20     printk ("gs %lx\t%ld\n", gs, gs);
>  21     printk ("**********************************\n");
>  22
>  23 }
> 24
>  25 static void __exit print_exit (void)
>  26 {
>  27     unsigned long cs, ds, ss;
>  28     asm volatile("movl %%cs,%0\n\t":"=r"(cs));
>  29     asm volatile("movl %%ds,%0\n\t":"=r"(ds));
>  30     asm volatile("movl %%ss,%0\n\t":"=r"(ss));
>  31
>  32     printk ("**********************************\n");
>  33     printk ("cs %lx\t%ld\n", cs, cs);
>  34     printk ("ds %lx\t%ld\n", ds, ds);
>  35     printk ("ss %lx\t%ld\n", ss, ss);
>  36     printk ("**********************************\n");
>  37     printk ("*****************bye***************\n");
>  38 }
>  39
>  40 module_init (print_init);
>  41 module_exit (print_exit);
>
>  42 MODULE_LICENSE ("GPL");
>
>
> the result of the running this module is
>
> [root at shell--box kernel_mod]# dmesg -c
> **********************************
> cs 60 96
> ds 7b 123
> ss 68 104
> es 7b 123
> fs d8 216
> gs e0 224
> **********************************
>
> 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?
>
>
> Thanks
> Fan
>

sorry, the kernel define the KERNEL_DS as 68, but I get 7b in my machine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20121028/1fa6c002/attachment-0001.html 

  reply	other threads:[~2012-10-28 14:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 12:04 linux segment Fan Yang
2012-10-26 23:53 ` Mulyadi Santosa
2012-10-27  7:49 ` Jun Hu
2012-10-28 14:02   ` Fan Yang
2012-10-28 14:20     ` Fan Yang [this message]
2012-10-29  7:32     ` Mulyadi Santosa
2012-10-30  0:44       ` Fan Yang
2012-10-30  6:04         ` Mulyadi Santosa
2012-11-02  9:32         ` Tobias Boege
2013-06-20  9:02 ` Baoquan He
2013-06-20 10:01   ` Fan Yang
2013-06-20 13:40     ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPihQtt5v1iXokcGSaBTRBLSDemxP-QrL_adsrN+vCcB7j+1DA@mail.gmail.com \
    --to=lljyangfan@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.