I wrote a beep function for my simple 64-bits OS and works well. but as I call it , "Double Fault Exception" occur.
this is my beep function code:
Code: Select all
; AX : Frequency
; BX : Lentgh
Beep:
push rbx
push rax
mov al,0xff
out 0x21,al ; Disable IRQ0
mov al,PIT_M_SW|PIT_RWF|PIT_T2
out 0x43,al
pop rax
mov bx,ax
mov eax,PIT_BF/2
mov edx,eax
and edx,0xFFFF0000
shr edx,16
div bx
push ax
out 0x42,al
mov al,ah
out 0x42,al
xor rax,rax
in al,0x61
or al,3
out 0x61,al
pop ax
pop rbx
mul bx
xor ebx,ebx
and eax,0xFFFF
mov ebx,eax
and edx,0xFFFF
shl edx,16
or ebx,edx
_b0:
in al,0x61
and al,1<<5
jz _b0
dec ebx
jnz _b0
in al,0x61
and al,0xFE
out 0x61,al
xor al,al
out 0x21,al ; Enable IRQ0
ret
thanks in advance.