HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Michael Almqui » Sat, 22 Feb 1997 04:00:00



I've checked all the faqs and tried a variety of things and I'm stuck!

I have a program orginally written in Microsoft C that I'm trying to translate
to netBSD 1.1.  I suspect that the porting issues involved are very similar if
I was porting to either BSDi, freeBSD, 386BSD, etc.

The original program makes various calles to "outp", as in:

  outp(BOARD,0); /* disable the timer */

netBSD (and I suspect other 386 unix flavors) don't have a "outp" command.
Digging through a Microsoft C manual I find that "outp" writes a single byte
to a specified I/O port address and is of the form:

  int outp(unsigned port, int byte);

Digging further I read that "outp" is essentially mapped to the assembly
language instruction "OUT".  Grabbing my 386 assembler book I see that "OUT"
is defined as "write to port".  Ah ha!  I'm on the right track - it all fits
together!

However, I am quickly stumped when gcc complains about not understanding the
asm call to "out".  Digging through the netBSD source code I find
"include/pio.h" with asm code for "outb", "outw", and "outl".  Digging further
into the netBSD code I find NUMEROUS calls throughout the kernel code to
"outb", etc.

I get e*d and write/steal a simple little program:

#include <stdio.h>
#include <machine/pio.h>

/* from i8042reg.h */
#define KBCMDP          0x64    /* kbd controller port (O) */
#define KBC_PULSE0      0xfe    /* pulse output bit 0 */

main()
{
   /* from arch/i386/i386/machdep.c */
   /* Toggle the hardware reset line on the keyboard controller. */
   outb(KBCMDP, KBC_PULSE0);

Quote:}

The program compiles FINE but when I run it I get:
Program received signal SIGBUS (10), Bus error
0x178c in __outb (port=100, data=254 '~') at /usr/include/machine/pio.h:149
149             __asm __volatile("outb %0,%%dx" : : "a" (data), "d" (port));

Every single little program I write "outb (0xd6, 0xc1);" "outb(0x60,0xFF);"
etc crashes with the same error.

So I dig some more. I find microtime.s and use it as an example to write:

#include <machine/asm.h>
#include <dev/isa/isareg.h>
#include "/sys/arch/i386/isa/timerreg.h"

#define KBCMDP          0x64    /* kbd controller port (O) */
#define KBC_PULSE0      0xfe    /* pulse output bit 0 */

ENTRY(resetkbd)
        movb    $(KBCMDP),%al
        outb    %al,$KBC_PULSE0

It compiles fine with "cpp -DLOCORE kbd.s | as -o kbd.o".  I then write a
simple c program and link it to kbd.o:

#include <stdio.h>

main()
{
   resetkbd();

Quote:}

It compiles find.  And when I go to run it I get the same bus error!

PLEASE help me out!  I'm tearing my hair out and running out of ideas!  I know
it has to be possible for there is lots of similar code within the netBSD
kernel.  Any help would be greatly appreciated!  Thanks for reading my long
story of woe.


 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Andrew Giert » Sat, 22 Feb 1997 04:00:00


 [tale of woe elided]

It might help if you realise that arbitrary hardware I/O is not permitted
in user programs on Unix.

Most PC Unixes have facilities whereby access to I/O ports can be obtained
by sufficiently privileged processes, but the details of how to do this
vary between systems. Furthermore, if you access any hardware device that
the kernel knows about, you risk crashing your system, or worse.

Whether you can achieve what you are attempting without having to write a
device driver I can't tell, since you don't say anything about what the
program is actually doing.

--
Andrew.

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Stefan Perss » Sat, 22 Feb 1997 04:00:00




>PLEASE help me out!  I'm tearing my hair out and running out of ideas!  I know
>it has to be possible for there is lots of similar code within the netBSD
>kernel.  Any help would be greatly appreciated!  Thanks for reading my long
>story of woe.

