File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33extern isr_handler
44extern irq_handler
5- global isr_handler
6- global irq_handler
75
86%macro ISR_NOERR 1
97global isr% 1
@@ -48,7 +46,7 @@ ISR_ERR 13
4846ISR_ERR 14
4947ISR_NOERR 15
5048ISR_NOERR 16
51- ISR_NOERR 17
49+ ISR_ERR 17
5250ISR_NOERR 18
5351ISR_NOERR 19
5452ISR_NOERR 20
@@ -61,7 +59,7 @@ ISR_NOERR 26
6159ISR_NOERR 27
6260ISR_NOERR 28
6361ISR_NOERR 29
64- ISR_NOERR 30
62+ ISR_ERR 30
6563ISR_NOERR 31
6664ISR_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
Original file line number Diff line number Diff line change @@ -57,22 +57,30 @@ switch_to:
5757 ret
5858
5959%define PROC_ESP 36
60+ %define PROC_EBP 40
6061
6162context_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
You can’t perform that action at this time.
0 commit comments