aboutsummaryrefslogtreecommitdiff
path: root/src/core/int.S
blob: 2897698a13e13249c196e6548883390cce9d4e85 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
.code64

.extern printk
.extern apic_ack

.macro CALL_PRINTK msg
    mov \msg, %rdi
    mov $0, %eax # Required for variadic functions
    mov $printk,%rcx
    call *(%rcx)
.endm

.macro  SAVE_REGS
    push %r8
    push %r9
    push %r10
    push %r11
    push %r12
    push %r13
    push %r14
    push %r15
    push %rax
    push %rbx
    push %rcx
    push %rdx
    push %rbp
    push %rsi
    push %rdi
    push %rax
    mov $0x10, %ax
    mov %ax, %ds
    pop %rax
.endm

.macro RESTORE_REGS
    pop %rdi    
    pop %rsi    
    pop %rbp    
    pop %rdx    
    pop %rcx    
    pop %rbx
    pop %rax
    pop %r15
    pop %r14
    pop %r13
    pop %r12
    pop %r11
    pop %r10
    pop %r9
    pop %r8
.endm

.globl INT_DEFAULT
INT_DEFAULT:
    SAVE_REGS
    RESTORE_REGS
    iretq

.globl INT_0
INT_0:
    CALL_PRINTK $MSG_INT_0
    INT_0_INFINITE:
    jmp INT_0_INFINITE
    iretq

.globl INT_10
INT_10:
    CALL_PRINTK $MSG_INT_10
    INT_10_INFINITE:
    jmp INT_10_INFINITE
    iretq

.globl INT_14
INT_14:
    CALL_PRINTK $MSG_INT_14
    INT_14_INFINITE:
    jmp INT_14_INFINITE
    iretq

.globl INT_KBD
INT_KBD:
    SAVE_REGS
    CALL_PRINTK $MSG_INT_KBD
    call apic_ack
    RESTORE_REGS
    iretq

.globl INT_CLK
.extern clock
INT_CLK:
    SAVE_REGS
    call clock
    call apic_ack
    RESTORE_REGS
    iretq

.globl INT_SYSCALL
.extern syscall
INT_SYSCALL:
    SAVE_REGS
    call syscall
    RESTORE_REGS
    iretq
  

MSG_INT_0:
.asciz "Zero Division error!"
MSG_INT_10:
.asciz "Invalid TSS!"
MSG_INT_14:
.asciz "Page fault!"
MSG_INT_KBD:
.asciz "Key press!"
MSG:
.asciz "Called :)\n"