New segmentation technique in device-drivers
Posted: Sun May 13, 2012 2:42 am
I'm right now moving a device-driver from assembler to C. This is the first time I move something I've written myself, and basically rewriting it in the process. The device-driver is the ini-file manager that apparently contains some bugs that I'm unable to locate.
The new design is starting to come up, and the structures are quite interesting as they are similar to how directories and files can be maintained in the filesystem driver.
Just doing a straight port gives a design like this:
1. Each ini-file is allocated it's own GDT selector, which results in appropriate limit checking and protection for the ini-file itself
2. Text from the file, sections and variable contents would need to be allocated from the small kernel memory pool, without selectors (they use flat addresses), basically breaking the whole idea of protection and isolation. The reason these cannot be allocated as selectors is that GDT selectors are a limited resource.
A slightly better approach is to place the text in the file itself at the end of the selector. The text would then be modified by inserting nulls at appropriate places, and using section names, variables and contents directly from this area. Then the section and variable structures would reference context in this area, and thus these pointers would also be protected. However, this still leaves the section and variable structures unprotected.
However, it is possible to place these are the end of the selector (after the text), and grow the selector as new sections and variables structures are added. A first implementation would probably set number of sections and variables to 0, and grow the selector when parsing the ini-file, as then the grow interface can be debugged and checked. After that, just searching for '[' and '=' would give a rough indicator of number of sections and variables, and this could be used to create a selector with the correct number of sections and variables before parsing, and so grow only needs to be done when adding sections or variables (uncommon).
This would create a fully protected design. An additional advantage might be that the "based" keyboard in OpenWatcom might be used, basically reducing the overhead of segment register loads to a single load upon entry.
The new design is starting to come up, and the structures are quite interesting as they are similar to how directories and files can be maintained in the filesystem driver.
Just doing a straight port gives a design like this:
1. Each ini-file is allocated it's own GDT selector, which results in appropriate limit checking and protection for the ini-file itself
2. Text from the file, sections and variable contents would need to be allocated from the small kernel memory pool, without selectors (they use flat addresses), basically breaking the whole idea of protection and isolation. The reason these cannot be allocated as selectors is that GDT selectors are a limited resource.
A slightly better approach is to place the text in the file itself at the end of the selector. The text would then be modified by inserting nulls at appropriate places, and using section names, variables and contents directly from this area. Then the section and variable structures would reference context in this area, and thus these pointers would also be protected. However, this still leaves the section and variable structures unprotected.
However, it is possible to place these are the end of the selector (after the text), and grow the selector as new sections and variables structures are added. A first implementation would probably set number of sections and variables to 0, and grow the selector when parsing the ini-file, as then the grow interface can be debugged and checked. After that, just searching for '[' and '=' would give a rough indicator of number of sections and variables, and this could be used to create a selector with the correct number of sections and variables before parsing, and so grow only needs to be done when adding sections or variables (uncommon).
This would create a fully protected design. An additional advantage might be that the "based" keyboard in OpenWatcom might be used, basically reducing the overhead of segment register loads to a single load upon entry.