wok diff BootProg/stuff/boot32.asm @ rev 24891
lynx: use ncursesw (tanks ceel)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 07 07:20:18 2022 +0000 (2022-04-07) |
parents | d77ab883a8b3 |
children | d1f31f5f6401 |
line diff
1.1 --- a/BootProg/stuff/boot32.asm Tue Feb 22 16:15:28 2022 +0000 1.2 +++ b/BootProg/stuff/boot32.asm Thu Apr 07 07:20:18 2022 +0000 1.3 @@ -11,7 +11,8 @@ 1.4 ;; ;; 1.5 ;; Features: ;; 1.6 ;; ~~~~~~~~~ ;; 1.7 -;; - FAT32 supported using BIOS int 13h function 42h or 02h. ;; 1.8 +;; - FAT32 supported using BIOS int 13h function 42h (IOW, it will only ;; 1.9 +;; work with modern BIOSes supporting HDDs bigger than 8 GB) ;; 1.10 ;; ;; 1.11 ;; - Loads a 16-bit executable file in the MS-DOS .COM or .EXE format ;; 1.12 ;; from the root directory of a disk and transfers control to it ;; 1.13 @@ -262,30 +263,33 @@ 1.14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.15 1.16 mov ds, bp ; bp=ds=seg the file is loaded to 1.17 + 1.18 add bp, [bx+08h] ; bp = image base 1.19 mov ax, [bx+06h] ; ax = reloc items 1.20 mov di, [bx+18h] ; di = reloc table pointer 1.21 1.22 cmp word [bx], 5A4Dh ; "MZ" signature? 1.23 - 1.24 je RelocateEXE ; yes, it's an EXE program 1.25 1.26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.27 ;; Setup and run a .COM program ;; 1.28 -;; Set CS=DS=ES=SP SP=0 IP=100h ;; 1.29 +;; Set CS=DS=ES=SS SP=0 IP=100h ;; 1.30 +;; AX=0ffffh BX=0 CX=0 DX=drive ;; 1.31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.32 1.33 + mov ax, 0ffffh ; both FCB in the PSP don't have a valid drive identifier 1.34 + mov di, 100h ; ip 1.35 mov bp, ImageLoadSeg-10h ; "org 100h" stuff :) 1.36 mov ss, bp 1.37 xor sp, sp 1.38 push bp ; cs, ds and es 1.39 - mov bh, 1 ; ip 1.40 jmp short Run 1.41 1.42 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.43 ;; Relocate, setup and run a .EXE program ;; 1.44 ;; Set CS:IP, SS:SP, DS, ES and AX according ;; 1.45 ;; to wiki.osdev.org/MZ#Initial_Program_State ;; 1.46 +;; AX=0ffffh BX=0 CX=0 DX=drive ;; 1.47 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.48 1.49 ReloCycle: 1.50 @@ -308,11 +312,11 @@ 1.51 push si ; containing the PSP structure 1.52 1.53 add bp, [bx+16h] ; cs for EXE 1.54 - mov bx, [bx+14h] ; ip for EXE 1.55 + mov di, [bx+14h] ; ip for EXE 1.56 Run: 1.57 pop ds 1.58 push bp 1.59 - push bx 1.60 + push di 1.61 push ds 1.62 pop es 1.63 1.64 @@ -332,6 +336,7 @@ 1.65 ReadCluster: 1.66 mov bp, [bx(bpbBytesPerSector)] 1.67 shr bp, 4 ; bp = paragraphs per sector 1.68 + add eax, byte 1 ; adjust LBA for next sector 1.69 inc cx 1.70 loop ReadSectorLBA 1.71 1.72 @@ -374,7 +379,6 @@ 1.73 add eax, edx 1.74 adc word [bx(HiLBA)], bx 1.75 add eax, [bx(bpbHiddenSectors)] 1.76 - adc word [bx(HiLBA)], bx 1.77 1.78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.79 ;; Reads a sector using BIOS Int 13h fn 42h ;; 1.80 @@ -386,6 +390,8 @@ 1.81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1.82 1.83 ReadSectorLBA: 1.84 + adc word [bx(HiLBA)], bx 1.85 + mov dx, [bx(bsDriveNumber)] ; restore BIOS boot drive number 1.86 pusha 1.87 1.88 push bx 1.89 @@ -395,43 +401,13 @@ 1.90 push bx 1.91 push byte 1 ; sector count word = 1 1.92 push byte 16 ; packet size byte = 16, reserved byte = 0 1.93 - push eax 1.94 - pop cx ; low LBA 1.95 - pop ax ; high LBA 1.96 - cwd ; clear dx (CHS disk <2TB) 1.97 - div word [bx(bpbSectorsPerTrack)] ; up to 8GB CHS disks 1.98 - 1.99 - xchg ax, cx ; restore low LBA, save high LBA / SPT 1.100 - div word [bx(bpbSectorsPerTrack)] 1.101 - ; ax = LBA / SPT 1.102 - ; dx = LBA % SPT = sector - 1 1.103 - inc dx 1.104 - 1.105 - xchg cx, dx ; restore high LBA / SPT, save sector no. 1.106 - div word [bx(bpbHeadsPerCylinder)] 1.107 - ; ax = (LBA / SPT) / HPC = cylinder 1.108 - ; dx = (LBA / SPT) % HPC = head 1.109 - shl ah, 6 1.110 - mov ch, al 1.111 - ; ch = LSB 0...7 of cylinder no. 1.112 - or cl, ah 1.113 - ; cl = MSB 8...9 of cylinder no. + sector no. 1.114 - mov dh, dl 1.115 - ; dh = head no. 1.116 1.117 ReadSectorLBARetry: 1.118 - mov dl, [bx(bsDriveNumber)] ; restore BIOS boot drive number 1.119 mov si, sp 1.120 mov ah, 42h ; ah = 42h = extended read function no. 1.121 int 13h ; extended read sectors (DL, DS:SI) 1.122 jnc ReadSuccess ; CF = 0 if no error 1.123 1.124 -ReadSectorCHSRetry: 1.125 - mov ax, 201h ; al = sector count = 1 1.126 - ; ah = 2 = read function no. 1.127 - int 13h ; read sectors (AL, CX, DX, ES:BX) 1.128 - jnc ReadSuccess ; CF = 0 if no error 1.129 - 1.130 cbw ; ah = 0 = reset function 1.131 int 13h ; reset drive (DL) 1.132 1.133 @@ -447,16 +423,12 @@ 1.134 1.135 popa 1.136 1.137 - add eax, byte 1 ; adjust LBA for next sector 1.138 - adc word [bx(HiLBA)], bx 1.139 - 1.140 stc 1.141 loop ReadSectorNext 1.142 1.143 cmp esi, 0FFFFFF8h ; carry=0 if last cluster, and carry=1 otherwise 1.144 1.145 ReadSectorNext: 1.146 - mov dx, [bx(bsDriveNumber)] ; restore BIOS boot drive number 1.147 ret 1.148 1.149 ;;;;;;;;;;;;;;;;;;;;;;;;;; 1.150 @@ -473,8 +445,8 @@ 1.151 cmp al, '.' 1.152 jne puts 1.153 cbw 1.154 -; int 16h ; wait for a key... 1.155 -; int 19h ; bootstrap 1.156 + int 16h ; wait for a key... 1.157 + int 19h ; bootstrap 1.158 1.159 Stop: 1.160 hlt