Page 2 of 2

Posted: Mon Jul 10, 2006 1:01 pm
by origin of
chase wrote:The BIOS provides a real mode IDT. In PMode you have to provide everything such as an IDT and the interrupt handling code. But if you do a cli before you start PMode and don't do a sti then your current problem shouldn't be related to the IDT stuff.
so, if isn't IDT, isn't GDT, what is my problem.... :roll:

Posted: Mon Jul 10, 2006 2:15 pm
by rexlunae
chase wrote:The BIOS provides a real mode IDT. In PMode you have to provide everything such as an IDT and the interrupt handling code. But if you do a cli before you start PMode and don't do a sti then your current problem shouldn't be related to the IDT stuff.
Well, disabling interrupts only disables external hardware interrupts. It won't prevent a triple fault caused by a processor-raised exception. If a handler were in place, it may be much easier to figure out what is happening. Of course, getting useful information out of the debugger is likely to require working video IO. I would still start with the IDT, even if there is a good indication that the current problem is elsewhere, because it is so useful for debugging problems like this.

Posted: Mon Jul 10, 2006 2:57 pm
by origin of
rexlunae wrote:
chase wrote:The BIOS provides a real mode IDT. In PMode you have to provide everything such as an IDT and the interrupt handling code. But if you do a cli before you start PMode and don't do a sti then your current problem shouldn't be related to the IDT stuff.
Well, disabling interrupts only disables external hardware interrupts. It won't prevent a triple fault caused by a processor-raised exception. If a handler were in place, it may be much easier to figure out what is happening. Of course, getting useful information out of the debugger is likely to require working video IO. I would still start with the IDT, even if there is a good indication that the current problem is elsewhere, because it is so useful for debugging problems like this.
so....i should try what ??
debugging ?
i try debug with bochs, and with qemu + gdb...this is what i get :

<bochs> n
Next at t=19980401
(0) [0x0007e9c4] 0008:0007e9c4 (unk. ctxt): add byte ptr ds:[eax], al ; 0000
<bochs> n
Next at t=19980402
(0) [0x0007e9c6] 0008:0007e9c6 (unk. ctxt): add byte ptr ds:[eax], al ; 0000
<bochs> nn
bochs:657: syntax error at 'nn'
<bochs> c
Next at t=20048417
(0) [0x0009fd24] 0008:9fd24 (unk. ctxt): lock add eax, esi ; f001f0
<bochs>


mmm...boh
if you want to look the project http://www.upload2.net/page/download/zL ... s.zip.html :wink:

Posted: Mon Jul 10, 2006 5:37 pm
by chase
Yes, you'll need to debug. Personally I don't debug with bochs or other virtual machines. My debugging method for this stage is to print data to the screen(which you can't do) and in the case of triple faults I see where the last place I can put I "jmp $" is without causing a reboot. Since the problem is in C/C++ code you might have to generate assembly, modify the assembly source code, assemble(with as) and then link everything together. I'd say that once you get PMode and basic printing to the screen working that you really want to add the IDT & debugging handler code. Maybe someone else can provide some better debugging techniques for virtual machines and C/C++ code.

Posted: Tue Jul 11, 2006 2:11 am
by origin of
chase wrote:Yes, you'll need to debug. Personally I don't debug with bochs or other virtual machines. My debugging method for this stage is to print data to the screen(which you can't do) and in the case of triple faults I see where the last place I can put I "jmp $" is without causing a reboot. Since the problem is in C/C++ code you might have to generate assembly, modify the assembly source code, assemble(with as) and then link everything together. I'd say that once you get PMode and basic printing to the screen working that you really want to add the IDT & debugging handler code. Maybe someone else can provide some better debugging techniques for virtual machines and C/C++ code.
i know where is the problem...but i don't know how resolve it...
i can print to the video, but only one character...
how can i generate assembly by c++... ?? :roll:

Posted: Tue Jul 11, 2006 8:27 am
by chase
origin of wrote:i know where is the problem...
Does the computer reboot when data is being pushed to the stack before the write call? Is it during the "call" instruction? The "ret" instruction? Is the compiler adding extra stuff that is causing the problem? I'd say the problem is in the code, if we knew where it was we would have fixed it by now :)
origin of wrote: but i don't know how resolve it...
i can print to the video, but only one character...
It still could be a GDT/segment descriptor problem, a compiler issue, a bug in your code, etc. Once you find the exact instruction that is causing the problem then you start to figure out why.
origin of wrote: how can i generate assembly by c++... ?? :roll:
By using the -S option that I keep talking about. Use all the options that you run when you compile but also add these.

Code: Select all

g++ -S -masm=intel -finhibit-size-directive -fverbose-asm -o video..asm video.cpp
g++ -S -masm=intel -finhibit-size-directive -fverbose-asm -o kernel.asm kernel.cpp
The syntax will be a little different then NASM and C++ mangles the symbol names for functions and variables but it should be readable. You have to understand how C/C++ handles argument passing and return values, I have a slightly out of date tutorial here http://www.osdev.org/howtos/1/

Posted: Tue Jul 11, 2006 8:43 am
by origin of
thanks for the help, thanks to all....but....i find the solution...i don't understand because fix my problem, but fix my problem....can you give me an explanetion about how fix my problem ?

i change those files :

kernel.cpp

Code: Select all

//Kernel.cpp
#include "video.h"
void __do_global_ctors (void);
int main(void)
{
__do_global_ctors ();
Video vid ; //local, (global variables need some Run-Time support code)
vid.write("ciao");
while(1);
}

void __do_global_ctors (void)
{
    //la lista dei costruttori è definita nello scrpt di ld
  extern void (*__CTOR_LIST__)();
  void (**constructor)() = &__CTOR_LIST__;
  //il primo intero è il numero di costruttori
  int total = *(int *)constructor;
  constructor++;
  // eseguo i costruttori uno alla volta
  while(total--)
    {
      (*constructor)();
      constructor++;
    }
}
link.ld

Code: Select all

/* LINK.ld*/
OUTPUT_FORMAT("binary")
OUTPUT_ARCH(i386)
ENTRY(_start)
SECTIONS
{
  . = 0x10000;
  .text           :  { *(.text .stub .text.* .gnu.linkonce.t.*)  }
  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  . = DATA_SEGMENT_ALIGN(0x1000, 0x1000);
  . = ALIGN(32 / 8);
  .data           :
  {


  /*costruttori del c++*/
           __CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) *(.ctors)   LONG(0) __CTOR_END__ = .;

        __DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ = .;

    *(.data .data.* .gnu.linkonce.d.*)
    SORT(CONSTRUCTORS)
  }
  .ctors          :
  {
    KEEP (*crtbegin.o(.ctors))
    KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
  }
  .dtors          :
  {
    KEEP (*crtbegin.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.dtors))
  }
  .bss            :  {
    *(.bss .bss.* .gnu.linkonce.b.*)
   *(COMMON)
   . = ALIGN(32 / 8);
  }
  . = ALIGN(32 / 8);
  _end = .;
  PROVIDE (end = .);
  . = DATA_SEGMENT_END (.);
}

