interesting error

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.
Post Reply
Amet

interesting error

Post by Amet »

Oopss..I think Im doing something else wrong.

Code: Select all

int main(void)
{
   OutTextXY(10, 20, "This line is printed at X=10,Y=20");
}
works well. But when I try to repeat print function 150 times like:

Code: Select all

int main(void)
{
   OutTextXY(10, 20, "This line is printed at X=10,Y=20");
   OutTextXY(10, 20, "This line is printed at X=10,Y=20");
   OutTextXY(10, 20, "This line is printed at X=10,Y=20");
   ...
}
bochs gives the error below:

Code: Select all

00000546599e[CPU  ] load_seg_reg: LDT invalid
00000546599p[CPU  ] >>PANIC<< exception(): 3rd (13) exception with no resolution
It is not important which function I repeat. I mean whenever my main code gets bigger, bochs gives this error.

At first I have thougt that I have to read more sectors in my bootsector. When my code gets bigger, I change the sector number that I read to 10. But then bochs gave me this error:

Code: Select all

00000557167i[BIOS ] FATAL: set_diskette_current_cyl(): drive > 1
00000557466p[BIOS ] >>PANIC<< BIOS panic at rombios.c, line 1563
My kernel code is 8kb(I make it bigger by repeating nonsense functions). But I can not read no more then 7 sectors in my bootsector.

Is it because a bad script file? Or did I something wrong? Im attaching my whole code(with script file). Ill be glad if someone helps me, Im going to be meddd..

[attachment deleted by admin]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:interesting error

Post by Pype.Clicker »

er ... if you load only 7 sectors (i.e. less than 4096 bytes) and if your kernel is larger than 8Kb, you'll eventually encounter a moment where you'll enter a portion of your kernel that hasn't been loaded... and execution anything can do nothing good.

If i were you, i would make sure my loader correctly loaded the whole kernel before jumping and executing it.
bkilgore

Re:interesting error

Post by bkilgore »

One way to verify that your entire kernel is loaded is to store a magic value at the end of your data section and then verify after loading that the last 4 bytes or however much you choose match that magic value.

While there's no guarantee that the magic value won't randomly be at the end of what you thought you loaded even if it fails, it at least provides better verification than nothing.

Place the check at the very beginning of your kernel, and this way if your loader fails to work, your kernel will fail and let you know it.

This was how I first discovered that my loader stopped working when my kernel got too big (about 20k), so instead of fixing it i just switched to grub.
Amet

Re:interesting error

Post by Amet »

Pype.Clicker wrote: If i were you, i would make sure my loader correctly loaded the whole kernel before jumping and executing it.
How can I be sure? And as I said, when I try to increment the KERNELLENGTH parameter(it is 7), bochs gives me error... I even dont know why can not I load more then 7 sectors....
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:interesting error

Post by Pype.Clicker »

the BIOS usually do not accept to load more than one track at a time, but nothing could prevent you from doing more INT13 calls until the complete kernel is loaded.

as for the "magic value", i would rather suggest a checksum approach: store as the last 32bits word of your kernel a value such as the sum of all dwords for your kernel is zero. Then when loading, check the sum is zero, if not don't jump.
Amet

Re:interesting error

Post by Amet »

Oopss.. when I load my kernel to 09000h (it was 1000h before) my problem solved. Am I missing something??

And also where can I find syntax info of GCC. I was used to use tcc before. For instance where can I learn the meanings of such code:
__asm__ __volatile__ ("lidt %0 : : "m", idt);
what does this %;: m mean for instance.. where can I learn their meaning?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:interesting error

Post by Pype.Clicker »

try out "info gcc" > C extensions > extended asm.

the structure is
  • <asm>::=asm("<asm operations>"[:<output arguments>[:<input arguments>]])
  • <asm-operations>::=any AT&T assembler commands, separated by ";" and using %0..%9 as arguments substituer. '%' signs must be doubled if it's not in a '%i' argument.
  • <output arguments>::=list(",") <output argument>
  • <output argument>::= " = <class>" ( <target C variable> )
  • <input argument>::= " <class>" ( <input C variable> )
btw, the correct code is

Code: Select all

__asm__ __volatile__ ("lidt %0 : : "m"(idt));
which can be decoded as
' emit assembler code 'lidt <stuff>" where "<stuff>" is the first argument in the list (%0).
there's no output argument, but there's one input argument which is the memory location of IDT.
Tim

Re:interesting error

Post by Tim »

Remember that "m" doesn't take a pointer, but a variable. So Pype.Clicker's example is fine if [tt]idt[/tt] is a variable, but he should use [tt]*idt[/tt] if it is a pointer. I made this mistake myself and had a nasty bug sitting in my code for a long time because of it.
Amet

Re:interesting error

Post by Amet »

info gcc not worked on my djgpp. Ill be glad for any externel tutorials..

And also some known but forgotten c commands. Also Ill be glad if someone makes me remember their meanins.

volatile:
inline:
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:interesting error

Post by Pype.Clicker »

you need to install the documentation packages to get "info gcc" work ...
"volatile" : turns off optimization. In this case, it means your asm command *will* be issued even if GCC thinks it's not useful.

"inline": request the compiler to expand the function body in the caller function. only effective if optimizations are turned on.
Post Reply