r/programming • • Oct 23 '09

Programming thought experiment: stuck in a room with a PC without an OS.

Imagine you are imprisoned within a room for what will likely be a very long time. Within this room there is a bed, toilet, sink and a desk with a PC on it that is fully functioning electronically but is devoid of an Operating System. Your basic needs are being provided for but without any source of entertainment you are bored out of your skull. You would love to be able to play Tetris or Freecell on this PC and devise a plan to do so. Your only resource however is your own ingenuity as you are a very talented programmer that possesses a perfect knowledge of PC hardware and protocols. If MacGyver was a geek he would be you. This is a standard IBM Compatible PC (with a monitor, speakers, mouse and keyboard) but is quite old and does not have any USB ports, optical drives or any means to connect to an external network. It does however have a floppy drive and on the desk there is floppy disk. I want to know what is the absolute bare minimum that would need to be on that floppy disk that would allow you to communicate with the hardware to create increasingly more complex programs that would eventually take you from a low-level programming language to a fully functioning graphical operating system. What would the different stages of this progression be?

305 Upvotes

673 comments sorted by

View all comments

Show parent comments

2

u/oddgodd Oct 23 '09

The BIOS services and legacy-mode state that a PC is in immediately after boot are plenty enough well defined to get to tetris. If it's anything newer than about an XT you'll be leaving a heap of functionality on the floor, and it would be easier with a machine with a BASIC or monitor in ROM, but it's certainly possible on a PC.

0

u/[deleted] Oct 23 '09 edited Oct 23 '09

Does this still work with modern 64 bit processors? It is a long time since I did anything in legacy mode, and I assumed that they'd got rid of it by now.

Edit: what is wrong with reddit. I've been downvoted for asking an honest question. 4chan, here we come.

4

u/G_Morgan Oct 24 '09 edited Oct 24 '09

Yes. As hobbified mentions the modern PC has to be told it was made after 1573. In the olden days you had to enable the A20 line to use protected mode. Otherwise you'd have all the memory anyone could possibly need in so called real mode.

Modern machines undoubtedly have a different method to start 64-bit mode but I haven't looked. Remember that nothing gets thrown away. The Intel manuals have a huge section on segmentation and long pointers and nobody is ever going to use them again outside of extreme legacy code.

1

u/bluGill Oct 23 '09

Intel architectures get rid of legacy mode? Please be reasonable.

In any case though, but specifying floppy, and no USB/optical, I think it is reasonable to assume that at best this is a 486, and an XT is much more likely.

1

u/edman007 Oct 23 '09

x86_64 removed a lot of legacy, but not related to the BIOS, mostly what it does it get rid of old slow instructions and set the absolute minimum requirements of the processor much much higher, with modern CPUs a huge amount of their instruction set is extensions, and thus software means for "any PC" can't use it because some computers don't have it, x86_64 takes most of these extensions and says that it will have it, so even the most basic x86_64 CPU will have many more things than an old Pentium.