Crash on memcpy (movsb) ?
-
- Posts: 22
- Joined: Mon Dec 04, 2006 5:34 pm
Crash on memcpy (movsb) ?
Hello,
Well, I recently tried to run my OS on vmware (I was always using qemu), and I found that it crashes when loading the OS in memory. I did various tests, and I found that the error happens while loading the kernel into memory (at 0x100000)...
Error message from VMWare :
*** Virtual machine kernel stack fault (hardware reset) ***
The virtual machine just suffered a stack fault in kernel mode. On a real computer, this would amount to a reset of the processor. It can be caused by an incorrect configuration of the virtual machine, a bug in the operating system, or a problem in the VMware Workstation software. Press OK to reboot virtual machine or Cancel to shut it down.
I tried to use my printf() function to see where it crashes, and I found that the problem happens while calling memcpy() (it's just a simple memcpy I coded, which use movsb, and works well on qemu).
If anyone knows why it happens, I'd be happy to have an explanation (seems that I'm able to write directly in this part of the memory, and read, etc...).
I also tried with a simple copy-loop (for+*(mem++)=buf) and I got the same result.
Well, I recently tried to run my OS on vmware (I was always using qemu), and I found that it crashes when loading the OS in memory. I did various tests, and I found that the error happens while loading the kernel into memory (at 0x100000)...
Error message from VMWare :
*** Virtual machine kernel stack fault (hardware reset) ***
The virtual machine just suffered a stack fault in kernel mode. On a real computer, this would amount to a reset of the processor. It can be caused by an incorrect configuration of the virtual machine, a bug in the operating system, or a problem in the VMware Workstation software. Press OK to reboot virtual machine or Cancel to shut it down.
I tried to use my printf() function to see where it crashes, and I found that the problem happens while calling memcpy() (it's just a simple memcpy I coded, which use movsb, and works well on qemu).
If anyone knows why it happens, I'd be happy to have an explanation (seems that I'm able to write directly in this part of the memory, and read, etc...).
I also tried with a simple copy-loop (for+*(mem++)=buf) and I got the same result.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Interesting...
Code: Select all
void *
memcpy(void *dest, const void *src, size_t len)
{
char *d = dest;
const char *s = src;
while (len--)
*d++ = *s++;
return dest;
}
-
- Posts: 22
- Joined: Mon Dec 04, 2006 5:34 pm
Ok, the crash still happens with Brynet-Inc's function (a bit modified).
Fyi, this happens in the bootloader. 512 bytes of data is read to memory location 0x68010 (using 16bit interrupt), then it's copied to 0x100000 in the 32bit bootloader code.
This just shows :
(and then the vmware crashes, still same message)
I tried to put the kprintf() in the while loop... vmware no longer shows a message saying it crashed, however the copy seems to freeze quickly.
Shot: http://mikan.ookoo.org/vmware_crash_memcpy.png
Btw that's how my initial memcpy() function was :
(found it on IBM's website, and it works well on qemu)
Fyi, this happens in the bootloader. 512 bytes of data is read to memory location 0x68010 (using 16bit interrupt), then it's copied to 0x100000 in the 32bit bootloader code.
Code: Select all
void *memcpy(void *dest, const void *src, size_t len) {
kprintf("memcpy: %p->%p (len=%d)\r\n", src, dest, len);
char *d = dest;
const char *s = src;
while (len--)
*d++ = *s++;
kprintf("memcpy: finished\r\n");
return dest;
}
Code: Select all
memcpy: 0x00068010->0x00100000 (len=512)
I tried to put the kprintf() in the while loop... vmware no longer shows a message saying it crashed, however the copy seems to freeze quickly.
Shot: http://mikan.ookoo.org/vmware_crash_memcpy.png
Btw that's how my initial memcpy() function was :
Code: Select all
void *memcpy (void *__restrict __dest,
__const void *__restrict __src, uint32_t __n) {
__asm__ ("cld\n"
"rep\n"
"movsb"
: /* no input (?) */
: "S"(__src), "D"(__dest), "c"(__n));
return __dest;
}
-
- Posts: 22
- Joined: Mon Dec 04, 2006 5:34 pm
Ok, it seems to be related to the A20 line. I don't understand why, I already coded something to enable it, however it seems that it didn't work.
Well, I guess I'll have to try to fix that, thanks for the help, now I know where I have to look
EDIT:
Ok, the code I initially took from grub (I didn't want to bother with that) didn't work, so I replaced by this tiny code :
And... it worked! Thanks!
Well, I guess I'll have to try to fix that, thanks for the help, now I know where I have to look
EDIT:
Ok, the code I initially took from grub (I didn't want to bother with that) didn't work, so I replaced by this tiny code :
Code: Select all
outb(0x92, inb(0x92)|2);
Hi,
Cheers,
Brendan
You might like to read something like this web page about A20 issues.....MagicalTux wrote:Ok, the code I initially took from grub (I didn't want to bother with that) didn't work, so I replaced by this tiny code :And... it worked! Thanks!Code: Select all
outb(0x92, inb(0x92)|2);
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.
-
- Posts: 22
- Joined: Mon Dec 04, 2006 5:34 pm
Yeah I know about A20 issues, however for now I had no bugreport from people with old machines.
Anyway my OS won't work on old hardware (pre-pentium) so it's probably not that problematic. Maybe one day more than two people will use my OS, in this case I'll consider about having a good fix to the A20 problem.
Anyway my OS won't work on old hardware (pre-pentium) so it's probably not that problematic. Maybe one day more than two people will use my OS, in this case I'll consider about having a good fix to the A20 problem.