Page 1 of 1

help, load from disk

Posted: Wed Dec 17, 2014 2:20 pm
by skid
i have some problem understanding howto load a file from disk (more like howto build the actual image) with int 13.

i have tried with code from tutorials and compiled like this;

Code: Select all

; -> a.asm
[bits 16]				; real-mode
[org 0x7C00]

entry:
	mov ax, cs 			; cs = 7c00
	mov ds, ax
	mov ss, ax
	mov sp, 0x9C00

	cli					; turn off interrupts
	jmp 0x0000:start		


start:

	mov   ax, 0x1112
	mov   bl, 0x00
	int   0x10	

load:
	xor ax, ax
	int 0x13	
	jc load		

	xor ax, ax
   	mov es,ax
	mov bx, 0x1000		
    mov ax,0x0207		
    mov cx,0x0002		
    mov dx,0x0000		
    int 0x13		
    jc load		

jmp $
times 510-($-$$) db 0
dw 0AA55h

; b.asm
[bits 16]

[org 0x1000]

	mov ax, 0xb800
	mov es, ax

	xor di, di
	mov byte [es:di], "K"
	

Code: Select all

nasm a.asm -o a.bin
nasm b.asm -o b.bin
build a floppy;

Code: Select all

dd if=/dev/zero of=floppy.img count=2880 bs=512
dd if=a.bin count=1 bs=512 of=floppy.img
dd if=b.bin seek=1 bs=512 of=floppy.img
I get no boot media found i virtualbox ?
someone please explain or guide me to some working tutorial without grub, using dd.

Re: help, load from disk

Posted: Wed Dec 17, 2014 3:09 pm
by M2004
You disable interrupts without enabling them back, when you use
bios int's.

regards
M2004

Re: help, load from disk

Posted: Wed Dec 17, 2014 8:54 pm
by Brendan
Hi,
skid wrote:I get no boot media found i virtualbox ?
That usually means the BIOS couldn't find the 0xAA55 marker at the end of your first sector.
skid wrote:

Code: Select all

dd if=/dev/zero of=floppy.img count=2880 bs=512
dd if=a.bin count=1 bs=512 of=floppy.img
dd if=b.bin seek=1 bs=512 of=floppy.img
Sadly, I can't see anything that would cause the marker to be in the wrong place, in either the assembly or the "dd" commands.

Your best option would be to examine the resulting floppy disk image manually (e.g. with something like "hexdump") to check if the marker really is where it should be.

Of course maybe the problem is something else entirely; like telling virtualbox the wrong file name or setting it to "boot from hard disk".


Cheers,

Brendan

Re: help, load from disk

Posted: Thu Dec 18, 2014 1:43 am
by Octocontrabass
skid wrote:

Code: Select all

	mov ax, cs 			; cs = 7c00
	mov ds, ax
	mov ss, ax
Do not use the value of CS given by the BIOS. It is not guaranteed to be correct. Since you are using [org 0x7C00], you probably want to set DS and SS to zero.
skid wrote:

Code: Select all

dd if=/dev/zero of=floppy.img count=2880 bs=512
dd if=a.bin count=1 bs=512 of=floppy.img
dd if=b.bin seek=1 bs=512 of=floppy.img
How big is the resulting file? It must be exactly 1,474,560 bytes or emulators will have trouble reading it correctly. (You may need to add conv=notrunc to your commands.)

Re: help, load from disk

Posted: Thu Dec 18, 2014 4:03 am
by skid
i guess the noconv did the trick but still it doesnt load the file (or jump to the right location),

Code: Select all

     mov byte [gs:di], "A"
load:
    xor ax, ax
    int 0x13   
    jc load      

    xor ax, ax
    mov es,ax
    mov bx, 0x1000      
    mov ax,0x0207      
    mov cx,0x0002      
    mov dx,0x0000      
    int 0x13       
    jc load      

    add di, 2
    mov byte [gs:di], "B"

    jmp 0x1000:0000
in b.asm it's supposed to print C but I never get there, A and B prints though. I have tried to alter the jump in all sorts of ways. what am I doing wrong here?

Re: help, load from disk

Posted: Thu Dec 18, 2014 4:16 am
by iansjack
You load the sector to 0x0000:0x1000 and then jump to 0x1000:0x0000. That's not going to work.

Re: help, load from disk

Posted: Thu Dec 18, 2014 4:49 am
by skid
iansjack wrote:You load the sector to 0x0000:0x1000 and then jump to 0x1000:0x0000. That's not going to work.
yeah but i tried the otherway around but it didn't work (then) for some reason, but now i have got it working. (jmp 0:0x1000)

thanks for the input and corrections

Re: help, load from disk

Posted: Thu Dec 18, 2014 5:34 am
by Combuster
skid wrote:yeah but i tried the otherway around but it didn't work (then) for some reason, but now i have got it working. (jmp 0:0x1000)
That's why you should never "try" fixes :wink:

Re: help, load from disk

Posted: Thu Dec 18, 2014 7:11 am
by iansjack
skid wrote:
iansjack wrote:You load the sector to 0x0000:0x1000 and then jump to 0x1000:0x0000. That's not going to work.
yeah but i tried the otherway around but it didn't work (then) for some reason, but now i have got it working. (jmp 0:0x1000)

thanks for the input and corrections
You really want to take some time out to study and understand how segmentation works in x86 processors. It's only going to get more complicated from here on and you are going to find it very frustrating if you don't really understand code that you are copying.