0

Does the kernel just not use system calls, or is the assembly being assembled before being on a new system? I might need some more info on assemblers, but I'm just confused that if instructions such as mov [register] are system calls, how would one use this without having to refer to the kernel of a relying operating system?

For example, let's say I'm making an assembly program with a GNU/Linux distro and using it's system calls. How does Linux itself use assembly if it has no kernel to make system calls to?

closed as unclear what you're asking by filbranden, mosvy, Michael Homer, Rui F Ribeiro, kemotep May 20 at 17:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    I think you are mixing up something, I just don't know on which side. Assembler or not has no relation to kernel or not. Maybe you have a misconception of one of the words you are dealing with. – Philippos May 17 at 11:15
  • 1
    Instruction such as mov are not system calls. On linux, the system calls are implemented via instruction such as int 0x80 (on i386) or the surprisingly named syscall (on x86-64). – Uncle Billy May 17 at 12:13
  • @UncleBilly ok yes I definitely did misunderstand something as every comment next to a mov command on everything I look at says system call in that line, that confused me. What is the use of int 0x80 and what does the hex represent? – TheRyGuy May 17 at 12:59
0

mov [register] and similar are not system calls, but assembler instructions.

System calls are basically a user-space program calling specific sub-routines in the kernel, using a mechanism built into the processor and set up by the kernel, that allows the called sub-routine to have a higher privilege level than regular user-space program code.

Assembler instructions are basically a human-friendly representation of actual bytes of machine code. And the machine code is not interpreted nor compiled, but implemented inside the processor either with the processor microcode, or directly at the hardware level, using large groups of logic gates.

A single system call invocation in assembler language is usually multiple lines of code. First the parameters for the system call are loaded in appropriate processor registers and/or to the stack, and then a special instruction like int 0x80 or syscall is used to actually make the system call.

In the 32-bit x86 architecture, the int 0x80 is used as the system call instruction. The kernel has prepared a table of software interrupt handler routines for the processor. This table is not directly accessible by regular user-space code, but using the int instruction the userspace code can trigger one of the routines pointed to by the table. int 0x80 simply tells the processor to switch into kernel mode and jump into the routine whose address is in slot #128 of that table. That routine is Linux's system call interface for 32-bit x86 architecture: it checks the parameters specified, identifies which process made the call and then jumps to the appropriate sub-routine.

In the 64-bit version of the x86 architecture, there is a dedicated syscall instruction for the same purpose. Actually the 32-bit x86 architecture now has it too, but either it did not exist yet when the 32-bit Linux system call convention was designed by Linus Torvalds, or the instruction had a hardware bug in some processor models, so it did not get used. But since all 64-bit x86 processors have the syscall instruction and it definitely works, it is used.

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