Oddity at 0x0000:0x0900.

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
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Oddity at 0x0000:0x0900.

Post by StephanvanSchaik »

Greetings,

I'm currently stuck on a bug while I was rewriting second stage of my boot loader. My boot sector loads my second stage to 0x0000:0x0500, which works fine. The second stage is currently about 1172 bytes in size and 1979-2614 (in RAM, so plus 0x500 bytes) is filled up with messages which are being display in order to present the current state of the second stage. However, when I created a new floppy image and booted it on Qemu, Bochs and VirtualBox, it displayed:

Code: Select all

Trying to ent
???OEMID
Where ??? is actually an replacement for some odd characters. I'm assuming this is:

Code: Select all

jmp short main
nop

OEM:					db "OEMID"



times 11 - ($ - $$)	db 0
However, that code is at 0x0000:0x7C00 and not at 0x0000:0x0900, which is where that code is being presented instead. Also, when doing a hexdump on the file, I'm getting this:

Code: Select all

2288  \r  \n  \0   T   r   y   i   n   g       t   o       e   n   t
         0d  0a  00  54  72  79  69  6e  67  20  74  6f  20  65  6e  74
2304   e   r       u   n   r   e   a   l       m   o   d   e   .  \r
So I'm assuming my file is fine. Also, when I left out some code in my Assembly file, reassembled it and then did a hexdump, I got this:

Code: Select all

2272  \n  \0   T   r   y   i   n   g       t   o       e   n   t   e
         0a  00  54  72  79  69  6e  67  20  74  6f  20  65  6e  74  65
2288   r       u   n   r   e   a   l       m   o   d   e   .  \r  \n
         72  20  75  6e  72  65  61  6c  20  6d  6f  64  65  2e  0d  0a
2304  \0   N   o   w       r   u   n   n   i   n   g       i   n    
         00  4e  6f  77  20  72  75  6e  6e  69  6e  67  20  69  6e  20
And the display showed:

Code: Select all

Trying to enter unreal mode.
???OEMID
So I concluded that the boot sector or something is being copied to 0x0000:0x0900 or is at least present at that address. However, this is odd as 0x0000:0x7C00 isn't 0x0000:0x0900. So I'm currently wondering what is actually happening here. Does the BIOS reserve this area for a copy of the boot sector or something similar?

Edit: fixed up the numbers as the switching between octal, hexadecimal and decimal was getting confusing.


Regards,
Stephan J.R. van Schaik.
Last edited by StephanvanSchaik on Wed Dec 23, 2009 1:49 am, edited 1 time in total.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Oddity at 0000:1500.

Post by ~ »

Try to check and fix the following:

- That your stack's SS and SP registers (SS:SP) aren't set to a location that you are trying to use.
- That other segment registers aren't pointing to wrong areas and used with string instructions.
- That you aren't using any reserved RAM areas of the first Megabyte.
- Any other bugs that your code could have.
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: Oddity at 0x0000:0x0900.

Post by StephanvanSchaik »

~ wrote:- That your stack's SS and SP registers (SS:SP) aren't set to a location that you are trying to use.
The stack is set up using the following code:

Code: Select all

	xor ax, ax

	...

	mov ss, ax
	mov sp, 0xFFFF
~ wrote:- That other segment registers aren't pointing to wrong areas and used with string instructions.
All my segment registers are set to 0 and my origin (at the top of my file) is set to 0x0500.

Code: Select all

.setup_segments:
	; Set up the segment registers.
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
~ wrote:- That you aren't using any reserved RAM areas of the first Megabyte.
Only using everything after 0x0500 up to 0xFFFF.
~ wrote:- Any other bugs that your code could have.
My code mainly exists out of enabling the A20 until the part of the unreal mode.

Code: Select all

[BITS 16]
[ORG 0x0500]

boot:
	jmp short main
	nop

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BIOS Parameter Block														  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; The OEM name (8 bytes).
OEM:					db ""

; Ensure the OEM has the right size.
times 11 - ($ - $$)	db 0

; Bytes per sector (2 bytes).
BytesPerSector:			dw 0

; Sectors per cluster (1 byte).
SectorsPerCluster:		db 0

; Reserved sectors (2 bytes).
ReservedSectors:		dw 0

; Amount of file allocation tables (1 byte).
FATs:					db 0

; Amount of entries in the root directory (2 bytes).
RootEntries:			dw 0

; The amount of sectors (2 bytes).
Sectors16:				dw 0

; The media descriptor (1 byte).
MediaDescriptor:		db 0

; Sectors per file allocation table (2 bytes).
SectorsPerFAT:			dw 0

; Sectors per track (2 bytes).
SectorsPerTrack:		dw 0

; Amount of heads (2 bytes).
Heads:					dw 0

; Amount of hidden sectors (4 bytes).
HiddenSectors			dd 0

; The amount of sectors (4 bytes).
Sectors32:				dd 0

; Ensure the EBPB starts at the right place.
times 36 - ($ - $$)		db 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Extended BIOS Parameter Block											  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; BIOS drive number (1 byte).
Drive:					db 0

; Flags used by Microsoft Windows NT (1 byte).
Flags:					db 0

; Signature used by Microsoft Windows NT (1 byte).
Signature:				db 0

; Volume ID (serial) (4 bytes).
VolumeID:				dd 0

; Ensure the volume ID has the right size.
times 43 - ($ - $$)		db 0

; Volume label (11 bytes).
VolumeLabel:			db ""

; Ensure the volume label has the right size.
times 54 - ($ - $$)		db 0

; System ID (8 bytes).
SystemID:				db ""

; Ensure the system ID has the right size.
times 62 - ($ - $$)		db 0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Entry Point																  ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

main:
	; Disable interrupts.
	cli

	; Nullify ax.
	xor ax, ax

.setup_segments:
	; Set up the segment registers.
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax

.setup_stack:
	; Set up the stack at 0000:FFFF.
	mov ss, ax
	mov sp, 0xFFFF

	; Display a welcome message.
	mov si, msg
	call print16

.copy_bpb:
	; Copy the BIOS Parameter Block and the extended BIOS Parameter Block.
	; TODO: uncomment when the bug has been found and fixed.
	;mov si, 0x7C03
	;mov di, 0x0503
	;mov cx, 59
	;rep movsb
	;mov si, VolumeLabel
	;call print16

.enable_a20:
	; Display that we're using the FAST A20 method.
	mov si, msgA20FAST
	call print16

	; Try and check if the A20 fast gate is supported.
	in al, 0x92
	cmp al, 0xFF
	je .no_fast_a20

	; Enable the A20 line via the fast gate.
	or	al, 2
	and al, 0xFE
	out	0x92, al

	jmp .done_a20

.no_fast_a20:
	; Display that we're using the BIOS A20 method.
	mov si, msgA20BIOS
	call print16

	; Try and check if the BIOS functions are supported.
	mov ax, 0x2403
	int 0x15
	jc .no_bios_a20

	cmp bx, 0x86
	je .no_bios_a20

	; Try and check if the A20 is already enabled.
	mov ax, 0x2402
	int 0x15
	jc .no_bios_a20
	cmp bx, 0x86
	je .no_bios_a20
	test al, al
	jnz .done_a20

	; Try to enable the A20 line.
	mov ax, 0x2401
	int 0x15
	jc .no_bios_a20
	cmp bx, 0x86
	jne .done_a20

.no_bios_a20:
	; Display that we're using the KBC A20 method.
	mov si, msgA20KBC
	call print16

	; Try to enable the A20 line via the keyboard controller.
	mov al, 0xDD
	out 0x64, al

	; Test if the A20 line is enabled.
	in al, 0x60
	bt ax, 1
	jc .done_a20

.no_kbc_a20:
	; Display that we're using the OP A20 method.
	mov si, msgA20OP
	call print16
	
	; Disable the keyboard.
	call .wait_input_a20
	mov al, 0xAD
	out 0x64, al
	call .wait_input_a20

	; Tell the controller to read from the output port.
	mov al, 0xD0
	out 0x64, al
	call .wait_output_a20

	; Get the data from the output port and store it
	in al, 0x60
	push eax
	call .wait_input_a20

	; Tell the controller to write to the output port.
	mov al, 0xD1
	out 0x64, al
	call .wait_input_a20

	; Write out data back to the output port.
	pop eax
	or al, 2
	out 0x60, al

	; Re-enable the keyboard.
	call .wait_input_a20
	mov al, 0xAE
	out 0x64, al
	call .wait_input_a20

	; Test if the A20 line is enabled.
	in al, 0x60
	bt ax, 1
	jc .done_a20

