First Linux Study

Source: Internet
Author: User
Linux first-Linux general technology-Linux programming and kernel information. The following is a detailed description. 1: # define FIRST_TSS_ENTRY 4

2: # define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY + 1)

3: # define _ TSS (n) (unsigned long n) <4) + (FIRST_TSS_ENTRY <3 ))

4: # define _ LDT (n) (unsigned long n) <4) + (FIRST_LDT_ENTRY <3 ))

5: # define ltr (n) _ asm _ ("ltr % ax": "a" (_ TSS (n )))

6: # define lldt (n) _ asm _ ("lldt % ax": "a" (_ LDT (n )))

The above 4 indicates that each starting with 0 represents 4th bits of 8 bytes.

FIRST_TSS_ENTRY <3

The tss of the 1st tasks is 2 8 bytes offset from the 0th tasks, so 16 bytes are moved.

That is, (unsigned long n) <4

The loading of the nth task tr ldtr is the number of bytes of their offset


// Certificate //---------------------------------------------------------------------------------------------------------------------------------------------

Where is TSS? In the struct task_struct component struct tss_struct tss

Where is LDT? Also in struct task_struct, the component struct desc_struct ldt [3]

How does GDT manage TSS and LDT?

Struct tss_struct and struct desc_struct are both in the kernel, so they can be found through 32 offset addresses.

What are their attributes? That is, permission issues.

Therefore, you must set their location and permissions in GDT.

The Code is as follows:

# Define _ set_tssldt_desc (n, addr, type )\

_ Asm _ ("movw $104, % 1 \ n \ t "\

"Movw % ax, % 2 \ n \ t "\

"Rorl $16, % eax \ n \ t "\

"Movb % al, % 3 \ n \ t "\

"Movb $" type ", % 4 \ n \ t "\

"Movb $0x00, % 5 \ n \ t "\

"Movb % ah, % 6 \ n \ t "\

"Rorl $16, % eax "\

: "A" (addr), "m" (* (n), "m" (* (n + 2 )), "m" (* (n + 4 )),\

"M" (* (n + 5), "m" (* (n + 6), "m" (* (n + 7 )\

)

The same applies to other IDT.

I learned Linux because I am ignorant of Windows ~~~~

However, a lot of things make a headache During the learning process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.