annotate cos/kernel/asmcode.asm @ 244:58155c7c4a8e

Add hexutil
author Windel Bouwman
date Wed, 24 Jul 2013 19:47:13 +0200
parents 91f91ff07ea8
children
rev   line source
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
1 ; The default interrupt handlers.
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
2 ; from 20 - 31 are reserved vectors.
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
3 ; below are the custom ones!
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
4
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
5 ; Calling convention AMD64 ABI:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
6 ; parameters in: rdi, rsi, rdx, rcx ....
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
7
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
8 section .text
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
9 align 4
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
10
25
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
11 ; Function to read the current instruction pointer value:
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
12 global read_rip
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
13 read_rip:
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
14 pop rax
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
15 jmp rax
d3c4bf3720a3 Beginning of multitasking
windel
parents: 21
diff changeset
16
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
17 global loadIDT
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
18 loadIDT:
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
19 extern idtP
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
20 ; TODO: make this pointer thing more insightfull:
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
21 lidt [idtP]
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
22 ret
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
23
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
24 global setCR3
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
25 setCR3:
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
26 mov cr3, rdi ; Load cr3
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
27 ret
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 31
diff changeset
28
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
29 ; ISR related assembler wrappers:
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
30
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
31 %macro ISR_NOERRCODE 1
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
32 global INT%1
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
33 INT%1:
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
34 cli
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
35 push strict qword 0 ; push dummy error code
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
36 push strict qword %1 ; push interrupt number
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
37 jmp isr_common_stub
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
38 %endmacro
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
39
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
40 %macro ISR_ERRCODE 1
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
41 global INT%1
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
42 INT%1:
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
43 cli ; disable interrupts
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
44 push strict qword %1 ; push interrupt number
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
45 jmp isr_common_stub
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
46 %endmacro
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
47
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
48 isr_common_stub:
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
49 ; Do some saving:
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
50 push rax ; regs[6]
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
51 push rcx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
52 push rdx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
53 push rbx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
54 push rbp
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
55 push rsi
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
56 push rdi ; regs[0]
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
57
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
58 ; AMD64 calling convention, first parameter is in rdi:
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
59 mov rdi, rsp ; Load stack pointer into rdi to indicate where the registers on the stack are (so that we can change them!)
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
60
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
61 ; TODO: load kernel interrupt stack pointer
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
62 extern isr_handler
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
63 call isr_handler
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
64
17
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
65 pop rdi
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
66 pop rsi
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
67 pop rbp
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
68 pop rbx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
69 pop rdx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
70 pop rcx
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
71 pop rax
f3e3e0e9c4bc First attempt IDT loader 64 bits. INT13 occurs
windel
parents: 14
diff changeset
72
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
73 add rsp, 16 ; cleanup error code and isr number
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
74 sti ; enable interrupts again
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
75 iretq
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
76
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
77 ; Exception handlers:
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
78 ISR_NOERRCODE 0
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
79 ISR_NOERRCODE 1
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
80 ISR_NOERRCODE 2
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
81 ISR_NOERRCODE 3
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
82 ISR_NOERRCODE 4
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
83 ISR_NOERRCODE 5
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
84 ISR_NOERRCODE 6
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
85 ISR_NOERRCODE 7
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
86 ISR_ERRCODE 8
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
87 ISR_NOERRCODE 9
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
88 ISR_ERRCODE 10
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
89 ISR_ERRCODE 11
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
90 ISR_ERRCODE 12
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
91 ISR_ERRCODE 13
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
92 ISR_ERRCODE 14
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
93 ; 15 is reserved
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
94 ISR_NOERRCODE 16
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
95 ISR_ERRCODE 17
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
96 ISR_NOERRCODE 18
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
97 ISR_NOERRCODE 19
36
91f91ff07ea8 Removed test variables
windel
parents: 33
diff changeset
98 ; 20 - 31 are reserved
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
99
33
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
100 ; irq handlers:
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
101 ISR_NOERRCODE 32
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
102 ISR_NOERRCODE 33
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
103 ISR_NOERRCODE 34
33
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
104 ISR_NOERRCODE 35
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
105 ISR_NOERRCODE 36
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
106 ISR_NOERRCODE 37
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
107 ISR_NOERRCODE 38
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
108 ISR_NOERRCODE 39
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
109 ISR_NOERRCODE 40
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
110 ISR_NOERRCODE 41
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
111 ISR_NOERRCODE 42
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
112 ISR_NOERRCODE 43
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
113 ISR_NOERRCODE 44
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
114 ISR_NOERRCODE 45
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
115 ISR_NOERRCODE 46
d8185ddb6c7b Added more interrupt handlers
windel
parents: 32
diff changeset
116 ISR_NOERRCODE 47
14
a58904747019 Added asm interrupt handler things, not yet working
windel
parents:
diff changeset
117
31
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
118 ; default handler:
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
119 ISR_NOERRCODE 255
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
120
88590c42320f Changed interrupt handler
windel
parents: 29
diff changeset
121