New MicroKernel in FreeBasic

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
trolly
Member
Member
Posts: 52
Joined: Tue Mar 25, 2008 12:26 pm

New MicroKernel in FreeBasic

Post by trolly »

I am glad to announce you that i finaly managed to evolve my os kernel to an (almost) true MicroKernel in freebasic (yes yes):

screenshot
screenshot


* Now there is a interface API that allow the user process to handle interrupts. they tell the kernel the address of the method to call. then they should wait for an event.
* When an user handled interrupt occurs, the kernel put the request to a queue for that irq number. it will wake the owner thread up if it was waiting, (else it will left the request to the queue, and will be dequeued when the thread will be "waiting")
* When the kernel wakes the thread up, it pass the general registers to the stack of the thread, to pass them as function parameters, and changes the eip of the thread , so the method will run in the next schedule
* the user process can then do his job , and eventually modify the value of his stack (the kernel will then copy them to the "caller" thread, so he can receive returns value)

* there is also a concept of "user mode device" wich are like the interrupt handler: the thread says the kernel to create a "device" and give it an name and a descriptor (an integer wich is mainingfull only for that thread). he also give to the kernel the address of the method to call when an invoke on that device is done.
* when a process want to comunicate with the device driver, it first ask the kernel to find descriptor of the device (using its name). then it can ask the kernel to invoke the device driver by giving it the descriptor and the parameters.
* the kernel will then make the caller "waiting for reply" and wake up the device thread at the correct address

with that two concepts i managed to implement:
* user mode GUI server: it exposes it services by handling an interrupt number
* user mode driver for the keyboard and the mouse (in the GUI Server, there is 2 thread that handle the interrupt 0x20 and 0x2C to get signals from the keyboard and the mouse)

* user mode driver for the hard drive: it exposes it services using the user mode device driver interface
* user mode VFS and FAT file system: it exposes it services trought another interrupt

* Note : the kernel also provide a mechanism for the called process to map memory from/to the caller into/From his address space, in this way it can easyly copy strings (to get a button text, or a file name to open), map a buffer to the client (so he can draw on it), copy data to the client (when FileRead is called by example)

* To launch a program, the process should first load the executable into his memory, then call the kernel to create a new process using that address (the kernel will then copy it to this address space, and create a new process from it)


* i cleaned them the kernel code to remove everyting about the gui, the devices drivers, the virtual file system (and the fat file system implementation)
* the only things that remains are : the GDT initialization, the IDT initialisation, the Interrupt management , the thread management and scheduling
* the hard disk , the virtual system, and the init process are loaded by grub , and the kernel will use that to create the first processes
* to enter in graphic mode, i prepared an embedded module who is moved into the lower memory, and the kernel will use it to jump into realmode to initialize the graphic mode; this is almos the only execption to the "microkernel" structure i thing



Note: Everything is done using FreeBasic, i used my previous OS as base and made it evolved little to little to achive this. i shoud thank the creator of the Frost OS (wich is also in freebasic) from wich i took the Virtual memory management
the sources codes are on github at https://github.com/stephaneweg/onyx-kernel
thewrongchristian
Member
Member
Posts: 406
Joined: Tue Apr 03, 2018 2:44 am

Re: New MicroKernel in FreeBasic

Post by thewrongchristian »

trolly wrote:I am glad to announce you that i finaly managed to evolve my os kernel to an (almost) true MicroKernel in freebasic (yes yes):


Documentation looks a bit sparse, so I'll start you off with some potential FAQ entries. (Genuine questions):

Why FreeBASIC?

Does it confer any advantages over C/C++?

What did you find easier or more difficult compared to more traditional system implementation languages?
Ethin
Member
Member
Posts: 624
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: New MicroKernel in FreeBasic

Post by Ethin »

thewrongchristian wrote:
trolly wrote:I am glad to announce you that i finaly managed to evolve my os kernel to an (almost) true MicroKernel in freebasic (yes yes):


Documentation looks a bit sparse, so I'll start you off with some potential FAQ entries. (Genuine questions):

Why FreeBASIC?

Does it confer any advantages over C/C++?

What did you find easier or more difficult compared to more traditional system implementation languages?

I second the question of "Why FreeBasic?" From what I've seen, FreeBasic is just C with a new syntax. But I haven't used it in years so...
ArsenArsen
Posts: 9
Joined: Wed Aug 05, 2020 3:38 pm

Re: New MicroKernel in FreeBasic

Post by ArsenArsen »

I never expected to see BASIC render anything that's not squares and lines in 16 colors. Good work!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Freenode IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: New MicroKernel in FreeBasic

Post by Combuster »

Ethin wrote:I second the question of "Why FreeBasic?" From what I've seen, FreeBasic is just C with a new syntax. But I haven't used it in years so...

It's the opposite: FreeBasic is based on quickbasic (and can actually compile quickbasic with the appropriate command line flags) with the addition of pointer types, so you still get memory safety with native strings and bounds-checked arrays when you write normal BASIC code. These features obviously don't come for free, so you end up using raw pointers initially in a "c-style" kernel until at least the point where you have a working memory allocator. So of course in every FreeBasic kernel project you are going to see the awkward version of the language first, before you get to the point where you can support the standard library and go back to idiomatic code.
"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 ]
Ethin
Member
Member
Posts: 624
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: New MicroKernel in FreeBasic

Post by Ethin »

Oh, I didn't know that. I thought it was something like PureBASIC, which is essentially C with a bloated standard library and an almost non-existent community.
trolly
Member
Member
Posts: 52
Joined: Tue Mar 25, 2008 12:26 pm

Re: New MicroKernel in FreeBasic

Post by trolly »

thewrongchristian wrote:Why FreeBASIC?


Just because i like this language, i learned programing with QBASIC, in the past i did somme gui with it (look by example at http://q-step.theguiblog.com)

The toolchain was also easy to set-up in windows (it is included in the github repository)

i use also FASM for the asm part (the mutliboot header ,and the interrupts stubs)

BTW i am a c# developer, and in the past i already made a kernel in ASM and another in C .


The next step would be to port the FreeBasic Compiler to my os, but for that i have to port GCC, GAS, LD, etc....
i already ported FASM to my os
Post Reply