calling BIOS :) - Minix

This is a discussion on calling BIOS :) - Minix ; Hi all, I was trying to interprete how minix make a BIOS call. And I found that in _int86 in klib386.s . The point is I could not interprete the marked lines in the following code. And the Qs are: ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: calling BIOS :)

  1. calling BIOS :)

    Hi all,

    I was trying to interprete how minix make a BIOS call. And I found that
    in _int86 in klib386.s . The point is I could not interprete the marked
    lines in the following code. And the Qs are:

    Q1. Why to push cs?
    Q2. What is the meanning of 20+2*4+10*4+2*4(esp)?
    Q3. And dose "jmpf" cause the CPU to return to the real mode again?

    Thanx in advance

    Regards,
    M.



    ..
    ..
    push (_reg86+16)
    push (_reg86+12)
    push (_reg86+ 8)
    push (_reg86+ 4)
    push (_reg86+ 0)
    mov ds, ax ! remaining data selectors
    mov es, ax
    mov fs, ax
    mov gs, ax
    >> push cs
    >> push return ! kernel return address and selector
    >> o16 jmpf 20+2*4+10*4+2*4(esp) ! make the call
    >> return:

    pop (_reg86+ 0)
    pop (_reg86+ 4)
    pop (_reg86+ 8)
    pop (_reg86+12)
    pop (_reg86+16)
    pop (_reg86+20)
    pop (_reg86+24)
    pop (_reg86+28)
    pop (_reg86+32)
    pop (_reg86+36)
    lgdt (_gdt+GDT_SELECTOR) ! reload global descriptor table
    jmpf CS_SELECTOR:csinit ! restore everything
    ..
    ..


  2. Re: calling BIOS :)

    > I was trying to interprete how minix make a BIOS call. And I found
    > that in _int86 in klib386.s . The point is I could not interprete the
    > marked lines in the following code. And the Qs are:
    >
    > Q1. Why to push cs?


    The following combination

    push cs
    push return
    jmpf something

    Basically corresponds to a far call, where "far" means that the
    destination is in a different code segment. To be able to return, both
    the current code segment (CS) and the return address inside this
    segment (return) need to be pushed on the stack.

    > Q2. What is the meanning of 20+2*4+10*4+2*4(esp)?


    It seems to me 20+2*4+10*4+2*4 is just a complex way to express 76,
    which is then added to the stack pointer (ESP). At this location the
    destination segment and pointer are read for the jump.

    As the stack grows downwards, 76(esp) is something that was pushed some
    time ago. The sum expression seems to correspond to the groups of
    pushes, so you should be able to find the place where the destination
    is pushed easily. 2*4 corresponds to push cs/push return. 10*4 seems to
    correspond to the block of _reg86 expressions pushed before. T

    > Q3. And dose "jmpf" cause the CPU to return to the real mode again?


    It's just a far jump. AFAIK the only way to switch between real and
    protected modes is to change a bit in one of the control registers. Of
    course the code at the destionation of the jump could do such a thing,
    but the jmpf itself does not.

  3. Re: calling BIOS :)

    > > Q3. And dose "jmpf" cause the CPU to return to the real mode again?
    >
    > It's just a far jump. AFAIK the only way to switch between real and
    > protected modes is to change a bit in one of the control registers. Of
    > course the code at the destionation of the jump could do such a thing,
    > but the jmpf itself does not.


    The way to switch from real mode to protected mode is easy (toggle a bit),
    but the way back isn't easy on a 80286. There you must reset the processor
    somehow (it's done through the keyboard handler, or doing a triple-fault),
    because this bit cannot be set back if the CPU is in protected mode.

    I don't know how Minix 3 handles that, but (although I didn't check this
    myself yet) I believe even Minix 2 (386) does it this hard way, simply
    because having one code base is easier than having many.

    Regards,
    Sebastian



  4. Re: calling BIOS :)

    In article <45747c47$0$30326$9b4e6d93@newsspool1.arcor-online.net>,
    Sebastian wrote:
    >
    >The way to switch from real mode to protected mode is easy (toggle a bit),
    >but the way back isn't easy on a 80286. There you must reset the processor
    >somehow (it's done through the keyboard handler, or doing a triple-fault),
    >because this bit cannot be set back if the CPU is in protected mode.
    >
    >I don't know how Minix 3 handles that,


    It doesn't run on a 286 anymore, so no reset needed.

    >but (although I didn't check this
    >myself yet) I believe even Minix 2 (386) does it this hard way, simply
    >because having one code base is easier than having many.


    That's how it started, because I didn't see any reason to run a 16-bit
    Minix on a 386+ other than for testing purposes, so I saw no need to
    optimize it. Until I got weird crashes on the 486 I used for testing.
    After a lot of hairpulling I found out that that system would corrupt
    memory here and there after a reset. So the 16-bit code was changed to
    only do the reset on a 286 and toggle a bit on a 386+.
    --
    Kees J. Bot, Systems Programmer, Sciences dept., Vrije Universiteit Amsterdam

+ Reply to Thread