.fail_a20:
	; Display that we failed to enable the A20 line.
	mov si, msgA20FAIL
	call print16

	; We failed epically.
	jmp epic_fail

.wait_input_a20:
	; Wait for the input buffer to be clear.
	in al, 0x64
	test al, 2
	jnz .wait_input_a20

	ret

.wait_output_a20:
	; Wait for the output buffer to be clear.
	in al, 0x64
	test al, 1
	jz .wait_output_a20

	ret

.done_a20:
	; Display that we succeeded to enable the A20 line.
	mov si, msgA20
	call print16

.enter_unreal_mode:
	; Display that we're trying to enter unreal mode.
	mov si, msgEnteringUM
	call print16

	; Halt here, because otherwise the CPU will triple fault...
	hlt
print16:

Code: Select all

print16:
	lodsb
	or al, al
	jz .done
	mov ah, 0x0E
	int 0x10
	jmp print16

.done:
	ret

Regards,
Stephan J.R. van Schaik.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Oddity at 0x0000:0x0900.

Post by ~ »

If it helps, also remember that the BIOS will always copy the boot sector of a floppy disk to address 07C0:0000 or 0000:7C00, so if the source code you put before is the code of your boot, maybe you should try changing the [ORG 0500h] to [ORG 7C00h] since the first program (boot sector) the BIOS copies from floppy to memory is put in that location.
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: Oddity at 0x0000:0x0900.

Post by StephanvanSchaik »

~ wrote:If it helps, also remember that the BIOS will always copy the boot sector of a floppy disk to address 07C0:0000 or 0000:7C00, so if the source code you put before is the code of your boot, maybe you should try changing the [ORG 0500h] to [ORG 7C00h] since the first program (boot sector) the BIOS copies from floppy to memory is put in that location.
The code in my previous comment was the second stage which is loaded at 0x0000:0x0500 by the boot sector which was loaded at 0x0000:0x7C00 by the BIOS.


Regards,
Stephan J.R. van Schaik.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Oddity at 0x0000:0x0900.

Post by Combuster »

It would probably be more interesting to see your first stage bootloader, being that your image doesn't seem get properly stored in memory. (mainly because the data gets cut off at a 512-byte boundary). Are you rounding the file size down when you should be rounding up? (0x494 bytes -> 0x600 = 3 sectors, not two)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: Oddity at 0x0000:0x0900.

Post by StephanvanSchaik »

Combuster wrote:It would probably be more interesting to see your first stage bootloader, being that your image doesn't seem get properly stored in memory. (mainly because the data gets cut off at a 512-byte boundary). Are you rounding the file size down when you should be rounding up? (0x494 bytes -> 0x600 = 3 sectors, not two)
I see, although I'm not entirely sure about it.

Code: Select all

[BITS 16]

[ORG 0x7C00]



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Boot Point																  ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



boot:

	; Jump over the BIOS Parameter Block.

	jmp short fix_main

	nop

	

; Ensure the BPB starts at the right place.	

times 3 - ($ - $$)		db 0



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; BIOS Parameter Block														  ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



; The OEM name (8 bytes).

OEM:					db "OEMID"



; Ensure the OEM has the right size.

times 11 - ($ - $$)	db 0



; Bytes per sector (2 bytes).

BytesPerSector:			dw 512



; Sectors per cluster (1 byte).

SectorsPerCluster:		db 1



; Reserved sectors (2 bytes).

ReservedSectors:		dw 1



; Amount of file allocation tables (1 byte).

FATs:					db 2



; Amount of entries in the root directory (2 bytes).

RootEntries:			dw 224



; The amount of sectors (2 bytes).

Sectors16:				dw 2880



; The media descriptor (1 byte).

MediaDescriptor:		db 0xF0



; Sectors per file allocation table (2 bytes).

SectorsPerFAT:			dw 9



; Sectors per track (2 bytes).

SectorsPerTrack:		dw 18



; Amount of heads (2 bytes).

Heads:					dw 2



; Amount of hidden sectors (4 bytes).

HiddenSectors			dd 0



; The amount of sectors (4 bytes).

Sectors32:				dd 0



; Ensure the EBPB starts at the right place.

times 36 - ($ - $$)		db 0



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Extended BIOS Parameter Block											  ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



; BIOS drive number (1 byte).

Drive:					db 0



; Flags used by Microsoft Windows NT (1 byte).

