* libcurses++, libc++ and liblightOS++ are installed into the crosscompiler directory
[lightOS.git] / kernel / x86 / _v86.S
blobef611b4f41a4e92ab263791c760fb5a2481905ea
1 /*
2 lightOS kernel
3 Copyright (C) 2007-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19 #include <Makefile.asm.config>
21 #ifdef _LIGHTOS_V86
23 .global executeV8086Thread
24 .global int86
25 .global getState86
26 .global kernelTSS
27 .global v8086TSS
28 /*#############################################################################
29 ##### code segment                                                        #####
30 #############################################################################*/
31 .section .text
32 /*#############################################################################
33 ##### Execute an interrupt in virtual-8086-mode                           #####
34 #############################################################################*/
35         int86:
36                 /* Initialize the kernel virtual-8086-TSS */
37                 movl $0x300000, (kernelTSS + 28)
38                 movl $0x10, (kernelTSS + 72)
39                 movl $0x08, (kernelTSS + 76)
40                 movl $0x10, (kernelTSS + 80)
41                 movl $0x10, (kernelTSS + 84)
42                 movl $0x10, (kernelTSS + 88)
43                 movl $0x10, (kernelTSS + 92)
44                 
45                 /* Initialize the virtual-8086-TSS */
46                 movl $0xFFFFE000, (v8086TSS + 4)        // esp0
47                 movl $0x10, (v8086TSS + 8)                      // ss0
48                 movl $0x300000, (v8086TSS + 28)         // cr3
49                 movw $0x88, (v8086TSS + 102)
50                 movb $0x40, (v8086TSS + 135)
51                 
52                 /* safe kernel state in tss */
53                 movl $int86_return, (kernelTSS+32)
54                 movl $0x01, (kernelTSS+40)
55                 mov %ecx, (kernelTSS+44)
56                 mov %edx, (kernelTSS+48)
57                 mov %ebx, (kernelTSS+52)
58                 mov %esp, (kernelTSS+56)
59                 mov %ebp, (kernelTSS+60)
60                 mov %esi, (kernelTSS+64)
61                 mov %edi, (kernelTSS+68)
62                 pushf
63                 pop %eax
64                 mov %eax, (kernelTSS+36)
65                 
66                 mov %esp, %ebp
67                 
68                 mov $0x300000, %eax
69                 mov %eax, %cr3
70                 
71                 mov 4(%ebp), %ebx
72                 mov $0xCD, %ah
73                 mov %ah, 0x100
74                 mov %bl, 0x101
75                 mov %ah, 0x102
76                 movb $0xFE, 0x103
77                 
78                 pushl $0                        /* gs */
79                 pushl $0                        /* fs */
80                 mov 24(%ebp), %eax
81                 push %eax                       /* ds */
82                 mov 28(%ebp), %eax
83                 push %eax                       /* es */
84                 pushl $0x0000           /* ss */
85                 pushl $0x1000           /* esp */
86                 pushl $0x23202          /* eflags */
87                 pushl $0                        /* cs */
88                 pushl $0x100            /* eip */
89                 
90                 mov 8(%ebp), %eax
91                 mov 12(%ebp), %ebx
92                 mov 16(%ebp), %ecx
93                 mov 20(%ebp), %edx
94                 mov 32(%ebp), %edi
95                 mov 36(%ebp), %esi
96                 
97                 iret
98         
99         executeV8086Thread:
100                 /* Clear NT flag */
101                 push %eax
102                 pushf
103                 pop %eax
104                 and $0xFFFFBFFF, %eax
105                 push %eax
106                 popf
107                 pop %eax
108                 
109                 mov $0xFFFFDFB4, %esp
110                 popa
111                 add $0x08, %esp
112                 iret
113         
114         int86_return:
115                 /* Clear NT Flag */
116                 push %eax
117                 pushf
118                 pop %eax
119                 and $0xFFFFBFFF, %eax
120                 push %eax
121                 popf
122                 pop %eax
123                 
124                 ret
125         
126         getState86:
127                 push %eax
128                 push %ebx
129                 mov 12(%esp), %ebx
130                 
131                 mov v8086TSS+40, %eax
132                 mov %eax, (%ebx)
133                 mov v8086TSS+52, %eax
134                 mov %eax, 4(%ebx)
135                 mov v8086TSS+44, %eax
136                 mov %eax, 8(%ebx)
137                 mov v8086TSS+48, %eax
138                 mov %eax, 12(%ebx)
139                 mov v8086TSS+84, %eax
140                 mov %eax, 16(%ebx)
141                 mov v8086TSS+72, %eax
142                 mov %eax, 20(%ebx)
143                 mov v8086TSS+68, %eax
144                 mov %eax, 24(%ebx)
145                 mov v8086TSS+64, %eax
146                 mov %eax, 28(%ebx)
147                 
148                 pop %ebx
149                 pop %eax
150                 ret
151 /*#############################################################################
152 ##### BSS segment                                                         #####
153 #############################################################################*/
154 .section .bss
155         /*########################################################################
156         ##### virtual-8086-mode tss                                          #####
157         ########################################################################*/
158         v8086TSS:
159                 .rept 0x2088
160                         .byte 0
161                 .endr
162         /*########################################################################
163         ##### Kernel TSS for virtual-8086-tasks                              #####
164         ########################################################################*/
165         kernelTSS:
166                 .rept 0x68
167                         .int 0
168                 .endr
170 #endif