Simple bootloader is outside RAM, when running it with qemu

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
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Simple bootloader is outside RAM, when running it with qemu

Post by leonid »

Hello. I'm trying to run a simple bootloader using qemu.

Code: Select all

start:
    jmp start

    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
and what I've done and what I've got:

Code: Select all

 $ nasm -f bin -o boot.bin boot.s

 $ dd if=/dev/zero of=boot.img bs=1M count=64
64+0 records in
64+0 records out
67108864 bytes (67 MB) copied, 0.178296 s, 376 MB/s

 $ dd status=noxfer conv=notrunc if=boot.bin of=boot.img
1+0 records in
1+0 records out

 $ qemu -pflash boot.img 
qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000

EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000633
ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000000
EIP=000affd6 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 00000000 0000ffff 00009300
CS =f000 ffff0000 0000ffff 00009b00
SS =0000 00000000 0000ffff 00009300
DS =0000 00000000 0000ffff 00009300
FS =0000 00000000 0000ffff 00009300
GS =0000 00000000 0000ffff 00009300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 0000ffff
IDT=     00000000 0000ffff
CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00000000 CCO=ADDB    
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
Aborted
All these things I'm doing in Debian x64. I've tried to use linker scripts and elf64 configuration when building object file, but it doesn't work. I guess the problem is in the code of bootloader. But where?
I found something the same here: http://forum.osdev.org/viewtopic.php?f=1&t=14507, but i don't understand clearly what is exactly wrong.
Thank you very much.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:Hello. I'm trying to run a simple bootloader using qemu.

Code: Select all

start:
    jmp start

    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
and what I've done and what I've got:

Code: Select all

 $ nasm -f bin -o boot.bin boot.s

 $ dd if=/dev/zero of=boot.img bs=1M count=64
64+0 records in
64+0 records out
67108864 bytes (67 MB) copied, 0.178296 s, 376 MB/s

 $ dd status=noxfer conv=notrunc if=boot.bin of=boot.img
1+0 records in
1+0 records out

 $ qemu -pflash boot.img 
qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000

EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000633
ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000000
EIP=000affd6 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 00000000 0000ffff 00009300
CS =f000 ffff0000 0000ffff 00009b00
SS =0000 00000000 0000ffff 00009300
DS =0000 00000000 0000ffff 00009300
FS =0000 00000000 0000ffff 00009300
GS =0000 00000000 0000ffff 00009300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 0000ffff
IDT=     00000000 0000ffff
CR0=60000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000 
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00000000 CCO=ADDB    
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
Aborted
All these things I'm doing in Debian x64. I've tried to use linker scripts and elf64 configuration when building object file, but it doesn't work. I guess the problem is in the code of bootloader. But where?
I found something the same here: http://forum.osdev.org/viewtopic.php?f=1&t=14507, but i don't understand clearly what is exactly wrong.
Thank you very much.

Did you set the ORG or are you not using NASM? Cause if your writing a Bootloader, if I am mistaken you should add:

Code: Select all

[BITS 16]
[ORG 0x7C00]
If your using NASM, if not still try to set the where the program will be loaded to.

- Matt
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

I've tried, but it didn't help too :|
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:I've tried, but it didn't help too :|
What does your current code look like?

Thanks, Matt
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

That's it:

Code: Select all

    BITS 16
    org 0x7C00
    jmp 0x0000:start
    
start:
    jmp start
    
    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

And, PearOs, ,from your first post, is it better to use gcc?
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:That's it:

Code: Select all

    BITS 16
    org 0x7C00
    jmp 0x0000:start
    
start:
    jmp start
    
    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
I've personally never used GCC so I wouldn't know. But remove "jmp 0x0000:start" your telling the CPU to use Code Segment 0x0000. Just do "jmp start" then try that.

Thanks, Matt
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

Code: Select all

    BITS 16
    org 0x7C00

start:
    jmp start
    
    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
The same error.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:

Code: Select all

    BITS 16
    org 0x7C00

start:
    jmp start
    
    times 510 - ($ - $$) db 0
    db 55h
    db 0AAh
The same error.
Ok well I took that and compiled it using a build script I wrote and booted it in Bochs with no problem. What does your build script look like? Cause your code is spot on.

Mine looks like this:
nasm -f bin Bootloader.asm -o boot.bin
dd conv=notrunc if=boot.bin of=bin/boot.flp

Thanks, Matt
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

build.sh

Code: Select all

nasm -f bin -o boot.bin boot.s
dd status=noxfer conv=notrunc if=boot.bin of=boot.img
qemu -pflash boot.img 
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:build.sh

Code: Select all

nasm -f bin -o boot.bin boot.s
dd status=noxfer conv=notrunc if=boot.bin of=boot.img
qemu -pflash boot.img 
Ok try removing "status=noxfer". Now "pflash"? I don't know Qemu 100% but boot.img is a floppy image, so make sure you load it as one. If that doesn't work try getting Bochs, and then using this configuration

bochs -f config.txt

Config.txt:
floppya: 1_44="boot.flp", status=inserted
memory: guest=256, host=256
boot: floppy

Thanks, Matt
leonid
Posts: 7
Joined: Wed Dec 25, 2013 2:36 pm

Re: Simple bootloader is outside RAM, when running it with q

Post by leonid »

Ok, what was wrong is using -pflash... I just replaced it with -fda and the program worked. Some time ago using floppy cosed: "PC system firmware (pflash) must be a multiple of 0x1000". Solved. I sould be more careful. Thank you.
Last edited by leonid on Wed Dec 25, 2013 3:47 pm, edited 1 time in total.
PearOs
Member
Member
Posts: 194
Joined: Mon Apr 08, 2013 3:03 pm
Location: Usually at my keyboard!

Re: Simple bootloader is outside RAM, when running it with q

Post by PearOs »

leonid wrote:Ok, what was wrong is using -pflash... I just replaced it with -fda and the program works. Some time ago using floppy cosed: "PC system firmware (pflash) must be a multiple of 0x1000". Solved. I sould be more careful. Thank you.
I thought pflash might have been the issue. Your very welcome.

- Matt
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: Simple bootloader is outside RAM, when running it with q

Post by Combuster »

pflash was the obvious error because it's not listed in the wiki examples. Which makes me wonder where you got the idea from in the first place.
"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 ]
Post Reply