OT : why, italian isn't the international language :(

Posted: Tue Jul 11, 2006 1:49 pm
by chase
origin of wrote:thanks for the help, thanks to all....but....i find the solution...i don't understand because fix my problem, but fix my problem....can you give me an explanetion about how fix my problem ?
So it is something the compiler is doing somewhere. From what I can tell it has some thing to do with global object contructors but I'm not a C++ expert. This is one of the reasons why most people just use assembly and C for OSDev.

The only information I could find at all was http://groups.google.com/group/alt.os.d ... 76f75afbac
origin of wrote: OT : why, italian isn't the international language :(
Because everyone knows english should be the international language ;)

Posted: Tue Jul 11, 2006 2:13 pm
by origin of
ok, thanks, thank you very much...BUT :lol: now i want to do this...

@rexlunae wrote:
You would know if you had created an IDT. It isn't something the compiler is likely to do for you. I think the first step is to create one. There may still be other problems with your code, but not having an IDT will cause problems like this one. You should always have an IDT before interrupts are enable, otherwise, the first interrupt will cause a tripple fault and the computer will reboot. If you define an IDT, and put in a handler which can report unexpected exceptions, it may give you much better information to work from.
i'll search in google, if i nedd some help...post another thread.....hehehe


8)

THANKS TO ALL
bye :wink: :wink: :wink:

Posted: Tue Jul 11, 2006 3:49 pm
by JAAman


i'll search in google, if i nedd some help...post another thread.....hehehe
the first place you should look for IDT information (which will greatly help solving problems like this), is in the intel manuals -- do you have them?

if not, check the link in my signature -- it links to the download, and from that page, you can get order information for ordering hard-copies (highly recommended)

everything you could ever want to know about the CPU is told in these books (particularly important is volume 3a -- chapter 5 talks about the IDT)

these books are completely free (including shipping) anywhere in the world, and are availible in other languages as well -- prob including italian

Posted: Tue Jul 11, 2006 6:36 pm
by jakelstr
I also recomend that you get the Intel Manals. They help a lot. I just got them yesterday. The AMD manuals may also help, even though they are essencially the same. :roll:

Posted: Wed Jul 12, 2006 2:15 am
by origin of
ok, doesn't exist in italian language...i'll download them, and print....only 640 pg the third manual..

Posted: Wed Jul 12, 2006 1:27 pm
by JAAman
dont print them -- order the hard-copies, they are free, and it will be easier (and nicer) than printing -- and cheaper too since they are completely free (and if you print, it will take lots of paper and ink -- not free) including shipping (and get all 5 books they are all useful, though 3a is most important)

did you call the ordering number and ask if they had it in italian? because i know they have it in several other languages (but i havent found downloads other than english)