Subversion Repositories shark

Rev

Rev 1676 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1676 tullio 1
\documentclass[a4paper,10pt]{report}
2
 
3
%\usepackage{html}
4
 
5
\title{The S.Ha.R.K. Quick Guide}
6
\author{Tullio Facchinetti\\
7
\textit{tullio.facchinetti at unipv.it}\\ \\
8
Version 1.11}
9
 
10
\begin{document}
11
\maketitle
12
 
13
\tableofcontents
14
 
15
% \begin{abstract}
16
% \end{abstract}
17
 
18
%------------------------------------------------------------
19
\chapter{Introduction}
20
\label{ch:introduction}
21
%------------------------------------------------------------
22
 
23
This document has been written for helping the beginner to start
24
using the S.Ha.R.K. (\textbf{S}oft \textbf{HA}rd \textbf{R}eal-time
25
\textbf{K}ernel) kernel. The S.Ha.R.K. kernel source code is
26
available at
27
 
28
\begin{center}
29
\underline{http://shark.sssup.it}
30
\end{center}
31
 
32
The S.Ha.R.K. Quick Guide is intended to be as an ongoing document,
33
since new topics will be added if needed.
34
 
35
%------------------------------------------------------------
36
\section{What S.Ha.R.K. is}
37
\label{sec:what-is}
38
%------------------------------------------------------------
39
 
40
S.Ha.R.K. is a set of libraries that are statically linked into a
41
multiboot image, that is the application. Then, the application is
42
run through a DOS memory extender (X.EXE) or directly launched at
43
boot time using the GRUB.
44
 
45
S.Ha.R.K. makes available to the application all the primitives to
46
create, activate and run real-time tasks using state of the art
47
scheduling algorithms (EDF, RM, etc.). It also allows to share data
48
among the tasks by chosing between several resource reservation
49
algorithms like Priority Ceiling, Priority Inheritance, SRP
50
\cite{But97}.
51
S.Ha.R.K. supports drivers for a huge amount of hardware, like video
52
and network cards, frame-grabbers, multi-purpose cards and custom
53
boards.
54
 
55
Shark is a compiling kernel with memory protection, not a kernel like
56
Linux. You will not find any main() routine into the kernel tree
57
because the tree only contains the set of libraries required to build
58
the application. The main() function is called by the kernel, and is
59
contained into the application files as specified by the C language
60
standard.
61
 
62
%------------------------------------------------------------
63
\chapter{Getting started}
64
\label{ch:getting-started}
65
%------------------------------------------------------------
66
 
67
This Section covers the S.Ha.R.K. installation and system building
68
from the sources available on the website. As will be introduced in
69
Section \ref{sec:platforms}, S.Ha.R.K. can be used under Linux,
70
Windows$^{TM}$ or xDOS (preferably the free version of DOS, FreeDOS).
71
 
72
%------------------------------------------------------------
73
\section{Supported platforms}
74
\label{sec:platforms}
75
%------------------------------------------------------------
76
 
77
S.Ha.R.K. application, as well as the Shark kernel, modules and
78
drivers, can be developed under three main platforms: DOS (either
79
MS-DOS$^{TM}$ or FreeDOS\footnote{In the rest of the document, we
80
will only refer to FreeDOS while addressing the xDOS platform. Most
81
of the topics  hold for other DOS systems; specific indications for
82
other platforms will be given if necessary.}), Windows$^{TM}$ or
83
Linux. Table \ref{t:platforms-comparison} shows some characteristics
84
of using Shark under the three systems.
85
 
86
\begin{table}[ht]
87
\centering
88
\begin{tabular}{|l|c|c|c|}
89
\hline
90
                                & DOS           & Linux                 &
91
Windows         \\ \hline
92
Graphical interface             & no            & \textbf{yes}          &
93
\textbf{yes}            \\
94
Good editors                    & it depends    & \textbf{yes}          &
95
\textbf{yes}           
96
\\
97
Compilation speed               & slow          & \textbf{fast}         &
98
\textbf{fast}           \\
99
Native compiler                 & no            & \textbf{yes}          & no   
100
        \\
101
Programming/debug tools         & no            & \textbf{yes}          & no   
102
        \\
103
Dealing with long filenames     & TSRs          & \textbf{native}       &
104
\textbf{native} \\
105
Native execution                & \textbf{yes}  & no                    & no   
106
        \\ \hline
107
\end{tabular}
108
\caption{Quick comparison among the different supported platforms.}
109
\label{t:platforms-comparison}
110
\end{table}
111
 
112
A quick consideration about the item "Good editors" for DOS. Someone
113
may consider RHIDE, the DOS editor distributed with S.Ha.R.K. a good
114
editor: I don't. But I also hate EDIT. Usually, I use an old editor
115
called AURORA. More information at
116
 
117
\begin{center}
118
\underline{http://www-personal.umich.edu/~knassen/aurora.html}
119
\end{center}
120
 
121
Linux and Windows$^{TM}$ are quite similar, in terms of programming
122
facilities. The main advantage on using FreeDOS platforms is that it
123
does not require to reboot the machine to execute the application,
124
while when developing under Linux or Windows$^{TM}$ it does.
125
 
126
Cygwin or other Linux console for Windows$^{TM}$ are not currently
127
and directly supported. However, the support to such platforms is not
128
mandatory in the current version, since a Windows$^{TM}$ user can
129
easily build the system and develop application directly from the
130
Windows$^{TM}$ platform.
131
 
132
%------------------------------------------------------------
133
\section{Installation}
134
\label{sec:platform-install}
135
%------------------------------------------------------------
136
 
137
The installation changes a little bit from platform to platform.
138
 
139
%------------------------------------------------------------
140
\subsection{Linux}
141
\label{sec:install-linux}
142
%------------------------------------------------------------
143
 
144
\begin{enumerate}
145
\item \label{linux-step1} download \texttt{shark-1.5.tar.bz2} from the S.Ha.R.K.
146
web site (\underline{http://shark.sssup.it})
147
\item \label{linux-step2} type \texttt{tar xvjf shark-1.5.tar.bz2}
148
\item \label{linux-step3} type \texttt{cd shark}
149
\item \label{linux-step4} edit the S.Ha.R.K. configuration file,
150
\texttt{shark.cfg}
151
\item \label{linux-step5} type \texttt{make all}
152
\item \label{linux-step6} type \texttt{cd demos}
153
\item \label{linux-step7} type \texttt{make}
154
\end{enumerate}
155
 
156
Some tips:
157
 
158
\begin{itemize}
159
\item Step \ref{linux-step4} is needed to setup the compiler options and
160
optimize the kernel for speed and precision.
161
\item Step \ref{linux-step5} builds the S.Ha.R.K. kernel, libraries, modules and
162
device drivers.
163
\item Finally, step \ref{linux-step7} builds the demo programs.
164
\end{itemize}
165
 
166
%------------------------------------------------------------
167
\subsection{DOS}
168
\label{sec:install-DOS}
169
%------------------------------------------------------------
170
 
171
The installation for the xDOS platform follows:
172
 
173
\begin{enumerate}
174
\item \label{DOS-step1} download \texttt{unzip32.exe}, \texttt{mindj333.zip}
175
and
176
\texttt{shark15.zip} from the S.Ha.R.K. web site.
177
\item \label{DOS-step2} type \texttt{unzip32 -o mindj333.zip -d c:}
178
\item \label{DOS-step3} type \texttt{cd c:$\backslash$djgpp}
179
\item \label{DOS-step4} type \texttt{install.bat}
180
\item \label{DOS-step5} type \texttt{setvar.bat}
181
\item \label{DOS-step6} type \texttt{unzip32 -o shark15.zip -d c:}
182
\item \label{DOS-step7} type \texttt{cd c:$\backslash$shark}
183
\item \label{DOS-step8} edit \texttt{shark.cfg}
184
\item \label{DOS-step9} type \texttt{make}
185
\item \label{DOS-step10} type \texttt{cd demos}
186
\item \label{DOS-step11} type \texttt{make}
187
\item \label{DOS-step12} type \texttt{cd $<$demo dir$>$}
188
\item \label{DOS-step13} type \texttt{x $<$demo name$>$}
189
\end{enumerate}
190
 
191
Some tips:
192
 
193
\begin{itemize}
194
\item If you already have \texttt{PkZip}, at step \ref{DOS-step2} you may
195
also type \texttt{pkunzip -d -o mindj333.zip c:$\backslash$}
196
\item If you change the DJGPP directory name or position,
197
\texttt{install.bat} and \texttt{setvar.bat} need also to be changed.
198
\item The \texttt{setvar.bat} script automatically set the environement
199
variables for DJGPP; you must run \texttt{install.bat} and
200
\texttt{setvar.bat} every time you reboot and start a compile
201
session.
202
\item After step \ref{DOS-step5}, DJGPP is installed and ready to compile
203
shark.
204
\item If you already have PkZip, at step \ref{DOS-step6} you may also type
205
\texttt{pkunzip -d -o shark15.zip c:$\backslash$}
206
\item Step \ref{DOS-step8} is needed to setup the compiler options and
207
optimize the kernel for speed and precision.
208
\item Step \ref{DOS-step9} builds the S.Ha.R.K. kernel, libraries, modules
209
and device drivers.
210
\item Finally, step \ref{DOS-step11} builds the demo programs.
211
\end{itemize}
212
 
213
In DOS real mode we suggest, even though it is not mandatory, to load
214
the smartdrive utility (\texttt{smartdrv 16000 /x}) to speedup the
215
disk access during all the previous steps. The \texttt{smartdrv}
216
utility is available for MS-DOS$^{TM}$. For the FreeDOS environemnt
217
you can use the lbacache instead.
218
 
219
\textbf{IMPORTANT:} You need DOSLFN.ZIP
220
(\underline{http://shark.sssup.it/distrib/doslfn.zip}), a TSR to use
221
long file names under DOS real mode. You have to run the doslfn
222
command before starting to work with S.Ha.R.K. every time the machine
223
is re-booted. You don't need it only if you are inside a DOS
224
emulation window (see Windows Millennium/NT/2000/XP paragraph).
225
 
226
In real DOS environement, you can compile and run a demos without
227
reboot, directly running the demo programs through the \texttt{X.EXE}
228
extender from the FreeDOS command line.
229
 
230
%------------------------------------------------------------
231
\subsection{Windows Millennium/NT/2000/XP}
232
\label{sec:install-win}
233
%------------------------------------------------------------
234
 
235
\begin{enumerate}
236
\item download unzip32.exe,mindj333.zip and shark15.zip from the S.Ha.R.K. web
237
site;
238
\item go in a DOS emulation window (DOS prompt);
239
\item follow the previous procedure for normal DOS environment.
240
\end{enumerate}
241
 
242
\textbf{Reminder:} YOU CAN NOT EXECUTE A S.Ha.R.K. APPLICATION
243
THROUGH THE X.EXE EXTENDER WITHIN A DOS EMULATION WINDOW. So, to test
244
a compiled demo programs you need  to reboot with the FreeDOS
245
bootdisk or something similar.
246
 
247
%------------------------------------------------------------
248
\section{How to partition the hard-disk for using with S.Ha.R.K.}
249
\label{sec:hd-installation}
250
%------------------------------------------------------------
251
 
252
Even though it is often not needed and it may be unconfortable to
253
setup an already partitioned machine, it may be very useful to setup
254
a machine to host the S.Ha.R.K. kernel in school and university
255
laboratories for teaching purposes.
256
 
257
This section is dedicated to the setup of an hard-disk for dedicating
258
a partition to the installation of S.Ha.R.K. It will explain how to
259
partition and format an hard-disk in order to install a multi-boot
260
environment allowing to choose between three operating systems:
261
FreeDOS and S.Ha.R.K., Linux and Windows$^{TM}$. The five basic steps
262
to setup the installation are:
263
 
264
\begin{enumerate}
265
\item partition the hard disk;
266
\item install Windows$^{TM}$;
267
\item install FreeDOS;
268
\item install Linux;
269
\item setup the boot loader.
270
\end{enumerate}
271
 
272
The tools needed to perform the installation are:
273
 
274
\begin{itemize}
275
\item Linux fdisk utility;
276
\item a copy of Linux installation CD;
277
\item a copy of Windows$^{TM}$ installation CD;
278
\item some FreeDOS utilities;
279
\item a copy of S.Ha.R.K.
280
\end{itemize}
281
 
282
To accomplish all the operation related to the hard-disk partition, I
283
suggest to use a Linux LiveCD distribution. My favourite one is
284
Knoppix, by Mark Knopper, downloadable from
285
 
286
\begin{center}
287
\underline{http://www.knoppix.org}.
288
\end{center}
289
 
290
Linux LiveCD distribution allow to use all the powerful Linux tools
291
without the need of installing anything on the hard-disk.
292
 
293
Boot the PC from the CD drive after inserting the Knoppix LiveCD into
294
the drive and open a shell. You must be the root user to have the
295
permissions for the next steps, so type
296
 
297
\begin{center}
298
\texttt{su}
299
\end{center}
300
 
301
with an empty password at the console prompt. Then launch the Linux
302
\texttt{fdisk}, typing
303
 
304
\begin{center}
305
\texttt{fdisk /dev/hdXXX}
306
\end{center}
307
 
308
where XXX identifies your hard-drive. Typically, the command
309
 
310
\begin{center}
311
\texttt{fdisk /dev/hda}
312
\end{center}
313
 
314
will work fine. To use the \texttt{fdisk} commands do refer to the
315
program help: you will need the commands to delete and create
316
partition as well as to change the partition ID and write the
317
partition table on the disk.
318
 
319
I suggest to partition your HD like something as described in Table
320
\ref{t:hd-partitioning}.
321
 
322
\begin{table}[ht]
323
\centering
324
\begin{tabular}{|c|c|c|c|}
325
\hline
326
                        & Partition number      & Dedicated to  & Type         
327
\\ \hline
328
                        & 1st                   & FreeDOS       & FAT32        
329
\\
330
primary partitions      & 2nd                   & Windows       & FAT32/NTFS   
331
\\
332
                        & 3rd                   & Linux         &
333
extX/Reiser/... \\ \hline
334
                        & 4th                   & Data 1        & any          
335
\\
336
extended partition      & ...                   & ...           & ...          
337
\\
338
                        & last but one          & Data n        & any          
339
\\
340
                        & last                  & Linux swap    & (if needed)  
341
\\
342
\hline
343
\end{tabular}
344
\caption{Example of hard-disk partitioning.}
345
\label{t:hd-partitioning}
346
\end{table}
347
 
348
\textbf{IMPORTANT:} The FreeDOS partition must be the FIRST partition
349
on your disk or you should experience some problems while booting
350
FreeDOS.
351
 
352
Since \texttt{fdisk} creates all the partitions as Linux partitions,
353
you must toggle the partition type of the 2nd partition to make it a
354
FAT32 (LBA) or NTFS.
355
 
356
\textbf{SUGGESTION:} Do leave all the other partition as Linux type,
357
so that Windows$^{TM}$ will put all the booting stuff into the only
358
partition that it can see at installation time.
359
 
360
Now, reboot and install Windows$^{TM}$ into the only partition that
361
is available for it. I only tested the 2000 and XP versions of
362
Windows. If you want to install previous Windows$^{TM}$ versions (98
363
or 95) I'm not sure that they will be able to boot if they are not
364
installed into the first partition. However if you want to use them,
365
you can skip the installation of FreeDOS, since you can use the
366
MS-DOS shell to run Shark programs.
367
 
368
After the installation of Windows$^{TM}$, boot Knoppix again and use
369
\texttt{fdisk} to change the partition type of the 1st partition:
370
toggle it as FAT32 (LBA) - suggested - or FAT16 if you want to test
371
the filesystem capabilities of Shark.
372
 
373
Do format the 1st partition using the Windows formatting program.
374
 
375
Install FreeDOS. You can download all the packages from
376
 
377
\begin{center}
378
\underline{http://www.freedos.org}.
379
\end{center}
380
 
381
I suggest to download the packages and to copy them manually into the
382
partition, avoiding the Installation CD or floppy. You can also use a
383
S.Ha.R.K. boot CD to copy the whole FreeDOS tree onto the disk.
384
 
385
Make a FreeDOS boot floppy using the \texttt{sys} command, executing
386
a command like
387
 
388
\begin{center}
389
\texttt{sys a:}
390
\end{center}
391
 
392
Copy also the \texttt{sys.com} FreeDOS program on the floppy.
393
 
394
Reboot the machine leaving the floppy into the drive and launch the
395
command
396
 
397
\begin{center}
398
\texttt{sys x: x:$\backslash$fdosboot.img}   % check the backslash
399
\end{center}
400
 
401
\textbf{ATTENTION:} "x:" refers to the drive letter of the partion in
402
which FreeDOS has been installed, as seen by FreeDOS after the boot
403
from floppy (check which is the right drive letter by listing the
404
content of the drives with "dir x:").
405
 
406
What you did is to created an image of the boot sector which is able
407
to boot FreeDOS, but instead of overwriting the Master Boot Record
408
(MBR), you writed it onto the disk.
409
 
410
Now insert the Linux intallation disk, reboot the PC and install
411
Linux. After the installation, the GRUB boot manager should be
412
installed in your MBR (I did not tested other boot managers, like
413
LILO).
414
 
415
Look for the configuration file of the GRUB, \texttt{grub.conf}, that
416
is
417
often placed into the \texttt{/boot/grub} directory. The lines to
418
boot Linux are usually added automatically by the installer. The
419
lines to boot Windows$^{TM}$ look like the following
420
 
421
\begin{verbatim}
422
title Win2000
423
rootnoverify (hd0,1)
424
chainloader +1
425
\end{verbatim}
426
 
427
Then, add the lines to boot FreeDOS:
428
 
429
\begin{verbatim}
430
title FreeDOS - Shark
431
rootnoverify (hd0,0)
432
makeactive
433
chainloader /fdosboot.img
434
boot
435
\end{verbatim}
436
 
437
Now you are ready to install the S.Ha.R.K. distribution following the
438
instructions of Section \ref{sec:platform-install}.
439
 
440
%------------------------------------------------------------
441
\section{Kernel and applications}
442
\label{sec:kernel-apps}
443
%------------------------------------------------------------
444
 
445
S.Ha.R.K. currently supports the PC platform (Intel$^{TM}$ or
446
AMD$^{TM}$ processors, etc.). Using the S.Ha.R.K. kernel is easy. Few
447
tools are required to build the kernel, to develop new applications
448
and to run existing or new applications.
449
 
450
%------------------------------------------------------------
451
\subsection{Building kernel and applications}
452
\label{sec:build-kernel}
453
%------------------------------------------------------------
454
 
455
S.Ha.R.K. is written in C, so it requires a C compiler to build the
456
system from the source code. Currently, S.Ha.R.K. supports the
457
\texttt{GCC version 3.3}, which is the standard compiler and is
458
already present in most of the Linux distributions.
459
 
460
\textbf{ATTENTION:} the \texttt{GCC version 3.4} does not properly
461
work while building the system or compiling user programs. You can
462
check your GCC version by typing
463
 
464
\begin{center}
465
\texttt{gcc -v}
466
\end{center}
467
 
468
into a Linux console.
469
 
470
Windows$^{TM}$ or FreeDOS come without their own C compiler. There
471
exist a version of the GCC which runs under FreeDOS, and
472
Windows$^{TM}$ too, called DJGPP and available at
473
 
474
\begin{center}
475
\underline{http://www.delorie.com/djgpp}.
476
\end{center}
477
 
478
However, the DJGPP version downloadable from the DJ Delorie website
479
it is not suitable to be used with S.Ha.R.K. since it produces the
480
COFF\footnote{See
481
\underline{http://www.theparticle.com/cs/bc/os/elfpecoff.html}
482
for some information on executable file formats.} executable file
483
format only. S.Ha.R.K. needs a compiler which has to be able to
484
produce the ELF file format. This is why the DJGPP has been rebuilt
485
in order to produce the ELF format.
486
 
487
\textbf{ATTENTION:} you must download the correct DJGPP version from
488
the S.Ha.R.K. website.
489
 
490
%------------------------------------------------------------
491
\subsection{Executing applications}
492
\label{sec:execute-app}
493
%------------------------------------------------------------
494
 
495
There are two options to run a new application or one of the demos
496
distributed with S.Ha.R.K.:
497
 
498
\begin{itemize}
499
\item using the X.EXE DOS memory extender;
500
\item loading the application from the GRUB boot manager.
501
\end{itemize}
502
 
503
Using X.EXE, which is available on the S.Ha.R.K. website, requires an
504
xDOS platform. Supported platforms are FreeDOS and MS-DOS$^{TM}$. In
505
the latter case, however, an application can be run using X.EXE only
506
from a Windows$^{TM}$ 95, Windows$^{TM}$ 98 and Windows$^{TM}$ 95SE
507
DOS console.
508
 
509
\textbf{ATTENTION:} Windows$^{TM}$ Millennium/ NT/2000/ XP consoles
510
can not be used to run S.Ha.R.K. applications.
511
 
512
Using the GRUB is more complicated and, since it is particularly
513
useful
514
for the remote execution of S.Ha.R.K. programs, this topic will be
515
covered in a dedicated section.
516
 
517
%------------------------------------------------------------
518
\subsection{Getting a DOS environment for executing S.Ha.R.K.
519
applications}
520
\label{sec:environment}
521
%------------------------------------------------------------
522
 
523
To execute a S.Ha.R.K. application a DOS environment is required, and
524
several options are available to get it:
525
 
526
\begin{itemize}
527
 
528
\item
529
an hard-disk can be partitioned and formatted for multi-boot, and a
530
partition can be reserved to FreeDOS. This may be a tricky way, and
531
it is suggested only if the users has a good knowledge of the
532
involved operations. It is particularly useful to setup the
533
workstations in school and university laboratories.
534
 
535
\item
536
re-booting a machine every time an execution of a S.Ha.R.K.
537
application is needed with the S.Ha.R.K. boot CD or the boor floppy
538
available on the S.Ha.R.K. website.
539
 
540
The second option needs some more indications. When the machine
541
restarts, a FreeDOS environment is made available. This means that it
542
is possible to launch the X.EXE extender to run a S.Ha.R.K.
543
application. The application itself should be put on the floppy or,
544
anyway, it MUST be put on a partition with a filesystem reachable by
545
the FreeDOS kernel. At the best of my knowledge, FreeDOS currently
546
supports FAT16 and FAT32 filesystems only. So that, an application
547
which is stored that resides on a NTFS (Windows$^{TM}$), ext2, ext3,
548
ReiserFS or other Linux filesystems can not be executed using the
549
boot from floppy or CD.
550
 
551
\end{itemize}
552
 
553
%------------------------------------------------------------
554
\chapter{Using S.Ha.R.K.}
555
\label{ch:using}
556
%------------------------------------------------------------
557
 
558
%------------------------------------------------------------
559
\section{Your first S.Ha.R.K. application}
560
\label{sec:first-app}
561
%------------------------------------------------------------
562
 
563
A typical S.Ha.R.K. application is composed by 3 main components: the
564
\texttt{program} source file, the initialization source file
565
(\texttt{initfile}) and the \texttt{makefile}.
566
 
567
%------------------------------------------------------------
568
\subsection{The makefile}
569
\label{sec:makefile}
570
%------------------------------------------------------------
571
 
572
The makefile is the script used by the \texttt{make} command to build
573
the application. Typically, the makefile is named "makefile", and you
574
can build the application by simply launching the command
575
\texttt{make} from the command line. However, the makefile may be
576
named differently in order, for example, to maintain different make
577
settings into the same directory. With a makefile named "myapp.mak",
578
the application can be built typing the command \texttt{make -f
579
myapp.mak}.
580
 
581
\textbf{IMPORTANT:} To build an application, you can not launch the
582
compiler directly without using the makefile, since the makefile sets
583
several variables and calls several sub-routines before invoking the
584
compiler.
585
 
586
\begin{figure}
587
\noindent
588
\newcounter{alines}
589
\begin{list}{\arabic{alines}}{\usecounter{alines}}
590
\addtolength{\parskip}{-8pt}
591
\hrule
592
 
593
\item ifndef BASE \label{l1:ifndef}
594
\item BASE=../.. \label{l1:def-base}
595
\item endif \label{l1:endif}
596
\item include \$(BASE)/config/config.mk \label{l1:inc-config}
597
\item PROGS = myapp \label{l1:prog-name}
598
\item include \$(BASE)/config/example.mk \label{l1:inc-example}
599
\item myapp: \label{l1:build-cmd}
600
\item \ \ \ \ make -f \$(SUBMAKE) APP=myapp INIT=
601
OTHEROBJS="initfile.o source2.o source3.o" OTHERINCL=
602
SHARKOPT="\_\_LINUXC26\_\_ \_\_PCI\_\_ \_\_INPUT\_\_ \_\_FB\_\_"  
603
\label{l1:make-instr}
604
 
605
\end{list}
606
\hrule
607
\caption{Example of makefile.}
608
\label{f:ex-makefile}
609
\end{figure}
610
 
611
The makefile contains some directives to specify the application
612
name, source file names and libraries needed for building the
613
application. Figure \ref{f:ex-makefile} shows an example of makefile
614
for building an application called \texttt{myapp}, thus contained
615
into the source file \texttt{myapp.c}. The application code is also
616
contained into two source files: \texttt{source1.c},
617
\texttt{source2.c}. For each of those files, the compiler produces an
618
\texttt{object file}, with the ".o" extension. The object files
619
required for making the application must be specified with the
620
OTHEROBJS directive into the instruction at line \ref{l1:make-instr}.
621
Notice that, since also the initfile contains the application source
622
code (Section \ref{sec:initfile}), you must include the related
623
object file name into the OTHEROBJS directive.
624
 
625
To customize the makefile in order to build your own application, you
626
must supply the program name at lines \ref{l1:prog-name} and
627
\ref{l1:make-instr}, and the same name should be used for the
628
instruction at line \ref{l1:build-cmd}.
629
 
630
At line \ref{l1:def-base}, you specify the path where the S.Ha.R.K.
631
kernel has been installed. Althought you can specify an absolute path
632
like \texttt{/home/username/shark} for Linux or \texttt{c:$\backslash$shark},
633
typically a relative path is used. In Figure \ref{f:ex-makefile}, the
634
instruction at line \ref{l1:def-base} says that the base S.Ha.R.K.
635
directory is located two levels before the application directory. For
636
example, if S.Ha.R.K. has been installed into
637
\begin{center}
638
\texttt{/home/toolleeo/shark},
639
\end{center}
640
the application is located into
641
\begin{center}
642
\texttt{/home/toolleeo/shark/projects/apps}.
643
\end{center}
644
 
645
The BASE directory in the example is relative to the current
646
application directory. This works fine if the application directory
647
is under the S.Ha.R.K. derictory tree. If the application stays
648
outside the system tree, you can use an absolute indication of the
649
S.Ha.R.K. base directory, such as \texttt{/home/toolleeo/shark} instead of
650
\texttt{../..}.
651
 
652
Finally, the instruction at line \ref{l1:make-instr} specifies also
653
the libraries that must be linked together the object code to build
654
the whole application. In the example, the application uses the Linux
655
2.6 compatibility layer, which is always required when the drivers
656
are used, the PCI driver, the Input driver (to manage the input
657
devices like keyboard, mouse, etc.) and the Frame Buffer driver for
658
the graphical display. The list of all the available libraries can be
659
found into the \texttt{\$(BASE)/lib} directory, where
660
\texttt{\$(BASE)} is the S.Ha.R.K. installation directory.
661
 
662
\textbf{ATTENTION:} when modifying the makefile, be sure to use a
663
text editor which saves the TAB character and avoids editors (often
664
you can configure this option into the editor preferences) which
665
substitute TAB characters with spaces. This is important because
666
instruction \ref{l1:make-instr} MUST be indented with a TAB
667
character. Otherwise, the \texttt{make} command will not be able to
668
interpret the makefile correctly.
669
 
670
%------------------------------------------------------------
671
\subsection{The initfile}
672
\label{sec:initfile}
673
%------------------------------------------------------------
674
 
675
The initfile is a normal source file which contains the instruction
676
for the program initialization. Initfiles include the system
677
headers, initialize modules regarding the scheduling policies for
678
tasks and shared resources, the graphical mode if needed, the
679
keyboard and all the required devices.
680
 
681
When the application is launched, before starting the multitasking
682
mode the program must initialize the devices, the resources and the
683
schedulers which will be used by the application. For doing so, the
684
kernel calls the \texttt{\_\_kernel\_register\_levels\_\_} function, that
685
usually registers the following modules (see the S.Ha.R.K. Kernel
686
architecture Manual for more details):
687
 
688
\begin{itemize}
689
\item scheduling modules: a scheduling module implements a particular scheduling
690
algorithm, for example EDF, RM, Round Robin, etc.;
691
\item resource Modules: a resource module implements a shared resource access
692
protocol (for example the semaphores, the mutexes, etc.);
693
\item other devices, such for example the file system, and other devices that
694
has to be initialized before entering the multitasking mode.
695
\end{itemize}
696
 
697
%------------------------------------------------------------
698
\subsection{The program}
699
\label{sec:program}
700
%------------------------------------------------------------
701
 
702
The program file is the source file containing the \texttt{main}
703
function
704
 
705
\begin{center}
706
\texttt{int main(int argc, char **argv)}
707
\end{center}
708
 
709
The main function is automatically called by the kernel when the application is
710
launched through the X memory extender or the GRUB. The main functions contains
711
the declarations for - or calls the routine to initialize - the user tasks, the
712
keyboard handler and all the components required by the application.
713
 
714
%------------------------------------------------------------
715
\section{Tips and tricks}
716
\label{sec:tips}
717
%-----------------------------------------------------------
718
 
719
%------------------------------------------------------------
720
\subsection{The BASE directory}
721
\label{sec:base-dir}
722
%------------------------------------------------------------
723
 
724
S.Ha.R.K. uses the BASE variable to identify the directory where the
725
system directory tree starts. For example, a typical installation
726
under Linux may be under \texttt{/home/username/shark}; under FreeDOS the
727
path would be ``c:$\backslash$shark''.
728
 
729
Unfortunately, the OSLib component of S.Ha.R.K., which is developed
730
separately from S.Ha.R.K., also requires to set a variable named BASE
731
when building. Recalling the previous examples, the BASE values for
732
the OSLib will be \texttt{/home/username/shark/oslib} and
733
\texttt{c:$\backslash$shark$\backslash$oslib}.
734
 
735
A problem during the kernel compilation arises if the BASE variable
736
is set into the OS environment\footnote{At the FreeDOS command line,
737
type ``\texttt{set}'' to get the content of the environment.}.
738
 
739
\textbf{IMPORTANT}: when compiling S.Ha.R.K., be sure that BASE is
740
not set environment variable to get no problem\footnote{At the
741
FreeDOS command line, type ``\texttt{set BASE=}'' to remove an
742
already set BASE variable.}.
743
 
744
During the application development, thus when S.Ha.R.K. is already
745
built and you do not need to rebuild the kernel, you may set BASE to
746
point to the S.Ha.R.K. base directory. In this sistuation, you can
747
move the application source code around your filesystem without
748
changing the BASE definition into the makefile. See Section
749
\ref{sec:makefile} for an overview on the S.Ha.R.K. makefiles.
750
However, you should avoid this practice; you should prefer to set
751
correctly the BASE directory into the makefile for each project you
752
are working at.
753
 
754
%------------------------------------------------------------
755
\subsection{Text output}
756
\label{sec:text-output}
757
%------------------------------------------------------------
758
 
759
There are few things to know for using the S.Ha.R.K.'s functions to
760
display text. Four functions should be used for a safe text output
761
management:
762
 
763
\begin{itemize}
764
 
765
\item
766
\texttt{sprintf()} to write a formatted string into a generic text
767
buffer (e.g., an array of chars);
768
 
769
\item
770
\texttt{cprintf()} for the regular text output while the application is in
771
text mode;
772
 
773
\item
774
\texttt{grx\_text()} for the text output when the application is in
775
graphical mode (to be used together with \texttt{sprintf()}, which generates
776
the string to be displayed);
777
 
778
\item
779
\texttt{printk()} for displaying strings in text mode into the kernel
780
and modules for debug purposes.
781
 
782
\end{itemize}
783
 
784
%------------------------------------------------------------
785
\subsection{I/O to the filesystems}
786
\label{sec:filesystem}
787
%------------------------------------------------------------
788
 
789
S.Ha.R.K. currently supports only FAT16 filesystems on IDE drivers.
790
This means that, while the kernel is running, only FAT16 filesystems
791
could be accessed from the application.
792
 
793
However, typically, read/write operations to the filesystem can be
794
done at the beginning or at the end of the application, to load
795
initial parameters or data and to save the results (which could be
796
contained in a memory buffer filled during the application
797
execution). To do so, do use the functions listed into
798
\texttt{include/ll/i386/x-dos.h}, and allow the user to read and
799
write binary and text files.
800
 
801
The difference between the full support of FAT16 filesystems and the
802
functions of the \texttt{x-dos} library is that, while the former is
803
a true driver which accesses the hard-disk hardware, the latter are
804
hooks to DOS INT 21h functions. Since DOS INT 21h are not reentrant
805
(basically, they can not be interrupted by the kernel), they can not
806
be used while real-time tasks are running.
807
% For more informations, see demos/dosfs/README.
808
% Tool: wait till demos are ok
809
%
810
 
811
%------------------------------------------------------------
812
\subsection{DJGPP and DOS utils}
813
\label{sec:dos-utils}
814
%------------------------------------------------------------
815
 
816
The DJGPP, the compiler used by S.Ha.R.K. under DOS, does not include
817
any replacement for some Unix commands required to build S.Ha.R.K.,
818
like \texttt{cp}, \texttt{rm}, \texttt{mv}, etc. Those comands can be
819
found easily in the Internet, but it is safer to use the ones
820
included into the S.Ha.R.K. package.
821
 
822
Someone may already have its own set of command replacements. This
823
may produce several problems, since different implementations manages
824
differently the special command options. This is why S.Ha.R.K. is
825
guaranteed to correctly build with the tested commands only (the
826
Linux versions are all right).
827
 
828
Short anecdote\footnote{I add this anecdote since it may help in
829
solving similar problems.}. The first version of the S.Ha.R.K.
830
bootable CD included the correct commands got from the S.Ha.R.K.
831
distribution package. It also included another version that is put
832
into the ``$\backslash$fdos$\backslash$bin'' directory. Both the
833
versions of the commands were reacheable through the PATH environment
834
variable. However, for a mistake, the FreeDOS path was inserted into
835
the PATH variable before the correct S.Ha.R.K. path, making S.Ha.R.K.
836
using the wrong commands. Results: the makefiles were invoking the
837
wrong command versions, producing several problems while building
838
kernel and applications.
839
 
840
%------------------------------------------------------------
841
\section{From version 1.4 to 1.5}
842
\label{sec:from14to15}
843
%------------------------------------------------------------
844
 
845
From the user point of view, few things are changed from the
846
S.Ha.R.K. 1.4 version to the current 1.5 version. The changes that
847
make an application developed for version 1.4 incompatible with the
848
1.5 version are only two:
849
 
850
\begin{enumerate}
851
 
852
\item
853
to make the new version compatible with the POSIX standard, functions
854
\texttt{sys\_end()} and \texttt{sys\_abort()} have been replaced by
855
the \texttt{exit(.)} function, which accepts an integer exit code
856
parameter.
857
 
858
\item
859
the S.Ha.R.K. directory tree has been slightly changed.
860
 
861
\end{enumerate}
862
 
863
The main effect of the changes to the tree are that an application
864
initfile now requires slightly different instructions to include the
865
needed modules. A comparison of the instructions required for the two
866
S.Ha.R.K. versions is depicted in Table \ref{t:initfile}.
867
 
868
\begin{table}[ht]
869
\centering
870
\begin{tabular}{|l|l|}
871
\hline
872
Version 1.4                     & Version 1.5                          
873
\\
874
\hline
875
\#include "kernel/kern.h"       & \#include "kernel/kern.h"            
876
\\
877
\#include "modules/intdrive.h"  & \#include
878
"intdrive/intdrive/intdrive.h"  \\
879
\#include "modules/edf.h"       & \#include "edf/edf/edf.h"            
880
\\
881
\#include "modules/cbs.h"       & \#include "cbs/cbs/cbs.h"            
882
\\
883
\#include "modules/rr.h"        & \#include "rr/rr/rr.h"               
884
\\
885
\#include "modules/dummy.h"     & \#include "dummy/dummy/dummy.h"      
886
\\
887
\#include "modules/sem.h"       & \#include "sem/sem/sem.h"            
888
\\
889
\#include "modules/hartport.h"  & \#include
890
"hartport/hartport/hartport.h"  \\
891
\#include "modules/cabs.h"      & \#include "cabs/cabs/cabs.h"         
892
\\
893
\#include "modules/pi.h"        & \#include "pi/pi/pi.h"               
894
\\
895
\hline
896
\end{tabular}
897
\caption{The differences between inifiles in S.Ha.R.K. 1.4 and 1.5.}
898
\label{t:initfile}
899
\end{table}
900
 
901
%------------------------------------------------------------
902
\section{Remote execution of S.Ha.R.K. applications}
903
\label{sec:remote-execution}
904
%------------------------------------------------------------
905
 
906
S.Ha.R.K. supports the Multiboot\footnote{See
907
\underline{http://www.gnu.org/software/grub/manual/multiboot/} for
908
more information.} standard. This means that it is possible to launch
909
remotely a S.Ha.R.K. application from, for example, the
910
GRUB\footnote{See \underline{http://www.gnu.org/software/grub/} for
911
more information.} boot loader.
912
 
913
Since this Section will describe how to boot a S.Ha.R.K. application
914
using the GRUB, let's say something more about it, and boot loaders
915
in general.
916
 
917
In very simple words, boot loaders are programs that, taking the
918
control of the machine after the system start-up, launch the
919
operative system kernels. Boot loaders are particularly useful
920
because they let you choose between different operative systems to
921
start. Section \ref{sec:hd-installation} illustrated how to partition
922
an hard-disk
923
to install more than one OS. This Section will describe how to load a
924
kernel (in our case, a S.Ha.R.K. application) from the network and
925
run it on a remote machine.
926
 
927
An example will explain the installation procedure and how to use
928
this mechanism.
929
 
930
%------------------------------------------------------------
931
\subsection{General setup}
932
\label{sec:remote-setup}
933
%------------------------------------------------------------
934
 
935
Suppose that there are two machines: computer A, where you develop
936
your S.Ha.R.K. applications using the Linux platform, and computer B,
937
where you want to execute the application.
938
 
939
Computer A needs:
940
 
941
\begin{itemize}
942
\item an Ethernet connection with B;
943
\item Linux;
944
\item an installed and properly configured version of S.Ha.R.K.;
945
\item a TFTP server.
946
\end{itemize}
947
 
948
Computer B needs:
949
 
950
\begin{itemize}
951
\item an Ethernet connection with A;
952
\item an installation of the GRUB with network support.
953
\end{itemize}
954
 
955
%------------------------------------------------------------
956
\subsection{Computer A setup}
957
\label{sec:A-setup}
958
%------------------------------------------------------------
959
 
960
There are two important things to setup on machine A. First of all,
961
the S.Ha.R.K. kernel must be compiled with the option BIOS set to
962
VM86 (Virtual Memory for x86) into the shark.cfg configuration file.
963
This ensures that the application will be compiled with the support
964
for the multiboot.
965
 
966
\textbf{ATTENTION}: as stated in the configuration file, the VM86
967
mode is not compatible with some VGA cards (like Matrox).
968
 
969
A TFTP server must be installed on computer A, to let B download the
970
application. TFTP means Trivial File Transfer Protocol; it is a
971
simplified version of FTP which permits only basic operations like
972
download and upload (no directory management, etc.). Moreover, it
973
works over the UDP protocol, while FTP works over TCP. Almost all
974
Linux distribution have a TFTP server. I will not discuss how to
975
install and run it. The only important thing to know is that,
976
typically, the server lets a remote machine to download a program
977
from a specific directory (e.g., /tftpboot/). The compiled S.Ha.R.K.
978
program will be put into that directory.
979
 
980
%------------------------------------------------------------
981
\subsection{Computer B setup}
982
\label{sec:B-setup}
983
%------------------------------------------------------------
984
 
985
First of all, let's build the GRUB for supporting the network.
986
Currently, the GRUB 2 is under development. I only tested the remote
987
execution with S.Ha.R.K. using the so called the GRUB Legacy, which
988
is still available.
989
 
990
Download the GRUB Legacy from
991
 
992
\begin{center}
993
\underline{ftp://alpha.gnu.org/gnu/grub/}
994
\end{center}
995
 
996
Since I only tested the behavior of the \texttt{grub-0.97.tar.gz}
997
package, I suggest to use this version.
998
 
999
After unpacking the sources on a Linux machine with
1000
 
1001
\begin{center}
1002
\texttt{tar -xvzf grub-0.97.tar.gz}
1003
\end{center}
1004
 
1005
you will get the \texttt{grub-0.97} directory. Do get into it using
1006
 
1007
\begin{center}
1008
\texttt{cd grub-0.97}
1009
\end{center}
1010
 
1011
and configure the GRUB with a command like
1012
 
1013
\begin{center}
1014
\texttt{./configure --enable-via-rhine --disable-ffs --disable-minix
1015
--disable-reiserfs --disable-xfs --disable-ufs2 --disable-vstafs}
1016
\end{center}
1017
 
1018
This instruction simply configures the GRUB to support a VIA network
1019
board (Rhine model) and turned off the support for many filesystems,
1020
like FFS, Minix, XFS and others.
1021
 
1022
Of course, if you have a different network board, you need to enable
1023
the correct one. You can find a list of the supported network boards
1024
under the directory \texttt{grub-0.97/netboot}, into the
1025
\texttt{README.netboot} file. The GRUB developers sugget to not
1026
enable too many network cards all together for stability
1027
problems\footnote{This may be the reason because it is not safe to
1028
build a copy of the GRUB with the native support of all the available
1029
network cards.}. For the same reason, all the unused filesystems have
1030
been disabled. The above configuration assume that the GRUB files
1031
stay into a directory called \texttt{/boot/grub}, which is into an
1032
ext2/ext3 filesystem. If your \texttt{/boot/grub} directory on a
1033
filesystem of different type, you must enable the support for that
1034
specific filesystem.
1035
 
1036
After the GRUB configuration has been correctly performed, type
1037
 
1038
\begin{center}
1039
\texttt{make}
1040
\end{center}
1041
 
1042
to launch the build of the GRUB.
1043
 
1044
After the compilation, you will find two files, \texttt{stage1} and
1045
\texttt{stage2}, into two separate directories with the same name.
1046
You must copy the two files into the \texttt{/boot/grub} directory of
1047
computer B. Before copying the files, do make a backup copy of the
1048
existing \texttt{stage1} and \texttt{stage2}. This step assumes that
1049
the GRUB is already installed on computer B, which is typically done
1050
when you install Linux on a PC: we only want to enhance the GRUB to
1051
support the network boot.
1052
 
1053
Then, add the following lines to the \texttt{menu.lst} script file
1054
into the \texttt{/boot/grub} directory:
1055
 
1056
\begin{verbatim}
1057
ifconfig --address=192.168.0.2 --mask=255.255.255.0
1058
tftpserver 192.168.0.1
1059
rootnoverify (nd)
1060
kernel /shark
1061
boot
1062
\end{verbatim}
1063
 
1064
Where 192.168.0.2 is the IP address assigned to computer B and
1065
192.168.0.1 is the IP address of computer A. Change those values to
1066
accomplish with the need of your local network\footnote{For example,
1067
avoiding duplicated IP addresses.}.
1068
 
1069
Finally, reboot the machine and, at the GRUB prompt, type
1070
\texttt{c} to get the commad line of the GRUB, and type the
1071
command
1072
 
1073
\begin{center}
1074
\texttt{install (hd0,2)/boot/grub/stage1 (hd0)
1075
(hd0,2)/boot/grub/stage2 0x8000 (hd0,2)/boot/grub/menu.lst}
1076
\end{center}
1077
 
1078
This instruction install the GRUB into the Master Boot Record of your
1079
hard-disk. Typing \texttt{(hd0,2)} you specify that the
1080
\texttt{/boot/grub/} directory stays into the 3rd partition of your
1081
first hard-disk. You must change this value if the directory is into
1082
another partition or another disk\footnote{While \texttt{hd1}
1083
identifies the 2nd disk, \texttt{hd2} the 3rd, etc., \texttt{(hd0,0)}
1084
is the 1st partition of the 1st disk, \texttt{(hd0,1)} is the 2nd
1085
partition of the 1st disk and so on. This is a convention of the
1086
GRUB.}.
1087
 
1088
%------------------------------------------------------------
1089
\subsection{Executing S.Ha.R.K. application}
1090
\label{sec:execution}
1091
%------------------------------------------------------------
1092
 
1093
After the setup of the GRUB and the TFTP server, you are able to run
1094
a S.Ha.R.K. application by compiling the application and copying it
1095
into the TFTP base directory (e.g., \texttt{/tftpboot}) and calling
1096
it \texttt{shark}. This is required because, after the configuration
1097
of \texttt{menu.lst} described in Section \ref{sec:B-setup}, the GRUB
1098
will look for a Multiboot kernel named \texttt{shark}.
1099
 
1100
Every time you reboot computer B, it will automatically look for the
1101
\texttt{shark} multiboot image to run it. To speed up the GRUB
1102
operations, you should set the remote S.Ha.R.K. application execution
1103
as the default option and, optionally, do set a low number of seconds
1104
for the GRUB initial waiting time.
1105
 
1106
There are some drawbacks of the previous installation. First, the
1107
S.Ha.R.K. application name must be \texttt{shark}; you may change
1108
that name, however the point is that you must change the
1109
\texttt{menu.lst} to use different names. Second, the S.Ha.R.K.
1110
application can not use the filesystem to read and write data, so do
1111
not put any I/O command to file into an application remotely
1112
executed. Finally, the S.Ha.R.K. application can not accept command
1113
line parameters.
1114
 
1115
%------------------------------------------------------------
1116
\subsection{Accepting command line parameters}
1117
\label{sec:command-line-parameters}
1118
%------------------------------------------------------------
1119
 
1120
To make a remotely executed S.Ha.R.K. application to accept command
1121
line parameters you can exploit a feature of the GRUB which allows to
1122
remotely load a configuration file from the TFTP server.
1123
 
1124
To obtain this result, put the following instruction into the
1125
\texttt{menu.lst} file on computer B:
1126
 
1127
\begin{verbatim}
1128
ifconfig --address=192.168.0.2 --mask=255.255.255.0
1129
tftpserver 192.168.0.1
1130
rootnoverify (nd)
1131
configfile /menu-remote.lst
1132
\end{verbatim}
1133
 
1134
The last instruction tells to the GRUB to download the
1135
\texttt{menu-remote.lst} configuration file from the TFTP server.
1136
 
1137
Put a file named \texttt{menu-remote.lst} into the TFTP base
1138
directory of computer A (\texttt{/tftpboot/}). Put the following
1139
instructions unto the \texttt{menu-remote.lst}:
1140
 
1141
\begin{verbatim}
1142
kernel /shark-app param1 param2 param3
1143
boot
1144
\end{verbatim}
1145
 
1146
In this way, by editing the \texttt{menu-remote.lst} on the machine
1147
where you are developing your S.Ha.R.K. applications, you are able to
1148
change the name of the S.Ha.R.K. application that will be looked for
1149
by the GRUB. Moreover, you can use as many command line parameters as
1150
needed when the S.Ha.R.K. application starts.
1151
 
1152
\bibliographystyle{alpha}
1153
\bibliography{../common/biblio}
1154
 
1155
\end{document}