Hello, this is Dr. Miller, and this
is Episode fourteen point thirteen
of Assembly
today we're going to talk about
interrupts and system calls.
Interrupts.
So an interrupt is an event that
signals to the CPU that something
occurred that it needs to handle.
And so a couple of examples of this.
Are devices ready or a timer
goes off?
And so examples of different
types of interrupts might include
hardware interrupts, and this would
include a mouse, a keyboard, a
network interface, any
sort of device that is connected
to the computer that is running at
a slower speed than the computer.
And that is generally almost
anything. Right.
So computers run at four billion
cycles a second.
And so there's a lot of things that
can go on while the computer is
waiting. And so instead of pulling
it to say, are you ready?
Are you ready? Are you ready?
It says you can go ahead and
interrupt me when you're ready.
We also have software interrupts
and that's the instruction
on Zaidee six.
And then we have exceptions.
So something happens that we don't
know what to deal with or cause a
catastrophic error with the system.
We have exceptions.
And so an example of that would be
trying to divide by zero.
So if you try and divide by zero on
a computer, it'll keep dividing
forever and never get out of that
loop. And so we make an exception
to not allow that to occur.
And the way that interrupts are
handled is that the colonel handles
interrupts, so the colonel
has what we call either an interrupt
service routine or interrupt
handler.
And so what that does is it's going
to look up. Which routine is bound
to a specific interrupt?
No, it will then
disable interrupts within that
routine run the code that it needs
to run and then re-enable
interrupts. And it does this.
So that way that code can
get to completion without getting
interrupted by another interrupt
handler.
So you don't want both of them to
happen at the same time.
And so then when the device is ready
again, it will again raise another
interrupt and then the OS will
be able to handle it.
And so we have two different Zaidee
instructions, so we have the stye
in the city and the city is
to set the interim flag and
so this will enable interrupts
to occur. And then we have the city.
So we have disable
interrupts or clear the interrupt
flag.
And so normally. Right, the
Interop handler will
do the keitai to clear the entire
flag so that no interrupts can come
in, do its code and then stye
to enable it.
And so these are privileged X
Eighty-six instructions.
And so you can't actually do
them from normal assembly if you're
not running as the colonel.
And then we have a system calls,
so system calls provide a way
for a regular users program
in order to interrupt with the
operating system, Colonel.
And so if there is a particular
action that you want to be done and
it needs to be done by the colonel,
then we go ahead and use
a system call.
And these, again, are privileged
instructions. So there are certain
instructions where we don't want the
user to just willy nilly be able to
modify something.
So, for example, you don't want to
allow one user to change another
using user's instruction pointer
or stack or modify somebody else's
file if that's not allowed.
And so we go through the process
of using a system called
and this also includes access to
privileged data structures.
So, for example, the list
of processes, you wouldn't want a
regular user to modify those.
And then if we have any shared
resources like a network, a disk,
a USB drive, anything that's shared
among all of the uses of a computer,
you would go through a system call
in order to write data or read data
from those devices or interact with
them in some way.
So some examples most
of us are probably familiar with
creating a file, reading a file,
writing a file, appending
or adding to the end of a file,
closing a file.
So most people are sort of familiar
with if you have a USB drive and you
want to be done with it, you have to
eject it. Well, that's going through
a system called to say, I
would like to remove this device.
So if you have any cache data, you
need to write
that to the device and then close
or a process.
We can create new processes, execute
processes, wait on a process,
kill processes or just even exit.
And so.
Operating systems will provide
different types of instructions in
order to do a system call
within the system.
And so back in the day when we just
had 30 two big machines,
Linux uses the interrupt 80
to make a system call.
And so you'll see in code,
if you look for interrupts,
you'll see into 80 code.
And so that's how Linux implements
doing. A system call is we do an
interrupt with sixty
four bit architectures.
We added the six call instruction.
So it is an instruction
and six calls and instruction.
And both of these are ways to do
system calls within,
for example, Linux.
And this, this call is not supported
on thirty two bit code.
So if you're running just a plain 30
to a machine that won't run.
But if you're running thirty two bit
code on a 64 bit machine,
thanasis call logs actually work.
And so when we have an interrupt
A-T, we have different parameters.
So each is going to be our system
call number and then we've got
parameter one parameter to parameter
three all the way up to parameter
six and those are stored in these
specific registers.
And so if you're going to make use
of that system call, you have to set
these registers to the appropriate
values.
When we do a 64 bit sis call
Linux instruction, then we use
these sort of our registers, so
the extended ones are sixty four bit
ones. So the system call number
goes into RSX and then
we have already RSI, RDX,
our 10 or eight or nine.
Go figure as to why they picked
those registers, but that's just how
they had set it up.
And if you want to look up any of
these numbers, you can basically
look inside the Linnik source code
and figure out what Sasko number you
want.
And so, for example, if you have a
thirty two or a sixty four bit
lennix, you'll have a couple of
different files.
So one is for thirty two bit system
calls. And we can see here that we
have numbers associated with
different operations.
So if we want to do it, we use this
call one.
If we want to do break, we use this
call 17.
And so, for example, if we want to
use the right function, we
have some code here, so
we have our normal code and then
we go and say, well, this
is called for is for
right. So we move into the
number four.
We want to use standard out.
Here's a pointer to our string and
then here's how many characters
we want to to print.
And then we do into 80 so that
execute an interrupt and do
the service routine for the right
system call that we would like
to run.
And then if you're on 60 Forbert,
you again can look in
your include directory and so we can
find that we have a 64 bit header
and again, it's going to have the
list of system call numbers.
And so then we can use that with
this this call.
And so here we had to do a little
extra work. So, for example, when
you build this, you have to do Nazan
minus ELV 64 in order
to get a 64 bit
version of your file.
And so then we have to use the R
registers. So we've got RSX versus
call. That's a right.
Here is standard out here is our
string pointer and then here is how
many characters are going to do and
then we go ahead and say Siskel.
And again, that's a way that we can
interact with the system
on a 64 bit machine using assembly.
So today, we talked about interrupts
and system calls.
In the future, we're going to do an
interrupt example using
Falke.
And here's our quiz, what types of
system calls are allowed on 64 bit
hardware under Linux?
So we got into 80 and says,
call if you have questions,
you can email me millirems at
Unclutter Edu and you can find me on
Twitter at my house 30.