Make the thing actually work!!! Yoo-hoo!!!
authorhpa <hpa>
Tue, 11 Dec 2001 19:18:45 +0000 (19:18 +0000)
committerhpa <hpa>
Tue, 11 Dec 2001 19:18:45 +0000 (19:18 +0000)
memdisk/Makefile
memdisk/memdisk.asm
memdisk/setup.c

index d5884c0..b3abf5a 100644 (file)
@@ -26,8 +26,13 @@ OBJS    = init.o16 setup.o16 msetup.o16 e820func.o16 conio.o16 memdisk.o
 
 all: memdisk e820test
 
+# tidy removes everything except the final binary
+tidy:
+       rm -f *.o *.s *.o16 *.s16 *.bin *.lst *.elf e820test
+
+# clean also removes the product binary
 clean:
-       rm -f *.o *.s *.o16 *.s16 *.bin *.lst *.elf e820test memdisk
+       rm -f memdisk
 
 %.o16: %.s16
        $(AS) -o $@ $<
index af5a2a3..1dd41b6 100644 (file)
@@ -85,6 +85,7 @@ Int13Start:
                mov ax,[SavedAX]
                pushad
                mov bp,sp               ; Point BP to the entry stack frame
+               ; Note: AH == P_AH here
                cmp ah,Int13FuncsMax
                jae Invalid
                xor al,al               ; AL = 0 is standard entry condition
@@ -98,15 +99,15 @@ DoneWeird:
                mov [LastStatus],ah
                and ah,ah
 
+               lds ebx,[Stack]
+               ; This sets the low byte (the arithmetric flags) of the
+               ; FLAGS on stack to either 00h (no flags) or 01h (CF)
+               ; depending on if AH was zero or not.
+               setnz [bx+4]            ; Set CF iff error
                popad
                pop es
                pop ds
                lss esp,[cs:Stack]
-
-               ; This sets the low byte (the arithmetric flags) of the
-               ; FLAGS on stack to either 00h (no flags) or 01h (CF)
-               ; depending on if AH was zero or not.
-               setnz [esp+4]           ; Set CF iff error
                iret
 
 Reset:
@@ -212,12 +213,12 @@ setup_regs:
                movzx edi,P_DH          ; Head number
                movzx eax,word [Heads]
                shr cl,6
-               xchg cl,ch              ; Now CX <- cylinder number
+               xchg cl,ch              ; Now (E)CX <- cylinder number
                mul ecx                 ; eax <- Heads*cyl# (edx <- 0)
                add eax,edi
                mul dword [Sectors]
                add eax,ebx
-               ; Now eax = LBA
+               ; Now eax = LBA, edx = 0
 
                ;
                ; setup_regs continues...
@@ -229,8 +230,8 @@ setup_regs:
                add edi,ecx             ; EDI = address to fetch to
                movzx ecx,P_AL          ; Sector count
                mov esi,eax
-               add eax,ecx
-               shl esi,SECTORSIZE_LG2
+               add eax,ecx             ; LBA of final sector + 1
+               shl esi,SECTORSIZE_LG2  ; LBA -> byte offset
                add esi,[DiskBuf]       ; Get address in high memory
                cmp eax,[DiskSize]      ; Check the high mark against limit
                ja .overrun
@@ -277,12 +278,12 @@ int15_e820:
                pop ds
                mov ecx,20              ; Bytes loaded
 int15_success:
-               mov byte [bp+12], 02h   ; Clear CF
+               mov byte [bp+6], 02h    ; Clear CF
                pop bp
                iret
 
 err86:
-               mov byte [bp+12], 03h   ; Set CF
+               mov byte [bp+6], 03h    ; Set CF
                mov ah,86h
                pop bp
                iret
@@ -340,7 +341,7 @@ bcopy:
                jna .safe_size
                mov ecx,8000h
 .safe_size:
-               push ecx
+               push ecx        ; Transfer size this cycle
                mov eax, esi
                mov [Mover_src1], si
                shr eax, 16
@@ -354,7 +355,8 @@ bcopy:
                mov si,Mover
                mov ah, 87h
                int 15h
-               pop eax
+               cli             ; Some BIOSes enable interrupts on INT 15h
+               pop eax         ; Transfer size this cycle
                pop ecx
                pop edi
                pop esi
@@ -411,6 +413,7 @@ Mover_dst1: db 0, 0, 0              ; Low 24 bits of target addy
                db 93h                  ; Access rights
                db 00h                  ; Extended access rights
 Mover_dst2:    db 0                    ; High 8 bits of source addy
+Mover_dummy2:  dd 0, 0, 0, 0           ; More space for the BIOS
 
 LastStatus     db 0                    ; Last return status
 
@@ -436,7 +439,6 @@ DriveNo             db 0                    ; Our drive number
 DriveType      db 0                    ; Our drive type (floppies)
 
 MyStack                dw 0                    ; Offset of stack
-               dw 0                    ; Padding
 
                ; End patch area
 
index d2cec95..1ae49df 100644 (file)
@@ -275,9 +275,6 @@ uint32_t setup(void)
   driveraddr  = stddosmem - total_size;
   driveraddr &= ~0x3FF;
 
-  /* Anything beyond the end is for the stack */
-  pptr->mystack = (uint16_t)(stddosmem-driveraddr);
-
   printf("Old dos memory at 0x%05x (map says 0x%05x), loading at 0x%05x\n",
         stddosmem, dos_mem, driveraddr);
 
@@ -295,6 +292,9 @@ uint32_t setup(void)
   driverseg = driveraddr >> 4;
   driverptr = driverseg  << 16;
 
+  /* Anything beyond the end is for the stack */
+  pptr->mystack    = (uint16_t)(stddosmem-driveraddr);
+
   pptr->oldint13 = rdz_32(BIOS_INT13);
   pptr->oldint15 = rdz_32(BIOS_INT15);