FreeBasic ......

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
fachamix
Posts: 21
Joined: Thu Oct 26, 2006 9:30 pm

FreeBasic ......

Post 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 ??????
fachamix
Posts: 21
Joined: Thu Oct 26, 2006 9:30 pm

.....

Post by fachamix »

anyone know if somebody is doing a OS with FreeBasic at least?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Re: .....

Post by Alboin »

fachamix wrote:anyone know if somebody is doing a OS with FreeBasic at least?
Combuster...
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: .....

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply