flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Input/Output And Device Drivers

Author
Thread Post new topic Reply to topic
Dark Dude



Joined: 21 Jul 2007
Posts: 6
Dark Dude
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 <.<
Post 21 Jul 2007, 18:27
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
ok i'll try to reply Wink
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....
example:
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
says 0001.
ok now we have 2 function
0000 addition
0001 subtraction
when you program card you set this bit and send to register Wink
Post 21 Jul 2007, 18:49
View user's profile Send private message Reply with quote
Dark Dude



Joined: 21 Jul 2007
Posts: 6
Dark Dude
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
Post 21 Jul 2007, 19:39
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
ok Wink
you must learn datasheet of your device...but not always manufacturer
release free document ,sometimes you must pay ,sometimes are secret Laughing see ATI
sometimes you'll find on this forum ( read FAQ ) sometimes on google ,sometimes you can ask to people of forum ..... Wink
Post 21 Jul 2007, 20:39
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
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 .
Code:
;===============================================================; 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.
Code:
;===============================================================; 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.
Code:
        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:
http://alsa.cybermirror.org/datasheets/forte_media/FM801-AU-Data.PDF
see page 18 in the manual, is how you write a driver.

Your should find the info you need on vendor/device ID here.
http://www.pcidatabase.com/#notice

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.
Post 22 Jul 2007, 02:08
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.