CHDK_DE Vorschauversion  Trunk Rev. 5663
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
code_gen.c-Dateireferenz
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include "stubs_load.h"
#include "firmware_load.h"
#include "chdk_dasm.h"
+ Include-Abhängigkeitsdiagramm für code_gen.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  _op
 

Makrodefinitionen

#define NULL_OP   0
 
#define FILE_OP   1
 
#define ENDFILE_OP   2
 
#define COPY_OP   3
 
#define COPY_LINE   4
 
#define FUNC_OP   5
 
#define ENDFUNC_OP   6
 
#define ASM_OP   7
 
#define ENDASM_OP   8
 
#define FW_OP   9
 
#define PATCHSUB_OP   10
 
#define PATCHVAL_OP   11
 
#define REM_OP   12
 
#define SKIP_OP   13
 
#define CONTFW_OP   14
 
#define LI_OP   15
 

Typdefinitionen

typedef struct _op op
 

Funktionen

char * skip_space (char *c)
 
char * skip_token (char *c)
 
char * skip_string (char *c)
 
char * next_token (char *line)
 
void parse_line (char *line)
 
char * next_line (char *line)
 
void print_args ()
 
void set_op_name (op *p, char *nm)
 
void set_op_comment (op *p, char *s)
 
opnew_op (int type)
 
void chk_args (int count, char *msg, op *p)
 
void parse_FILE ()
 
void parse_ENDFILE ()
 
void parse_COPY ()
 
void parse_FUNC ()
 
void parse_ENDFUNC ()
 
void parse_ASM ()
 
void parse_ENDASM ()
 
void parse_FW ()
 
void parse_PATCHSUB ()
 
void parse_PATCHVAL ()
 
void parse_REM ()
 
void parse_SKIP ()
 
void parse_CONTFW ()
 
void parse_LI ()
 
void op_prelabel (op *p)
 
void op_COPY (op *p)
 
void op_FUNC (op *p)
 
void op_FW (op *p)
 
void op_PATCHSUB (op *p)
 
void op_PATCHVAL (op *p)
 
void op_REM (op *p)
 
void do_ops (op *p)
 
int run_op (char *name, void(*func)())
 
void parse_ops ()
 
void usage (char *err)
 
void error (__attribute__((unused)) char *fmt, __attribute__((unused)) int n)
 
int main (int ac, const char *av[])
 

Variablen

firmwarefw
 
int lineno
 
int largc
 
char largs [20][256]
 
char * last_line
 
char token [1024]
 
FILEoutfile
 
int direct_copy
 
int in_func
 
opop_head
 
opop_tail
 
opcur_func
 
oplast_op = 0
 

Makro-Dokumentation

#define ASM_OP   7

Definiert in Zeile 423 der Datei code_gen.c.

#define CONTFW_OP   14

Definiert in Zeile 430 der Datei code_gen.c.

#define COPY_LINE   4

Definiert in Zeile 420 der Datei code_gen.c.

#define COPY_OP   3

Definiert in Zeile 419 der Datei code_gen.c.

#define ENDASM_OP   8

Definiert in Zeile 424 der Datei code_gen.c.

#define ENDFILE_OP   2

Definiert in Zeile 418 der Datei code_gen.c.

#define ENDFUNC_OP   6

Definiert in Zeile 422 der Datei code_gen.c.

#define FILE_OP   1

Definiert in Zeile 417 der Datei code_gen.c.

#define FUNC_OP   5

Definiert in Zeile 421 der Datei code_gen.c.

#define FW_OP   9

Definiert in Zeile 425 der Datei code_gen.c.

#define LI_OP   15

Definiert in Zeile 431 der Datei code_gen.c.

#define NULL_OP   0

Definiert in Zeile 416 der Datei code_gen.c.

#define PATCHSUB_OP   10

Definiert in Zeile 426 der Datei code_gen.c.

#define PATCHVAL_OP   11

Definiert in Zeile 427 der Datei code_gen.c.

#define REM_OP   12

Definiert in Zeile 428 der Datei code_gen.c.

#define SKIP_OP   13

Definiert in Zeile 429 der Datei code_gen.c.

Dokumentation der benutzerdefinierten Typen

typedef struct _op op

Dokumentation der Funktionen

