Rev 28 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 28 | Rev 65 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | # |
27 | # |
28 | 28 | ||
29 | # very low and hardware-level functions |
29 | ## very low and hardware-level functions |
30 | 30 | ||
31 | .text |
31 | .text |
32 | 32 | ||
33 | .global cpu_priority_high |
33 | .global cpu_priority_high |
34 | .global cpu_priority_low |
34 | .global cpu_priority_low |
Line 51... | Line 51... | ||
51 | .global memcopy |
51 | .global memcopy |
52 | .global memsetb |
52 | .global memsetb |
53 | .global memsetw |
53 | .global memsetw |
54 | .global memcmp |
54 | .global memcmp |
55 | 55 | ||
- | 56 | ||
- | 57 | ## Set priority level high |
|
- | 58 | # |
|
- | 59 | # Disable interrupts and return previous |
|
- | 60 | # EFLAGS in EAX. |
|
56 | # |
61 | # |
57 | # set priority level high |
- | |
58 | cpu_priority_high: |
62 | cpu_priority_high: |
59 | pushf |
63 | pushf |
60 | pop %eax |
64 | pop %eax |
61 | cli |
65 | cli |
62 | ret |
66 | ret |
- | 67 | ||
63 | 68 | ||
- | 69 | ## Set priority level low |
|
64 | # |
70 | # |
65 | # set priority level low |
71 | # Enable interrupts and return previous |
- | 72 | # EFLAGS in EAX. |
|
- | 73 | # |
|
66 | cpu_priority_low: |
74 | cpu_priority_low: |
67 | pushf |
75 | pushf |
68 | pop %eax |
76 | pop %eax |
69 | sti |
77 | sti |
70 | ret |
78 | ret |
71 | 79 | ||
- | 80 | ||
- | 81 | ## Restore priority level |
|
- | 82 | # |
|
- | 83 | # Restore EFLAGS. |
|
72 | # |
84 | # |
73 | # restore priority level |
- | |
74 | cpu_priority_restore: |
85 | cpu_priority_restore: |
75 | push 4(%esp) |
86 | push 4(%esp) |
76 | popf |
87 | popf |
77 | ret |
88 | ret |
78 | 89 | ||
79 | # return raw priority level |
90 | ## Return raw priority level |
- | 91 | # |
|
- | 92 | # Return EFLAFS in EAX. |
|
- | 93 | # |
|
80 | cpu_priority_read: |
94 | cpu_priority_read: |
81 | pushf |
95 | pushf |
82 | pop %eax |
96 | pop %eax |
83 | ret |
97 | ret |
84 | 98 | ||
- | 99 | ||
- | 100 | ## Halt the CPU |
|
- | 101 | # |
|
- | 102 | # Halt the CPU using HLT. |
|
- | 103 | # |
|
85 | cpu_halt: |
104 | cpu_halt: |
86 | cpu_sleep: |
105 | cpu_sleep: |
87 | hlt |
106 | hlt |
88 | ret |
107 | ret |
89 | 108 | ||
- | 109 | ||
- | 110 | ## Turn paging on |
|
- | 111 | # |
|
- | 112 | # Enable paging and write-back caching in CR0. |
|
- | 113 | # |
|
90 | paging_on: |
114 | paging_on: |
91 | pushl %eax |
115 | pushl %eax |
92 | movl %cr0,%eax |
116 | movl %cr0,%eax |
93 | orl $(1<<31),%eax # paging on |
117 | orl $(1<<31),%eax # paging on |
94 | andl $~((1<<30)|(1<<29)),%eax # clear Cache Disable and not Write Though |
118 | andl $~((1<<30)|(1<<29)),%eax # clear Cache Disable and not Write Though |
Line 96... | Line 120... | ||
96 | jmp 0f |
120 | jmp 0f |
97 | 0: |
121 | 0: |
98 | popl %eax |
122 | popl %eax |
99 | ret |
123 | ret |
100 | 124 | ||
- | 125 | ||
- | 126 | ## Read CR3 |
|
- | 127 | # |
|
- | 128 | # Store CR3 in EAX. |
|
- | 129 | # |
|
101 | cpu_read_dba: |
130 | cpu_read_dba: |
102 | movl %cr3,%eax |
131 | movl %cr3,%eax |
103 | ret |
132 | ret |
104 | 133 | ||
- | 134 | ||
- | 135 | ## Write CR3 |
|
- | 136 | # |
|
- | 137 | # Set CR3. |
|
- | 138 | # |
|
105 | cpu_write_dba: |
139 | cpu_write_dba: |
106 | pushl %eax |
140 | pushl %eax |
107 | movl 8(%esp),%eax |
141 | movl 8(%esp),%eax |
108 | movl %eax,%cr3 |
142 | movl %eax,%cr3 |
109 | popl %eax |
143 | popl %eax |
110 | ret |
144 | ret |
111 | 145 | ||
- | 146 | ||
- | 147 | ## Read CR2 |
|
- | 148 | # |
|
- | 149 | # Store CR2 in EAX. |
|
- | 150 | # |
|
112 | cpu_read_cr2: |
151 | cpu_read_cr2: |
113 | movl %cr2,%eax |
152 | movl %cr2,%eax |
114 | ret |
153 | ret |
115 | 154 | ||
- | 155 | ||
- | 156 | ## Enable local APIC |
|
- | 157 | # |
|
- | 158 | # Enable local APIC in MSR. |
|
- | 159 | # |
|
116 | enable_l_apic_in_msr: |
160 | enable_l_apic_in_msr: |
117 | pusha |
161 | pusha |
118 | 162 | ||
119 | movl $0x1b, %ecx |
163 | movl $0x1b, %ecx |
120 | rdmsr |
164 | rdmsr |
Line 123... | Line 167... | ||
123 | wrmsr |
167 | wrmsr |
124 | 168 | ||
125 | popa |
169 | popa |
126 | ret |
170 | ret |
127 | 171 | ||
- | 172 | ||
- | 173 | ## Declare interrupt handlers |
|
- | 174 | # |
|
- | 175 | # Declare interrupt handlers for n interrupt |
|
- | 176 | # vectors starting at vector i. |
|
- | 177 | # |
|
- | 178 | # The handlers setup data segment registers |
|
- | 179 | # and call trap_dispatcher(). |
|
- | 180 | # |
|
128 | .macro handler i n |
181 | .macro handler i n |
129 | push %ebp |
182 | push %ebp |
130 | movl %esp,%ebp |
183 | movl %esp,%ebp |
131 | pusha |
184 | pusha |
132 | 185 | ||
Line 167... | Line 220... | ||
167 | # handler 128 192 |
220 | # handler 128 192 |
168 | # handler 192 256 |
221 | # handler 192 256 |
169 | h_end: |
222 | h_end: |
170 | 223 | ||
171 | 224 | ||
- | 225 | ## I/O input (byte) |
|
- | 226 | # |
|
- | 227 | # Get a byte from I/O port and store it AL. |
|
- | 228 | # |
|
172 | inb: |
229 | inb: |
173 | push %edx |
230 | push %edx |
174 | xorl %eax,%eax |
231 | xorl %eax,%eax |
175 | movl 8(%esp),%edx |
232 | movl 8(%esp),%edx |
176 | inb %dx,%al |
233 | inb %dx,%al |
177 | pop %edx |
234 | pop %edx |
178 | ret |
235 | ret |
179 | 236 | ||
- | 237 | ||
- | 238 | ## I/O input (word) |
|
- | 239 | # |
|
- | 240 | # Get a word from I/O port and store it AX. |
|
- | 241 | # |
|
180 | inw: |
242 | inw: |
181 | push %edx |
243 | push %edx |
182 | xorl %eax,%eax |
244 | xorl %eax,%eax |
183 | movl 8(%esp),%edx |
245 | movl 8(%esp),%edx |
184 | inw %dx,%ax |
246 | inw %dx,%ax |
185 | pop %edx |
247 | pop %edx |
186 | ret |
248 | ret |
187 | 249 | ||
- | 250 | ||
- | 251 | ## I/O input (dword) |
|
- | 252 | # |
|
- | 253 | # Get a dword from I/O port and store it EAX. |
|
- | 254 | # |
|
188 | inl: |
255 | inl: |
189 | push %edx |
256 | push %edx |
190 | xorl %eax,%eax |
257 | xorl %eax,%eax |
191 | movl 8(%esp),%edx |
258 | movl 8(%esp),%edx |
192 | inl %dx,%eax |
259 | inl %dx,%eax |
193 | pop %edx |
260 | pop %edx |
194 | ret |
261 | ret |
195 | 262 | ||
- | 263 | ||
- | 264 | ## I/O output (byte) |
|
- | 265 | # |
|
- | 266 | # Send a byte to I/O port. |
|
- | 267 | # |
|
196 | outb: |
268 | outb: |
197 | push %ebp |
269 | push %ebp |
198 | movl %esp,%ebp |
270 | movl %esp,%ebp |
199 | pusha |
271 | pusha |
200 | 272 | ||
Line 204... | Line 276... | ||
204 | 276 | ||
205 | popa |
277 | popa |
206 | pop %ebp |
278 | pop %ebp |
207 | ret |
279 | ret |
208 | 280 | ||
- | 281 | ||
- | 282 | ## I/O output (word) |
|
- | 283 | # |
|
- | 284 | # Send a word to I/O port. |
|
- | 285 | # |
|
209 | outw: |
286 | outw: |
210 | push %ebp |
287 | push %ebp |
211 | movl %esp,%ebp |
288 | movl %esp,%ebp |
212 | pusha |
289 | pusha |
213 | 290 | ||
Line 217... | Line 294... | ||
217 | 294 | ||
218 | popa |
295 | popa |
219 | pop %ebp |
296 | pop %ebp |
220 | ret |
297 | ret |
221 | 298 | ||
- | 299 | ||
- | 300 | ## I/O output (dword) |
|
- | 301 | # |
|
- | 302 | # Send a dword to I/O port. |
|
- | 303 | # |
|
222 | outl: |
304 | outl: |
223 | push %ebp |
305 | push %ebp |
224 | movl %esp,%ebp |
306 | movl %esp,%ebp |
225 | pusha |
307 | pusha |
226 | 308 | ||
Line 230... | Line 312... | ||
230 | 312 | ||
231 | popa |
313 | popa |
232 | pop %ebp |
314 | pop %ebp |
233 | ret |
315 | ret |
234 | 316 | ||
- | 317 | ||
- | 318 | ## Copy memory |
|
- | 319 | # |
|
- | 320 | # Copy a given number of bytes (3rd argument) |
|
- | 321 | # from the memory location defined by 1st argument |
|
- | 322 | # to the memory location defined by 2nd argument. |
|
- | 323 | # The memory areas cannot overlap. |
|
- | 324 | # |
|
235 | SRC=8 |
325 | SRC=8 |
236 | DST=12 |
326 | DST=12 |
237 | CNT=16 |
327 | CNT=16 |
238 | memcopy: |
328 | memcopy: |
239 | push %ebp |
329 | push %ebp |
Line 249... | Line 339... | ||
249 | 339 | ||
250 | popa |
340 | popa |
251 | pop %ebp |
341 | pop %ebp |
252 | ret |
342 | ret |
253 | 343 | ||
- | 344 | ||
- | 345 | ## Fill memory with bytes |
|
- | 346 | # |
|
- | 347 | # Fill a given number of bytes (2nd argument) |
|
- | 348 | # at memory defined by 1st argument with the |
|
- | 349 | # byte value defined by 3rd argument. |
|
- | 350 | # |
|
254 | DST=8 |
351 | DST=8 |
255 | CNT=12 |
352 | CNT=12 |
256 | X=16 |
353 | X=16 |
257 | memsetw: |
354 | memsetb: |
258 | push %ebp |
355 | push %ebp |
259 | movl %esp,%ebp |
356 | movl %esp,%ebp |
260 | pusha |
357 | pusha |
261 | 358 | ||
262 | cld |
359 | cld |
263 | movl CNT(%ebp),%ecx |
360 | movl CNT(%ebp),%ecx |
264 | movl DST(%ebp),%edi |
361 | movl DST(%ebp),%edi |
265 | movl X(%ebp),%eax |
362 | movl X(%ebp),%eax |
266 | 363 | ||
267 | rep stosw %ax,%es:(%edi) |
364 | rep stosb %al,%es:(%edi) |
268 | 365 | ||
269 | popa |
366 | popa |
270 | pop %ebp |
367 | pop %ebp |
271 | ret |
368 | ret |
272 | 369 | ||
- | 370 | ||
- | 371 | ## Fill memory with words |
|
- | 372 | # |
|
- | 373 | # Fill a given number of words (2nd argument) |
|
- | 374 | # at memory defined by 1st argument with the |
|
- | 375 | # word value defined by 3rd argument. |
|
- | 376 | # |
|
273 | DST=8 |
377 | DST=8 |
274 | CNT=12 |
378 | CNT=12 |
275 | X=16 |
379 | X=16 |
276 | memsetb: |
380 | memsetw: |
277 | push %ebp |
381 | push %ebp |
278 | movl %esp,%ebp |
382 | movl %esp,%ebp |
279 | pusha |
383 | pusha |
280 | 384 | ||
281 | cld |
385 | cld |
282 | movl CNT(%ebp),%ecx |
386 | movl CNT(%ebp),%ecx |
283 | movl DST(%ebp),%edi |
387 | movl DST(%ebp),%edi |
284 | movl X(%ebp),%eax |
388 | movl X(%ebp),%eax |
285 | 389 | ||
286 | rep stosb %al,%es:(%edi) |
390 | rep stosw %ax,%es:(%edi) |
287 | 391 | ||
288 | popa |
392 | popa |
289 | pop %ebp |
393 | pop %ebp |
290 | ret |
394 | ret |
291 | 395 | ||
- | 396 | ||
- | 397 | ## Compare memory regions for equality |
|
- | 398 | # |
|
- | 399 | # Compare a given number of bytes (3rd argument) |
|
- | 400 | # at memory locations defined by 1st and 2nd argument |
|
- | 401 | # for equality. If the bytes are equal, EAX contains |
|
- | 402 | # 0. |
|
- | 403 | # |
|
292 | SRC=12 |
404 | SRC=12 |
293 | DST=16 |
405 | DST=16 |
294 | CNT=20 |
406 | CNT=20 |
295 | memcmp: |
407 | memcmp: |
296 | push %ebp |
408 | push %ebp |