I really only have experiences with Linux, but I suspect the same applies
to *BSD as well: The kernel may be doing lots of calls to outb, but the
thing is that user space programs are normally not allowed direct access
to physical io-ports.
Now for a solution: as I'm only familiar with how things work in Linux, I
am not sure how it's done under *BSD, but linux have two system calls named
ioperm() and iopl(), which let a program run as root gain the privileges
necessary for direct port access.
In Linux, those calls are used, among other things, by the X server in
order to control the video hardware. See if you can find some graphics
library that works with netBSD/386, there would probably be some useful code
there.

hope this helps!

/stefan

--
'The number of Unix installations has grown to ten, with more expected.'
     <Unix Programmer's Manual, 2nd ed.; june 1972>

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Ken Pizzin » Sat, 22 Feb 1997 04:00:00



: However, I am quickly stumped when gcc complains about not understanding the
: asm call to "out".  Digging through the netBSD source code I find
: "include/pio.h" with asm code for "outb", "outw", and "outl".  Digging further
: into the netBSD code I find NUMEROUS calls throughout the kernel code to
: "outb", etc.
...
: PLEASE help me out!  I'm tearing my hair out and running out of ideas!  I know
: it has to be possible for there is lots of similar code within the netBSD
: kernel.  Any help would be greatly appreciated!  Thanks for reading my long
: story of woe.

The problem is that the kernel runs in a priveleged processor
mode, and your programs run in a non-priveledged processor
mode which does not, by default, have permissions to do direct
port I/O (even if you are root).  I know that Linux provides
a special system call (available only to root) for gaining
direct port I/O permissions; I do not know if netBSD offers
such a thing or not.

                --Ken Pizzini

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Richard Scranto » Sun, 23 Feb 1997 04:00:00


Although this all sounds like a terrible idea to attempt under Unix,
you can probably accomplish it via the "/dev/io" facility.  It was
described recently by Joerg Wunsch in comp.unix.*.freebsd in response
to a similar request.  Check DejaNews.  Are you sure you want to do
this?


> I've checked all the faqs and tried a variety of things and I'm stuck!

> I have a program orginally written in Microsoft C that I'm trying to translate
> to netBSD 1.1.  I suspect that the porting issues involved are very similar if
> I was porting to either BSDi, freeBSD, 386BSD, etc.

> The original program makes various calles to "outp", as in:

>   outp(BOARD,0); /* disable the timer */

> netBSD (and I suspect other 386 unix flavors) don't have a "outp" command.
> Digging through a Microsoft C manual I find that "outp" writes a single byte
> to a specified I/O port address and is of the form:

>   int outp(unsigned port, int byte);

> Digging further I read that "outp" is essentially mapped to the assembly
> language instruction "OUT".  Grabbing my 386 assembler book I see that "OUT"
> is defined as "write to port".  Ah ha!  I'm on the right track - it all fits
> together!

> However, I am quickly stumped when gcc complains about not understanding the
> asm call to "out".  Digging through the netBSD source code I find
> "include/pio.h" with asm code for "outb", "outw", and "outl".  Digging further
> into the netBSD code I find NUMEROUS calls throughout the kernel code to
> "outb", etc.

> I get e*d and write/steal a simple little program:

> #include <stdio.h>
> #include <machine/pio.h>

> /* from i8042reg.h */
> #define KBCMDP          0x64    /* kbd controller port (O) */
> #define KBC_PULSE0      0xfe    /* pulse output bit 0 */

> main()
> {
>    /* from arch/i386/i386/machdep.c */
>    /* Toggle the hardware reset line on the keyboard controller. */
>    outb(KBCMDP, KBC_PULSE0);

> }

> The program compiles FINE but when I run it I get:
> Program received signal SIGBUS (10), Bus error
> 0x178c in __outb (port=100, data=254 '~') at /usr/include/machine/pio.h:149
> 149             __asm __volatile("outb %0,%%dx" : : "a" (data), "d" (port));

> Every single little program I write "outb (0xd6, 0xc1);" "outb(0x60,0xFF);"
> etc crashes with the same error.

> So I dig some more. I find microtime.s and use it as an example to write:

> #include <machine/asm.h>
> #include <dev/isa/isareg.h>
> #include "/sys/arch/i386/isa/timerreg.h"

