Linxz' Blog

Still trying to think of something witty, I will let you know once I get something...

Home Blog
9 January 2019

SLAE 32 Day 2

Tags: Certifications - Courses - SLAE - Assembly Language - Linux


So, after a little break I’ve returned back to the SLAE course, in this post I’m going to gopick up from where I left off. In the last post we finished on video 6 which was the IA-32 Architecture exercises, we didn’t cover those in a lot of detail because I do not want to spoil the course, however as I mentioned it was mostly jusst getting the basics with gdb and that’s it.

In this post we’re going to cover videoos 7-9 which is a theory video on CPU modes & Memory and then moving into our first assembler program and then video 9 being disassembling our first assembler program.

Second Day

Let’s start with CPU Modes & Memory, this video introduces us to some common information about CPU modes & memory - hah that was pretty obvious, wasn’t it? So, CPU modes, what are they? Well, they are the modes in which a CPU can operate (yes, yes I’m getting to the non obvious stuff, God…) what this means is, they allow us to place restrictions on the type of operations a running process can carry out.

So, we’re introduced to three basic modes in this lecture we learn three basic modes, real moed, protected mode and system management mode.

Real Mode

By default, when the processor is powered up or reset it by default will run in real mode, however, for normal usage real mode is pretty useless because A. it can only access 1MB of memory, B. there is no memory protection at all and C. there is no such concept as Kernel vs User space in this mode of operation.

Protected Mode

Protected mode I guess is what you could call the “day-day” mode as this is the mode that almost all modern OS’ use. Protected mode can access up to 4GB of memory on top of this it also supports memory protection features, privilege levels and multi-tasking.

System Management Mode

Finally we have System Management mode, this mode is used for things such as power management and that is really all the SLAE covers on this topic.

As Vivek states in the course material, as far as the course is concerned, the only mode we will cover is Protected mode, due to the fact that as we mentioned, this is the mode almost all modern operating systems will run in. Now, lets take a look into Memory models.

Memory Models

We have three basic memory models, of which we will only cover one as far as this course is concerned. The three models are the Flat model, Segemented model and the Real-Address Mode model which is pretty much just a special case of the Segemented model. Vivek does have some diagrams in his PDF of these models, so I won’t link them here but all you need to know for now is that we will be focusong on a Flat memory model for this course.

So, why Protected Mode & Flat Memory model?

Well, the answer is simple, this is what 32-bit Linux uses. We use Protected mode on a Flat Memory model with a 2^32 addressable space - Vivek explains this in his videos/PDF.

What’s next?

Well, we’re not going to go any deeper on this video now as we’re going to move onto writing our first ASM program and then disassembling it, these blog posts aren’t meant to be centered around one whole video, more like just an introduction to what you will learn in each video so you can have an idea going into it.

Writing our first ASM program

So, let’s get into writing our very first ASM program, you probably already guessed we’re going to make hello world, how fun! There’s not much to cover here because really Vivek covers everything in the videos and it would take me a very long time to write about everything. In short, we are introduced to the basics of writing an ASM program and the concept of moving the registers to get the CPU to do what we want it to do!

Firstly we need to define two sections using section the first is section .text and the second will be section .data. Data is where our message will be stored and the text section will be where we print the data.

Once we have defined the two sections we then need to specify where the program will start, we will use the _start: line to do this, under this is where all of our instructions will go for printing to the screen (you can find this in Viveks vidfeo I am not going to post them here)

Now we’ve done that we also need to actually specify the data, we will use message: here to do that which wil store the string hello world! we will then use mlen to get the length of the message (once again you can find all of this in Viveks video) As for the disassembling part, I’m not going to cover that in this video because really it is quite basic and I think Vivek does an excellent job of covering everything there.

Closing Notes

So far I am really enjoying the course and I think for anyone looking to get into learning more about ASM or even taking the OSCE, this is a perfect course for that! I will keep you updated as I make my way through the course with the assignments to come soon! Thanks for reading!