Rev 26 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | # |
2 | # Copyright (C) 2001-2004 Jakub Jermar |
||
3 | # All rights reserved. |
||
4 | # |
||
5 | # Redistribution and use in source and binary forms, with or without |
||
6 | # modification, are permitted provided that the following conditions |
||
7 | # are met: |
||
8 | # |
||
9 | # - Redistributions of source code must retain the above copyright |
||
10 | # notice, this list of conditions and the following disclaimer. |
||
11 | # - Redistributions in binary form must reproduce the above copyright |
||
12 | # notice, this list of conditions and the following disclaimer in the |
||
13 | # documentation and/or other materials provided with the distribution. |
||
14 | # - The name of the author may not be used to endorse or promote products |
||
15 | # derived from this software without specific prior written permission. |
||
16 | # |
||
17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | # |
||
28 | |||
29 | # very low and hardware-level functions |
||
30 | |||
31 | .text |
||
32 | |||
33 | .global cpu_priority_high |
||
34 | .global cpu_priority_low |
||
35 | .global cpu_priority_restore |
||
36 | .global cpu_priority_read |
||
37 | .global cpu_halt |
||
38 | .global cpu_sleep |
||
39 | .global paging_on |
||
40 | .global cpu_read_dba |
||
41 | .global cpu_write_dba |
||
42 | .global cpu_read_cr2 |
||
43 | .global enable_l_apic_in_msr |
||
44 | .global interrupt_handlers |
||
45 | .global inb |
||
46 | .global inw |
||
47 | .global inl |
||
48 | .global outb |
||
49 | .global outw |
||
50 | .global outl |
||
51 | .global memcopy |
||
52 | .global memsetb |
||
53 | .global memsetw |
||
54 | .global memcmp |
||
27 | jermar | 55 | .global write_dr0 |
56 | .global read_dr0 |
||
1 | jermar | 57 | |
27 | jermar | 58 | write_dr0: |
59 | pushl %eax |
||
60 | movl 8(%esp),%eax |
||
61 | movl %eax,%dr0 |
||
62 | popl %eax |
||
63 | ret |
||
64 | |||
65 | read_dr0: |
||
66 | movl %dr0,%eax |
||
67 | ret |
||
68 | |||
1 | jermar | 69 | # |
70 | # set priority level high |
||
71 | cpu_priority_high: |
||
72 | pushf |
||
73 | pop %eax |
||
74 | cli |
||
75 | ret |
||
76 | |||
77 | # |
||
78 | # set priority level low |
||
79 | cpu_priority_low: |
||
80 | pushf |
||
81 | pop %eax |
||
82 | sti |
||
83 | ret |
||
84 | |||
85 | # |
||
86 | # restore priority level |
||
87 | cpu_priority_restore: |
||
88 | push 4(%esp) |
||
89 | popf |
||
90 | ret |
||
91 | |||
92 | # return raw priority level |
||
93 | cpu_priority_read: |
||
94 | pushf |
||
95 | pop %eax |
||
96 | ret |
||
97 | |||
98 | cpu_halt: |
||
99 | cpu_sleep: |
||
100 | hlt |
||
101 | ret |
||
102 | |||
103 | paging_on: |
||
104 | pushl %eax |
||
105 | movl %cr0,%eax |
||
106 | orl $(1<<31),%eax # paging on |
||
107 | andl $~((1<<30)|(1<<29)),%eax # clear Cache Disable and not Write Though |
||
108 | movl %eax,%cr0 |
||
109 | jmp 0f |
||
110 | 0: |
||
111 | popl %eax |
||
112 | ret |
||
113 | |||
114 | cpu_read_dba: |
||
115 | movl %cr3,%eax |
||
116 | ret |
||
117 | |||
118 | cpu_write_dba: |
||
119 | pushl %eax |
||
120 | movl 8(%esp),%eax |
||
121 | movl %eax,%cr3 |
||
122 | popl %eax |
||
123 | ret |
||
124 | |||
125 | cpu_read_cr2: |
||
126 | movl %cr2,%eax |
||
127 | ret |
||
128 | |||
129 | enable_l_apic_in_msr: |
||
130 | pusha |
||
131 | |||
132 | movl $0x1b, %ecx |
||
133 | rdmsr |
||
134 | orl $(1<<11),%eax |
||
135 | orl $(0xfee00000),%eax |
||
136 | wrmsr |
||
137 | |||
138 | popa |
||
139 | ret |
||
140 | |||
141 | .macro handler i n |
||
142 | push %ebp |
||
143 | movl %esp,%ebp |
||
144 | pusha |
||
26 | jermar | 145 | |
146 | push %ds |
||
147 | push %es |
||
1 | jermar | 148 | |
149 | # we must fill the data segment registers |
||
150 | movw $16,%ax |
||
151 | movw %ax,%ds |
||
152 | movw %ax,%es |
||
153 | |||
154 | movl $(\i),%edi |
||
155 | pushl %ebp |
||
156 | addl $4,(%esp) |
||
157 | pushl %edi |
||
158 | call trap_dispatcher |
||
159 | addl $8,%esp |
||
160 | |||
26 | jermar | 161 | pop %es |
162 | pop %ds |
||
163 | |||
1 | jermar | 164 | popa |
165 | pop %ebp |
||
166 | |||
167 | iret |
||
168 | |||
169 | .if (\n-\i)-1 |
||
170 | handler "(\i+1)",\n |
||
171 | .endif |
||
172 | .endm |
||
173 | |||
174 | # keep in sync with pm.h !!! |
||
175 | IDT_ITEMS=64 |
||
176 | interrupt_handlers: |
||
177 | h_start: |
||
178 | handler 0 64 |
||
179 | # handler 64 128 |
||
180 | # handler 128 192 |
||
181 | # handler 192 256 |
||
182 | h_end: |
||
183 | |||
184 | |||
185 | inb: |
||
186 | push %edx |
||
187 | xorl %eax,%eax |
||
188 | movl 8(%esp),%edx |
||
189 | inb %dx,%al |
||
190 | pop %edx |
||
191 | ret |
||
192 | |||
193 | inw: |
||
194 | push %edx |
||
195 | xorl %eax,%eax |
||
196 | movl 8(%esp),%edx |
||
197 | inw %dx,%ax |
||
198 | pop %edx |
||
199 | ret |
||
200 | |||
201 | inl: |
||
202 | push %edx |
||
203 | xorl %eax,%eax |
||
204 | movl 8(%esp),%edx |
||
205 | inl %dx,%eax |
||
206 | pop %edx |
||
207 | ret |
||
208 | |||
209 | outb: |
||
210 | push %ebp |
||
211 | movl %esp,%ebp |
||
212 | pusha |
||
213 | |||
214 | movl 8(%ebp),%edx |
||
215 | movl 12(%ebp),%eax |
||
216 | outb %al,%dx |
||
217 | |||
218 | popa |
||
219 | pop %ebp |
||
220 | ret |
||
221 | |||
222 | outw: |
||
223 | push %ebp |
||
224 | movl %esp,%ebp |
||
225 | pusha |
||
226 | |||
227 | movl 8(%ebp),%edx |
||
228 | movl 12(%ebp),%eax |
||
229 | outw %ax,%dx |
||
230 | |||
231 | popa |
||
232 | pop %ebp |
||
233 | ret |
||
234 | |||
235 | outl: |
||
236 | push %ebp |
||
237 | movl %esp,%ebp |
||
238 | pusha |
||
239 | |||
240 | movl 8(%ebp),%edx |
||
241 | movl 12(%ebp),%eax |
||
242 | outl %eax,%dx |
||
243 | |||
244 | popa |
||
245 | pop %ebp |
||
246 | ret |
||
247 | |||
248 | SRC=8 |
||
249 | DST=12 |
||
250 | CNT=16 |
||
251 | memcopy: |
||
252 | push %ebp |
||
253 | movl %esp,%ebp |
||
254 | pusha |
||
255 | |||
256 | cld |
||
257 | movl CNT(%ebp),%ecx |
||
258 | movl DST(%ebp),%edi |
||
259 | movl SRC(%ebp),%esi |
||
260 | |||
261 | rep movsb %ds:(%esi),%es:(%edi) |
||
262 | |||
263 | popa |
||
264 | pop %ebp |
||
265 | ret |
||
266 | |||
267 | DST=8 |
||
268 | CNT=12 |
||
269 | X=16 |
||
270 | memsetw: |
||
271 | push %ebp |
||
272 | movl %esp,%ebp |
||
273 | pusha |
||
274 | |||
275 | cld |
||
276 | movl CNT(%ebp),%ecx |
||
277 | movl DST(%ebp),%edi |
||
278 | movl X(%ebp),%eax |
||
279 | |||
280 | rep stosw %ax,%es:(%edi) |
||
281 | |||
282 | popa |
||
283 | pop %ebp |
||
284 | ret |
||
285 | |||
286 | DST=8 |
||
287 | CNT=12 |
||
288 | X=16 |
||
289 | memsetb: |
||
290 | push %ebp |
||
291 | movl %esp,%ebp |
||
292 | pusha |
||
293 | |||
294 | cld |
||
295 | movl CNT(%ebp),%ecx |
||
296 | movl DST(%ebp),%edi |
||
297 | movl X(%ebp),%eax |
||
298 | |||
299 | rep stosb %al,%es:(%edi) |
||
300 | |||
301 | popa |
||
302 | pop %ebp |
||
303 | ret |
||
304 | |||
305 | SRC=12 |
||
306 | DST=16 |
||
307 | CNT=20 |
||
308 | memcmp: |
||
309 | push %ebp |
||
310 | subl $4,%esp |
||
311 | movl %esp,%ebp |
||
312 | |||
313 | pusha |
||
314 | |||
315 | cld |
||
316 | movl CNT(%ebp),%ecx |
||
317 | movl DST(%ebp),%edi |
||
318 | movl SRC(%ebp),%esi |
||
319 | |||
320 | repe cmpsb %es:(%edi),%ds:(%esi) |
||
321 | movl %ecx,(%ebp) |
||
322 | |||
323 | popa |
||
324 | |||
325 | movl (%ebp),%eax # return value => %eax (zero on success) |
||
326 | addl $4,%esp |
||
327 | pop %ebp |
||
328 | |||
329 | ret |
||
330 | |||
331 | |||
332 | # THIS IS USERSPACE CODE |
||
333 | .global utext |
||
334 | utext: |
||
335 | 0: |
||
26 | jermar | 336 | # movl $0xdeadbeaf, %eax |
1 | jermar | 337 | int $48 |
338 | jmp 0b |
||
339 | # not reached |
||
340 | utext_end: |
||
341 | |||
342 | .data |
||
343 | .global utext_size |
||
344 | utext_size: |
||
345 | .long utext_end - utext |
||
346 | |||
347 | |||
348 | .section K_DATA_START |
||
349 | .global interrupt_handler_size |
||
350 | |||
351 | interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS |