17

As I understand, the BIOS code/bitstream that held in the ROM should be generic (work alongside with multiple CPU types or ISAs). In addition, I saw mentions in the web that claim to have the possibility to dump it's code (and to 'disassemble' it).

So, in which language, instruction set or machine code is it written? Doesn't it need any kind of processor to perform its operations? If so I guess that it will use the external CPU, then how does it knows the specific instruction set of the employed one?

Maybe it has an internal processor?

  • 1
    BIOS code is very much not generic, it will only work with a particular instruction set. This used to be (for PCs) the 16-bit x86 real mode instruction set. UEFI is either x86_32 or x86_64, one or the other. – pjc50 Sep 30 '15 at 14:41
  • 3
    I believer asking literally the same question on two stack exchange sites at the same time is frowned upon in general. Certainly I think its probably a bad idea. programmers.stackexchange.com/questions/298628/… – Sam Sep 30 '15 at 16:21
14

So, in which language, instruction set or machine code is it written?

It's written in a language that can be compiled to machine code that can be executed by the processor (the CPU). Typically, it's a combination of C and assembly language.

Doesn't it need any kind of processor to perform its operations?

Yes, the processor is what runs the BIOS code.

If so I guess that it will use the external CPU

Correct.

then how does it knows the specific instruction set of the employed one?

It doesn't. That's why when you purchase a motherboard, you need to make sure to buy one compatible with the CPU you plan to use with it. See, for example, ASUS's motherboard list. They have motherboards meant for Intel CPUs, motherboards meant for AMD CPUs, etc. And if you drill into the specs for a given motherboard, you'll see which specific CPUs it's meant to work with:

CPUs

  • 3
    On the other hand, EFI bytecode. – hobbs Sep 30 '15 at 15:11
  • Wait a minute. Could you give some supporting evidence that a BIOS can be written in C? It was my understanding that a hardware BIOS has to be pure assembler that can run natively on the machine, without compiling or translation. Perhaps there's some distinction between different kinds of BIOSes that you might go into if I am not understanding this correctly. – ErikE Sep 30 '15 at 16:02
  • 2
    @Erik The BIOS that you run on your computer is in assembly and can be directly run, but it may be developed in any language that can compile to assembly. – bjb568 Sep 30 '15 at 16:07
  • Ah, you did say that, I just missed it, since I had a different concept of "language a BIOS is written in". – ErikE Sep 30 '15 at 16:09
  • 1
    @bjb568: This is a bit pedantic, but... the BIOS code that you run on your computer is actually machine code, not assembly. The former is "binary", whereas the latter is human-readable text. – Jason Geffner Sep 30 '15 at 16:19
1

As complementary answer, BIOS used to be written in assembler (now is mostly ANSI C code) which compiles to

a) Machine code for old architectures (in the past, like PC IBM; which was actually written in assembler according to https://sites.google.com/site/pcdosretro/ibmpcbios and an old book from Gottfried in Assembler for PC IBM).

b) UEFI bytecode for EFI currently (BIOS replacement).

As evidence, have a look at https://en.wikipedia.org/wiki/Coreboot & http://review.coreboot.org/gitweb?p=coreboot.git;a=tree

(Notice there are several other open source efforts on BIOS/EFI replacements).

UEFI Is an spec of a framework with several several layers, exposing among other things services, a shell console and an interpreter layer (for EFI byte code), the idea of abstracting "BIOS" away from machine code was to facilitate portability to other non x86 architectures (Itanium, ARM, etc)

This is a good conceptual introduction on UEFI http://www.amazon.com/Beyond-Bios-Implementing-Extensible-Interface/dp/0974364908/ref=sr_1_2?ie=UTF8&qid=1452724127&sr=8-2&keywords=efi+bios

PS. In one company I used to work, I actually had access to the BIOS/EFI code base.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.