Message board for the users of flat assembler.
> OS Construction > Input/Output And Device Drivers
I'm quite intermediate with Operating System programming, but there was always one thing that hindered me, one thing I never understood. I always knew it would pop up eventually, but I hoped to evade it and find some good documentations on the subject at hand before coming and posting here (I usually found my previous answers by guesting here <.<)
That one thing being writing a device driver to go alongside my kernel, allowing me to initiate use of things such as the Mouse, Ethernet Card, USB Storage, Speakers etc...
I understand how the devices work, by using I/O on their respective I/O Ports, but I just dont understand what you send to the ports and/or do with the ports in order to achieve functionality of these devices =\
I am using FASM along with Emu8086, so Input and Output can be achieved using IN and OUT registers, I know, but yea...
If I'm not making it clear enough, just say so, I'll try and explain more <.<
|21 Jul 2007, 18:27||
ok i'll try to reply
in digital electronics the only one language is 1 or 0 ,
every card has inside electronic chip that you program with
signal that perform something....
i have this string of bit 0000 ( 4 zero )
if you apply this to ALU ( Arithmetic and Logic Unit ) says that perform
addition,now if we intend to do subtraction ,can expand our circuit
and add our ALU another control signal and therefore one bit
ok now we have 2 function
when you program card you set this bit and send to register
|21 Jul 2007, 18:49||
Ok, yea, so I'm guessing you'd send that to the device like so:
mov ax, 0110000001000111b
out 4, ax
Which would send 0110000001000111 to the device located on IO Port 4...
But how/where would I find out what bit does what to the device? For example, I know there's something you do to retrieve the mouse position and stuff, but I cant find documentations on the bits or anything
|21 Jul 2007, 19:39||
you must learn datasheet of your device...but not always manufacturer
release free document ,sometimes you must pay ,sometimes are secret see ATI
sometimes you'll find on this forum ( read FAQ ) sometimes on google ,sometimes you can ask to people of forum .....
|21 Jul 2007, 20:39||
Heres a basic guide to making a FM801 sound card driver, all gather round.
Step 1. First you write a function to read PCI , we will start with dos .
;===============================================================; 8/16/32bit PCI reader;; Entry: EAX=PCI Bus/Device/fn/register number; BIT30 set if 32 bit access requested; BIT29 set if 16 bit access requested; otherwise defaults to 8bit read;; Exit: DL,DX,EDX register data depending on requested read size;; Note: this routine is meant to be called via pciRegRead8, pciRegread16,; or pciRegRead32, listed below.;; Note2: don't attempt to read 32bits of data from a non dword aligned reg; number. Likewise, don't do 16bit reads from non word aligned reg #;BIT30 EQU 40000000hBIT31 EQU 80000000hPCI_INDEX_PORT EQU 0CF8hPCI_DATA_PORT EQU 0CFChPCI32 EQU BIT31 ; bitflag to signal 32bit accessPCI16 EQU BIT30 ; bitflag for 16bit accessVIA_VID equ 1319h ; VIAPCI vendor IDVIA_DID equ 0801h ; VIA device IDpciRegRead: push ebx push cx mov ebx, eax ; save eax, dh mov cl, dh and eax, NOT PCI32+PCI16 ; clear out data size request or eax, BIT31 ; make a PCI access request and al, NOT 3 ; force index to be dword mov dx, PCI_INDEX_PORT out dx, eax ; write PCI selector mov dx, PCI_DATA_PORT mov al, bl and al, 3 ; figure out which port to add dl, al ; read to in eax, dx ; do 32bit read test ebx, PCI32 jz @f mov edx, eax ; return 32bits of data@@: mov dx, ax ; return 16bits of data test ebx, PCI32+PCI16 jnz @f mov dh, cl ; restore dh for 8 bit read@@: mov eax, ebx ; restore eax and eax, NOT PCI32+PCI16 ; clear out data size request pop cx pop ebx retpciRegRead8: and eax, NOT PCI16+PCI32 ; set up 8 bit read size jmp pciRegRead ; call generic PCI accesspciRegRead16: and eax, NOT PCI16+PCI32 ; set up 16 bit read size or eax, PCI16 ; call generic PCI access jmp pciRegReadpciRegRead32: and eax, NOT PCI16+PCI32 ; set up 32 bit read size or eax, PCI32 ; call generic PCI access jmp pciRegRead
Step 2. we fill in the vendor id and device id to see it is on the pc, to do that we need a function to scan through pci space to look for vendor+device id like this.
;===============================================================; PCIFindDevice: scan through PCI space looking for a device+vendor ID;; Entry: EAX=Device+vendor ID;; Exit: EAX=PCI address if device found; CY clear if found, set if not found. EAX invalid if CY set.;; [old stackless] Destroys: ebx, edx, esi, edi, cl;pciFindDevice: push cx push edx push esi push edi mov esi, eax ; save off vend+device ID mov edi, (80000000h - 100h) ; start with bus 0, dev 0 func 0nextPCIdevice: add edi, 100h cmp edi, 80fff800h ; scanned all devices? stc jz PCIscanExit ; not found mov eax, edi ; read PCI registers call pciRegRead32 cmp edx, esi ; found device? jnz nextPCIDevice clcPCIScanExit: pushf mov eax, edi ; return found PCI address and eax, NOT BIT31 ; return only bus/dev/fn # popf pop edi pop esi pop edx pop cx retEnd
Step 3. we need to put it together and call the above functions.
mov eax, (VIA_DID shl 16) + VIA_VID call pciFindDevice jnc @f; couldn't find the audio device! lea dx, noVIAMsg mov ah, 9 int 21h jmp $ ; if run from dos replace this with, the normal dos returnnoVIAMsg db "Error: Unable to find FM801 audio device!",CR,LF,"$"VIAMsg db "Found FM801 audio device!",CR,LF,"$"@@: lea dx, VIAMsg mov ah, 9 int 21h jmp $ ; if run from dos replace this with, the normal dos return
Step 4. put the above code in to a com file (adding org 100h, etc) and boot it from dos, MiniDos or bootprog you can get it here: http://alexfru.chat.ru/epm.html
Print one message for found and one for not found.
Note: It returns PCI address of device, if device found, and togeather with info you can find in here:
see page 18 in the manual, is how you write a driver.
Your should find the info you need on vendor/device ID here.
Step 5. well i think that enough for now, tune in for the next installment of basic sound card basics, only joking i do not want to bore you.
|22 Jul 2007, 02:08||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.