OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 10:28 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: minix 3.1's jmp statement problem
PostPosted: Sat Nov 18, 2023 7:58 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
i am reading minix3.1 text book, the save procedure in the book on page 712 tests
whether the caller enter the kernel for the first time (from user to kernel) or later
(from kernel to kernel).
on line 6638 jmp RETADR-P_STACKBASE(eax)

The RETADR = 24
P_STACKBASE = 0
eax is essentially esp before testing k_reenter for kernel stack switch
so this statement is essentially

jmp 24-0(esp)

how does this work? it looks rather odd to me

Code:
06613
06614 !*===========================================================================*
06615 !* save *
06616 !*===========================================================================*
06617 ! Save for protected mode.
06618 ! This is much simpler than for 8086 mode, because the stack already points
06619 ! into the process table, or has already been switched to the kernel stack.
06620
06621 .align 16
06622 save:
06623 cld ! set direction flag to a known value
06624 pushad ! save "general" registers
06625 o16 push ds ! save ds
06626 o16 push es ! save es
06627 o16 push fs ! save fs
06628 o16 push gs ! save gs
06629 mov dx, ss ! ss is kernel data segment
06630 mov ds, dx ! load rest of kernel segments
06631 mov es, dx ! kernel does not use fs, gs
06632 mov eax, esp ! prepare to return
06633 incb (_k_reenter) ! from -1 if not reentering
06634 jnz set_restart1 ! stack is already kernel stack
06635 mov esp, k_stktop
06636 push _restart ! build return address for int handler
06637 xor ebp, ebp ! for stacktrace
06638 jmp RETADR-P_STACKBASE(eax)
06639
06640 .align 4
06641 set_restart1:
06642 push restart1
06643 jmp RETADR-P_STACKBASE(eax)
06644


Top
 Profile  
 
 Post subject: Re: minix 3.1's jmp statement problem
PostPosted: Sat Nov 18, 2023 8:47 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
ITchimp wrote:
The RETADR = 24

No, RETADR is 40.


Top
 Profile  
 
 Post subject: Re: minix 3.1's jmp statement problem
PostPosted: Sun Nov 19, 2023 4:34 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
i figure that out, it is just jmp -40(eax); i didn't take into account of the precedence :(


Top
 Profile  
 
 Post subject: Re: minix 3.1's jmp statement problem
PostPosted: Sun Nov 19, 2023 11:31 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1605
No, it is jmp 40(eax) (BTW, that is a weird assembler syntax, like a weird hybrid between AT&T and Intel syntax). The offset is positive. It is reading the return pointer from stack and jumping there.

_________________
Carpe diem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], MichaelPetch and 36 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group