Code: Select all
send_verb_respond:
mov [edi],word 2
mov [edi-8],eax
mov [edi],word 1
wait2:
mov dx,[edi]
and dl,3
cmp dl,2
jnz wait2
mov edx,[edi-4]
test edx,edx
ret
send_verb:
mov [edi-8],eax
mov [edi],word 1
wait1:
test [edi],byte 1
jnz wait1
ret
start: ; edi -> HDA register base address + 0x68
xor eax,eax
inc eax
mov [edi-0x60],eax
wait:
test byte [edi-0x60],1 ;Controller is in operational state
jz wait
dec eax
mov [edi-0x48],eax ;All interrupts are disabled
mov [edi+8],eax ;disable DMA position buffer
mov [edi-0x34],eax ;Stream Synchronization
mov [edi-0x30],eax ; Stream Synchronization
mov [edi-0x1c],eax ;CORB is stopped
mov [edi-0xc],eax ;RIRB is stopped
mov eax,0xf00f0000
find_codec:
add eax,0x10000000
call send_verb_respond
jz find_codec
cmp edx,-1
jz find_codec
mov al,4 ;get node count
call send_verb_respond
jz find_codec
xor ecx,ecx
xchg cl,dl
shl edx,4
add eax,edx ;starting node number
mov al,9 ;Audio Widget Capabilities
find_node:
call send_verb_respond
and edx,0xf00000 ;is it an output widget?
jz node_found
node_not_valid:
add eax,0x100000
loop find_node
node_found:
mov al,0x12 ; Amplifier Capabilities
call send_verb_respond
jz node_not_valid
; get an appropriate volume value in al that is less than dl
xor eax,0xcb000 ;amplifier gain
call send_verb
mov al,0
xor eax,0x4b500 ;set power state in full power
call send_verb
xor ax,0x310 ;stream 1
call send_verb
xor eax,0x50601 ;16bits, 2 channels
call send_verb
mov eax,[edi-0x68]
movzx ebx,ah ;directy "movzx ebx,byte [edi-0x67]" would cause bl to be 0 in QEMU
shl bl,4
shl ebx,1
lea edi,[ebx+edi+0x18] ;edi -> stream 1 base address
mov [edi],byte 1 ;reset
wait3:
cmp [edi],byte 1
jnz wait3
mov [edi],byte 0
wait4:
cmp [edi],byte 0
jnz wait4
mov [edi+0x18],esp ; Lower Base Address of Buffer Descriptor List
xor eax,eax
mov [edi+0x1c],eax ;Upper Base Address of Buffer Descriptor List
mov al,3
mov [edi+0xc],eax ;Last Valid Index
mov al,0x11
mov [edi+0x12],ax ;16 bits and 2 channels as mentioned above
mov al,0x40
mov [edi+8],eax
mov [edi],dword 0x140002 ;launch
jmp $


