Shop OBEX P1 Docs P2 Docs Learn Events
A Linux-like Propeller OS -- pfth 1.00 with SDcard — Parallax Forums

A Linux-like Propeller OS -- pfth 1.00 with SDcard

LoopyBytelooseLoopyByteloose Posts: 12,537
edited 2013-09-20 11:38 in Propeller 1
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.
«1345

Comments

  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2013-08-13 14:33
    And, with Clusso's spotting of the Wifi SD card hack ...
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-08-13 18:30
    Linux in 60 lines of Forth code. OK, so maybe it's not exactly Linux, but it does contain some familiar commands that are used in Linux.

    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.
  • kwinnkwinn Posts: 8,697
    edited 2013-08-13 18:56
    @Loopy

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-08-14 13:33
    I think the main point is not to duplicate Linux, but to recognize that Forth allows one to use the same lexicon to do the same or nearly the same thing.

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-14 14:11
    I think the main point is not to duplicate Linux, but to recognize that Forth allows one to use the same lexicon to do the same or nearly the same thing.

    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.
    The SD card is already supported in PropGCC for P2. It has been since at least January.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-08-14 16:40
    I think the main point is not to duplicate Linux, but to recognize that Forth allows one to use the same lexicon to do the same or nearly the same thing.

    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.
  • jazzedjazzed Posts: 11,803
    edited 2013-08-14 17:00
    I wonder why Forth isn't just used as an OS (and much more) by many Prop heads ...
    Not speaking for anyone else here ... I just prefer to use a language that doesn't require me to think backwards.
  • kwinnkwinn Posts: 8,697
    edited 2013-08-14 18:32
    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 ;-)
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-08-14 19:36
    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.
    I considered using the DOS commands instead of the Linux ones, but the TYPE command conflicted with the Forth TYPE word. Also, I prefer the Linux commands to the DOS version, and it meshes well with spinix. Forth does have some nice features that work well with an OS. It basically has shell scripting capability built into it. It could load Spin apps into the high end of memory, which could be used to implement most of the Linux-style commands. Forth binaries could also be loaded. They would just need to be position independent, or a fixed memory space would need to be set aside to run the Forth binaries.

    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.
  • RickInTexasRickInTexas Posts: 124
    edited 2013-08-14 21:21
    Dave Hein wrote: »
    Linux in 60 lines of Forth code. OK, so maybe it's not exactly Linux, but it does contain some familiar commands that are used in Linux.

    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.
    pfth running under spinix, very cool! I Love it.keep up the great work. Look me up if you're around Plano, just North of Dallas. I'll buy you a beer or two and a steak or whatever.
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 02:50
    What an amazing piece of work.

    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 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'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,
    Not speaking for anyone else here ... I just prefer to use a language that doesn't require me to think backwards.
    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,
    Unfortunately, I don't think Forth is the best language for writing an OS.
    Phew...:)

    Apologies to all Forthers. I do realize it is only our problem if we have "dysforthia".
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-08-15 04:55
    Heater. wrote: »
    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!! :smile:

    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.
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 05:56
    mindrobots,

    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.
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-08-15 06:05
    Heater. wrote: »
    mindrobots,

    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. :lol:

    Carry on!!
  • Martin_HMartin_H Posts: 4,051
    edited 2013-08-15 06:30
    Heater, learn Lisp and allow the prefix notation will rewire your brain just a little bit, then FORTH's postfix notation becomes easier to tolerate.

    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.
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 06:34
    mindrobots,

    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


  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-08-15 06:39
    jazzed wrote: »
    Not speaking for anyone else here ... I just prefer to use a language that doesn't require me to think backwards.

    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.
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-08-15 06:46
    Heater. wrote: »
    mindrobots,

    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 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!! :lol:
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 06:55
    Martin_H,

    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
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-08-15 07:13
    I just prefer to use a language that doesn't require me to think backwards.

    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.
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 07:15
    Loopy,
    But the truth is that Forth doesn't make one think backwards,
    I don't know about backwards but it sure is not natural. If I'm adding up a
    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:)
  • jazzedjazzed Posts: 11,803
    edited 2013-08-15 07:38
    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.
    I take it then that you are quite proud of my Go forth .sig entry. Think I'll keep it.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-15 07:41
    I just loaded pfth onto my C3 and I'm having trouble remembering Forth. :-)

    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:
    S" foo.bas" cat
    

    What is the correct syntax for "cat"?
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-08-15 08:24
    The linux commands work like they do under Linux. The parameters follow the command. So you would type "cat foo.bas". BTW, s" does not work from the interpreter. It can only be used within a compiled word. Most Forth interpreters allow s" to be used under the interpreter, but it's a non-standard extension.

    Type WORDS to see all the words in the dictionary.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-15 08:27
    Thanks Dave. Isn't it kind of un-forth-like to accept parameters following the word? :-)
    Would it be hard to get S" to work from the interpreter?
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-08-15 08:59
    There are a few Forth words that use a parameter after the word, such as create, :, defer, is, constant, variable, marker, forget, char and '. It would be cumbersome to have to do these with .s and post-fix notation. That's why I prefer the non-standard INCLUDE word instead of the standard INCLUDED word. The purpose of the linux words is to provide a linux-like environment, so I implemented them with the parameters after the word.

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-15 09:07
    Dave Hein wrote: »
    It would be cumbersome to have to do these with .s and post-fix notation.
    Cumbersome? Is that a problem? I thought Forth was all about being cumbersome! :-)
    (running and ducking for cover...)
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 10:36
    S" foo.bas" cat

    What a grotesque idea. We could have a postfix notation command line shell for Unix:
    $ cat inFile | someComand1 | someCommand2 | someCommand3 > outFile
    
    becomes:
    $ "outFile" "someComan3" "someComand2" "someComand1"  "inFile" cat | | | >
    

    Or some such gibberish.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-15 10:46
    Heater. wrote: »
    What a grotesque idea. We could have a postfix notation command line shell for Unix:
    $ cat inFile | someComand1 | someCommand2 | someCommand3 > outFile
    
    becomes:
    $ "outFile" "someComan3" "someComand2" "someComand1"  "inFile" cat | | | >
    

    Or some such gibberish.

    (putting my Forth hat on)

    Looks good to me!
  • Heater.Heater. Posts: 21,230
    edited 2013-08-15 11:21
    I think I'm going to go back to zeros and ones like we had in the old days:)
Sign In or Register to comment.