Audio driver programming - static address ========================================= With this example, you can write a static memory address driver, which greatly simplifies driver programming. You just need to check that driver address at rbp matches the assembled base address. Enable driver_development in config.mnt to load non-certified drivers. Audio driver parameters at config.mnt: audio_driver = Audio drivers filename audio_card_enable = 0/1 = disabled/enabled General driver steps: 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 request. Driver is executed at ring-0 privelidge level. If needed, set page non-cacheable with system call 400. Driver memory consists of two 2MB pages. First page for code and internal driver data, the second page for data communication between driver and device. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; PCI audio card driver for MenuetOS ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; driver_base equ (0x100000*56) use64 org driver_base db 'MENUET64' ; Header identifier dq 0x101 ; PCI audio card driver dq driver_entry-driver_base ; Driver entry dq image_end ; Size of image dq 0x100000*4 ; Required memory (max 4mb) 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 5,105,400 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cmp rbp , driver_base je addressfine mov [status],dword 0xff mov rax , 0xff ret addressfine: 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 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; If needed, set next 2M page non-cacheable with system call 400 ; for data transfer between driver and device. ; mov rax , 400 ; mov rbx , 1 ; mov rcx , driver_base+0x100000*2 ; call r14 ; syscall entry ; Success mov [status], dword 1 mov rax , 0 ret ; Fail mov [status],dword 0xff mov rbx , 0 mov rax , 1 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 ; ; See syscall 117 for parameters. ; ; Out: rax = 0 - Success ; 1 - Fail ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; add [outbytes], rcx mov rax , 0 ret audio_record: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description: Audio record functions ; ; See syscall 117 for parameters. ; ; Out: rax = 0 - Success ; 1 - Fail ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; add [inbytes], rcx mov rax , 0 ret ; ; Driver data ; parameter1: dq 0x0 parameter2: dq 0x0 ; ; Non-cacheable data between driver and device ; org (driver_base+0x100000*2) structure1: ; .. structure2: ; .. image_end: