MultiMIPS 8051 Operating System Kernel
Personal Considerations
Design Philosophy
The Five Levels
8051 Hardware Resource Usage
Personal Considerations
The motivation for constructing this Kernel is threefold. First, I want to learn
the 8051 chip architecture, and I can imagine no better way than to construct
an OS kernel. Second, when it reaches a certain stage of completion it just
might be very useful.
Finally, I designed this OS kernel in the late '60s when I wrote an operating
system and other software for a Digital Equipment Corporation PDP-8 mini-
computer. The design was the basis at that time of the thesis for my Master
of Science degree in Computer Science at Western University. It will be
interesting to see now how the design principles have held up over
approximately 30 years. [Actually, the time difference is only 10 years; my
thesis work was completed by about 1970, and the design of the 8051
processor was completed by about 1980.]
One thing to note here is my belief and contention that over the course of
these past three decades, computers have not changed other than to become
merely smaller, faster, and cheaper. The essential elements are the same:
CPU, registers, memory for program and data storage, interrupt system,
external storage, and so on. And the principles of software design have not
changed; structured programming has evolved into OOP, but the principles
are the same. So, in theory, if this design was good in Y2K-30, it should still
be good in Y2K and beyond. I am most interested in hearing comments
about this and any other aspects of this project.
Design Philosophy
The design of this system is based on the concept of structure. There are two
components to a structure, these being a set of units, either abstract or
concrete, and the relationships among these units. The expression computer
software structure refers to the functional units [functions, subroutines,
coroutines, objects, etc] of the software, and the communication techniques
by which internal information flows among them. [Internal information
refers to program control variables and context dependent information, as
opposed to external information which is data being processed by the
program.] It is the internal information flows that bind the program units
together and impart to the system its structure.
In considering system structure, we must also consider the structure of the
individual software units. These units should be constructed according to the
tenets of structured programming and object oriented programming which
have become well known since the late 1960s. That is, each module should
be single entry single exit, entry at the physical beginning exit at the
physical end, restricted use of global variables, etc.
The kernel described here is structured as a hierarchy of software levels.
Each level of the hierarchy defines a new machine by effecting an
abstraction of the next lower level machine. A hierarchical structure results
because of the communication techniques within levels and between
adjacent levels. It is not too soon to note that it is a violation of design
principle that communication would skip a level. So the above compound
phrase within levels and between adjacent levels is precise
The Five Levels
Level-0 is the hardware machine. The purpose of the higher levels is to
abstract from this machine to one that more readily lends itself to building
the next higher level, and eventually to interfacing to user programs. The
master design criterion for the lower levels is efficient access to the
hardware. It will become the responsibility of the higher levels to provide
ready interfacing to utility and user programs.
Level-1 software is usually referred to as interrupt handlers or interrupt
service routines [ISRs]. This software recognizes interrupts and effects
transfers of information between elements of the level-0 machine, usually
between I/O devices and memory. This is a precise description of this level;
no other processes should be executed here. In particular, as a general
principle, software at this level should not make decisions, but rather should
only execute predetermined processes.
Level-2 software initializes variables in the level-1 machine to prepare the
latter to process information transfers in response to interrupts. Specifically,
these variables include buffer pointers, the item count and memory address
for information transfers, and the [optional] memory address of a process,
designated by a next higher level routine, to be executed as an extension of
the interrupt service routine. Level-2 should set up level-1 so that the latter
can operate, as much as possible, in a predetermined way when the interrupt
occurs.
Level-3 software is utility programs and user programs. The main utility
program at this level is the command interpreter. This program inputs text,
typically entered by a person from a keyboard, interprets the text as
commands, and executes the commands. It is useful, and usually trivial, to
design this module so that it is independent of the source of command
information, so that commands may come from other programs and devices
in addition to the keyboard.
Level-4. One view of level-4 is that, for machines with external mass
storage [hard drives, etc], it provides automatic access to level-3 programs
that are stored on the mass storage device. For a microcontroller these
programs may be stored in external memory devices. These programs can be
accessed by using the system command interpreter either from the keyboard
or from other running programs. This can provide a very powerful operating
system kernel.
8051 Hardware Resource Usage
These are the hardware resources of the 8051, and how they are used by the
MultiMIPS 8051 Operating System Kernel. Some of this information has
been gleaned from the M51 map file created by the linker.
Program Status Word
The Kernel uses the user definable flag PSW.1, and the available general
purpose flag PSW.5 [F0].
Program Memory
The Kernel occupies less than 0x300 bytes of program memory. Using the
MultiMIPS HEX file relocator program, the Kernel can be placed virtually
anywhere in the program memory space.
SFR Memory
The Kernel ISRs [interrupt service routines or interrupt handlers] preserve
the contents of any SFRs used, except for SFRs specific to devices that it is
using itself. The Level-2 routine used to output individual data bytes to the
serial port preserves the SFRs that it uses.
Register Banks 0-3
The Kernel ISRs preserve the contents of any registers that it uses.
Bit Addressable Area
The Kernel uses no bit addressable memory
Scratch Pad Area
The Kernel uses scratch pad memory beginning at address 0x0030:
serial port input pointers: 4 bytes
serial port output pointers: 5 bytes
level-3 command interpreter: 2 bytes
Indirect Address Area
The Kernel uses Indirect Address Area memory beginning immediately after
it's scratch pad memory:
serial port input buffer: 4 bytes [needs 3 bytes at 4800 baud]
serial port output buffer: 4 bytes [needs 3 bytes at 4800 baud]
command interpreter: 6 bytes [to store the largest possible command]
stack: serial port 0 ISR: 5 bytes; serial port 0 single byte output
routine: 1 byte; command interpreter: 4 bytes. These are needed
simultaneously.
It is trivial to relocate the stack by modifying the HEX file with a text editor
program such as Windows NotePad. Follow these steps:
1. Find the HEX data for program memory location 0x0000. It should be
similar to: 0240E6
2. 02 is the LJMP instruction; 40E6, in this case, is the address of the
first instruction of the Kernel to be executed on reset or restart.
3. Find the HEX data for memory location 0x40E6 [or whatever it may
be]. It should be similar to: 758148
4. 75 is a MOV instruction; 81 is the stack pointer SFR; 48 is the
IDATA memory address for the stack.
5. Change the [48] to whatever you wish between the current value and
the end of the IDATA memory area [0xFF].
External Data Memory
The Kernel uses no external data memory.
Parallel I/O Ports
The Kernel uses no parallel I/O ports [P0, P1, P2, P3].
Timer/Counters
Serial Interface
The Kernel uses serial port 0 in mode 1 with timer 1 in mode 2. The default
baud rate is 4800 governed by a reload value of , 0xea. [The test bed
processor is 20 MHz].
Interrupts
…..
Link to More Detailed Information…