7 ms·
Menuet – A pre-emptive, real-time and multiprocessor OS written in assembly
- kryptiskt 9y agoSo what's the point of GPL if it's written in assembler?
- kryptiskt 9y agoApparently the 64-bit version is under another non-commercial-only license.
- setzer22 9y agoAssembly language can be reasonably structured and have comprehensive comments to name subroutines, for example. There is some value to that vs what you would get by de-assembling a binary. Depending on the GPL, this would also ensure this OS doesn't run on restrictive platforms like iOS.
- colejohnson66 9y agoThat’s not the GPL, that’s just the usage of assembly. As a side note, I remember years ago (around iOS 5 or earlier IIRC), there was a version of Bochs compiled for iOS and available on Cydia. It came with an IMG of an installed Windows 95 box and was very slow, but it was “running”[0] x86 on iOS. [0] Quotes around “running” because Bochs isn’t so much of an emulator as it is an interpreter. It’s still an emulator, but it runs by interpreting each instruction instead of binary translation like “modern” emulators.
- 0x0 9y agoAssembly source code is vastly better for modifications compared to a assembled binary? It's not like it's written in a hex editor?
- colejohnson66 9y agoTo add to this: the reason is that you still have function names (the assembler or linker might remove all but `_start'[0]). If the assembly used any macros, you have those. And the biggest IMO: comments are still there. [0]: Or whatever it’s called on $(OS)
- tyingq 9y agoHere's an example. OpenSSL uses assembly routines to speed up some cryptographic operations. For example, here's some routines for MD5 on x86_64: https://github.com/openssl/openssl/blob/master/crypto/md5/asm/md5-x86_64.pl https://github.com/openssl/openssl/blob/master/crypto/md5/as... Don't let the perl extension fool you. It's mostly ASM, the perl is there to help with the build. It was pretty easy to find someone that had copied it and violated their license by removing the copyright text, and further claiming to release it into the public domain. Perhaps not on purpose, but... https://github.com/GaloisInc/hacrypto/blob/master/src/C/libssl/HEAD/src/crypto/md5/asm/md5-x86_64.pl https://github.com/GaloisInc/hacrypto/blob/master/src/C/libs...
- 482794793792894 9y agoJust because you can view the source code, doesn't mean you're allowed to modify it and then use the modified version for yourself or publish the modified version. GPL ensures that you're allowed these things and that anyone, who does modify it, has to then again allow these things to anyone who uses their version. Yes, a good chunk of GPL – that the source code has to be published along with the software, is pointless here, so a simpler license could have been chosen, but I guess, they went with GPL anyways, as it's a proven license which has already had a few courts look over it.
- mikebenfield 9y agoThe common misconception you seem to be displaying is that the advantage of "open source" software is that it comes with the source code. This is exactly why Richard Stallman objects to the term "open source" and prefers "free software": because the point of the thing is that you are legally free to modify and distribute it. Access to source code is just a prerequisite to be able to practically exercise those freedoms. (I'm making no commentary on whether he's right about this. Personally I tend to say "open source" more often, because that term has basically won out and I'm more likely to be understood.) By the way, years ago when Microsoft was apparently going to war against open source/free software, there was a bit from some Microsoft executive who said something like, "Open source is pointless. If our customers want to see our source code, they can just ask. But nobody does. Nobody cares about source code." He was exploiting people's misconceptions about what "open source" means. Indeed, nobody cares much about source code if they're not allowed to do anything with it. (Plus, disassembling a binary is a massive pain compared to just using the commented and labelled assembly file.)
- ZenoArrow 9y agoAssembler and machine code aren't the same thing. Your computer does not run assembly, it runs machine code. Assembly languages are still "compiled" into machine code, except that this process is called "assembling" and is much simpler than compiling other languages due to the structure of assembly and machine language being so close. Whilst that similarity makes it easier to disassemble (i.e. decompile) back to working assembly, the structure of the code can be lost, especially if code is organised in a modular way (using macros, etc...). As modularity improves maintainability, there is a technical benefit to having code written in assembly protected under the GPL.
- raverbashing 9y agoAt this point, in the evolution of compilers, assembly does not make it faster (by means of "running faster" though it does by means of "it's harder to write, hence bloat is kept smaller")
- davemp 9y ago> assembly does not make it faster It is still very possible to hand write assembly that’s faster than optimized C. The compiler can’t just magically assume the same pre/post conditions that you can. Also register allocation is an NP problem (graph coloring). Can a human keep that level of optimization up for the length of an OS? No idea. Would it even be worth it? Probably not.
- betterunix2 9y agoActually compilers are much better at register allocation than humans and have been for many years; the fact that it is NP complete is irrelevant, because NP completeness is just as difficult for humans to deal with. Other than taking advantage of special instructions that are hard for compilers to use, there are few cases where the performance of hand-written assembly is better than compiler-generated code. Compilers cannot assume pre/post conditions, but they can analyze much larger amounts of code than humans and will often detect things that humans miss -- which constants that can be propagated, expressions that can be reduced, etc. Compilers are a lot better at deciding which of two equivalent instruction sequences will be faster on a given CPU architecture.
- gizmo 9y agoAnd yet the most efficient programs are written in the low level languages, and the slowest programs are written in high level languages where optimization is the responsibility of the compiler. Compilers can definitely do better than humans in some situations, but you can also use an optimizing assembler that helps with register allocation (not as important for x64) and all sorts of peephole optimizations. The compiler doesn't reason about the data, which means the compiler has to make worst-case assumptions that the programmer knows won't occur. This is a big source of inefficiency. Compilers will never be able to make strategic optimizations because the compiler doesn't understand what it's compiling. Like with chess, computer + human is the winning combination.
- exikyut 9y agoAlmost GPL. MenuetOS has both 64-bit and 32-bit variants. The 32-bit version has a fully open source kernel, the 64-bit version's kernel is closed. Light details and strong hinting of drama here: https://board.flatassembler.net/topic.php?t=16822 https://board.flatassembler.net/topic.php?t=16822 (just found this to cite the 32/64 open/closed thing and TIL'd) What IS interesting is that it uses flat assembler. fasm is kind of interesting. Anybody looking to play with it on Linux may find this (very) high-level/vague/rough idea of where to start helpful: https://news.ycombinator.com/item?id=15282073 https://news.ycombinator.com/item?id=15282073
- slim 9y agohttp://kolibrios.org/en/ http://kolibrios.org/en/ The opensource fork
- pizza234 9y agoKolibriOS is the fork of the 32-bit version of MenuetOS, which is already open source, so they're both valid for that matter.
- andrewflnr 9y agoThe comment you linked says that nasm is "tied to gcc", "indirectly". What kind of tie does it have? All I really know about it is that it uses a different syntax than GCC's assembler.
- im3w1l 9y agoGCC uses GAS.
- exikyut 9y agonasm cannot generate ELF binaries directly, only .o files which must be formally linked. So you have to use `ld` on the generated object file(s) to produce a binary. (I've not (yet) tested using LLVM's new linker or the linker stages from other compilers.) Some extremely anecdotal and unscientific testing I did a little while back seemed to show that fasm's "hello world" example is several scales smaller than nasm's. I decided to be scientific and re-do my test with similar programs. fasm includes a hello-world program in the distribution: format ELF64 executable 3 segment readable executable entry $ mov edx, len lea rsi, [msg] mov edi, 1 mov eax, 1 syscall xor edi, edi mov eax, 60 syscall segment readable writeable msg db 'Hello world!', 10 len = $ - msg Here I pretty much converted the fasm example to match nasm as closely as possible (using various online references to get an idea of how it should look for nasm): section .text global _start _start: mov edx, len mov rsi, msg mov eax, 1 mov edi, 1 syscall xor edi, edi mov eax, 60 syscall section .data msg db "hello, world!", 10 len equ $ - msg What isn't really possible with nasm is to remove the symbol table and _start export. This makes a phenomenal difference in file size. Here's nasm: $ ls -lh nasm64 nasm64.o -rwxr-xr-x 1 i336 users 512 Oct 9 10:10 nasm64 -rw-r--r-- 1 i336 users 880 Oct 9 10:10 nasm64.o Because fasm doesn't need to mess around with exports or symbols and can just write binaries directly, it absolutely kills nasm: $ ls -lh hello64 -rwxr-xr-x 1 i336 users 222 Oct 9 10:29 hello64 One of my major interests in assembly language is in having tight control over output file size, so fasm is super interesting to me. I am very curious as to the file format differences though. Apparently nasm generates SYSV-format ELF files, while fasm generates a Linux-specific variant...? $ file nasm64 nasm64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped $ file hello64 hello64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, stripped That's interesting. I'm genuinely curious what this means. As far as the size differences are concerned, http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... shows that to make smaller stuff than ld generates, you have to start hand-composing the ELF file. So fasm is pretty much the only way to produce the smallest ELFs with minimal fuss on Linux.
- winter_blue 9y agoI think our goal should be to develop even better programming languages that can express high-level concepts succinctly, and that provide even larger sets of compile-time guarantees (e.g. static typing). I don't see the benefit in writing anything that doesn't need to be super-optimized in assembly language. Compilers are so good at optimizing right now that assembly is only justified for very small pieces of code that for example need to use special new CPU instructions (for e.g. in video decoding), or for particular segments of code that a profiler shows that the compiler can't optimize well enough. Assembly language is hard to write, read, understand, and reason about. It shares the same memory model as C, with all its flaws. There is nothing impressive about this. It's like someone saying they built a house with their bare hands without using any machines or technology -- machines and modern technology could have helped them build a house faster, and that was of better quality.
- pjmlp 9y agoActually Assembly usually does what I mean, instead of the UB pulllig rug under my feet tricks of C optimizers.
- 0xcde4c3db 9y agoEven outside of UB and just in terms of implicit actions, I've also been bitten by destructors/finalizers. They can especially cause mysterious problems if they invoke any synchronization magic (join a thread, exchange state through a pipe/FIFO, acquire locks, etc.).
- sigjuice 9y agoYour hardware might still pull the rug from under you with caches, prefetching, NUMA, out-of-order execution, speculative execution and other stuff.
- pjmlp 9y agoTrue, but those things are usually easier to track down, than having them and C's UB on top.
- mikebenfield 9y agoMy tired brain initially thought it saw "GPU" in the acronym soup "GPL GUI PC OS" and started to think "Weird, what must an OS running on a GPU be like?... Oh. Nevermind."
- verri 9y agoMaybe interesting to post here are the comments of Steve Yegge (GeoWorks developer) on large scale assembly projects: https://youtu.be/tz-Bb-D6teE?t=2161 https://youtu.be/tz-Bb-D6teE?t=2161 His argument was that while assembly allowed for more optimized local routines, they've lost the perspective on how the system should behave at large (the handling of window drawing routines, etc.)
- amigoingtodie 9y agoGeoworks. Haven't heard that mentioned in a long while.
- luckydude 9y agoI miss those guys, they did some nice stuff. Shame it didn't catch on.
- GeorgeTirebiter 9y agoFolks might forget that before unix, most OSs were written in assembly, the obvious important one not written in asm was Multics (used PL/I). I worked on the Tops-10 and -20 OSs and they were pure assembly. People seem to think that it's not possible to write maintainable, reliable code in assembly, that's just not true. The DEC source was well-documented and well-tested. Sure, it had bugs fixed each release, as every code base has bugs. Still, I was never flummoxed as to what a routine did: after all, it was executing one machine instruction after another, and once you knew the operands, you knew the result. Debugging was at the machine level, instruction by instruction. Building higher-level code was accomplished just like it's done today: from smaller modules / subroutines. PUSHJ - Push PC and Jump, or 'Call'. These days, writing software is almost magic, meaning there is a whole 'chain of trust' that must be invoked -- all based on belief that it's all correct -- before proceeding. With assembly, magic stops at the hardware / software boundary; that is the actual machine instructions.
- JPLeRouzic 9y agoThanks that is a fantastic comment. I particuliarly appreciate the "These days, writing software is almost magic, meaning there is a whole 'chain of trust' that must be invoked". Even as late as the 80" there were large business software like telecom switches (ITT's Metaconta or Alcatel's E10) that were written only in assembly. Those software had to be reliable.
- maxpert 9y agoI have followed this project for quite long time, have even used it once or twice for fun (in floppy days). Makes me wonder why didn't anyone tried to write similar thing for Raspberry, I mean Linux is sometimes too much, this could have spinned off a complete genre of OS for these kind of devices for education as well.
- LeoPanthera 9y agoFor the Pi, there is RISC OS. https://www.riscosopen.org/ https://www.riscosopen.org/
- throwaway7645 9y agoBeat me to it!
- userbinator 9y agowhy didn't anyone tried to write similar thing for Raspberry This is close: https://news.ycombinator.com/item?id=7926004 https://news.ycombinator.com/item?id=7926004 But the answer to your question could probably be answered in one word: Broadcom. By keeping secret the details of their SoC, it's far harder for "from scratch" projects to appear, despite it being one platform. On the other hand, the PC, while far more diverse, still relies plenty on documented, de-facto standard interfaces and there is no shortage of articles on things like "how to write a bootsector".
- feelin_googley 9y agoAnd yet, as far as I have seen, it is still much easier to run a variety of OS from a RPi than a PC. Simply swap mini SD cards. While PCs can usually boot from USB, I have seen ones that cannot also boot from SD card. (Bias disclosure: For many years I've been compiling own kernels with embedded filesystem and minimal utilties and then running from removable media, even on the PC, so RPi was easy transition. Further I stopped using disk or swap years ago, even on PC, again making RPi transition painless. Finally, I am more interested in non-graphical tasks so I can live without the use of a GPU.) The greatest value to me of the RPi is the ability to run a variety of OS. One can readily find other boards that are better than RPi in many ways, but in each case running the variety OS that using a RPi allows for is not as easy, if it is even possible. Despite the disadvantage of RPi's closed bootloader and GPU, the flexibility to run a variety of OS is great advantage over many alternatives, for me. The way I think about it, user freedom in choosing an OS is actually constrained by "too much choice" in hardware. I reason that this is because it is difficult for OS projects other than Linux to timely add support for each and every different item of hardware coming off the assembly line in each new year. Whereas with the RPi, the "moving target" of hardware support moves less. This IMO opens up possibilities for more OS projects to add support for RPi hardware. Whether this is the reason a variety of OS are suppported on the RPi I do not know. But I am glad that this variety exists.
- johnhattan 9y agoA bunch of years ago, there was a "Menuet" product that was a cross-platform C++ UI library for Mac/Windows/Whatever. Did they expand the underpinnings into a complete OS, or is this an unrelated product?
- FollowSteph3 9y agoDoes it feel any faster than a modern OS not written in assembly?
- lightedman 9y agoI remember it being a practically instant bootup from USB on a Pentium 4 (needed a little FDD hack to make it work but it screamed.)
- xwvvvvwx 9y agoI would be quite surprised if anyone could write that much assembly that's faster than what a modern optimising compiler outputs. Makes me happy that people are trying though... :)
- rasz 9y agotry it, every application open instantaneously, no load times.
- ParrotyError 9y agoI suppose you can run it in bochs or quemu or one of those things if you want to use it on non-x86 hardware.
- hoodoof 9y agoThis sort of thing no longer makes sense. It used to, back in the days when every cycle counted. Not today, more important is maintainability of the source code, because compiled C is fast enough. Menuetos may be fast, but it also does less - for those who would compare to current OS's - it's not an apples versus apples comparison, no pun intended.
- wyldfire 9y agoMaintainability is a high-ranked concern for the project maintenance, for sure. But for the sake of the project's applicability and longevity, an even more important reason to write it in C is portability. It's an OS, after all. Porting Menuet to another architecture would likely be a significant amount of work. Whereas most OSs have very limited arch-specific portions.