ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / i386 / boot98 / video.S
1 /*      video.S
2  *
3  *  Video mode setup, etc. for NEC PC-9800 series.
4  *
5  *  Copyright (C) 1997,98,99  Linux/98 project  <seraphim@kmc.kyoto-u.ac.jp>
6  *
7  *  Based on the video.S for IBM PC:
8  *      copyright (C) Martin Mares <mj@atrey.karlin.mff.cuni.cz>
9  */
10
11 /* Positions of various video parameters passed to the kernel */
12 /* (see also include/linux/tty.h) */
13 #define PARAM_CURSOR_POS        0x00
14 #define PARAM_VIDEO_PAGE        0x04
15 #define PARAM_VIDEO_MODE        0x06
16 #define PARAM_VIDEO_COLS        0x07
17 #define PARAM_VIDEO_EGA_BX      0x0a
18 #define PARAM_VIDEO_LINES       0x0e
19 #define PARAM_HAVE_VGA          0x0f
20 #define PARAM_FONT_POINTS       0x10
21
22 #define PARAM_VIDEO98_COMPAT    0x0a
23 #define PARAM_VIDEO98_HIRESO    0x0b
24 #define PARAM_VIDEO98_MACHTYPE  0x0c
25 #define PARAM_VIDEO98_LINES     0x0e
26 #define PARAM_VIDEO98_COLS      0x0f
27
28 # PARAM_LFB_* and PARAM_VESAPM_* are unused on PC-9800.
29
30 # This is the main entry point called by setup.S
31 # %ds *must* be pointing to the bootsector
32 video:  xorw    %ax, %ax
33         movw    %ax, %es                        # %es = 0
34
35         movb    %es:BIOS_FLAG, %al
36         movb    %al, PARAM_VIDEO_MODE
37
38         movb    $0, PARAM_VIDEO98_HIRESO        # 0 = normal
39         movw    $NORMAL_TEXT, PARAM_VIDEO_PAGE
40         testb   $0x8, %al
41         movw    $(80 * 256 + 25), %ax
42         jz      1f
43         # hireso machine.
44         movb    $1, PARAM_VIDEO98_HIRESO        # !0 = hi-reso
45         movb    $(HIRESO_TEXT >> 8), PARAM_VIDEO_PAGE + 1
46         movw    $(80 * 256 + 31), %ax
47 1:      movw    %ax, PARAM_VIDEO98_LINES        # also sets VIDEO98_COLS
48
49         movb    $0xc0, %ch                      # 400-line graphic mode
50         movb    $0x42, %ah
51         int     $0x18
52
53         movw    $80, PARAM_VIDEO_COLS
54
55         movw    $msg_probing, %si
56         call    prtstr_cs
57
58 # Check vendor from font pattern of `A'...
59
60 1:      inb     $0x60, %al                      # wait V-sync
61         testb   $0x20, %al
62         jnz     1b
63 2:      inb     $0x60, %al
64         testb   $0x20, %al
65         jz      2b
66
67         movb    $0x00, %al                      # select font of `A'
68         outb    %al, $0xa1
69         movb    $0x41, %al
70         outb    %al, $0xa3
71
72         movw    $8, %cx
73         movw    PARAM_VIDEO_PAGE, %ax
74         cmpw    $NORMAL_TEXT, %ax
75         je      3f
76         movb    $24, %cl                        # for hi-reso machine
77 3:      addw    $0x400, %ax                     # %ax = CG window segment
78         pushw   %ds
79         movw    %ax, %ds
80         xorw    %dx, %dx                        # get sum of `A' pattern...
81         xorw    %si, %si
82 4:      lodsw
83         addw    %ax, %dx
84         loop    4b
85         popw    %ds
86
87         movw    %dx, %ax
88         movw    $msg_nec, %si
89         xorw    %bx, %bx                        # vendor info will go into %bx
90         testb   $8, %es:BIOS_FLAG
91         jnz     check_hireso_vendor
92         cmpw    $0xc7f8, %ax
93         je      5f
94         jmp     6f
95 check_hireso_vendor:
96         cmpw    $0x9639, %ax                    # XXX: NOT VERIFIED!!!
97         je      5f
98 6:      incw    %bx                             # compatible machine
99         movw    $msg_compat, %si
100 5:      movb    %bl, PARAM_VIDEO98_COMPAT
101         call    prtstr_cs
102
103         movw    $msg_fontdata, %si
104         call    prtstr_cs                       # " (CG sum of A = 0x"
105         movw    %dx, %ax
106         call    prthex
107         call    prtstr_cs                       # ") PC-98"
108
109         movb    $'0', %al
110         pushw   %ds
111         pushw   $0xf8e8
112         popw    %ds
113         cmpw    $0x2198, (0)
114         popw    %ds
115         jne     7f
116         movb    $'2', %al
117 7:      call    prtchr
118         call    prtstr_cs                       # "1 "
119
120         movb    $0, PARAM_VIDEO98_MACHTYPE
121 #if 0   /* XXX - This check is bogus? [0000:BIOS_FLAG2]-bit7 does NOT
122                  indicate whether it is a note machine, but merely indicates
123                  whether it has ``RAM drive''. */
124 # check note machine
125         testb   $0x80, %es:BIOS_FLAG2
126         jnz     is_note
127         pushw   %ds
128         pushw   $0xfd80
129         popw    %ds
130         movb    (4), %al
131         popw    %ds
132         cmpb    $0x20, %al                      # EPSON note A
133         je      epson_note
134         cmpb    $0x22, %al                      # EPSON note W
135         je      epson_note
136         cmpb    $0x27, %al                      # EPSON note AE
137         je      epson_note
138         cmpb    $0x2a, %al                      # EPSON note WR
139         jne     note_done
140 epson_note:
141         movb    $1, PARAM_VIDEO98_MACHTYPE
142         movw    $msg_note, %si
143         call    prtstr_cs
144 note_done:
145 #endif
146         
147 # print h98 ? (only NEC)
148         cmpb    $0, PARAM_VIDEO98_COMPAT
149         jnz     8f                              # not NEC -> not H98
150
151         testb   $0x80, %es:BIOS_FLAG5
152         jz      8f                              # have NESA bus -> H98
153         movw    $msg_h98, %si
154         call    prtstr_cs
155         orb     $2, PARAM_VIDEO98_MACHTYPE
156 8:      testb   $0x40, %es:BIOS_FLAG5
157         jz      9f
158         movw    $msg_gs, %si
159         call    prtstr_cs                       # only prints it :-)
160 9:
161         movw    $msg_normal, %si                # "normal"
162         testb   $0x8, %es:BIOS_FLAG
163         jz      1f
164         movw    $msg_hireso, %si
165 1:      call    prtstr_cs
166
167         movw    $msg_sysclk, %si
168         call    prtstr_cs
169         movb    $'5', %al
170         testb   $0x80, %es:BIOS_FLAG
171         jz      2f
172         movb    $'8', %al
173 2:      call    prtchr
174         call    prtstr_cs
175
176 #if 0
177         testb   $0x40, %es:(0x45c)
178         jz      no_30line                       # no 30-line support
179
180         movb    %es:KB_SHFT_STS, %al
181         testb   $0x01, %al                      # is SHIFT key pressed?
182         jz      no_30line
183
184         testb   $0x10, %al                      # is CTRL key pressed?
185         jnz     line40
186
187         # switch to 30-line mode
188         movb    $30, PARAM_VIDEO98_LINES
189         movw    $msg_30line, %si
190         jmp     3f
191
192 line40:
193         movb    $37, PARAM_VIDEO98_LINES
194         movw    $40, PARAM_VIDEO_LINES
195         movw    $msg_40line, %si
196 3:      call    prtstr_cs
197
198         movb    $0x32, %bh
199         movw    $0x300c, %ax
200         int     $0x18                           # switch video mode
201         movb    $0x0c, %ah
202         int     $0x18                           # turn on text plane
203         movw    %cs:cursor_address, %dx
204         movb    $0x13, %ah
205         int     $0x18                           # move cursor to correct place
206         mov     $0x11, %ah
207         int     $0x18                           # turn on text plane
208
209         call    prtstr_cs                       # "Ok.\r\n"
210 no_30line:
211 #endif
212         ret
213
214 prtstr_cs:
215         pushw   %ds
216         pushw   %cs
217         popw    %ds
218         call    prtstr
219         popw    %ds
220         ret
221
222 # prthex is for debugging purposes, and prints %ax in hexadecimal.
223 prthex: pushw   %cx
224         movw    $4, %cx
225 1:      rolw    $4, %ax
226         pushw   %ax
227         andb    $0xf, %al
228         cmpb    $10, %al
229         sbbb    $0x69, %al
230         das
231         call    prtchr
232         popw    %ax
233         loop    1b
234         popw    %cx
235         ret
236
237 msg_probing:    .string "Probing machine: "
238
239 msg_nec:        .string "NEC"
240 msg_compat:     .string "compatible"
241
242 msg_fontdata:   .string " (CG sum of A = 0x"
243                 .string ") PC-98"
244                 .string "1 "
245
246 msg_gs:         .string "(GS) "
247 msg_h98:        .string "(H98) "
248
249 msg_normal:     .string "normal"
250 msg_hireso:     .string "Hi-reso"
251
252 msg_sysclk:     .string " mode, system clock "
253                 .string "MHz\r\n"
254
255 #if 0
256 msg_40line:     # cpp will concat following lines, so the assembler can deal.
257                 .ascii  "\
258 Video mode will be adjusted to 37-line (so-called ``40-line'') mode later.\r\n\
259 THIS MODE MAY DAMAGE YOUR MONITOR PHYSICALLY. USE AT YOUR OWN RISK.\r\n"
260 msg_30line:     .string "Switching video mode to 30-line (640x480) mode... "
261                 .string "Ok.\r\n"
262 #endif