Image Map Image Map
Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: 80286 Real Mode emulation on 8088 ?

  1. #21
    Join Date
    Feb 2017
    Location
    Guildford, U.K.
    Posts
    294

    Default

    So, you also need to store the old BP value at the start of the interrupt stack, shouldn't be a problem, you just need an equate for that stack offset and to fiddle with what's there already (FLAGS on return), so you can't use an IRET to return.

    _old_BP equ 20h

    save_flags dw 0

    ;!!!!!!!!
    mov bx, word ptr [bp+_rfl]
    mov word ptr [save_flags],bx
    mov bx, word ptr [bp+_bp]
    mov word ptr [bp+_old_bp],bx
    mov bx,sp
    sub bx,ax
    mov word ptr [bp+_bp],bx
    ;!!!!!

    ...
    ; most of POPA order up to
    pop ax
    push word ptr [save_flags]
    popf
    retf (do not pop old BP into flags)

    It's probably better to use a register than a save_flags word, as I've probably forgotten something, but the principle's correct. Clear?
    Last edited by WBST; November 30th, 2019 at 11:58 AM.

  2. #22
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    3,476

    Default

    The problem is that the sp is modified 'downwards' to accommodate the additional space required for the new stack frame. The OP posted the incorrect pseudocode.

    Dave

  3. #23
    Join Date
    Feb 2017
    Location
    Guildford, U.K.
    Posts
    294

    Default

    Quote Originally Posted by daver2 View Post
    The problem is that the sp is modified 'downwards' to accommodate the additional space required for the new stack frame. The OP posted the incorrect pseudocode.

    Dave
    Yeah, I realised that after I saw your post (it took me a while to write and edit my code), and went back to my 386 Assembly Language manual. So, it's a bit more complex than I thought.

  4. #24
    Join Date
    Jun 2012
    Location
    UK - Worcester
    Posts
    3,476

    Default

    You might want to check out the source code for bochs over at https://github.com/svn2github/bochs/...cpu/stack16.cc. Search for BX_CPU_C::ENTER16_IwIb.

    Use this as your pseudocode. However, this won't help you implement it in assembler of course...

    What I am thinking is:

    1. Save all of the 80x86 registers 'classically' on the stack.
    2. Give yourself some local workspace on the stack below the registers you have just saved.
    3. Create the stack frame as you want it to be below your local workspace.
    4. Move the items above your stack frame (saved CS/IP/FLAGS and other register values) down to below your new stack frame.
    5. Copy the contents of your entire new stack frame plus register contents below 'up' (overwriting the old locations) i.e. closing up the 'gap'.
    6. Restore the CPU registers and IRET (remembering that SP and BP should contain 'new' values).

    There may be some optimisation here as the stack frame not containing pointers should just have 'garbage' in it - so doesn't need to be copied.

    Probably not explained too well - but it is late at night in the UK!

    Dave
    Last edited by daver2; November 30th, 2019 at 03:32 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •