Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* -----------------------------------------------------------------------
0003  *
0004  *   Copyright 2009-2014 Intel Corporation; author H. Peter Anvin
0005  *
0006  * ----------------------------------------------------------------------- */
0007 
0008 /*
0009  * "Glove box" for BIOS calls.  Avoids the constant problems with BIOSes
0010  * touching registers they shouldn't be.
0011  */
0012 
0013     .code16
0014     .section ".inittext","ax"
0015     .globl  intcall
0016     .type   intcall, @function
0017 intcall:
0018     /* Self-modify the INT instruction.  Ugly, but works. */
0019     cmpb    %al, 3f
0020     je  1f
0021     movb    %al, 3f
0022     jmp 1f      /* Synchronize pipeline */
0023 1:
0024     /* Save state */
0025     pushfl
0026     pushw   %fs
0027     pushw   %gs
0028     pushal
0029 
0030     /* Copy input state to stack frame */
0031     subw    $44, %sp
0032     movw    %dx, %si
0033     movw    %sp, %di
0034     movw    $11, %cx
0035     rep; movsd
0036 
0037     /* Pop full state from the stack */
0038     popal
0039     popw    %gs
0040     popw    %fs
0041     popw    %es
0042     popw    %ds
0043     popfl
0044 
0045     /* Actual INT */
0046     .byte   0xcd        /* INT opcode */
0047 3:  .byte   0
0048 
0049     /* Push full state to the stack */
0050     pushfl
0051     pushw   %ds
0052     pushw   %es
0053     pushw   %fs
0054     pushw   %gs
0055     pushal
0056 
0057     /* Re-establish C environment invariants */
0058     cld
0059     movzwl  %sp, %esp
0060     movw    %cs, %ax
0061     movw    %ax, %ds
0062     movw    %ax, %es
0063 
0064     /* Copy output state from stack frame */
0065     movw    68(%esp), %di   /* Original %cx == 3rd argument */
0066     andw    %di, %di
0067     jz  4f
0068     movw    %sp, %si
0069     movw    $11, %cx
0070     rep; movsd
0071 4:  addw    $44, %sp
0072 
0073     /* Restore state and return */
0074     popal
0075     popw    %gs
0076     popw    %fs
0077     popfl
0078     retl
0079     .size   intcall, .-intcall