Trying to execute code outside RAM?

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.
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Trying to execute code outside RAM?

Post by Lionel »

Hello!
My kernel, Chronos, was enabling interrupts, and crashed qemu with the message "Trying to execute code outside RAM or ROM at 0x000000006a006afa".
This address is never defined in my code, so the only clue I have is that it's in the irq code (It works fine with normal interrupts)
This is the output from qemu:

Code: Select all

qemu: fatal: Trying to execute code outside RAM or ROM at 0x000000006a006afa

EAX=00103000 EBX=00010000 ECX=000b82a4 EDX=000703d5
ESI=00000000 EDI=00000000 EBP=0007fef0 ESP=0007fecc
EIP=6a006afa EFL=00200002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     00104040 00000027
IDT=     00104080 000007ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000008 CCD=00103000 CCO=LOGICB  
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
The link to the code is in my sig (in the dev branch)
Thanks,
Lionel
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Trying to execute code outside RAM?

Post by VolTeK »

No one should have to click the link to solve your problem. Use the debugger.
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: Trying to execute code outside RAM?

Post by Lionel »

Debugger? Do you mean gdb? I could never get it to work with qemu...
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Trying to execute code outside RAM?

Post by bubach »

Try bochs and it's internal debugger.
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: Trying to execute code outside RAM?

Post by Lionel »

Also could never get bochs to work. :oops:
Maybe developing on a prerelease version of Ubuntu was a bad thing...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Trying to execute code outside RAM?

Post by gerryg400 »

I'll give you a clue.

Code: Select all

EIP=6a006afa
If you reverse the contents of the EIP you get

Code: Select all

EIP=fa6a006a
If you then pass that through a disassembler you get

Code: Select all

    cli
    push  0
    push  ...
If a trainstation is where trains stop, what is a workstation ?
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Trying to execute code outside RAM?

Post by gravaera »

Yo:

One of the few core basics of getting a kernel to run is to ensure that the CPU is executing the code in the first place... ;)
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: Trying to execute code outside RAM?

Post by assembler01 »

I had the same problem with my bootloader and it turned out to be a segmentation problem, so maby that is what it is.
PS: This is my first post.
Talk is cheap, show me the code. - Linus Torvalds
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: Trying to execute code outside RAM?

Post by bubach »

Lionel wrote:Also could never get bochs to work. :oops:
This is my bochsrc.bxrc (just trial&error on my part with some googling to get this working with bochs 2.5.1)

Code: Select all

# configuration file generated by Bochs
#plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, gameport=1, pci_ide=1, acpi=1, ioapic=1
config_interface: win32config
display_library: win32
megs: 32
#romimage: file="C:\Program\Bochs-2.5.1\BIOS-bochs-latest"
#vgaromimage: file="C:\Program\Bochs-2.5.1\VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
magic_break: enabled=1
floppya: type=1_44, 1_44="a:", status=inserted
# no floppyb
and I use real floppies or mount a 1.44mb image file with the program ImDisk:
http://www.ltr-data.se/opencode.html/#ImDisk
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: Trying to execute code outside RAM?

Post by assembler01 »

If you look at the segment registers you can see that cs is different from all the other segment regs, so you can try loading your segment regs with this:

Code: Select all

mov ax, cs
mov ds, ax
mov ss, ax
mov fs, ax
mov gs, ax
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Trying to execute code outside RAM?

Post by gerryg400 »

CS should be different from the other segment regs.

Since the hint didn't work ...

The bug is here, in descriptor_tables.c line 25

Code: Select all

//Apparently, I have to extern IRQ's
extern u32int irq0;
Last edited by gerryg400 on Mon Feb 27, 2012 2:57 pm, edited 2 times in total.
If a trainstation is where trains stop, what is a workstation ?
assembler01
Member
Member
Posts: 25
Joined: Mon Feb 27, 2012 9:46 am

Re: Trying to execute code outside RAM?

Post by assembler01 »

But if you have a bootloader then cs is 07C0h, right?
Talk is cheap, show me the code. - Linus Torvalds
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Trying to execute code outside RAM?

Post by gerryg400 »

Chronos boots from Grub I think. So it's already in protected mode.
If a trainstation is where trains stop, what is a workstation ?
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: Trying to execute code outside RAM?

Post by Combuster »

The effect of Segmentation is different in Protected Mode compared to Real Mode.

Also, you're hijacking someone else's thread. It's better that you refrain from posting than to just guess because wrong information isn't helping anyone. If you don't understand something, will you please make a new thread so we can help you instead of fencing you out like paparazzi.
"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
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: Trying to execute code outside RAM?

Post by Lionel »

I had to externalize the irqs because they wouldn't be recognized by C.
Also, I don't get what your saying with line 25, what's wrong with it? I have a feeling its the type.
Post Reply