> #define KBCMDP          0x64    /* kbd controller port (O) */
> #define KBC_PULSE0      0xfe    /* pulse output bit 0 */

> ENTRY(resetkbd)
>         movb    $(KBCMDP),%al
>         outb    %al,$KBC_PULSE0

> It compiles fine with "cpp -DLOCORE kbd.s | as -o kbd.o".  I then write a
> simple c program and link it to kbd.o:

> #include <stdio.h>

> main()
> {
>    resetkbd();
> }

> It compiles find.  And when I go to run it I get the same bus error!

> PLEASE help me out!  I'm tearing my hair out and running out of ideas!  I know
> it has to be possible for there is lots of similar code within the netBSD
> kernel.  Any help would be greatly appreciated!  Thanks for reading my long
> story of woe.



--
========================================================================
Richard Scranton - LDA Systems, Columbus

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Mark Lazarawie » Wed, 26 Feb 1997 04:00:00


<On 25 Feb 1997 17:00:22 GMT, in an article from comp.lang.c, you wrote:
) Hello this unix program uses the following format

)      sort <file.srec >sorted.srec

) Could anyone convert this to run in DOS

<What, EXACTLY, is the problem? You don't say.

Hello

As far as I know dos does not support the < operator.Unix will use

sort <file.srec >sorted.srec

and take file.srec input and  sort in ascending order and write to sorted.srec

I know nothing about file operations and don't care to. I need someone

who programs c in unix and dos to add two args(infile and outfile) to

main() as I beleive dos requires and modify the c file function calls

so this works in dos.The version I attached works fine on a unix box

but crashes on borlandc compiled for dos.

If you supply file.in as input you should get file.out as output
These are motorolla srecord and i need the 4 column for a length of
6 digits sorted in ascendind order.The provided program does this fine for
unix.I need the file operations modified.

Thanks for responding

file.in

S0030000FC
<encoded_portion_removed>

file.out

