source: trunk/hal/x86_64/core/hal_cpu.S @ 193

Last change on this file since 193 was 166, checked in by max@…, 7 years ago

identify the cpu features

File size: 2.8 KB
Line 
1/*
2 * hal_cpu.S - Miscellaneous CPU functions
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#define x86_ASM
23#include <hal_boot.h>
24#include <hal_segmentation.h>
25#include <hal_register.h>
26
27ASM_ENTRY(lgdt)
28        lgdt    (%rdi)
29        /* Reload the prefetch queue */
30        jmp     1f
31        nop
321:      /* Reload stale selectors */
33        movl    $GDT_FIXED_SEL(GDT_KDATA_SEL, SEL_KPL),%eax
34        movl    %eax,%ds
35        movl    %eax,%es
36        movl    %eax,%ss
37        ret
38
39ASM_ENTRY(lidt)
40        lidt    (%rdi)
41        ret
42
43ASM_ENTRY(ltr)
44        ltr     %di
45        ret
46
47ASM_ENTRY(invlpg)
48        invlpg  (%rdi)
49        ret
50
51ASM_ENTRY(sti)
52        sti
53        ret
54
55ASM_ENTRY(cli)
56        cli
57        ret
58
59ASM_ENTRY(rdtsc)
60        xorq    %rax,%rax
61        rdtsc
62        shlq    $32,%rdx
63        orq     %rdx,%rax
64        ret
65
66ASM_ENTRY(in8)
67        movq    %rdi,%rdx
68        xorq    %rax,%rax
69        inb     %dx,%al
70        ret
71
72ASM_ENTRY(out8)
73        movq    %rdi,%rdx
74        movq    %rsi,%rax
75        outb    %al,%dx
76        ret
77
78ASM_ENTRY(rdmsr)
79        movq    %rdi,%rcx
80        xorq    %rax,%rax
81        rdmsr
82        shlq    $32,%rdx
83        orq     %rdx,%rax
84        ret
85
86ASM_ENTRY(wrmsr)
87        movq    %rdi,%rcx
88        movq    %rsi,%rax
89        movq    %rsi,%rdx
90        shrq    $32,%rdx
91        wrmsr
92        ret
93
94ASM_ENTRY(mfence)
95        mfence
96        ret
97
98ASM_ENTRY(rcr2)
99        movq    %cr2,%rax
100        ret
101
102ASM_ENTRY(rcr4)
103        movq    %cr4,%rax
104        ret
105
106ASM_ENTRY(lcr4)
107        movq    %rdi,%cr4
108        ret
109
110ASM_ENTRY(cpuid)
111        movq    %rbx,%r8
112        movq    %rdi,%rax
113        movq    %rsi,%rcx
114        movq    %rdx,%rsi
115        cpuid
116        movl    %eax,0(%rsi)
117        movl    %ebx,4(%rsi)
118        movl    %ecx,8(%rsi)
119        movl    %edx,12(%rsi)
120        movq    %r8,%rbx
121        ret
122
123/*
124 * To flush all TLB entries, we must re-set the CR4_PGE flag in %cr4.
125 */
126ASM_ENTRY(tlbflushg)
127        movq    %cr4,%rax
128        movq    %rax,%rdx
129        andq    $~CR4_PGE,%rdx
130        movq    %rdx,%cr4
131        movq    %rax,%cr4
132        ret
133
134ASM_ENTRY(tlbflush)
135        movq    %cr3,%rax
136        movq    %rax,%cr3
137        ret
138
139ASM_ENTRY(x86_stop) /* debug only */
140        int     $0x0b
141        ret
142
143/* -------------------------------------------------------------------------- */
144
145ASM_ENTRY(atomic_cas_32)
146        movl    %esi,%eax
147        lock
148        cmpxchgl %edx,(%rdi)
149        /* %eax now contains the old value */
150        ret
151
152ASM_ENTRY(atomic_add_32)
153        movl    %esi,%eax
154        lock
155        xaddl   %eax,(%rdi)
156        /* %eax now contains the old value */
157        ret
158
159ASM_ENTRY(atomic_and_32)
160        movl    (%rdi),%eax
1611:
162        movl    %eax,%ecx
163        andl    %esi,%ecx
164        lock
165        cmpxchgl %ecx,(%rdi)
166        jnz     1b
167        /* %eax now contains the old value */
168        ret
169
170ASM_ENTRY(atomic_or_32)
171        movl    (%rdi),%eax
1721:
173        movl    %eax,%ecx
174        orl     %esi,%ecx
175        lock
176        cmpxchgl %ecx,(%rdi)
177        jnz     1b
178        /* %eax now contains the old value */
179        ret
180
Note: See TracBrowser for help on using the repository browser.