OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 9:07 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: TSS and software switching
PostPosted: Fri Jun 26, 2020 4:29 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
nullplan wrote:
I wrote the syscall handler first, and then the multitasking code afterwards. The syscall handler was basically an outgrowth of the interrupt handler code I needed first.


That's interesting... I came from a different direction where I implemented interrupt handlers first, multitasking second and system calls last.

The end result is that I use a fake interrupt frame to spawn kernel thread and to jump to user space.

For example:

Code:
.global JumpToUserMode
JumpToUserMode:

    # rdi = entry point in user space
    # rsi = user args
    # rdx = user space stack

    movq $0x1b, %rax    # Selector 0x18 (User Data) + RPL 3
    movw %ax, %ds
    movw %ax, %es

    # Build a fake iret frame
    pushq %rax          # Selector 0x18 (User Data) + RPL 3
    pushq %rdx          # User space stack
    pushq $0x202        # rflags = interrupt enable + reserved bit
    pushq $0x23         # Selector 0x20 (User Code) + RPL 3
    pushq %rdi          # Entry point in user space

    # Setup "user args" as parameter to user function
    movq %rsi, %rdi     # First parameter = user args

    # Interrupts need to be disabled to ensure we don't
    # get interrupted between swapgs and iret.
    cli

    swapgs
    iretq

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], SemrushBot [Bot] and 112 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group