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

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

add IOC (ATA)

File size: 3.0 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(in16)
73        movq    %rdi,%rdx
74        xorq    %rax,%rax
75        inw     %dx,%ax
76        ret
77
78ASM_ENTRY(out8)
79        movq    %rdi,%rdx
80        movq    %rsi,%rax
81        outb    %al,%dx
82        ret
83
84ASM_ENTRY(out16)
85        movq    %rdi,%rdx
86        movq    %rsi,%rax
87        outw    %ax,%dx
88        ret
89
90ASM_ENTRY(rdmsr)
91        movq    %rdi,%rcx
92        xorq    %rax,%rax
93        rdmsr
94        shlq    $32,%rdx
95        orq     %rdx,%rax
96        ret
97
98ASM_ENTRY(wrmsr)
99        movq    %rdi,%rcx
100        movq    %rsi,%rax
101        movq    %rsi,%rdx
102        shrq    $32,%rdx
103        wrmsr
104        ret
105
106ASM_ENTRY(mfence)
107        mfence
108        ret
109
110ASM_ENTRY(rcr2)
111        movq    %cr2,%rax
112        ret
113
114ASM_ENTRY(rcr4)
115        movq    %cr4,%rax
116        ret
117
118ASM_ENTRY(lcr4)
119        movq    %rdi,%cr4
120        ret
121
122ASM_ENTRY(cpuid)
123        movq    %rbx,%r8
124        movq    %rdi,%rax
125        movq    %rsi,%rcx
126        movq    %rdx,%rsi
127        cpuid
128        movl    %eax,0(%rsi)
129        movl    %ebx,4(%rsi)
130        movl    %ecx,8(%rsi)
131        movl    %edx,12(%rsi)
132        movq    %r8,%rbx
133        ret
134
135/*
136 * To flush all TLB entries, we must re-set the CR4_PGE flag in %cr4.
137 */
138ASM_ENTRY(tlbflushg)
139        movq    %cr4,%rax
140        movq    %rax,%rdx
141        andq    $~CR4_PGE,%rdx
142        movq    %rdx,%cr4
143        movq    %rax,%cr4
144        ret
145
146ASM_ENTRY(tlbflush)
147        movq    %cr3,%rax
148        movq    %rax,%cr3
149        ret
150
151ASM_ENTRY(x86_stop) /* debug only */
152        int     $0x0b
153        ret
154
155/* -------------------------------------------------------------------------- */
156
157ASM_ENTRY(atomic_cas_32)
158        movl    %esi,%eax
159        lock
160        cmpxchgl %edx,(%rdi)
161        /* %eax now contains the old value */
162        ret
163
164ASM_ENTRY(atomic_add_32)
165        movl    %esi,%eax
166        lock
167        xaddl   %eax,(%rdi)
168        /* %eax now contains the old value */
169        ret
170
171ASM_ENTRY(atomic_and_32)
172        movl    (%rdi),%eax
1731:
174        movl    %eax,%ecx
175        andl    %esi,%ecx
176        lock
177        cmpxchgl %ecx,(%rdi)
178        jnz     1b
179        /* %eax now contains the old value */
180        ret
181
182ASM_ENTRY(atomic_or_32)
183        movl    (%rdi),%eax
1841:
185        movl    %eax,%ecx
186        orl     %esi,%ecx
187        lock
188        cmpxchgl %ecx,(%rdi)
189        jnz     1b
190        /* %eax now contains the old value */
191        ret
192
Note: See TracBrowser for help on using the repository browser.