fix SB16 driver broken in r3727, convert to PE

git-svn-id: svn://kolibrios.org@5057 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2014-08-25 09:49:27 +00:00
parent 0ede580d2f
commit 727d1c9b53
11 changed files with 111 additions and 107 deletions

View File

@ -131,7 +131,6 @@ FASM_PROGRAMS:=\
drivers/emu10k1x.obj:DRIVERS/EMU10K1X.OBJ:$(KERNEL)/drivers/emu10k1x.asm \
drivers/fm801.obj:DRIVERS/FM801.OBJ:$(KERNEL)/drivers/fm801.asm \
drivers/infinity.obj:DRIVERS/INFINITY.OBJ:$(KERNEL)/drivers/infinity.asm \
drivers/sb16.obj:DRIVERS/SB16.OBJ:$(KERNEL)/drivers/sb16/sb16.asm \
drivers/sound.obj:DRIVERS/SOUND.OBJ:$(KERNEL)/drivers/sound.asm \
drivers/intelac97.obj:DRIVERS/INTELAC97.OBJ:$(KERNEL)/drivers/intelac97.asm \
drivers/vt823x.obj:DRIVERS/VT823X.OBJ:$(KERNEL)/drivers/vt823x.asm \
@ -230,6 +229,7 @@ FASM_PROGRAMS_PESTRIP:=\
drivers/ps2mouse.sys:DRIVERS/PS2MOUSE.SYS:$(REPOSITORY)/drivers/mouse/ps2mouse4d/trunk/ps2mouse.asm \
drivers/tmpdisk.sys:DRIVERS/TMPDISK.SYS:$(REPOSITORY)/drivers/disk/tmpdisk.asm \
drivers/intel_hda.sys:DRIVERS/intel_hda.sys:$(REPOSITORY)/drivers/audio/intel_hda/intel_hda.asm \
drivers/sb16.sys:DRIVERS/SB16.SYS:$(REPOSITORY)/drivers/audio/sb16/sb16.asm \
# end of list
# The list of all FASM programs with one main FASM file for CD image.
# Format of an item is exactly the same as in the previous list.

View File

@ -12,18 +12,6 @@ use_cli_sti equ 1 ;driver become more stable (theoretically)
;constants--------------------------------------------------------
API_VERSION equ 0 ;debug
OS_BASE equ 0x80000000
new_app_base equ 0x0
PROC_BASE equ (OS_BASE+0x080000)
SB16Buffer equ (OS_BASE+0x2A0000)
SB16_Status equ (OS_BASE+0x2B0000)
DMAPage equ ((SB16Buffer-OS_BASE) shr 16)
SB16Buffer0 equ SB16Buffer
SB16Buffer1 equ (SB16Buffer+16384)
SB16Buffer2 equ (SB16Buffer+(2*16384))
SB16Buffer3 equ (SB16Buffer+(3*16384))
sb_irq_num equ 5 ;default values for SB16, may be overrided by autodetect
sb_dma_num equ 5 ;default values for SB16, may be overrided by autodetect

View File

@ -17,7 +17,7 @@ sb_set_dma:
.dma_setup_error:
if DEBUG
mov esi, msgErrDMAsetup
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
mov dword[esp], START.stop
ret
@ -33,16 +33,20 @@ end if
lea eax, [ebx+0x58];auto-init mode for channel (ebx)
out 0xB, al;DMA channel 0-3 mode register
mov eax, [SB16Buffer]
invoke GetPhysAddr
mov ecx, eax
shr eax, 16
movzx edx, byte[ebx+dma_table];page register
mov al, DMAPage
out dx, al
lea edx, [ebx*2];DMA channel 0-3 base address
mov al, 0;LSB is 0
mov al, cl;LSB
out dx, al
; mov al,0 ;MSB is 0 too
mov al, ch;MSB
out dx, al
inc edx ;DMA channel 0-3 byte count
@ -78,16 +82,21 @@ end if
lea eax, [ebx+0x58];auto-init mode for channel (ebx+4)
out 0xD6, al;DMA channel 4-7 mode register
mov eax, [SB16Buffer]
invoke GetPhysAddr
mov ecx, eax
shr eax, 16
shr ecx, 1 ; 16-bit DMA takes offset in words
movzx edx, byte[ebx+dma_table+4];page register
mov al, DMAPage
out dx, al
lea edx, [ebx*4+0xC0];DMA channel 4-7 base address
mov al, 0;LSB is 0 ;for 16bit DMA this contains
mov al, cl;LSB;for 16bit DMA this contains
out dx, al;A1-A8 lines of address bus, A0 is zero
; mov al,0 ;MSB is 0 too ;for 16bit DMA this contains
mov al, ch;MSB;for 16bit DMA this contains
out dx, al;A9-A16 lines of address bus
inc edx

View File

