flat assembler
Message board for the users of flat assembler.

Index > OS Construction > A serial port driver...

Author
Thread Post new topic Reply to topic
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 20 Sep 2004, 21:58
I recently wrote a serial port driver for my OS. This is pretty simple code, so I thought I'd share it so others can learn from it and maybe help find bugs in it. Smile

Code:
; Serial Port Driver
; Developed by Charles Childers and Christopher Brannon
; -----------------------------------------------------
; * Released into the public domain *
; -----------------------------------------------------
; Port Addresses
;  $3F8  =  COM1
;  $2F8  =  COM2
;  $3E8  =  COM3
;  $2E8  =  COM4
; -----------------------------------------------------
; Baud Rates
;  $01 = 115,200
;  $02 =  57,600
;  $03 =  38,400
;  $06 =  19,200
;  $0C =   9,600
;  $18 =   4,800
;  $30 =   2,400
; -----------------------------------------------------
port = $3f8     ; Default to COM1
baud = $03 ; Default to 38,400 baud

; al = byte to send
write_serial:                        ;
   mov dx, port + 5        ; LSR
       xchg ah, al             ;
.a:    in al, dx               ;
   test al, $20            ; Bit 5 of LSR is set when the
      jz .a                   ; transmit buffer is empty
  xchg ah, al             ;
   mov dx, port            ;
   out dx, al              ;
ret                                ;

init_serial:                       ;
   mov dx, port + 1        ; Turn off interrupts
       mov al, 0               ;
   out dx, al              ;
   mov al, $80             ; Turn DLAB on
      mov dx, port + 3        ;
   out dx, al              ;
   mov dx, port            ; Set baud rate
     mov al, baud            ; baud rate (38,400 is default)
     out dx, al              ;
   mov dx, port + 1        ; Set baud rate
     mov al, 0               ;
   out dx, al              ;
   mov dx, port + 3        ; 8 bits, no parity, 1 stop bit
     mov al, $03             ;
   out dx, al              ;
   mov dx, port + 4        ; Turn on DTR, RTS, and OUT2
        mov al, $0b             ;
   out dx, al              ;
   mov dx, port + 2        ; Enable FIFO
       mov al, $c7             ;
   out dx, al              ;
ret                                ;

; returns al = byte read
read_serial:                   ;
   xor eax, eax            ;
   mov dx, port + 5        ; LSR
.a:        in al, dx               ;
   test al, 1              ;
   jz .a                   ;
   mov dx, port            ;
   in al, dx               ;
ret                                ;    

_________________
Charles Childers, Programmer
Post 20 Sep 2004, 21:58
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 20 Sep 2004, 23:01
Thanks crc, can i use it in my OS ? .

\\\\||////
(@@)
ASHLEY4.
Post 20 Sep 2004, 23:01
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 21 Sep 2004, 11:04
Go ahead and use it any way you want. I only ask that you give credit to me and Christopher in the documentation somewhere.
Post 21 Sep 2004, 11:04
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 21 Sep 2004, 11:38
That goes with out saying, did you have any luck with vesa ?.

\\\\||////
(@@)
ASHLEY4.
Post 21 Sep 2004, 11:38
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 21 Sep 2004, 23:21
I've got a 640x480x256 linear mode working in a test program now, so I'm attempting to code a full driver right now. Smile
Post 21 Sep 2004, 23:21
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 22 Sep 2004, 01:16
I have code for that vesa mode for my OS, with fonts if you want it let me know.

ps: i am looking for people with a AC97 onboard sound ,to test a driver i am do for that chip, do you have one ?.

\\\\||////
(@@)
ASHLEY4.
Post 22 Sep 2004, 01:16
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 22 Sep 2004, 12:51
Sure, I'd love to see your VESA code. Anything that saves time is good. Smile

I'm sorry, but I don't have AC97 sound; I only have a rather oddly implemented ESS Maestro 3 in my laptop. (Odd because it shares some circuitry with the modem)
Post 22 Sep 2004, 12:51
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 23 Sep 2004, 01:00
Here is some simple lfb 640*480*256 vesa code, to get you started,let me know if you need more.
This code will be available on request.

\\\\||////
(@@)
ASHLEY4.


Last edited by ASHLEY4 on 28 Sep 2004, 14:15; edited 4 times in total
Post 23 Sep 2004, 01:00
View user's profile Send private message Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu 23 Sep 2004, 09:22
I've got a VIA AC'97 sound on board... send me the code and an instruction, how to use, and I'll test it!
email: look at my profile!
Post 23 Sep 2004, 09:22
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 24 Sep 2004, 20:52
crc, did you try the code ? .

\\\\||////
(@@)
ASHLEY4.
Post 24 Sep 2004, 20:52
View user's profile Send private message Reply with quote
joachim_neu



Joined: 22 Dec 2003
Posts: 139
joachim_neu 24 Sep 2004, 22:27
i don't understand, how to use it. what's the device ID?
Post 24 Sep 2004, 22:27
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 24 Sep 2004, 23:39
Here is a place you can get info on device id http://www.pcidatabase.com
Things like soundcards, graphic cards, modems etc. have number on there chips to identify them.
so if you want to know what sound card is on a pc you write to a address and it give's you a number, if the sound is made by say "intel Corporation" you would get back "0x8086", but intel make alot of chips, so you need to identify which one, so you write to another address to get that number and that number is called a device id.

\\\\||////
(@@)
ASHLEY4.
Post 24 Sep 2004, 23:39
View user's profile Send private message Reply with quote
Gomer73



Joined: 29 Nov 2003
Posts: 151
Gomer73 25 Sep 2004, 17:40
Thanks Ashley4, nice link.
Post 25 Sep 2004, 17:40
View user's profile Send private message Reply with quote
eet_1024



Joined: 22 Jul 2003
Posts: 59
eet_1024 27 Sep 2004, 09:22
The GNU <b>lspci</b> command, handily available on a BBC (www.lnx-bbc.com), usually can extract Make, Model, and other useful info on PCI entities.
Post 27 Sep 2004, 09:22
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 27 Sep 2004, 18:02
Gomer73, nice to know there are still people with manners Smile .

\\\\||////
(@@)
ASHLEY4.
Post 27 Sep 2004, 18:02
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 27 Sep 2004, 19:38
Ashley4, the code works; thank you! It will be very helpful as I work on this VESA driver.
Post 27 Sep 2004, 19:38
View user's profile Send private message Visit poster's website Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 28 Sep 2004, 11:20
I have VIA AC'97... Smile
Post 28 Sep 2004, 11:20
View user's profile Send private message Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 28 Sep 2004, 12:11
Glad it works crc,
bubach, the driver for the ac97 works on all intel made chips (eg: ICH0, ICH1, ICH2, ICH3, ICH4 ) and some others.
but not on via like(eg: vt82c686).
So if you have any of the above, other than the ( vt82c686) or a differant model, let me know, so you can test it.
All so, all the driver code will, use's is in/out, no OS dependent code will be used ( other than printing messages, which can be changed for your own) so will be easy converted for your own OS project.

\\\\||////
(@@)
ASHLEY4.
Post 28 Sep 2004, 12:11
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.