summaryrefslogtreecommitdiff
path: root/kernel/include/x86_64_regs.S
blob: 7b72d765670a018d36d9512b1669bba5f12684fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* isr stack */
/* ss:rsp (original rsp) -> rflags -> cs -> rip */

/* callee saved registers: rbx, rbp, rsp, r12, r13, r14, r15 */
/* isr saved registers: rsp, rip, rflags, cs, ss */

/* if the code will stay on same thread of execution use push/pop_caller_saved
 * else use push/pop_callee_saved with push/pop_caller_saved
 */

/* push 0x30 bytes to stack */
.macro push_callee_saved
	push %rbx
	push %rbp
	push %r12
	push %r13
	push %r14
	push %r15
.endm

/* pop 0x30 bytes from stack */
.macro pop_callee_saved
	push %rbx
	push %rbp
	push %r12
	push %r13
	push %r14
	push %r15
.endm

/* push 0x50 bytes to stack */
.macro push_caller_saved
	push %rax
	push %rcx
	push %rdx
	push %rsi
	push %rdi
	push %r8
	push %r9
	push %r10
	push %r11
	mov %ds, %ax
	shl $16, %rax
	mov %es, %ax
	shl $16, %rax
	mov %fs, %ax
	shl $16, %rax
	mov %gs, %ax
	push %rax
	mov $0x10, %ax
	mov %ax, %ds
	mov %ax, %ss
	mov %ax, %es
	mov %ax, %fs
	mov %ax, %gs
	mov 0x48(%rsp), %rax
.endm

/* pop 0x50 bytes from stack */
.macro pop_caller_saved
	pop %rax
	mov %ax, %gs
	shr $16, %rax
	mov %ax, %fs
	shr $16, %rax
	mov %ax, %es
	shr $16, %rax
	mov %ax, %ds
	pop %r11
	pop %r10
	pop %r9
	pop %r8
	pop %rdi
	pop %rsi
	pop %rdx
	pop %rcx
	pop %rax
.endm