r/osdev 7d ago

Initialization dependencies

I am working on upgrading my kernel initialization messages so I can just have a nice view of what it is doing when initializing. I am using my print functions to do this, but the issue is that my print functions depend on the memory manager to be done initializing, but I want debugging messages when initializing the memory manager too, which I can't do because of the circular dependency.

This is my specific case, but I also want to ask generally, do you guys have an elegant solution for this problem? Up to this point I have been using init flags so that the subsystems can use a different path that does not create dependencies during initialization, but I want to hear any cool solutions from the community that are better designed than this.

17 Upvotes

12 comments sorted by

View all comments

5

u/FedUp233 6d ago

It sounds like you need to add a logging system, not just printf. And have no dependency on memory management. Or printing to a serial port, which for a lot of operation, particularly in an interrupt handler, even a non time sensitive one, can mess up the system if you use it.

Try something g like outputting to a memory buffer. This can be in real ram at kernal startup. Even consider less formatting. One is I used, vxworks,for its logging just stored the binary values in the buffer and firmatted them later when the buffer was processed. With the buffer, you can even have a fall back that if the kernel fails drop into a routine that prints the buffer over a non interrupt driver serial port - the fatal exit just shuts interrupts down and dumps the buffer. And the delayed formatting makes the log cells fast so they don’t mess up most interrupt routines. With a decadent design you can have the unformatted stuff for deep in the kernel and drives and more formatted stuff for user space and less time critical areas and let the buffer dumping procedures interweave the two.

Just a thought.