Omnimaga

Calculator Community => Casio Calculators => Topic started by: Kristaba on January 20, 2014, 12:42:40 pm

Title: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on January 20, 2014, 12:42:40 pm
Welcome back, Omnimaga!

I'm working on a litle project from a long time ago (but as I have to deal with IRL and my personal motivation, the project progress a bit randomly ;)), but I only released informations about it on Planète Casio forum.
Now, it's enought mature to begin to introduce this project on other communities, I think.

So I will not say here all I said on french Planète Casio topic, but I will try to summarize main informations, and of course to reply to any question if something is not clear.


FiXos is a kernel, writen from scratch to work on fx9860 and similar calculators. I would like to support all the SH3/SH4 models, but for now I prefer to fully support the only test model I have (fx9860G SD).
It's a UNIX-like kernel, which will try to support most important UNIX paradigms (device management, VFS, main syscalls...), but the goal is not to be 100% compatible with any POSIX version, only to be enought close for main usages.
Once the kernel is running, no more part of the Casio's OS is executed, and the kernel is fully independant of any other software.

For now, the kernel is never executed from the EEPROM directly!
It will not replace Casio's OS definitively, and it is copied on RAM before to be executed. So a simple reset of the calculator will allow to return to Casio's OS.
Later, it may be interesting to write it on a part of the EEPROM (to avoid heavy RAM usage before any user code is running), and maybe to redirect the Calculator reset code to the bootloader, to choose on which one to boot after a reset. But for now it's too much dangerous for nothing, so RAM is our best friend! ;D


From few days ago, the project includes an independant bootloader, which take the form of a G1A file. It has its own code to access efficiently to the SMEM filesystem, and use Casio's OS "syscalls" to display a menu. The whole bootloader is configurable using a config file, to change global properties (default selected entry, quiet mode or interactive mode), and individual entries content (kernel file, kernel arguments, type).
This booloader is able to prepare and run any ELF file, so the kernel is an ELF binary (with minimum informations to keep a small binary).

All the kernel, userspace tools and the bootloader are designed to be compiled by GCC toolchain for SuperH processors. It's also why the ELF file format was chosen : it's a very powerful binary format, and is now used on almost all UNIX-like and other OS. Any modern compiler (so, not the Renesas one...) is able to output ELF binary.


The kernel itself is still young, but begins to be interesting and partialy usable.
It takes advantage of the modernity of the SuperH processor, with virtual memory, separation of adress spaces between processes, and all embeded modules like SDHI for controling SD Card, USB device controler...

Main features for now are :

If you want just to take a look on a user program code, you can read user/first_test_elf.c (https://www.gitorious.org/fixos/fixos/source/7eb91d5ceb15c063eb4b116b9bfe18bca2643fb8:user/first_test_elf.c). Of course, it's a file used for testing purpose, so do not try to look for a concrete goal in this program. ;D


The project is hosted on Gitorious (https://www.gitorious.org/fixos (https://www.gitorious.org/fixos) for the project and https://www.gitorious.org/fixos/fixos (https://www.gitorious.org/fixos/fixos) for the main repository).
Of course, it's an open source project, anybody who would like to take a look to the code, to modify it for educationnal and curiosity purpose, or to contribute to the project is welcome.
(about it, sory for two things :
- my english mistakes in my messages and in my code or comments, I probably do a lot of stupid grammar mistakes, especialy in old comments)
- the quality of the kernel code is not always as clean as I would like to, sometimes I do some black magic usage, or quick implementation of something, before to clean the code later when I have a better idea or I am motivated again. So I try to maintain beautiful and clean code, but it's possible for you to burn your eyes when reading some functions and tricks used :ninja: )

I probably forgot some things, so if you have any question, I will modify this post if the reply is relevant to take place in this introduction.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on January 20, 2014, 12:43:58 pm
Oh sh*t, you're alive! WHat's up pal! It's been a very long time! Welcome back in our community!

And now, if you're wiling to provide some infos about configure GCC to compile for our cute blue calcs, I'm back on Casio C. (oh, and ping me on Skype sometimes, I'd love to talk about that!)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: flyingfisch on January 20, 2014, 12:47:47 pm
Wow, I have been wondering what happened to this project.

Do you think it could be easily ported to PRIZM? (Especially since it appears there are hardly any graphics functions yet)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on January 20, 2014, 01:05:16 pm
Do you think it could be easily ported to PRIZM? (Especially since it appears there are hardly any graphics functions yet)

I added some informations about that in README (https://www.gitorious.org/fixos/fixos/source/7eb91d5ceb15c063eb4b116b9bfe18bca2643fb8:README) of the project, but in some words, it seems not so difficult to port it on Prizm (excepted for not documented at all parts, like filesystem, SD card...). I have no Prizm to work on that, and I don't remember exactly what is known or not about it's CPU.
If the documentation of the closest generic processor is correct for MMU, exception and interrupt handling, and some other registers, I think 80% of the job will be to write the CPU register definition header, and to change some constants values.
But if even for low-level things we have to deal with reverse engineering because of undocumented informations, it will be, of course, more difficult...

The arch-specific code is sometime used directly in generic code, so some changes have to be done before any portage, but if its targeting an other SuperH CPU it will not be a heavy task, I think/hope.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on January 20, 2014, 01:25:58 pm
DO you have any explanations for using GCC on Windows? I'm trying to compile GCC for sh3-elf target, but it's not the domain I'm at my best.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Sorunome on January 20, 2014, 02:32:05 pm
Wow, this sounds pretty awesome!
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on February 05, 2014, 06:10:45 pm
Nice to see you still active in the Casio community. This project seems interesting,although I would probably not use it much, since I am not familiar with Linux-like stuff and mainly use my calc for games, but I hope this eventually come to fruition. Linux is now available on the TI-Nspire (although not installable as main OS) and some people managed to browse internet from it (while the calc is connected to an USB dongle)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on February 06, 2014, 01:11:47 pm
It's not really Linux at the moment, it's an Unix-like kernel germ. THe terminal just takes input, no shell is done. I'll try to manage to code for this project. Do you have some tasks I could do Kris?
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on February 06, 2014, 03:20:15 pm
DO you have any explanations for using GCC on Windows? I'm trying to compile GCC for sh3-elf target, but it's not the domain I'm at my best.
Sorry for the delay, but in my case I am not familiar with MS Windows, so I can't help you a lot.
I think the best idea is to cross-build GCC from Linux (even using a VM only for that), or with a full Cygwin install. If I have some time I'll try to build latest GCC toolchain (binutils and GCC binaries, libraries are not needed, even libc), but I think there are some binaries available somewhere, used for some Prizm toolchain, and should be able to build for SH3 big endian target.

Nice to see you still active in the Casio community. This project seems interesting,although I would probably not use it much, since I am not familiar with Linux-like stuff and mainly use my calc for games, but I hope this eventually come to fruition. Linux is now available on the TI-Nspire (although not installable as main OS) and some people managed to browse internet from it (while the calc is connected to an USB dongle)
Nice to see you still active in both communities too ;)

To make things clear, this project is far far away to be considered as a Linux-like. Even if I finish everything I would like to do, it will probably be closed to the 1990's System V than to a modern Linux or BSD ;D
TI-Nspire has a lot of ressources availables compared to fx9860 (Prizm is more interesting, but still realy light to imagine a Linux running on it).
For example, in TI89-titanium and TI-Nspire, there is a USB "on-the-go" controler, allowing to act as a usual computer with USB devices (Keyboard, WiFi dongle, USB pen or HDD...). On Casio's calculators, it's only the device part of the USB which is available (so the calculator may act as a USB device, but there is no way for it to deal with other devices, and for exemple it's not possible to use WiFi dongle to give internet capabilities).

In the other hand, as everything is written from scratch, it's not impossible to design some part of the kernel to allow games to run at a correct speed.
It's not my main goal, of course, but basicaly what is needed is a near-realtime scheduler (or a "single process" mode to avoid useless context-switches), and some realy specific device drivers to have a fast access to display rendering and keyboard input.
And a good kernel can allow game developpers to have better (and more reliable...) bases to code their software. Imagine at least a good filesystem access, memory swaping to allow to use more memory than available RAM (even if in theory, swaping in EEPROM is either fast nor a good idea for EEPROM lifetime  :ninja:).
In addition, something I realy want to do in a near future is shared library support, which can be also realy useful for games (lighter executables and possibility to update/fix libraries without compiling again).

Do you have some tasks I could do Kris?
It's not easy to say you a precise thing to do, mainly because I have no precise plan myself x.x
If you want to do some kernel functionalities, first try to read some piece of existing code to check a bit how the kernel is designed. After that, you can contact me using mail/pm, to find a better way to discuss a bit (irc, skype or something else).
A possible task should be to implement a serial device driver (using the real USART, not the USB emulating a serial device ^^).
It will be useful to both kernel (serial debugging) and user space (calc-to-calc comunication), and is a task which need to use the CPU's documentation, some plateform-specific code, and a device driver. So it's probably a good exercice to begin kernel programming  :D



Now, about the project advancement, I had not a lot of free time, but I did some important things last days.
In a first time, a realy better keyboard handling. Before there were only some functions inherited from my old projects, like is_key_down(), and was only used for debuging purpose.
Now there is a real implementation of keyboard, with 3 abstraction layers. The first is the 'keymatrix" level, to check the state of physical keys, and interpret state changes as keyboard pressed/released. These informations are used by the logical-keyboard layer, able to handle key modifiers (SHIFT/ALHPA and later a character case modifier), and when I will have the time to implement it, the key repetition parameters. Finaly, the higher layer is implemented in the /dev/console driver, to act as standard input stream (with DEL used as backspace for corrections).
The keyboard state is updated with a 64Hz interrupt, and later will use some pin state detection interrupt to minimize overhead when no key are pressed, but because of hardware configuration there is no "perfect way" to handle each key press/release whithout some timer interrupt usage.
Everything is not finished, but now there is a correct stdin for interractive user process. I will have to add ioctls to be able to change the input properties (at least ICANON and a raw mode, which are realy needed for ncurses-like usage).

In a second time, the first partialy working implementation of exec-like syscall (execve), one of the most important syscall on a UNIX-like system.
So it's now possible to begin to write some useful userland software (a bash-like use mainly fork/exec, as well as a userspace init program).
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on February 06, 2014, 05:15:17 pm
I'm thinking about a GUI interface, but, well, it's too early to test things like this! XD

I saw some typos here and there, I'll make you a correction.

I'm plannning so to implement UART driver as long as I get a sh3-GCC here. Thanks for the suggestion.

Another suggestion : port ML in ASM. That would be very useful as a library.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on February 06, 2014, 08:05:59 pm
Thanks for the clarifications. :) And yeah I could understand why Linux would be hard to run on a Casio calc. I am curious if it would work on the SD models, but I don't even know if they're still in production and even if they are, having Linux only on  the SD models would cause the userbase to be so incredibly small compared to the TI-Nspire.
Title: Re: AW: FiXos, a UNIX-like kernel for fx9860
Post by: naib864 on February 07, 2014, 06:41:13 am
Sounds really awesome :) I hope we can test it soon ;)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Siapran on February 07, 2014, 07:57:20 am
might be out of topic, but can anyone tell me where I can find the said GCC toolchain to biuld .g1a executables?
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: shinolife63 on March 21, 2014, 06:35:22 pm
might be out of topic, but can anyone tell me where I can find the said GCC toolchain to biuld .g1a executables?
I would like to know this as well
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on March 23, 2014, 12:51:00 pm
Same for me.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on June 21, 2014, 02:32:14 pm
might be out of topic, but can anyone tell me where I can find the said GCC toolchain to biuld .g1a executables?

It's late to reply, but if anybody would like to have a sh3 GCC toolchain, as the SuperH architecture is not so common, the better way is to compile yourself GCC from sources. To avoid having to understand every details on GCC configuration, you can compile it through crosstool-NG (http://crosstool-ng.org/ (http://crosstool-ng.org/)).
The only other tool than GCC binaries themself you need is a G1A wrapper tool, and you will be able to create G1A from a GCC toolchain ;)


