summaryrefslogtreecommitdiffstats
path: root/include/iprt/solaris/kmoddeps.mac
blob: e1cf1b20d4560d2f45c193f0e612da2b9dcdb951 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
; $Id: kmoddeps.mac $
;; @file
; Assembly macros for generating Solaris kernel module dependencies
;

;
; Copyright (C) 2012-2023 Oracle and/or its affiliates.
;
; This file is part of VirtualBox base platform packages, as
; available from https://www.virtualbox.org.
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation, in version 3 of the
; License.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, see <https://www.gnu.org/licenses>.
;
; The contents of this file may alternatively be used under the terms
; of the Common Development and Distribution License Version 1.0
; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
; in the VirtualBox distribution, in which case the provisions of the
; CDDL are applicable instead of those of the GPL.
;
; You may elect to license modified versions of this file under the
; terms and conditions of either the GPL or the CDDL or both.
;
; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
;

; Solaris kernel modules use non-standard ELF constructions to express inter-
; module dependencies, namely a DT_NEEDED tag inside a relocatable ELF file.
; The Solaris linker can generate these automatically; since yasm can't
; produce an ELF file which quite fits Solaris's requirements we create one
; manually using flat binary output format.  In order to save unnecessary
; repetition, this file defines macros for the repetitive bits which can be
; reused by the actual dependency objects.  Certainly not the nicest way to
; get the effect we want, but probably a reasonable compromise between
; cleanness and required effort.
;

%ifdef RT_ARCH_AMD64

BITS 64
;;
; Native word size
%define DNAT dq

;;
; ELF machine number for the current architecture.
%define EM_CUR 62 ; EM_X86_64

;;
; ELF header class for the current architecture.
%define CLASS 2

%else

BITS 32
%define DNAT dd
%define EM_CUR 3 ; EM_386
%define CLASS 1

%endif

;;
; ELF file header, section tables and shared string table for the dependency
; object.
%macro kmoddeps_header 0
elf_hdr:            ; elfxx_hdr structure
 db 7fh, "ELF"      ; e_ident
 db CLASS, 1, 1     ; e_ident
 times 9 db 0       ; padding
 dw 1               ; e_type ET_REL
 dw EM_CUR          ; e_machine
 dd 1               ; e_version EV_CURRENT
 DNAT 0             ; e_entry
 DNAT 0             ; e_phoff
 DNAT sect_hdr - $$ ; e_shoff
 dd 0               ; e_flags
 dw elf_hsize       ; e_ehsize
 dw 0               ; e_phentsize
 dw 0               ; e_phnum
 dw sect_hsize      ; e_shentsize
 dw 4               ; e_shnum
 dw 1               ; e_shstrndx section .shstrtab
elf_hsize equ $ - elf_hdr

sect_hdr:              ; elfxx_shdr structure
 times sect_hsize db 0 ; undefined section

sect_hdr1:
 dd str_shstrtab       ; sh_name .shstrtab
 dd 3                  ; sh_type SHT_STRTAB
 DNAT 20h              ; sh_flags SHF_STRINGS
 DNAT 0                ; sh_addr
 DNAT shstrtab - $$    ; sh_offset
 DNAT shstrtab_size    ; sh_size
 dd 0                  ; sh_link
 dd 0                  ; sh_info
 DNAT 1                ; sh_addralign
 DNAT 0                ; sh_entsize
sect_hsize equ $ - sect_hdr1

 dd str_dynstr         ; sh_name .dynstr
 dd 3                  ; sh_type SHT_STRTAB
 DNAT 20h              ; sh_flags SHF_STRINGS
 DNAT 0                ; sh_addr
 DNAT dynstr - $$      ; sh_offset
 DNAT dynstr_size      ; sh_size
 dd 0                  ; sh_link
 dd 0                  ; sh_info
 DNAT 1                ; sh_addralign
 DNAT 0                ; sh_entsize

 dd str_dynamic        ; sh_name .dynamic
 dd 6                  ; sh_type SHT_DYNAMIC
 DNAT 1                ; sh_flags SHF_WRITE
 DNAT 0                ; sh_addr
 DNAT dynamic - $$     ; sh_offset
 DNAT dynamic_size     ; sh_size
 dd 2                  ; sh_link .dynstr
 dd 0                  ; sh_info
 DNAT 8                ; sh_addralign
 DNAT 0                ; sh_entsize

shstrtab:
str_shstrtab equ $ - shstrtab
 db ".shstrtab", 0
str_dynstr equ $ - shstrtab
 db ".dynstr", 0
str_dynamic equ $ - shstrtab
 db ".dynamic", 0
shstrtab_size equ $ - shstrtab
%endmacro  ; kmoddeps_header

;;
; Start of the .dynstr section for the dependency object.
%macro kmoddeps_dynstr_start 0
dynstr:
 db 0
%endmacro

;;
; A .dynstr string entry for the dependency object.
; The parameters are a symbolic name for the string and the string itself.
%macro kmoddeps_dynstr_string 2
dynstr_name_%1 equ $ - dynstr
 db %2, 0
%endmacro

;;
; End of the .dynstr section for the dependency object.
%macro kmoddeps_dynstr_end 0
dynstr_size equ $ - dynstr
%endmacro

;;
; Start of the .dynamic section for the dependency object.
%macro kmoddeps_dynamic_start 0
dynamic:
%endmacro

;;
; A .dynamic DT_NEEDED entry for the dependency object.
; The parameter is a symbolic string name previously defined using
; @a kmoddeps_dynstr_string.
%macro kmoddeps_dynamic_needed 1
 DNAT 1            ; DT_NEEDED
 DNAT dynstr_name_%1
%endmacro

;;
; End of the .dynamic section for the dependency object.
%macro kmoddeps_dynamic_end 0
 DNAT 1ah          ; DT_FLAGS
 DNAT 4            ; TEXTREL
 DNAT 6ffffffbh    ; DT_FLAGS1
 DNAT 0
 DNAT 601900h      ; SUNW_STRPAD
 DNAT 200h
 DNAT 601b00h      ; SUNW_LDMACH
 DNAT 62           ; EM_X86_64
 times 22 DNAT 0   ; padding
dynamic_size equ $ - dynamic
%endmacro  ; kmoddeps_dynamic_end