calling asm function from c
calling asm function from c
I'm using gcc as a compiler, nasm as an assembler and ld as a linker.
When I call an asm function from my c code the code craches.
I use bochs as an emulator and it says: "00000576062p[CPU ] >>PANIC<< prefetch: running in bogus memory" end the EIP is: 1012492f, which is way outside of the amount of allocated memory, also when I disassemble my kernel with ndisasm, I can see some calls which are outside of the bounds of my kernel. Anybody know what i'm doing wrong and how to fic this?
Thanks in advance,
Jules
When I call an asm function from my c code the code craches.
I use bochs as an emulator and it says: "00000576062p[CPU ] >>PANIC<< prefetch: running in bogus memory" end the EIP is: 1012492f, which is way outside of the amount of allocated memory, also when I disassemble my kernel with ndisasm, I can see some calls which are outside of the bounds of my kernel. Anybody know what i'm doing wrong and how to fic this?
Thanks in advance,
Jules
He is telling you to put a cli hlt so that if nothing goes wrong with the hlt in place, you know that it isn't the function call. That's one of the first things to do when debugging a kernel.
When I read your post I immediately thought that it was some bug with the linker. Is your linker script correct.
When I read your post I immediately thought that it was some bug with the linker. Is your linker script correct.
I have put a cli, hlt infront of the function and still got the same error, so its probably an error with the function call and I've put the function in the .text section and my linker script seems correct though simple.
Here it is:
I get no compile or assemble warnings/errors.
Anybody see any problems?
Thanks in advance,
Jules
Here it is:
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(main)
SECTIONS
{
.text 0x100000 : {
*(.text)
}
.data : {
*(.data)
}
.bss :
{
*(.bss)
}
}
Anybody see any problems?
Thanks in advance,
Jules
Yah sorry, should have done so at the beginning...
I'm calling this function:
its a basic isr from c with a simple call:
I define the like this:
and in asm:
Anybody see any problems?
Thanks in advance,
Jules
edit: I think it might be because i'm calling it as an function thought it is an isr and using iret though the CPU didn't call from an interupt... therefore the SS, EIP, ESP and CS are not poped to the stack, but the CPU pops them back at the end because of the iret even though there not on the stack...
I'm calling this function:
Code: Select all
_isr0:
cli
hlt
pusha
push es
push ds
push fs
push gs
mov eax, cr2
push eax
call _int_dev_0
call _hlt_cpu
pop eax
pop s
pop fs
pop ds
pop es
popa
iret
Code: Select all
isr0()
Code: Select all
extern void isr0()
Code: Select all
[global _isr0]
Thanks in advance,
Jules
edit: I think it might be because i'm calling it as an function thought it is an isr and using iret though the CPU didn't call from an interupt... therefore the SS, EIP, ESP and CS are not poped to the stack, but the CPU pops them back at the end because of the iret even though there not on the stack...
- Combuster
- 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:
I was going to suggest the samesuthers wrote:edit: I think it might be because i'm calling it as an function thought it is an isr and using iret though the CPU didn't call from an interupt... therefore the SS, EIP, ESP and CS are not poped to the stack, but the CPU pops them back at the end because of the iret even though there not on the stack...
I didn't have access to my code when i posted my last post, but when I replaced iret by ret, I still get the same problem, I should of known as I still got the problem when I added cli, hlt to the beginning of my isr. So I still don't see what I'm doing wrong, anybody know what's happening?
Also, where would I normally add the .rodata section in the linker script (I've seen it after the .text section, would that be ok?)?
Thanks in advance,
Jules
Also, where would I normally add the .rodata section in the linker script (I've seen it after the .text section, would that be ok?)?
Thanks in advance,
Jules
I noticed the error changed to >>PANIC<< exception(): 3rd (13) exception with no resolution and the final EIP = 00203cb4, which is slightly less crazy than before (this is weird as i haven't really changed any code...)
Ill use the bochs debugger to find the error, but I've never used it before so I'm a bit clueless, I'll post what I've found as soon as I figure it out...
Thanks,
Jules
Ill use the bochs debugger to find the error, but I've never used it before so I'm a bit clueless, I'll post what I've found as soon as I figure it out...
Thanks,
Jules
Ok here are the three exceptions that cause bochs to stop execution:
According to this post: http://www.osdev.org/phpBB2/viewtopic.p ... d9eeaa7818
The vector indicates what interrupt number it is, so there all CPU interrupts caused by exceptions...
So we have a double fault, then a general protection exception, then another double fault...
INT is always 0 (I presume indicating whether the interrupt flag is on or off)
and EXT apparently indicates that its external, but since i haven't activated any devices yet, this is weird, anybody know whats wrong?
Thanks in advance,
Jules
Edit: Also there is the EIP which is way out of the range of memory were I have any instructions... and the fact that when I dissemble it, I see some jumps that seem to be out of the range of instructions loaded in memory...
Code: Select all
00000582862d[CPU ] interrupt(): vector = 8, INT = 0, EXT = 1
00000582862d[CPU ] interrupt(): gate descriptor is not valid sys seg
00000582862d[CPU ] exception(0d h)
00000582862d[CPU ] interrupt(): vector = 13, INT = 0, EXT = 1
00000582862d[CPU ] interrupt(): gate descriptor is not valid sys seg
00000582862d[CPU ] exception(0d h)
00000582862d[CPU ] interrupt(): vector = 8, INT = 0, EXT = 1
00000582862d[CPU ] interrupt(): gate descriptor is not valid sys seg
00000582862d[CPU ] exception(0d h)
The vector indicates what interrupt number it is, so there all CPU interrupts caused by exceptions...
So we have a double fault, then a general protection exception, then another double fault...
INT is always 0 (I presume indicating whether the interrupt flag is on or off)
and EXT apparently indicates that its external, but since i haven't activated any devices yet, this is weird, anybody know whats wrong?
Thanks in advance,
Jules
Edit: Also there is the EIP which is way out of the range of memory were I have any instructions... and the fact that when I dissemble it, I see some jumps that seem to be out of the range of instructions loaded in memory...