S0030000FC
<encoded_portion_removed>

) #include "stdio.h"

) #ifdef DEBUG
) #define DBP(x,y) printf((x),(y))
) #else
) #define DBP
) #endif

) #define MAXLINE       0x50            /* input array dim      */
) #define MALLOC_E      (-1)            /* fior exit()          */
) #define NNULL                 (NODE*)0        /* for pointer init     */

) #define SUCCESS               (0)
) #define FAIL          (-1)

) typedef unsigned  char UCHAR;         /* unsigned  8 bits     */
) typedef unsigned short USHRT;         /* unsigned 16 bits     */
) typedef unsigned  long ULONG;         /* unsigned 32 bits     */

) /* the S-record list is made up of these */
) typedef struct node {
)             ULONG address;
)              char *record;
)       struct node *last;
)       struct node *next;
) }NODE;

) ULONG genAddress();

) int main()
) {

)   NODE *np;           /* pointer to the list  */
)   NODE *anchor=NNULL; /* anchor of the list   */
)   NODE *end;          /* end of the list      */

)   char *record;               /* reads in the line    */

)       for(record=(char*)malloc(MAXLINE);
)           (record!= (char *)NULL) && (fgets(record,MAXLINE,stdin)!=NULL);
)           record=(char*)malloc(MAXLINE)) {

)          if((np = (NODE *)malloc(sizeof(NODE))) == ((NODE*)NULL)) {
)               printf("Error: node malloc error\n");
)               exit(MALLOC_E);
)          }

)          /* only work on S1,S2 and S3 type records    */
)          if(!((record[1]=='1') ||
)                 (record[1]=='2') ||
)               (record[1]=='3'))) {
)               continue;
)            }

)          np->address = genAddress(record); /* Hex Ascii to long    */
)          np->record=record;                        /* link S-rec to node   */

)          insert(np,&anchor);                      /* insert node in list  */
)       }
)          
)       printList(anchor);              /* writes the new file          */

)       return SUCCESS;
) }

) /*
)  *******************************************************************************
)  * Function: ULONG genAddress(char *)
)  *
)  *    Input: pointer to a type S1,S2 or S3  S-record
)  *   Output: an unsigned long int
)  *******************************************************************************
) */

) ULONG genAddress(rec)
)       char *rec;
) {

)       ULONG             tmp=0L;       /* tmp to store address         */
)         int                 size;     /* depends on s-rec type        */
)        char                 *cur;     /* current ascii character      */
)        char                  adj;     /* ascii to int adjustment      */

)       /* switch on S-record type doesn't validate the S-record        */      

)       size = ((rec[1]-'0')*2)+2; /* sizes are 4,6,8 */

)       for(cur=rec+4;size>0;size--,cur++) {
)          switch(*cur){
)             case '0':
)             case '1':
)             case '2':
)             case '3':
)             case '4':
)             case '5':
)             case '6':
)             case '7':
)             case '8':
)             case '9':
)                   tmp = (tmp <<4 ) | ((0x0f)&((*cur) - '0'));
)                   break;

)             case 'a':
)             case 'b':
)             case 'c':
)             case 'd':
)             case 'e':
)             case 'f':
)                   tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'a' + 10));
)                   break;

)             case 'A':
)             case 'B':
)             case 'C':
)             case 'D':
)             case 'E':
)             case 'F':
)                   tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'A' + 10));
)                   break;

)             default:
)                   fprintf(stderr,"tmp=%lx ",tmp);
)                   fprintf(stderr,"*cur=<%c> ",*cur);
)                   fprintf(stderr,"rec=%s\n",rec);
)                   fprintf(stderr,"Add Error\n");
)                   return 0l;
)                   break;
)          }
)       }
)       return tmp;
) }

) /*
)  *******************************************************************************
)  * Function: int insert(NODE*,NODE*)
)  *
)  *    Input: pointer of the node to enter,
)  *         pointer to the base of the list
)  *   Output: SUCCESS or FAIL
)  *******************************************************************************
) */
) int insert(p,a)
)    NODE *p;
)    NODE **a;
) {

)    NODE *la;          /* local anchor         */
)    NODE *ln;          /* local node           */

)    ln = *a;  

)   if(ln == NNULL){    /* insert first entry */
)           *a = p;
)      p->next = NNULL;
)      p->last = NNULL;

)      return SUCCESS;
)   }

)   while(ln != NNULL){
)      if(ln->address >= p->address){
)        if(ln->last != NNULL) {
)          (ln->last)->next=p;
)          p->last=ln->last;
)          ln->last=p;
)          p->next=ln;
)          } else {
)            *a = p;
)            p->next = ln;
)            p->last = NNULL;
)          ln->last = p;
)        }      
)        return SUCCESS;
)      } else {
)        if(ln->next != NNULL) {
)           ln = ln->next;
)        } else {
)           ln->next = p;
)           p->last = ln;
)           p->next = NNULL;
)           return SUCCESS;
)        }
)      }
)        
)   }

)   return FAIL;

) }

) printList(p)
)    NODE *p;
) {
)      NODE *lp;                /* local pointer        */

)      for(lp=p;lp!=NNULL;lp=lp->next) {
)        printf("%s",lp->record);
)      }

) }

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by riot nrr » Wed, 26 Feb 1997 04:00:00



: As far as I know dos does not support the < operator.Unix will use

Wrong...DOS supports it nicely. Create some text file and try to
more < yourfile.txt

: ) #define MAXLINE     0x50            /* input array dim      */

You might need to add an extra byte here for the ^M

--
73 de Dave Weingart  KB2CWF                 "Can you find the Valium?


http://www.liii.com/~phydeaux                Baying at the Moon"
                                                   -- Hawkwind

BY SENDING UNSOLICTED, COMMERCIAL SPAM EMAIL TO THIS ADDRESS, YOU HEREBY
AGREE TO RECEIVE UP TO 20 MEGABYTES OF RANDOM CORE DUMP INFORMATION.

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Andrew Giert » Thu, 27 Feb 1997 04:00:00


[Followups narrowed. Bogus "Distribution: inet" removed.]

 Mark> The version I attached works fine on a unix box
 Mark> but crashes on borlandc compiled for dos.

