Prints the wrong filename

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
benjii
Posts: 14
Joined: Sat Oct 20, 2012 3:27 pm

Prints the wrong filename

Post by benjii »

Hello, I was writing a bootsector based on a FAT12 filesystem. After a while I came up with a problem.

Code: Select all

	.FindBootSectorTwo:
		push SI
		push DI
		push CX
		mov CX, 11
		mov SI, BootloaderSTG2
		rep cmpsb
		pop CX
		pop DI
		pop SI
		je LOAD_BOOTLOADER_STG2
		add DI, 32
		loop .FindBootSectorTwo
		jmp ERROR_NOT_FOUND
This label searches for a file called BLS2.SYS and if it finds it, it jumps to LOAD_BOOTLOADER_STG2 label. The beginning of LOAD_BOOTLOADER_STG2 label:

Code: Select all

LOAD_BOOTLOADER_STG2:
	push SI
	push CX
	push DI
	;sub DI, 32
	mov SI, DI
	mov CX, 11
	call Printname
	pop DI
	pop CX
	pop SI
	pop DS
If I try to subtract 32 from DI, it gives me the right file name -- BLS2.SYS, but if I don't , I get only a bunch of spaces. What could be the problem here? Is this is a bug, that the program finds the wrong file, or I just don't understand something here? I'm launching this code on Bochs, on a x86 machine. P.S. here's the LOAD_ROOT label together with .FindBootSectorTwo.

Code: Select all

LOAD_ROOT:
	mov [BS_DriveNumber], DL
	mov AX, 0x0000
	mov SS, AX
	mov SP, 0x7C00
	mov DS, AX
	mov ES, AX
	xor DX, DX
	movzx AX, [BPB_NumberOfFATs]
	mov BX, [BPB_SectorsPerFAT]
	mul BX ; BX = NumFATS * SecPerFAT
	mov BX, AX
	add BX, [BPB_ReservedSectors] ; BX now contains LBA value aka NumFATS * SecPerFAT + ResvSecs
	push DI
	push ES
	mov AX, [BPB_RootEntries]
	shl AX, 5
	xor DX, DX
	div WORD[BPB_BytesPerSector] ; AL = (RootEntries * 32) / BytesPerSec
	mov AH, 0x0002
	push AX
	mov AX, 0x0800
	mov ES, AX ; ES = 0x0800
	pop AX
	mov DI, 0x0000
	call ReadSectors
	mov CX, [BPB_RootEntries]
	push DS
	push AX
	mov AX, 0x0800
	mov ES, AX
	mov DS, AX
	pop AX
	mov DI, 0x0000
	.FindBootSectorTwo:
		push SI
		push DI
		push CX
		mov CX, 11
		mov SI, BootloaderSTG2
		rep cmpsb
		pop CX
		pop DI
		pop SI
		je LOAD_BOOTLOADER_STG2
		add DI, 32
		loop .FindBootSectorTwo
		jmp ERROR_NOT_FOUND
If you need any additional peaces of code -- tell me. I'll give you whatever you need.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Prints the wrong filename

Post by BMW »

Why do you do mov di,0x0000?

At memory location 0x0000 is the interrupt vector table...
http://wiki.osdev.org/Memory_Map_%28x86%29

Comparing the filename with the IVT is no good
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Prints the wrong filename

Post by bluemoon »

BMW wrote:Why do you do mov di,0x0000?

At memory location 0x0000 is the interrupt vector table...
http://wiki.osdev.org/Memory_Map_%28x86%29

Comparing the filename with the IVT is no good

Code: Select all

mov AX, 0x0800
mov ES, AX ; ES = 0x0800
pop AX
mov DI, 0x0000
0800:0000 is not IVT.

Code: Select all

rep cmpsb
Do you mean repe cmpsb?
Post Reply