source: mainline/arch/amd64/src/asm_utils.S@ 4bb86b4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4bb86b4 was 7df54df, checked in by Ondrej Palkovsky <ondrap@…>, 20 years ago

Fixed stack settings in boot.S in real mode.
Added ia32 memmap support.
Added cpuid support.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#
2# Copyright (C) 2005 Ondrej Palkovsky
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
30# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
31# and 1 means interrupt with error word
32
33
34#define ERROR_WORD_INTERRUPT_LIST 0x00027D00
35
36#define __ASM__
37#include <arch/pm.h>
38
39.text
40.global interrupt_handlers
41.global panic_printf
42
43panic_printf:
44 movq $halt, (%rsp)
45 jmp printf
46
47.global has_cpuid
48.global rdtsc
49
50
51## Determine CPUID support
52#
53# Return 0 in EAX if CPUID is not support, 1 if supported.
54#
55has_cpuid:
56 pushq %rbx
57
58 pushfq # store flags
59 popq %rax # read flags
60 movq %rax,%rbx # copy flags
61 btcl $21,%ebx # swap the ID bit
62 pushq %rbx
63 popfq # propagate the change into flags
64 pushfq
65 popq %rbx # read flags
66 andl $(1<<21),%eax # interested only in ID bit
67 andl $(1<<21),%ebx
68 xorl %ebx,%eax # 0 if not supported, 1 if supported
69
70 popq %rbx
71 ret
72
73
74rdtsc:
75 xorq %rax,%rax
76 rdtsc
77 ret
78
79
80# Push all general purpose registers on stack except %rbp, %rsp
81.macro push_all_gpr
82 pushq %rax
83 pushq %rbx
84 pushq %rcx
85 pushq %rdx
86 pushq %rsi
87 pushq %rdi
88 pushq %r8
89 pushq %r9
90 pushq %r10
91 pushq %r11
92 pushq %r12
93 pushq %r13
94 pushq %r14
95 pushq %r15
96.endm
97
98.macro pop_all_gpr
99 popq %r15
100 popq %r14
101 popq %r13
102 popq %r12
103 popq %r11
104 popq %r10
105 popq %r9
106 popq %r8
107 popq %rdi
108 popq %rsi
109 popq %rdx
110 popq %rcx
111 popq %rbx
112 popq %rax
113.endm
114
115## Declare interrupt handlers
116#
117# Declare interrupt handlers for n interrupt
118# vectors starting at vector i.
119#
120# The handlers setup data segment registers
121# and call trap_dispatcher().
122#
123.macro handler i n
124 pushq %rbp
125 movq %rsp,%rbp
126
127 push_all_gpr
128
129 # trap_dispatcher(i, stack)
130 movq $(\i),%rdi # %rdi - first parameter
131 movq %rbp, %rsi
132 addq $8, %rsi # %rsi - second parameter - original stack
133 call trap_dispatcher
134
135# Test if this is interrupt with error word or not
136 mov $\i,%cl;
137 movl $1,%eax;
138 test $0xe0,%cl;
139 jnz 0f;
140 and $0x1f,%cl;
141 shl %cl,%eax;
142 and $ERROR_WORD_INTERRUPT_LIST,%eax;
143 jz 0f;
144
145
146# Return with error word
147 pop_all_gpr
148
149 popq %rbp;
150 add $8,%esp; # Skip error word
151 iretq
152
1530:
154# Return with no error word
155 pop_all_gpr
156
157 popq %rbp
158 iretq
159
160 .if (\n-\i)-1
161 handler "(\i+1)",\n
162 .endif
163.endm
164
165interrupt_handlers:
166h_start:
167 handler 0 IDT_ITEMS
168# handler 64 128
169# handler 128 192
170# handler 192 256
171h_end:
172
173
174.data
175.global interrupt_handler_size
176
177interrupt_handler_size: .long (h_end-h_start)/IDT_ITEMS
Note: See TracBrowser for help on using the repository browser.