@ -1,49 +1,32 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format MS COFF
format PE DLL native 0.05
entry START
include 'CONFIG.INC'
;structs----------------------------------------------------------
struc IOCTL
{ .handle dd ?
.io_code dd ?
.input dd ?
.inp_size dd ?
.output dd ?
.out_size dd ?
}
virtual at 0
IOCTL IOCTL
end virtual
;something--------------------------------------------------------
public START
public service_proc
public version
include '..\proc32.inc'
include '..\imports.inc'
section '.flat' code readable align 16
section '.flat' code readable writable executable
include '..\..\struct.inc'
include '..\..\macros.inc'
include '..\..\proc32.inc'
include '..\..\peimport.inc'
include 'SB16.INC'
;-------------------------------------------------------------------------------
proc START stdcall, state:dword
proc START c uses ebx esi edi, state:dword, cmdline:dword
cmp [state], 1
jne .stop
.entry:
if DEBUG
mov esi, msgInit
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
call detect ;returns DSP version or zero if
@ -64,35 +47,39 @@ if DEBUG
mov dword[esi], '16 '
.sb_say_about_found_dsp:
mov esi, msgDSPFound
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
xor ebx, ebx
mov ecx, [sb_base_port]
lea edx, [ecx+0xF]
call ReservePortArea ;these ports must be mine !
invoke ReservePortArea ;these ports must be mine !
dec eax
jnz @f
if DEBUG
mov esi, msgErrRsrvPorts
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
jmp .exit
@@:
invoke AllocDMA24, sb_buffer_size
test eax, eax
jz .exit
mov [SB16Buffer], eax
call sb_setup ;clock it, etc
stdcall AttachIntHandler, sb_irq_num, sb_irq, 0
invoke AttachIntHandler, sb_irq_num, sb_irq, 0
if DEBUG
test eax, eax
jnz @f
mov esi, msgErrAtchIRQ
call SysMsgBoardStr
invoke SysMsgBoardStr
; stdcall GetIntHandler, sb_irq_num
; call SysMsgBoardNum
@ -100,9 +87,9 @@ if DEBUG
jmp .stop
@@:
mov esi, msgSucAtchIRQ
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
stdcall RegService, my_service, service_proc
invoke RegService, my_service, service_proc
ret
.stop:
call sb_reset
@ -110,7 +97,7 @@ end if
if DEBUG
mov esi, msgExit
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
xor eax, eax
@ -118,22 +105,14 @@ end if
endp
;-------------------------------------------------------------------------------
handle equ IOCTL.handle
io_code equ IOCTL.io_code
input equ IOCTL.input
inp_size equ IOCTL.inp_size
output equ IOCTL.output
out_size equ IOCTL.out_size
align 4
proc service_proc stdcall, ioctl:dword
proc service_proc stdcall uses ebx esi edi, ioctl:dword
mov edi, [ioctl]
mov eax, [edi+io_code]
mov eax, [edi+IOCTL.io_code]
cmp eax, SRV_GETVERSION
jne @F
mov eax, [edi+output]
cmp [edi+out_size], 4
mov eax, [edi+IOCTL.output]
cmp [edi+IOCTL.out_size], 4
jne .fail
mov [eax], dword API_VERSION
xor eax, eax
@ -143,7 +122,7 @@ proc service_proc stdcall, ioctl:dword
jne @f
if DEBUG
mov esi, msgPlay
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
call sb_stop ;to play smth new we must stop smth old
@ -171,9 +150,9 @@ end if
jne @f
if DEBUG
mov esi, msgCallback
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
mov edi, [edi+input]
mov edi, [edi+IOCTL.input]
mov eax, [edi]
mov [callback], eax
if DEBUG
@ -188,9 +167,9 @@ end if
if DEBUG
mov esi, msgSetVol
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
mov eax, [edi+input]
mov eax, [edi+IOCTL.input]
mov eax, [eax]
call sb_set_master_vol
xor eax, eax
@ -200,9 +179,9 @@ end if
jne @F
if DEBUG
mov esi, msgGetVol
call SysMsgBoardStr
invoke SysMsgBoardStr
end if
mov eax, [edi+output]
mov eax, [edi+IOCTL.output]
mov edx, [sb_master_vol]
mov [eax], edx
xor eax, eax
@ -213,15 +192,7 @@ end if
ret
endp
restore handle
restore io_code
restore input
restore inp_size
restore output
restore out_size
;-------------------------------------------------------------------------------
align 4
proc sb_irq
mov edx, [sb_base_port];tell the DSP that we have processed IRQ
add dl, 0xF ;0xF for 16 bit sound, 0xE for 8 bit sound
@ -235,10 +206,15 @@ pre_fill_data:
jns .fill_second_half
if sb_buffer_size eq small_buffer
stdcall [callback], SB16Buffer0 ;for 32k buffer
mov eax, [SB16Buffer]
stdcall [callback], eax ;for 32k buffer
else if sb_buffer_size eq full_buffer
stdcall [callback], SB16Buffer0 ;for 64k buffer
stdcall [callback], SB16Buffer1 ;for 64k buffer
mov eax, [SB16Buffer]
push eax
stdcall [callback], eax ;for 64k buffer
pop eax
add eax, 16384
stdcall [callback], eax ;for 64k buffer
end if
xor eax, eax
not eax
@ -246,10 +222,17 @@ end if
.fill_second_half:
if sb_buffer_size eq small_buffer
stdcall [callback], SB16Buffer1 ;for 32k buffer
mov eax, [SB16Buffer]
add eax, 16384
stdcall [callback], eax ;for 32k buffer
else if sb_buffer_size eq full_buffer
stdcall [callback], SB16Buffer2 ;for 64k buffer
stdcall [callback], SB16Buffer3 ;for 64k buffer
mov eax, [SB16Buffer]
add eax, 32768
push eax
stdcall [callback], eax ;for 64k buffer
pop eax
add eax, 16384
stdcall [callback], eax ;for 64k buffer
end if
xor eax, eax
not eax
@ -337,13 +320,12 @@ proc SysMsgBoardNum ;warning: destroys eax,ebx,ecx,esi
shr ebx, 4
loop .1
dec esi
call SysMsgBoardStr
invoke SysMsgBoardStr
ret
endp
end if
;all initialized data place here
align 4
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
sb_base_port:
dd 200h ;don't ask me why - see the code&docs
@ -384,10 +366,12 @@ sb_DSP_description:
;-------------------------------------------------------------------------------
end if
section '.data' data readable writable align 16
;all uninitialized data place here
align 4
data fixups
end data
;pTempBuf rd 1
align 4
SB16Buffer rd 1
callback rd 1

