Re: Dos2Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 05, 2001 at 10:19:05AM +0200, Bart Vandewoestyne wrote:
> I'm having the following DOS-code that I want to port to linux:
> 
> static union {
>   unsigned int *a;      // One 32 bits address
>   unsigned long  l;     // One 32 bits long
>   unsigned int w[2];    // Two 16 bits words
>   unsigned char  b[4];  // Four 8 bits bytes
> } DMAaddr;
> 
> ...
> static void setadr( unsigned int far *buff, unsigned int length )
> {
>   unsigned int lw;
> 
>   lw = FP_SEG( buff );                // Segment address of buffer
>   DMAaddr.w[1] = ( lw >> 12 ) & 0xf;    // Makes real 32bit address
>   DMAaddr.w[0] = ( lw << 4 ) & 0xfff0;
>   DMAaddr.l += ( unsigned long )FP_OFF( buff );
>   DMAcntr.w = length;
> }
> 
> How do i translate this?  Can I just leave the 'far' out?  And how do
> I replace the FP_SEG and FP_OFF things?

(/me digs up his DOS knowledge) DOS runs in the so called "real mode"
of the CPU, which basically means that the CPU is compatible with the
good old 8086 (talk about wasting silicon...).

Anyway, the 8086 uses a segmented memory model in which each address is
referenced by a segment and an offset within that segment. The segments
in real mode are overlapping, and you can compute the linear address
with:

  address =  segment * 16 + offset
  (or address = segment << 4 + offset)

The segment and offset are each 16 bit words, the address is a 20 bit
word (so the CPU could address 1MB).

To make life even more complicated, DOS binaries could use various
memory models:

- tiny: code and data in the same segment
- small: code and data each in a separate segment
- medium: code in a single segment, data can span multiple segments
- large: code and data can both span multiple segments
- huge: same as large, but there was something different

Pointers in the tiny and small memory models are called "near pointers"
because you only need the offset of the pointer within a segment. The
other memory models used so called "far pointers" which means that a
pointer contains a segment and an offset. To be able to specify what
kind of pointers you meant, the C language had the "near" and "far"
extensions.


Hope this helps,
Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux