S
S
Soft_touch_plastic2020-08-03 21:04:45
Iron
Soft_touch_plastic, 2020-08-03 21:04:45

How is C used in writing an operating system?

Hello, I smoke guides on writing an axis, only for general development, I found out that the bootloader / bios / firewood is written in assembler (by the way, which syntax should I choose - intel or AT & T?), And the rest - in high-level jap - si, si + +. A natural question has surfaced in my mind - how is the C code compiled and executed, if there is only bare metal and a bootloader with a BIOS? Or the compiler is also written in asme? Please explain, thanks.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
15432, 2020-08-03
@Soft_touch_plastic

It doesn't matter what the drivers / axis / programs are written on, as a result, the processor executes machine code - binary data of a certain format, according to which the processor understands what to do at the moment. You have to program in assembler when you need to implement things that are very "close to hardware" - memory translation, I / O registers. Each assembler instruction corresponds to one machine word, in short, the human-readable code closest to the machine.
It's much easier to write in high-level languages ​​- parts of the OS and drivers are often written in C. This language is easier for a human. Naturally, this code is also first translated by the compiler into assembler, and then into machine code. The other processor "does not understand". This data set is palmed off to the computer in some form. For example, the very first instruction in an x86 PC is executed at address 0xFFFFFFF0 in the address space. This address in modern PCs corresponds to the very last 16 bytes of flash memory in the BIOS. From this piece the computer is started (in short, in fact, it’s not like that).
Previously, the BIOS loaded the operating system from a special boot sector on the disk. There, in its raw form, lay the machine code, which further ensured the loading of the OS. Now everything is more simple - UEFI has taken the place of the BIOS, by agreement, the system now starts from a file in the /efi/boot/bootx64.efi folder on the boot disk. That is, not just raw sectors, but files right away. The handling of the file system and disk devices is programmed into the UEFI itself.

V
Vladimir Korotenko, 2020-08-03
@firedragon

https://en.wikipedia.org/wiki/History_of_Linux
Something like this
Or what we taught at university
https://homes.cs.washington.edu/~tom/nachos/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question