void chk_args ( int  count,
char *  msg,
op p 
)

Definiert in Zeile 531 der Datei code_gen.c.

532 {
533  if (largc != count+1)
534  {
535  fprintf(stderr,"ERROR - %s\n",msg);
536  fprintf(stderr,"LINE - %d, SOURCE - %s\n",p->lineno,p->source);
537  exit(1);
538  }
539 }
void do_ops ( op p)

Definiert in Zeile 997 der Datei code_gen.c.

998 {
999  switch (p->operation)
1000  {
1001  case FILE_OP:
1002  // Open an output file
1003  outfile = fopen(p->name, "w");
1004  fprintf(outfile, "/*\n * %s - auto-generated by CHDK code_gen.\n */\n", p->name);
1005  break;
1006  case ENDFILE_OP:
1007  // Close output file
1008  if (outfile != stdout)
1009  {
1010  fclose(outfile);
1011  outfile = stdout;
1012  }
1013  break;
1014  case COPY_OP:
1015  op_COPY(p);
1016  break;
1017  case COPY_LINE:
1018  fprintf(outfile, "%s\n", p->comment);
1019  break;
1020  case FUNC_OP:
1021  op_FUNC(p);
1022  break;
1023  case ENDFUNC_OP:
1024  // End function, writes the function end to the file
1025  fprintf(outfile,"}\n");
1026  in_func = 0;
1027  break;
1028  case ASM_OP:
1029  // Writes the 'asm...' stuff to the file
1030  fprintf(outfile,"asm volatile (\n");
1031  break;
1032  case ENDASM_OP:
1033  // Ends the 'asm...' block
1034  op_prelabel(p);
1035  fprintf(outfile,");\n");
1036  break;
1037  case FW_OP:
1038  op_FW(p);
1039  break;
1040  case PATCHSUB_OP:
1041  op_PATCHSUB(p);
1042  break;
1043  case PATCHVAL_OP:
1044  op_PATCHVAL(p);
1045  break;
1046  case REM_OP:
1047  op_REM(p);
1048  break;
1049  case SKIP_OP:
1050  // Skip N words in the firmware - used to skip over DCD in the middle of a function
1051  addr += (p->skip_len * 4);
1052  break;
1053  case CONTFW_OP:
1054  // Generate a B instruction to jump back to the firmware code at the current address
1055  if (options.flags & disopt_line_numbers) fprintf(outfile," ");
1056  fprintf(outfile,"\" LDR PC, =0x%08X \\n\" // Continue in firmware\n",addr);
1057  break;
1058  case LI_OP:
1059  // set line number output state
1060  if (p->li_state != 0)
1061  options.flags |= disopt_line_numbers;
1062  else
1063  options.flags &= ~disopt_line_numbers;
1064  break;
1065  }
1066 }
void error ( __attribute__((unused)) char *  fmt,
__attribute__((unused)) int  n 
)

Definiert in Zeile 1111 der Datei code_gen.c.

1112 {
1113  if (last_op)
1114  fprintf(stderr,"Line - %d, Source --> %s\n",last_op->lineno,last_op->source);
1115  exit(1);
1116 }
int main ( int  ac,
const char *  av[] 
)

Definiert in Zeile 1120 der Datei code_gen.c.

