OSDev Series Tutorial 17

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

OSDev Series Tutorial 17

Post 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 :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: OSDev Series Tutorial 17

Post 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
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDev Series Tutorial 17

Post 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 :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: OSDev Series Tutorial 17

Post 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
Last edited by cr2 on Sun Sep 28, 2008 2:06 pm, edited 1 time in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDev Series Tutorial 17

Post 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 :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDev Series Tutorial 17

Post 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... ;)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: OSDev Series Tutorial 17

Post by cr2 »

well... it compiles... :D

...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>
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDev Series Tutorial 17

Post 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...)
Last edited by neon on Sun Sep 28, 2008 6:41 pm, edited 1 time in total.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: OSDev Series Tutorial 17

Post 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!)!! =D> =D>

Thanks neon. :D
Last edited by cr2 on Sun Sep 28, 2008 7:06 pm, edited 1 time in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: OSDev Series Tutorial 17

Post by neon »

I uploaded a new demo with the fix just in case anyone wants to test it out :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
vladislas
Posts: 2
Joined: Thu Mar 19, 2009 3:13 pm

Re: OSDev Series Tutorial 17

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