Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. acpiuasm.c
  5. Abstract:
  6. Test wrapper for the unassembler
  7. Author:
  8. Stephane Plante
  9. Based on code by Ken Reneris
  10. Environment:
  11. User
  12. Revision History:
  13. --*/
  14. #include "acpiuasm.h"
  15. IFILE Orig; // Image of original aml file
  16. BOOLEAN Verbose;
  17. BOOLEAN ArgsParsed;
  18. int
  19. __cdecl
  20. main(
  21. IN int argc,
  22. IN char *argv[]
  23. )
  24. {
  25. //
  26. // Init globals
  27. //
  28. Orig.Desc = "original image";
  29. //
  30. // Parse args
  31. //
  32. ParseArgs(argc, argv);
  33. //
  34. // Check the image header
  35. //
  36. CheckImageHeader(
  37. &Orig
  38. );
  39. //
  40. // Debug the image
  41. //
  42. return ScopeParser(
  43. (PUCHAR) (Orig.Image + sizeof(DSDT)),
  44. Orig.FileSize,
  45. (ULONG) ( 0 - (ULONG) Orig.Image - sizeof(DSDT) ),
  46. 0
  47. );
  48. }
  49. VOID
  50. CheckImageHeader (
  51. IN PIFILE File
  52. )
  53. {
  54. PUCHAR Image;
  55. PDSDT Dsdt;
  56. UCHAR check;
  57. ULONG i;
  58. if (File->FileSize < sizeof(DSDT)) {
  59. FAbort ("Invalid image size in", File);
  60. }
  61. Dsdt = (PDSDT) File->Image;
  62. if (Dsdt->Signature != 'TDSD') {
  63. FAbort ("Image signature not DSDT in", File);
  64. }
  65. if (File->FileSize != Dsdt->Length) {
  66. FAbort ("File size in DSDT does not match image size in", File);
  67. }
  68. check = 0;
  69. for (Image = File->Image; Image < File->EndOfImage; Image += 1) {
  70. check += *Image;
  71. }
  72. if (check) {
  73. FAbort ("Image checksum is incorrect in", File);
  74. }
  75. // normalize fixed strings
  76. File->OemID = FixString (Dsdt->OemID, 6);
  77. File->OemTableID = FixString (Dsdt->OemID, 8);
  78. memcpy (File->OemRevision, Dsdt->OemRevision, 4);
  79. for (i=0; i < 4; i++) {
  80. if (File->OemRevision[i] == 0 || File->OemRevision[i] == ' ') {
  81. File->OemRevision[i] = '_';
  82. }
  83. }
  84. if (Verbose) {
  85. printf ("\n");
  86. printf ("DSDT info for %s (%s)\n", File->Desc, File->FileName);
  87. printf (" size of image: %d\n", File->FileSize);
  88. printf (" OEM id.......: %s\n", File->OemID);
  89. printf (" OEM Table id.: %s\n", File->OemTableID);
  90. printf (" OEM revision.: %4x\n", File->OemRevision);
  91. }
  92. }
  93. PUCHAR
  94. FixString (
  95. IN PUCHAR Str,
  96. IN ULONG Len
  97. )
  98. {
  99. PUCHAR p;
  100. ULONG i;
  101. p = malloc(Len+1);
  102. memcpy (p, Str, Len);
  103. p[Len] = 0;
  104. for (i=Len; i; i--) {
  105. if (p[i] != ' ') {
  106. break;
  107. }
  108. p[i] = 0;
  109. }
  110. return p;
  111. }
  112. VOID
  113. FAbort (
  114. PUCHAR Text,
  115. PIFILE File
  116. )
  117. {
  118. printf ("%s %s (%s)\n", Text, File->Desc, File->FileName);
  119. Abort();
  120. }
  121. VOID
  122. Abort(
  123. VOID
  124. )
  125. {
  126. if (!ArgsParsed) {
  127. printf ("amlload: UpdateImage [OriginalImage] [-v] [-d]\n");
  128. }
  129. exit (1);
  130. }
  131. VOID
  132. ParseArgs (
  133. IN int argc,
  134. IN char *argv[]
  135. )
  136. {
  137. PIFILE File;
  138. OFSTRUCT OpenBuf;
  139. File = &Orig;
  140. while (--argc) {
  141. argv += 1;
  142. //
  143. // If it's a flag crack it
  144. //
  145. if (argv[0][0] == '-') {
  146. switch (argv[0][1]) {
  147. case 'v':
  148. case 'V':
  149. Verbose = TRUE;
  150. break;
  151. default:
  152. printf ("Unkown flag %s\n", argv[0]);
  153. Abort ();
  154. }
  155. } else {
  156. if (!File) {
  157. printf ("Unexcepted parameter %s\n", argv[0]);
  158. Abort();
  159. }
  160. //
  161. // Open the file
  162. //
  163. File->FileName = argv[0];
  164. File->FileHandle = OpenFile(argv[0], &OpenBuf, OF_READ);
  165. if (File->FileHandle == HFILE_ERROR) {
  166. FAbort ("Can not open", File);
  167. }
  168. File->FileSize = GetFileSize(File->FileHandle, NULL);
  169. //
  170. // Map it
  171. //
  172. File->MapHandle =
  173. CreateFileMapping(
  174. File->FileHandle,
  175. NULL,
  176. PAGE_READONLY,
  177. 0,
  178. File->FileSize,
  179. NULL
  180. );
  181. if (!File->MapHandle) {
  182. FAbort ("Can not map", File);
  183. }
  184. File->Image =
  185. MapViewOfFile (
  186. File->MapHandle,
  187. FILE_MAP_READ,
  188. 0,
  189. 0,
  190. File->FileSize
  191. );
  192. if (!File->Image) {
  193. FAbort ("Can not map view of image", File);
  194. }
  195. File->EndOfImage = File->Image + File->FileSize;
  196. File->Opened = TRUE;
  197. //
  198. // Next file param
  199. //
  200. File = NULL;
  201. }
  202. }
  203. //
  204. // At least a update image is needed
  205. //
  206. if (!Orig.Opened) {
  207. Abort ();
  208. }
  209. ArgsParsed = TRUE;
  210. return ;
  211. }
  212. PVOID
  213. MEMORY_ALLOCATE(
  214. ULONG Num
  215. )
  216. {
  217. return malloc( Num );
  218. }
  219. VOID
  220. MEMORY_COPY(
  221. PVOID Dest,
  222. PVOID Src,
  223. ULONG Length
  224. )
  225. {
  226. memcpy( Dest, Src, Length);
  227. }
  228. VOID
  229. MEMORY_FREE(
  230. PVOID Dest
  231. )
  232. {
  233. free( Dest );
  234. }
  235. VOID
  236. MEMORY_SET(
  237. PVOID Src,
  238. UCHAR Value,
  239. ULONG Length
  240. )
  241. {
  242. memset(Src, Value, Length );
  243. }
  244. VOID
  245. MEMORY_ZERO(
  246. PVOID Src,
  247. ULONG Length
  248. )
  249. {
  250. memset( Src, 0, Length );
  251. }
  252. VOID
  253. PRINTF(
  254. PUCHAR String,
  255. ...
  256. )
  257. {
  258. va_list ap;
  259. va_start( ap, String );
  260. vprintf( String, ap );
  261. va_end( ap );
  262. }
  263. ULONG
  264. STRING_LENGTH(
  265. PUCHAR String
  266. )
  267. {
  268. return strlen( String );
  269. }
  270. VOID
  271. STRING_PRINT(
  272. PUCHAR Buffer,
  273. PUCHAR String,
  274. ...
  275. )
  276. {
  277. va_list ap;
  278. va_start( ap, String );
  279. vsprintf( Buffer, String, ap );
  280. va_end( ap );
  281. }