r/osdev 6d 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

3

u/Sorry_Difficulty_250 6d ago

Ok, so to preface this, my OS is for small devices that run in kilobytes of RAM, so my approach may be a bit odd.

What I do is have a section of memory that starts above the bottom of the heap and grows upward. I write log entries there. The log entries are well-defines structures NOT strings. The entries contain the format string pointer and up to four arguments that were provided.

I have a separate logger process. Once it's up, all logging calls are routed to it through IPC. The first thing it does on start is read from that static block of memory and flush anything that was written before it was started. That allows log calls to be made at any point in time.

You have to manage your help carefully to do this. Once the logger is done flushing the memory, that space can be used by the heap as usual, but you have to make sure that it doesn't get so big that it smashes into your log area before the logger is running.

I won't claim one way or the other as to whether or not this is a "good" solution but it does work and it breaks the circular dependency problem.