OpenCores
URL https://opencores.org/ocsvn/vtach/vtach/trunk

Subversion Repositories vtach

[/] [vtach/] [trunk/] [asm/] [soloasm.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wd5gnr
/**********************************************************************
2
axasm Copyright 2006, 2007, 2008, 2009
3
by Al Williams (alw@al-williams.com).
4
 
5
 
6
This file is part of axasm.
7
 
8
axasm is free software: you can redistribute it and/or modify it
9
under the terms of the GNU General Public Licenses as published
10
by the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12
 
13
axasm is distributed in the hope that it will be useful, but
14
WITHOUT ANY WARRANTY: without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with axasm (see LICENSE.TXT).
20
If not, see http://www.gnu.org/licenses/.
21
 
22
If a non-GPL license is desired, contact the author.
23
 
24
This is the retargetable assembler core file
25
 
26
***********************************************************************/
27
#include <stdio.h>
28
#include <unistd.h>
29
#include <getopt.h>
30
#define _SOLO_MAIN
31
#include "soloasm.h"
32
 
33
 
34
extern unsigned genasm(unsigned);
35
 
36
static FILE *outfile;
37
 
38
int main(int argc, char *argv[])
39
{
40
  unsigned int endmem,i,j;
41
  unsigned int siz;
42
  unsigned mask;
43
  int opt=0;
44
  int mode=0;
45
  outfile=stdout;
46
  while (opt!=-1)
47
    {
48
      opt=getopt(argc,argv,"bvhixo:");
49
      switch (opt)
50
        {
51
        case 'b':
52
          mode=4;
53
          break;
54
        case 'v':
55
          mode=3;
56
          break;
57
        case 'i':
58
          mode=2;
59
          break;
60
        case 'x':
61
          mode=1;
62
          break;
63
        case 'h':
64
          mode=0;
65
          break;
66
 
67
        case 'o':
68
          // note -b must be before -o 
69
          outfile=fopen(optarg,mode==4?"r+":"w");
70
          if (!outfile)
71
            {
72
              perror(optarg);
73
              return 1;
74
            }
75
          break;
76
        }
77
    }
78
  _solo_info.psize=32;   //default size
79
  endmem=genasm(1); // let labels get filled in
80
  if (_solo_info.err==0) endmem=genasm(2); // pass 2 for real
81
  if (_solo_info.err!=0)
82
    {
83
      fprintf(stderr,"Fatal error. No output generated.\n");
84
      return 1;
85
    }
86
  siz=_solo_info.psize;
87
  switch (mode)
88
    {
89
    case 1:
90
      fprintf(outfile,";Generated by soloasm\n");
91
      fprintf(outfile,"MEMORY_INITIALIZATION_RADIX=16;\n");
92
      fprintf(outfile,"MEMORY_INITIALIZATION_VECTOR=\n");
93
      for (i=_solo_info.begin;i<=_solo_info.end;i++) fprintf(outfile,"%0*X%c\n",siz/4,_solo_info.ary[i],i==_solo_info.end?';':',');
94
      break;
95
    case 2:  // basic 64k intel hex file only; psize must be multiple of 8
96
      mask=0xFF;
97
      unsigned bytesper=16/(siz/8);
98
      for (i=_solo_info.begin;i<=_solo_info.end;i+=bytesper)
99
        {
100
          /* need to compute # of output words on this line */
101
          unsigned bsize;
102
          unsigned lsize=bytesper;  // nominal line size (round up)
103
          if (i+lsize>_solo_info.end)
104
              lsize=(_solo_info.end-i)+1;
105
          bsize=lsize*bytesper;
106
          unsigned csum=lsize+(i>>8)+(i&0xFF);
107
          unsigned byt;
108
          fprintf(outfile,":");
109
          fprintf(outfile,"%02x%04x00",bsize,i);
110
          for (j=0;j<lsize;j++)
111
            {
112
              fprintf(outfile,"%02x",_solo_info.ary[i+j]&mask);
113
              csum+=_solo_info.ary[i+j]&mask;
114
              if (siz>8)
115
                {
116
                  fprintf(outfile,"%02x",byt=(_solo_info.ary[i+j]>>8)&mask);
117
                  csum+=byt;
118
                }
119
              if (siz>16)
120
                {
121
                  fprintf(outfile,"%02x",byt=(_solo_info.ary[i+j]>>16)&mask);
122
                  csum+=byt;
123
                }
124
              if (siz>24)
125
                {
126
                  fprintf(outfile,"%02x",byt=(_solo_info.ary[i+j]>>24)&mask);
127
                  csum+=byt;
128
                }
129
            }
130
          fprintf(outfile,"%02x\n",((~csum)+1)&0xFF);
131
        }
132
      fprintf(outfile,":00000001FF\n");
133
      break;
134
    case 4:   // binary for 32 bit targets only (arch dependent)
135
      fseek(outfile,_solo_info.begin,SEEK_SET);
136
      fwrite(_solo_info.ary+_solo_info.begin,1,(_solo_info.end+1-_solo_info.begin)*(siz/8),outfile);
137
      break;
138
    default:  // including mode=0;
139
      if (mode==3) fprintf(outfile,"@%X ",_solo_info.begin);
140
      for (i=_solo_info.begin;i<=_solo_info.end;i+=16)
141
        {
142
          if (mode!=3 && mode!=0)fprintf(outfile,"%0*X: ",siz==8?4:8,i);
143
          for (j=0;j<16;j++)
144
            if (i+j<=_solo_info.end)
145
              {
146
                if (mode==0) fprintf(outfile,"%0*X: ",siz==8?4:8,i+j);
147
              fprintf(outfile,"%0*X ",(siz+3)/4,_solo_info.ary[i+j]);
148
              if (mode==0) fprintf(outfile,"\n");
149
              }
150
          if (mode!=0) fprintf(outfile,"\n");
151
        }
152
    }
153
  if (outfile!=stdout) fclose(outfile);
154
  return 0;
155
}
156
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.