Flags:					db 0



; Signature used by Microsoft Windows NT (1 byte).

Signature:				db 0x29



; Volume ID (serial) (4 bytes).

VolumeID:				dd 0



; Ensure the volume ID has the right size.

times 43 - ($ - $$)		db 0



; Volume label (11 bytes).

VolumeLabel:			db "FLOPPY"



; Ensure the volume label has the right size.

times 54 - ($ - $$)		db 0



; System ID (8 bytes).

SystemID:				db "FAT 12"



; Ensure the system ID has the right size.

times 62 - ($ - $$)		db 0



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Entry Point																  ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



fix_main:

	; Ensure the code segment is set to 0.

	jmp 0:main

	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Real Entry Point															  ;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



main:

	; Nullify ax.

	xor ax, ax

	

.setup_segments:

	; Set up the segment selectors.

	mov ds, ax

	mov es, ax

	mov fs, ax

	mov gs, ax

	

.setup_stack:

	; Set up the stack.

	mov ss, ax

	mov sp, 0x7C00



.check_drive:

	; Sanity check on the drive the BIOS passed us.

	test dl, 0x7F

	jnz .invalid_drive

	mov BYTE [Drive], dl

	

.invalid_drive:

	; Just get the drive number from the BPB.

	mov dl, BYTE [Drive]

	

	; If a floppy disk is being used, then get the size of the root directory.

	test dl, dl

	jz .get_root_dir_size

	

	; Otherwise, get the disk geometry first.

	mov ah, 0x08

	int 0x13

	

	; If it fails, get away from here.

	jc .get_root_dir_size



	; Fix up the BPB.

	and cx, 0x3F

	mov WORD [SectorsPerTrack], cx

	mov cl, dh

	inc cx

	mov WORD [Heads], cx

	

.get_root_dir_size:

	; Calculate the root directory size using:

	; (RootEntries * 32) / BytesPerSector

	mov ax, WORD [RootEntries]

	shl ax, 5

	xor dx, dx

	div WORD [BytesPerSector]

	

	; Store the result in cx.

	xchg ax, cx



.get_root_dir_region:

	; Calculate the region of the root directory using:

	; ReservedSectors + (FATs * SectorsPerFAT)

	xor ax, ax

	mov al, BYTE [FATs]

	mul WORD [SectorsPerFAT]

	add ax, WORD [ReservedSectors]



.get_data_region:

	; Calculate the data region using:

	; ReservedSectors + (FATs * SectorsPerFAT) + (RootEntries * 32) / ...

	; ... BytesPerSector

	mov WORD [SystemID], ax

	add WORD [SystemID], cx

	

.load_root:

	; Load the root directory to 0000:7E00

	mov bx, 0x7E00

	call read_sectors

	

.find_file:

	; Try to find the file.

	mov cx, WORD [RootEntries]

	mov di, 0x7E00

	

.find_loop:

	; Loop through each file name and compare.

	push cx

	mov cx, 11

	mov si, ImageName

	push di

	rep cmpsb

	pop di

	je .found_file

	pop cx

	add di, 32

	loop .find_loop

	

.no_file:

	; The file is not found.

	mov si, msgFailure

	

.print:

	lodsb

	or al, al

	jz .print_done

	mov ah, 0x0E

	int 0x10

	jmp .print

	

.print_done:

	

	xor ax, ax

	int 0x16

	int 0x19

	

	cli

	hlt



.found_file:

	; Get the starting cluster of the boot image.

	mov dx, WORD [di + 26]

	mov WORD [SystemID + 2], dx



.load_fat:

	; Get the size of the FAT we stored before.

	xor ax, ax

	mov al, BYTE [FATs]

	mul WORD [SectorsPerFAT]

	mov cx, ax

	

	; Calculate the location of the FAT.

	mov ax, WORD [ReservedSectors]

	

	; Load the FAT to 0000:7E00

	mov bx, 0x7E00

	call read_sectors

	

.load_file:

	mov bx, 0x0500

	push bx

	

.next_cluster:

	mov ax, WORD [SystemID + 2]

	pop bx

	

	sub ax, 2

	xor cx, cx

	mov cl, BYTE [SectorsPerCluster]

	mul cx

	add ax, WORD [SystemID]



	xor cx, cx

	mov cl, BYTE [SectorsPerCluster]

	call read_sectors

	push bx

	

	mov ax, WORD [SystemID + 2]

	mov cx, ax

	mov dx, ax

	shr dx, 1

	add cx, dx

	mov bx, 0x7E00

	add bx, cx

	mov dx, WORD [bx]

	test ax, 1

	jnz .odd

	

