summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/BiosCommonCode/commondefs.inc
blob: dcd9edfd98a6783296da1f4341f623ebf29df16b (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
; $Id: commondefs.inc $
;; @file
; Stuff for drawing the BIOS logo.
;

;
; Copyright (C) 2004-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>.
;
; SPDX-License-Identifier: GPL-3.0-only
;


;; Switches back to default CPU mode.
SET_DEFAULT_CPU macro
 if VBOX_BIOS_CPU eq 8086
        .8086
 elseif VBOX_BIOS_CPU eq 80186
        .186
 elseif VBOX_BIOS_CPU eq 80286
        .286
 elseif VBOX_BIOS_CPU eq 80386
        .386
 else
  .errnz 1, Unsupported target CPU value: VBOX_BIOS_CPU
        .386
 endif
endm


;; Switches back to default CPU mode, max 286.
SET_DEFAULT_CPU_286 macro
 if VBOX_BIOS_CPU eq 8086
        .8086
 elseif VBOX_BIOS_CPU eq 80186
        .186
 else
        .286
 endif
endm


;;
; Pretends to do a call by pushing the return address and jumping
; to the function.
;
; This is slightly problematic on 8086 since it doesn't support pushing
; word immediates. OTOH, it support pushing memory, so we'll do that
; instead when targeting 8086.
;
if 0 ;; this crap crashes wasm, makes it call exit(0), or similar weird stuff.
     ;; switched to a simpler approach where I define the one return address variable myself.
DO_JMP_CALL     macro calling, returning
 if VBOX_BIOS_CPU gt 8086
        push    returning
        jmp     calling
 else
        push    word ptr cs:[%jmp_call_addr_&returning]
        jmp     calling
;public jmp_call_addr_&returning
%jmp_call_addr_&returning: dw offset retaddr
 endif
endm

DO_JMP_CALL_AGAIN macro calling, returning
 if VBOX_BIOS_CPU gt 8086
        push    returning
        jmp     calling
 else
        push    word ptr cs:[%jmp_call_addr_&returning]
        jmp     calling
 endif
endm

else  ; Simplified.
DO_JMP_CALL_EX  macro calling, returning, returning_ptr_var
 if VBOX_BIOS_CPU gt 8086
        push    returning
        jmp     calling
  else
        push    word ptr cs:[returning_ptr_var]
        jmp     calling
  endif
endm

endif ; Simplified.


;; For handling the pusha instruction depending on target CPU.
DO_pusha        macro
 if VBOX_BIOS_CPU gt 8086
        pusha
 else
        push    ax
        push    cx
        push    dx
        push    bx
        push    sp
        push    bp
        push    si
        push    di
 endif
endm


;; For handling the popad/popa instruction depending on target CPU.
DO_popa         macro
 if VBOX_BIOS_CPU gt 8086
        popa
 else
        pop     di
        pop     si
        pop     bp
        pop     bx ;pop sp
        pop     bx
        pop     dx
        pop     cx
        pop     ax
 endif
endm


;; For handling the pushad/pusha instruction depending on target CPU.
DO_PUSHAD       macro
 if VBOX_BIOS_CPU ge 80386
        pushad
 elseif VBOX_BIOS_CPU gt 8086
        pusha
 else
        push    ax
        push    cx
        push    dx
        push    bx
        push    sp
        push    bp
        push    si
        push    di
 endif
endm


;; For handling the popad/popa instruction depending on target CPU.
DO_POPAD        macro
 if VBOX_BIOS_CPU ge 80386
        popad
 elseif VBOX_BIOS_CPU gt 8086
        popa
 else
        pop     di
        pop     si
        pop     bp
        pop     bx ;pop sp
        pop     bx
        pop     dx
        pop     cx
        pop     ax
 endif
endm


;; ASSUMES working stack.
DO_shr          macro reg, count
 if VBOX_BIOS_CPU ge 80186
        shr     reg, count
 else
  if count ge 6
        push    cx
        mov     cl, count
        shr     reg, cl
        pop     cx
  else
   if count ge 5
        shr     reg, 1
   endif
   if count ge 4
        shr     reg, 1
   endif
   if count ge 3
        shr     reg, 1
   endif
   if count ge 2
        shr     reg, 1
   endif
   if count ge 1
        shr     reg, 1
   endif
  endif
 endif
endm


;; ASSUMES working stack.
DO_shl          macro reg, count
 if VBOX_BIOS_CPU ge 80186
        shl     reg, count
 else
  if count ge 6
        push    cx
        mov     cl, count
        shl     reg, cl
        pop     cx
  else
   if count ge 5
        shl     reg, 1
   endif
   if count ge 4
        shl     reg, 1
   endif
   if count ge 3
        shl     reg, 1
   endif
   if count ge 2
        shl     reg, 1
   endif
   if count ge 1
        shl     reg, 1
   endif
  endif
 endif
endm




;; Adds a special label that will have its address checked after linking.
BIOSORG_CHECK macro addr
public biosorg_check_at_&addr
biosorg_check_at_&addr:
        endm

;; Adds a special label that will have its address checked after linking.
BIOSORG_CHECK_BEFORE macro addr
public biosorg_check_before_or_at_&addr
biosorg_check_before_or_at_&addr:
        endm