Page 1 of 1
OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 1:25 pm
by neon
Hey everyone,
Im looking for some feedback on this one... At first I was going to integrate virtual memory management and physical memory management all in one tutorial. After concluding that this is bad, I decided to split them in two.
Here it is...
OS Development Series Tutorial 17: Physical Memory Management
Im looking for some feedback on both the tutorial itself as well as demo code which builds from the last tutorials. Specifically, I am looking for suggestions on the physical memory manager itself. ie; is there any problems with its design? What would you like to add to it? If there are any errors please let me know so it can be fixed.
I also would like to cover stack based memory allocation as well. I may cover that a little later though.
Demo should work with all optimization levels in MSVC++, Bochs, and VirtualPC. I havnt checked it in other emulators. If you try it in another emulator, please let me know if it works or not.
Thanks for any feedback
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 1:44 pm
by cr2
I just TRIED to compile your code in MSVC++ 2008. I get an error stating that there is an unresolved external symbol, __aulshr, in i86_install_ir
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 1:49 pm
by neon
cr2 wrote:I just TRIED to compile your code in MSVC++ 2008. I get an error stating that there is an unresolved external symbol, __aulshr, in i86_install_ir
Can you please post the exact error for me and optimization level? (__aulshr or __aurllshr? __aulshr doesnt seem to exist.. ) I cant replicate that error so I need something to go by. Thanks for trying it for me
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 1:52 pm
by cr2
3|fatal error LNK1120: 1 unresolved externals||KRNL32.EXE
1|error LNK2019: unresolved external symbol __aulshr referenced in function "int __cdecl i86_install_ir(unsigned int,unsigned short,void (__cdecl*)(void))" (?i86_install_ir@@YAHIGGP6AXXZ@Z)||Hal.lib
2|error LNK2001: unresolved external symbol __aulshr||Hal.lib
Optimization: Custom
Inline Function Expansion: Default
Enable Istrinsic Functions: No
Favor Size or Speed: Neither
Omit Frame Pointers: Yes(/Oy)
Enable Fiber-safe Optimizations: No
Whole Program Optimization: No
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 2:13 pm
by neon
Im going to see if I can replicate the problem on VC++ 2008 and develop a solution for it. Thanks again for trying it
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 4:04 pm
by neon
After writing my own version of _aullshr() I was able to get it working with my copy of VC++ 2008 on all optimization levels. I suspect _aulshr() may work as well.
Copy this in
cstd.cpp right after
_ftol2_sse() and please see if it helps. Try both the
_aullshr and
_aulshr names.
Code: Select all
uint64_t _declspec (naked) _aullshr () {
_asm {
//! only handle 64bit shifts or more
cmp cl,64
jae invalid
//! handle shifts between 0 and 31 bits
cmp cl, 32
jae more32
shrd eax,edx,cl
shr edx,cl
ret
//! handle shifts of 32-63 bits
more32:
mov eax,edx
xor edx,edx
and cl,31
shr eax,cl
ret
//! invalid number (its less then 32bits), return 0
invalid:
xor eax,eax
xor edx,edx
ret
}
}
I hope this fixes it...
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 5:49 pm
by cr2
well... it compiles...
...but when I run it, it...
A. panics
B. triple faults("running in bogus memory")
<update>
when I take out the code that has to do with the vs_printf call, it works(ok...it still panics, but no triple fault). Well...it was a GPF.
</update>
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 6:37 pm
by neon
Ah, you know what? I just tried it with "custom" optimization level and it GPFs. Im going to have to fix that :p
Does it run with any other optimization level? (*edit: It seems like it works with every one but Optimization: Disabled and custom levels. Im going to have to look into those...)
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 6:40 pm
by cr2
ok...
kernel had full optimization, but hal and lib had custom
I changed hal and lib's optimization settings to "full optimization", and it worked(completely!)!!
Thanks neon.
Re: OSDev Series Tutorial 17
Posted: Sun Sep 28, 2008 7:04 pm
by neon
I uploaded a new demo with the fix just in case anyone wants to test it out
Re: OSDev Series Tutorial 17
Posted: Fri Mar 20, 2009 3:45 pm
by vladislas
Hi Neon. I'm really liking this tutorial, and basically I'm just going through it and modifying a few things that I want to do differently. Thanks for explaining a lot of these things in such detail. I started an OS project years ago, but had to put it on hold for a while and I'm just getting back into it. The problem is that a lot of stuff that used to be around seems to have disappeared now. Was glad to see this site was still up and running though.