TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to run a program without an operating system?

394 pointsby Cieplakover 6 years ago

17 comments

emilfihlmanover 6 years ago
&gt;Technically, a program that runs without an OS, is an OS.<p>It is not. A program that runs without an OS just doesn&#x27;t need the OS provided services but instead manages everything itself.<p>A perfectly valid program might be:<p><pre><code> #include &lt;avr&#x2F;io.h&gt; int main(void) { DDRB=255; while(1) { PORTB++; } }</code></pre>
评论 #18534126 未加载
评论 #18534853 未加载
评论 #18535587 未加载
评论 #18534332 未加载
评论 #18534252 未加载
CoolGuySteveover 6 years ago
If you ever programmed a ROM for a Gameboy or something this should look familiar. The BIOS of those old systems just jumps right into a certain address and all you have to do is make sure your linker is setup properly to put crt0.s there.<p>The Gameboy Advance in particular is pretty fun and simple, I recommend it.
评论 #18531961 未加载
评论 #18531697 未加载
Communitivityover 6 years ago
For any &quot;How do I...X?&quot; question involving connecting two pieces of software together in a different way, the first thing I try to do is look at the API(s) that connects them. In the case of a program and the OS, it&#x27;s the system calls, device drivers, and standard libraries.<p>There have been efforts to provide the capability of running a program without an OS before, but any such effort is going to need to provide the system calls and standard libraries used by the program, and the infrastructure to support it (device drivers, management, etc.). That that point it becomes a mini-OS.<p>An example is Erlang on Xen. Xen is more often run with a guest OS running inside it, and then the program runs within that guest os. The <a href="http:&#x2F;&#x2F;erlangonxen.org&#x2F;" rel="nofollow">http:&#x2F;&#x2F;erlangonxen.org&#x2F;</a> folks made Ling (<a href="https:&#x2F;&#x2F;github.com&#x2F;cloudozer&#x2F;ling" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cloudozer&#x2F;ling</a>), software that enables an Erlang BEAM VM to be run directly on Xen, and thereby run a single Erlang program on Ling.
beached_whaleover 6 years ago
Saw a talk on Include OS that is a C++ library that allows one to do this <a href="http:&#x2F;&#x2F;www.includeos.org" rel="nofollow">http:&#x2F;&#x2F;www.includeos.org</a>
评论 #18532041 未加载
sureaboutthisover 6 years ago
People forget that an operating system is, itself, just a program.
评论 #18534303 未加载
Arainachover 6 years ago
For another take on the subject, see &quot;This OS is a bootloader&quot; in PoC||GTFO 0x4:<p><a href="https:&#x2F;&#x2F;www.alchemistowl.org&#x2F;pocorgtfo&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.alchemistowl.org&#x2F;pocorgtfo&#x2F;</a><p>There&#x27;s a sequel in 0x5 that explains how to add a basic form of multiprocessing support.
评论 #18532047 未加载
justincormackover 6 years ago
The Osdev wiki is a great resource on this type of thing <a href="https:&#x2F;&#x2F;wiki.osdev.org&#x2F;Expanded_Main_Page" rel="nofollow">https:&#x2F;&#x2F;wiki.osdev.org&#x2F;Expanded_Main_Page</a>
评论 #18532070 未加载
babuskovover 6 years ago
Not directly related to the topic, but I wrote a simple puzzle game that emulates a computer which executes programs directly in the memory and you can modify memory to rewrite running programs. Here&#x27;s a web-based demo if anyone wants to check it out:<p><a href="https:&#x2F;&#x2F;roguebit.bigosaur.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;roguebit.bigosaur.com&#x2F;</a>
lostgameover 6 years ago
A lot of people here seem to be questioning the usefulness of this, why someone would want to do this, et cetera.<p>Embedded systems are one of the most extremely relevant uses of this today.<p>However, historically, I think my first case of programming without an OS would be ASM development for the Sega Genesis?<p>Another addition is that I saw a comment ‘a program that runs an OS, is an OS.’<p>This is absolutely not true. An Operating System is a multi-faceted, complex piece of software, usually with the capacity to run other pieces of software within it, as well as usually offering high-level API’s to improve ease-of-use for developers to access common functionality, such as playing sound, or displaying images.<p>A ROM for the NES, while a program, is certainly not an OS, and to be very clear, the NES does not have an OS, like I believe the PS4 and XB1 have.<p>It contains a certain number of hardware features that can be accessed and manipulated by low-level software functions.
ameliusover 6 years ago
Now try to do it on a smartphone.
评论 #18533732 未加载
nmstokerover 6 years ago
Would be interesting to hear discussion on why one might consider doing this.<p>My take is that it&#x27;s most likely just being asked for the theoretical details, and few people would practically benefit, but does anyone think this would be practically useful?<p>Presumably you&#x27;d potentially cut overhead from anything you didn&#x27;t explicitly want happening on the host, but as soon as I start to think about most of the uses typically have, the advantages quickly sink below the disadvantages of having to actually manage everything. It&#x27;s reminiscent of that person who set out to build a toaster from scratch.
评论 #18536206 未加载
评论 #18535685 未加载
评论 #18558630 未加载
评论 #18537307 未加载
评论 #18536109 未加载
jancsikaover 6 years ago
&gt; printf &#x27;\364%509s\125\252&#x27; &gt; main.img<p>It appears that bash `printf` wraps coreutils printf &quot;with ARGUMENTs converted to proper type first,&quot; according to the manual. I guess that&#x27;s how the &quot;%509s&quot; specifier is able to work without any args.<p>So how does bash `printf` actually determine the proper arg types? Is coreutils printf implemented with hooks that let wrappers fetch the proper arg types without generating an output string? Or does bash `printf` implement its own separate parser for the format specifier?
评论 #18533751 未加载
评论 #18533760 未加载
finchiskoover 6 years ago
Very nice post. However I thought it would be about writing programs that could be executed from OS, but OS would be completely unaware that such a program is running. Not sure if that is even possible.<p>I know it’s possible to not use libc or similar, but os is aware of such a program.
评论 #18533098 未加载
评论 #18532897 未加载
评论 #18533454 未加载
评论 #18532876 未加载
评论 #18533458 未加载
andrewstuartover 6 years ago
Stack Overflow is for very specific questions with very specific answers.<p>You&#x27;ll get better results for more general questions from a reddit forum.
评论 #18532678 未加载
评论 #18532062 未加载
评论 #18533055 未加载
vectorEQover 6 years ago
i always feel these questions are answered to best effort of a person just starting out in the field of os &#x2F; bare metal programming. there is a whole plethora of information missing in this post crucial to x86&#x2F;64 early development which will get new programmers of this type into trouble if they don&#x27;t become aware of it.<p>i&#x27;d be careful following such advices. for example this person isn&#x27;t aware you really need to build a cross toolchain for your OS to compile to your target. on 64-bit there&#x27;s some more things to take into account about compilers (red-zone?). even if you go all assembly your assembler will probably be an optimising one and shoot you in the back on more than one occasion! Thats just the tool-chain surface issues (deeper ones ignored... like file formats..? binary is fun, but good luck scaling that up to a complex project... bios can&#x27;t load you up that high in memory and limited amounts...)<p>Next you get to things omitted which on baremetal would cause problems, like no mention of power management and such topics. or even assumptions that your code is loaded at 0x0000:0x7c00 while it could be loaded at that address but via a different CS value, completely screwing you over if you don&#x27;t flush it immediately on your mbr...<p>Take an example of opengl tutorials. people tell you to write your first polygon because they just managed to do so. They forget to mention to throttle the loop, so you burn out your VGA card rendering 10000000000fps of 1 triangle.... good job!<p>this tutorials are kind of like that. fun to put into qemu which is sort of &#x27;safe&#x27; learning and get acquainted but really doesn&#x27;t do what it says on the box.<p>I&#x27;m not against these type of tutorials, i like that more people become interested in this, but really take some time and state the scope of the offered information properly. like this is a bit of clickbait &#x2F; misinformation which is a shame
everyoneover 6 years ago
Prompted a fascinating answer. &#x27;closed as too broad&#x27; -- modern Stack overflow in a nutshell.
评论 #18531909 未加载
评论 #18532690 未加载
评论 #18533017 未加载
评论 #18531679 未加载
评论 #18532058 未加载
评论 #18532072 未加载
stevefan1999over 6 years ago
This is wrong, you&#x27;d still have a operating system: BIOS
评论 #18532124 未加载
评论 #18532119 未加载
评论 #18534076 未加载