Changes in / [6b1a85c:5f83634] in mainline
- Location:
- kernel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/amd64/include/cpu.h
r6b1a85c r5f83634 45 45 #define RFLAGS_DF (1 << 10) 46 46 #define RFLAGS_OF (1 << 11) 47 #define RFLAGS_NT (1 << 14)48 47 #define RFLAGS_RF (1 << 16) 49 48 -
kernel/arch/amd64/include/interrupt.h
r6b1a85c r5f83634 74 74 typedef struct istate { 75 75 uint64_t rax; 76 uint64_t rbx;77 76 uint64_t rcx; 78 77 uint64_t rdx; 79 78 uint64_t rsi; 80 79 uint64_t rdi; 81 uint64_t rbp;82 80 uint64_t r8; 83 81 uint64_t r9; 84 82 uint64_t r10; 85 83 uint64_t r11; 86 uint64_t r12; 87 uint64_t r13; 88 uint64_t r14; 89 uint64_t r15; 90 uint64_t alignment; /* align rbp_frame on multiple of 16 */ 91 uint64_t rbp_frame; /* imitation of frame pointer linkage */ 92 uint64_t rip_frame; /* imitation of return address linkage */ 93 uint64_t error_word; /* real or fake error word */ 84 uint64_t rbp; 85 uint64_t error_word; 94 86 uint64_t rip; 95 87 uint64_t cs; 96 88 uint64_t rflags; 97 uint64_t rsp; /* only if istate_t is from uspace */ 98 uint64_t ss; /* only if istate_t is from uspace */ 89 uint64_t stack[]; /* Additional data on stack */ 99 90 } istate_t; 100 91 -
kernel/arch/amd64/src/asm.S
r6b1a85c r5f83634 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 #define IREGISTER_SPACE 80 30 31 #define IOFFSET_RAX 0x00 32 #define IOFFSET_RCX 0x08 33 #define IOFFSET_RDX 0x10 34 #define IOFFSET_RSI 0x18 35 #define IOFFSET_RDI 0x20 36 #define IOFFSET_R8 0x28 37 #define IOFFSET_R9 0x30 38 #define IOFFSET_R10 0x38 39 #define IOFFSET_R11 0x40 40 #define IOFFSET_RBP 0x48 41 42 /** 43 * Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int 44 * has no error word and 1 means interrupt with error word 45 * 46 */ 47 #define ERROR_WORD_INTERRUPT_LIST 0x00027D00 28 48 29 49 #include <arch/pm.h> … … 154 174 ret 155 175 156 #define ISTATE_OFFSET_RAX 0 157 #define ISTATE_OFFSET_RBX 8 158 #define ISTATE_OFFSET_RCX 16 159 #define ISTATE_OFFSET_RDX 24 160 #define ISTATE_OFFSET_RSI 32 161 #define ISTATE_OFFSET_RDI 40 162 #define ISTATE_OFFSET_RBP 48 163 #define ISTATE_OFFSET_R8 56 164 #define ISTATE_OFFSET_R9 64 165 #define ISTATE_OFFSET_R10 72 166 #define ISTATE_OFFSET_R11 80 167 #define ISTATE_OFFSET_R12 88 168 #define ISTATE_OFFSET_R13 96 169 #define ISTATE_OFFSET_R14 104 170 #define ISTATE_OFFSET_R15 112 171 #define ISTATE_OFFSET_ALIGNMENT 120 172 #define ISTATE_OFFSET_RBP_FRAME 128 173 #define ISTATE_OFFSET_RIP_FRAME 136 174 #define ISTATE_OFFSET_ERROR_WORD 144 175 #define ISTATE_OFFSET_RIP 152 176 #define ISTATE_OFFSET_CS 160 177 #define ISTATE_OFFSET_RFLAGS 168 178 #define ISTATE_OFFSET_RSP 176 179 #define ISTATE_OFFSET_SS 184 180 181 /* 182 * Size of the istate structure without the hardware-saved part and without the 183 * error word. 184 */ 185 #define ISTATE_SOFT_SIZE 144 186 187 /** 188 * Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int 189 * has no error word and 1 means interrupt with error word 190 * 191 */ 192 #define ERROR_WORD_INTERRUPT_LIST 0x00027D00 193 194 #define INTERRUPT_ALIGN 256 176 /** Push all volatile general purpose registers on stack 177 * 178 */ 179 .macro save_all_gpr 180 movq %rax, IOFFSET_RAX(%rsp) 181 movq %rcx, IOFFSET_RCX(%rsp) 182 movq %rdx, IOFFSET_RDX(%rsp) 183 movq %rsi, IOFFSET_RSI(%rsp) 184 movq %rdi, IOFFSET_RDI(%rsp) 185 movq %r8, IOFFSET_R8(%rsp) 186 movq %r9, IOFFSET_R9(%rsp) 187 movq %r10, IOFFSET_R10(%rsp) 188 movq %r11, IOFFSET_R11(%rsp) 189 movq %rbp, IOFFSET_RBP(%rsp) 190 .endm 191 192 .macro restore_all_gpr 193 movq IOFFSET_RAX(%rsp), %rax 194 movq IOFFSET_RCX(%rsp), %rcx 195 movq IOFFSET_RDX(%rsp), %rdx 196 movq IOFFSET_RSI(%rsp), %rsi 197 movq IOFFSET_RDI(%rsp), %rdi 198 movq IOFFSET_R8(%rsp), %r8 199 movq IOFFSET_R9(%rsp), %r9 200 movq IOFFSET_R10(%rsp), %r10 201 movq IOFFSET_R11(%rsp), %r11 202 movq IOFFSET_RBP(%rsp), %rbp 203 .endm 204 205 #define INTERRUPT_ALIGN 128 195 206 196 207 /** Declare interrupt handlers … … 218 229 * Version with error word. 219 230 */ 220 subq $I STATE_SOFT_SIZE, %rsp231 subq $IREGISTER_SPACE, %rsp 221 232 .else 222 233 /* 223 * Version without error word .234 * Version without error word, 224 235 */ 225 subq $(I STATE_SOFT_SIZE + 8), %rsp236 subq $(IREGISTER_SPACE + 8), %rsp 226 237 .endif 227 238 .else 228 239 /* 229 * Version without error word .240 * Version without error word, 230 241 */ 231 subq $(I STATE_SOFT_SIZE + 8), %rsp242 subq $(IREGISTER_SPACE + 8), %rsp 232 243 .endif 233 244 245 save_all_gpr 246 cld 247 234 248 /* 235 * Save the general purpose registers.236 */237 movq %rax, ISTATE_OFFSET_RAX(%rsp)238 movq %rbx, ISTATE_OFFSET_RBX(%rsp)239 movq %rcx, ISTATE_OFFSET_RCX(%rsp)240 movq %rdx, ISTATE_OFFSET_RDX(%rsp)241 movq %rsi, ISTATE_OFFSET_RSI(%rsp)242 movq %rdi, ISTATE_OFFSET_RDI(%rsp)243 movq %rbp, ISTATE_OFFSET_RBP(%rsp)244 movq %r8, ISTATE_OFFSET_R8(%rsp)245 movq %r9, ISTATE_OFFSET_R9(%rsp)246 movq %r10, ISTATE_OFFSET_R10(%rsp)247 movq %r11, ISTATE_OFFSET_R11(%rsp)248 movq %r12, ISTATE_OFFSET_R12(%rsp)249 movq %r13, ISTATE_OFFSET_R13(%rsp)250 movq %r14, ISTATE_OFFSET_R14(%rsp)251 movq %r15, ISTATE_OFFSET_R15(%rsp)252 253 /*254 * Imitate a regular stack frame linkage.255 249 * Stop stack traces here if we came from userspace. 256 250 */ 251 movq %cs, %rax 257 252 xorq %rdx, %rdx 258 cmpq $(gdtselector(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp) 259 cmovnzq %rdx, %rbp 260 261 movq %rbp, ISTATE_OFFSET_RBP_FRAME(%rsp) 262 movq ISTATE_OFFSET_RIP(%rsp), %rax 263 movq %rax, ISTATE_OFFSET_RIP_FRAME(%rsp) 264 leaq ISTATE_OFFSET_RBP_FRAME(%rsp), %rbp 265 266 movq $(\i), %rdi /* pass intnum in the first argument */ 267 movq %rsp, %rsi /* pass istate address in the second argument */ 268 269 cld 270 253 cmpq %rax, IREGISTER_SPACE+16(%rsp) 254 cmovneq %rdx, %rbp 255 256 movq $(\i), %rdi /* %rdi - first argument */ 257 movq %rsp, %rsi /* %rsi - pointer to istate */ 258 271 259 /* Call exc_dispatch(i, istate) */ 272 260 call exc_dispatch 273 274 /* 275 * Restore all scratch registers and the preserved registers we have 276 * clobbered in this handler (i.e. RBP). 277 */ 278 movq ISTATE_OFFSET_RAX(%rsp), %rax 279 movq ISTATE_OFFSET_RCX(%rsp), %rcx 280 movq ISTATE_OFFSET_RDX(%rsp), %rdx 281 movq ISTATE_OFFSET_RSI(%rsp), %rsi 282 movq ISTATE_OFFSET_RDI(%rsp), %rdi 283 movq ISTATE_OFFSET_RBP(%rsp), %rbp 284 movq ISTATE_OFFSET_R8(%rsp), %r8 285 movq ISTATE_OFFSET_R9(%rsp), %r9 286 movq ISTATE_OFFSET_R10(%rsp), %r10 287 movq ISTATE_OFFSET_R11(%rsp), %r11 261 262 restore_all_gpr 288 263 289 264 /* $8 = Skip error word */ 290 addq $(I STATE_SOFT_SIZE + 8), %rsp265 addq $(IREGISTER_SPACE + 8), %rsp 291 266 iretq 292 267 -
kernel/arch/amd64/src/syscall.c
r6b1a85c r5f83634 66 66 * - clear DF so that the string instructions operate in 67 67 * the right direction 68 * - clear NT to prevent a #GP should the flag proliferate to an IRET69 68 */ 70 write_msr(AMD_MSR_SFMASK, RFLAGS_IF | RFLAGS_DF | RFLAGS_NT);69 write_msr(AMD_MSR_SFMASK, RFLAGS_IF | RFLAGS_DF); 71 70 } 72 71 -
kernel/arch/ia32/include/cpu.h
r6b1a85c r5f83634 37 37 38 38 #define EFLAGS_IF (1 << 9) 39 #define EFLAGS_DF (1 << 10)40 #define EFLAGS_NT (1 << 14)41 39 #define EFLAGS_RF (1 << 16) 42 40 -
kernel/arch/ia32/src/asm.S
r6b1a85c r5f83634 1 1 /* 2 * Copyright (c) 20 10Jakub Jermar2 * Copyright (c) 2001 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 32 32 33 33 #include <arch/pm.h> 34 #include <arch/cpu.h>35 34 #include <arch/mm/page.h> 36 35 … … 191 190 .global sysenter_handler 192 191 sysenter_handler: 192 sti 193 193 subl $(ISTATE_REAL_SIZE), %esp 194 194 … … 227 227 * Switch to kernel selectors. 228 228 */ 229 movw $ (gdtselector(KDATA_DES)), %ax229 movw $16, %ax 230 230 movw %ax, %ds 231 231 movw %ax, %es 232 232 233 /* 234 * Sanitize EFLAGS. 235 * 236 * SYSENTER does not clear the NT flag, which could thus proliferate 237 * from here to the IRET instruction via a context switch and result 238 * in crash. 239 * 240 * SYSENTER does not clear DF, which the ABI assumes to be cleared. 241 * 242 * SYSENTER clears IF, which we would like to be set for syscalls. 243 * 244 */ 245 pushl $(EFLAGS_IF) /* specify EFLAGS bits that we want to set */ 246 popfl /* set bits from the mask, clear or ignore others */ 247 233 cld 248 234 call syscall_handler 249 235 … … 308 294 * Switch to kernel selectors. 309 295 */ 310 movl $ (gdtselector(KDATA_DES)), %eax296 movl $16, %eax 311 297 movl %eax, %ds 312 298 movl %eax, %es … … 372 358 .if (1 << \i) & ERROR_WORD_INTERRUPT_LIST 373 359 /* 374 * Exception with error word .360 * Exception with error word: do nothing 375 361 */ 376 subl $ISTATE_SOFT_SIZE, %esp377 362 .else 378 363 /* 379 364 * Exception without error word: fake up one 380 365 */ 381 subl $(ISTATE_SOFT_SIZE + 4), %esp366 pushl $0 382 367 .endif 383 368 .else 384 369 /* 385 * Interrupt: fake up an error word370 * Interrupt: fake up one 386 371 */ 387 subl $(ISTATE_SOFT_SIZE + 4), %esp372 pushl $0 388 373 .endif 374 375 subl $ISTATE_SOFT_SIZE, %esp 389 376 390 377 /* … … 417 404 * Switch to kernel selectors. 418 405 */ 419 movl $ (gdtselector(KDATA_DES)), %eax406 movl $16, %eax 420 407 movl %eax, %ds 421 408 movl %eax, %es … … 426 413 */ 427 414 xorl %eax, %eax 428 cmpl $ (gdtselector(KTEXT_DES)), ISTATE_OFFSET_CS(%esp)429 cmov nzl %eax, %ebp415 cmpl $8, ISTATE_OFFSET_CS(%esp) 416 cmovl %eax, %ebp 430 417 431 418 movl %ebp, ISTATE_OFFSET_EBP_FRAME(%esp) -
kernel/generic/src/console/kconsole.c
r6b1a85c r5f83634 210 210 link_t *pos = NULL; 211 211 const char *hint; 212 char *output = malloc(MAX_CMDLINE, 0);212 char output[MAX_CMDLINE]; 213 213 214 214 output[0] = 0; … … 235 235 str_cpy(input, size, output); 236 236 237 free(output);238 237 return found; 239 238 } … … 246 245 wchar_t *current = history[history_pos]; 247 246 current[0] = 0; 248 char *tmp = malloc(STR_BOUNDS(MAX_CMDLINE), 0);249 247 250 248 while (true) { … … 291 289 beg++; 292 290 291 char tmp[STR_BOUNDS(MAX_CMDLINE)]; 293 292 wstr_to_str(tmp, position - beg + 1, current + beg); 294 293 … … 416 415 } 417 416 418 free(tmp);419 417 return current; 420 418 } … … 632 630 cmd->argv[i].vartype = ARG_TYPE_STRING; 633 631 } else { 634 printf("Wrong syn tax.\n");632 printf("Wrong synxtax.\n"); 635 633 error = true; 636 634 } … … 690 688 printf("Type \"exit\" to leave the console.\n"); 691 689 692 char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE), 0);693 690 while (true) { 694 691 wchar_t *tmp = clever_readline((char *) prompt, stdin); … … 697 694 continue; 698 695 696 char cmdline[STR_BOUNDS(MAX_CMDLINE)]; 699 697 wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp); 700 698 … … 708 706 (void) cmd_info->func(cmd_info->argv); 709 707 } 710 free(cmdline);711 708 } 712 709
Note:
See TracChangeset
for help on using the changeset viewer.