Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

$0x13 not reading hdd, BIOS & GNU Assembly

assembly bootloader gnu assembly

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Poe


    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 81 posts

Posted 08 August 2015 - 06:14 AM

I'm attempting to write a FAT filesystem using BI/OS routines.  This is a learning experience to learn GNU Assembly (I can read from a disk in NASM), however I keep running into a problem.  It will not load the disk.  I'm using qemu-kvm on an amd64 and here is the assembler:

.globl _start
_start:	xor %ax, %ax
	mov %cs, %ax
	mov %ax, %ds
	mov %ax, %es

		Clear Screen **/
	mov $0x03, %al
	mov $0x0, %ah
	int $0x10

	mov $boot_msg, %si
	call print

	mov $disk_msg, %si
	call print

	mov $0x1000, %ax
	mov %ax, %es
	mov $0x3, %cl
	mov $0x2, %al

	call load_sector
	.loop:	jmp .loop

print:	mov %sp, %bp
	.continue:	lodsb
		or %al, %al
		jz .done

		mov $0x0e, %ah
		int $0x10

		jmp .continue
		.done:	ret

	Read a Given Sector From Disk **/
read_sector:	pusha
	mov $0x02, %si
	.top:	mov $0x02, %ah
		int $0x13
		jnc .end
		dec %si
		jc .end
		xor %ah, %ah
		int $0x13
		jnc .top
	.end:	popa

load_sector:	mov $0x01, %al
	mov $0x7E00, %bx
	mov $0x0002, %cx
	mov $0x80, %dl
	xor %dh, %dh
	call read_sector
	jnc success_load
	mov $error_msg, %si
	call print

error_load:	mov $error_msg, %si
	call print

success_load:	mov $disk_lod, %si
		call print

boot_msg:	.ascii "Loading...\0"
error_msg:	.ascii "Error Loading Disk...\0"
disk_msg:	.ascii "Start Disk...\0"
disk_lod:	.ascii "Disk Loaded...\0"

. = _start + 510
.byte 0x55
.byte 0xaa

the output is simply:


Loading...Start Disk...Error Loading Disk...


Anyone have any ideas?

"Portability is for those who can't write new programs" - Linus Torvalds

#2 dargueta


    I chown trolls.

  • Moderator
  • 4854 posts

Posted 11 August 2015 - 08:49 PM

You're probably reading from the wrong drive. When the BIOS first boots, DL contains the drive number. Save this somewhere and use that instead of doing mov $0x80, %dl in load_sector. If you're booting off a floppy, 0x80 is the wrong drive number.

Edited by dargueta, 11 August 2015 - 08:50 PM.

sudo rm -rf / && echo $'Sanitize your inputs!'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download