About the FiXos, as usual with me, I stopped a time, and I'm working again on it from one or two months.
The kernel like more and more to a usable UNIX kernel, the main changes from the last time I posted here are :

I think it's more or less all the important changes. If you were patient enough to read all of them, you can figure the kernel is now close to be mature to support a consequent user space, but some crutial things still missing.
The memory management is not enough powerful and will need big improvements (to support Copy-On-Write, shared area of memory, memory mapped files with mmap() syscall...).
The other really missing feature remains the shared library support. I know on some platforms it is done in user space (using mmap() and oter stuff), but I still plan to implement it in kernel space, maybe with a couple of non-POSIX syscalls.


Finaly, userland need a working libc, even before dynamic libraries implementation, in order to be really usable. Playing with syscalls is fun, but a libc is more efficient to make real programs...  [-.-]~
I'm considering to port Newlib for FiXos (Newlib is already working fine on SuperH bare-metal target, and is relatively easy to port on a new platform). I tried some month ago, but there was a problem with Newlib usage of automake, which is fixed now I hope...


I don't know if I will be active on this project during the summer, but I'll let you know if any progress is done.
And of course, if some experimented programmers are interested for working on FiXos, there is probably tons of things to do or to improve. I'm still interested to work on a port of FiXos for any other platform (Prizm or other SH4-based casio calculators, maybe m68k TI calc like TI-89, or even a x86/PC port could be fun ^^), because it will force a good kernel design to be able to separate arch/platform specific code from generic kernel code, and in the same time a portage often highlights hidden bug in a software.  ;)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on June 21, 2014, 03:03:37 pm
I'd be glad to help this summer, but it'll need for me to read a lot of docs, I never touched a *nix kernel, so...
But, if you can give me pointers, I'd help to port to Prizm! :p
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Streetwalrus on June 21, 2014, 03:16:07 pm
Sorry I tl;dr'd the thread but I guess this is like KnightOS for the (more powerful) Casio calcs ?
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on June 21, 2014, 09:55:24 pm
Just make sure that the OS plays nice with the calculator hardware, because with certain PRIZM add-ins, if you run OS 2.0 and do certain things with your calc, you can permanently brick it. (there's a topic about this on Cemetech with more details)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on June 22, 2014, 01:49:50 pm
Sorry I tl;dr'd the thread but I guess this is like KnightOS for the (more powerful) Casio calcs ?

In fact, for now, the name of the project is a lie (FiXos is only a kernel currently, but it should become more or less a "full" operating system someday). So it should look like KnightOS, but more focused on a "powerful" kernel, because the targeted CPU is far more complex (MMU, USB controler, SD Card, and dozen of other on-chip peripherals) and hardware is enough powerful to support a bit heavier kernel.

Just make sure that the OS plays nice with the calculator hardware, because with certain PRIZM add-ins, if you run OS 2.0 and do certain things with your calc, you can permanently brick it. (there's a topic about this on Cemetech with more details)

I read this topic, and unfortunately with the Casio boot design, with everything on the same EEPROM, I imagine there is small chance to brick the calculator when rebooting at the (very) worst time of an EEPROM write/erase operation.
For now I try to avoid playing too much with EEPROM, it will be necessary, but I prefer to have a stable kernel before to do that.
Of course, I'll do the best to avoid any problems, especially on other calcs than my ones (in fact I'm surprised to never broke my calc as I ran thousand times my kernel to debug it, with really not stables things sometimes), but I can't be 100% sure that will never happen (as Casio themselves apparently failed...).
Only thing I can say is that a buggy free software have a chance to be fixed if a such a thing ever happen, and a protected-mode kernel which run user applications in user-mode limits the possibles location of a such issue ;)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Streetwalrus on June 23, 2014, 03:56:40 am
Yeah I figured these calculators stand closer to the 68k line than to the z80 line in comparison. But the goal is still the same : a UNIX-ish OS for calculators.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on June 23, 2014, 02:42:20 pm
It's a shame that the PRIZM and 9860G don't use ARM processors, because it would have made it much easier to port TI-Nspire stuff to it. The HP Prime uses ARM too (although there isn't any real doc on how to create a third-party firmware for it nor a mod of the existing ones to allow ARM assembly and C).
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Streetwalrus on June 23, 2014, 05:48:46 pm
Well on the bright side they have a good c compiler so it makes the non asm stuff portable. All the HW is incompatible across the HP, Nspire and Casio calcs though.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on July 03, 2014, 08:41:31 am
I spend several days to write many proof-of-concepts around FiXos, and I finally added some intersting things to the kernel  ;)

