1*1641b506Schristos /* $NetBSD: exec_ecoff.h,v 1.21 2017/02/23 18:54:30 christos Exp $ */ 2fccfa11aScgd 37890c5a8Sglass /* 47890c5a8Sglass * Copyright (c) 1994 Adam Glass 57890c5a8Sglass * All rights reserved. 67890c5a8Sglass * 77890c5a8Sglass * Redistribution and use in source and binary forms, with or without 87890c5a8Sglass * modification, are permitted provided that the following conditions 97890c5a8Sglass * are met: 107890c5a8Sglass * 1. Redistributions of source code must retain the above copyright 117890c5a8Sglass * notice, this list of conditions and the following disclaimer. 127890c5a8Sglass * 2. Redistributions in binary form must reproduce the above copyright 137890c5a8Sglass * notice, this list of conditions and the following disclaimer in the 147890c5a8Sglass * documentation and/or other materials provided with the distribution. 157890c5a8Sglass * 3. All advertising materials mentioning features or use of this software 167890c5a8Sglass * must display the following acknowledgement: 1709fe6820Sglass * This product includes software developed by Adam Glass. 187890c5a8Sglass * 4. The name of the author may not be used to endorse or promote products 197890c5a8Sglass * derived from this software without specific prior written permission 207890c5a8Sglass * 217890c5a8Sglass * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 227890c5a8Sglass * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 237890c5a8Sglass * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 247890c5a8Sglass * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 257890c5a8Sglass * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 267890c5a8Sglass * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 277890c5a8Sglass * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 287890c5a8Sglass * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 297890c5a8Sglass * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 307890c5a8Sglass * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 317890c5a8Sglass */ 327890c5a8Sglass 337890c5a8Sglass #ifndef _SYS_EXEC_ECOFF_H_ 347890c5a8Sglass #define _SYS_EXEC_ECOFF_H_ 357890c5a8Sglass 3664f4e193Scgd #include <machine/ecoff_machdep.h> 377890c5a8Sglass 38*1641b506Schristos #ifdef ECOFF32_PAD 39*1641b506Schristos 40*1641b506Schristos typedef uint32_t ecoff32_addr; 41*1641b506Schristos typedef uint32_t ecoff32_off; 42*1641b506Schristos typedef uint32_t ecoff32_ulong; 43*1641b506Schristos typedef int32_t ecoff32_long; 44*1641b506Schristos typedef uint32_t ecoff32_uint; 45*1641b506Schristos typedef int32_t ecoff32_int; 46*1641b506Schristos typedef uint16_t ecoff32_ushort; 47*1641b506Schristos typedef int16_t ecoff32_short; 48*1641b506Schristos typedef uint8_t ecoff32_ubyte; 49*1641b506Schristos typedef int8_t ecoff32_byte; 50*1641b506Schristos 51*1641b506Schristos struct ecoff32_filehdr { 52*1641b506Schristos ecoff32_ushort f_magic; /* magic number */ 53*1641b506Schristos ecoff32_ushort f_nscns; /* # of sections */ 54*1641b506Schristos ecoff32_uint f_timdat; /* time and date stamp */ 55*1641b506Schristos ecoff32_ulong f_symptr; /* file offset of symbol table */ 56*1641b506Schristos ecoff32_uint f_nsyms; /* # of symbol table entries */ 57*1641b506Schristos ecoff32_ushort f_opthdr; /* sizeof the optional header */ 58*1641b506Schristos ecoff32_ushort f_flags; /* flags??? */ 59*1641b506Schristos }; 60*1641b506Schristos 61*1641b506Schristos struct ecoff32_aouthdr { 62*1641b506Schristos ecoff32_ushort magic; 63*1641b506Schristos ecoff32_ushort vstamp; 64*1641b506Schristos ECOFF32_PAD 65*1641b506Schristos ecoff32_ulong tsize; 66*1641b506Schristos ecoff32_ulong dsize; 67*1641b506Schristos ecoff32_ulong bsize; 68*1641b506Schristos ecoff32_ulong entry; 69*1641b506Schristos ecoff32_ulong text_start; 70*1641b506Schristos ecoff32_ulong data_start; 71*1641b506Schristos ecoff32_ulong bss_start; 72*1641b506Schristos ECOFF32_MACHDEP; 73*1641b506Schristos }; 74*1641b506Schristos 75*1641b506Schristos struct ecoff32_scnhdr { /* needed for size info */ 76*1641b506Schristos char s_name[8]; /* name */ 77*1641b506Schristos ecoff32_ulong s_paddr; /* physical addr? for ROMing?*/ 78*1641b506Schristos ecoff32_ulong s_vaddr; /* virtual addr? */ 79*1641b506Schristos ecoff32_ulong s_size; /* size */ 80*1641b506Schristos ecoff32_ulong s_scnptr; /* file offset of raw data */ 81*1641b506Schristos ecoff32_ulong s_relptr; /* file offset of reloc data */ 82*1641b506Schristos ecoff32_ulong s_lnnoptr; /* file offset of line data */ 83*1641b506Schristos ecoff32_ushort s_nreloc; /* # of relocation entries */ 84*1641b506Schristos ecoff32_ushort s_nlnno; /* # of line entries */ 85*1641b506Schristos ecoff32_uint s_flags; /* flags */ 86*1641b506Schristos }; 87*1641b506Schristos 88*1641b506Schristos struct ecoff32_exechdr { 89*1641b506Schristos struct ecoff32_filehdr f; 90*1641b506Schristos struct ecoff32_aouthdr a; 91*1641b506Schristos }; 92*1641b506Schristos 93*1641b506Schristos #define ECOFF32_HDR_SIZE (sizeof(struct ecoff32_exechdr)) 94*1641b506Schristos 95*1641b506Schristos #define ECOFF32_TXTOFF(ep) \ 96*1641b506Schristos ((ep)->a.magic == ECOFF_ZMAGIC ? 0 : \ 97*1641b506Schristos ECOFF_ROUND(ECOFF32_HDR_SIZE + (ep)->f.f_nscns * \ 98*1641b506Schristos sizeof(struct ecoff32_scnhdr), ECOFF32_SEGMENT_ALIGNMENT(ep))) 99*1641b506Schristos 100*1641b506Schristos #define ECOFF32_DATOFF(ep) \ 101*1641b506Schristos (ECOFF_BLOCK_ALIGN((ep), ECOFF32_TXTOFF(ep) + (ep)->a.tsize)) 102*1641b506Schristos 103*1641b506Schristos #define ECOFF32_SEGMENT_ALIGN(ep, value) \ 104*1641b506Schristos (ECOFF_ROUND((value), ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_LDPGSZ : \ 105*1641b506Schristos ECOFF32_SEGMENT_ALIGNMENT(ep)))) 106*1641b506Schristos #endif 107*1641b506Schristos 1087890c5a8Sglass struct ecoff_filehdr { 1090f1b3e09Scgd u_short f_magic; /* magic number */ 1100f1b3e09Scgd u_short f_nscns; /* # of sections */ 1110f1b3e09Scgd u_int f_timdat; /* time and date stamp */ 1120f1b3e09Scgd u_long f_symptr; /* file offset of symbol table */ 1130f1b3e09Scgd u_int f_nsyms; /* # of symbol table entries */ 1140f1b3e09Scgd u_short f_opthdr; /* sizeof the optional header */ 1150f1b3e09Scgd u_short f_flags; /* flags??? */ 1167890c5a8Sglass }; 1177890c5a8Sglass 1187890c5a8Sglass struct ecoff_aouthdr { 1190f1b3e09Scgd u_short magic; 1200f1b3e09Scgd u_short vstamp; 1217890c5a8Sglass ECOFF_PAD 1220f1b3e09Scgd u_long tsize; 1230f1b3e09Scgd u_long dsize; 1240f1b3e09Scgd u_long bsize; 1250f1b3e09Scgd u_long entry; 1260f1b3e09Scgd u_long text_start; 1270f1b3e09Scgd u_long data_start; 1280f1b3e09Scgd u_long bss_start; 1297890c5a8Sglass ECOFF_MACHDEP; 1307890c5a8Sglass }; 1317890c5a8Sglass 1327890c5a8Sglass struct ecoff_scnhdr { /* needed for size info */ 1330f1b3e09Scgd char s_name[8]; /* name */ 1340f1b3e09Scgd u_long s_paddr; /* physical addr? for ROMing?*/ 1350f1b3e09Scgd u_long s_vaddr; /* virtual addr? */ 1360f1b3e09Scgd u_long s_size; /* size */ 1370f1b3e09Scgd u_long s_scnptr; /* file offset of raw data */ 1380f1b3e09Scgd u_long s_relptr; /* file offset of reloc data */ 1390f1b3e09Scgd u_long s_lnnoptr; /* file offset of line data */ 1400f1b3e09Scgd u_short s_nreloc; /* # of relocation entries */ 1410f1b3e09Scgd u_short s_nlnno; /* # of line entries */ 1420f1b3e09Scgd u_int s_flags; /* flags */ 1437890c5a8Sglass }; 1447890c5a8Sglass 1450f1b3e09Scgd struct ecoff_exechdr { 1460f1b3e09Scgd struct ecoff_filehdr f; 1470f1b3e09Scgd struct ecoff_aouthdr a; 1480f1b3e09Scgd }; 1490f1b3e09Scgd 1500f1b3e09Scgd #define ECOFF_HDR_SIZE (sizeof(struct ecoff_exechdr)) 1517890c5a8Sglass 1527890c5a8Sglass #define ECOFF_OMAGIC 0407 153af77c1caSglass #define ECOFF_NMAGIC 0410 1547890c5a8Sglass #define ECOFF_ZMAGIC 0413 1557890c5a8Sglass 156af77c1caSglass #define ECOFF_ROUND(value, by) \ 1570f1b3e09Scgd (((value) + (by) - 1) & ~((by) - 1)) 158af77c1caSglass 1590f1b3e09Scgd #define ECOFF_BLOCK_ALIGN(ep, value) \ 1600f1b3e09Scgd ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_ROUND((value), ECOFF_LDPGSZ) : \ 1610f1b3e09Scgd (value)) 162af77c1caSglass 1630f1b3e09Scgd #define ECOFF_TXTOFF(ep) \ 1640f1b3e09Scgd ((ep)->a.magic == ECOFF_ZMAGIC ? 0 : \ 1650f1b3e09Scgd ECOFF_ROUND(ECOFF_HDR_SIZE + (ep)->f.f_nscns * \ 1660f1b3e09Scgd sizeof(struct ecoff_scnhdr), ECOFF_SEGMENT_ALIGNMENT(ep))) 167af77c1caSglass 1680f1b3e09Scgd #define ECOFF_DATOFF(ep) \ 1690f1b3e09Scgd (ECOFF_BLOCK_ALIGN((ep), ECOFF_TXTOFF(ep) + (ep)->a.tsize)) 170af77c1caSglass 1710f1b3e09Scgd #define ECOFF_SEGMENT_ALIGN(ep, value) \ 1720f1b3e09Scgd (ECOFF_ROUND((value), ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_LDPGSZ : \ 1730f1b3e09Scgd ECOFF_SEGMENT_ALIGNMENT(ep)))) 1747890c5a8Sglass 1757c042338Sjtc #ifdef _KERNEL 17695e1ffb1Schristos int exec_ecoff_makecmds(struct lwp *, struct exec_package *); 17795e1ffb1Schristos int cpu_exec_ecoff_probe(struct lwp *, struct exec_package *); 1786a9e4e8eSmatt void cpu_exec_ecoff_setregs(struct lwp *, struct exec_package *, vaddr_t); 179e85db685Scgd 18002cdf4d2Sdsl int exec_ecoff_prep_omagic(struct lwp *, struct exec_package *, 18102cdf4d2Sdsl struct ecoff_exechdr *, struct vnode *); 18202cdf4d2Sdsl int exec_ecoff_prep_nmagic(struct lwp *, struct exec_package *, 18302cdf4d2Sdsl struct ecoff_exechdr *, struct vnode *); 18402cdf4d2Sdsl int exec_ecoff_prep_zmagic(struct lwp *, struct exec_package *, 18502cdf4d2Sdsl struct ecoff_exechdr *, struct vnode *); 186e85db685Scgd 1877c042338Sjtc #endif /* _KERNEL */ 1887890c5a8Sglass #endif /* !_SYS_EXEC_ECOFF_H_ */ 189