1121 {
1122  // Check number of args
1123  if (ac < 4)
1124  {
1125  fprintf(stderr,"Usage: code_gen ROMBASE code_gen.txt PRIMARY.BIN [ALT_ROMBASE]\n");
1126  exit(1);
1127  }
1128 
1129  // Get ROMBASE value
1130  options.ROM_start = strtoul(av[1],0,0);
1131  if (options.ROM_start == 0)
1132  {
1133  fprintf(stderr,"Invalid ROMBASE.\n");
1134  exit(1);
1135  }
1136 
1137  // Get instruction file length
1138  struct stat st;
1139  if (stat(av[2],&st) != 0)
1140  {
1141  fprintf(stderr, "Failed to stat \"%s\".\n", av[2]);
1142  exit(1);
1143  }
1144  size_t len = st.st_size;
1145 
1146  // Open & read instruction file
1147  FILE *fp = fopen(av[2], "rb");
1148  if (!fp)
1149  {
1150  fprintf(stderr, "Failed to open \"%s\".\n", av[2]);
1151  exit(1);
1152  }
1153 
1154  // Allocate block for instruction file
1155  char *def = malloc(len+1);
1156  if (def == 0)
1157  {
1158  fprintf(stderr, "Not enough memory.\n");
1159  exit(1);
1160  }
1161 
1162  // Read instruction file
1163  size_t n = fread(def, 1, len, fp);
1164  def[n] = 0;
1165  fclose(fp);
1166 
1167  // Open Firmware dump file
1168  fw = malloc(sizeof(firmware));
1169  load_firmware(fw, av[3], av[1], (ac==5)?av[4]:0, OS_DRYOS);
1170 
1171  // Load function name/address values from stubs files
1172  fw->sv = new_stub_values();
1173  load_funcs(fw->sv, "funcs_by_name.csv");
1174  load_stubs(fw->sv, "stubs_entry.S", 0);
1175  load_stubs(fw->sv, "stubs_entry_2.S", 0); // Load second so values override stubs_entry.S
1176 
1177  outfile = stdout;
1178  direct_copy = 0;
1179  in_func = 0;
1180 
1181  op_head = op_tail = 0;
1182 
1183  // Pre-Process
1184  lineno = 0;
1185  char *line = def;
1186  while ((line != 0) && (*line != 0))
1187  {
1188  char *nxt = next_line(line);
1189 
1190  // Check if just copying from input file to output file
1191  if (direct_copy)
1192  {
1193  // Check if end of copy
1194  if (strncmp(line,"<<<",3) == 0)
1195  {
1196  direct_copy = 0;
1197  }
1198  else
1199  {
1200  op *p = new_op(COPY_LINE);
1201  set_op_comment(p,line);
1202  }
1203  }
1204  else
1205  {
1206  parse_line(line);
1207  parse_ops();
1208  }
1209 
1210  line = nxt;
1211  }
1212 
1213  // Process
1214  op *p = op_head;
1215  while (p)
1216  {
1217  last_op = p;
1218  do_ops(p);
1219  p = p->next;
1220  }
1221 
1222  if (outfile != stdout)
1223  fclose(outfile);
1224 
1225  return 0;
1226 }
op* new_op ( int  type)

Definiert in Zeile 488 der Datei code_gen.c.

489 {
490  op *p = malloc(sizeof(op));
491 
492  p->operation = type;
493 
494  p->source = malloc(strlen(last_line)+1);
495  strcpy(p->source,last_line);
496  p->lineno = lineno;
497 
498  p->name = 0;
499  p->comment = 0;
500  p->prelabel = 0;
501  p->func_start = 0;
502  p->func_end = 0;
503  p->func_len = 0;
504  p->patch_ref = -1;
505  p->fw_start = 0;
506  p->fw_end = 0;
507  p->fw_func_end_offset = 0;
508  p->fw_is_func_end_offset = 0;
509  p->fw_func_start_offset = 0;
511  p->fw_len = -1;
512  p->patch_new_val = 0;
513  p->skip_len = 0;
514  p->li_state = 0;
515 
516  if (op_tail)
517  {
518  op_tail->next = p;
519  }
520  else
521  {
522  op_head = p;
523  }
524 
525  op_tail = p;
526  p->next = 0;
527 
528  return p;
529 }
char* next_line ( char *  line)

Definiert in Zeile 382 der Datei code_gen.c.

383 {
384  char *nxt = strchr(line,'\r');
385  if (nxt != 0)
386  {
387  *nxt++ = 0;
388  if (*nxt == '\n')
389  nxt++;
390  }
391  else
392  {
393  nxt = strchr(line,'\n');
394  if (nxt != 0)
395  *nxt++ = 0;
396  }
397  lineno++;
398  return nxt;
399 }
char* next_token ( char *  line)

Definiert in Zeile 344 der Datei code_gen.c.

345 {
346  token[0] = 0;
347  char *c = skip_space(line);
348  char *n;
349  if (*c)
350  {
351  if (*c == '"')
352  {
353  c++;
354  n = skip_string(c);
355  strncpy(token, c, n-c);
356  token[n-c] = 0;
357  return skip_space((*n)?n+1:n);
358  }
359  else
360  {
361  n = skip_token(c);
362  strncpy(token, c, n-c);
363  token[n-c] = 0;
364  return skip_space(n);
365  }
366  }
367  return c;
368 }
void op_COPY ( op p)

