131 Week 11/12 - Memory layout Flashcards

1
Q

64 bit processors

A

In theory they can address 2^64 bytes of byte addressable memory but currently all addresses are not needed to be used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Virtual memory

A

Read/write operations use virtual memory addresses.
Memory management unit (MMU) in microprocessor uses a lookup table called translation lookaside buffer (TLB) to translate virtual
to physical addresses.
OS dynamically allocates pages (4KB per page for x86 architecture) to process and create entries in TLB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Virtual memory layout

A

//high address
- OS Kernel: Memory reserved by the OS to monitor and control mapping between physical and virtual addresses.
- STACK: Data needed by function calls, including arguments and local variables. The set of values pushed for one function call is referred to as a stack frame.
- HEAP: Dynamic memory allocation for variables whose size is known at runtime and cannot be statically determined by the compiler before program execution (e.g., malloc, new, free, delete).
- BSS Global variables that are initialized to zero or do not have explicit initialization.
- DATA: Global variables that have been initialized.
- TEXT: The binary executable instructions of a program.
//low address

Stack and heap will grow from the top and bottom of the unused memory space respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Stack pointers

A

Stack pointer (SP): points to the lowest address of the stack for the current frame.
Frame pointer (FP)/ base pointer (BP): points to a reference address of the previous frame.
Saved instruction pointer (IP): points to the address that the function will return to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Stack layout

A

Stack is made up of frames.
Frame is made up of:
- function parameters
- saved instruction pointer (IP)
- saved base pointer (BP)
- locally declared variables
Parameter values are pushed in reverse order, so that the first parameter will be the last to be pushed to the stack.
Each function call will have its own stack frame in the stack. Frames will be removed from the stack when the function has fully executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Examining the stack

A
  1. Use lscpu to find if CPU architecture is little or big endian.
  2. Develop code to examine
  3. Use -g flag to compile to include debug info in executable
  4. Set breakpoints for when you want to examine the stack. Run the code using run. Use info stack at breakpoints to display the call stack
  5. Can use info frame int to examine a specific frame where int is a number referring to a stack frame.
  6. Can use info reg to print contents of registers.
  7. Can use disass frameName to see contents of a frame
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Visualising memory

A

can use command x/intcharx address to examine memory.
char specifies the type to examine
int specifies how many of the types are examined
address is the starting address to be examined from
e.g., x/28xw $sp examines 28 words from the address of stack pointer.
x/40xb &s examines 40 bytes from the address of s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Flash memory

A

Non-volatile memory. Not as fast as RAM but faster than hard disks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Random access memory (RAM)

A

Volatile memory that can be static (SRAM – used for the cache of the CPU to store common instructions) or dynamic (DRAM – used as the main memory).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

nRF52833 System on Chip memory map

A

Device: 1.5GB
RAM: 1GB
Peripheral
SRAM
Code: 512MB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

memory mapped IO

A

Allows microcontroller to interact with peripherals and devices (general purpose IO - GPIO) by reading from and writing to predefined memory addresses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

nRF52833 System on Chip memory map when Bluetooth is disabled

A

SRAM {
RAM, 127.98 KB
NONIT, 16B: Memory area that persists across micro:bit resets. E.g., tracking how many time reset has been pressed so Bluetooth pairing can be activated.

Code {
UCIR, 8B: UICR: User Information Configuration Register (reserved).
Storage, 4KB
Flash, 508KB: Long term non-volatile data (e.g., calibration data for the sensors). }

RAM stores stack, heap, BSS, data. Flash stores text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

nRF52833 System on Chip memory map when Bluetooth is enabled

A

SRAM {
Same for if Bluetooth is enabled or disabled. }

Code {
Settings, 8KB: Holds similar information to ‘Storage’ as well as Bluetooth pairing keys and state.
Bootloader, 28KB: Memory area for over-the-air firmware updates.
SD, 108KB: soft device, area that holds information about the Bluetooth low energy (BLE) protocol.
MBR, 4KB: Master Boot Record

RAM stores stack, heap, BSS, data. Flash stores text.
Text size is decreased when Bluetooth is enabled so code cannot be as large.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly