data.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <system.h>
  2. #include <out.h>
  3. #include "back.h"
  4. #include "mach.h"
  5. /* Global datastructures :
  6. * - 'text_area' points to the text segment, 'text' points to first free
  7. * entry in the text segment.
  8. * - 'data_area' points to the data segment, 'data' points to the first free
  9. * entry in the data segmnet.
  10. * - 'string_area' points to the string area, 'string' points to the first free
  11. * entry in the string area.
  12. * - 'reloc_info' points to the relocation table, 'relo' points to the first
  13. * free entry in the relocation table.
  14. * - 'symbol_table' points to the symbol table, 'nname' is the index of the
  15. * first free entry in the symbol_table. If pointers were used it is a pain
  16. * to do a realloc on the symbol table, because all pointers in the
  17. * relocation table to the symbol table have to be updated.
  18. * - The bss segment contains only one vaue, so its enough to count the
  19. * the bytes wanted.
  20. * - The 'size_*' variables count the number of entries in each segment.
  21. * - 'cur_seg' contains the number of the segment to be filled.
  22. * (see "back.h")
  23. */
  24. char *text_area,
  25. *data_area,
  26. *string_area,
  27. *text, *data, *string;
  28. struct outrelo *reloc_info, *relo;
  29. struct outname *symbol_table;
  30. int cur_seg = -1 , nname = 0;
  31. long nbss = 0, size_text, size_data, size_reloc, size_symbol,
  32. size_string, text_cnt, data_cnt;
  33. put2(sect,addr,w)
  34. char *sect;
  35. long addr;
  36. int w;
  37. {
  38. #ifdef BYTES_REVERSED
  39. put1(sect, addr, (w>>8));
  40. put1(sect, addr+1, w);
  41. #else
  42. put1(sect, addr, w);
  43. put1(sect, addr+1, (w>>8));
  44. #endif
  45. }
  46. put4(sect,addr,l)
  47. char *sect;
  48. long addr;
  49. long l;
  50. {
  51. #ifdef WORDS_REVERSED
  52. put2(sect,addr,(int) (l>>16));
  53. put2(sect,addr+2,(int) l);
  54. #else
  55. put2(sect,addr,(int) l);
  56. put2(sect,addr+2,(int) (l>>16));
  57. #endif
  58. }
  59. int get2(sect,addr)
  60. char *sect;
  61. long addr;
  62. {
  63. #ifdef BYTES_REVERSED
  64. return (get1(sect,addr) << 8) | (get1(sect,addr+1) & 255);
  65. #else
  66. return (get1(sect,addr+1) << 8) | (get1(sect,addr) & 255);
  67. #endif
  68. }
  69. long get4(sect,addr)
  70. char *sect;
  71. long addr;
  72. {
  73. #ifdef WORDS_REVERSED
  74. return ((long)get2(sect,addr) << 16) | (get2(sect, addr+2) & 65535L);
  75. #else
  76. return ((long)get2(sect,addr+2) << 16) | (get2(sect, addr) & 65535L);
  77. #endif
  78. }