Question:
How would you write an OS from scratch from an empty computer?
Zenon
2012-02-10 18:28:49 UTC
When Windows is broken down into its core elements, its C and assembly language.

When you build a computer from scratch, it gives you a prompt for an OS to be installed. So how would you begin writing one from scratch? How would you "Build" another OS?
There isnt anywhere you can input data so even if you had to program it with the most basic level of binary computing, how would you input this information to the machine?
Seven answers:
Ratchetr
2012-02-10 19:08:15 UTC
Think about what a CPU does when it is first powered on. What is it going to do? CPU's only know how to do 1 thing: execute code. No, wait. they don't even know how to do that. They know how to fetch bytes of data from memory and interpret them as instructions. It isn't really code at all, just bytes of data in memory.



So when you power on a CPU, it has to start executing something. Every CPU defines where is starts executing from. Any CPU spec will tell you the physical memory address that it fetches the first instruction from.



So where does the code that prompts you for an OS come from? That prompt for an OS isn't baked into the CPU. So where is it? The BIOS, of course. And what is the BIOS? Well, it's an operating system, and it's been baked into a ROM (well EEPROM probably) And it's just more code. Typically it's written in C and assembly code, then 'burned' into the ROM. The BIOS is set up so that its code is at the memory address that the CPU executes first.



SO...the CPU powers up, and starts fetching instructions. A ROM in the machine provides those instructions. That ROM contains the BIOS code...the code that knows how to bring the hardware to life and start looking for a *real* operating system to run. If the BIOS can't find one...then you get the missing OS message.



So...all you need to do to write your own OS is...write your own BIOS, and burn it into a ROM. Plug the ROM into the machine and boot. All you need to know to burn a ROM is the right pattern of bytes to write.



So you just need to create a BIOS that gives you the basic tools for writing an OS, and lets you transfer that code to a CD, HD or FD. Then you can boot from that device.



But that would be hard. It's easier if you already have a working computer with an OS that gives you the tools. Then you can just burn a ROM from that. Or use an existing ROM and bootstrap your OS from it.



See link about bootstrapping, because that is really what you are asking. (It's the 'who created God' question, but it's much easier to answer in computer science than it is in theology).
ʄaçade
2012-02-10 18:35:05 UTC
>"When Windows is broken down..."



If I had a nickel ... !



An operating system is a complicated thing. It performs all the control functions tieing all the computer's devices into the programmes that run on it, and acts as a traffic cop for those programmes.



To design an OS from scratch, you would first have to decide all the functions you want it to do. Most modern OS's are quite busy doing all kinds of internal management. Make a list of the things it does.



That alone will take half an hour.



The "Boot Loader" is a programme that knows how to read the floppy and start up the OS from there. A boot loader is normally burned into the PROM (Programmable Read-Only Memory) chip that is part of the hardware (or "firmware") of the machine. A boot loader only has to know very little: How to read the floppy (or whatever) and store enough of the OS it finds there into memory and jump to it. That first part of the OS then needs to know how to load the rest of itself into memory.



It is a bit like getting out of bed in the morning: You only need to get one foot on the floor, then push a little, ...and away we go!
John H
2012-02-10 19:00:26 UTC
The very first time a digital computer was programmed (there are such things as analog computers), the program had to be entered using toggle switches on the front panel. You literally entered the zeros and ones into the machine's memory, and then told it to begin executing your program.



Usually one of the first programs written was a bootstrap loader - a simple program that could load larger programs off of storage devices, like a paper tape reader or similar. That's where the term "boot" comes from, it comes from "bootstrap".



Now, fifty or sixty years later, the way a completely new processor is brought up is to build the software on an existing computer, using cross-development tools. It is called cross-development because they are for developing software for a different target, not the one the tools are running on. Once the software is built, there is usually a little bootstrap loader already running on the target that can load in the bigger program you just built with the cross-development tools. This is how you say, build Linux for an embedded ARM controller, using a Windows PC as your development platform.
Cool Guy
2012-02-10 18:32:15 UTC
You seem to misunderstand what the output means by "install OS". It is asking that you put in the cd that contains your OS so that you may install it onto your hard drive. Its impossible to write an OS, without using an OS. So, you cant really do ANYTHING with a computer that doesnt have an OS except install an OS. Writing an OS takes years and years of hard work and is not the easiest thing to do on this planet.
Jonathan
2012-02-10 21:27:50 UTC
You can learn this stuff entirely on your own. And it will cost you less than $5 to do it. Which is way better than in my time. Texas Instruments sells a "LaunchPad" embedded system for $4.30, shipped to your door (US.) It includes two microcontrollers, which gets you pretty close to what you are talking about. But it's still perhaps a ways away.



If you build a computer from scratch, as I have, what you have is a chunk of hardware that includes clocks, buses, and so on. But zero program code. There are lots of ways of getting code in there. One way, a very old way, is to actually "wire up" the code with jumper wires (called plug board programming) so that when the computer starts up and reads the first memory location (the CPU will always have a known, default memory location to start at -- also hard-wired) it sees what was intended by moving physical jumpers around. You can't do much code that way -- it takes up a lot of room. So some folks started selling ROMs -- which were just very, very tiny plug boards where the memory was "hard-wired" by a taped-out design. Later, folks worked out how to not have to tape these out, but instead to allow an external bit of hardware to "burn out" certain bits. The bits were then called "fuses" and you could "blow the fuse" to change the bit. You couldn't change it back. So if you needed to reprogram the memory, you threw away the old one and programmed up a new one. Then they invented UV erasable fuses, which could be "blown" electronically but only could be reset back using UV light. Those had windows in them. Then they invented EEPROM (electrically erasable, instead of UV.) And then flash and so on. These memories were all external and wired up into the circuit just like other parts were.



In the case of the IBM PC, a "BIOS" was included. This was just a UV erasable chip that was socketed on the motherboard and was pre-programmed with some general purpose code. The BIOS knew how to read a floppy disk, how to read a program from a standard cassette tape player, and how to accept keys from a keyboard or put characters into memory so that a display could show them. If it detected a floppy, and if the floppy happened to have data on it in the right places, then the BIOS would read program code from the floppy, stick it into memory, and then jump into it (and hope.) The IBM PC BIOS also supported downloading code into memory by way of the keyboard port, too. Most people don't know that fact. But it is true.



I've written multitasking operating systems in as little as 10-12 hours. However, they depended upon the BIOS for certain services I didn't have to write -- such as floppy disk I/O. The basic concepts of cooperative switching is relatively simple (just a handful of lines of assembly code is all that is needed to add a context switch to C), with pre-emption being more complex by a fair amount but not so much that it is scary -- you just have to attend to static memory issues in libraries, for example. Anyway, it's not hard once you know the concepts to just sit down and do it. This isn't to say that writing Windows would be fast -- Windows is an incredible monster and it requires teams of people many years to do something even slightly similar.



But you can learn all this stuff for just that $4.30 I mentioned. That's because the microcontroller doesn't have any code in it when you buy a new one. You have to write everything yourself. There are tools to help you load it into the memory where the computer will see it. And that part you don't have to do (you could, though, if you really wanted to.) But you write every single line of code that executes when the microcontroller powers up. So you learn a lot that way.



Some computers had front panels (I miss them) which allowed you to "toggle in" your code from there. I used to get callouses on my fingers from doing that, in fact. You set up an address, load it, change data, store that, move to another address, and do it again. Then when you are done "toggling in" your program from the front panel, you'd set the program counter to where ever you'd placed your code by hand using the front panel and just hit "start" and the computer would go.



If you are curious, you should get a microcontroller kit that includes a compiler and assembler and play around with that. It's too bad that front panel computers are mostly dead. But if you could find a PDP-8/e or a PDP-11/45 or PDP-11/70 floating about, or perhaps an IMSAI 8080 or an Altair 8800, you could learn to use the front panel to stick code into blank memory and see how it "used to be done," in that way.
deonejuan
2012-02-10 18:36:56 UTC
Yes you will at least have to have a command-prompt (much like DOS was originally). Look at miniDOS. At least miniDOS has a terminal you can fire up.



Just remember, Microsoft has spent over 40 years making an OS and they haven't got it right yet. Win8 is going to take all-new hardware.
2016-03-03 06:15:05 UTC
no, you can not legally install OS X on a PC as Apple's EULA specifically states it can only be installed on Apple branded hardware.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...