FreeBASIC
FreeBASIC is the name of a modern Basic language variant, as well as the corresponding compiler. Whereas classic Basic can not do native OS development, Freebasic comes with lots of features useful for OS Development.
Overview
Apart from being mostly QuickBasic compatible, it offers the following useful features:
- Unsigned data types
- Inline assembly
- Pointers
- Callbacks
- A portable runtime.
The major downside is that most of the BASIC-specific instructions require the runtime which can not be easily used in an freestanding environment. The consequence is that several typical BASIC constructs can not be used until runtime support is included, making development very tricky.
Usage
FreeBASIC has a command line syntax similar to that of GCC:
fbc -c -o kernel.o kernel.bas
to link the output:
ld -T script.ld -o kernel.bin kernel.o
To get a running start, there is a FreeBasic Bare Bones tutorial that ends in a working "hello world" kernel.
Runtime Library
In an freestanding environment, the runtime is unavailable. Programmers should take care not to use any of the following:
- Strings
- Dynamic arrays (only local, fixed-size arrays are allowed)
- Globals of any kind. All information must be passed in arguments.
- All non-primitive built-in functions, i.e. anything more complex than + - * / and the logic operators.
- IO functions, including port outs and ins, peek and poke.
You'll need to provide a runtime init to allow the use of globals, you'll need a malloc() to get strings and arrays working (the rest of the dependencies are cross-platform ctype+stdlib functions and don't pose much of a problem).
If you sit down and think about it, writing a kernel in C, and writing the same thing in FreeBASIC is just about the same. Of course, there's that huge language difference, what with FreeBASIC's syntax resembling English a little more than C...but to do anything useful, both strategies need a C runtime and library. With the FB kernel, after you've managed to port a C library, you could think about porting the FB runtime on top. What's more, FB can link into existing C libraries, so porting a C library isn't a pain.
See Also
Articles
- FreeBasic Bare Bones tutorial
- Alternative Languages in general.
External Links
- FreeBasic homepage
- The FreeBasic Manual
- FreeBASIC tutorial: syntax highlighting in gedit