Skip to content

Commit 7b1d944

Browse files
committed
more optimizations and typo fixes
1 parent 76c5026 commit 7b1d944

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,5 @@ debug: image
136136
qemu-system-i386 -serial stdio -rtc base=localtime -S -s -drive file=bin/boot12.img,format=raw,if=floppy
137137

138138
gdb: image
139-
-gdb -q -ex "exec-file bin/boot12.elf" -ex "add-symbol-file bin/boot12.elf 0x9FA00 -readnow" -ex "b reallocatedEntry"
139+
-gdb -q -ex "exec-file bin/boot12.elf" -ex "add-symbol-file bin/boot12.elf 0x9FA00 -readnow" -ex "break reallocatedEntry"
140140
endif

src/boot12.asm

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ reallocatedEntry:
122122
;---------------------------------------------------
123123

124124
allocDiskbuffer:
125-
xor ax, ax
126-
mov dx, ax ; Calculate the size of fat in sectors
125+
xor ah, ah
126+
xor dx, dx ; Calculate the size of fat in sectors
127127
mov al, byte [fats] ; Take the number of fats
128128
mul word [fatSectors] ; And multiply that by the number of sectors per fat
129129

@@ -166,7 +166,7 @@ loadRoot:
166166
;---------------------------------------------------
167167

168168
findFile:
169-
mov dx, word [rootDirEntries] ; Search through all of the root dir entrys for the kernel
169+
mov dx, word [rootDirEntries] ; Search through all of the root dir entries for the kernel
170170
push di
171171

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

254-
xor ch, ch
255-
mov cl, byte [sectorsPerCluster] ; Sectors to read
254+
mov cx, bx ; Sectors to read
256255
call readSectors ; Read the sectors
257256

258257
pop ax
@@ -261,14 +260,14 @@ readClusters:
261260
push ds
262261
push si
263262

264-
xor dx, dx ; Get the next cluster for FAT
265-
mov bx, 3 ; We want to multiply by 1.5 so divide by 3/2
263+
xor dx, dx ; Get the next cluster for fat
264+
mov bl, 3 ; We want to multiply by 1.5 so divide by 3/2
266265
mul bx ; Multiply the cluster by the numerator
267-
mov bl, 2 ; Return value in ax and remainder in dx
266+
dec bx ; Return value in ax and remainder in dx
268267
div bx ; Divide the cluster by the denominator
269268

270-
add si, ax ; Point to the next cluster in the FAT entry
271-
mov ax, word [ds:si] ; Load ax to the next cluster in FAT
269+
add si, ax ; Point to the next cluster in the fat entry
270+
mov ax, word [ds:si] ; Load ax to the next cluster in fat
272271

273272
pop si
274273
pop ds
@@ -301,8 +300,8 @@ readClusters:
301300
add ch, dl ; Then add the lower half to the segment
302301
mov es, cx
303302

304-
clc
305-
add di, bx ; Add to the pointer offset
303+
clc ; Add to the pointer offset
304+
add di, bx
306305
jnc .clusterLoop
307306

308307
.fixBuffer: ; An error will occur if the buffer in memory
@@ -342,7 +341,7 @@ readSectors:
342341
push cx
343342
push dx
344343

345-
div word [sectorsPerTrack] ; Divide the lba (value in ax:dx) by sectorsPerTrack
344+
div word [sectorsPerTrack] ; Divide lba by the sectors per track
346345
mov cx, dx ; Save the absolute sector value
347346
inc cx
348347

@@ -382,7 +381,9 @@ readSectors:
382381
pop cx
383382
pop ax
384383

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

387388
clc
388389
add bx, word [bytesPerSector] ; Add to the buffer address for the next sector

src/boot16.asm

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ reallocatedEntry:
119119
;---------------------------------------------------
120120

121121
allocDiskbuffer:
122-
xor ax, ax
123-
mov dx, ax ; Calculate the size of fat in sectors
122+
xor ah, ah
123+
mov dx, dx ; Calculate the size of fat in sectors
124124
mov al, byte [fats] ; Take the number of fats
125125
mul word [fatSectors] ; And multiply that by the number of sectors per fat
126126

@@ -163,7 +163,7 @@ loadRoot:
163163
;---------------------------------------------------
164164

165165
findFile:
166-
mov dx, word [rootDirEntries] ; Search through all of the root dir entrys for the kernel
166+
mov dx, word [rootDirEntries] ; Search through all of the root dir entries for the kernel
167167
push di
168168

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

251-
xor ch, ch
252-
mov cl, byte [sectorsPerCluster] ; Sectors to read
251+
mov cx, bx ; Sectors to read
253252
call readSectors ; Read the sectors
254253

255254
pop ax
@@ -259,20 +258,20 @@ readClusters:
259258
push si
260259

261260
xor dx, dx
262-
mov cx, 2 ; Get the next cluster for FAT16
261+
mov cx, 2 ; Get the next cluster for fat
263262
mul cx ; Multiply the cluster by 2
264263

265264
xor bx, bx
266-
add si, ax ; Add the offset into the FAT16 table
265+
add si, ax ; Add the offset into the fat table
267266
adc bx, dx ; Make sure to adjust for carry
268267

269268
mov cl, 4
270-
shl bl, cl ; Correct the segment based on the offset into the FAT16 table
269+
shl bl, cl ; Correct the segment based on the offset into the fat table
271270
mov dx, ds ; Shift left by 4 bits
272271
add dh, bl ; Then add the higher half to the segment
273272
mov ds, dx
274273

275-
mov ax, word [ds:si] ; Load ax to the next cluster in the FAT16 table
274+
mov ax, word [ds:si] ; Load ax to the next cluster in the fat table
276275

277276
pop si
278277
pop ds
@@ -335,7 +334,7 @@ readSectors:
335334
push cx
336335
push dx
337336

338-
div word [sectorsPerTrack] ; Divide the lba (value in ax:dx) by sectorsPerTrack
337+
div word [sectorsPerTrack] ; Divide lba by the sectors per track
339338
mov cx, dx ; Save the absolute sector value
340339
inc cx
341340

0 commit comments

Comments
 (0)