1 ; mapper.S - LILO chain loader subroutine
3 ; Copyright 2003-2004 John Coffman
4 ; Copyright 2009-2011 Joachim Wiedorn
7 ; Licensed under the terms contained in the file 'COPYING'
8 ; in the source directory.
12 ; Check for presence of existing drive mapper
14 ; Enter with DS == CS, SS == 0000 (chain loader)
15 ; Enter with DS == CS == ES, SS != 0000 (second stage)
17 ; If a previous drive mapper exists, ES:DI points at the drvmap
20 ; If no recognizable drive map exists, DI == 0 and ZF==1
36 les di,[4*0x13] ; vector to int 0x13
38 jnz is_p_no_mapper ; our mappers start at offset 0
41 cmp di,#0xA000 ; start of system reserved locations
43 cmp di,#0x0060 ; VERY conservative
46 ; first test for new mapper
54 ; found new (v.22) mapper
56 mov di,[new13_drvmap_offset]
57 #if defined CHAIN_LOADER && defined DEBUG_NEW
65 mov cx,#new13_old_length
71 ; likely old (<=v.21) mapper
74 cmp di,#new13_old_min_offs ; validate the range of values
76 cmp di,#new13_old_max_offs ; validate the range of values
77 #if defined CHAIN_LOADER && defined DEBUG_NEW
87 xor di,di ; set DI = 0, ZF=1
89 or di,di ; set ZF by DI
95 /* LILO version 21 (and maybe earlier) drive map header signature code */
97 push ax ! save AX (contains function code in AH)
98 push bp ! need BP to mess with stack
100 pushf ! push flags (to act like interrupt)
104 new13_old_drvmap_offs = * - new13_old - 2
105 new13_old_length = new13_old_drvmap_offs
106 new13_old_min_offs = 0x46 ; min seen in old code is 0x49
107 new13_old_max_offs = 0x50 ; maxed out at 21.7.5 at 0x4d
109 .even ! this is very important
111 new13: push ax ! save AX (contains function code in AH)
112 push bp ! need BP to mess with stack
114 jmp new13a ! make space for signature
118 .word STAGE_DRIVE_MAP
119 new13_length = *-new13 ; max compare length
121 new13_drvmap_offset = * - new13
122 .word drvmap-new13 ! relative pointer to drive map
132 pushf ! push flags (to act like interrupt)
135 mapfl: seg cs ! get next entry
136 mov ax,(si) ! do not depend on DIRECTION flag
139 jz nomap ! yes -> do not map
141 jne mapfl ! no -> continue
142 mov dl,ah ! map drive
143 nomap: pop si ! restore SI
144 mov 8(bp),ax ! overwrite old flags (to remember mapping)
145 mov ax,2(bp) ! restore AX
146 mov bp,(bp) ! restore BP
151 push bp ! save BP again
155 ! +10 mapping (was flags)
161 xchg ax,4(bp) ! save AX and get command
162 pushf ! fix driver number, if necessary
163 cmp ah,#8 ! do not fix
165 cmp ah,#0x15 ! do not fix
167 mov ax,10(bp) ! no mapping ?
170 mov dl,al ! fix mapping
171 done13: mov ax,4(bp) ! restore AX
172 pop 10(bp) ! restore flags
178 drvmap: .blkw DRVMAP_SIZE+1
182 #ifdef SECOND_STAGE_LOADER
186 /* end of mapper.S */