help, load from disk

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
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

help, load from disk

Post 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.
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: help, load from disk

Post by M2004 »

You disable interrupts without enabling them back, when you use
bios int's.

regards
M2004
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: help, load from disk

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: help, load from disk

Post 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.)
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Re: help, load from disk

Post 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?
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: help, load from disk

Post by iansjack »

You load the sector to 0x0000:0x1000 and then jump to 0x1000:0x0000. That's not going to work.
skid
Posts: 11
Joined: Wed Dec 17, 2014 12:43 pm

Re: help, load from disk

Post 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
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: help, load from disk

Post 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:
"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 ]
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: help, load from disk

Post 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.
Post Reply