lundump.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** $Id: lundump.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $
  3. ** load precompiled Lua chunks
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lundump_h
  7. #define lundump_h
  8. #include "llimits.h"
  9. #include "lobject.h"
  10. #include "lzio.h"
  11. /* These allow a multi=byte flag:1,type:3,data:4 packing in the tt byte */
  12. #define LUAU_TNIL (0<<4)
  13. #define LUAU_TBOOLEAN (1<<4)
  14. #define LUAU_TNUMFLT (2<<4)
  15. #define LUAU_TNUMPINT (3<<4)
  16. #define LUAU_TNUMNINT (4<<4)
  17. #define LUAU_TSSTRING (5<<4)
  18. #define LUAU_TLSTRING (6<<4)
  19. #define LUAU_TMASK (7<<4)
  20. #define LUAU_DMASK 0x0f
  21. /* data to catch conversion errors */
  22. #define LUAC_DATA "\x19\x93\r\n\x1a\n"
  23. #define LUAC_INT 0x5678
  24. #define LUAC_NUM cast_num(370.5)
  25. #define LUAC_FUNC_MARKER 0xFE
  26. #define LUA_TNUMNINT (LUA_TNUMBER | (2 << 4)) /* negative integer numbers */
  27. #define MYINT(s) (s[0]-'0')
  28. #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
  29. #define LUAC_FORMAT 10 /* this is the NodeMCU format */
  30. #define LUAC_LFS_IMAGE_FORMAT 11
  31. #define LUA_STRING_SIG "\x19ss"
  32. #define LUA_PROTO_SIG "\x19pr"
  33. #define LUA_HDR_BYTE '\x19'
  34. /* load one chunk; from lundump.c */
  35. LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);
  36. /* dump one chunk; from ldump.c */
  37. LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w,
  38. void* data, int strip);
  39. LUAI_FUNC int luaU_DumpAllProtos(lua_State *L, const Proto *m, lua_Writer w,
  40. void *data, int strip);
  41. LUAI_FUNC int luaU_undumpLFS(lua_State *L, ZIO *Z, int isabs);
  42. typedef struct FlashHeader LFSHeader;
  43. /*
  44. ** The LFSHeader uses offsets rather than pointers to avoid 32 vs 64 bit issues
  45. ** during host compilation. The offsets are in units of lu_int32's and NOT
  46. ** size_t, though clearly any internal pointers are of the size_t for the
  47. ** executing architectures: 4 or 8 byte. Likewise recources are size_t aligned
  48. ** so LFS regions built for 64-bit execution will have 4-byte alignment packing
  49. ** between resources.
  50. */
  51. struct FlashHeader{
  52. lu_int32 flash_sig; /* a standard fingerprint identifying an LFS image */
  53. lu_int32 flash_size; /* Size of LFS image in bytes */
  54. lu_int32 seed; /* random number seed used in LFS */
  55. lu_int32 timestamp; /* timestamp of LFS build */
  56. lu_int32 nROuse; /* number of elements in ROstrt */
  57. lu_int32 nROsize; /* size of ROstrt */
  58. lu_int32 oROhash; /* offset of TString ** ROstrt hash */
  59. lu_int32 protoROTable; /* offset of master ROTable for proto lookup */
  60. lu_int32 protoHead; /* offset of linked list of Protos in LFS */
  61. lu_int32 shortTShead; /* offset of linked list of short TStrings in LFS */
  62. lu_int32 longTShead; /* offset of linked list of long TStrings in LFS */
  63. lu_int32 reserved;
  64. };
  65. #ifdef LUA_USE_HOST
  66. extern void *LFSregion;
  67. LUAI_FUNC void luaN_setabsolute(lu_int32 addr);
  68. #endif
  69. #define FLASH_FORMAT_VERSION ( 2 << 8)
  70. #define FLASH_SIG_B1 0x06
  71. #define FLASH_SIG_B2 0x02
  72. #define FLASH_SIG_PASS2 0x0F
  73. #define FLASH_FORMAT_MASK 0xF00
  74. #define FLASH_SIG_B2_MASK 0x04
  75. #define FLASH_SIG_ABSOLUTE 0x01
  76. #define FLASH_SIG_IN_PROGRESS 0x08
  77. #define FLASH_SIG (0xfafaa050 | FLASH_FORMAT_VERSION)
  78. #define FLASH_FORMAT_MASK 0xF00
  79. #endif