So it's not our problem here in comp.unix.programmer, is it? Keep DOS's
brain damage in the DOS groups, thank you very much.

--
Andrew.

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Andy Eskilsso » Thu, 27 Feb 1997 04:00:00


Uhm there is a port of bash for dos, can be found at
http://www.delorie.com, in the djgpp distribution.

This shell allows the < 'operator'.

        /Andy

/ mlaza...@atm.dsccc.com (Mark Lazarawiecz) wrote:
| <On 25 Feb 1997 17:00:22 GMT, in an article from comp.lang.c, you wrote:
| ) Hello this unix program uses the following format
|
|
| )      sort <file.srec >sorted.srec
|
| ) Could anyone convert this to run in DOS
|
| <What, EXACTLY, is the problem? You don't say.
|
| Hello
|
| As far as I know dos does not support the < operator.Unix will use
|
| sort <file.srec >sorted.srec
|
| and take file.srec input and  sort in ascending order and write to sorted.srec
|
| I know nothing about file operations and don't care to. I need someone
|
| who programs c in unix and dos to add two args(infile and outfile) to
|
| main() as I beleive dos requires and modify the c file function calls
|
| so this works in dos.The version I attached works fine on a unix box
|
| but crashes on borlandc compiled for dos.
|
|
| If you supply file.in as input you should get file.out as output
| These are motorolla srecord and i need the 4 column for a length of
| 6 digits sorted in ascendind order.The provided program does this fine for
| unix.I need the file operations modified.
|
| Thanks for responding
|
|
| file.in
|
| S0030000FC
<encoded_portion_removed>
|
|
| file.out
|  
| S0030000FC
<encoded_portion_removed>
|
|
|
|
| ) #include "stdio.h"
|
| ) #ifdef DEBUG
| ) #define DBP(x,y) printf((x),(y))
| ) #else
| ) #define DBP
| ) #endif
|
| ) #define MAXLINE     0x50            /* input array dim      */
| ) #define MALLOC_E    (-1)            /* fior exit()          */
| ) #define NNULL               (NODE*)0        /* for pointer init     */
|
| ) #define SUCCESS             (0)
| ) #define FAIL                (-1)
|
|
| ) typedef unsigned  char UCHAR;               /* unsigned  8 bits     */
| ) typedef unsigned short USHRT;               /* unsigned 16 bits     */
| ) typedef unsigned  long ULONG;               /* unsigned 32 bits     */
|
| ) /* the S-record list is made up of these */
| ) typedef struct node {
| )           ULONG address;
| )            char *record;
| )     struct node *last;
| )     struct node *next;
| ) }NODE;
|
|
| ) ULONG genAddress();
|
|
| ) int main()
| ) {
|
| )   NODE *np;         /* pointer to the list  */
| )   NODE *anchor=NNULL;       /* anchor of the list   */
| )   NODE *end;                /* end of the list      */
|
| )   char *record;             /* reads in the line    */
|
| )     for(record=(char*)malloc(MAXLINE);
| )         (record!= (char *)NULL) && (fgets(record,MAXLINE,stdin)!=NULL);
| )         record=(char*)malloc(MAXLINE)) {
|
| )        if((np = (NODE *)malloc(sizeof(NODE))) == ((NODE*)NULL)) {
| )             printf("Error: node malloc error\n");
| )             exit(MALLOC_E);
| )        }
|
| )        /* only work on S1,S2 and S3 type records    */
| )        if(!((record[1]=='1') ||
| )                 (record[1]=='2') ||
| )             (record[1]=='3'))) {
| )             continue;
| )            }
|
| )        np->address = genAddress(record); /* Hex Ascii to long    */
| )        np->record=record;                        /* link S-rec to node   */
|
| )        insert(np,&anchor);                      /* insert node in list  */
| )     }
| )        
| )     printList(anchor);              /* writes the new file          */
|
| )     return SUCCESS;
| ) }
|
| ) /*
| )  *******************************************************************************
| )  * Function: ULONG genAddress(char *)
| )  *
| )  *    Input: pointer to a type S1,S2 or S3  S-record
| )  *   Output: an unsigned long int
| )  *******************************************************************************
| ) */
|
| ) ULONG genAddress(rec)
| )     char *rec;
| ) {
|
| )       ULONG                   tmp=0L;       /* tmp to store address         */
| )         int                 size;   /* depends on s-rec type        */
| )        char                 *cur;   /* current ascii character      */
| )        char                  adj;   /* ascii to int adjustment      */
|
|
| )     /* switch on S-record type doesn't validate the S-record        */      
|
|
| )     size = ((rec[1]-'0')*2)+2; /* sizes are 4,6,8 */
|
| )     for(cur=rec+4;size>0;size--,cur++) {
| )        switch(*cur){
| )           case '0':
| )           case '1':
| )           case '2':
| )           case '3':
| )           case '4':
| )           case '5':
| )           case '6':
| )           case '7':
| )           case '8':
| )           case '9':
| )                 tmp = (tmp <<4 ) | ((0x0f)&((*cur) - '0'));
| )                 break;
|
| )           case 'a':
| )           case 'b':
| )           case 'c':
| )           case 'd':
| )           case 'e':
| )           case 'f':
| )                 tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'a' + 10));
| )                 break;
|
| )           case 'A':
| )           case 'B':
| )           case 'C':
| )           case 'D':
| )           case 'E':
| )           case 'F':
| )                 tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'A' + 10));
| )                 break;
|
| )           default:
| )                 fprintf(stderr,"tmp=%lx ",tmp);
| )                 fprintf(stderr,"*cur=<%c> ",*cur);
| )                 fprintf(stderr,"rec=%s\n",rec);
| )                 fprintf(stderr,"Add Error\n");
| )                 return 0l;
| )                 break;
| )        }
| )     }
| )             return tmp;
| ) }
|
| ) /*
| )  *******************************************************************************
| )  * Function: int insert(NODE*,NODE*)
| )  *
| )  *    Input: pointer of the node to enter,
| )  *       pointer to the base of the list
| )  *   Output: SUCCESS or FAIL
| )  *******************************************************************************
| ) */
| ) int insert(p,a)
| )    NODE *p;
| )    NODE **a;
| ) {
|
| )    NODE *la;                /* local anchor         */
| )    NODE *ln;                /* local node           */
|
| )    ln = *a;
|
| )   if(ln == NNULL){  /* insert first entry */
| )           *a = p;
| )      p->next = NNULL;
| )      p->last = NNULL;
|
| )      return SUCCESS;
| )   }
|
| )   while(ln != NNULL){
| )      if(ln->address >= p->address){
| )      if(ln->last != NNULL) {
| )        (ln->last)->next=p;
| )        p->last=ln->last;
| )        ln->last=p;
| )        p->next=ln;
| )          } else {
| )            *a = p;
| )            p->next = ln;
| )            p->last = NNULL;
| )        ln->last = p;
| )      }      
| )      return SUCCESS;
| )      } else {
| )      if(ln->next != NNULL) {
| )         ln = ln->next;
| )      } else {
| )         ln->next = p;
| )         p->last = ln;
| )         p->next = NNULL;
| )         return SUCCESS;
| )      }
| )      }
| )      
| )   }
|
| )   return FAIL;
|
| ) }
|
| ) printList(p)
| )    NODE *p;
| ) {
| )      NODE *lp;              /* local pointer        */
|
|
| )      for(lp=p;lp!=NNULL;lp=lp->next) {
| )        printf("%s",lp->record);
| )      }
|
| ) }

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by James Youngm » Thu, 27 Feb 1997 04:00:00



