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

Custom Operating System Series

Part Eight : Reading the Real-Time Clock

This article is part eight 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 seven 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, reporting keystroke data to an operator information area,echoing user input to the console screen and handling several simple commands.

In this article, we will extend our console task to support two new commands, "date" and "time". Additional service request calls will be added to read the real-time clock chip and return formatted date and time strings.

1. Additional Equates

First we add some additional equates to define ports and registers on the real-time clock chip.

2. Updated Structures

Next we add two new buffers to our console data, ConsoleOutBuffer and ConsoleDateTime. We also define a new structure, DATETIME, to hold values read from the real-time clock chip.

3. New Service Requests

We add new service request table entries for PutDateString, PutTimeString and ReadReaTimeClock services. We also define macros to call these services. Note that more than one macro can be defined for the same service. This allows the service to be called with different register-loading code.

4. New Kernel Functions

The new functions added are PutDateString, PutTimeString and ReadRealTimeClock. Also added are helper functions that return fields from the DATETIME structure.

5. Console Task Updates

We add two new command-handling routines, ConDate and ConTime. These routines are called when the "date" and "time" commands are entered, respectively, at the console.

Lastly, we update the jump and command tables to include our two new commands.


In this article we have added logic to read the date and time from the real-time clock and display this information at the console. In our next article, we will introduce basic multi-tasking, starting a second task to run concurrently with our console task.

Program Notes:

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

Program Listing

Revised 10 October 2014