dxeload.pp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by Pierre Muller,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { Translated to FPK pascal by Pierre Muller,
  13. without changing the fpu.s file }
  14. {
  15. /* Copyright (C) 1994, 1995 Charles Sandmann ([email protected])
  16. * FPU setup and emulation hooks for DJGPP V2.0
  17. * This file maybe freely distributed, no warranty. */
  18. this file has been translated from
  19. dxe.h
  20. dxeload.c
  21. npxsetup.c
  22. it uses fpu.as unchanged from fpu.s in DJGPP/SRC/LIBC/}
  23. {/* Copyright (C) 1995 Charles Sandmann ([email protected])
  24. This software may be freely distributed with above copyright, no warranty.
  25. Based on code by DJ Delorie, it's really his, enhanced, bugs fixed. */}
  26. Unit dxeload;
  27. interface
  28. type
  29. dxe_header = record
  30. magic : longint;
  31. symbol_offset : longint;
  32. element_size : longint;
  33. nrelocs : longint;
  34. end;
  35. const
  36. DXE_MAGIC = $31455844;
  37. {/* data stored after dxe_header in file; then relocs, 4 bytes each */}
  38. function dxe_load(filename : string) : pointer;
  39. implementation
  40. function dxe_load(filename : string) : pointer;
  41. type
  42. pointer_array = array[0..0] of pointer;
  43. tpa = ^pointer_array;
  44. plongint = ^longint;
  45. ppointer = ^pointer;
  46. var
  47. dh : dxe_header;
  48. data : pchar;
  49. f : file;
  50. relocs : tpa;
  51. i : longint;
  52. addr : plongint;
  53. begin
  54. dxe_load:=nil;
  55. assign(f,filename);
  56. reset(f,1);
  57. blockread(f,@dh,sizeof(dxe_header));
  58. if dh.magic<>DXE_MAGIC then
  59. begin
  60. close(f);
  61. exit;
  62. end;
  63. { get memory for code }
  64. getmem(data,dh.element_size);
  65. if data=nil then
  66. exit;
  67. { get memory for relocations }
  68. getmem(relocs,dh.nrelocs*sizeof(pointer));
  69. if relocs=nil then
  70. begin
  71. freemem(data,dh.element_size);
  72. exit;
  73. end;
  74. { copy code }
  75. blockread(f,data^,dh.element_size);
  76. blockread(f,relocs^,dh.nrelocs*sizeof(pointer));
  77. { relocate internal references }
  78. for i:=0 to dh.nrelocs-1 do
  79. begin
  80. cardinal(addr):=cardinal(data)+cardinal(relocs^[i]);
  81. addr^:=addr^+pointer(data);
  82. end;
  83. dxe_load:=pointer( dh.symbol_offset + cardinal(data));
  84. end;
  85. end.
  86. {
  87. $Log$
  88. Revision 1.1 1998-03-25 11:18:42 root
  89. Initial revision
  90. Revision 1.3 1998/01/26 11:57:29 michael
  91. + Added log at the end
  92. Revision 1.2 1998/01/19 17:04:39 pierre
  93. * bug in dxe loading corrected, emu still does not work !!
  94. Revision 1.1 1998/01/16 16:50:49 pierre
  95. dxeload is a pascal version of the DJGPP C dxe loader
  96. }
  97. {
  98. $Log$
  99. Revision 1.1 1998-03-25 11:18:42 root
  100. Initial revision
  101. Revision 1.3 1998/01/26 11:57:29 michael
  102. + Added log at the end
  103. Working file: rtl/dos/go32v2/dxeload.pp
  104. description:
  105. ----------------------------
  106. revision 1.2
  107. date: 1998/01/19 17:04:39; author: pierre; state: Exp; lines: +7 -3
  108. * bug in dxe loading corrected, emu still does not work !!
  109. ----------------------------
  110. revision 1.1
  111. date: 1998/01/16 16:50:49; author: pierre; state: Exp;
  112. dxeload is a pascal version of the DJGPP C dxe loader
  113. =============================================================================
  114. }