MSVC - KernelStart and KernelEnd Location

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
LipkeGu
Posts: 2
Joined: Sun Aug 22, 2021 2:59 pm

MSVC - KernelStart and KernelEnd Location

Post by LipkeGu »

Hi,

Im Writting an Operating System and got to the Point where i have to setup my Memory (Paging etc.).
Memory and Paging are setted up so far but i have the Problem to tell my MemoryManager where the Kernel Starts and Ends. In GCC i can simply say

Code: Select all

_KernelStart = .; <-----
	.text : ALIGN(0x1000)
	.data : ALIGN(0x1000)
	.rodata : ALIGN(0x1000)
	.bss : ALIGN(0x1000)
_KernelEnd = .; <-----
and using the variables in cpp but how can i do that in msvc?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: MSVC - KernelStart and KernelEnd Location

Post by neon »

Hi,

The kernel already has all the information needed; its header information and associated data structures are in memory at the image base address. It can obtain the locations and sizes of all the sections there.

To provide a little more context, this is a small snippet from our system:

Code: Select all

PUBLIC size_t PeGetImageSize(IN char* imageBase) {

	IMAGE_DOS_HEADER*     p;
	IMAGE_NT_HEADERS*     ntHeaders;

	p = (IMAGE_DOS_HEADER*)imageBase;
	ntHeaders = (IMAGE_NT_HEADERS*) (p->lfanew + imageBase);

	return (size_t) ntHeaders->optionalHeader.sizeOfImage;
}
...
PeGetImageSize (KERNEL_PHYSICAL)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply