1

Question 1.
Whats the meaning of

asm volatile ("ljmp %0, $1f\n 1:\n" :: "i" (KERNEL_CS));

My guess is setting %cs as KERNEL_CS,but what about the immediate number $1f?

Question 2.

If we can use jmp label to jump to some label,why do we bother writing jmp label f or jmp label b?

Question 3.

Can my kernel program use asm volatile ("ljmp %0, $1f\n 1:\n" :: "i" (USER_CS)); to change the privilege level to ring 3 at ring 0?I did this in my ISR,and I got General Protection Error.But I think my %cs and %ip are in valid exeutable and readeble memory segment after jmp,because my GDT is something like this

static struct segdesc gdt[] = {
SEG_NULL,
[SEG_KTEXT] = SEG(STA_X | STA_R, 0x0, 0xFFFFFFFF, DPL_KERNEL),
[SEG_KDATA] = SEG(STA_W, 0x0, 0xFFFFFFFF, DPL_KERNEL),
[SEG_UTEXT] = SEG(STA_X | STA_R, 0x0, 0xFFFFFFFF, DPL_USER),
[SEG_UDATA] = SEG(STA_W, 0x0, 0xFFFFFFFF, DPL_USER),
[SEG_TSS]    = SEG_NULL,

};

Both KERNEL TEXT ,DATA and USER TEXT ,DATA segment are strating from the same address and have the same size.

8
  • 3
    The code is using unnamed local labels. They come in handy if you want to avoid name collision. You can only use b (back) and f (forward) with such local labels.
    – Jester
    Jan 4, 2018 at 12:37
  • but $1 is an immediate number,if its a label,why not 1f instead? Jan 4, 2018 at 12:44
  • 2
    That's just a syntax peculiarity of at&t far jump.
    – Jester
    Jan 4, 2018 at 12:53
  • 1
    Basically, the AT&T assembler was never designed to actually use segmentation, so anything involving segmentation is a bit clunky. Here, a long jump is implemented as an instruction taking two immediates as that's simpler to implement in the assembler for an instruction used about once in the kernel.
    – fuz
    Jan 4, 2018 at 12:55
  • Got it,thank you very much Jan 4, 2018 at 13:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.