Definiert in Zeile 800 der Datei code_gen.c.

801 {
802  int x;
803 
804  op_prelabel(p);
805 
806  // Check if the copy is from another source file - if so just copy that file
807  if (p->name)
808  {
809  FILE *fp = fopen(p->name,"r");
810  if (!fp)
811  {
812  fprintf(stderr,"Can't open file '%s'\n",p->name);
813  exit(1);
814  }
815 
816  char buf[1024];
817  do
818  {
819  x = fread(buf,1,1024,fp);
820  if (x > 0) fwrite(buf,1,x,outfile);
821  } while (x > 0);
822 
823  fclose(fp);
824  direct_copy = 0;
825  }
826 }
void op_FUNC ( op p)

Definiert in Zeile 832 der Datei code_gen.c.

833 {
834  char func_name[256];
835 
836  *func_name = 0;
837 
838  cur_func = p;
839 
840  if (p->name)
841  strcpy(func_name, p->name);
842 
843  if (p->patch_ref >= 0)
844  {
846  strcpy(func_name, patch_ref_name[p->patch_ref]);
847  }
848 
849  in_func = 1;
850 
851  if (p->func_start == 0) chk_args(-1,"Missing FUNC start address",p);
852 
853  if ((p->func_end == 0) && (p->func_len == 0))
854  {
855  op *n = p->next;
856  int cont = 1;
857  while (n && cont)
858  {
859  switch (n->operation)
860  {
861  case FW_OP:
862  if (n->fw_is_func_end_offset)
863  {
864  cont = 0;
865  p->func_len = 0;
866  }
867  else
868  {
869  p->func_len += n->fw_len;
870  }
871  break;
872  case PATCHSUB_OP:
873  case PATCHVAL_OP:
874  case REM_OP:
875  p->func_len++;
876  break;
877  case SKIP_OP:
878  p->func_len += n->skip_len;
879  break;
880  case ENDFUNC_OP:
881  cont = 0;
882  break;
883  }
884  n = n->next;
885  }
886 
887  if (p->func_len == 0)
888  {
889  p->func_end = find_end(fw, p->func_start);
890  if (p->func_end == 0)
891  chk_args(-1,"Missing FUNC end address or length",p);
892  }
893  }
894 
895  if ((p->func_end == 0) && (p->func_len > 0))
896  p->func_end = p->func_start + p->func_len * 4 - 4;
897  if ((p->func_len == 0) && (p->func_end > 0))
898  p->func_len = (p->func_end - p->func_start) / 4 + 1;
899  if (p->func_end < p->func_start) chk_args(-1,"FUNC start > end",p);
900  if (p->func_len != (int)((p->func_end - p->func_start) / 4 + 1)) chk_args(-1,"FUNC start/end/length mismatch",p);
901 
902  if (*func_name == 0)
903  sprintf(func_name, "sub_%08X_my", p->func_start);
904 
905  options.start_address = p->func_start;
906  options.end_address = p->func_end;
907 
913 
914  fprintf(outfile,"\n/*************************************************************/");
915  fprintf(outfile,"\n//** %s @ 0x%08X - 0x%08X, length=%d\n", func_name, p->func_start, last_used_addr, (last_used_addr - p->func_start) / 4 + 1 ) ;
916  fprintf(outfile,"void __attribute__((naked,noinline)) %s() {\n", func_name);
917 
918  addr = p->func_start;
919 }
void op_FW ( op p)

Definiert in Zeile 922 der Datei code_gen.c.

923 {
924  t_address start_address = addr;
925  t_address end_address = addr;
926 
927  patch_comment = p->comment;
928  if (patch_comment)
929  {
930  options.flags |= disopt_patch_comment;
931  }
932 
933  if (p->fw_start > 0)
934  start_address = p->fw_start;
935  if (p->fw_end > 0)
936  end_address = p->fw_end;
937  if (p->fw_is_func_end_offset)
938  end_address = cur_func->func_end + p->fw_func_end_offset;
940  end_address = cur_func->func_start + p->fw_func_start_offset;
941  if (p->fw_len > 0)
942  end_address = start_address + p->fw_len * 4 - 4;
943 
944  disassemble(fw, outfile, start_address, (end_address + 4 - start_address) / 4);
945 }
void op_PATCHSUB ( op p)

