Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / sparc / krtld / kobj_isa.c
bloba4074f7998dc84900172b322c7d6747292e8ad09
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1994-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Miscellaneous ISA-specific code.
32 #include <sys/types.h>
33 #include <sys/elf.h>
34 #include <sys/kobj.h>
35 #include <sys/kobj_impl.h>
36 #include <sys/archsystm.h>
38 extern int use_iflush;
41 * Check that an ELF header corresponds to this machine's
42 * instruction set architecture. Used by kobj_load_module()
43 * to not get confused by a misplaced driver or kernel module
44 * built for a different ISA.
46 int
47 elf_mach_ok(Ehdr *h)
50 * XX64 This should eventually be folded into a v9-isa specific file
52 return (h->e_ident[EI_DATA] == ELFDATA2MSB &&
53 (h->e_machine == EM_SPARCV9));
58 * return non-zero for a bad-address
60 int
61 kobj_addrcheck(void *xmp, caddr_t adr)
63 struct module *mp;
65 mp = (struct module *)xmp;
67 if ((adr >= mp->text && adr < mp->text + mp->text_size) ||
68 (adr >= mp->data && adr < mp->data + mp->data_size))
69 return (0); /* ok */
70 if (mp->bss && adr >= (caddr_t)mp->bss &&
71 adr < (caddr_t)mp->bss + mp->bss_size)
72 return (0);
73 return (1);
77 * Flush instruction cache after updating text
79 void
80 kobj_sync_instruction_memory(caddr_t addr, size_t len)
82 caddr_t eaddr = addr + len;
84 if (!use_iflush)
85 return;
87 addr = (caddr_t)((uintptr_t)addr & -8l); /* sparc needs 8-byte align */
89 while (addr < eaddr) {
90 doflush(addr);
91 addr += 8;
96 * Calculate memory image required for relocatable object.
98 /* ARGSUSED3 */
99 int
100 get_progbits_size(struct module *mp, struct proginfo *tp, struct proginfo *dp,
101 struct proginfo *sdp)
103 struct proginfo *pp;
104 uint_t shn;
105 Shdr *shp;
108 * loop through sections to find out how much space we need
109 * for text, data, (also bss that is already assigned)
111 for (shn = 1; shn < mp->hdr.e_shnum; shn++) {
112 shp = (Shdr *)(mp->shdrs + shn * mp->hdr.e_shentsize);
113 if (!(shp->sh_flags & SHF_ALLOC))
114 continue;
115 if (shp->sh_addr != 0) {
116 _kobj_printf(ops,
117 "%s non-zero sect addr in input file\n",
118 mp->filename);
119 return (-1);
121 pp = (shp->sh_flags & SHF_WRITE)? dp : tp;
123 if (shp->sh_addralign > pp->align)
124 pp->align = shp->sh_addralign;
125 pp->size = ALIGN(pp->size, shp->sh_addralign);
126 pp->size += ALIGN(shp->sh_size, 8);
128 tp->size = ALIGN(tp->size, 8);
129 dp->size = ALIGN(dp->size, 8);
130 return (0);