| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #define SAVE_REGS() \
- pushq %rax; \
- pushq %rcx; \
- pushq %rdx; \
- pushq %rbx; \
- /* we shouldn't push it because it's really in stack */ \
- pushq %rsp; \
- pushq %rbp; \
- pushq %rsi; \
- pushq %rdi; \
- pushq %r8; \
- pushq %r9; \
- pushq %r10; \
- pushq %r11; \
- pushq %r12; \
- pushq %r13; \
- pushq %r14; \
- pushq %r15; \
- /* and, segment registers */ \
- movq %ds, %rax; \
- pushq %rax; \
- movq %es, %rax; \
- pushq %rax; \
- movq %fs, %rax; \
- pushq %rax; \
- movq %gs, %rax; \
- pushq %rax; \
- movq %ss, %rax; \
- pushq %rax
-
-
- restore_all:
- popq %rax
- movq %rax, %ss
- popq %rax
- movq %rax, %gs
- popq %rax
- movq %rax, %fs
-
- popq %rax
- movq %rax, %es
-
- popq %rax
- movq %rax, %ds
- popq %r15
- popq %r14
- popq %r13
- popq %r12
- popq %r11
- popq %r10
- popq %r9
- popq %r8
- popq %rdi
- popq %rsi
- popq %rbp
- popq %rsp
- popq %rbx
- popq %rdx
- popq %rcx
- popq %rax
- /* add it because we don't want errcode or func */
- addq $0x10, %rsp
- /* iretq will pop ss if it need */
- iretq
- .globl __stack_chk_fail
- __stack_chk_fail:
- movq schkfail_msg(%rip), %rdi
- callq printf
- scf_die:
- hlt
- jmp scf_die
- .globl divide_error
- divide_error:
- /* at fact, we don't need cli because CPU will do it. */
- cli
- /* error code: 0 */
- pushq $0
- pushq %rax
- SAVE_REGS();
- /* first argument for do_divide_error */
- movq %rsp, %rdi
-
- leaq do_divide_error(%rip), %rcx
- callq *%rcx
- /* return */
- sti
- jmp restore_all
-
- .section .rodata
- schkfail_msg:
- .asciz "kernel panic: stack check fail. \n"
|