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 | |
---|
26 | ASM_ENTRY(lgdt) |
---|
27 | lgdt (%rdi) |
---|
28 | /* Reload the prefetch queue */ |
---|
29 | jmp 1f |
---|
30 | nop |
---|
31 | 1: /* Reload stale selectors */ |
---|
32 | movl $GDT_FIXED_SEL(GDT_KDATA_SEL, SEL_KPL),%eax |
---|
33 | movl %eax,%ds |
---|
34 | movl %eax,%es |
---|
35 | movl %eax,%ss |
---|
36 | ret |
---|
37 | |
---|
38 | ASM_ENTRY(lidt) |
---|
39 | lidt (%rdi) |
---|
40 | ret |
---|
41 | |
---|
42 | ASM_ENTRY(ltr) |
---|
43 | ltr %di |
---|
44 | ret |
---|
45 | |
---|
46 | ASM_ENTRY(invlpg) |
---|
47 | invlpg (%rdi) |
---|
48 | ret |
---|
49 | |
---|
50 | ASM_ENTRY(sti) |
---|
51 | sti |
---|
52 | ret |
---|
53 | |
---|
54 | ASM_ENTRY(cli) |
---|
55 | cli |
---|
56 | ret |
---|
57 | |
---|
58 | ASM_ENTRY(rdtsc) |
---|
59 | xorq %rax,%rax |
---|
60 | rdtsc |
---|
61 | shlq $32,%rdx |
---|
62 | orq %rdx,%rax |
---|
63 | ret |
---|
64 | |
---|
65 | ASM_ENTRY(in8) |
---|
66 | movq %rdi,%rdx |
---|
67 | xorq %rax,%rax |
---|
68 | inb %dx,%al |
---|
69 | ret |
---|
70 | |
---|
71 | ASM_ENTRY(out8) |
---|
72 | movq %rdi,%rdx |
---|
73 | movq %rsi,%rax |
---|
74 | outb %al,%dx |
---|
75 | ret |
---|
76 | |
---|
77 | ASM_ENTRY(rdmsr) |
---|
78 | movq %rdi,%rcx |
---|
79 | xorq %rax,%rax |
---|
80 | rdmsr |
---|
81 | shlq $32,%rdx |
---|
82 | orq %rdx,%rax |
---|
83 | ret |
---|
84 | |
---|
85 | ASM_ENTRY(wrmsr) |
---|
86 | movq %rdi,%rcx |
---|
87 | movq %rsi,%rax |
---|
88 | movq %rsi,%rdx |
---|
89 | shrq $32,%rdx |
---|
90 | wrmsr |
---|
91 | ret |
---|
92 | |
---|
93 | ASM_ENTRY(rcr2) |
---|
94 | movq %cr2,%rax |
---|
95 | ret |
---|
96 | |
---|
97 | ASM_ENTRY(x86_stop) /* debug only */ |
---|
98 | int $0x0b |
---|
99 | ret |
---|
100 | |
---|
101 | /* -------------------------------------------------------------------------- */ |
---|
102 | |
---|
103 | ASM_ENTRY(atomic_cas_32) |
---|
104 | movl %esi,%eax |
---|
105 | lock |
---|
106 | cmpxchgl %edx,(%rdi) |
---|
107 | /* %eax now contains the old value */ |
---|
108 | ret |
---|
109 | |
---|
110 | ASM_ENTRY(atomic_add_32) |
---|
111 | movl %esi,%eax |
---|
112 | lock |
---|
113 | xaddl %eax,(%rdi) |
---|
114 | /* %eax now contains the old value */ |
---|
115 | ret |
---|
116 | |
---|
117 | ASM_ENTRY(atomic_and_32) |
---|
118 | movl (%rdi),%eax |
---|
119 | 1: |
---|
120 | movl %eax,%ecx |
---|
121 | andl %esi,%ecx |
---|
122 | lock |
---|
123 | cmpxchgl %ecx,(%rdi) |
---|
124 | jnz 1b |
---|
125 | /* %eax now contains the old value */ |
---|
126 | ret |
---|
127 | |
---|
128 | ASM_ENTRY(atomic_or_32) |
---|
129 | movl (%rdi),%eax |
---|
130 | 1: |
---|
131 | movl %eax,%ecx |
---|
132 | orl %esi,%ecx |
---|
133 | lock |
---|
134 | cmpxchgl %ecx,(%rdi) |
---|
135 | jnz 1b |
---|
136 | /* %eax now contains the old value */ |
---|
137 | ret |
---|
138 | |
---|