X-Git-Url: http://git.dujemihanovic.xyz/posts?a=blobdiff_plain;f=boot%2Fx86%2Ffat32%2Ffat32.s;fp=boot%2Fx86%2Ffat32.s;h=df5dd89260a3fff08e70e6729ee54f170def9559;hb=750b9e3f093f34310a05ffbac7f6b1317ef786e7;hp=75e7904ae5b94a2116529542e0342fb2f1791e0b;hpb=c4408dfedc5d7b3a4e6b584c37c58e064265ef2d;p=nameless-os.git diff --git a/boot/x86/fat32.s b/boot/x86/fat32/fat32.s similarity index 91% rename from boot/x86/fat32.s rename to boot/x86/fat32/fat32.s index 75e7904..df5dd89 100644 --- a/boot/x86/fat32.s +++ b/boot/x86/fat32/fat32.s @@ -7,6 +7,7 @@ ; eax - start cluster number ; es:di - where to load the cluster chain +; RETURN: CF set = error ; NOTE: Cluster chain might be the root directory or a file. read_cluster_chain: push eax @@ -14,8 +15,10 @@ read_cluster_chain: push di .loop: call read_cluster + jc .done cmp eax, 0xffffff7 jl .loop +.done: pop di pop es pop eax @@ -24,6 +27,7 @@ read_cluster_chain: ; eax - cluster number ; es:di - where to load the cluster (incremented automatically) ; RETURN: eax - next cluster number +; CF set = error read_cluster: push ebx push ecx @@ -44,6 +48,8 @@ read_cluster: movzx cx, BPB_SecPerClus call read_sectors pop cx + cmp dl, 0 + je .error ; increment the load offset (and segment if needed) push eax @@ -78,16 +84,20 @@ read_cluster: xor ax, ax mov es, ax pop ebx ; pop LBA into EBX - mov di, 0x1000 + mov di, 0x6000 mov cx, 1 call read_sectors - + cmp dl, 0 ; find the cluster we're looking for pop es ; restore STAGE3_SEGMENT pop ebx ; pop FAT offset back into EBX for cmp mov eax, [di+bx] pop di + jne .end ; cleanup and return +.error: + stc +.end: pop edx pop ecx pop ebx @@ -96,8 +106,11 @@ read_cluster: ; es:di - where to load the sector(s) ; ebx - start LBA address ; cx - how many sectors to read +; RETURN: DL=0 means error read_sectors: - pusha + clc + push ax + push si mov ah, 0x42 push dword 0 push dword ebx @@ -108,15 +121,14 @@ read_sectors: mov si, sp mov dl, [BOOT_DRIVE] int 0x13 - jc .error + mov dl, 1 + jnc .done + mov dl, 0 +.done: add sp, 16 - popa + pop si + pop ax ret - .error: - mov si, read_error - call print - hlt - jmp $-1 ; ds:si - pointer to partition table entry ; RETURN: ecx - first data sector