Add externs to avoid multiple definitions, and then add missing definitions.
[rrq/maintain_lilo.git] / src / biosdata.S
1 ;  biosdata.S
2 ;
3 ;  Copyright 2002-2004 John Coffman
4 ;  Copyright 2009-2011 Joachim Wiedorn
5 ;  All rights reserved.
6 ;
7 ;  Licensed under the terms contained in the file 'COPYING'
8 ;  in the source directory.
9 ;
10
11
12 io_sig: .long   0               ; space for CRC
13         .ascii  PROBE_SIGNATURE ; "LiLo"
14         .word   PROBE_VERSION   ; sanity check
15 io_lth: .word   0               ; byte count overall
16 io_good_disk:
17         .byte   0       ; last good drive (in low byte)
18         .byte   BD_GET_VIDEO
19         .byte   BD_MAX_FLOPPY
20         .byte   BD_MAX_HARD
21 io_flp: .word   0
22 io_hrd: .word   0
23 io_pt:  .word   0
24
25 #if PROBE_VERSION >= 5
26 io_eqp: .word   0
27 io_vid: .word   0
28 #endif
29
30 io_l_sig        = *-io_sig
31
32 ; read partition table of device in DL
33 ;
34 ; save PT
35 ;
36 io_get_pt:
37         push    ds
38         push    es
39
40         push    #0
41         pop     es
42         mov     bx,#BOOTSEG*16+SECTOR_SIZE
43         mov     cx,#1
44         mov     dh,#0
45         mov     ax,#0x201               ; read 1 sector
46 #ifdef BD_VERBOSE
47         pusha
48         call    say
49         .ascii  "Read partition table\n"
50         .byte   0
51         popa
52 #endif
53         call    dsk_do_rw               ; make 5 tries
54         push    es
55         pop     ds
56
57         pop     es
58 #if  PROBE_VERSION == 3
59         lea     si,(bx+PART_TABLE_OFFSET)
60         mov     cx,#4*16
61 #elif  PROBE_VERSION >= 4
62         lea     si,(bx+PART_TABLE_OFFSET-8)
63         mov     cx,#4*16+8
64 #endif
65         jc      io_get_pt_err
66         rep
67           movsb
68 io_get_pt_ret:
69         pop     ds
70         ret
71
72 io_get_pt_err:
73         mov     al,#-1
74         rep
75           stosb
76         jmp     io_get_pt_ret
77
78
79
80 ; check a hard drive for EDD support
81 ;
82 ;       device code is in DL
83 ;
84 ;
85 io_do_edd_check:
86         push    dx
87         mov     ah,#0x41
88         mov     bx,#0x55AA
89 #ifdef BD_VERBOSE
90         pusha
91         call    say
92         .ascii  "Check EDD present\n"
93         .byte   0
94         popa
95 #endif
96         int     0x13
97
98         xchg    al,ah
99         lahf
100         pop     dx
101
102         stosw
103         mov     ax,bx
104         stosw
105         xchg    ax,cx
106         stosw
107
108         jc      io_do_edd_check_ret
109         cmp     bx,#0xAA55
110         jne     io_do_edd_check_ret
111 #if PROBE_VERSION < 6
112         test    al,#EDD_SUBSET  ; test for EDD call supported
113         jz      io_do_edd_check_ret
114 #endif
115
116 ; get the EDD parameters
117
118         push    dx              ; paranoia, protect DL
119         push    es              ; more paranoia
120         push    ds
121
122         push    es
123         pop     ds
124         mov     si,di           ; DS:SI points at return area
125         push    di
126         mov     ah,#0x48
127         mov     word (si),#EDD_LTH      ; set max count to return
128 #ifdef BD_VERBOSE
129         pusha
130         call    say
131         .ascii  "Get EDD parameters\n"
132         .byte   0
133         popa
134 #endif
135         int     0x13
136         pop     di
137
138         xchg    al,ah
139         lahf
140         
141         add     di,#EDD_LTH
142         stosw                   ; save the return flags
143
144         pop     ds
145         pop     es
146         pop     dx
147
148 io_do_edd_check_ret:
149         ret
150
151
152
153 ;
154 ; io_biosdata:  examine hard disk BIOS devices
155 ;               and video state
156 ;
157 ;  Enter with:
158 ;               DS == CS
159 ;               direction flag clear
160 ;
161 ;
162 ;  Exit with:
163 ;               All registers preserved
164 ;               
165 ;               Side effect is to write the low memory disk data area
166 ;
167 ;
168 ;
169
170 io_biosdata:
171         pusha                   ;save all registers
172         push    es
173
174         push    #PROBESEG       ;save area is at 0060:0000 (0x000600)
175         pop     es
176         mov     di,#io_l_sig    ;skip over header area
177
178 ; get the equipment configuration flags
179
180 #if PROBE_VERSION >= 5
181         mov     io_eqp,di       ;save equipment pointer
182         push    dx              ; protect this register
183 #endif
184 #ifdef BD_VERBOSE
185         pusha
186         call    say
187         .ascii  "Get equipment configuration\n"
188         .byte   0
189         popa
190 #endif
191         int     0x11
192         stosw
193
194 ; get the conventional memory size
195
196 #ifdef BD_VERBOSE
197         pusha
198         call    say
199         .ascii  "Get conventional memory size\n"
200         .byte   0
201         popa
202 #endif
203         int     0x12
204         stosw                   ; save the number
205
206 #if PROBE_VERSION >= 5
207 #ifdef BD_VERBOSE
208         pusha
209         call    say
210         .ascii  "Save boot device code\n"
211         .byte   0
212         popa
213 #endif
214         pop     ax              ; get saved DX register
215         stosw                   
216 #endif
217
218 ; collect the video information
219
220 #if PROBE_VERSION >= 5
221         mov     io_vid,di       ; set the pointer
222 #endif
223 #if BD_GET_VIDEO >= 1
224         mov     ah,#0x0F        ; get video mode
225 #ifdef BD_VERBOSE
226         pusha
227         call    say
228         .ascii  "Get video mode\n"
229         .byte   0
230         popa
231 #endif
232         int     0x10
233
234         push    ds
235         push    #0x40
236         pop     ds
237         mov     bl,[0x84]       ; get rows, too
238         pop     ds
239
240         stosw                   ; save AX
241         xchg    ax,bx
242         stosw                   ; save BX
243         cmp     bl,#7           ; is it MDA
244         beq     io_floppies     ; yup, skip it all
245         cmp     bh,#80          ; number of columns on screen
246         jb      io_floppies1    ; probably CGA
247
248 #endif
249 #if BD_GET_VIDEO >= 2
250 #if 1
251         mov     ah,#0x12
252         mov     bx,#0xFF10      ; get configuration information
253 #ifdef BD_VERBOSE
254         pusha
255         call    say
256         .ascii  "Get video configuration\n"
257         .byte   0
258         popa
259 #endif
260         int     0x10
261
262         stosw                   ; save AX
263         xchg    ax,bx
264         stosw                   ; save BX
265         cmp     ah,#1
266         ja      io_floppies1
267
268 #endif
269         mov     ax,#0x1A00      ; get display combination code
270 #ifdef BD_VERBOSE
271         pusha
272         call    say
273         .ascii  "Get display combination\n"
274         .byte   0
275         popa
276 #endif
277         int     0x10
278
279         stosw                   ; save AX
280         xchg    ax,bx
281         stosw                   ; save BX
282         cmp     bl,#0x1A        ; is function supported?
283 #ifndef BD_VERBOSE
284         jne     io_floppies
285 #else
286         bne     io_floppies
287 io_floppies1    equ     *-3
288 #endif
289         cmp     al,#4
290         jb      io_floppies1
291
292 #if PROBE_VERSION >= 5
293
294 ; test to see if registers get trashed (some geforce video bios trashes dx)
295         push    ds
296         push    es
297         push    di
298
299         mov     cx,#0x1234
300         mov     dx,#0x5680
301         mov     bp,#0x4321
302
303         mov     ax,#0x1200
304         mov     bx,#0x0036
305 #ifdef BD_VERBOSE
306         pusha
307         call    say
308         .ascii  "Enable Screen Refresh\n"
309         .byte   0
310         popa
311 #endif
312         int     0x10            ; enable screen refresh
313
314         pop     di
315         pop     es
316         pop     ds
317         stosw                   ; AX
318         xchg    ax,cx
319         stosw                   ; CX
320         xchg    ax,dx
321         stosw                   ; DX
322         xchg    ax,bp
323         stosw                   ; BP
324 #endif
325
326 #endif  /* BD_GET_VIDEO >= 2 */
327
328 #if BD_GET_VIDEO >= 3
329         mov     ax,#0x4F00      ; check VESA present
330 ; ES:DI is already set
331 #ifdef BD_VERBOSE
332         pusha
333         call    say
334         .ascii  "Check VESA present\n"
335         .byte   0
336         popa
337 #endif
338         int     0x10
339
340         seg es
341           mov   bx,(di)         ; possible "VE"
342         seg es
343           mov   cx,(di+2)       ; possible "SA"
344         stosw                   ; save AX
345         xchg    ax,bx
346         stosw                   ; possible "VE"
347         xchg    ax,cx           ; possible "SA"
348         stosw
349         cmp     bx,#0x004F      ; good return
350         jne     io_floppies
351         cmp     cx,#0x4556      ; "VE"
352         jne     io_floppies
353         cmp     ax,#0x4153      ; "SA"
354         jne     io_floppies
355         
356         mov     ax,#0x4F01
357         mov     cx,#0x0101      ; get mode information
358 #ifdef BD_VERBOSE
359         pusha
360         call    say
361         .ascii  "Get VESA mode information 1\n"
362         .byte   0
363         popa
364 #endif
365         int     0x10    
366
367         seg es
368           mov   bx,(di)         ; get bits
369         stosw                   ; save AX
370         xchg    ax,bx
371         stosw                   ; save bits
372
373         mov     ax,#0x4F01
374         mov     cx,#0x0103      ; get mode information
375 #ifdef BD_VERBOSE
376         pusha
377         call    say
378         .ascii  "Get VESA mode information 3\n"
379         .byte   0
380         popa
381 #endif
382         int     0x10    
383
384         seg es
385           mov   bx,(di)         ; get bits
386         stosw                   ; save AX
387         xchg    ax,bx
388         stosw                   ; save bits
389 #else
390         mov     ax,#-1          ; flag for VESA not present
391         stosw
392         stosw
393         stosw
394 ;       jmp     io_floppies     ; exit to this point
395 #endif
396
397 ; now go after the disk drive information
398
399 io_floppies:
400 #ifndef BD_VERBOSE
401 io_floppies1:
402 #endif
403         mov     cx,#BD_MAX_FLOPPY       ;test 4 floppies
404         xor     dx,dx
405         mov     io_flp,di               ;set pointer to floppy info
406
407 io_next_drive:
408         push    cx
409
410 ; get the drive type
411
412         mov     ah,#0x15
413         push    dx
414 #ifdef BD_VERBOSE
415         pusha
416         test    dl,#3           ; pause every 4th drive
417         jnz     io_no_pause
418         call    pause
419 io_no_pause:
420         call    say
421         .ascii  "Get drive type "
422         .byte   0
423         mov     al,dl
424         call    bout
425         call    say
426         .byte   10,0
427         popa
428 #endif
429         int     0x13
430
431         xchg    al,ah           ;code to AL
432         lahf                    ;flags to AH
433
434         stosw                   ; save AX
435         xchg    ax,dx
436         stosw                   ; save DX (low order)
437         xchg    ax,cx
438         stosw                   ; save CX (high order)
439         xchg    ax,dx           ; restore code to AL
440         pop     dx
441
442         jc      io_no_disk      ; error means no disk present
443         dec     al              ; AL==0 means no disk present
444         jns     io_get_param    ; if S=0, some disk type is present
445
446 io_no_disk:
447         or      dl,dl
448         jns     io_get_param    ;do it all on floppies
449
450         pop     cx              ;premature loop termination
451         jmp     io_loop_end     ;skip the rest on fixed disks
452
453 io_get_param:
454
455 ; get drive parameters
456
457         push    dx
458         push    es              ; supposedly clobbered for floppies only
459         push    di              ; do not trust anyone
460
461         mov     ah,#0x08
462 #ifdef BD_VERBOSE
463         pusha
464         call    say
465         .ascii  "Get drive parameters\n"
466         .byte   0
467         popa
468 #endif
469         int     0x13
470         xchg    al,ah
471         lahf
472         
473         mov     bp,di           ; save floppy param pointer
474         mov     bx,es
475
476         pop     di
477         pop     es
478
479         stosw                   ; save return code & flags
480         xchg    ax,cx
481         stosw
482         xchg    ax,dx
483         stosw
484         pop     dx
485
486         jc      io_fh_check     ; bad return above
487 ;;;     mov     [io_good_disk],dl       ; save DL
488
489         cmp     dl,#0x80        ; check for first HD
490         jne     io_fh_check
491         cbw                     ; former DL has disk count
492         pop     cx              ; get HD count
493         push    ax              ; set new HD count
494
495 io_fh_check:
496         or      dl,dl           ; check floppy/hard disk
497         js      io_check_edd
498         xchg    ax,bp           ; was DI
499         stosw
500         xchg    ax,bx           ; was ES
501         stosw
502         jmp     io_skip_edd
503
504 ; check EDD extensions present
505
506 io_check_edd:
507
508         call    io_do_edd_check
509
510 io_skip_edd:
511
512         mov     [io_good_disk],dl       ;save last disk checked
513         pop     cx
514         inc     dl
515 #ifndef BD_VERBOSE
516         loop    io_next_drive
517 #else
518         dec     cx
519         bne     io_next_drive
520 #endif
521 io_loop_end:
522         or      dl,dl           ; set the S flag
523         push    di              ;
524         mov     cx,#BD_MAX_HARD ; do not touch flags ***
525         mov     dl,#0x80        ; do not touch flags ***
526 #ifndef BD_VERBOSE
527         jns     io_next_drive   ; do the hard drives if not done
528 #else
529         bpl     io_next_drive
530 #endif
531         pop     word [io_pt]    ; save pt pointer
532         pop     word [io_hrd]   ; save hd pointer
533
534 ; now save the partition tables
535         
536 io_get: 
537         cmp     dl,io_good_disk
538         ja      io_got
539         call    io_get_pt
540         inc     dx
541         jmp     io_get
542 io_got:
543
544 io_checksum_it:
545
546 ; now must record and checksum the results
547
548         mov     io_lth,di               ; address of end is overall count
549
550         push    di
551         xor     di,di                   ;move to here
552         mov     si,#io_sig              ;move from here
553         mov     cx,#io_l_sig            ;this number of bytes
554         rep
555           movsb                         ;
556         pop     di
557         mov     si,#4                   ; skip long at beginning
558         sub     di,si
559 #ifndef BD_VERBOSE
560         push    dword #CRC_POLY1
561         call    crc32
562
563         seg     es
564         mov     [0],eax                 ; save that crc
565 #endif
566
567 ; restore the registers and return
568
569         pop     es
570         popa
571         ret
572
573 ; end biosdata.S