1 | ; $Id: bs3-cmn-PrintStrN.asm 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; BS3Kit - Bs3PrintStrN.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2007-2022 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 |
|
---|
38 | ;*********************************************************************************************************************************
|
---|
39 | ;* Header Files *
|
---|
40 | ;*********************************************************************************************************************************
|
---|
41 | %include "bs3kit-template-header.mac"
|
---|
42 |
|
---|
43 |
|
---|
44 | ;*********************************************************************************************************************************
|
---|
45 | ;* External Symbols *
|
---|
46 | ;*********************************************************************************************************************************
|
---|
47 | %if TMPL_BITS == 16
|
---|
48 | BS3_EXTERN_DATA16 g_bBs3CurrentMode
|
---|
49 | %endif
|
---|
50 | BS3_EXTERN_CMN Bs3Syscall
|
---|
51 |
|
---|
52 |
|
---|
53 | TMPL_BEGIN_TEXT
|
---|
54 |
|
---|
55 | ;;
|
---|
56 | ; @cproto BS3_DECL(void) Bs3PrintStrN_c16(const char BS3_FAR *pszString, size_t cchString);
|
---|
57 | ;
|
---|
58 | ; ASSUMES cchString < 64KB!
|
---|
59 | ;
|
---|
60 | BS3_PROC_BEGIN_CMN Bs3PrintStrN, BS3_PBC_NEAR
|
---|
61 | BS3_CALL_CONV_PROLOG 2
|
---|
62 | push xBP
|
---|
63 | mov xBP, xSP
|
---|
64 | push xAX
|
---|
65 | push xCX
|
---|
66 | push xBX
|
---|
67 | push xSI
|
---|
68 |
|
---|
69 | %if TMPL_BITS == 16
|
---|
70 | ; If we're in real mode or v8086 mode, call the VGA BIOS directly.
|
---|
71 | mov bl, [g_bBs3CurrentMode]
|
---|
72 | cmp bl, BS3_MODE_RM
|
---|
73 | je .do_bios_call
|
---|
74 | %if 0
|
---|
75 | test bl, BS3_MODE_CODE_V86
|
---|
76 | jz .do_system_call
|
---|
77 | %else
|
---|
78 | jmp .do_system_call
|
---|
79 | %endif
|
---|
80 |
|
---|
81 | ;
|
---|
82 | ; We can do the work right here.
|
---|
83 | ;
|
---|
84 | .do_bios_call:
|
---|
85 | push ds
|
---|
86 | lds si, [xBP + xCB + cbCurRetAddr] ; DS:SI -> string.
|
---|
87 | cld
|
---|
88 | mov cx, [xBP + xCB + cbCurRetAddr + sCB] ; Use CX for counting down.
|
---|
89 | call Bs3PrintStrN_c16_CX_Bytes_At_DS_SI
|
---|
90 | pop ds
|
---|
91 | jmp .return
|
---|
92 | %endif
|
---|
93 |
|
---|
94 |
|
---|
95 | ;
|
---|
96 | ; Need to do system call(s).
|
---|
97 | ; String goes into CX:xSI, count into DX.
|
---|
98 | ;
|
---|
99 | ; We must ensure the string is real-mode addressable first, if not we
|
---|
100 | ; must do it char-by-char.
|
---|
101 | ;
|
---|
102 | .do_system_call:
|
---|
103 | %if TMPL_BITS == 16
|
---|
104 | mov cx, [xBP + xCB + cbCurRetAddr + 2]
|
---|
105 | %else
|
---|
106 | mov cx, ds
|
---|
107 | %endif
|
---|
108 | mov xSI, [xBP + xCB + cbCurRetAddr]
|
---|
109 | mov dx, [xBP + xCB + cbCurRetAddr + sCB]
|
---|
110 | %if TMPL_BITS == 16
|
---|
111 |
|
---|
112 | %else
|
---|
113 | cmp xSI, _1M
|
---|
114 | jae .char_by_char
|
---|
115 | %endif
|
---|
116 | mov ax, BS3_SYSCALL_PRINT_STR
|
---|
117 | call Bs3Syscall ; near! no BS3_CALL!
|
---|
118 |
|
---|
119 | .return:
|
---|
120 | pop xSI
|
---|
121 | pop xBX
|
---|
122 | pop xCX
|
---|
123 | pop xAX
|
---|
124 | pop xBP
|
---|
125 | BS3_CALL_CONV_EPILOG 2
|
---|
126 | BS3_HYBRID_RET
|
---|
127 |
|
---|
128 | ;
|
---|
129 | ; Doesn't look like it's real-mode addressable. So, char-by-char.
|
---|
130 | ;
|
---|
131 | .char_by_char:
|
---|
132 | %if TMPL_BITS == 16
|
---|
133 | push es
|
---|
134 | mov es, cx
|
---|
135 | %endif
|
---|
136 | cld
|
---|
137 | test dx, dx
|
---|
138 | jz .char_by_char_return
|
---|
139 | .char_by_char_loop:
|
---|
140 | mov ax, BS3_SYSCALL_PRINT_CHR
|
---|
141 | mov cl, [BS3_ONLY_16BIT(es:) xSI]
|
---|
142 | call Bs3Syscall ; near! no BS3_CALL!
|
---|
143 | inc xSI
|
---|
144 | dec xDX
|
---|
145 | jnz .char_by_char_loop
|
---|
146 | .char_by_char_return:
|
---|
147 | %if TMPL_BITS == 16
|
---|
148 | pop es
|
---|
149 | %endif
|
---|
150 | jmp .return
|
---|
151 |
|
---|
152 | BS3_PROC_END_CMN Bs3PrintStrN
|
---|
153 |
|
---|
154 |
|
---|
155 | %if TMPL_BITS == 16
|
---|
156 | ;
|
---|
157 | ; This code is shared with the system handler.
|
---|
158 | ;
|
---|
159 | ; @param CX Number of byte sto print.
|
---|
160 | ; @param DS:SI The string to print
|
---|
161 | ; @uses AX, BX, CX, SI
|
---|
162 | ;
|
---|
163 | BS3_PROC_BEGIN Bs3PrintStrN_c16_CX_Bytes_At_DS_SI
|
---|
164 | CPU 8086
|
---|
165 | ; Check if CX is zero first.
|
---|
166 | test cx, cx
|
---|
167 | jz .bios_loop_done
|
---|
168 |
|
---|
169 | ; The loop, processing the string char-by-char.
|
---|
170 | .bios_loop:
|
---|
171 | mov bx, 0ff00h
|
---|
172 | lodsb ; al = next char
|
---|
173 | cmp al, 0ah ; \n
|
---|
174 | je .bios_loop_newline
|
---|
175 | %ifdef BS3_STRICT
|
---|
176 | test al, al
|
---|
177 | jnz .not_zero
|
---|
178 | hlt
|
---|
179 | .not_zero:
|
---|
180 | %endif
|
---|
181 | mov ah, 0eh
|
---|
182 | .bios_loop_int10h:
|
---|
183 | int 10h
|
---|
184 | loop .bios_loop
|
---|
185 | .bios_loop_done:
|
---|
186 | ret
|
---|
187 |
|
---|
188 | .bios_loop_newline:
|
---|
189 | mov ax, 0e0dh ; cmd + '\r'.
|
---|
190 | int 10h
|
---|
191 | mov ax, 0e0ah ; cmd + '\n'.
|
---|
192 | mov bx, 0ff00h
|
---|
193 | jmp .bios_loop_int10h
|
---|
194 | BS3_PROC_END Bs3PrintStrN_c16_CX_Bytes_At_DS_SI
|
---|
195 |
|
---|
196 |
|
---|
197 | ;
|
---|
198 | ; Generate 16-bit far stub.
|
---|
199 | ; Peformance critical, so don't penalize near calls.
|
---|
200 | ;
|
---|
201 | BS3_CMN_FAR_STUB Bs3PrintStrN, 6
|
---|
202 |
|
---|
203 | %endif
|
---|
204 |
|
---|