The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: GoneFishing on July 03, 2013, 01:18:18 AM

Title: Port I/O
Post by: GoneFishing on July 03, 2013, 01:18:18 AM
Hello, DOS guys!

I'm a happy owner of a pair of older machines (Pentium I, Pentium III) and a pair of motherboards with CPUs and RAM on them. So I must make a use of all these toys  ;)

My idea is to make a bootable  floppy disk  with a kind of hardware testing utility on it. What I want to achieve is  to interact with every (if possible) microcontroller  on the motherboard .

I've already taught my floppy disk to say Hello to me. Now it's not enough. I want him to talk about those things hidden deep inside the hardware controllers. First of all I plan to read vendor/model/version info and output it to the screen.I will use only BIOS interrupts and real mode.

I know that PORT I/O is tricky and need some guidance.
Title: Re: Port I/O
Post by: MichaelW on July 03, 2013, 08:59:10 AM
You are probably going to need Ralf Brown's Interrupt List, an HTML version is  here (http://ctyme.com/rbrown.htm) and a downloadable version here (http://www.cs.cmu.edu/~ralf/files.html). The downloadable version includes an I/O port list.

Another good reference would be The Undocumented PC by Frank van Gilluwe.

What do you mean by vendor/model/version info?
Title: Re: Port I/O
Post by: GoneFishing on July 03, 2013, 07:02:40 PM
Quote from: MichaelW on July 03, 2013, 08:59:10 AM
You are probably going to need Ralf Brown's Interrupt List, an HTML version is  here (http://ctyme.com/rbrown.htm) and a downloadable version here (http://www.cs.cmu.edu/~ralf/files.html). The downloadable version includes an I/O port list.

Another good reference would be The Undocumented PC by Frank van Gilluwe.

What do you mean by vendor/model/version info?

Thank you for your help,  Michael.  It'll check those links.
I'll try to explain. Lets take a BIOS  for example.The  BIOS ROM chip (hardware)  has its own specs (i.e. manufacturer, model, physical capacity etc.) while BIOS  itself (firmware)  also has its own specifications.
First thing I want to do is to read this sort of info .

   

Title: Re: Port I/O
Post by: sinsi on July 03, 2013, 07:43:32 PM
A lot of that information is stored in tables in the ROM BIOS but the pointers usually point to memory >1MB, so no real mode.
Title: Re: Port I/O
Post by: MichaelW on July 03, 2013, 09:14:28 PM
For an application like this you can just switch to PM, load a selector with a 32-bit limit into an appropriate segment register (probably GS because it's unlikely to be used by the BIOS) then return to RM and access anywhere in address space with a segment override.
Title: Re: Port I/O
Post by: FORTRANS on July 03, 2013, 11:26:05 PM
Hi,

   You can search the old forum for boot sector code.  There was
some that used the bios to map the computer's memory.

   The process that MichaelW mentioned is sometimes called unreal
mode, big real mode, or flat real mode if you need to locate code.

HTH,

Steve N.
Title: Re: Port I/O
Post by: GoneFishing on July 04, 2013, 01:44:44 AM
Till today I believed there are only three CPU modes:real, protected and virtual real ones.
Thanks to MichaelW and FORTRANS for pointing  at new horizons!
Title: Re: Port I/O
Post by: Gunther on July 04, 2013, 06:01:06 AM
Hi vertograd,

Quote from: vertograd on July 04, 2013, 01:44:44 AM
Till today I believed there are only three CPU modes:real, protected and virtual real ones.
Thanks to MichaelW and FORTRANS for pointing  at new horizons!

it's not so new. But you should know that it'll work only under plain DOS; there's no chance to do it under modern OS with DOS emulations.

Gunther
Title: Re: Port I/O
Post by: GoneFishing on July 04, 2013, 09:45:05 PM
Quote from: Gunther on July 04, 2013, 06:01:06 AM
Hi vertograd,

Quote from: vertograd on July 04, 2013, 01:44:44 AM
Till today I believed there are only three CPU modes:real, protected and virtual real ones.
Thanks to MichaelW and FORTRANS for pointing  at new horizons!

it's not so new. But you should know that it'll work only under plain DOS; there's no chance to do it under modern OS with DOS emulations.

Gunther

Fortunately I have old box to play with. It'll be a  simple bootable floppy without any OS at all.
Title: Re: Port I/O
Post by: Gunther on July 04, 2013, 11:30:31 PM
Hi vertograd,

Quote from: vertograd on July 04, 2013, 09:45:05 PM
Fortunately I have old box to play with. It'll be a  simple bootable floppy without any OS at all.

so, that's the way to go. Good luck.

Gunther
Title: Re: Port I/O
Post by: GoneFishing on July 05, 2013, 01:01:29 AM
Thank you, Gunther!
Already digging in the old forum archives.
Title: Re: Port I/O
Post by: dedndave on July 05, 2013, 01:07:10 AM
never tried any of this in real mode,
but - the CPU is fairly easy to read - see CPUID
AMD and Intel have a number of related documents

for the other devices, like disk controllers, video cards, etc, you can look into the APIC identifiers
Title: Re: Port I/O
Post by: Gunther on July 05, 2013, 05:02:56 AM
Hi vertograd,

I've found an old 16 bit assembly language source for switching under DOS into flat mode. I think it was written 20 years ago for PowerBASIC. If you're interested, I can send it to you via mail. That shows at least the direction to go. Please send me a PM for the details.

Gunther
Title: Re: Port I/O
Post by: dedndave on July 05, 2013, 01:09:07 PM
that code may have been written for the 80286
a strange animal - and they played some strange tricks to make it go to protected mode

i seem to recall something like - you set the reset code address, then cause a triple fault - lol
Title: Re: Port I/O
Post by: GoneFishing on July 05, 2013, 05:40:16 PM
Quote
i seem to recall something like - you set the reset code address, then cause a triple fault - lol
Hi,Dave!
" ... a triple fault " does sound good  ;)
and thanks for the hint on APIC.
Title: Re: Port I/O
Post by: dedndave on July 05, 2013, 08:42:49 PM
http://en.wikipedia.org/wiki/Triple_fault (http://en.wikipedia.org/wiki/Triple_fault)

