Update Basque translation for debconf
[rrq/maintain_lilo.git] / src / mapper.S
1 ;  mapper.S  -  LILO chain loader subroutine
2 ;
3 ; Copyright 2003-2004 John Coffman.
4 ; All rights reserved.
5 ;
6 ; Licensed under the terms contained in the file 'COPYING' in the 
7 ; source directory.
8 ;
9 ; Check for presence of existing drive mapper
10 ;
11 ;       Enter with  DS == CS,  SS == 0000         (chain loader)
12 ;       Enter with  DS == CS == ES,  SS != 0000   (second stage)
13 ;
14 ;       If a previous drive mapper exists, ES:DI points at the  drvmap
15 ;               and ZF=0        (DI != 0)
16 ;
17 ;       If no recognizable drive map exists, DI == 0  and  ZF==1
18 ;               ES is indeterminate
19 ;
20 ;
21 ;
22 is_prev_mapper:
23         push    cx
24         push    si
25
26 #ifndef CHAIN_LOADER
27         push    #0
28         pop     es
29         seg es
30 #else
31         seg ss
32 #endif
33           les   di,[4*0x13]     ; vector to int 0x13
34         or      di,di
35         jnz     is_p_no_mapper  ; our mappers start at offset 0
36
37         mov     di,es
38         cmp     di,#0xA000      ; start of system reserved locations
39         jae     is_p_no_mapper
40         cmp     di,#0x0060      ; VERY conservative
41         jb      is_p_no_mapper
42
43 ; first test for new mapper
44         xor     di,di
45         mov     cx,#new13_length
46         mov     si,#new13
47         repe
48           cmpsb
49         jne     is_p_try_old
50
51 ; found new (v.22) mapper
52         seg es
53           mov   di,[new13_drvmap_offset]
54 #if defined CHAIN_LOADER && defined DEBUG_NEW
55         mov     si,#msg_new
56         call    say
57 #endif
58         jmp     is_prev_ret
59
60 is_p_try_old:
61         xor     di,di
62         mov     cx,#new13_old_length
63         mov     si,#new13_old
64         repe
65           cmpsb
66         jne     is_p_no_mapper
67
68 ; likely old (<=v.21) mapper
69         seg es
70           mov   di,(di) 
71         cmp     di,#new13_old_min_offs  ; validate the range of values
72         jb      is_p_no_mapper
73         cmp     di,#new13_old_max_offs  ; validate the range of values
74 #if defined CHAIN_LOADER && defined DEBUG_NEW
75         ja      is_p_no_mapper
76         mov     si,#msg_old
77         call    say
78         jmp     is_prev_ret
79 #else
80         jbe     is_prev_ret
81 #endif
82
83 is_p_no_mapper:
84         xor     di,di           ; set DI = 0, ZF=1
85 is_prev_ret:
86         or      di,di           ; set ZF by DI
87         pop     si
88         pop     cx
89         ret
90
91
92 /* LILO version 21 (and maybe earlier) drive map header signature code */
93 new13_old:
94         push    ax              ! save AX (contains function code in AH)
95         push    bp              ! need BP to mess with stack
96         mov     bp,sp
97         pushf                   ! push flags (to act like interrupt)
98         push    si
99         mov     si,#drvmap-new13
100
101 new13_old_drvmap_offs   =       * - new13_old - 2
102 new13_old_length        =       new13_old_drvmap_offs
103 new13_old_min_offs      =       0x46    ; min seen in old code is 0x49
104 new13_old_max_offs      =       0x50    ; maxed out at  21.7.5 at 0x4d
105
106         .even                   ! this is very important
107
108 new13:  push    ax              ! save AX (contains function code in AH)
109         push    bp              ! need BP to mess with stack
110         mov     bp,sp
111         jmp     new13a          ! make space for signature
112
113         .org    new13+6
114         .ascii  "LILO"
115         .word   STAGE_DRIVE_MAP
116 new13_length            =       *-new13         ; max compare length
117         .word   VERSION
118 new13_drvmap_offset     =       * - new13
119         .word   drvmap-new13    ! relative pointer to drive map
120 new13a:
121 #ifdef CHAIN_LOADER
122         ! Stack layout:
123         !
124         !   +8  INT flags
125         !   +6  INT CS
126         !   +4  INT IP
127         !   +2  AX
128         ! BP+0 BP
129         pushf                   ! push flags (to act like interrupt)
130         push    si
131         mov     si,#drvmap-new13
132 mapfl:  seg     cs              ! get next entry
133          mov    ax,(si)         ! do not depend on DIRECTION flag
134         lea     si,(si+2)       ! **
135         or      ax,ax           ! at end ?
136         jz      nomap           ! yes -> do not map
137         cmp     dl,al           ! match ?
138         jne     mapfl           ! no -> continue
139         mov     dl,ah           ! map drive
140 nomap:  pop     si              ! restore SI
141         mov     8(bp),ax        ! overwrite old flags (to remember mapping)
142         mov     ax,2(bp)        ! restore AX
143         mov     bp,(bp)         ! restore BP
144 old13of =       *+1
145 old13sg =       *+3
146         callf   0,0
147
148         push    bp              ! save BP again
149         mov     bp,sp
150         ! New stack layout:
151         !
152         !   +10 mapping (was flags)
153         !   +8  INT CS
154         !   +6  INT IP
155         !   +4  AX
156         !   +2  obsolete BP
157         ! BP+0  BP
158         xchg    ax,4(bp)        ! save AX and get command
159         pushf                   ! fix driver number, if necessary
160         cmp     ah,#8 ! do not fix
161         je      done13
162         cmp     ah,#0x15 ! do not fix
163         je      done13
164         mov     ax,10(bp)       ! no mapping ?
165         or      ax,ax
166         jz      done13
167         mov     dl,al           ! fix mapping
168 done13: mov     ax,4(bp)        ! restore AX
169         pop     10(bp)          ! restore flags
170         pop     bp              ! get BP
171         add     sp,#4           ! fix SP
172         iret                    ! done
173         
174         .even
175 drvmap: .blkw   DRVMAP_SIZE+1
176
177 new13end:
178 #endif
179 #ifdef SECOND_STAGE_LOADER
180 drvmap:
181 #endif
182
183 /* end of mapper.S  */