Quote:>Every single little program I write "outb (0xd6, 0xc1);" "outb(0x60,0xFF);"
>etc crashes with the same error.

You either need to ask the kernel's permission to do device I/O (probably
ioperm(2), or iopl(2)), or mmap() the io-ports device (under Linux this is
/dev/port, NetBSD may or may not have an equivalent).

This is the approach that some programs (e.g. the X server) take.  However,
some others just use the kernel to drive the hardware (and use a device
ddriver).

--
James Youngman       VG Gas Analysis Systems  The trouble with the rat-race
Before sending advertising material, read     is, even if you win, you're
http://www.law.cornell.edu/uscode/47/227.html         still a rat.

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Dale Penningto » Thu, 27 Feb 1997 04:00:00





> ) Hello this unix program uses the following format

> )      sort <file.srec >sorted.srec

> ) Could anyone convert this to run in DOS

> <What, EXACTLY, is the problem? You don't say.

> Hello

> As far as I know dos does not support the < operator.Unix will use

> sort <file.srec >sorted.srec

DOS Sorts the input redirection "<" operator fine. For example, to see a
long file,
  you can type "more <longfile" which redirects longfile to more's standard
input.

<file and source code snipped>

If your program is crashing, it is something other that input and output
redirection operators.

One problem might be that the file names you are trying to use are illegal
for DOS (limit of 3 chars
after the dot). This might keep DOS from successfully opening your
redirected files and causing the crash.

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Maynard Ho » Fri, 28 Feb 1997 04:00:00



