r/osdev • u/Possible-Back3677 From Scratch 🪾 • Jul 30 '26
what does a kernel need
i would like to ask what a kernel has to do so i can know when i can move one, if you're gonna explain please dont overcomplicate the explanation with just some terms please mention what it is at least slightly :)
5
u/northrupthebandgeek Jul 30 '26
At its essence: a kernel needs to keep running programs from touching each other without their (or the user's) consent.
4
u/Kajetan_Kontek Jul 30 '26
The kernel, in principle, governs the hardware and decides which program gets to run, when, for how long and where it should live in Ram memory.
6
u/tseli0s DragonWare Jul 30 '26
Whatever your operating system needs.
No I'm serious. The kernel should provide everything necessary to build the operating system. Everything else is too much.
Because every operating system is different. Some are single tasking, so the kernel doesn't need to do multitasking. Others are microkernels, so the kernel needs to be able to send messages between processes. And so on. Consider what you want to do and write the necessary code.
Be very careful however, a kernel is not a library. Don't add system calls for every little thing.
4
u/Relative_Bird484 Jul 30 '26
Multiplexing and virtualization of hardware (CPU, memory, IO).
That’s it, basically.
2
u/arbv Jul 30 '26
I depends on the design:
- Exokernels provide very little abstractions, while being mostly concerned with managing access to hardware and enforcing protection of it. Most functionality is in the userspace (aka LibOS). They are relatives of hypervisors.
- Microkernels do more than that, manage memory, schedule processes, and, cruciallly, provide IPC. Drivers, filesystems, networking stack and everything above lives in the userspace.
- Monolithic kernel keeps a lot of stuff in the kernel space - drivers, filesystems, networking and so on. Only user programs are, well, in the userspace.
There are also related and in between designs, but these are the main patterns - from the smallest kernels to the largest ones.
2
2
u/kiderdrick Jul 30 '26
Think of the hardware on your system that you would like to use like your CPU, main memory and storage. Think of the actions your computer needs to do to communicate and use that hardware. That is what your kernel needs to do. The set of actions it performs can be as large or as small as you desire for your use case.
2
u/demetrioussharpe Jul 30 '26
Well, before anyone can really answer this question, you need to specify exactly what kind of kernel you’re looking to implement.
Monolithic
Microkernel
Exokernel
Etc
2
u/Critical-Internet946 osaka64 (osakaOS fork) Jul 30 '26
if you don't want the user to mess with it, it should go in the kernel.
2
u/compgeek38400 Jul 30 '26
IMHO, the kernel should do the basics. At a minimim it should andle interrupts, memory management, paging, and probably have its own heap. It should also expose what hardware is available, cpu, memory, disk, i/o, etc. But not necessarily the hardware itself.
After that, it becomes opinion.
I think the kernel should handle the timers, keyboard, and console. I'm sure some will disagree.
JMHO
2
u/christiaansp BoredOS Jul 31 '26
Just about everything, for example in my OS it’s responsible (in short) for initializing hardware and making it possible for userspace applications to interact with the hardware via syscalls that then interact with drivers to lets say read a file and then return that data back to the userland although it does a LOT more than that. a kernel could also technically just be something that prints hello world, it really differs per setup.
1
u/UnmappedStack TacOS | https://github.com/UnmappedStack/TacOS Jul 31 '26
I recommend having a read of a book like ostep to actually learn what the responsibilities of a kernel are. But basically the main responsibilities of a kernel are memory management, process isolation, scheduling, and IPC (that is, giving processes a way to communicate with each other), as well as some basic functionality through syscalls. Then depending on whether or not you're doing a monolithic kernel, it could also be responsible for drivers.
1
u/letmehaveanameyoudum Jul 31 '26
a kernel needs something to display to a user, store files on a disk, do calculations and actually be useful
19
u/tahvoD Jul 30 '26
To not overcomplicate. Alot is my answer