Definiert in Zeile 949 der Datei code_gen.c.

950 {
951  patch_func_name = p->name;
953  patch_comment = p->comment;
954  if (patch_comment)
955  {
956  options.flags |= disopt_patch_comment;
957  }
958 
959  options.flags |= disopt_patch_branch;
960  disassemble(fw, outfile, addr, 1);
962 }
void op_PATCHVAL ( op p)

Definiert in Zeile 965 der Datei code_gen.c.

966 {
968  patch_comment = p->comment;
969  if (patch_comment)
970  {
971  options.flags |= disopt_patch_comment;
972  }
973 
974  options.flags |= disopt_patch_value;
975  disassemble(fw, outfile, addr, 1);
977 }
void op_prelabel ( op p)

Definiert in Zeile 786 der Datei code_gen.c.

787 {
788  // If after then write label to output and remove from list (so it doesn't get written twice)
789  if (in_func && (p->prelabel == 0) && (addr <= options.end_address))
790  {
791  if (l_search(branch_list, addr))
792  {
793  fprintf(outfile,"\n\"loc_%08X:\\n\"\n", addr) ;
795  }
796  }
797 }
void op_REM ( op p)

Definiert in Zeile 981 der Datei code_gen.c.

982 {
983  patch_comment = p->comment;
984  if (patch_comment)
985  {
986  options.flags |= disopt_patch_comment;
987  }
988 
989  options.flags |= disopt_comment_lines;
990  disassemble(fw, outfile, addr, 1);
992 }
void parse_ASM ( )

Definiert in Zeile 635 der Datei code_gen.c.

636 {
637  new_op(ASM_OP);
638 }
void parse_CONTFW ( )

Definiert in Zeile 771 der Datei code_gen.c.

772 {
773  new_op(CONTFW_OP);
774 }
void parse_COPY ( )

Definiert in Zeile 558 der Datei code_gen.c.

559 {
560  op *p = new_op(COPY_OP);
561  int n;
562 
563  // Check if copy goes before or after the current instruction address label
564  for (n=1; n<largc; n++)
565  {
566  if (strcmp(largs[n],"prelabel") == 0)
567  p->prelabel = 1;
568  }
569 
570  direct_copy = 1;
571 
572  // Check if the copy is from another source file - if so just copy that file
573  for (n=1; n<largc; n++)
574  {
575  if (strcmp(largs[n],"file") == 0)
576  {
577  set_op_name(p,largs[++n]);
578  direct_copy = 0;
579  }
580  }
581 }
void parse_ENDASM ( )

Definiert in Zeile 641 der Datei code_gen.c.

642 {
643  op *p = new_op(ENDASM_OP);
644  int n;
645 
646  // Check if copy goes before or after the current instruction address label
647  for (n=1; n<largc; n++)
648  {
649  if (strcmp(largs[n],"prelabel") == 0)
650  p->prelabel = 1;
651  }
652 }
void parse_ENDFILE ( )

Definiert in Zeile 552 der Datei code_gen.c.

553 {
555 }
void parse_ENDFUNC ( )

Definiert in Zeile 629 der Datei code_gen.c.

630 {
632 }
void parse_FILE ( )

Definiert in Zeile 544 der Datei code_gen.c.

545 {
546  op *p = new_op(FILE_OP);
547  chk_args(1,"Missing FILE name",p);
548  set_op_name(p,largs[1]);
549 }
void parse_FUNC ( )

Definiert in Zeile 587 der Datei code_gen.c.

