Search code examples
assemblyx86operating-systembootloaderosdev

How to run a program without an operating system?


How do you run a program all by itself without an operating system running? Can you create assembly programs that the computer can load and run at startup, e.g. boot the computer from a flash drive and it runs the program that is on the CPU?


Solution

  • How do you run a program all by itself without an operating system running?

    You place your binary code to a place where processor looks for after rebooting (e.g. address 0 on ARM).

    Can you create assembly programs that the computer can load and run at startup ( e.g. boot the computer from a flash drive and it runs the program that is on the drive)?

    General answer to the question: it can be done. It's often referred to as "bare metal programming". To read from flash drive, you want to know what's USB, and you want to have some driver to work with this USB. The program on this drive would also have to be in some particular format, on some particular filesystem... This is something that boot loaders usually do, but your program could include its own bootloader so it's self-contained, if the firmware will only load a small block of code.

    Many ARM boards let you do some of those things. Some have boot loaders to help you with basic setup.

    Here you may find a great tutorial on how to do a basic operating system on a Raspberry Pi.

    Edit: This article, and the whole wiki.osdev.org will anwer most of your questions http://wiki.osdev.org/Introduction

    Also, if you don't want to experiment directly on hardware, you can run it as a virtual machine using hypervisors like qemu. See how to run "hello world" directly on virtualized ARM hardware here.