Memory Allocation on a Real Mode Operating System
Posted: Sun Jan 19, 2020 9:51 am
I am building a real mode OS as a hobby project. As my first OS project I wanted to begin at the beginning and so the choice to build a Real Mode Operating System. Having said that, I am not following any OS in particular, but have ideas from many sources. I think more Real Mode as a scratch pad sort of mode where given the hardware, software can be anything with very little intervention by the processor.
Coming to the problem, I am building a like system call which the user programs can call when they want more memory. I understand a brk() like system call would be more simple to implement but then there would anyways be a anyways.
A user program in this OS would be a simple COM file, with no header and with statically allocated data and code together. However the dynamically allocated memory will reside after the Code and Stack Segments. The A, AE, B, BE, C, CE are addresses in the memory model. Note that such an memory arrangement is needed to conform with the SMALL memory model (because most compilers assume such a model).
Now that there is some context, I plan to implement the dynamic memory allocation via a table of the sort below. The 'Offset' column is the start of allotted memory after the 'C' address. When more memory is requested OS will allocate memory by either finding a large enough block from the table which is currently free or allocate more memory after the end of the last 'Offset + Size' in the table.
Consequently, a free() system call will free one or more a blocks when done.
My question is:
Coming to the problem, I am building a
Code: Select all
alloc()
Code: Select all
malloc()
A user program in this OS would be a simple COM file, with no header and with statically allocated data and code together. However the dynamically allocated memory will reside after the Code and Stack Segments. The A, AE, B, BE, C, CE are addresses in the memory model. Note that such an memory arrangement is needed to conform with the SMALL memory model (because most compilers assume such a model).
Now that there is some context, I plan to implement the dynamic memory allocation via a table of the sort below. The 'Offset' column is the start of allotted memory after the 'C' address. When more memory is requested OS will allocate memory by either finding a large enough block from the table which is currently free or allocate more memory after the end of the last 'Offset + Size' in the table.
Consequently, a free() system call will free one or more a blocks when done.
My question is:
- 1. Is such a model of dynamic memory allocation is feasible? And why such a model is not used?
2. Should such system calls 'alloc' and 'free' are better to of in a library rather than as a system call?