Jump to content

Serial Port

- - - - -

  • Please log in to reply
11 replies to this topic

#1
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Hi, I've been trying to program for the serial ports, but I just can't seem to get it to work.

;Written in FASM


cli


mov dx,PORT+1

mov ax,0

out dx,ax


mov dx,PORT+3

mov ax,0x80

out dx,ax


mov dx,PORT+0

mov ax,0x03

out dx,ax


mov dx,PORT+1

mov ax,0

out dx,ax


mov dx,PORT+3

mov ax,3

out dx,ax


mov dx,PORT+2

mov ax,0xc7

out dx,ax


mov dx,PORT+4

mov ax,0x0b

out dx,ax


mov dx,PORT

mov ax,'H'

out dx,ax


halt:

hlt

jmp halt


PORT=0x3f8

I have been running it in VirtualBox. I set up the VM to log all serial port output to a text file, and the file is always blank afterward. Then, I set up the VM to open a pipe for I/O over that. I made a little program to read the pipe. The VM opens the pipe, but no data is put in it. These together make me think it is something wrong with the code. Can someone help?
Latinamne loqueris?

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
You're not setting the DLAB right; you need to read in the entire value and or it in, otherwise you're trashing whatever else is in the line control register.

Serial Ports - OSDev Wiki
sudo rm -rf /

#3
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Still doesn't work. My code is actually the same code as their example on that page, which is why I am so stumped as to why it doesn't work.
Latinamne loqueris?

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 761 posts
You may want to check first if your serial port address is really at 0x3f8. It can be changed through BIOS. So check your BIOS.

#5
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Yes, I am sure because I am running it in VirtualBox and have made sure that the port is set up att 0x3f8
Latinamne loqueris?

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I don't see sti in there anywhere.
sudo rm -rf /

#7
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
I didn't put an STI in there because I don't want to use interrupts for the serial port.
Latinamne loqueris?

#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
CLI followed by HLT at any point will make the processor hang indefinitely. CLI just disables external interrupts, not software interrupts you trigger yourself.
sudo rm -rf /

#9
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Well, that was the whole point of the HLT loop. And I know that CLI just disables external interrupts. I didn't want to deal with interrupts from the serial port controller or whatever it is called.
Latinamne loqueris?

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
I just noticed something...you should be writing bytes out the ports, not words
sudo rm -rf /

#11
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Oops LOL.... It works now. I wasn't really paying attention I guess. Thanks!
Latinamne loqueris?

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
No problem. :)
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users