SLAE - 32 bit Linux Flashcards
(32 cards)
What are the diff processors?
intel, ARM, MIPS
Intel Architecture
IA-32 and IA-64
What are the diff components of a CPU?
Control Unit > Execution Unit which uses Registers and Flags
What does the control unit do?
Retrieve/decode instructions, retrieve/store data in memory
What is the execution unit within the CPU?
Actual execution of instructions happens here
What is the purpose of registers and flags?
Registers are internal memory locations used as ‘variables’.
Flags are used to indicate various ‘events’ during execution.
What are the different IA-32 registers?
General purpose regs Segment regs Flags and EIP Floating Point Unit regs MMX regs XMM regs
There are 4 different general purpose regs in IA-32. What are they?
EAX (32 bits wide) Accumulator register and is used to store operand and result data EBX (32 bits wide) Base register which contains pointer to data ECX (32 bits wide) Counter register EDX (32 bits wide) Data register ESP (32 bits wide) Stack pointer register EBP (32 bits wide) Stack Data pointer register ESI (32 bits wide) Data pointer regs for memory locations EDI (32 bits wide) Data pointer regs for memory locations
Decompose the IA-32 general purpose regs.
EAX (32 bits) = AX (16 bits) = AL (0-7) and AH (8-15) EBX, ECX and EDX all work the same way. ESP (32 bits) = SP (0-15) (16 bits) EBP (32 bits) = BP (0-15) (16 bits) ESI (32 bits) = SI (0-15) (16 bits) EDI (32 bits) = DI (0-15) (16 bits)
What are the different segment registers?
They are all 16 bits wide! CS (Code) DS (Data) SS (Stack) ES (Data) FS (Data) GS (Data)
What are some examples of the different flag registers?
Parity flag
Zero flag
Carry flag
SIMD?
Single Instruction Multiple Data
MMX and XMM
MMX are carved out of FPU regs and are 64 bits wide.
XMM are 128 bits wide!
GDB syntax - 1
#shows all the register info info registers #to see all floating point registers info all-registers #print the value of EAX and AX registers display /x $eax display /x $ax #command to disassemble code disassemble $eip disassemble main #gdb assembly syntax #Default is att syntax in linux. Change that to intel syntax set disassembly-flavor intel
What are the diff CPU modes for IA-32?
Real mode (kernel and user priv levels not possible) Protected Mode (priv level possible) System management mode (used for power management tasks)
What are the 3 diff memory models?
Flat memory model
Segmented memory model
Real-address mode model
What mode and memory model does 32 bit linux use?
Protected mode and flat memory model
Process organization in memory.
cat /proc//maps #within GDB to view process mappings, run the following command info proc mappings pmap -d
What are the different steps to gen an exe from an assembly program?
NASM + LD (for assembling and linking)
Exe in ELF format!
Helloworld.asm explain.
; Helloworld.asm
;Author Veer Singh
global _start
section .text _start: 'write interrupt value is 4 mov eax, 0x4 ;stdout whose value is 1 mov ebx, 0x1 ; contains a pointer to the hello worls string mov ecx, message ; contains the length of the 'message' string mov edx, 12 ;mov edx, mlen ; this interrupt will invoke the print sys call int 0x80 mov eax, 0x1 mov ebx, 0x5 ; this interrupt will invoke the sys to exit with the error code 5 int 0x80
;db stands for define byte
section .data
message: db “Hello World!”
; could also do this: ; or you could do mlen equ $-message
How do system calls work?
User space program generates an interrupt “0x80”
The CPU then checks the interrupt handlers table and invokes the system call handler
The system call handler is a kernel mode program and it figures out which particular system call routine is of interest
For instance read and write system calls are diff and hence have diff routines
All these system calls are defined in the file: /usr/include/i386-linux-gnu/asm/unistd_32.h
Compile the hellowolrd.asm assembly code. Steps?
nasm -f elf32 -o Helloworld.o Helloworld.asm
ld -o Helloworld Helloworld.o
./Helloworld.o
#to check the return value of the program you can do
echo $?
What are the fundamental data types?
byte - 8 bits word - 16 bits double word - 32 bits quad word - 64 bits double quad word - 128
Signed and unsigned double word?
Signed - 31 bits for value and the 32nd bit for the sign
Unsigned for all 32 bits