Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / platform / win32 / coff.h
blob81a395a56dda54beb51b5e96d4927edf53948243
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2006
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmplus_coff__
41 #define __avmplus_coff__
44 namespace avmplus
46 #if defined(DEBUGGER) && defined(AVMPLUS_IA32)
47 namespace compiler
49 /** The magic number in COFF files signifying an i386 object file */
50 const int I386MAGIC = 0x14c;
52 /**
53 * The header of a COFF file
54 * @see Coff
56 typedef struct
58 unsigned short f_magic; /**< magic number */
59 unsigned short f_nscns; /**< number of sections */
60 unsigned long f_timdat; /**< time & date stamp */
61 unsigned long f_symptr; /**< file pointer to symtab */
62 unsigned long f_nsyms; /**< number of symtab entries */
63 unsigned short f_opthdr; /**< sizeof(optional hdr) */
64 unsigned short f_flags; /**< flags */
66 CoffHeader_t;
68 /**
69 * If set, there is no relocation information in this file.
70 * This is usually clear for objects and set for executables.
72 const int F_RELFLG = 0x0001;
74 /**
75 * If set, all unresolved symbols have been resolved
76 * and the file may be considered executable.
78 const int F_EXEC = 0x0002;
80 /**
81 * If set, all line number information has been removed
82 * from the file (or was never added in the first place).
84 const int F_LNNO = 0x0004;
86 /**
87 * If set, all the local symbols have been removed
88 * from the file (or were never added in the first place).
90 const int F_LSYMS = 0x0008;
92 /**
93 * Indicates that the file is 32-bit little endian
95 const int F_AR32WR = 0x0100;
97 /**
98 * A section header in the COFF file format
99 * @see Coff
101 typedef struct
103 /** section name */
104 char s_name[8];
106 /** physical address, aliased s_nlib */
107 unsigned long s_paddr;
109 /** virtual address */
110 unsigned long s_vaddr;
112 /** section size */
113 unsigned long s_size;
115 /** file ptr to raw data for section */
116 unsigned long s_scnptr;
118 /** file ptr to relocation */
119 unsigned long s_relptr;
121 /** file ptr to line numbers */
122 unsigned long s_lnnoptr;
124 /** number of relocation entries */
125 unsigned short s_nreloc;
127 /** number of line number entries */
128 unsigned short s_nlnno;
130 /** flags */
131 unsigned long s_flags;
133 SectionHeader_t;
136 * If set, indicates that this section contains only executable code.
138 const int STYP_TEXT = 0x0020;
141 * If set, indicates that this section contains only initialized data.
143 const int STYP_DATA = 0x0040;
146 * If set, indicates that this section defines uninitialized data,
147 * and has no data stored in the coff file for it.
149 const int STYP_BSS = 0x0080;
151 #pragma pack(2) // don't add trailing bytes
153 * A symbol entry in the COFF file format
154 * @see Coff
156 typedef struct
158 union
160 /** inline name */
161 char str[8];
162 struct
164 unsigned long zero;
165 unsigned long offset;
166 } table;
167 } name;
168 unsigned long value;
169 short scnum;
170 unsigned short type;
171 unsigned char sclass;
172 unsigned char numaux;
174 SymbolEntry_t;
175 #pragma pack() // return to default
178 * The Coff class writes out object files in the COFF format
179 * (Common Object File Format)
181 * This is a useful tool for debugging the Compiler code generator
182 * that translates AVM+ bytecode to native machine code.
184 class Coff
186 public:
188 enum { NUM_SECTIONS = 64 };
189 enum { NUM_SYMBOLS = 128 };
191 Coff();
192 void addSection(const char* ar, int numBytes, int startAddr, int endAddr);
193 void addSymbol(const char* name, int value);
194 void done();
196 private:
197 virtual ~Coff();
198 void initHeader();
199 char* write(char* dst, const char* src, int count);
201 CoffHeader_t header;
202 SectionHeader_t* sections[NUM_SECTIONS];
203 SymbolEntry_t* symbols[NUM_SYMBOLS];
206 #endif // DEBUGGER
209 #endif /* __avmplus_coff__ */