
103
Chapter 2 Applications Programming
When application benchmark programs use HIF services, care should be taken.
If a program requests a service such as
time
(service 49) it will suffer the delays of
communicating the service request to a remote host if the OS–boot operating system
is used. This can greatly effect the performance of a program, as execution will be
delayed until the remote host responds to the service request. It is better to use ser-
vices such as
cycles
(service 274) or
clock
(service 273) which are executed by the
29K processor and do not suffer the delays of remote host communication.
The assembly level glue routines for HIF services 255 and lower are rarely re-
quested directly by an application program. They are more frequently called upon by
library routines. For example, use of the library
printf()
routine is the typical way of
generating a
write
HIF service request. The mapping between library routines and
HIF services may not be always direct. The
printf()
routine, when used with a device
operating in COOKED mode, may only request
write
services when flushing buffers
supporting device communication. Appendix A contains a detailed description of
each HIF service in terms of input and output parameters, as well as error codes.
2.2.4 Switching to Supervisor Mode
Operating systems which conform to HIF normally run application code in User
mode. However, many real–time applications require access to resources which are
restricted to Supervisor mode. If the HIF
settrap
service is supported, it is easy to
install a trap handler which causes application code to commence execution in Su-
pervisor mode. The example code sequence below uses the
settrap()
HIF library rou-
tine to install a trap handler for trap number 70. The trap is then asserted using assem-
bly language glue routine
assert_70()
.
extern int super_mode();/* Here in User mode */
_settrap(70,super_mode);/* install trap handler */
assert_70();
. . .
/* routine to assert trap */
/* Here in Supervisor mode */
The trap handler is shown below. Its operation is very simple; it sets the Supervi-
sor mode bit in the old processors status registers (OPS) before issuing a trap return
instruction (IRET). Other application status information is not affected. For exam-
ple, if the application was running with address translation turned on, then it will con-
tinue to run with address translation on, but now in Supervisor mode.
In fact the example relies on application code running with physical addressing;
or if the Memory Management Unit is used to perform address translation, then virtu-
al addresses are mapped directly to physical addresses. This is because the Freeze
mode handler,
super_mode()
, runs in Supervisor mode with address translation
turned off. But the
settrap
system call, which installs the
super_mode()
handler ad-
dress, runs in User mode and thus operates with User mode address values.