xref: /reactos/boot/freeldr/freeldr/arch/i386/int386.S (revision ff722ac7)
1/*
2 *  FreeLoader
3 *  Copyright (C) 1998-2002  Brian Palmer  <brianp@sginet.com>
4 *
5 *  This program is free software; you can redistribute it and/or modify
6 *  it under the terms of the GNU General Public License as published by
7 *  the Free Software Foundation; either version 2 of the License, or
8 *  (at your option) any later version.
9 *
10 *  This program is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 *  GNU General Public License for more details.
14 *
15 *  You should have received a copy of the GNU General Public License along
16 *  with this program; if not, write to the Free Software Foundation, Inc.,
17 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <asm.inc>
21#include <arch/pc/x86common.h>
22#include <arch/pc/pcbios.h>
23
24.code32
25
26EXTERN SwitchToReal:PROC
27EXTERN ContinueAddress:DWORD
28
29Int386_regsin:
30    .long 0
31Int386_regsout:
32    .long 0
33
34/*
35 * int Int386(int ivec, REGS* in, REGS* out);
36 */
37PUBLIC _Int386
38_Int386:
39
40    /* Get the function parameters */
41    mov eax, dword ptr [esp + 4]
42    mov dword ptr ds:[BSS_IntVector], eax
43    mov eax, dword ptr [esp + 8]
44    mov dword ptr [Int386_regsin], eax
45    mov eax, dword ptr [esp + 12]
46    mov dword ptr [Int386_regsout], eax
47
48    /* Save all registers + segment registers */
49    push ds
50    push es
51    push fs
52    push gs
53    pusha
54
55    /* Copy input registers */
56    mov esi, dword ptr [Int386_regsin]
57    mov edi, BSS_RegisterSet
58    mov ecx, REGS_SIZE / 4
59    rep movsd
60
61    /* Set the function ID */
62    mov bx, FNID_Int386
63
64    /* Set continue address and switch to real mode */
65    mov dword ptr [ContinueAddress], offset Int386_return
66    jmp SwitchToReal
67
68Int386_return:
69
70    /* Copy output registers */
71    mov esi, BSS_RegisterSet
72    mov edi, dword ptr [Int386_regsout]
73    mov ecx, REGS_SIZE / 4
74    rep movsd
75
76    /* Restore all registers + segment registers */
77    popa
78    pop gs
79    pop fs
80    pop es
81    pop ds
82    ret
83
84END
85