Merge from vendor branch LIBSTDC++:
[dragonfly.git] / sys / boot / pc32 / kgzldr / crt.s
1 #
2 # Copyright (c) 1999 Global Technology Associates, Inc.
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
18 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20 # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #
26 #       From: btx.s 1.10 1999/02/25 16:27:41 rnordier
27 # $FreeBSD: src/sys/boot/i386/kgzldr/crt.s,v 1.4 2002/09/17 01:48:55 peter Exp $
28 # $DragonFly: src/sys/boot/pc32/kgzldr/crt.s,v 1.3 2003/11/10 06:08:35 dillon Exp $
29 #
30
31 # Screen defaults and assumptions.
32
33                 .set SCR_MAT,0x7                # Mode/attribute
34                 .set SCR_COL,0x50               # Columns per row
35                 .set SCR_ROW,0x19               # Rows per screen
36
37 # BIOS Data Area locations.
38
39                 .set BDA_SCR,0x449              # Video mode
40                 .set BDA_POS,0x450              # Cursor position
41
42                 .globl crt_putchr
43
44 # void crt_putchr(int c)
45
46 crt_putchr:     movb 0x4(%esp,1),%al            # Get character
47                 pusha                           # Save
48                 xorl %ecx,%ecx                  # Zero for loops
49                 movb $SCR_MAT,%ah               # Mode/attribute
50                 movl $BDA_POS,%ebx              # BDA pointer
51                 movw (%ebx),%dx                 # Cursor position
52                 movl $0xb8000,%edi              # Regen buffer (color)
53                 cmpb %ah,BDA_SCR-BDA_POS(%ebx)  # Mono mode?
54                 jne crt_putchr.1                # No
55                 xorw %di,%di                    # Regen buffer (mono)
56 crt_putchr.1:   cmpb $0xa,%al                   # New line?
57                 je crt_putchr.2                 # Yes
58                 xchgl %eax,%ecx                 # Save char
59                 movb $SCR_COL,%al               # Columns per row
60                 mulb %dh                        #  * row position
61                 addb %dl,%al                    #  + column
62                 adcb $0x0,%ah                   #  position
63                 shll %eax                       #  * 2
64                 xchgl %eax,%ecx                 # Swap char, offset
65                 movw %ax,(%edi,%ecx,1)          # Write attr:char
66                 incl %edx                       # Bump cursor
67                 cmpb $SCR_COL,%dl               # Beyond row?
68                 jb crt_putchr.3                 # No
69 crt_putchr.2:   xorb %dl,%dl                    # Zero column
70                 incb %dh                        # Bump row
71 crt_putchr.3:   cmpb $SCR_ROW,%dh               # Beyond screen?
72                 jb crt_putchr.4                 # No
73                 leal 2*SCR_COL(%edi),%esi       # New top line
74                 movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move
75                 rep                             # Scroll
76                 movsl                           #  screen
77                 movb $' ',%al                   # Space
78                 movb $SCR_COL,%cl               # Columns to clear
79                 rep                             # Clear
80                 stosw                           #  line
81                 movb $SCR_ROW-1,%dh             # Bottom line
82 crt_putchr.4:   movw %dx,(%ebx)                 # Update position
83                 popa                            # Restore
84                 ret                             # To caller