d a v i d j w a l l i n g . c o m

Custom Operating System Series

Part Six : Adding a Message Queue

This article is part six in a series introducing system software concepts for Intel® x86 or compatible processors in protected mode. In this series we are developing a simple protected mode operating system in assembly language. We are using the Netwide Assembler (NASM) to assemble our code and VMware® Player as our test platform.

In our first five articles, we configured VMware Player to launch a virtual machine that loaded a boot sector from a floppy disk image file, called our boot sector code which searched the disk image file for an operating system program, loaded that program into memory and called it, which configured a 32-bit operating system kernel, entered protected mode and transfered control to a task, capturing keyboard input and reporting keystroke data to an operator information area.

In this article, we will extend our keyboard interrupt to place "message" events in a queue for tasks to interrogate. We will also update the main logic loop of our console task to poll for message queue events, recognize keyboard events and display ASCII characters from keyboard messages on the console at the current cursor location.




1. Additional Equates

This article adds new equates for additional ASCII character values, an LDT selector for a message queue, additional console control values and three message identifiers.










2. Structures

We add a buffer in our operating system storage for a command buffer. Also, we define a structure for a message queue.






3. Keyboard Interrupt Handler

Next, we add code in our keyboard interrupt handler to append keyboard event information to the message queue. The new code is from label irq1.110 through irq1.130.










4. New Service Request Function - GetConsoleString

We add a new service request table entry, function and macro to get a string of keyboard characters.






5. New Kernel Functions

This article adds the kernel functions PutMessage, GetConsoleString, GetConsoleChar, Yield, GetMessage, PreviousConsoleColumn.












6. Console Task Updates

Finally, we update the logic loop in our console task routine, "ConCode". Now, our logic loop will call the conGetString macro after the prompt is displayed. Since we are not yet parsing console input, we will respond with an "unknown command" message and repeat.






With these additions, keyboard entry is now echoed on the console screen. Also note, that when input reaches the bottom of the screen, we scroll displayed output up one line.






Conclusion

In this article we have added a simple message queue to relay keyboard events from the interrupt handler to a task. Our console task polls for messages and handles keyboard character events by echoing the ASCII characters to the console screen. In our next article, we will add a simple command parser and support for commands to clear the screen, display a program version and restart the computer.




Program Notes

Here is a link to the entire listing of the code and data from this lab.

Program Listing

Revised 10 October 2014