it was used to go from protected mode to real mode   :P
Title: Re: Port I/O
Post by: FORTRANS on July 05, 2013, 11:39:15 PM
Hi,

   I have collected a number of programs that set up a flat
mode segment register.  Here is a snippet from one of them.
It should be enough to track it down.

QuoteThis file was downloaded from

Programmers Heaven
http://www.programmersheaven.com

The Internet's most complete source of free downloadable programming files,
source codes, utilities, C/C++, Java, .NET, C#, and other tools for programmers

and developers. Here you will find over 10000 files and 4500 links organized
in an easy-to-find format.


  Inflating: FLAT.TXT  <to console>

FLAT REAL / REAL BIG / UNREAL MODE (v1.2)

Flat Real mode, Real Big mode and UnReal mode are three names with the very same
meaning, I will call it FLAT in this text.

   You could check the usenet groups comp.lang.asm.x86,
alt.lang.asm, or alt.os.development though you would have to
go way back in time I suppose.

Regards,

Steve
Title: Re: Port I/O
Post by: GoneFishing on July 06, 2013, 12:36:17 AM
Thank you all ,guys!
Now I need some time " to go way back in time "  ;)
There's so much to be read.

Dave: so triple fault may be useful in some cases?
http://en.wikipedia.org/wiki/Triple_fault :
QuoteHowever, intentionally triple-faulting the CPU was found to cause the transition to occur much faster and more cleanly, permitting multitasking operating systems to switch back and forth at high speed.
Title: Re: Port I/O
Post by: dedndave on July 06, 2013, 02:20:02 AM
80386 and newer were much better processors   :P
the 80286 was often refered to as "brain-dead"
Title: Re: Port I/O
Post by: FORTRANS on July 06, 2013, 02:43:21 AM
Hi,

   Yeah, the 80286 had real mode and 16-bit protected mode.  It
could switch from real mode to protected mode just fine.  After all
that was the whole point of the 80286, protected mode accessed
more than one megabyte of memory.  But most programs then
were real mode.  And the memory access circuit was different in
protected mode than in real mode.  And interrupt logic was also
different.  So to run most programs you had to be in real mode.
And Intel did not have a way for the 80286 to transition from
protected mode to real mode.  By making protected mode
incompatible with real mode, and not providing a way to restore
real mode, prompted the brain dead comment.  The PC/AT had
the keyboard controller reboot/reset the CPU.

   The 80386 had real mode, 16-bit protected mode, 32-bit
protected mode, and virtual 86 mode.  V86 allowed protected
mode to look like real mode to run real mode programs.  Ta da,
problems fixed, more or less.

Cheers,

Steve N.