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

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
milyges

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

Post 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.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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

Post 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.
milyges

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

Post 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??
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

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

Post by Candy »

As a sidenote, what "from 8AM to 10PM" do you mean?
milyges

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

Post by milyges »

Candy wrote: As a sidenote, what "from 8AM to 10PM" do you mean?
My server work at this time ;)
Kemp

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

Post by Kemp »

Candy was asking where in the world that was, 8am til 10pm for you probably isn't 8am til 10pm for him.
milyges

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

Post 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)
DruG5t0r3

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

Post 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.
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:Works on Bochs, but on real PC page faults :/

Post 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.
milyges

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

Post by milyges »

Hmmm.
GRUB clean kernel bss section??? If not maybe I found error, but now I can not check it :-\
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

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

Post 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...
Every good solution is obvious once you've found it.
milyges

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

Post 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 :/
milyges

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

Post 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.
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:Works on Bochs, but on real PC page faults :/

Post 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 ;) ...
milyges

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

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