Audio driver programming ======================== Set driver path/name for 'audio_driver' at Config.mnt. Parameters at config.mnt: audio_driver = audio driver path/name audio_card_enable = 0/1 - audio card disabled/enabled 1) Kernel loads driver (config.mnt 'audio_driver') 2) Kernel scans PCI for matching device ID's from drivers header. 3) If a match is found, kernel executes driver_entry functions 1 and 2. 4) Kernel calls play and record functions at application requests. Memory references within the driver: ; Relative mov [testaddr] , rax ; Absolute mov rdi , testaddr add rdi , rbp ; rbp = Driver base address. Set by OS. mov [rdi], rax testaddr: dq 0x0 Driver is executed at ring-0 privelidge level. If needed, set page uncacheable with system call 400. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; PCI audio card driver for MenuetOS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; use64 db 'MENUET64' ; Header identifier dq 0x101 ; PCI audio card driver dq driver_entry ; Driver entry dq IMAGE_END ; Size of image dq 0x20000 ; Required memory dd 0x11223344 ; Supported PCI card 1 dd 0xAABBCCDD ; Supported PCI card 2, .. dd 0x00000000 ; End db "Audio card",0 ; Device type db "Newco",0 ; Manufacturer inbytes: dq 0x0 ; Received bytes outbytes: dq 0x0 ; Sent bytes status: dq 0x0 ; 0x00 = driver not initialized ; 0x01 = device is working properly ; 0xff = undefined error driver_entry: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Driver entry from OS ; ; In : rax - function ; rbp - driver physical memory address ; r10 - card IO port base ; r13 - PCI position [pci_bus] shl 16 + [pci_dev] shl 8 ; r14 - Entry point for drivers internal system calls ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cmp rax , 1 je audio_probe cmp rax , 2 je audio_reset cmp rax , 3 je audio_play cmp rax , 4 je audio_record mov rax , 0xff ; function not supported ret audio_probe: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Verify search ; ; Out: rax = 0 - Success ; 1 - Fail ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov [status], dword 1 mov rax , 0 ret audio_reset: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Reset PCI audio card ; ; Out: rax = 0 - Success ; 1 - Fail ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov [status],dword 1 mov rax , 0 ret audio_play: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Audio out functions ; ; In : rbx,rcx,rdx,rex - See syscall.txt, function 117 ; ; Out: rax = 0 - Success ; 1 - Failed ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; add [outbytes], rcx mov rax , 0 ret audio_record: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description : Record functions - not yet implemented ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; add [inbytes], rcx mov rax , 0 ret