Page 1 of 1

FreeBasic ......

Posted: Fri Jun 15, 2007 12:53 pm
by fachamix
I want to make an educational OS.

I have a doubt, at least is something i cant understand.

with nasm and C, i used to assembler in aout format, make a start.o (asm, ntry point of my OS) and the rest of the kernel in C (.o format), after that use the ld linker like this (or somthng like that) ld -o kernel.bin start.o kernel.o ,........

But FreeBasic drops me the executable, or the OBJ!!!!!!!!

can i deal with the OBJ file with ld linker ? If i can, what steps should i follow to make a hello wolrd example??? what should be the command line secuence ??????

.....

Posted: Fri Jun 15, 2007 12:56 pm
by fachamix
anyone know if somebody is doing a OS with FreeBasic at least?

Re: .....

Posted: Fri Jun 15, 2007 12:59 pm
by Alboin
fachamix wrote:anyone know if somebody is doing a OS with FreeBasic at least?
Combuster...

Re: .....

Posted: Fri Jun 15, 2007 4:16 pm
by Combuster
Alboin wrote:
fachamix wrote:anyone know if somebody is doing a OS with FreeBasic at least?
Combuster...
Sure

Well, there is quite some stuff going on below the hood when using FreeBasic as your compiler. I don't use it for the actual kernel, but rather for the drivers.
Most of the Basic language comes from the basic runtime. Without it you have serious feature problems unless you want to sortof program C with a different syntax. You can only use register primitives (integer, long, byte, and pointers) and basic control flow. Declaring global variables already drags in runtime references. Forget about arrays and strings without the runtime that comes with it.

You can quickly hack together a runtime that supports globals, which you'll need when you want to write a kernel.

So far the discouragement, now for the tutorial part:

Build a GCC Cross-Compiler.
Create a copy of your freebasic installation.
Replace the binutils bundled with freebasic with those built with the crosscompiler (keep the executable names the same)
If you are using windows you can put them in a separate directory and use the -target parameter to select which set of binutils to use.

Now you have everything needed:
use i586-elf-gcc as the c compiler
use i586-elf-ld as the linker
use fbc (fbc -target xxxxx if you didn't overwrite the default binaries) as the basic compiler
use i586-elf-as or direct your assembler to create ELF object files.

next, you can copy the code from Bare_bones and compile that.
If you want to use basic instead of c, try something like the following (*NOT* tested)

Code: Select all

Public Sub ModMain Cdecl Alias "main" ()
    Dim vram as Byte Ptr

    vaddress = CPtr(Byte Ptr, &HB8000)
    vaddress[0] = &H48
    vaddress[1] = 15
    vaddress[2] = &H49
    vaddress[3] = 15

    While 1 = 1

    Wend

End Sub
Compile this using either
fbc -c -nodeflibs main.bas -o main.o
fbc -c -nodeflibs -target linux main.bas -o main.o
depending on the setup

Once you get further, you should compile a libc, then compile libfb and libfbx to get the runtime working. You'll need to have startup code that calls constructors and destructors.
You can compile only parts of libc/libfb if your system doesn't support a full libc yet to use some useful functionality. if you have ctype+string+stdlib+malloc you can compile the parts of the basic runtime that allow you to use arrays and strings.

If you have any questions, just fire away.

If there is more interest, I'll see if I can find time to write a freebasic setup+barebones tutorial for the wiki.