memdisk-cd: Kill off Int13MaxFunc slot for installer handling EDD case
[profile/ivi/syslinux.git] / memdisk / memdisk.inc
1 ; -*- fundamental -*- (asm-mode sucks)
2 ; ****************************************************************************
3 ;
4 ;  memdisk.inc
5 ;
6 ;  A program to emulate an INT 13h disk BIOS from a "disk" in extended
7 ;  memory.
8 ;
9 ;   Copyright 2001-2009 H. Peter Anvin - All Rights Reserved
10 ;
11 ;  This program is free software; you can redistribute it and/or modify
12 ;  it under the terms of the GNU General Public License as published by
13 ;  the Free Software Foundation, Inc., 53 Temple Place Ste 330,
14 ;  Boston MA 02111-1307, USA; either version 2 of the License, or
15 ;  (at your option) any later version; incorporated herein by reference.
16 ;
17 ; ****************************************************************************
18
19 %ifndef DEPEND
20 %include        "../version.gen"
21 %endif
22
23 ; %define DEBUG_TRACERS                 ; Uncomment to get debugging tracers
24
25 %ifdef DEBUG_TRACERS
26
27 %macro TRACER   1
28         call debug_tracer
29         db %1
30 %endmacro
31
32 %else   ; DEBUG_TRACERS
33
34 %macro  TRACER  1
35 %endmacro
36
37 %endif  ; DEBUG_TRACERS
38
39 %define CONFIG_READONLY 0x01
40 %define CONFIG_RAW      0x02
41 %define CONFIG_SAFEINT  0x04
42 %define CONFIG_BIGRAW   0x08            ; MUST be 8!
43
44                 org 0h
45
46 %define SECTORSIZE_LG2  9               ; log2(sector size)
47 %define SECTORSIZE      (1 << SECTORSIZE_LG2)
48
49                 ; Parameter registers definition; this is the definition
50                 ; of the stack frame.
51 %define         P_DS            word [bp+34]
52 %define         P_ES            word [bp+32]
53 %define         P_EAX           dword [bp+28]
54 %define         P_HAX           word [bp+30]
55 %define         P_AX            word [bp+28]
56 %define         P_AL            byte [bp+28]
57 %define         P_AH            byte [bp+29]
58 %define         P_ECX           dword [bp+24]
59 %define         P_HCX           word [bp+26]
60 %define         P_CX            word [bp+24]
61 %define         P_CL            byte [bp+24]
62 %define         P_CH            byte [bp+25]
63 %define         P_EDX           dword [bp+20]
64 %define         P_HDX           word [bp+22]
65 %define         P_DX            word [bp+20]
66 %define         P_DL            byte [bp+20]
67 %define         P_DH            byte [bp+21]
68 %define         P_EBX           dword [bp+16]
69 %define         P_HBX           word [bp+18]
70 %define         P_HBXL          byte [bp+18]
71 %define         P_BX            word [bp+16]
72 %define         P_BL            byte [bp+16]
73 %define         P_BH            byte [bp+17]
74 %define         P_EBP           dword [bp+8]
75 %define         P_BP            word [bp+8]
76 %define         P_ESI           dword [bp+4]
77 %define         P_SI            word [bp+4]
78 %define         P_EDI           dword [bp]
79 %define         P_DI            word [bp]
80
81                 section .text
82                 ; These pointers are used by the installer and
83                 ; must be first in the binary
84 Pointers:       dw Int13Start
85                 dw Int15Start
86                 dw PatchArea
87                 dw TotalSize
88                 dw IretPtr
89
90 IretPtr         equ Int13Start.iret
91 Int13Start:
92                 ; Swap stack
93                 mov [cs:Stack],esp
94                 mov [cs:SavedAX],ax
95                 mov ax,ss
96                 mov [cs:Stack+4],ax
97                 mov ax,cs
98                 mov ss,ax
99                 mov sp,[cs:MyStack]
100
101                 ; See if DL points to our class of device (FD, HD)
102                 push dx
103                 push dx
104                 xor dl,[cs:DriveNo]
105                 pop dx
106                 js .nomatch             ; If SF=0, we have a class match here
107                 jz .our_drive           ; If ZF=1, we have an exact match
108                 cmp dl,[cs:DriveNo]
109                 jb .nomatch             ; Drive < Our drive
110                 dec dl                  ; Drive > Our drive, adjust drive #
111 .nomatch:
112                 mov ax,[cs:SavedAX]
113                 pushf
114                 call far [cs:OldInt13]
115                 pushf
116                 push bp
117                 mov bp,sp
118                 cmp byte [cs:SavedAX+1],08h
119                 je .norestoredl
120                 cmp byte [cs:SavedAX+1],15h
121                 jne .restoredl
122                 test byte [bp+4],80h    ; Hard disk?
123                 jnz .norestoredl
124 .restoredl:
125                 mov dl,[bp+4]
126 .norestoredl:
127                 push ax
128                 push ebx
129                 push ds
130                 mov ax,[bp+2]           ; Flags
131                 lds ebx,[cs:Stack]
132                 mov [bx+4],al           ; Arithmetric flags
133                 pop ds
134                 pop ebx
135                 pop ax
136                 pop bp
137                 lss esp,[cs:Stack]
138 .iret:          iret
139
140 .our_drive:
141                 ; Set up standard entry frame
142                 push ds
143                 push es
144                 mov ds,ax
145                 mov es,ax
146                 mov ax,[SavedAX]
147                 pushad
148                 mov bp,sp               ; Point BP to the entry stack frame
149                 TRACER 'F'
150                 ; Note: AH == P_AH here
151                 cmp ah,[Int13FuncsCnt-1]
152                 ja Invalid_jump
153                 xor al,al               ; AL = 0 is standard entry condition
154                 mov di,ax
155                 shr di,7                ; Convert AH to an offset in DI
156                 call [Int13Funcs+di]
157
158 Done:           ; Standard routine for return
159                 mov P_AX,ax
160 DoneWeird:
161                 TRACER 'D'
162                 xor bx,bx
163                 mov es,bx
164                 mov bx,[StatusPtr]
165                 mov [es:bx],ah          ; Save status
166                 and ah,ah
167
168                 lds ebx,[Stack]
169                 ; This sets the low byte (the arithmetric flags) of the
170                 ; FLAGS on stack to either 00h (no flags) or 01h (CF)
171                 ; depending on if AH was zero or not.
172                 setnz [bx+4]            ; Set CF iff error
173                 popad
174                 pop es
175                 pop ds
176                 lss esp,[cs:Stack]
177                 iret
178
179 Reset:
180                 ; Reset affects multiple drives, so we need to pass it on
181                 TRACER 'R'
182                 xor ax,ax               ; Bottom of memory
183                 mov es,ax
184                 test dl,dl              ; Always pass it on if we are resetting HD
185                 js .hard_disk           ; Bit 7 set
186                 ; Some BIOSes get very unhappy if we pass a reset floppy
187                 ; command to them and don't actually have any floppies.
188                 ; This is a bug, but we have to deal with it nontheless.
189                 ; Therefore, if we are the *ONLY* floppy drive, and the
190                 ; user didn't request HD reset, then just drop the command.
191                 ; BIOS equipment byte, top two bits + 1 == total # of floppies
192                 test byte [es:0x410],0C0h
193                 jz success
194                 jmp .pass_on            ; ... otherwise pass it to the BIOS
195 .hard_disk:
196                 ; ... same thing for hard disks, sigh ...
197                 cmp byte [es:0x475],1   ; BIOS variable for number of hard disks
198                 jbe success
199
200 .pass_on:
201                 pop ax                  ; Drop return address
202                 popad                   ; Restore all registers
203                 pop es
204                 pop ds
205                 lss esp,[cs:Stack]      ; Restore the stack
206                 and dl,80h              ; Clear all but the type bit
207                 jmp far [cs:OldInt13]
208
209
210 Invalid:
211                 pop dx                  ; Drop return address
212 Invalid_jump:
213                 TRACER 'I'
214                 mov ah,01h              ; Unsupported function
215                 jmp short Done
216
217 GetDriveType:
218                 test byte [DriveNo],80h
219                 mov bl,02h              ; Type 02h = floppy with changeline
220                 jz .floppy
221                 ; Hard disks only...
222                 inc bx                  ; Type = 03h
223                 mov dx,[DiskSize]       ; Return the disk size in sectors
224                 mov P_DX,dx
225                 mov cx,[DiskSize+2]
226                 mov P_CX,cx
227 .floppy:
228                 mov P_AH,bl             ; 02h floppy, 03h hard disk
229                 pop ax                  ; Drop return address
230                 xor ax,ax               ; Success...
231                 jmp DoneWeird           ; But don't stick it into P_AX
232
233 GetStatus:
234                 xor ax,ax
235                 mov es,ax
236                 mov bx,[StatusPtr]
237                 mov ah,[bx]             ; Copy last status
238                 ret
239
240 ReadMult:
241                 TRACER 'm'
242 Read:
243                 TRACER 'R'
244                 call setup_regs
245 do_copy:
246                 TRACER '<'
247                 call bcopy
248                 TRACER '>'
249                 movzx ax,P_AL           ; AH = 0, AL = transfer count
250                 ret
251
252 WriteMult:
253                 TRACER 'M'
254 Write:
255                 TRACER 'W'
256                 test byte [ConfigFlags],CONFIG_READONLY
257                 jnz .readonly
258                 call setup_regs
259                 xchg esi,edi            ; Opposite direction of a Read!
260                 jmp short do_copy
261 .readonly:      mov ah,03h              ; Write protected medium
262                 ret
263
264                 ; Verify integrity; just bounds-check
265 Seek:
266 Verify:
267                 call setup_regs         ; Returns error if appropriate
268                 ; And fall through to success
269
270 CheckIfReady:                           ; These are always-successful noop functions
271 Recalibrate:
272 InitWithParms:
273 DetectChange:
274 EDDDetectChange:
275 EDDLock:
276 SetMode:
277 success:
278                 xor ax,ax               ; Always successful
279                 ret
280
281 GetParms:
282                 TRACER 'G'
283                 mov dl,[DriveCnt]       ; Cached data
284                 mov P_DL,dl
285                 test byte [DriveNo],80h
286                 jnz .hd
287                 mov P_DI,DPT
288                 mov P_ES,cs
289                 mov bl,[DriveType]
290                 mov P_BL,bl
291 .hd:
292                 mov ax,[Cylinders]
293                 dec ax                  ; We report the highest #, not the count
294                 xchg al,ah
295                 shl al,6
296                 or al,[Sectors]
297                 mov P_CX,ax
298                 mov ax,[Heads]
299                 dec ax
300                 mov P_DH,al
301
302                 ;
303                 ; Is this MEMDISK installation check?
304                 ;
305                 cmp P_HAX,'ME'
306                 jne .notic
307                 cmp P_HCX,'MD'
308                 jne .notic
309                 cmp P_HDX,'IS'
310                 jne .notic
311                 cmp P_HBX,'K?'
312                 jne .notic
313
314                 ; MEMDISK installation check...
315                 mov P_HAX,'!M'
316                 mov P_HCX,'EM'
317                 mov P_HDX,'DI'
318                 mov P_HBX,'SK'
319                 mov P_ES,cs
320                 mov P_DI,MemDisk_Info
321
322 .notic:
323                 xor ax,ax
324                 ret
325 ;
326 ; EDD functions -- only if enabled
327 ;
328 %if EDD
329 EDDPresence:
330                 TRACER 'E'
331                 TRACER 'c'
332
333                 cmp P_BX,55AAh
334                 jne Invalid
335                 mov P_BX,0AA55h         ; EDD signature
336                 mov P_AX,03000h         ; EDD 3.0
337                 mov P_CX,0003h          ; Bit 0 - Fixed disk access subset
338                                         ; Bit 1 - Locking and ejecting subset
339                 pop ax                  ; Drop return address
340                 xor ax,ax               ; Success
341                 jmp DoneWeird           ; Success, but AH != 0, sigh...
342
343 EDDRead:
344                 TRACER 'E'
345                 TRACER 'r'
346
347                 call edd_setup_regs
348                 call bcopy
349                 xor ax,ax
350                 ret
351
352 EDDWrite:
353                 TRACER 'E'
354                 TRACER 'w'
355
356                 call edd_setup_regs
357                 xchg esi,edi
358                 call bcopy
359                 xor ax,ax
360                 ret
361
362 EDDVerify:
363 EDDSeek:
364                 call edd_setup_regs     ; Just bounds checking
365                 xor ax,ax
366                 ret
367
368 EDDGetParms:
369                 TRACER 'E'
370                 TRACER 'p'
371
372                 mov es,P_DS
373                 mov di,P_SI
374                 mov si,EDD_DPT
375
376                 lodsw                   ; Length of our DPT
377                 mov cx,[es:di]
378                 cmp cx,26               ; Minimum size
379                 jb .overrun
380
381                 cmp cx,ax
382                 jb .oksize
383                 mov cx,ax
384
385 .oksize:
386                 mov ax,cx
387                 stosw
388                 dec cx
389                 dec cx
390                 rep movsb
391
392                 xor ax,ax
393                 ret
394
395 .overrun:
396                 mov ax,0100h
397                 ret
398 %endif ; EDD
399
400                 ; Set up registers as for a "Read", and compares against disk size.
401                 ; WARNING: This fails immediately, even if we can transfer some
402                 ; sectors.  This isn't really the correct behaviour.
403 setup_regs:
404
405                 ; Convert a CHS address in P_CX/P_DH into an LBA in eax
406                 ; CH = cyl[7:0]
407                 ; CL[0:5] = sector (1-based)  CL[7:6] = cyl[9:8]
408                 ; DH = head
409                 movzx ecx,P_CX
410                 movzx ebx,cl            ; Sector number
411                 and bl,3Fh
412                 dec ebx                 ; Sector number is 1-based
413                 cmp bx,[Sectors]
414                 jae .overrun
415                 movzx edi,P_DH          ; Head number
416                 movzx eax,word [Heads]
417                 cmp di,ax
418                 jae .overrun
419                 shr cl,6
420                 xchg cl,ch              ; Now (E)CX <- cylinder number
421                 mul ecx                 ; eax <- Heads*cyl# (edx <- 0)
422                 add eax,edi
423                 mul dword [Sectors]
424                 add eax,ebx
425                 ; Now eax = LBA, edx = 0
426
427                 ;
428                 ; setup_regs continues...
429                 ;
430                 ; Note: edi[31:16] and ecx[31:16] = 0 already
431                 mov di,P_BX             ; Get linear address of target buffer
432                 mov cx,P_ES
433                 shl ecx,4
434                 add edi,ecx             ; EDI = address to fetch to
435                 movzx ecx,P_AL          ; Sector count
436                 mov esi,eax
437                 add eax,ecx             ; LBA of final sector + 1
438                 shl esi,SECTORSIZE_LG2  ; LBA -> byte offset
439                 add esi,[DiskBuf]       ; Get address in high memory
440                 cmp eax,[DiskSize]      ; Check the high mark against limit
441                 ja .overrun
442                 shl ecx,SECTORSIZE_LG2-2 ; Convert count to dwords
443                 ret
444
445 .overrun:       pop ax                  ; Drop setup_regs return address
446                 mov ax,0200h            ; Missing address mark
447                 ret                     ; Return to Done
448
449                 ; Set up registers as for an EDD Read, and compares against disk size.
450 %if EDD
451 edd_setup_regs:
452                 push es
453                 mov si,P_SI             ; DS:SI -> DAPA
454                 mov es,P_DS
455
456                 mov dx,[es:si]
457                 cmp dx,16
458                 jb .baddapa
459
460                 cmp dword [es:si+4],-1
461                 je .linear_address
462
463                 movzx ebx,word [es:si+4]        ; Offset
464                 movzx edi,word [es:si+6]        ; Segment
465                 shl edi,4
466                 add ebx,edi
467                 jmp .got_address
468
469 .linear_address:
470                 cmp dx,24               ; Must be large enough to hold
471                                         ; linear address
472                 jb .baddapa
473
474                 cmp dword [es:si+20],0  ; > 4 GB addresses not supported
475                 mov ax,0900h            ; "Data boundary error" - bogus, but
476                                         ; no really better code available
477                 jne .error
478
479                 mov ebx,[es:si+16]
480
481 .got_address:
482                 cmp dword [es:si+12],0          ; LBA too large?
483                 jne .overrun
484
485                 movzx ecx, word [es:si+2]       ; Sectors to transfer
486                 mov esi,[es:si+8]               ; Starting sector
487                 mov eax,esi
488                 add eax,ecx
489                 jc .overrun
490                 cmp eax,[DiskSize]
491                 ja .overrun
492
493                 shl ecx,SECTORSIZE_LG2-2        ; Convert to dwords
494                 shl esi,SECTORSIZE_LG2          ; Convert to an offset
495                 add esi,[DiskBuf]
496                 mov edi,ebx
497                 pop es
498                 ret
499
500 .baddapa:
501                 mov ax,0100h            ; Invalid command
502                 pop es
503                 pop ax                  ; Drop setup_regs return address
504                 ret
505
506 .overrun:
507                 mov ax,0200h            ; "Address mark not found" =
508                                         ; LBA beyond end of disk
509 .error:
510                 and word [es:si+2],0    ; No sectors transferred
511                 pop es
512                 pop ax
513                 ret
514
515 EDDEject:
516                 mov ax,0B200h           ; Volume Not Removable
517                 ret
518
519 %endif ; EDD
520
521
522 ;
523 ; INT 15h intercept routines
524 ;
525 int15_e820:
526                 cmp edx,534D4150h       ; "SMAP"
527                 jne oldint15
528                 cmp ecx,20              ; Need 20 bytes
529                 jb err86
530                 push ds
531                 push cs
532                 pop ds
533                 push edx                ; "SMAP"
534                 and ebx,ebx
535                 jne .renew
536                 mov ebx,E820Table
537 .renew:
538                 add bx,16               ; Advance to next
539                 mov eax,[bx-8]          ; Type
540                 and eax,eax             ; Null type?
541                 jz .renew               ; If so advance to next
542                 mov [es:di+16],eax
543                 and cl,~3
544                 cmp ecx,24
545                 jb .no_extattr
546                 mov eax,[bx-4]          ; Extended attributes
547                 mov [es:di+20],eax
548                 mov ecx,24              ; Bytes loaded
549 .no_extattr:
550                 mov eax,[bx-16]         ; Start addr (low)
551                 mov edx,[bx-12]         ; Start addr (high)
552                 mov [es:di],eax
553                 mov [es:di+4],edx
554                 mov eax,[bx]            ; End addr (low)
555                 mov edx,[bx+4]          ; End addr (high)
556                 sub eax,[bx-16]         ; Derive the length
557                 sbb edx,[bx-12]
558                 mov [es:di+8],eax       ; Length (low)
559                 mov [es:di+12],edx      ; Length (high)
560                 cmp dword [bx+8],-1     ; Type of next = end?
561                 jne .notdone
562                 xor ebx,ebx             ; Done with table
563 .notdone:
564                 pop eax                 ; "SMAP"
565                 mov edx,eax             ; Some systems expect eax = edx = SMAP
566                 pop ds
567 int15_success:
568                 mov byte [bp+6], 02h    ; Clear CF
569                 pop bp
570                 iret
571
572 err86:
573                 mov byte [bp+6], 03h    ; Set CF
574                 mov ah,86h
575                 pop bp
576                 iret
577
578 Int15Start:
579                 push bp
580                 mov bp,sp
581                 cmp ax,0E820h
582                 je near int15_e820
583                 cmp ax,0E801h
584                 je int15_e801
585                 cmp ax,0E881h
586                 je int15_e881
587                 cmp ah,88h
588                 je int15_88
589 oldint15:       pop bp
590                 jmp far [cs:OldInt15]
591
592 int15_e801:
593                 mov ax,[cs:Mem1MB]
594                 mov cx,ax
595                 mov bx,[cs:Mem16MB]
596                 mov dx,bx
597                 jmp short int15_success
598
599 int15_e881:
600                 mov eax,[cs:Mem1MB]
601                 mov ecx,eax
602                 mov ebx,[cs:Mem16MB]
603                 mov edx,ebx
604                 jmp short int15_success
605
606 int15_88:
607                 mov ax,[cs:MemInt1588]
608                 jmp short int15_success
609
610 ;
611 ; Routine to copy in/out of high memory
612 ; esi = linear source address
613 ; edi = linear target address
614 ; ecx = 32-bit word count
615 ;
616 ; Assumes cs = ds = es
617 ;
618 bcopy:
619                 push eax
620                 push ebx
621                 push edx
622                 push ebp
623
624                 mov bx, real_int15_stub
625
626                 test byte [ConfigFlags], CONFIG_RAW|CONFIG_SAFEINT
627                 jz .anymode             ; Always do the real INT 15h
628
629                 smsw ax                 ; Unprivileged!
630                 test al,01h
631                 jnz .protmode           ; Protmode -> do real INT 15h
632
633 .realmode:
634                 ; Raw or Safeint mode, and we're in real mode...
635
636                 test byte [ConfigFlags], CONFIG_SAFEINT
637                 jnz .fakeint15
638
639 .raw:
640                 TRACER 'r'
641                 ; We're in real mode, do it outselves
642
643                 pushfd                  ; <A>
644                 push ds                 ; <B>
645                 push es                 ; <C>
646
647                 cli
648                 cld
649
650                 xor ebx,ebx
651                 mov bx,cs
652                 shl ebx,4
653                 lea edx,[Shaker+ebx]
654                 mov [Shaker+2],edx
655
656                 ; Test to see if A20 is enabled or not
657                 xor ax,ax
658                 mov ds,ax
659                 dec ax
660                 mov es,ax
661
662                 mov ax,[0]
663                 mov bx,ax
664                 xor bx,[es:10h]
665                 not ax
666                 mov [0],ax
667                 mov dx,ax
668                 xor dx,[es:10h]
669                 not ax
670                 mov [0],ax
671
672                 or dx,bx
673                 push dx                 ; <D> Save A20 status
674                 jnz .skip_a20e
675
676                 mov ax,2401h            ; Enable A20
677                 int 15h
678 .skip_a20e:
679                 mov dl,[ConfigFlags]
680                 and dx,CONFIG_BIGRAW
681                 add dx,8
682                 ; DX = 16 for BIGRAW, 8 for RAW
683                 ;  8 is selector for a 64K flat segment,
684                 ; 16 is selector for a 4GB flat segment.
685
686                 lgdt [cs:Shaker]
687                 mov eax,cr0
688                 or al,01h
689                 mov cr0,eax
690
691                 mov bx,16               ; Large flat segment
692                 mov ds,bx
693                 mov es,bx
694
695                 a32 rep movsd
696
697                 ; DX has the appropriate value to put in
698                 ; the registers on return
699                 mov ds,dx
700                 mov es,dx
701
702                 and al,~01h
703                 mov cr0,eax
704
705                 pop dx                  ; <D> A20 status
706                 pop es                  ; <C>
707                 pop ds                  ; <B>
708
709                 and dx,dx
710                 jnz .skip_a20d
711                 mov ax,2400h            ; Disable A20
712                 int 15h
713 .skip_a20d:
714                 popfd                   ; <A>
715                 jmp .done
716
717 .fakeint15:
718                 ; We're in real mode with CONFIG_SAFEINT, invoke the
719                 ; original INT 15h vector.  We used to test for the
720                 ; INT 15h vector being unchanged here, but that is
721                 ; *us*; however, the test was wrong for years (always
722                 ; negative) so instead of fixing the test do what we
723                 ; tested and don't bother probing.
724                 mov bx, fake_int15_stub
725
726 .protmode:
727                 TRACER 'p'
728 .anymode:
729
730 .copy_loop:
731                 push esi
732                 push edi
733                 push ecx
734                 cmp ecx,4000h
735                 jna .safe_size
736                 mov ecx,4000h
737 .safe_size:
738                 push ecx        ; Transfer size this cycle
739                 mov eax, esi
740                 mov [Mover_src1], si
741                 shr eax, 16
742                 mov [Mover_src1+2], al
743                 mov [Mover_src2], ah
744                 mov eax, edi
745                 mov [Mover_dst1], di
746                 shr eax, 16
747                 mov [Mover_dst1+2], al
748                 mov [Mover_dst2], ah
749                 mov si,Mover
750                 mov ah, 87h
751                 shl cx,1        ; Convert to 16-bit words
752                 call bx         ; INT 15h stub
753                 pop eax         ; Transfer size this cycle
754                 pop ecx
755                 pop edi
756                 pop esi
757                 jc .error
758                 lea esi,[esi+4*eax]
759                 lea edi,[edi+4*eax]
760                 sub ecx, eax
761                 jnz .copy_loop
762                 ; CF = 0
763 .error:
764 .done:
765                 pop ebp
766                 pop edx
767                 pop ebx
768                 pop eax
769                 ret
770
771 real_int15_stub:
772                 int 15h
773                 cli             ; Some BIOSes enable interrupts on INT 15h
774                 ret
775
776 fake_int15_stub:
777                 pushf
778                 call far [OldInt15]
779                 cli
780                 ret
781
782 %ifdef DEBUG_TRACERS
783 debug_tracer:   pushad
784                 pushfd
785                 mov bp,sp
786                 mov bx,[bp+9*4]
787                 mov al,[cs:bx]
788                 inc word [bp+9*4]
789                 mov ah,0Eh
790                 mov bx,7
791                 int 10h
792                 popfd
793                 popad
794                 ret
795 %endif
796
797                 section .data
798                 alignb 2
799 Int13Funcs      dw Reset                ; 00h - RESET
800                 dw GetStatus            ; 01h - GET STATUS
801                 dw Read                 ; 02h - READ
802                 dw Write                ; 03h - WRITE
803                 dw Verify               ; 04h - VERIFY
804                 dw Invalid              ; 05h - FORMAT TRACK
805                 dw Invalid              ; 06h - FORMAT TRACK AND SET BAD FLAGS
806                 dw Invalid              ; 07h - FORMAT DRIVE AT TRACK
807                 dw GetParms             ; 08h - GET PARAMETERS
808                 dw InitWithParms        ; 09h - INITIALIZE CONTROLLER WITH DRIVE PARAMETERS
809                 dw Invalid              ; 0Ah
810                 dw Invalid              ; 0Bh
811                 dw Seek                 ; 0Ch - SEEK TO CYLINDER
812                 dw Reset                ; 0Dh - RESET HARD DISKS
813                 dw Invalid              ; 0Eh
814                 dw Invalid              ; 0Fh
815                 dw CheckIfReady         ; 10h - CHECK IF READY
816                 dw Recalibrate          ; 11h - RECALIBRATE
817                 dw Invalid              ; 12h
818                 dw Invalid              ; 13h
819                 dw Invalid              ; 14h
820                 dw GetDriveType         ; 15h - GET DRIVE TYPE
821                 dw DetectChange         ; 16h - DETECT DRIVE CHANGE
822 %if EDD
823                 dw Invalid              ; 17h
824                 dw Invalid              ; 18h
825                 dw Invalid              ; 19h
826                 dw Invalid              ; 1Ah
827                 dw Invalid              ; 1Bh
828                 dw Invalid              ; 1Ch
829                 dw Invalid              ; 1Dh
830                 dw Invalid              ; 1Eh
831                 dw Invalid              ; 1Fh
832                 dw Invalid              ; 20h
833                 dw ReadMult             ; 21h - READ MULTIPLE
834                 dw WriteMult            ; 22h - WRITE MULTIPLE
835                 dw SetMode              ; 23h - SET CONTROLLER FEATURES
836                 dw SetMode              ; 24h - SET MULTIPLE MODE
837                 dw Invalid              ; 25h - IDENTIFY DRIVE
838                 dw Invalid              ; 26h
839                 dw Invalid              ; 27h
840                 dw Invalid              ; 28h
841                 dw Invalid              ; 29h
842                 dw Invalid              ; 2Ah
843                 dw Invalid              ; 2Bh
844                 dw Invalid              ; 2Ch
845                 dw Invalid              ; 2Dh
846                 dw Invalid              ; 2Eh
847                 dw Invalid              ; 2Fh
848                 dw Invalid              ; 30h
849                 dw Invalid              ; 31h
850                 dw Invalid              ; 32h
851                 dw Invalid              ; 33h
852                 dw Invalid              ; 34h
853                 dw Invalid              ; 35h
854                 dw Invalid              ; 36h
855                 dw Invalid              ; 37h
856                 dw Invalid              ; 38h
857                 dw Invalid              ; 39h
858                 dw Invalid              ; 3Ah
859                 dw Invalid              ; 3Bh
860                 dw Invalid              ; 3Ch
861                 dw Invalid              ; 3Dh
862                 dw Invalid              ; 3Eh
863                 dw Invalid              ; 3Fh
864                 dw Invalid              ; 40h
865                 dw EDDPresence          ; 41h - EDD PRESENCE DETECT
866                 dw EDDRead              ; 42h - EDD READ
867                 dw EDDWrite             ; 43h - EDD WRITE
868                 dw EDDVerify            ; 44h - EDD VERIFY
869                 dw EDDLock              ; 45h - EDD LOCK/UNLOCK MEDIA
870                 dw EDDEject             ; 46h - EDD EJECT
871                 dw EDDSeek              ; 47h - EDD SEEK
872                 dw EDDGetParms          ; 48h - EDD GET PARAMETERS
873                 dw EDDDetectChange      ; 49h - EDD MEDIA CHANGE STATUS
874 %endif
875
876 Int13FuncsEnd   equ $
877 Int13FuncsCnt   equ (Int13FuncsEnd-Int13Funcs) >> 1
878
879
880                 alignb 8, db 0
881 Shaker          dw ShakerEnd-$-1        ; Descriptor table limit
882                 dd 0                    ; Pointer to self
883                 dw 0
884
885 Shaker_RMDS:    dd 0x0000ffff           ; 64K data segment
886                 dd 0x00009300
887
888 Shaker_DS:      dd 0x0000ffff           ; 4GB data segment
889                 dd 0x008f9300
890
891 ShakerEnd       equ $
892
893                 alignb 8, db 0
894
895 Mover           dd 0, 0, 0, 0           ; Must be zero
896                 dw 0ffffh               ; 64 K segment size
897 Mover_src1:     db 0, 0, 0              ; Low 24 bits of source addy
898                 db 93h                  ; Access rights
899                 db 00h                  ; Extended access rights
900 Mover_src2:     db 0                    ; High 8 bits of source addy
901                 dw 0ffffh               ; 64 K segment size
902 Mover_dst1:     db 0, 0, 0              ; Low 24 bits of target addy
903                 db 93h                  ; Access rights
904                 db 00h                  ; Extended access rights
905 Mover_dst2:     db 0                    ; High 8 bits of source addy
906 Mover_dummy2:   dd 0, 0, 0, 0           ; More space for the BIOS
907
908                 alignb 4, db 0
909 MemDisk_Info    equ $                   ; Pointed to by installation check
910 MDI_Bytes       dw MDI_Len              ; Total bytes in MDI structure
911 MDI_Version     db VERSION_MINOR, VERSION_MAJOR ; MEMDISK version
912
913 PatchArea       equ $                   ; This gets filled in by the installer
914
915 DiskBuf         dd 0                    ; Linear address of high memory disk
916 DiskSize        dd 0                    ; Size of disk in blocks
917 CommandLine     dw 0, 0                 ; Far pointer to saved command line
918
919 OldInt13        dd 0                    ; INT 13h in chain
920 OldInt15        dd 0                    ; INT 15h in chain
921
922 OldDosMem       dw 0                    ; Old position of DOS mem end
923 BootLoaderID    db 0                    ; Boot loader ID from header
924                 db 0                    ; pad
925
926 DPT_ptr         dw 0                    ; If nonzero, pointer to DPT
927                                         ; Original DPT pointer follows
928
929 MDI_Len         equ $-MemDisk_Info
930
931 ; ---- MDI structure ends here ---
932 MemInt1588      dw 0                    ; 1MB-65MB memory amount (1K)
933
934 Cylinders       dw 0                    ; Cylinder count
935 Heads           dw 0                    ; Head count
936 Sectors         dd 0                    ; Sector count (zero-extended)
937
938 Mem1MB          dd 0                    ; 1MB-16MB memory amount (1K)
939 Mem16MB         dd 0                    ; 16MB-4G memory amount (64K)
940
941 DriveNo         db 0                    ; Our drive number
942 DriveType       db 0                    ; Our drive type (floppies)
943 DriveCnt        db 0                    ; Drive count (from the BIOS)
944
945 ConfigFlags     db 0                    ; Bit 0 - readonly
946
947 MyStack         dw 0                    ; Offset of stack
948 StatusPtr       dw 0                    ; Where to save status (zeroseg ptr)
949
950 DPT             times 16 db 0           ; BIOS parameter table pointer (floppies)
951 OldInt1E        dd 0                    ; Previous INT 1E pointer (DPT)
952
953 %if EDD
954 EDD_DPT:
955 .length         dw 30
956 .info           dw 0029h
957                 ; Bit 0 - DMA boundaries handled transparently
958                 ; Bit 3 - Device supports write verify
959                 ; Bit 5 - Media is lockable
960 .cylinders      dd 0                    ; Filled in by installer
961 .heads          dd 0                    ; Filled in by installer
962 .sectors        dd 0                    ; Filled in by installer
963 .totalsize      dd 0, 0                 ; Filled in by installer
964 .bytespersec    dw SECTORSIZE
965 .eddtable       dw -1, -1               ; Invalid DPTE pointer
966
967 %endif
968
969                 ; End patch area
970 Stack           dd 0                    ; Saved SS:ESP on invocation
971                 dw 0
972 SavedAX         dw 0                    ; AX saved on invocation
973
974                 alignb 4, db 0          ; We *MUST* end on a dword boundary
975
976 E820Table       equ $                   ; The installer loads the E820 table here
977 TotalSize       equ $                   ; End pointer