Annotation of coherent/b/lib/libc/gen/i8086/setjmp.s, revision 1.1

1.1     ! root        1: / Coherent C library
        !             2: / i8086 small model
        !             3: 
        !             4:        .globl  setjmp_
        !             5:        .globl  longjmp_
        !             6: 
        !             7: / #include <setjmp.h>
        !             8: / int
        !             9: / setjmp(env);
        !            10: / jmp_buf env;
        !            11: /
        !            12: / int
        !            13: / longjmp(env, value);
        !            14: / jmp_buf env;
        !            15: / int value;
        !            16: /
        !            17: / These two routines implement non local gotos. "setjmp" treasures away,
        !            18: / int the supplied "env", the frame pointer, the stack pointer and the
        !            19: / return address. It then returns 0. A call to "longjmp" restores the stack
        !            20: / to that saved in the "env", and causes the call to "setjmp" to return
        !            21: / again, returning "value".
        !            22: 
        !            23: setjmp_:
        !            24:        pop     cx                      / cx = return address.
        !            25: 
        !            26:        mov     bx, sp                  / bx = pointer to the
        !            27:        mov     bx, 0(bx)               / env. block.
        !            28:        mov     0(bx), bp               / save frame.
        !            29:        mov     2(bx), sp               / save stack (ret addr popped).
        !            30:        mov     4(bx), cx               / save ret addr.
        !            31: 
        !            32:        sub     ax, ax                  / return 0 to the
        !            33:        ijmp    cx                      / caller.
        !            34: 
        !            35: longjmp_:
        !            36:        mov     bx, sp                  / point bx into the stack and
        !            37:        mov     ax, 4(bx)               / grab the value
        !            38:        mov     bx, 2(bx)               / and the saved env. pointer.
        !            39: 
        !            40:        mov     cx, 0(bx)               / cx is desired bp.
        !            41: 
        !            42: l0:    cmp     cx, 0(bp)               / correct frame ??
        !            43:        je      l1                      / yes.
        !            44:        mov     bp, 0(bp)               / unwind a frame.
        !            45:        or      bp, bp                  / hit top ??
        !            46:        jne     l0                      / nope, unwind another.
        !            47: 
        !            48:        mov     bp, cx                  / take a stab at
        !            49:        jmp     l2                      / restoring the frame.
        !            50: 
        !            51: l1:    mov     sp, bp                  / reset stack to correct place
        !            52:        pop     bp                      / and restore frame
        !            53:        pop     di                      / and the two
        !            54:        pop     si                      / register variables.
        !            55: 
        !            56: l2:    mov     sp, 2(bx)               / reload sp and
        !            57:        ijmp    4(bx)                   / return from the setjmp.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.