>As far as I know dos does not support the < operator.

All I can say is RTFM. DOS inherited the <, >, and | operators from
Unix (via Xenix) way back in version 2.0.

Then turn to the SORT page.

Quote:>Unix will use
>sort <file.srec >sorted.srec
>and take file.srec input and  sort in ascending order
>and write to sorted.srec

Funny, that's exactly what DOS 2.x's SORT does too. It will even let
you specify the starting column and sort in reverse.

The Unix sort does much more, but from your attitude, I gather that
you're not interested in keys, multiple keys, and all those other
arcane details.

Quote:>I know nothing about file operations and don't care to.

Interesting attitude for someone working with files to say the least.

Quote:>I need someone who programs c in unix and dos to add two args(infile
>and outfile) to main() as I beleive dos requires and modify the c
>file function calls so this works in dos.

DOS does not "require" anything of the sort! Every DOS program
automatically inherits open file handles for stdin, stdout, and
stderr. You'd almost think Microsoft was cribbing from Unix.

Quote:>The version I attached works fine on a unix box
>but crashes on borlandc compiled for dos.

Which version of Borland C, which DOS, and what CPU?

One of the reasons I'm taking the time to reply is that I recently had
a similar problem with a linked list in a problem compiled with BC++
3.1 and tested on a 486/33 failed to sort properly when run on my
Pentium.

Quote:>These are motorolla srecord and i need the 4 column for a length of
>6 digits sorted in ascendind order.

So that's what Motorola (note spelling) S records look like! I
remember Intel HEX format from my CP/M days, but my clients support
both.

From what you're saying, even DOS SORT should work.

sort /4 <infile >outfile

I assume that

(a) you are willing to accept having the S0, S1, and S2 records mixed
up (i.e., that it is safe to ignore the first three columns).

(b) the addresses (columns 4-10) are sufficiently unique that SORT
doesn't ever have to look beyond column 10.

Quote:>The provided program does this fine for unix.

Overkill in more ways than one even to these inexperienced eyes since
you admit that sort does the trick.

Quote:>>      for(cur=rec+4;size>0;size--,cur++) {
>>         switch(*cur){
>>            case '0': case '1': case '2': case '3': case '4':
>>            case '5': case '6': case '7': case '8': case '9':
>>                  tmp = (tmp <<4 ) | ((0x0f)&((*cur) - '0'));
>>                  break;
>>            case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
>>                  tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'a' + 10));
>>                  break;
>>            case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
>>                  tmp = (tmp <<4 ) | ((0x0f)&((*cur) - 'A' + 10));
>>                  break;
>>            default:
>>                  fprintf(stderr,"tmp=%lx ",tmp);
>>                  fprintf(stderr,"*cur=<%c> ",*cur);
>>                  fprintf(stderr,"rec=%s\n",rec);
>>                  fprintf(stderr,"Add Error\n");
>>                  return 0l;
>>                  break;
>>         }
>>      }

