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