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