588 {
589  op *p = new_op(FUNC_OP);
590  int n;
591 
592  for (n=1; n<largc; n++)
593  {
594  if (strcmp(largs[n], "name") == 0)
595  {
596  set_op_name(p,largs[++n]);
597  }
598  else if (strcmp(largs[n], "start") == 0)
599  {
600  p->func_start = strtoul(largs[++n],0,0);
601  }
602  else if (strcmp(largs[n], "end") == 0)
603  {
604  p->func_end = strtoul(largs[++n],0,0);
605  }
606  else if (strcmp(largs[n], "length") == 0)
607  {
608  p->func_len = strtoul(largs[++n],0,0);
609  }
610  else if (strcmp(largs[n], "ref") == 0)
611  {
612  p->patch_ref = strtol(largs[++n],0,0);
613  }
614  else if (strcmp(largs[n], "sig") == 0)
615  {
616  osig *sig = find_sig(fw->sv->stubs, largs[++n]);
617  if (sig == 0) chk_args(-1,"Can't find firmware function for 'sig='",p);
618  p->func_start = sig->val;
619  p->name = sig->nm;
620  }
621  else
622  {
623  chk_args(-1,"Invalid FUNC argument",p);
624  }
625  }
626 }
void parse_FW ( )

Definiert in Zeile 655 der Datei code_gen.c.

656 {
657  op *p = new_op(FW_OP);
658  int n;
659 
660  for (n=1; n<largc; n++)
661  {
662  switch (largs[n][0])
663  {
664  case '^':
665  p->fw_start = strtoul(largs[n]+1,0,0);
666  break;
667  case '-':
668  p->fw_end = strtoul(largs[n]+1,0,0);
669  break;
670  case '$':
671  p->fw_func_end_offset = strtol(largs[n]+1,0,0) * 4;
672  p->fw_is_func_end_offset = 1;
673  break;
674  case 'L':
675  p->fw_func_start_offset = strtol(largs[n]+1,0,0) * 4 - 4;
677  break;
678  default:
679  if (strcmp(largs[n], "comment") == 0)
680  {
681  set_op_comment(p,largs[++n]);
682  }
683  else
684  {
685  p->fw_len = strtoul(largs[n],0,0);
686  if (p->fw_len == 0) p->fw_len++;
687  }
688  break;
689  }
690  }
691 
692  if ((p->fw_start != 0) && (p->fw_end != 0))
693  p->fw_len = (p->fw_end - p->fw_start) / 4 + 1;
694 }
void parse_LI ( )

Definiert in Zeile 777 der Datei code_gen.c.

778 {
779  op *p = new_op(LI_OP);
780  if (largc > 1)
781  p->li_state = strtol(largs[1],0,0);
782 }
void parse_line ( char *  line)

Definiert in Zeile 370 der Datei code_gen.c.

371 {
372  last_line = line;
373  largc = 0;
374  largs[largc][0] = 0;
375  while (line && *line)
376  {
377  line = next_token(line);
378  strcpy(largs[largc++], token);
379  }
380 }
void parse_ops ( )

Definiert in Zeile 1080 der Datei code_gen.c.

1081 {
1082  if (largc > 0)
1083  {
1084  if (run_op("FILE", parse_FILE)) return;
1085  if (run_op("ENDFILE", parse_ENDFILE)) return;
1086  if (run_op(">>>", parse_COPY)) return;
1087  if (run_op("FUNC", parse_FUNC)) return;
1088  if (run_op("ENDFUNC", parse_ENDFUNC)) return;
1089  if (run_op("ASM", parse_ASM)) return;
1090  if (run_op("ENDASM", parse_ENDASM)) return;
1091  if (run_op("FW", parse_FW)) return;
1092  if (run_op("PATCHSUB", parse_PATCHSUB)) return;
1093  if (run_op("PATCHVAL", parse_PATCHVAL)) return;
1094  if (run_op("REM", parse_REM)) return;
1095  if (run_op("SKIP", parse_SKIP)) return;
1096  if (run_op("->FW", parse_CONTFW)) return;
1097  if (run_op("LI", parse_LI)) return;
1098  }
1099 }
void parse_PATCHSUB ( )

Definiert in Zeile 698 der Datei code_gen.c.

699 {
700  op *p = new_op(PATCHSUB_OP);
701  int n;
702 
703  for (n=1; n<largc; n++)
704  {
705  if (strcmp(largs[n], "name") == 0)
706  {
707  set_op_name(p,largs[++n]);
708  }
709  else if (strcmp(largs[n], "ref") == 0)
710  {
711  p->patch_ref = strtoul(largs[++n],0,0);
712  }
713  else if (strcmp(largs[n], "comment") == 0)
714  {
715  set_op_comment(p,largs[++n]);
716  }
717  else
718  {
719  chk_args(-1,"Invalid PATCHSUB argument",p);
720  }
721  }
722 }
void parse_PATCHVAL ( )

