开发者

Can software be executed in bare metal machine? [duplicate]

This question already has answers here: How to run a program without an operating system? (4 answers) Closed 5 years ago.

I just wonder, can we execute a program on a machine without an operating system?

Besides, I heard that the Linux kernel is written in C language and a kernel is run during booting, so I just wonder how a computer understan开发者_运维技巧d the language without first compiling?


From Wikipedia:

When a computer is first powered on, it does not have an operating system in ROM or RAM. The computer must initially execute a small program stored in ROM along with the bare minimum of data needed to access the nonvolatile devices from which the operating system programs and data are loaded into RAM. The small program that starts this sequence of loading into RAM, is known as a bootstrap loader, bootstrap or boot loader. This small boot loader program's only job is to load other data and programs which are then executed from RAM.

The computer can understand the Linux kernel because it has already been compiled and stored (usually) on disk. The bootloader gives the computer enough functionality to load the precompiled kernel into memory.

You wouldn't need to load a whole operating system to run a program on a computer, you could write a bootloader to kick off a program you had compiled. You would not have access to any of the operating system calls that make life easier for programmers.


In short, yes.

Linux is still a software program, in machine code, that runs on a bare metal machine. While you can execute a software program without an operating system, your program will need to implement ALL the code that is used to talk to various pieces of hardware in a computer to various degrees - e.g. outputting data to a display, interpreting input from a keyboard / mouse / network card etc. (Some of the very low level stuff are implemented by the firmware in computer components, but the rest your program will have to implement). This makes it very time-consuming and difficult for you to write something that runs entirely without an operating system.


Yes, and it is done today for small microcontrollers with a few KB of memory.

The program is typically written in C and compiled on some other computer (that is called cross-compiling) and then loaded as binary data into the flash memory of the controller.


the linux kernel might be written in C. It is still compiled to machinecode. And it is this machine code which is executed during boot

You can also write software which is run during a boot. This way you can make your own custom OS, or make your own custom software which can run without an OS directly. Beware though, that an OS gives you a lot of functionality which you'll have to make yourself. Things like driver support, disk IO routines, networkstacks, multitasking and memory management you'll have to do yourself.

Finally: I don't think people don't like it that much if they have to reboot their machine in able to run your software. So I'd go with writing for an OS... it makes live easier on you and the user.


What is an operating system if not software running on a "bare" machine? Voodoo? XD


1st: Sure. You don't really need an operating system just to burn some cycles.

You might need some kind of OS support if you want to load or store files or data, manage input or output, but this can also be done calling BIOS functions directly: read key from keyboard, write to some screen or LED or serial interface. Only when you want to run multiple programs, or deal with interrupts from outside, conflicting ressources or such, then you will desperately need an OS.

2nd: The kernel is compiled to machine code, which is executed during boot. There's no C involved when running a kernel. C only helps writing a kernel or any program which should run, if in the kernel or "bare metal".


Just look at any games console prior to the 32 bit ones. Almost all of them lacked any boot code at all, and simply booted directly from the inserted cartridge.


theoretically, you can build bootloader by using hex editor on another machine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