A Linux-like Propeller OS -- pfth 1.00 with SDcard
LoopyByteloose
Posts: 12,537
From time-to-time, we get inquiries from new people about Linux on the Propeller. I generally have tried to stay out of these discussions as Linux really is a multi-user OS with a file system that supports a vast array of services.
For me, the Propeller is a cosy, one-user device that is better suited for MS-DOS or CPM. And yet, I really would like the Unix utilities that Linux provides
~~~~~~~~~~~
So I was recently surprised when Dave Hein included a file called Linux.fth in his pfth v. 1.00 release.
Actually it is a set of file management words that are cloned from LInux - cat, ls, rm, and so on. He also included a line text editor called Ted.
I loaded all this into an SDcard and am using it with my Propeller Demo Board and it holds up very well as simple, but useful OS. In fact, with all the .fth files that one can INCLUDE and later remove, he has a growing library of Forth software that can be nicely stored on the SDcard and it feels "Linux-like".
++++++++++++++
Personally, I don't think that in many cases the users that have requested Linux on the Propeller would be offended by this "Linux-like" alternative. After all, if you can keep extending utilities and libraries on an SDcard, it all begins to feel very much like a nice little personal computing system.
Right now, I am trying to finish up an Real Time Clock module for it and enjoying using Ted to edit the code in development and the file system for storing all the .fth modules and the .txt files of documentation.
For me, the Propeller is a cosy, one-user device that is better suited for MS-DOS or CPM. And yet, I really would like the Unix utilities that Linux provides
~~~~~~~~~~~
So I was recently surprised when Dave Hein included a file called Linux.fth in his pfth v. 1.00 release.
Actually it is a set of file management words that are cloned from LInux - cat, ls, rm, and so on. He also included a line text editor called Ted.
I loaded all this into an SDcard and am using it with my Propeller Demo Board and it holds up very well as simple, but useful OS. In fact, with all the .fth files that one can INCLUDE and later remove, he has a growing library of Forth software that can be nicely stored on the SDcard and it feels "Linux-like".
++++++++++++++
Personally, I don't think that in many cases the users that have requested Linux on the Propeller would be offended by this "Linux-like" alternative. After all, if you can keep extending utilities and libraries on an SDcard, it all begins to feel very much like a nice little personal computing system.
Right now, I am trying to finish up an Real Time Clock module for it and enjoying using Ted to edit the code in development and the file system for storing all the .fth modules and the .txt files of documentation.
Comments
I'm currently working on making pfth run under spinix. spinix provides more of a Linux-like environment than pfth. Some of the code development I'm doing is being done on the Prop under spinix. I edit Forth programs using vi, and then run them in pfth. The Linux.fth words make switching back-and-forth between spinix and pfth a little easier.
Thanks for posting that info. You've inspired me to give it a try.
@Dave Hein
I like your approach to this. Familiar commands regardless of what's under the hood makes changing or upgrading so much simpler. I always hated moving to the next version of Windows and having to learn a whole new way of doing the same old things I did in the previous version. I don't think it's that I'm resistant to change, it's more an aversion to change for the sake of change. I'm quite happy to dig in and learn about the new and improved.
If another user really desires DOS or CPM file commands, another .fth file can provide that lexicon for the user's comfort.
Providing cat really makes reading short files quite painless.
In this case, pfth reached a critical mass of usefullness by providing the SDcard with a text editor and going with Linux/Unix terms to manage file manipulation.
Forth can even go further with other lexicon extensions. And these don't have to linger around when not used. pfth allows sets of words to sit in a .fth file to be installed for a specific task or work session, and then removed with a Forget so that the space is available for other tasks or work sessions.
Early on, I built a dumb terminal with a Propeller Proto Board in anticipation of having Forth on several other boards that I could develop as separate projects. It all now seems easy.
I peeked in on the Propeller2 discussion and they seem to be worried about SDcard code being ready for deployment in GCC at this point. But from what I understand, all the various Forths on Propeller are pretty much just waiting for the Propeller2 to be available. If that means they allow the SDcard to be up and running right away, this is even more attractive.
I do have my one little .fth file called BS2_io.fth that allows me to designate i/o by pin number and to use High, Low, Input, and Output in coding. This is so much more user-friendly than other alternatives. It is just another example of how Forth can adopt a lexicon that the user is familiar with rather than impose learning a whole new way.
I am having lots of fun with Forth. Above all, it allows me to explore and confirm interactively. That cuts through a lot of very dry documentation.
If you noticed a couple of months ago when I was talking about FAT32 that I was using Linux style commands such "ls" and "cat" and so from Tachyon as they seemed the most logical names to use. However I wouldn't really call it a "Linux-like Propeller OS" though but it's true that you can make it look and feel like that if you want. I wonder why Forth isn't just used as an OS (and much more) by many Prop heads, it's much better than a menu of a relatively dumb CLI. I might just make sure that Tachyon V3 comes out with HiRes VGA text built-in along with a nice screen editor as it certainly has the capacity to load and launch source and binaries from SD.
That's an interesting idea. We could call ot Forthos. Now we just need to find something to name after the other two musketeers ;-)
Unfortunately, I don't think Forth is the best language for writing an OS. For me, it's better to use C or Spin. Spin has the nice feature of being position independent, which is why it's the basis for spinix. Spin programs can be built to run at location 0, but can be easily relocated to another location in memory.
Now excuse me whilst I enter pedantic, cantankerous old curmudgeon mode:
This is not any Linux-like Propeller OS.
Firstly Linux is not an operating system, it's a kernel, it provides hardware abstraction, it manages drivers, and memory, and networking, and permissions and task scheduling etc etc. Linux does not even have or require a command line.
What we have here is a command line "shell" look alike in the style of Unix and by extension most familiar operating systems that us Linux. This is of course very cool. Those original Unix commands were terse and short "ls", "rm", "cat", "cp" etc, all the most often used file operations expressed as concisely as possible to avoid tedious typing.
I know this is pedantic, but on a technical forum shouldn't we at least try to get our terminology straight?
@Peter, I'm sure you did not imply that a Unix shell is a dumb CLI. I'd just like to point out that generally they are fully Turing complete programming languages in their own right.
I have no answer to your question but I suspect it's the same as why the world is not using Lisp or Scheme etc. These things are elegant, expressive, extensible and powerful. They are also impossible for normal people to program in.
@Jazzed, I also start to feel giddy and disoriented when trying to read Forth, never mind write it. The confusion rises culminating in nausea and blackout.
However, I have been thinking, this raises an interesting challenge for us "dysforthics". You see these Forth guys do actually manage to fit a lot of functionality into a very small space that seems to run in a reasonable time. The icing in the cake being the self-contained interactive user environment. The Read, Execute, Print Loop (REPL).
Question then is: Is it even possible to create such a small, reasonably efficient, interactive, extensible system using a syntax/semantics that does not make you want to heave? And results in code that normal people can read?
Of course there are many interactive self hosting dev systems:
1) BASIC. Somewhat lacking in the speed and extensibility.
2) JavaScript. The run time is huge.
3) Lua. Nice but also big.
etc etc.
Could it be, God forbid, that the only way to do what the Forth guys do is to abandon any concept of syntax and readability and use prefix notation?
@Dave Hein, Phew...:)
Apologies to all Forthers. I do realize it is only our problem if we have "dysforthia".
Accepting you have a problem is the first step on the road to recovery!!
Actually, using forth as a monitor on the propeller to load other programs makes a lot of sense (it must, it's been done a lot!). There can be a lot of bootstrapping and diagnostic power in those words and the REPL is very handy.
Today I read that dyslexia can be seen in the brain scans of young children: http://www.bbc.co.uk/news/health-23679363
I now suspect "dysforthia" is also a structural problem in the brain that might not be so easy to fix with counselling, group therapy or whatever.
Us "dysforthics" just have to learn to live with our disability and use some other substitute language to make progress.
Adaptability over conformity is a common theme I've been hearing lately. It's the end result, not the process you use.
Carry on!!
I'm at the point where the postfix notation doesn't bother me, but I still find FORTH difficult. It's the stack management when writing reentrant code that's hard part for me. FORTH also encourages a terse programming style to reduce typing, which reduces readability a bit. So when encountering new code I usually find the need to reverse engineer it before I can use it for anything.
However, I've been putting up with this on my recent project because I've found that FORTH can do things that are much harder in other languages. Specifically the ability to create a command line driven embedded system because the FORTH interpreter solves most of the problem for you. The use case for this is a GUI on PC, Android, or Rasp Pi emitting serial commands and parsing FORTH responses. It allows the Propeller (or another MCU) to be transmogrified into a serial motor controller, servo controller, or remote sensor.
It really is pretty powerful.
What I was getting at is that if, for example, I happen to not have legs then no amount of walking practice, or therapy is going to help me grow legs.
So how to get around? Perhaps it's better to forget about the legs and get some wheels.
Similarly dysforthics can make progress by using some other language like C or Cobol. They need a lot of support.
Then there are other sufferers that are so allergic to syntax and semantics that no high level language can help them and they would rather use assembler for everything. Like this poor chap: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=34779
I suppose that would be English if your Chinese or Israeli. But the truth is that Forth doesn't make one think backwards, it just uses a LIFO stack for local variables.
The implication is that C, or Basic, or whatever is thinking fowards. I suppose you would exclude all programing with backward branches as thinking backwards. That implies that you never use loops in your code.
@ Peter J
It seems that you were the first to use Linux-like commands, not Peter. Forgive the oversight.
I understand that. Our daughter had a stroke as an infant and is paralyzed to some degree on her right side. My wife and are both right handed. We've learned that our daughter will never do things the same as we do being both left handed and having little to no use of her right hand. She will do things differently but the end result needs to be the same so she adapts and finds ways to do things that are bilateral processes with only one hand for the most part.
Old thinking was conformity and changing the person to meet with their dyslexia, left handedness, learning difference, etc. Now it should of adaptability and flexibility to find a way to get to the end goal when you may not be able to follow the path most people do. Getting there safely and in a timely manner is more important that taking the same route everyone else does.
I'm certainly willing to embrace diversity when it comes to programming languages as much as I embrace the diversity of the human condition in all other areas. If you need braces, then so be it, you need braces!!
Did you say Lisp? I could have sworn you said Lisp.
I don't think the prefix notation is the problem exactly. After all
a b + c d + *
Is not much more irksome than:
(a + b) * (c + d)
although I might like Scheme's postfix better:
(* (+ a b) (+ c d))
No, I just can't put my finger on the problem with Forth.
P.S. Lisp reference from here: http://www.youtube.com/watch?v=bzkRVzciAZg
Backwards is of course relative and subjective. I can see how if one is limited to a specific approach, any other approach would seem more difficult.
list of numbers I don't memorize them all first by stacking them up in my brain
and then add them up in the reverse order that I read them in.
This kind of thing can cause epilepsy:
a b c d e f AND OR XOR AND OR
and that's before we get into using dup, swap, drop, burp, etc.
Keeping track of all those annonymous items on the stack, for that's what they
are once you get into doing the operations, is a mental chore that computers
should do. That's why we have computers, to do the tedious, boring stuff.
Anyway, that's enough language debating for me. Today at least:)
Is there a brief description of the words that are supported in this version? I tried "ls" and it seemed to work fine but I'm not sure how to "cat" a file. I tried this but got an error:
What is the correct syntax for "cat"?
Type WORDS to see all the words in the dictionary.
Would it be hard to get S" to work from the interpreter?
I took another look at the ANS standard, and the core version of s" is undefined under the interpreter. However, there is an extension of s" under the FILE group of words that is defined under the interpreter. The standard implementation under the interpreter is to use an 80-character buffer to store the string. This buffer would be overwritten by subsequent uses of s" under the interpreter. I'll probably add that to the next update.
(running and ducking for cover...)
What a grotesque idea. We could have a postfix notation command line shell for Unix:
becomes:
Or some such gibberish.
(putting my Forth hat on)
Looks good to me!