.even:

	and dx, 0x0FFF

	jmp .done

	

.odd:

	shr dx, 4

	

.done:

	mov WORD [SystemID + 2], dx

	cmp dx, 0x0FF0

	jb .next_cluster



	mov dl, BYTE [Drive]

	jmp 0x0050:0x0000

	

	cli

	hlt

	

read_sectors:

	mov di, 5

	

.loop:

	push ax

	push bx

	push cx

	

	; Convert the LBA-address to CHS-format.

	xor dx, dx

	div WORD [SectorsPerTrack]

	inc dl

	mov cl, dl

	xor dx, dx

	div WORD [Heads]

	mov dh, dl

	mov dl, al



	; Attempt to read the sector.

	mov ax, 0x0201

	mov dl, BYTE [Drive]

	int 0x13

	jnc .ok

	

	; Reset the drive.

	xor ax, ax

	int 0x13

	

	dec di

	

	pop cx

	pop bx

	pop ax

	

	jnz .loop

	

	int 0x18



.ok:

	pop cx

	pop bx

	pop ax

	

	add bx, WORD [BytesPerSector]

	inc ax

	

	loop read_sectors

	

	ret



msgFailure				db "ERROR: PRESS ANY KEY TO REBOOT...", 0x0D, 0x0A, 0x00

ImageName				db "LOADER  BIN"



times 510 - ($ - $$)	db 0

dw 0xAA55
Regards,
Stephan J.R. van Schaik.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Oddity at 0x0000:0x0900.

Post by ~ »

Maybe it would be better to put those strings in the second stage loader itself. This is the order in which the messages were displayed:

msg
msgA20FAST
msgA20
msgEnteringUM


It didn't seem to display any messages from the 512-byte MBR.

I made a test under Bochs emulator and it FAILED to load with a floppy full of files, but it worked with an empty floppy with your bootsector and your second stage bootloader only.

Maybe 2 things:

- Put your strings in the 2nd stage bootloader itself.
- Review your FAT code or other modules to see if it doesn't have any bugs


After the test, Bochs floppy and VM seemed to freeze, so mayte it would be better to change the HLT instruction by a JMP $ instruction.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Oddity at 0x0000:0x0900.

Post by qw »

This is probably not related to the problem, but you'd better keep the stack aligned: "mov sp, 0xFFFE" or even "mov sp, 0".
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

Re: Oddity at 0x0000:0x0900.

Post by StephanvanSchaik »

~ wrote:Maybe it would be better to put those strings in the second stage loader itself. This is the order in which the messages were displayed:

msg
msgA20FAST
msgA20
msgEnteringUM
Those strings are in the second stage loader already, although I didn't add them to my post. Also, you will not really see the issue as the code you're using might be too small.
~ wrote:It didn't seem to display any messages from the 512-byte MBR.
It isn't supposed to, unless it fails to load the file.
~ wrote:I made a test under Bochs emulator and it FAILED to load with a floppy full of files, but it worked with an empty floppy with your bootsector and your second stage bootloader only.
Are you sure you didn't use FAT16? Only FAT12 is actually 'properly' supported. That's because I was too lazy to write some proper FAT12/FAT16 detect code :lol:.
~ wrote:- Review your FAT code or other modules to see if it doesn't have any bugs
Currently doing that.
~ wrote:After the test, Bochs floppy and VM seemed to freeze, so mayte it would be better to change the HLT instruction by a JMP $ instruction.
I was actually putting hlt in to stop the execution, otherwise, if it would get any further it would try to get into protected mode and load the GDT which will fail as the GDT is replaced by the BPB/EBPB.
Hobbes wrote:This is probably not related to the problem, but you'd better keep the stack aligned: "mov sp, 0xFFFE" or even "mov sp, 0".
Sorry, forgot about that, but is shouldn't change much as I already tried playing around with the stack before posting this topic.

Will probably end up writing some FAT12/FAT16 detection code as well as rewriting the cluster loading code, if it still doesn't solve the issue, you'll probably see me back, replying in this topic.


Regards,
Stephan J.R. van Schaik.
Post Reply