OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 4:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Writing memory management system smartly
PostPosted: Fri Jan 19, 2024 3:24 am 
Offline

Joined: Fri Jan 19, 2024 3:07 am
Posts: 1
I am writing memory management and I'm stuck, I want to use memory management before kernel start, that mean my memry management will be able to create two zones: Kernel memory zones, where I placed my kernel, then load my kernel (stored in binary) into memory, then execute kernel.

However, when the memory manager is booted in the bootloader Stage 2, the bootloader will only use it to create memory area for the nuclear space, and the nucleus will use the memory management process and take responsibility For all later memory operations, including memory protection and memory area for user space.

Kernel will use memory management to mark kernel memory permissions that only kernel will have full permissions (R/W/X) to kernel memory. After that, all memory access from the outside Kernel will be rejected, even bootloader.

Then kernel will use driver framework to load drivers and enable devices, then kernel will use memory management to create another memory zone, called User-space memory zones, and they are seperated with kernel memory zone. After that, kernel startup process end up and User-space will be entered.

All processes in the user mode, when calling the functions related to memory, these functions simply call the system calling commands deployed by Kernel. Kernel will then be responsible for manipulating memory, and providing that memory for that process, and because the nucleus will manipulate all operations related to memory on the user space memory area. From the time the user space is executed, there will be no security problem.

That is my idea.

But if so, we will have a chicken and egg problem. I will have to create two memory managers but it uses the same title files. This creates a lot of problems because I will have to maintain two memory managers at the same time.

However, if developing a common memory manager for the whole system, where should I put it? Moreover, after bootloader transferred the rights of nuclear management, how will the nucleus use the memory manager? It should be searched for memory management, or it is imperative to deploy a memory manager for Kernel and still use the same old title files, just because Kernel does not know how to reuse the memory manager.

The two memory management processes for bootloader and kernel, but have the same features and functions because they use the same title files that seem not to be wise decisions.

What is the best solution for this? Should I write a common and only memory manager for the whole system to be smartest?

_________________
Write code, security research and discover old software have been forgotten


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Tue Feb 13, 2024 2:56 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
thanhdz167 wrote:
I want to use memory management before kernel start,

Why? What do you want to do with it?

In a typical OS, the bootloader needs to find some available memory to load the kernel, then it needs to set up page tables to map the kernel. After that, the bootloader is done. It doesn't need the kernel's memory manager.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Wed Feb 14, 2024 6:16 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3195
Octocontrabass wrote:
thanhdz167 wrote:
I want to use memory management before kernel start,

Why? What do you want to do with it?

In a typical OS, the bootloader needs to find some available memory to load the kernel, then it needs to set up page tables to map the kernel. After that, the bootloader is done. It doesn't need the kernel's memory manager.


Agreed, but the bootloader doesn't need to setup paging either. My bootloaders (both BIOS and EFI) will enter the kernel in protected mode without paging. It's then up to the kernel to setup paging as it wishes.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sat Mar 02, 2024 11:22 am 
Offline
Member
Member

Joined: Sun Apr 21, 2019 7:39 am
Posts: 76
rdos wrote:
(...) the bootloader doesn't need to setup paging either.


Unless you're developing for 64-bit x86. That requires a page table set up before you can enter long mode. You can setup an identity map, but at that point why not just set up a higher half map in the bootloader?

_________________
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sat Mar 02, 2024 11:39 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
But you don’t have to enter 64-bit mode in the bootloader. It’s semantics really, but not all (what are commonly known as) bootloaders put the loaded program into 64-bit mode. It can be part of the kernel’s initialization routine.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sat Mar 02, 2024 11:27 pm 
Offline
Member
Member

Joined: Sun Apr 21, 2019 7:39 am
Posts: 76
iansjack wrote:
But you don’t have to enter 64-bit mode in the bootloader. It’s semantics really, but not all (what are commonly known as) bootloaders put the loaded program into 64-bit mode. It can be part of the kernel’s initialization routine.

That's a crappy way to do it, but yes, some kernels do have to bring themselves up to 64-bit mode because the bootloader put them in 32-bit protected mode. It requires some unsightly hacks to combine 32- and 64- bit code into one, though.

_________________
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sun Mar 03, 2024 12:32 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
You don’t have to combine 32- and 64-bit modes into one.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sun Mar 03, 2024 4:26 am 
Offline
Member
Member

Joined: Sun Apr 21, 2019 7:39 am
Posts: 76
iansjack wrote:
You don’t have to combine 32- and 64-bit modes into one.

No? Well then how do you get into the kernel proper if the bootloader placed you in protected mode, aside from inserting some 32-bit code?

_________________
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.


Top
 Profile  
 
 Post subject: Re: Writing memory management system smartly
PostPosted: Sun Mar 03, 2024 5:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4597
Location: Chichester, UK
You load the 32-bit code as a module (for example, using GRUB as your boot loader).

If your boot loader makes the move to 64-bit mode then it has to combine 16-, 32-, and 64-bit code. It's better to keep these as separate modules.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group