Skip to content

Try to register syscall but got smth wrong #592

Description

@zhangxuan2011

Preface

I just writin a fn that enables the syscall. Here's the code about making GDT and enabling syscall:

Making GDT:

    let kcode = gdt.append(Descriptor::kernel_code_segment());
    let kdata = gdt.append(Descriptor::kernel_data_segment());
    let udata = gdt.append(Descriptor::user_data_segment());
    let ucode = gdt.append(Descriptor::user_code_segment());
    let tss = gdt.append(Descriptor::tss_segment(&TSS));

Enabling syscall:

    let sel = GDT.1;
    Star::write(
        sel.user_code,  // cs_sysret
        sel.user_data,  // ss_sysret
        sel.kernel_code, // cs_syscall
        sel.kernel_data,  // ss_syscall
    )
    .expect("Failed to do STAR register writing");

It didn't panick. But once i do sysret, i found smth weird.

Here's the selectors of the GDT:

Image

After sysret:

Image

That's not expected! My scheduler throw an #GP because of this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions