Skip to content

Commit 32ba861

Browse files
committed
ISR/IRQ Exports and Exception Macros
1 parent e06f7fa commit 32ba861

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/cpu/isr.s

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
extern isr_handler
44
extern irq_handler
5-
global isr_handler
6-
global irq_handler
75

86
%macro ISR_NOERR 1
97
global isr%1
@@ -48,7 +46,7 @@ ISR_ERR 13
4846
ISR_ERR 14
4947
ISR_NOERR 15
5048
ISR_NOERR 16
51-
ISR_NOERR 17
49+
ISR_ERR 17
5250
ISR_NOERR 18
5351
ISR_NOERR 19
5452
ISR_NOERR 20
@@ -61,7 +59,7 @@ ISR_NOERR 26
6159
ISR_NOERR 27
6260
ISR_NOERR 28
6361
ISR_NOERR 29
64-
ISR_NOERR 30
62+
ISR_ERR 30
6563
ISR_NOERR 31
6664
ISR_NOERR 128
6765

@@ -100,8 +98,7 @@ isr_common_stub:
10098
mov gs, ax
10199
push esp
102100
call isr_handler
103-
add esp, 4
104-
mov esp, eax
101+
mov esp, eax ; IMPORTANT: use the returned (potentially switched) stack pointer
105102

106103
pop eax
107104
mov gs, ax
@@ -135,8 +132,7 @@ irq_common_stub:
135132
mov gs, ax
136133
push esp
137134
call irq_handler
138-
add esp, 4
139-
mov esp, eax
135+
mov esp, eax ; IMPORTANT: use the returned (potentially switched) stack pointer
140136

141137
pop eax
142138
mov gs, ax

src/task/switch.s

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,30 @@ switch_to:
5757
ret
5858

5959
%define PROC_ESP 36
60+
%define PROC_EBP 40
6061

6162
context_switch:
62-
mov eax, [esp+4]
63-
mov edx, [esp+8]
64-
mov ecx, [esp+12]
63+
; [esp+4] = previous process (process_t*)
64+
; [esp+8] = next process (process_t*)
65+
; [esp+12] = registers (registers_t*)
66+
67+
mov eax, [esp+4] ; eax = previous
68+
mov edx, [esp+8] ; edx = next
69+
6570
test eax, eax
6671
jz .load_next
67-
mov [eax+PROC_ESP], ecx
72+
73+
; Save current ESP and EBP to previous task
74+
mov [eax+PROC_ESP], esp
75+
mov [eax+PROC_EBP], ebp
76+
6877
.load_next:
78+
; Switch to next task's ESP and EBP
6979
mov esp, [edx+PROC_ESP]
70-
pop eax
71-
mov ds, ax
72-
mov es, ax
73-
mov fs, ax
74-
mov gs, ax
75-
popa
76-
add esp, 8
77-
sti
78-
iret
80+
mov ebp, [edx+PROC_EBP]
81+
82+
; Note: If this was called from irq0_handler, the 'esp' we just restored
83+
; points to a registers_t struct. The assembly stub in isr.s will
84+
; then pop these registers and iret.
85+
86+
ret

0 commit comments

Comments
 (0)