First of all, a lot of work was done on dynamic libraries!
After some reflexion and studying existing implementations on several platforms and OS, I decided to implement shared object stuff in kernel. In most modern OS (linux for example), dynamic linker is a userland tool, and the kernel is agnostic about any dynamic linking.
As FiXos kernel already have some ELF facilities, it seemed easier and lighter to have a kernel-part implementation (so userland is simpler to understand and to maintain). I also implemented it in a way it's still possible to write a full userland dynamic linker, without breaking the kernel implementation (and it's even possible to disable any kernel dynamic linker related stuff at build time with a config option ^^).

The main problem I faced was than dynamic linking is deeply dependant of the toolchain target arch/OS, and the one I used is configured to target sh3 arch without operating system (and it makes no sense to support dynamic linking for unexisting OS).
So, the two choices I had were to do some changes in GCC's sources to target my OS, or to cheat a bit in order to make a part of the normal linker job "by hand". As changes in GCC is not a good idea for now (a lot of time waste to maintain and distribute it...), I did the second choice.
Mainly, to build a shared library for FiXos, the following is done (and automatized by some shell scripts and Makefile itself) :
When a program should use a dynamic library, you just have to link it with the corresponding stubs library, and to call the functions exactly as there were normal, local ones.
The first time a dynamic-linked function is called (which, in fact, call the corresponding stub code), some complex job is done, including a specific system call to find the corresponding symbol by its name.
Then, all subsequent calls will be faster by using the cached value of this symbol (in fact the overhead is only 4 instructions, so it should not be a problem for performances).

The kernel ELF loader will only care about a special segment of the ELF (the one of type PT_SHLIB, defined by ELF specification but with no predefined semantics). It expects to find a list of zero-terminated strings, each one corresponding to the shared object name (the library name, with no path). For each name, it will try to find and load the content of the shared object. Once loaded to an arbitrary not used address range, the kernel try to "relocate" it (a vector of absolute-based addresses is located, and each element is incremented by the base address where the code was loaded).
Please note this segment is populated automaticaly (when at least one of the stubs for a given library is used, the library name is added to this section).

I'll have to write some documentation about all that in the project source tree, because it involves many complex things, and it's possible that my implementation fail for complex patterns.
In addition, it's only an early implementation (the shared memory is not implemented, only one library may be linked to a process...), but the more difficult part is done and seems to work fine for now!


An other cool thing added is a more powerful post-mortem debug information display.
A new function, kdebug_oops(), may be used when the kernel reaches an abnormal state (to not say "crash"  [-.-]~ ), which should display every potentially useful information (some CPU registers, current process related stuff like a memory map, and a call trace of the kernel stack).
   Unfortunately, SH3 calling convention does not allow a very good call trace without a lot of additional information (more or less all the "unwind" data needed for C++ exception handling...), so the current code only display the "guessed" calls, and may repport some false-positive :/

Even if it's usefull to have addresses of caller functions, having their names allow to don't spend much time to find it by looking at the disassembly dump of the kernel. So a bit tricky mechanism may be triggered by the config option CONFIG_DEBUG_SYMBOL_NAMES to extract all symbols located in ".text" section, and to include a table for "begin address" <-> "symbol name" conversion (it is possible to keep symbol names in ELF, but it takes more memory and its more difficult to read...).
Finally, this configuration option takes many space (currently around 30% of the kernel size...), but leads to a more understandable call traces, and so should be used for kernel development.

To make this more visual, here is an example of displayed message when an unaligned data is accessed in kernel mode :
Code: [Select]
> Address : 0x3FFFFFF3
> SPC Value = 0x880025F6
Fatal kernel oops!
(CPU Access Violation (R/W))
Following informations may help :
Running pid 1 (asid=0)
Memory Map :
DIR(0x10000000~0x10008000):
  vvuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
DIR(0x3FFF8000~0x40000000):
  uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuv
(End of Memory Map)
Stack=0x880126F0
Call trace:
@0x880126F4: <_exception_handler + 272> (0x88008AC0)
@0x880126F8: <_printk + 0> (0x88006E78)
@0x88012708: <infloop + 0> (0x8800896A)
@0x88012710: <_sys_ioctl + 0> (0x88005DD8)
@0x88012714: <_interrupt_inhibit_all + 0> (0x88008680)
@0x8801271C: <_exception_handler + 0> (0x880089B0)
(End of call trace)

---- Previous Context ----
       PC: <_display_ioctl + 58> (0x880025F6)
       PR: <_exception_handler + 192> (0x88008A70)
Stack=0x8801277C
Call trace:
@0x88012780: <_exception_handler + 192> (0x88008A70)
@0x8801278C: <infloop + 0> (0x8800896A)
@0x880127A0: <_exception_handler + 0> (0x880089B0)
(End of call trace)

Of course, without knowing the kernel internals it's difficult to interpret, but in this case, the error was located in _display_ioctl(), itself called by _exception_handler(), which is displayed in the second context info.


Now, I try to add the needed syscalls to allow a fully functionnal port of Newlib.
Some work is done, and it is still possible to build Newlib for sh3-unknown-fixos target, but without a working sbrk() syscall, malloc() can't work and a large part of Newlib depends on it.
The last syscalls really needed are sbrk() and stat(), the others are either not essential for the most part of the library (symlink(), unlink(), chown()...) or implemented by using other syscalls (isatty() may be replaced by some ioctl() calls or fstat()).
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: ProgrammerNerd on July 03, 2014, 10:19:03 am
Wow the feature lists sound very existing. Very nice work.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: bb010g on July 03, 2014, 04:02:42 pm
Awesome. :D
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: aeTIos on July 04, 2014, 01:42:17 am
So many TL;DR posts so I skipped the thread :trollface:
Anyway this looks prettty interesting, definitely keeping an eye on this thread even though I don't have a fx9860.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on July 08, 2014, 08:32:22 am
Is there any functions done to start a shell? I could do one if you want!


EDIT : FXShell (consider that name already taken, guys)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Kristaba on July 27, 2014, 05:50:41 pm
Once again, some news of the kernel advancement ;)
Of course, the summer is not the better time to code everyday, but since my laptop has a great backlight, I can even enjoy the sun and write code at the same time!  [-.-]~

Main new features are :

Newlib should now be more or less functionnal now, I did some tests recently (mainly for malloc() and date/time related functions) and its working fine. I will try to make a new repository for the Newlib port, but in the same time I think Newlib is a good temporary solution (probably the fastest way to have a working libc/libm on any new system/architecture!), but it should be more interesting in the medium/long run to use Newlib sources but with a lot of custom changes in a lot of files.
As Newlib is designed to separate platform-specific code, and to never deal directly with the generic implementation, its probably better to don't keep the Newlib build system if changes are too much importants...


Some week ago, I tried to port a game from PierrotLL on FiXos (gravity duck for fx9860), mainly to see how difficult it is and to discover potential issues in the case of a "real-time" interactive application.
So I ported MonochromeLib in a first time (using the /dev/display device, for direct rendering), which work as well as a static library and as a dynamic library with acceptable performances (around 500 FPS for overwriting the whole screen and display it).
In a second time, some changes were needed in GravityDuck code itself for replacing Casio OS functions used (GetKey(), IsKeyDown() and some functions related to ticks ellapsed to limitate the frame rate). An other function (PrintMini()) was simply removed (a similar function should be added to MonochromeLib), but it is not a big deal as Gravity Duck do not use a lot of text... As the game makes use of malloc(), I also linked the Newlib libc, but I think it is the only libc function used.

The final result is really encouraging, the game run at normal speed, and everything seems to work as the original version!  :P


I didn't released the ported Gravity Duck for now because I did it for testing purpose, and everything is not really clean, but I will try to do that in order to show than it is still possible and relatively easy to write real applications for FiXos (less than a day for porting MonochromeLib and Gravity Duck, and less issue than I feared).


