Page 1 of 1

Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 6:04 am
by milyges
Hello.
I'm writting OS and I write microkernel for it and some modules (init, keyboard driver and simple shell). OS works well on bochs but when i boot real computer from cd with it, i get page fault in process init.sys. I want check it and i dump page dir and page tabless, and all values are ok :/. I think that I make mistake in paging code, and once works, but if i try again don't work :/ I trying dump more information, and on 2PC's, Bochs, Quemu, VMWare are the same. OS source is on cvs, you can browse it via WWW http://cvs.milyges.homelinux.net (module idylla_os), paging code is in src/kernel/hal/ia32/paging.c. Boot CD image os at http://milyges.homelinux.net/~milyges/idylla.iso.gz. CVS server is my home server and it works from 8AM to 10PM.
Sorry for my english :P
Greetings for all.

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 8:30 am
by Candy
Common differences between bochs and a real pc:

* You need retries for your code. Your floppy is not ideal and does not work every time, nor does any other bit of hardware.

* Your memory is filled with something not unlike /dev/urandom. You MUST clean it before using it or you'll get very weird things. I forgot once, just after adding threadswitching & page fault handling, gave me a 160M dump of all sorts of thread switches to unavailable threads that were uninitialized entries until one accidentally contained just zeroes, which made it go to the idle thread.

* Your hardware is not bochs. Your drivers can make errors, some bits don't work like they do in bochs and some do, where bochs fails.

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 9:39 am
by milyges
Hello.
I add some debuging code to procedure umap_mem and it's work! Next I remove it code and again page fault ??? ??? ???
Strange......

//EDIT: I test some it under PC and I think that is something wrong with kernel stack :-\ But I don't know what :-\
Anybody can help me??

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 10:07 am
by Candy
As a sidenote, what "from 8AM to 10PM" do you mean?

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 11:23 am
by milyges
Candy wrote: As a sidenote, what "from 8AM to 10PM" do you mean?
My server work at this time ;)

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 11:41 am
by Kemp
Candy was asking where in the world that was, 8am til 10pm for you probably isn't 8am til 10pm for him.

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 11:53 am
by milyges
Kemp wrote: Candy was asking where in the world that was, 8am til 10pm for you probably isn't 8am til 10pm for him.
Sorry, my english is not good.
I'm live in Poland (now on my timer is 8PM)

Re:Works on Bochs, but on real PC page faults :/

Posted: Tue Aug 15, 2006 8:11 pm
by DruG5t0r3
I believe bochs fills all memory with 0's on boot while a regular PC is filled with static junk. This can make a huge difference with paging.

Re:Works on Bochs, but on real PC page faults :/

Posted: Wed Aug 16, 2006 7:41 am
by Pype.Clicker
in other words, be paranoid, and everytime you assume a given area of memory contains zeroes, just do a "memset(...,0)" instead of just assuming.

Re:Works on Bochs, but on real PC page faults :/

Posted: Wed Aug 16, 2006 8:10 am
by milyges
Hmmm.
GRUB clean kernel bss section??? If not maybe I found error, but now I can not check it :-\

Re:Works on Bochs, but on real PC page faults :/

Posted: Wed Aug 16, 2006 8:13 am
by Solar
From the FAQ (BareBones):
Will GRUB wipe the BSS section before loading the kernel?

Yes. For ELF kernels, the .bss section is automatically identified and cleared (despite the Multiboot specification being a bit vague about it). For other formats, if you ask it politely to do so, that is if you use the 'address override' information from the multiboot header (flag #16) and give a non-zero value to the bss_end_addr field. Note that using "address override" with an ELF kernel will disable the default behaviour and do what is described by the "address override" header instead.
Note that other Multiboot bootloaders might not support this, so do the memset() anyway...

Re:Works on Bochs, but on real PC page faults :/

Posted: Wed Aug 16, 2006 12:43 pm
by milyges
OK. I add memset in kernel initialization code (clear BSS), when create heap (clear all heap memory), and when I create new page dir and new page table. Now First multiboot module (init.sys) is loading well. But......
Module init.sys starting and loading other modules and now I get Page fault when sheduler give control to second module, code is not mapped :/ Why it working for first, but not working for second module??? I do not have any idea :/

Re:Works on Bochs, but on real PC page faults :/

Posted: Thu Aug 17, 2006 4:03 am
by milyges
OK it is working. ;D
Thanks for help. I add cleaning kernel .bss section, new page tabs and page dirs, and reloading page dir after any change of page dir/table.

Re:Works on Bochs, but on real PC page faults :/

Posted: Thu Aug 17, 2006 5:26 am
by Pype.Clicker
there's one very important thing to keep in mind with GRUB's "modules": they are loaded, period. That is, they are loaded as-is, without having a single byte in memory that is different from its on-disk version.

That strongly differs from e.g. linux modules that are processed and have their symbols resolved against the kernel symtable, have their BSS allocated and initialized (i cannot even guarantee that GRUB will see that your module needs 4MB extra space for its .bss section, for instance, and in a paged environment you barely care ;) ...

Re:Works on Bochs, but on real PC page faults :/

Posted: Thu Aug 17, 2006 7:37 am
by milyges
Sorry, I not sure what you want talk to me, I hope that I understand you ::)

My modules have elf format, and I copy all sections of them to my memory, I manualy allocate space for .bss ;D Grub only loading file for me. Kernel do rest.