View File

@ -96,6 +96,7 @@ import core,\
Kmalloc,\
Kfree,\
CreateRingBuffer,\
AllocDMA24,\
\
GetPid,\
CreateThread,\

View File

@ -22,11 +22,6 @@ ramdisk_functions:
.size = $ - ramdisk_functions
endg
; See memmap.inc.
; Currently size of memory allocated for the ramdisk is fixed.
; This should be revisited when/if memory map would become more dynamic.
RAMDISK_CAPACITY = 2880 ; in sectors
iglobal
align 4
ramdisk_actual_size dd RAMDISK_CAPACITY

View File

@ -228,10 +228,6 @@ VGABasePtr equ (OS_BASE+0x00A0000)
CLEAN_ZONE equ (_CLEAN_ZONE-OS_BASE)
IDE_DMA equ (_IDE_DMA-OS_BASE)
; unused?
SB16Buffer equ (OS_BASE+0x02A0000)
SB16_Status equ (OS_BASE+0x02B0000)
UPPER_KERNEL_PAGES equ (OS_BASE+0x0400000)
virtual at (OS_BASE+0x05FFF80)

View File

@ -48,6 +48,7 @@ __exports:
get_phys_addr, 'GetPhysAddr', \ ; eax
map_space, 'MapSpace', \
release_pages, 'ReleasePages', \
alloc_dma24, 'AllocDMA24', \ ; stdcall
\
mutex_init, 'MutexInit', \ ; gcc fastcall
mutex_lock, 'MutexLock', \ ; gcc fastcall

View File

@ -350,6 +350,31 @@ proc map_page_table stdcall, lin_addr:dword, phis_addr:dword
ret
endp
uglobal
sb16_buffer_allocated db 0
endg
; Allocates [.size] bytes so that the target memory block
; is inside one 64K page for 24-bit DMA controller,
; that is, somewhere between 00xx0000h and 00xxFFFFh.
proc alloc_dma24
; Implementation note.
; The only user of that function is SB16 driver,
; so just return a statically allocated buffer.
virtual at esp
dd ? ; return address
.size dd ?
end virtual
cmp [sb16_buffer_allocated], 0
jnz .fail
inc [sb16_buffer_allocated]
mov eax, SB16Buffer
ret 4
.fail:
xor eax, eax
ret 4
endp
; Allocates a physical page for master page table
; that duplicates first Mb of OS_BASE at address 0;
; used for starting APs and for shutting down,

View File

@ -523,16 +523,21 @@ end if
org (OS_BASE+0x0100000)
RAMDISK: rb 2880*512
rb 2856*4 ; not used
; Currently size of memory allocated for the ramdisk is fixed.
; This should be revisited when/if memory map would become more dynamic.
RAMDISK_CAPACITY = 2880 ; in sectors
RAMDISK: rb RAMDISK_CAPACITY*512
_CLEAN_ZONE:
BgrAuxTable rb 32768
align 65536
SB16Buffer rb 65536
align 4096
_IDE_DMA rb 16*512
BgrAuxTable rb 32768
BUTTON_INFO rb 64*1024
RESERVED_PORTS: rb 64*1024
FLOPPY_BUFF: rb 18*512 ;one track
sys_pgmap: rb 1024*1024/8