^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -----------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 2009-2014 Intel Corporation; author H. Peter Anvin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * ----------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * "Glove box" for BIOS calls. Avoids the constant problems with BIOSes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * touching registers they shouldn't be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) .code16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) .section ".inittext","ax"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) .globl intcall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .type intcall, @function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) intcall:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Self-modify the INT instruction. Ugly, but works. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) cmpb %al, 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) je 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) movb %al, 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) jmp 1f /* Synchronize pipeline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Save state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) pushfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) pushw %fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pushw %gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) pushal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Copy input state to stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) subw $44, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) movw %dx, %si
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) movw %sp, %di
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) movw $11, %cx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) rep; movsd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Pop full state from the stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) popal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) popw %gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) popw %fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) popw %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) popw %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) popfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Actual INT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .byte 0xcd /* INT opcode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 3: .byte 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* Push full state to the stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) pushfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) pushw %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) pushw %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) pushw %fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) pushw %gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) pushal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Re-establish C environment invariants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) cld
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) movzwl %sp, %esp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) movw %cs, %ax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) movw %ax, %ds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) movw %ax, %es
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Copy output state from stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) movw 68(%esp), %di /* Original %cx == 3rd argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) andw %di, %di
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) jz 4f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) movw %sp, %si
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) movw $11, %cx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) rep; movsd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 4: addw $44, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Restore state and return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) popal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) popw %gs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) popw %fs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) popfl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) retl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .size intcall, .-intcall