
The TTY demystified - tim_sw
http://www.linusakesson.net/programming/tty/index.php
======
klum
Things like this, with quirks due to decades and decades of history, always
make me wonder what things would be like if we started over, with a clean
slate. In so many places, when you start digging, you find something that
references the way mainframes worked in the sixties or teletypes way before
that etc. I mean, it's probably not practical, and it would probably be killed
by committee or reimplemented in JavaScript anyway, but you can't help but
wonder...

~~~
ZenoArrow
There are a few groups working on reimagining computing from first principals.
VPRI is one such group:

[http://vpri.org](http://vpri.org)

The most interesting work I know of from VPRI is the STEPS project, which aims
to design an OS that fits in less than 20000 lines of code:

[http://www.vpri.org/pdf/tr2011004_steps11.pdf](http://www.vpri.org/pdf/tr2011004_steps11.pdf)

~~~
klum
Interesting stuff, thanks for the link!

~~~
ZenoArrow
You're welcome klum.

You may also be interested in unikernel operating systems. The designs vary,
but the three points below describe the general idea:

* Existing virtualisation technologies (KVM, Xen, etc...) used to manage hardware.

* OS images run on top of this virtualised base.

* OS images consist of a single software application + a minimal kernel that is customised for the needs of the application.

Unikernel-based software has many potential advantages over traditional OS
designs, including increased performance (especially compared to other VM
approaches), reduced size, better security (though hacks like Blue Pill would
probably still apply). The most active unikernel projects are almost all based
on functional languages, so you get the benefits associated with functional
development too.

The Xen Project Wiki has a decent introduction to Unikernels:

[http://wiki.xenproject.org/wiki/Unikernels](http://wiki.xenproject.org/wiki/Unikernels)

If you wanted an easy way to get started, this guide on the MirageOS website
walks you through setting up a simple web server that can be hosted on Xen:

[https://mirage.io/blog/mirage-seal](https://mirage.io/blog/mirage-seal)

------
Animats
For historical reasons, UNIX and Linux handle the line discipline and echoing
in the kernel. But really, that should be done in a user-space program.
Something like xterm, but without X. The kernel should just handle the serial
port hardware.

Is serial port login even enabled by default any more on Linux?

~~~
marvy
I agree it should be done in user space, but how? Surely requiring every
program to use something like GNU readline is a bad idea? I vaguely remember
reading somewhere that Plan 9 does this well. Does anyone know how, or know
another OS that does it well? I also vaguely remember one of my textbooks
mentioning something called STREAMS from System V. Anyone know anything about
it?

~~~
Animats
In QNX, the serial console, if present, is managed by a driver in user space,
loaded with the kernel as part of the boot image. That's how all initial
drivers in QNX start up. For embedded systems, the serial console driver might
not be loaded, or could be a special-purpose driver for the hardware. The user
mode driver is used for any messages during boot; there's no special startup-
time kernel driver.

The boot image may be in ROM, and on small embedded devices, it usually is.
For QNX, disks and file systems are optional. If disk support is desired, some
disk drivers and an init program are included in the boot image, and the later
phases of startup are somewhat UNIX-like.

It's possible to build a QNX boot image so that networking comes up before the
file system, which is useful for headless embedded systems. It's also possible
to build a classic system for x86-type BIOS-controlled boot from disk, and run
QNX on the desktop, but that's not done much any more.

~~~
CountSessine
_In QNX, the serial console, if present, is managed by a driver in user space,
loaded with the kernel as part of the boot image. That 's how all initial
drivers in QNX start up. For embedded systems, the serial console driver might
not be loaded, or could be a special-purpose driver for the hardware. The user
mode driver is used for any messages during boot; there's no special startup-
time kernel driver._

How realistic is this on a monolithic kernel like Linux, though? On QNX _all_
drivers - not just the serial ports - are in user-space. QNX has a
microkernel.

User-space drivers on Linux are always a special case - like FUSE. Someone
always has to write bespoke infrastructure to make it happen.

~~~
Animats
Linux has, over the years, acquired many of the features of QNX - interprocess
communication, real-time scheduling, user mode drivers, user mode file
systems, etc. But all the old in-kernel stuff remains, resulting in a huge,
bloated kernel with a huge attack surface.

(If only QNX, the company, weren't so screwed up. They were sold twice, once
to Harmon (car stereos) and once to Blackberry. They went open source, closed
source, open source, and closed source again. Most developers got fed up and
went to other platforms. QNX powers most of Boston Dynamics's robots; when you
need coordinated control of all those actuators at 1KHz, you need something at
least as good as QNX.)

------
Aardwolf
What are the cylindrical metal things on the wall panel in the "1940's
teletypes" picture? Is it capacitors?

I see those often in similar old photos, but nothing in modern electronics
looks like that afaik so I wonder :)

~~~
david-given
They're probably thermionic tubes, a.k.a. valves. You want them accessible so
you can replace them, but they're also fragile so you put cases over them so
you don't bump them.

------
joepvd
Here a discussion of three months ago:

[https://news.ycombinator.com/item?id=10064657](https://news.ycombinator.com/item?id=10064657)

~~~
ZenoArrow
It's come up 12 times now apparently, I wonder if that's the highest number of
HN submissions for a single article:

[https://hn.algolia.com/?query=The%20TTY%20demystified&sort=b...](https://hn.algolia.com/?query=The%20TTY%20demystified&sort=byDate&dateRange=all&type=story&storyText=false&prefix&page=0)

------
INTPenis
If you're feeling nerdy and missed it you should check out Linus Åkessons
other stuff, like his organ and his sendmail turtle.

~~~
pdkl95
LFT's "bitbuf" sequencer[1] is one of the better examples I've seen of the
concept "leaving money on the table". He released the demo video in 2011 and
people are _still_ trying to buy it in the comments.

I would pay good money for just the his code that transposing/modulating live
MIDI loop sequences (e.g. from the bass line).

[1] [http://www.linusakesson.net/bitbuf/](http://www.linusakesson.net/bitbuf/)

~~~
kzrdude
Really cool.

Why is it called 8-bit music?

~~~
pdkl95
The bitbuf is primarily an ATmega88, an 8-bit microcontroller (see his earlier
project, the Chipophone[1]). He is also alluding to the 8-bit "chiptune" style
of music from the C64/NES era.

[1]
[http://www.linusakesson.net/chipophone/index.php](http://www.linusakesson.net/chipophone/index.php)

------
Ayaz
This was a very insightful read.

------
snowy
Great article. However I don't under stand how it has managed to be posted 12
times:
[https://hn.algolia.com/?query=%09The%20TTY%20demystified&sor...](https://hn.algolia.com/?query=%09The%20TTY%20demystified&sort=byPopularit&prefix&page=0&dateRange=all&type=story)

~~~
luckystarr
Because:

> Great article.

~~~
snowy
So are those the rules now? If we consider some thing to be worthy we can post
it again and again and again?

~~~
snowy
Down votes? Anyone care to elaborate?

Seriously, I don't understand. If I find an article that I find interesting I
can just post it multiple times under different URL's?

Is that now acceptable on HN?

~~~
cooper12
The official stance seems to be: [0]

> Are reposts ok?

> If a story has had significant attention in the last year or so, we kill
> reposts as duplicates. If not, a small number of reposts is ok.

It was posted 3 months ago with 31 comments though so looks like that doesn't
apply. It's possible that mods didn't see the post (due to the different URL)
or that the rules have been relaxed.

As for the downvotes, people in general don't like remarks about reposts
because they're off topic and always come off as complaining. It's more likely
that most users are seeing something for the first time or if they have
already seen it, might not make mind because they like the content.

[0]:
[https://news.ycombinator.com/newsfaq.html](https://news.ycombinator.com/newsfaq.html)

