Pascal

From OSDev Wiki
Jump to: navigation, search

Contents

Historical note

The original Standard Pascal was in many ways a different language from the Object Pascal that most people today are familiar with, being much simpler but also more limited.

Dr. Wirth himself did not intend Pascal for systems programming, and his ongoing language evolution were the languages Modula-2 and Oberon. Both languages are related to Pascal in a similar way as C++, C# and Java are related to C. Oberon-2 supports all concepts of object-oriented programming. In contrast to the C language family, in the course from Pascal to Oberon the language definition got a lot more compact, but the language itself got more powerful.

The successors of Pascal were developed to address the weaknesses of Pascal in this regard. However, with the widespread adoption of the Object Pascal extensions (e.g.. unit, bitwise operators), many of these weaknesses (most specifically the lack of support for separate compilation) were eliminated. The reputation of Pascal as a toy language has unfairly persisted in many places however.

Past uses in OS development

Pascal was used in early Apple Macs as implementation language.

Oberon as a successor of Pascal has been used extensively to develop and research Operating Systems (see Native Oberon and BlueBottle).

Commonly used tools

The most popular pascal compilers today seems to be Delphi and FreePascal Compiler, and to a smaller extent Turbo Pascal.

There is a commercial (proprietary license, apparently) operating system being developed in Delphi, ClassiOS, a Windows clone, (formerly PetrOSĀ®, developed with an internal Pascal compiler) by Peter Tattam (best known for his TCP/IP stack for DOS, the Trumpet line of products). He customized Delphi to produce Windows device drivers too.

Anyway, FPC (FreePascal Compiler) seems more suited to develop a portable operating system as it's highly configurable and generates code to a great number of platforms.

Interfacing Pascal with Assembler

Just like when Doing a kernel in C++, Pascal compilers mangle functions name to make them convey more information (such as arguments and return types). That means if you just write

unit KernelMain;
 
interface
 
implementation
 
procedure kernel_main;
begin
    ...
end;
 
end.

You may end up with "THREADVARLIST_P$KERNEL_MAIN" rather than just "kernel_main" as a function name. If you're using FreePascal, the tool objdump can show you the symbol table of the .o file generated by the compiler, which will give you the "real" name of the function.

Alternatively, you could use compiler extra statements to enforce a "public name" to your function:

unit KernelMain;
 
interface
 
implementation
 
procedure kernel_main; [public, alias: 'KERNEL_MAIN'];
begin
    ...
end;
 
end.

Finally, simply declaring a program like you would when writing Pascal code for any normal platform will create a main routine named PASCALMAIN.

program Kernel;
 
uses Console,Stuff,Etc;
 
var
 stuff: type;
 
begin
{Your kernel here.}
end.

Note, too, that C and PASCAL doesn't share the same calling convention. Most notably, arguments in PASCAL are pushed from left to right while C push them from right to left. If this gets you in trouble, you can use cdecl modifier to force the compiler considering that your PASCAL procedure works like a C function (that should mainly be useful to interface pascal code with C code). Moreover, in PASCAL, the callee function is responsible from stack cleaning, while this is typically the job of the caller in C/C++ environment.

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox