| 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 TF_REGSIZE (19 * 8) |
|---|
| 48 | |
|---|
| 49 | #define INTR_SAVE_REGS \ |
|---|
| 50 | subq $TF_REGSIZE,%rsp ; \ |
|---|
| 51 | movq %rax,TF_RAX(%rsp) ; \ |
|---|
| 52 | movq %rbx,TF_RBX(%rsp) ; \ |
|---|
| 53 | movq %rcx,TF_RCX(%rsp) ; \ |
|---|
| 54 | movq %rdx,TF_RDX(%rsp) ; \ |
|---|
| 55 | movq %rbp,TF_RBP(%rsp) ; \ |
|---|
| 56 | movq %rdi,TF_RDI(%rsp) ; \ |
|---|
| 57 | movq %rsi,TF_RSI(%rsp) ; \ |
|---|
| 58 | movq %r8,TF_R8(%rsp) ; \ |
|---|
| 59 | movq %r9,TF_R9(%rsp) ; \ |
|---|
| 60 | movq %r10,TF_R10(%rsp) ; \ |
|---|
| 61 | movq %r11,TF_R11(%rsp) ; \ |
|---|
| 62 | movq %r12,TF_R12(%rsp) ; \ |
|---|
| 63 | movq %r13,TF_R13(%rsp) ; \ |
|---|
| 64 | movq %r14,TF_R14(%rsp) ; \ |
|---|
| 65 | movq %r15,TF_R15(%rsp) ; \ |
|---|
| 66 | /* movw %gs,TF_GS(%rsp) */ ; \ |
|---|
| 67 | movw %fs,TF_FS(%rsp) ; \ |
|---|
| 68 | movw %es,TF_ES(%rsp) ; \ |
|---|
| 69 | movw %ds,TF_DS(%rsp) ; \ |
|---|
| 70 | cld |
|---|
| 71 | |
|---|
| 72 | #define INTR_RESTORE_REGS \ |
|---|
| 73 | movq TF_RAX(%rsp),%rax ; \ |
|---|
| 74 | movq TF_RBX(%rsp),%rbx ; \ |
|---|
| 75 | movq TF_RCX(%rsp),%rcx ; \ |
|---|
| 76 | movq TF_RDX(%rsp),%rdx ; \ |
|---|
| 77 | movq TF_RBP(%rsp),%rbp ; \ |
|---|
| 78 | movq TF_RDI(%rsp),%rdi ; \ |
|---|
| 79 | movq TF_RSI(%rsp),%rsi ; \ |
|---|
| 80 | movq TF_R8(%rsp),%r8 ; \ |
|---|
| 81 | movq TF_R9(%rsp),%r9 ; \ |
|---|
| 82 | movq TF_R10(%rsp),%r10 ; \ |
|---|
| 83 | movq TF_R11(%rsp),%r11 ; \ |
|---|
| 84 | movq TF_R12(%rsp),%r12 ; \ |
|---|
| 85 | movq TF_R13(%rsp),%r13 ; \ |
|---|
| 86 | movq TF_R14(%rsp),%r14 ; \ |
|---|
| 87 | movq TF_R15(%rsp),%r15 ; \ |
|---|
| 88 | /* movw TF_GS(%rsp),%gs */ ; \ |
|---|
| 89 | movw TF_FS(%rsp),%fs ; \ |
|---|
| 90 | movw TF_ES(%rsp),%es ; \ |
|---|
| 91 | movw TF_DS(%rsp),%ds ; \ |
|---|
| 92 | addq $TF_REGSIZE,%rsp ; \ |
|---|
| 93 | cld |
|---|
| 94 | |
|---|
| 95 | #ifndef x86_ASM |
|---|
| 96 | |
|---|
| 97 | /* |
|---|
| 98 | * The x86_64 trap frame. |
|---|
| 99 | */ |
|---|
| 100 | struct trapframe { |
|---|
| 101 | /* Pushed by INTR_SAVE_REGS */ |
|---|
| 102 | uint64_t tf_rax; |
|---|
| 103 | uint64_t tf_rbx; |
|---|
| 104 | uint64_t tf_rcx; |
|---|
| 105 | uint64_t tf_rdx; |
|---|
| 106 | uint64_t tf_rdi; |
|---|
| 107 | uint64_t tf_rsi; |
|---|
| 108 | uint64_t tf_rbp; |
|---|
| 109 | uint64_t tf_r8; |
|---|
| 110 | uint64_t tf_r9; |
|---|
| 111 | uint64_t tf_r10; |
|---|
| 112 | uint64_t tf_r11; |
|---|
| 113 | uint64_t tf_r12; |
|---|
| 114 | uint64_t tf_r13; |
|---|
| 115 | uint64_t tf_r14; |
|---|
| 116 | uint64_t tf_r15; |
|---|
| 117 | uint64_t tf_gs; |
|---|
| 118 | uint64_t tf_fs; |
|---|
| 119 | uint64_t tf_es; |
|---|
| 120 | uint64_t tf_ds; |
|---|
| 121 | |
|---|
| 122 | /* Pushed by the ISR */ |
|---|
| 123 | uint64_t tf_trapno; |
|---|
| 124 | |
|---|
| 125 | /* These are pushed for a trap */ |
|---|
| 126 | uint64_t tf_err; |
|---|
| 127 | uint64_t tf_rip; |
|---|
| 128 | uint64_t tf_cs; |
|---|
| 129 | uint64_t tf_rflags; |
|---|
| 130 | |
|---|
| 131 | /* These are always pushed */ |
|---|
| 132 | uint64_t tf_rsp; |
|---|
| 133 | uint64_t tf_ss; |
|---|
| 134 | }; |
|---|
| 135 | |
|---|
| 136 | /* |
|---|
| 137 | * Our small trap frame. |
|---|
| 138 | */ |
|---|
| 139 | struct small_trapframe { |
|---|
| 140 | uint64_t tf_trapno; |
|---|
| 141 | |
|---|
| 142 | /* These are pushed for a trap */ |
|---|
| 143 | uint64_t tf_err; /* in fact, this one may not... */ |
|---|
| 144 | uint64_t tf_rip; |
|---|
| 145 | uint64_t tf_cs; |
|---|
| 146 | uint64_t tf_rflags; |
|---|
| 147 | |
|---|
| 148 | /* These are always pushed */ |
|---|
| 149 | uint64_t tf_rsp; |
|---|
| 150 | uint64_t tf_ss; |
|---|
| 151 | }; |
|---|
| 152 | |
|---|
| 153 | #else |
|---|
| 154 | |
|---|
| 155 | /* offsets in the trapframe structure */ |
|---|
| 156 | #define TF_RAX 0 |
|---|
| 157 | #define TF_RBX 8 |
|---|
| 158 | #define TF_RCX 16 |
|---|
| 159 | #define TF_RDX 24 |
|---|
| 160 | #define TF_RDI 32 |
|---|
| 161 | #define TF_RSI 40 |
|---|
| 162 | #define TF_RBP 48 |
|---|
| 163 | #define TF_R8 56 |
|---|
| 164 | #define TF_R9 64 |
|---|
| 165 | #define TF_R10 72 |
|---|
| 166 | #define TF_R11 80 |
|---|
| 167 | #define TF_R12 88 |
|---|
| 168 | #define TF_R13 96 |
|---|
| 169 | #define TF_R14 104 |
|---|
| 170 | #define TF_R15 112 |
|---|
| 171 | #define TF_GS 120 |
|---|
| 172 | #define TF_FS 128 |
|---|
| 173 | #define TF_ES 136 |
|---|
| 174 | #define TF_DS 144 |
|---|
| 175 | |
|---|
| 176 | #endif |
|---|
| 177 | |
|---|