Definiert in Zeile 725 der Datei code_gen.c.

726 {
727  op *p = new_op(PATCHVAL_OP);
728  int n;
729 
730  for (n=1; n<largc; n++)
731  {
732  if (strcmp(largs[n], "value") == 0)
733  {
734  p->patch_new_val = strtoul(largs[++n],0,0);
735  }
736  else if (strcmp(largs[n], "comment") == 0)
737  {
738  set_op_comment(p,largs[++n]);
739  }
740  else
741  {
742  chk_args(-1,"Invalid PATCHVAL argument",p);
743  }
744  }
745 }
void parse_REM ( )

Definiert in Zeile 749 der Datei code_gen.c.

750 {
751  op *p = new_op(REM_OP);
752 
753  if (largc > 1)
754  {
755  set_op_comment(p,largs[1]);
756  }
757 }
void parse_SKIP ( )

Definiert in Zeile 760 der Datei code_gen.c.

761 {
762  op *p = new_op(SKIP_OP);
763 
764  if (largc > 1)
765  p->skip_len = strtol(largs[1],0,0);
766  else
767  p->skip_len = 1;
768 }
void print_args ( )

Definiert in Zeile 401 der Datei code_gen.c.

402 {
403  int n;
404  for (n=0; n<largc; n++) fprintf(stderr,"\t%d %s\n",n,largs[n]);
405 }
int run_op ( char *  name,
void(*)()  func 
)

Definiert in Zeile 1069 der Datei code_gen.c.

1070 {
1071  if (strcmp(largs[0], name) == 0)
1072  {
1073  func();
1074  return 1;
1075  }
1076  return 0;
1077 }
void set_op_comment ( op p,
char *  s 
)

Definiert in Zeile 475 der Datei code_gen.c.

476 {
477  if (s)
478  {
479  p->comment = malloc(strlen(s)+1);
480  strcpy(p->comment,s);
481  }
482  else
483  {
484  p->comment = 0;
485  }
486 }
void set_op_name ( op p,
char *  nm 
)

Definiert in Zeile 462 der Datei code_gen.c.

463 {
464  if (nm)
465  {
466  p->name = malloc(strlen(nm)+1);
467  strcpy(p->name,nm);
468  }
469  else
470  {
471  p->name = 0;
472  }
473 }
char* skip_space ( char *  c)

Definiert in Zeile 326 der Datei code_gen.c.

327 {
328  while (*c && ((*c == ' ') || (*c == '\t') || (*c == '='))) c++;
329  return c;
330 }
char* skip_string ( char *  c)

Definiert in Zeile 338 der Datei code_gen.c.

339 {
340  while (*c && (*c != '"')) c++;
341  return c;
342 }
char* skip_token ( char *  c)

Definiert in Zeile 332 der Datei code_gen.c.

333 {
334  while (*c && (*c != ' ') && (*c != '\t') && (*c != '=')) c++;
335  return c;
336 }
void usage ( char *  err)

Definiert in Zeile 1103 der Datei code_gen.c.

1104 {
1105  fprintf(stderr,"code_gen <base> <primary> [alt base] - Error = %s\n",err);
1106  exit(1);
1107 }

Variablen-Dokumentation

op * cur_func

Definiert in Zeile 460 der Datei code_gen.c.

int direct_copy

Definiert in Zeile 411 der Datei code_gen.c.

firmware* fw

Definiert in Zeile 316 der Datei code_gen.c.

int in_func

Definiert in Zeile 412 der Datei code_gen.c.

int largc

Definiert in Zeile 321 der Datei code_gen.c.

char largs[20][256]

Definiert in Zeile 322 der Datei code_gen.c.

char* last_line

Definiert in Zeile 323 der Datei code_gen.c.

op* last_op = 0

Definiert in Zeile 1109 der Datei code_gen.c.

int lineno

Definiert in Zeile 320 der Datei code_gen.c.

op* op_head

Definiert in Zeile 460 der Datei code_gen.c.

op * op_tail

Definiert in Zeile 460 der Datei code_gen.c.

FILE* outfile

Definiert in Zeile 410 der Datei code_gen.c.

char token[1024]

Definiert in Zeile 324 der Datei code_gen.c.