00001 /*********************************************************** 00002 *PANALIX 0.06, (c) Adrian Panasiuk 2002-4 * 00003 *adek336[at]o2.pl, panalix.prv.pl * 00004 *under GPLv3 license * 00005 * * 00006 *panalix - small osdev project * 00007 ************************************************************ 00008 * align.cpp, version 1.01 * 00009 ************************************************************ 00010 * * 00011 *aligning addresses of memory up and down * 00012 * * 00013 *23'04'04- fork from the 0.05 branch (1.01) * 00014 * * 00015 ***********************************************************/ 00016 00017 #include "src/common/shared.hpp" 00018 #include "src/memory/align.hpp" 00019 00020 /*align up from addr, with alignment*/ 00021 uint32 align_up (uint32 addr, uint32 alignment) 00022 { 00023 //nakazuje --W- godz 17- 1.VIII.1944 00024 uint32 var = addr & (alignment - 1); //we mask the addr 00025 if (var) //is any of these bits enabled? 00026 return addr + alignment - var; //if yes, we have to align up 00027 else 00028 return addr; /*already aligned*/ 00029 } 00030 00031 /*align down an addr, with alignment*/ 00032 uint32 align_down (uint32 addr, uint32 alignment) 00033 { 00034 uint32 mask; 00035 mask = 0xFFFFFFFF - (alignment - 1); /*the bits to leave in the addr*/ 00036 /*return the addr without the appropriate bits*/ 00037 return addr & mask; 00038 } 00039 00040 /*********************************************************** 00041 * * 00042 *panalix 0.06 (c) Adrian Panasiuk 2002-4 * 00043 *adek336[at]o2.pl, panalix.prv.pl * 00044 * * 00045 ***********************************************************/