# Memória RAM

### 🧠 Hierarquia Fundamental de Memória

```mermaid
graph TD
    A[CPU] --> B[Registradores 1ns]
    B --> C[Cache L1 2ns]
    C --> D[Cache L2 5ns]
    D --> E[Cache L3 10ns]
    E --> F[RAM 60-100ns]
    F --> G[Armazenamento 5-10ms]
```

### 🖥️ Arquitetura Física da RAM

#### Organização de um Módulo DIMM

```mermaid
graph TB
    subgraph DIMM
        A[PCB] --> B[DRAM Chips]
        A --> C[SPD Chip]
        A --> D[Buffer de Memória]
        B --> E[Bank]
        E --> F[Matriz de Células]
        F --> G[Row/Column Decoder]
    end
```

**Componentes Chave:**

* **Célula DRAM**: 1 Transistor + 1 Capacitor (1T1C)
* **Tamanho do Capacitor**: \~30fF (femtofarads)
* **Tensão de Operação**: 1.2V (DDR4), 1.1V (DDR5)

### ⚡ Tecnologias de Memória

#### Comparativo SDRAM Generations

| Parâmetro       | DDR3        | DDR4         | DDR5         |
| --------------- | ----------- | ------------ | ------------ |
| **Clock Base**  | 800-2133MHz | 1600-3200MHz | 2400-4800MHz |
| **Prefetch**    | 8n          | 8n           | 16n          |
| **Voltagem**    | 1.5V        | 1.2V         | 1.1V         |
| **Bank Groups** | N/A         | 4            | 8            |
| **Channel**     | 64-bit      | 64-bit       | 2x32-bit     |

***

### 🔌 Interface Elétrica

**Sinalização DDR (Double Data Rate):**

```plaintext
Ciclo de Clock:
   ___     ___     ___
__|   |___|   |___|   |___
  ^     ^     ^     ^
  D0    D1    D2    D3  (Transições nos dois bordos)
```

**Timings RAM (CL-tRCD-tRP-tRAS):**

```plaintext
CAS Latency (CL): 15 ciclos (DDR4-3200)
tRCD: 17 ciclos
tRP: 17 ciclos
tRAS: 36 ciclos
```

### ⚙️ Operação de Baixo Nível

#### Refresh DRAM

```c
// Pseudocódigo do ciclo de refresh
void dram_refresh() {
    for(row = 0; row < 2^17; row++) { // 128K rows típicas
        activate_row(row);
        precharge_row(row); 
        // 64ms/8192 = 7.8μs por refresh
    }
}
```

**Problemas de Escala:**

* **Row Hammer**: Acessos repetidos causam bit-flips

  ```python
  # Simulador conceitual de Row Hammer
  def row_hammer(aggressor_row):
      for _ in range(500000):
          read_memory(aggressor_row + 1)
          read_memory(aggressor_row - 1)
  ```

### 🔬 Arquitetura de Banco DRAM

```mermaid
graph LR
    subgraph Bank
        A[Row Buffer] --> B[Matriz 2D]
        B --> C[Linha: 8KB típico]
        C --> D[Célula: 4-8 bits]
    end
```

**Operações Básicas:**

1. **ACTIVATE**: Carrega linha no row buffer
2. **READ/WRITE**: Acessa coluna específica
3. **PRECHARGE**: Descarrega linha

### 📊 Projeto Avançado de Controlador

**Arquitetura DDR5:**

```plaintext
┌──────────────────────┐
│ Memory Controller    │
├──────────────────────┤
│ 2x 32-bit Channels   │
│ ECC On-Die           │
│ Decision Feedback EQ │
└──────────┬───────────┘
           │
┌──────────▼───────────┐
│ PMIC (Power Mgmt IC) │
│ Voltage Regulators   │
│ Temperature Sensors  │
└──────────────────────┘
```

***

### 🛠️ Ferramentas de Análise

**Linux:**

```bash
sudo dmidecode --type memory  # Detalhes dos módulos
sudo edac-util -v  # Verificação de erros ECC
```

**Windows:**

```powershell
Get-WmiObject Win32_PhysicalMemory | Format-Table *
```

**Teste de Estresse:**

```bash
memtester 1G 5  # Testa 1GB por 5 iterações
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://0xmorte.gitbook.io/bibliadopentestbr/conceitos/arquitetura-de-hardware/memoria-ram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
