source: trunk/hal/x86_64/core/hal_kentry.h @ 244

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

style

File size: 4.2 KB
Line 
1/*
2 * hal_kentry.h - General values used in the different kernel entries
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 T_PRIVINFLT      0      /* privileged instruction */
23#define T_BPTFLT         1      /* breakpoint trap */
24#define T_ARITHTRAP      2      /* arithmetic trap */
25#define T_ASTFLT         3      /* asynchronous system trap */
26#define T_PROTFLT        4      /* protection fault */
27#define T_TRCTRAP        5      /* trace trap */
28#define T_PAGEFLT        6      /* page fault */
29#define T_ALIGNFLT       7      /* alignment fault */
30#define T_DIVIDE         8      /* integer divide fault */
31#define T_NMI            9      /* non-maskable interrupt */
32#define T_OFLOW         10      /* overflow trap */
33#define T_BOUND         11      /* bounds check fault */
34#define T_DNA           12      /* device not available fault */
35#define T_DOUBLEFLT     13      /* double fault */
36#define T_FPOPFLT       14      /* fp coprocessor operand fetch fault */
37#define T_TSSFLT        15      /* invalid tss fault */
38#define T_SEGNPFLT      16      /* segment not present fault */
39#define T_STKFLT        17      /* stack fault */
40#define T_MCA           18      /* machine check */
41#define T_XMM           19      /* SSE FP exception */
42#define T_RESERVED      20      /* reserved fault base */
43
44/* Trap's coming from user mode */
45#define T_USER  0x100
46
47#define CPUVAR(off)     %gs:CPU_INFO_ ## off
48
49#define TF_REGSIZE      (19 * 8)
50
51#define PSL_I           0x00000200
52#define PSL_MBO         0x00000002
53#define PSL_USERSET     (PSL_MBO | PSL_I)
54
55#define INTR_SAVE_REGS  \
56        subq    $TF_REGSIZE,%rsp        ; \
57        movq    %rax,TF_RAX(%rsp)       ; \
58        movq    %rbx,TF_RBX(%rsp)       ; \
59        movq    %rcx,TF_RCX(%rsp)       ; \
60        movq    %rdx,TF_RDX(%rsp)       ; \
61        movq    %rbp,TF_RBP(%rsp)       ; \
62        movq    %rdi,TF_RDI(%rsp)       ; \
63        movq    %rsi,TF_RSI(%rsp)       ; \
64        movq    %r8,TF_R8(%rsp)         ; \
65        movq    %r9,TF_R9(%rsp)         ; \
66        movq    %r10,TF_R10(%rsp)       ; \
67        movq    %r11,TF_R11(%rsp)       ; \
68        movq    %r12,TF_R12(%rsp)       ; \
69        movq    %r13,TF_R13(%rsp)       ; \
70        movq    %r14,TF_R14(%rsp)       ; \
71        movq    %r15,TF_R15(%rsp)       ; \
72        /* movw %gs,TF_GS(%rsp) */      ; \
73        movw    %fs,TF_FS(%rsp)         ; \
74        movw    %es,TF_ES(%rsp)         ; \
75        movw    %ds,TF_DS(%rsp)         ; \
76        cld
77
78#define INTR_RESTORE_REGS       \
79        movq    TF_RAX(%rsp),%rax       ; \
80        movq    TF_RBX(%rsp),%rbx       ; \
81        movq    TF_RCX(%rsp),%rcx       ; \
82        movq    TF_RDX(%rsp),%rdx       ; \
83        movq    TF_RBP(%rsp),%rbp       ; \
84        movq    TF_RDI(%rsp),%rdi       ; \
85        movq    TF_RSI(%rsp),%rsi       ; \
86        movq    TF_R8(%rsp),%r8         ; \
87        movq    TF_R9(%rsp),%r9         ; \
88        movq    TF_R10(%rsp),%r10       ; \
89        movq    TF_R11(%rsp),%r11       ; \
90        movq    TF_R12(%rsp),%r12       ; \
91        movq    TF_R13(%rsp),%r13       ; \
92        movq    TF_R14(%rsp),%r14       ; \
93        movq    TF_R15(%rsp),%r15       ; \
94        /* movw TF_GS(%rsp),%gs */      ; \
95        movw    TF_FS(%rsp),%fs         ; \
96        movw    TF_ES(%rsp),%es         ; \
97        movw    TF_DS(%rsp),%ds         ; \
98        addq    $TF_REGSIZE,%rsp        ; \
99        cld
100
101#ifndef x86_ASM
102
103/*
104 * The x86_64 CPU context.
105 */
106typedef struct hal_cpu_context_s {
107        /* Pushed by INTR_SAVE_REGS */
108        uint64_t tf_rax;
109        uint64_t tf_rbx;
110        uint64_t tf_rcx;
111        uint64_t tf_rdx;
112        uint64_t tf_rdi;
113        uint64_t tf_rsi;
114        uint64_t tf_rbp;
115        uint64_t tf_r8;
116        uint64_t tf_r9;
117        uint64_t tf_r10;
118        uint64_t tf_r11;
119        uint64_t tf_r12;
120        uint64_t tf_r13;
121        uint64_t tf_r14;
122        uint64_t tf_r15;
123        uint64_t tf_gs;
124        uint64_t tf_fs;
125        uint64_t tf_es;
126        uint64_t tf_ds;
127
128        /* Pushed by the ISR */
129        uint64_t tf_trapno;
130
131        /* Pushed by the hardware if exception */
132        uint64_t tf_err;        /* in fact, this one may not... */
133        uint64_t tf_rip;
134        uint64_t tf_cs;
135        uint64_t tf_rflags;
136
137        /* Always pushed by the hardware */
138        uint64_t tf_rsp;
139        uint64_t tf_ss;
140} hal_cpu_context_t;
141
142#else
143
144/* offsets in the trapframe structure */
145#define TF_RAX  0
146#define TF_RBX  8
147#define TF_RCX  16
148#define TF_RDX  24
149#define TF_RDI  32
150#define TF_RSI  40
151#define TF_RBP  48
152#define TF_R8   56
153#define TF_R9   64
154#define TF_R10  72
155#define TF_R11  80
156#define TF_R12  88
157#define TF_R13  96
158#define TF_R14  104
159#define TF_R15  112
160#define TF_GS   120
161#define TF_FS   128
162#define TF_ES   136
163#define TF_DS   144
164
165#endif
166
Note: See TracBrowser for help on using the repository browser.