Skip to content

Commit

Permalink
more optimizations and typo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua-Riek committed Dec 23, 2022
1 parent 76c5026 commit 7b1d944
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@ debug: image
qemu-system-i386 -serial stdio -rtc base=localtime -S -s -drive file=bin/boot12.img,format=raw,if=floppy

gdb: image
-gdb -q -ex "exec-file bin/boot12.elf" -ex "add-symbol-file bin/boot12.elf 0x9FA00 -readnow" -ex "b reallocatedEntry"
-gdb -q -ex "exec-file bin/boot12.elf" -ex "add-symbol-file bin/boot12.elf 0x9FA00 -readnow" -ex "break reallocatedEntry"
endif
29 changes: 15 additions & 14 deletions src/boot12.asm
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ reallocatedEntry:
;---------------------------------------------------

allocDiskbuffer:
xor ax, ax
mov dx, ax ; Calculate the size of fat in sectors
xor ah, ah
xor dx, dx ; Calculate the size of fat in sectors
mov al, byte [fats] ; Take the number of fats
mul word [fatSectors] ; And multiply that by the number of sectors per fat

Expand Down Expand Up @@ -166,7 +166,7 @@ loadRoot:
;---------------------------------------------------

findFile:
mov dx, word [rootDirEntries] ; Search through all of the root dir entrys for the kernel
mov dx, word [rootDirEntries] ; Search through all of the root dir entries for the kernel
push di

.searchRoot:
Expand Down Expand Up @@ -251,8 +251,7 @@ readClusters:
mul bx ; Multiply the cluster by the sectors per cluster
add ax, word [cs:startOfData] ; Finally add the first data sector

xor ch, ch
mov cl, byte [sectorsPerCluster] ; Sectors to read
mov cx, bx ; Sectors to read
call readSectors ; Read the sectors

pop ax
Expand All @@ -261,14 +260,14 @@ readClusters:
push ds
push si

xor dx, dx ; Get the next cluster for FAT
mov bx, 3 ; We want to multiply by 1.5 so divide by 3/2
xor dx, dx ; Get the next cluster for fat
mov bl, 3 ; We want to multiply by 1.5 so divide by 3/2
mul bx ; Multiply the cluster by the numerator
mov bl, 2 ; Return value in ax and remainder in dx
dec bx ; Return value in ax and remainder in dx
div bx ; Divide the cluster by the denominator

add si, ax ; Point to the next cluster in the FAT entry
mov ax, word [ds:si] ; Load ax to the next cluster in FAT
add si, ax ; Point to the next cluster in the fat entry
mov ax, word [ds:si] ; Load ax to the next cluster in fat

pop si
pop ds
Expand Down Expand Up @@ -301,8 +300,8 @@ readClusters:
add ch, dl ; Then add the lower half to the segment
mov es, cx

clc
add di, bx ; Add to the pointer offset
clc ; Add to the pointer offset
add di, bx
jnc .clusterLoop

.fixBuffer: ; An error will occur if the buffer in memory
Expand Down Expand Up @@ -342,7 +341,7 @@ readSectors:
push cx
push dx

div word [sectorsPerTrack] ; Divide the lba (value in ax:dx) by sectorsPerTrack
div word [sectorsPerTrack] ; Divide lba by the sectors per track
mov cx, dx ; Save the absolute sector value
inc cx

Expand Down Expand Up @@ -382,7 +381,9 @@ readSectors:
pop cx
pop ax

inc ax ; Increase the next sector to read
clc
add ax, 1 ; Add one for the the next lba value
adc dx, 0 ; Make sure to adjust dx for carry

clc
add bx, word [bytesPerSector] ; Add to the buffer address for the next sector
Expand Down
19 changes: 9 additions & 10 deletions src/boot16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ reallocatedEntry:
;---------------------------------------------------

allocDiskbuffer:
xor ax, ax
mov dx, ax ; Calculate the size of fat in sectors
xor ah, ah
mov dx, dx ; Calculate the size of fat in sectors
mov al, byte [fats] ; Take the number of fats
mul word [fatSectors] ; And multiply that by the number of sectors per fat

Expand Down Expand Up @@ -163,7 +163,7 @@ loadRoot:
;---------------------------------------------------

findFile:
mov dx, word [rootDirEntries] ; Search through all of the root dir entrys for the kernel
mov dx, word [rootDirEntries] ; Search through all of the root dir entries for the kernel
push di

.searchRoot:
Expand Down Expand Up @@ -248,8 +248,7 @@ readClusters:
mul bx ; Multiply the cluster by the sectors per cluster
add ax, word [cs:startOfData] ; Finally add the first data sector

xor ch, ch
mov cl, byte [sectorsPerCluster] ; Sectors to read
mov cx, bx ; Sectors to read
call readSectors ; Read the sectors

pop ax
Expand All @@ -259,20 +258,20 @@ readClusters:
push si

xor dx, dx
mov cx, 2 ; Get the next cluster for FAT16
mov cx, 2 ; Get the next cluster for fat
mul cx ; Multiply the cluster by 2

xor bx, bx
add si, ax ; Add the offset into the FAT16 table
add si, ax ; Add the offset into the fat table
adc bx, dx ; Make sure to adjust for carry

mov cl, 4
shl bl, cl ; Correct the segment based on the offset into the FAT16 table
shl bl, cl ; Correct the segment based on the offset into the fat table
mov dx, ds ; Shift left by 4 bits
add dh, bl ; Then add the higher half to the segment
mov ds, dx

mov ax, word [ds:si] ; Load ax to the next cluster in the FAT16 table
mov ax, word [ds:si] ; Load ax to the next cluster in the fat table

pop si
pop ds
Expand Down Expand Up @@ -335,7 +334,7 @@ readSectors:
push cx
push dx

div word [sectorsPerTrack] ; Divide the lba (value in ax:dx) by sectorsPerTrack
div word [sectorsPerTrack] ; Divide lba by the sectors per track
mov cx, dx ; Save the absolute sector value
inc cx

Expand Down

0 comments on commit 7b1d944

Please sign in to comment.