Rev 1 | 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 |
||
55 | |||
56 | # |
||
57 | # set priority level high |
||
58 | cpu_priority_high: |
||
59 | pushf |
||
60 | pop %eax |
||
61 | cli |
||
62 | ret |
||
63 | |||
64 | # |
||
65 | # set priority level low |
||
66 | cpu_priority_low: |
||
67 | pushf |
||
68 | pop %eax |
||
69 | sti |
||
70 | ret |
||
71 | |||
72 | # |
||
73 | # restore priority level |
||
74 | cpu_priority_restore: |
||
75 | push 4(%esp) |
||
76 | popf |
||
77 | ret |
||
78 | |||
79 | # return raw priority level |
||
80 | cpu_priority_read: |
||
81 | pushf |
||
82 | pop %eax |
||
83 | ret |
||
84 | |||
85 | cpu_halt: |
||
86 | cpu_sleep: |
||
87 | hlt |
||
88 | ret |
||
89 | |||
90 | paging_on: |
||
91 | pushl %eax |
||
92 | movl %cr0,%eax |
||
93 | orl $(1<<31),%eax # paging on |
||
94 | andl $~((1<<30)|(1<<29)),%eax # clear Cache Disable and not Write Though |
||
95 | movl %eax,%cr0 |
||
96 | jmp 0f |
||
97 | 0: |
||
98 | popl %eax |
||
99 | ret |
||
100 | |||
101 | cpu_read_dba: |
||
102 | movl %cr3,%eax |
||
103 | ret |
||
104 | |||
105 | cpu_write_dba: |
||
106 | pushl %eax |
||
107 | movl 8(%esp),%eax |
||
108 | movl %eax,%cr3 |
||
109 | popl %eax |
||
110 | ret |
||
111 | |||
112 | cpu_read_cr2: |
||
113 | movl %cr2,%eax |
||
114 | ret |
||
115 | |||
116 | enable_l_apic_in_msr: |
||
117 | pusha |
||
118 | |||
119 | movl $0x1b, %ecx |
||
120 | rdmsr |
||
121 | orl $(1<<11),%eax |
||
122 | orl $(0xfee00000),%eax |
||
123 | wrmsr |
||
124 | |||
125 | popa |
||
126 | ret |
||
127 | |||
128 | .macro handler i n |
||
129 | push %ebp |
||
130 | movl %esp,%ebp |
||
131 | pusha |
||
26 | jermar | 132 | |
133 | push %ds |
||
134 | push %es |
||
1 | jermar | 135 | |
136 | # we must fill the data segment registers |
||
137 | movw $16,%ax |
||
138 | movw %ax,%ds |
||
139 | movw %ax,%es |
||
140 | |||
141 | movl $(\i),%edi |
||
142 | pushl %ebp |
||
143 | addl $4,(%esp) |
||
144 | pushl %edi |
||
145 | call trap_dispatcher |
||
146 | addl $8,%esp |
||
147 | |||
26 | jermar | 148 | pop %es |
149 | pop %ds |
||
150 | |||
1 | jermar | 151 | popa |
152 | pop %ebp |
||
153 | |||
154 | iret |
||
155 | |||
156 | .if (\n-\i)-1 |
||
157 | handler "(\i+1)",\n |
||
158 | .endif |
||
159 | .endm |
||
160 | |||
161 | # keep in sync with pm.h !!! |
||
162 | IDT_ITEMS=64 |
||
163 | interrupt_handlers: |
||
164 | h_start: |
||
165 | handler 0 64 |
||
166 | # handler 64 128 |
||
167 | # handler 128 192 |
||
168 | # handler 192 256 |
||
169 | h_end: |
||
170 | |||
171 | |||
172 | inb: |
||
173 | push %edx |
||
174 | xorl %eax,%eax |
||
175 | movl 8(%esp),%edx |
||
176 | inb %dx,%al |
||
177 | pop %edx |
||
178 | ret |
||
179 | |||
180 | inw: |
||
181 | push %edx |
||
182 | xorl %eax,%eax |
||
183 | movl 8(%esp),%edx |
||
184 | inw %dx,%ax |
||
185 | pop %edx |
||
186 | ret |
||
187 | |||
188 | inl: |
||
189 | push %edx |
||
190 | xorl %eax,%eax |
||
191 | movl 8(%esp),%edx |
||
192 | inl %dx,%eax |
||
193 | pop %edx |
||
194 | ret |
||
195 | |||
196 | outb: |
||
197 | push %ebp |
||
198 | movl %esp,%ebp |
||
199 | pusha |
||
200 | |||
201 | movl 8(%ebp),%edx |
||
202 | movl 12(%ebp),%eax |
||
203 | outb %al,%dx |
||
204 | |||
205 | popa |
||
206 | pop %ebp |
||
207 | ret |
||
208 | |||
209 | outw: |
||
210 | push %ebp |
||
211 | movl %esp,%ebp |
||
212 | pusha |
||
213 | |||
214 | movl 8(%ebp),%edx |
||
215 | movl 12(%ebp),%eax |
||
216 | outw %ax,%dx |
||
217 | |||
218 | popa |
||
219 | pop %ebp |
||
220 | ret |
||
221 | |||
222 | outl: |
||
223 | push %ebp |
||
224 | movl %esp,%ebp |
||
225 | pusha |
||
226 | |||
227 | movl 8(%ebp),%edx |
||
228 | movl 12(%ebp),%eax |
||
229 | outl %eax,%dx |
||
230 | |||
231 | popa |
||
232 | pop %ebp |
||
233 | ret |
||
234 | |||
235 | SRC=8 |
||
236 | DST=12 |
||
237 | CNT=16 |
||
238 | memcopy: |
||
239 | push %ebp |
||
240 | movl %esp,%ebp |
||
241 | pusha |
||
242 | |||
243 | cld |
||
244 | movl CNT(%ebp),%ecx |
||
245 | movl DST(%ebp),%edi |
||
246 | movl SRC(%ebp),%esi |
||
247 | |||
248 | rep movsb %ds:(%esi),%es:(%edi) |
||
249 | |||
250 | popa |
||
251 | pop %ebp |
||
252 | ret |
||
253 | |||
254 | DST=8 |
||
255 | CNT=12 |
||
256 | X=16 |
||
257 | memsetw: |
||
258 | push %ebp |
||
259 | movl %esp,%ebp |
||
260 | pusha |
||
261 | |||
262 | cld |
||
263 | movl CNT(%ebp),%ecx |
||
264 | movl DST(%ebp),%edi |
||
265 | movl X(%ebp),%eax |
||
266 | |||
267 | rep stosw %ax,%es:(%edi) |
||
268 | |||
269 | popa |
||
270 | pop %ebp |
||
271 | ret |
||
272 | |||
273 | DST=8 |
||
274 | CNT=12 |
||
275 | X=16 |
||
276 | memsetb: |
||
277 | push %ebp |
||
278 | movl %esp,%ebp |
||
279 | pusha |
||
280 | |||
281 | cld |
||
282 | movl CNT(%ebp),%ecx |
||
283 | movl DST(%ebp),%edi |
||
284 | movl X(%ebp),%eax |
||
285 | |||
286 | rep stosb %al,%es:(%edi) |
||
287 | |||
288 | popa |
||
289 | pop %ebp |
||
290 | ret |
||
291 | |||
292 | SRC=12 |
||
293 | DST=16 |
||
294 | CNT=20 |
||
295 | memcmp: |
||
296 | push %ebp |
||
297 | subl $4,%esp |
||
298 | movl %esp,%ebp |
||
299 | |||
300 | pusha |
||
301 | |||
302 | cld |
||
303 | movl CNT(%ebp),%ecx |
||
304 | movl DST(%ebp),%edi |
||
305 | movl SRC(%ebp),%esi |
||
306 | |||
307 | repe cmpsb %es:(%edi),%ds:(%esi) |
||
308 | movl %ecx,(%ebp) |
||
309 | |||
310 | popa |
||
311 | |||
312 | movl (%ebp),%eax # return value => %eax (zero on success) |
||
313 | addl $4,%esp |
||
314 | pop %ebp |
||
315 | |||
316 | ret |
||
317 | |||
318 | |||
319 | # THIS IS USERSPACE CODE |
||
320 | .global utext |
||
321 | utext: |
||
322 | 0: |
||
26 | jermar | 323 | # movl $0xdeadbeaf, %eax |
1 | jermar | 324 | int $48 |
325 | jmp 0b |
||
326 | # not reached |
||
327 | utext_end: |
||
328 | |||
329 | .data |
||
330 | .global utext_size |
||
331 | utext_size: |
||
332 | .long utext_end - utext |
||
333 | |||
334 | |||
335 | .section K_DATA_START |
||
336 | .global interrupt_handler_size |
||
337 | |||
338 | interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS |