Page 1 of 1
Simple bootloader is outside RAM, when running it with qemu
Posted: Wed Dec 25, 2013 3:06 pm
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.
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:10 pm
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:
If your using NASM, if not still try to set the where the program will be loaded to.
- Matt
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:16 pm
by leonid
I've tried, but it didn't help too

Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:19 pm
by PearOs
leonid wrote:I've tried, but it didn't help too

What does your current code look like?
Thanks, Matt
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:22 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:24 pm
by leonid
And, PearOs, ,from your first post, is it better to use gcc?
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:25 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:28 pm
by leonid
Code: Select all
BITS 16
org 0x7C00
start:
jmp start
times 510 - ($ - $$) db 0
db 55h
db 0AAh
The same error.
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:30 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:32 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:35 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:40 pm
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.
Re: Simple bootloader is outside RAM, when running it with q
Posted: Wed Dec 25, 2013 3:41 pm
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
Re: Simple bootloader is outside RAM, when running it with q
Posted: Thu Dec 26, 2013 9:58 am
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.