That is a nonsense answer. (it is about a kernel or did you miss that?)
A good way would be to look at how Ultibo has solved this.
That is great code for such things. Ultibo focusses on -even modular -kernel writing in FreePascal and is available through OPM. Comes with all sources.
Frankly, you may even give up on your own efforts, because Ultibo is as far kernel writing so easy, with the provision that the code may be smaller later. You are obviously a kernel writer so ignore any comments about tags. Few know what they are doing....
On this forum there are less than 50 people interested AND capable of kernel programming. But they are there and most are scientists in the field.