MINIX 防止中断重入的代码有问题,还是我错了?
本人在学习MINIX,在做中断的时候,遇到一个百思不得其解的地方,minix 的代码
!*===========================================================================*
!* save *
!*===========================================================================*
! Save for protected mode.
! This is much simpler than for 8086 mode, because the stack already points
! into the process table, or has already been switched to the kernel stack.
.align 16
save:
cld ! set direction flag to a known value
pushad ! save "general" registers
o16 push ds ! save ds
o16 push es ! save es
o16 push fs ! save fs
o16 push gs ! save gs
mov dx, ss ! ss is kernel data segment
mov ds, dx ! load rest of kernel segments
mov es, dx ! kernel does not use fs, gs
mov eax, esp ! prepare to return
incb (_k_reenter) ! from -1 if not reentering
jnz set_restart1 ! stack is already kernel stack
mov esp, k_stktop
push _restart ! build return address for int handler
xor ebp, ebp ! for stacktrace
jmp RETADR-P_STACKBASE(eax)
.align 4
set_restart1:
push restart1
jmp RETADR-P_STACKBASE(eax)
;==============================我是分割线 ==================================;
;上面是保存CONTEXT的代码
;==============================我是分割线 ==================================;
! Note this is a macro, it looks like a subroutine.
#define hwint_master(irq) \
call save /* save interrupted process state */;\
inb INT_CTLMASK ;\
orb al, [1<<irq] ;\
outb INT_CTLMASK /* disable the irq */;\
movb al, ENABLE ;\
outb INT_CTL /* reenable master 8259 */;\
sti /* enable interrupts */;\
push irq /* irq */;\
call (_irq_table + 4*irq) /* eax = (*irq_table[irq])(irq) */;\
pop ecx ;\
cli /* disable interrupts */;\
test eax, eax /* need to reenable irq? */;\
jz 0f ;\
inb INT_CTLMASK ;\
andb al, ~[1<<irq] ;\
outb INT_CTLMASK /* enable the irq */;\
0: ret /* restart (another) process */
;==============================我又是分割线 ==================================;
;上面是8259A主片的宏
;==============================还是我 ==================================;
?????????????????????????
>>本人有一点很不明白百思不得其解,为什么只设置了一个(_k_reenter),来防止中断重入,试想一下,要是我先是键盘中断产生了,键盘程序没处理完,这时候时钟中断发生,因为键盘中断没处理完,那么(_k_reenter) 没有 减1,时钟这时候CMP (_k_reenter),0是不成立的,时钟ISR不能执行,这真的是滑天下之大稽了,难道他写的时候没发现这个有问题吗?还是我脑子进水了?
!*===========================================================================*
!* save *
!*===========================================================================*
! Save for protected mode.
! This is much simpler than for 8086 mode, because the stack already points
! into the process table, or has already been switched to the kernel stack.
.align 16
save:
cld ! set direction flag to a known value
pushad ! save "general" registers
o16 push ds ! save ds
o16 push es ! save es
o16 push fs ! save fs
o16 push gs ! save gs
mov dx, ss ! ss is kernel data segment
mov ds, dx ! load rest of kernel segments
mov es, dx ! kernel does not use fs, gs
mov eax, esp ! prepare to return
incb (_k_reenter) ! from -1 if not reentering
jnz set_restart1 ! stack is already kernel stack
mov esp, k_stktop
push _restart ! build return address for int handler
xor ebp, ebp ! for stacktrace
jmp RETADR-P_STACKBASE(eax)
.align 4
set_restart1:
push restart1
jmp RETADR-P_STACKBASE(eax)
;==============================我是分割线 ==================================;
;上面是保存CONTEXT的代码
;==============================我是分割线 ==================================;
! Note this is a macro, it looks like a subroutine.
#define hwint_master(irq) \
call save /* save interrupted process state */;\
inb INT_CTLMASK ;\
orb al, [1<<irq] ;\
outb INT_CTLMASK /* disable the irq */;\
movb al, ENABLE ;\
outb INT_CTL /* reenable master 8259 */;\
sti /* enable interrupts */;\
push irq /* irq */;\
call (_irq_table + 4*irq) /* eax = (*irq_table[irq])(irq) */;\
pop ecx ;\
cli /* disable interrupts */;\
test eax, eax /* need to reenable irq? */;\
jz 0f ;\
inb INT_CTLMASK ;\
andb al, ~[1<<irq] ;\
outb INT_CTLMASK /* enable the irq */;\
0: ret /* restart (another) process */
;==============================我又是分割线 ==================================;
;上面是8259A主片的宏
;==============================还是我 ==================================;
?????????????????????????
>>本人有一点很不明白百思不得其解,为什么只设置了一个(_k_reenter),来防止中断重入,试想一下,要是我先是键盘中断产生了,键盘程序没处理完,这时候时钟中断发生,因为键盘中断没处理完,那么(_k_reenter) 没有 减1,时钟这时候CMP (_k_reenter),0是不成立的,时钟ISR不能执行,这真的是滑天下之大稽了,难道他写的时候没发现这个有问题吗?还是我脑子进水了?
...全文
相关推荐
minix源代码完整版
这个源代码完整版包含了约28000行的源代码,是操作系统学习者深入了解OS内核工作原理的宝贵资料。下面我们将详细探讨Minix系统的一些关键知识点。1.
MINIX3内核分析文档(纯原创)
- **2.6 MINIX3其部件处理中断举例**:通过具体的代码示例,展示了MINIX3是如何处理不同类型的中断事件的。
Minix源代码
这是为了防止头文件被多次包含而造成的问题。 - 行 `00023` 到 `00025` 检查编译器是否声明支持标准 C(`__STDC__`)。
Minix3源码解读报告
此外,它通过设置定时器,能够防止单一进程长时间占用CPU,确保系统具有良好的响应性和交互性。
MINIX3 源代码 操作系统
**内存管理**:MINIX3如何分配、回收内存,以及如何防止内存泄漏和确保内存安全,这些都是通过源码可以深入理解的部分。4.