Is there any functions done to start a shell? I could do one if you want!
I think more or less everything needed is working, if you want to do that, but you will really need a libc if you want to have some helper functions, else you will have to deal only with syscalls.
Two things missing for a such project are the current/working directory (for now processes are not associated to a working directory, and every path need to be absolute for open(), stat() and similar syscalls), and maybe some ioctls and VT100-like escape codes for the TTYs. I will also need to implement process groups, sessions and controling terminal for a better UNIX concept support.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on July 27, 2014, 10:59:33 pm
Good to hear that you managed to run a Casio OS game into FiXos. It's a good step in the right direction for people interested in this OS who might still want to play older games like this. :)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on August 02, 2014, 05:22:05 am
OK I'm officially on the project. Let's see if I can make something like a shell..

EDIT : stupid echo routine
Code: [Select]
static void test_echo(int fdin, int fdout) {
char buffer[33];
ssize_t result = 0;
int index = 0;
char current_char;
while(1){
read(fdin, &current_char, 1);
buffer[index++] = current_char;
if(current_char == '\n' || index == 32) {
result = write(fdout, buffer, index);
if(result != index)
break;
index = 0;
}
}
}
I think I should find a way to cleanly read a whole line of text.
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on October 01, 2014, 02:41:26 pm
I'm on the rails again as a side side project. I started to parse arguments given from a command line to train my UNIX programming skills. That'll come quite handy for the minishell project i plan to do.

Here's the code atm for anyone who wants to dig into (only for PC as test, I haven't ported it to FiXOS, but that should be easy) :
Code: [Select]
#define _GNU_SOURCE
#include <unistd.h>
#include <string.h>
#define BUFFER_LENGTH 128
#define COMMAND_LIST_SIZE 8
#define COMMAND_SIZE 32

void next_command(char* current_command, int* current_command_index, int* command_index) {
current_command[*current_command_index] = '\0';
*current_command_index = 0;
*command_index += 1;
}

void parse_command(char* buffer, char command_list[COMMAND_LIST_SIZE][COMMAND_SIZE], int buffer_index) {
int command_index = 0;
int current_command_index = 0;
char in_quotes = 0;
char in_double_quotes = 0;
char c;
int i;
for(i = 0; i < buffer_index; i++) {
char *current_command = command_list[command_index];
c = buffer[i];

if(in_quotes) {
if(c == '\'') {
in_quotes = 0;
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}
else if(in_double_quotes) {
if(c == '"') {
in_double_quotes = 0;
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}
else {
if(c == '"' || c == '\'') {
if(current_command_index > 0) {
next_command(current_command, &current_command_index, &command_index);
}
if(c == '"')
in_double_quotes = 1;
else
in_quotes = 1;
}
else if(c == ' ' && current_command_index > 0) {
next_command(current_command, &current_command_index, &command_index);
}
else {
current_command[current_command_index] = c;
current_command_index++;
}
}

}
next_command(command_list[command_index], &current_command_index, &command_index);

for(i = 0; i < command_index; i++) {
write(1, "=>{", 3);
write(1, &command_list[i], strlen(command_list[i]));
write(1, "}\n", 2);
}
}

int main()
{
char c;
int buffer_index = 0;
char buffer[BUFFER_LENGTH + 1];
char command_list[COMMAND_LIST_SIZE][COMMAND_SIZE];

while(1) {
read(0, &c, 1);
if(c == '\n') {
// TODO : manage command
parse_command(buffer, command_list, buffer_index);
buffer_index = 0;
}
else if(buffer_index <= BUFFER_LENGTH) {
buffer[buffer_index++] = c;
}
}
return 0;
}
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: DJ Omnimaga on October 01, 2014, 03:40:42 pm
Good to hear it's still progressing :)
Title: Re: FiXos, a UNIX-like kernel for fx9860
Post by: Eiyeron on October 02, 2014, 09:18:39 am
(http://2.bp.blogspot.com/-s5AEA51c1jw/UfW-_UOaogI/AAAAAAAABwA/kyCLrDHJuvM/s1600/futurama-good-news-everyone.gif)
My shell project seems to work. Seems because I don't know if it actually tries to open anything but I get the reply when the program execution failed, so I consider my fork/exec/wait routine working!