Correct me if I'm wrong, but if you must write your own atol()
routine--and here you must--isn't the following easier to understand?

ULONG genAddress(char *rec)
{
  ULONG      tmp=0L;       /* tmp to store address         */
    int      size;     /* depends on s-rec type        */
    char     *cur;     /* current ascii character      */
   char      adj;     /* ascii to int adjustment      */

  /* switch on S-record type doesn't validate the S-record        */

  size = ((rec[1]-'0')*2)+2; /* sizes are 4,6,8 */

  for (cur = rec + 4; size-- > 0; cur++) {
    if (isdigit(adj=*cur)) /*do nothing yet*/
    elseif (isxdigit(adj)) adj += 9;
    else {
      fprintf(stderr,"tmp=%lx *cur=<%c> *cur=%s\n",tmp,adj,rec);
      fprintf(stderr,"Add Error\n");
      return 0l;
    }
    tmp = (tmp << 4) | (0x0f & adj);
  }

Quote:}

===

    |\^/|     Maynard Hogg
 _|\|   |/|_  #306, 4-30-10 Yoga, Setagaya-ku, Tokyo, Japan 158
 >         <  Fax: +81-3-3700-7399

Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of US$200/hour (half-hour minimum).

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Maynard Ho » Fri, 28 Feb 1997 04:00:00


In comp.unix.programmer, comp.os.msdos.4dos, comp.os.msdos.programmer,

Quote:>Uhm there is a port of bash for dos, can be found at
>http://www.veryComputer.com/, in the djgpp distribution.
>This shell allows the < 'operator'.

Since I'm reading this in comp.os.msdos.4dos, I reluctant to praise
"that other shell", but, for the record, COMMAND.COM has supported the

Quote:>, <, and | operators since version 2.0.

Just my way of saying: Keep this off-topic *out of
comp.os.msdos.4dos! If you must cross-post, please limit your
Newsgroup: line to RELEVANT groups.

===

    |\^/|     Maynard Hogg
 _|\|   |/|_  #306, 4-30-10 Yoga, Setagaya-ku, Tokyo, Japan 158
 >         <  Fax: +81-3-3700-7399

Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of US$200/hour (half-hour minimum).

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Maynard Ho » Fri, 28 Feb 1997 04:00:00


In the *irrelevant* newsgroup, comp.os.msdos.4dos, "Dale Pennington"


>DOS Sorts the input redirection "<" operator fine. For example, to
>see a long file, you can type "more <longfile" which redirects
>longfile to more's standard input.

I checked. Even in DOS 6.20, DOS more still requires redirection.

The Unix original is more flexible, among other things supporting
multifile specifications on the command line. (I prefer pg and less,
where available--not on GOL, alas. <g>)

more file1 file2...

===

    |\^/|     Maynard Hogg
 _|\|   |/|_  #306, 4-30-10 Yoga, Setagaya-ku, Tokyo, Japan 158
 >         <  Fax: +81-3-3700-7399

Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of US$200/hour (half-hour minimum).

 
 
 

HELP, I need intel assembler and UNIX C porting help - I'm STUCK! ):

Post by Alaric Dail » Tue, 11 Mar 1997 04:00:00



: ) Hello this unix program uses the following format
:
:
: )      sort <file.srec >sorted.srec
:
: ) Could anyone convert this to run in DOS
:
: <What, EXACTLY, is the problem? You don't say.
:
: Hello
:
: As far as I know dos does not support the < operator.Unix will use
:
: sort <file.srec >sorted.srec
:
Actually Dos does support the '<' operator but you dont need it all you
need is

sort file.srec > sorted.srec

(although if we are talking DOS and not win32 you cant use the long file
extentions.)  

If this is the UNIX source that has been converted to DOS you can do this
easier with

sort file.srec -o sorted.srec


#############################################################################
Failing Tao, man resorts to Virtue.
Failing Virtue, man resorts to humanity.
Failing humanity, man resorts to morality.
Failing morality, man resorts to ceremony.
Now, ceremony is the merest husk of faith and loyalty;
It is the beginning of all confusion and disorder.

                        -Lao Tzu