News for hackers. Stuff that matters.
Re:Thor – A minimalistic operating system in assembly and C++ by dbcurtis on Tuesday August 23, 2016 @11:08AM (#12344324)
> If yes, why people still even think about doing it with unsafe languages?

What you need for OS or embedded development is a language that doesn't get in your way. C doesn't get in your way. C is the first language that both stayed out of your way and also provided reasonable productivity features (over BCPL, B, and assembly).

It was only recently that people have figured out how to come close to a "safe" language that doesn't get in your way.

Here is a test case: grab an ARM Cortex-Mx processor. Boot, configure the I/O matrix, and set up, oh say, the counter/timer peripherals for PWM motor control and quadrature decode. If you can do that without a trip to an "unsafe" language, that is a worthy accomplishment for your safe language.

Another test case might be doing page swapping and page-table updates on a virtual memory subsystem on a multi-core CPU without a trip to an unsafe language.

I guess a more direct answer to your question is that when you get down to the hardware, you have to deal with weirdo bit fields, volatile hardware registers, strange read/write ordering requirements, interlocks, and even some totally non-interlockable volatile stuff. C can do it (although I admit it uses language features not everyone sees every day).

Re:Thor – A minimalistic operating system in assembly and C++ by steveklabnik on Tuesday August 23, 2016 @12:40PM (#12345072)
Funny you should mention the Cortex-M :) https://github.com/helena-project/tock/ (written in Rust, just linked to it down thread as well)
Re:Thor – A minimalistic operating system in assembly and C++ by dbcurtis on Tuesday August 23, 2016 @01:03PM (#12345267)
I will check that out.
Re:Thor – A minimalistic operating system in assembly and C++ by orcy on Wednesday August 24, 2016 @01:36AM (#12349907)
$ grep -r unsafe | wc -l

292

Re:Thor – A minimalistic operating system in assembly and C++ by steveklabnik on Wednesday August 24, 2016 @10:31AM (#12352299)
Sure. Hardware is inherently not safe; the key is to build up safe abstractions around it by using the type system.
Re:Thor – A minimalistic operating system in assembly and C++ by pjmlp on Tuesday August 23, 2016 @02:34PM (#12346232)
> C is the first language that both stayed out of your way and also provided reasonable productivity features

If we ignore the history of computers outside AT&T....

Re:Thor – A minimalistic operating system in assembly and C++ by dbcurtis on Tuesday August 23, 2016 @03:27PM (#12346720)
Example? Standard language that never required a trip to assembly language for system level programming?

On IBM's, PL/I didn't cut it that regard.

On a UNIVAC you could do a lot of system programming in FORTRAN, but only because there were a zillion proprietary extensions that accessed system programming primitives.

BASIC on a Commodore 64 had PEEK() and POKE() but that doesn't count either, very non-standard.

FORTH? Nope... still asm at the bottom.

Concurrent Pascal? Nope... not safe, despite the type checking, because you could twist variant records however you liked. And I think there was asm at the bottom anyway, IIRC.

COBOL, well, CDC COBOL had a bunch of extensions, too, but you still ended up in asm for system programming.

Show me the source code for a device driver in a high-level language that pre-dates C/B/BCPL.

Re:Thor – A minimalistic operating system in assembly and C++ by pjmlp on Tuesday August 23, 2016 @03:49PM (#12346904)
> On a UNIVAC you could do a lot of system programming in FORTRAN, but only because there were a zillion proprietary extensions that accessed system programming primitives.

Just like pure ANSI C without compiler extensions.

> Standard language that never required a trip to assembly language for system level programming?

Try to implement 100% of libc in ANSI C without writing one single line of Assembly, syscalls into the underlying OS or compiler specific language extensions.

> Show me the source code for a device driver in a high-level language that pre-dates C/B/BCPL.

ESPOL on Burroughs B5000, 1961.

Re:Thor – A minimalistic operating system in assembly and C++ by lake99 on Tuesday August 23, 2016 @07:30PM (#12348614)
You shouldn't complain about extensions to the language. C needs extensions too. For example, many architectures have 3 (or more) memory spaces: program/code, data, IO. If you want to do anything on IO, you'd have to rely on non-standard (proprietary) extensions to C, or, like FORTH, get to asm at the bottom, and call those functions from your C program.
Re:Thor – A minimalistic operating system in assembly and C++ by stcredzero on Tuesday August 23, 2016 @06:55PM (#12348431)
FORTH? Nope... still asm at the bottom.

I call shenanigans!

Re:Thor – A minimalistic operating system in assembly and C++ by dbcurtis on Tuesday August 23, 2016 @07:17PM (#12348551)
Either my sarcasm detecter is broken today, or you've never read the source code of a FORTH system. Or perhaps you are commenting that FORTH doesn't have high-level programming constructs -- but of course FORTH allows meta-programming, so you roll your own.
Re:Thor – A minimalistic operating system in assembly and C++ by stcredzero on Tuesday August 23, 2016 @08:02PM (#12348744)
I'm saying that it's shenanigans that he's justifying disqualifying FORTH as a systems programming language because "it's ASM at the bottom." So I'm on your side of that debate.
Re:Thor – A minimalistic operating system in assembly and C++ by Narishma on Tuesday August 23, 2016 @08:04PM (#12348750)
> Example? Standard language that never required a trip to assembly language for system level programming?

That would exclude C as well.

Re:Thor – A minimalistic operating system in assembly and C++ by nmjohn on Tuesday August 23, 2016 @12:10PM (#12344844)
> I guess a more direct answer to your question is that when you get down to the hardware, you have to deal with weirdo bit fields, volatile hardware registers, strange read/write ordering requirements, interlocks, and even some totally non-interlockable volatile stuff. C can do it (although I admit it uses language features not everyone sees every day).

I agree with you that building an entire OS to interface with hardware without using _any_ unsafe code is, by some definition of the word, impossible.

However that doesn't mean you must limit yourself to unsafe languages for the other 90% of the operating system code.