You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added %claude: paragraphs for all 12 %yoann: tags: graphics/network
coherence note, clever C warning, optional prerequisites, NOP/ERRSTR,
BRK meaning, directory syscall variants, security syscalls, BY2V name,
floating point intro, MMU page table ASCII diagram, VIRTIO address
space ASCII diagram, calling convention ASCII diagram with C vs syscall.
Fixed high vectors %claude: paragraph to address %yoann1: chicken-and-egg
concern (MMU must be set up before switching to high vectors).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
emulation). These issues are discussed in the Advanced Topics
1431
+
chapter.
1356
1432
1357
1433
\subsection{ARM MMU}
1358
1434
@@ -1378,6 +1454,25 @@ The basic unit of memory managed by the MMU is a {page},
1378
1454
which on ARM (and on x86) is 4~KiB:
1379
1455
1380
1456
%yoann: maybe ASCII diagram already useful here?
1457
+
%claude:
1458
+
The MMU translates virtual addresses to physical addresses
1459
+
using a two-level page table. The virtual address is split
1460
+
into fields that index into the tables:
1461
+
\begin{verbatim}
1462
+
31 20 19 12 11 0
1463
+
+------------+-----------+------------+
1464
+
| L1 index | L2 index | page offset|
1465
+
| (12 bits) | (8 bits) | (12 bits) |
1466
+
+-----+------+-----+-----+-----+------+
1467
+
| | |
1468
+
v v v
1469
+
+--------+ +--------+ +------+
1470
+
| L1 |-->| L2 |-->| byte |
1471
+
| table | | table | | in |
1472
+
| (4096 | | (256 | | page |
1473
+
| entries)| | entries)| | |
1474
+
+--------+ +--------+ +------+
1475
+
\end{verbatim}
1381
1476
1382
1477
% put BY2PG here cos referenced a few times.
1383
1478
<<constant [[BY2PG]](arm)>>=
@@ -1577,6 +1672,39 @@ the windowing system uses this framebuffer.
1577
1672
@
1578
1673
1579
1674
%yoann: maybe ASCII diagram showing "address space" of VIRTIO and how it's used by the different devices. what is the total size of the memory-mapped IO space?
1675
+
%claude:
1676
+
The following diagram summarizes the I/O register layout
1677
+
as offsets from [[VIRTIO]] ([[0x7E000000]]):
1678
+
\begin{verbatim}
1679
+
VIRTIO + 0x000000 +-----------------+
1680
+
| (base) |
1681
+
VIRTIO + 0x003000 +-----------------+
1682
+
| SYSTIMERS |
1683
+
VIRTIO + 0x007000 +-----------------+
1684
+
| DMAREGS |
1685
+
VIRTIO + 0x100000 +-----------------+
1686
+
| POWERREGS |
1687
+
VIRTIO + 0x200000 +-----------------+
1688
+
| GPIOREGS |
1689
+
VIRTIO + 0x215000 +-----------------+
1690
+
| AUXREGS (UART) |
1691
+
VIRTIO + 0x300000 +-----------------+
1692
+
| EMMCREGS (SD) |
1693
+
VIRTIO + 0x980000 +-----------------+
1694
+
| USBREGS |
1695
+
VIRTIO + 0xB200 +-----------------+
1696
+
| INTREGS |
1697
+
VIRTIO + 0xB400 +-----------------+
1698
+
| ARMTIMER |
1699
+
VIRTIO + 0xB880 +-----------------+
1700
+
| MAILBOX (GPU) |
1701
+
+-----------------+
1702
+
VIRTIO + IOSIZE (0x7E000000 + 16 MiB)
1703
+
\end{verbatim}
1704
+
%claude:
1705
+
The total I/O space is [[IOSIZE]] (16~MiB), though only
1706
+
a small fraction of that range is actually used by device
1707
+
registers. The rest is simply unmapped.
1580
1708
1581
1709
%\subsection{Exceptions}
1582
1710
@@ -1612,6 +1740,33 @@ cares about.
1612
1740
1613
1741
%yoann: ASCII diagram for calling conventions, and also C vs kernel
1614
1742
% calling convention
1743
+
%claude:
1744
+
Here is the stack layout when a C function [[foo(a, b, c)]]
1745
+
calls [[bar(x, y)]]:
1746
+
\begin{verbatim}
1747
+
+-------------+
1748
+
| c (arg 3) | 12(FP) for foo
1749
+
+-------------+
1750
+
| b (arg 2) | 8(FP)
1751
+
+-------------+
1752
+
| a (arg 1) | 4(FP)
1753
+
+-------------+
1754
+
| return addr | 0(FP) = saved R14
1755
+
SP ---> +-------------+
1756
+
| y (arg 2) | 8(SP) for bar
1757
+
+-------------+
1758
+
| x (arg 1) | 4(SP)
1759
+
+-------------+
1760
+
| (R14 save) | 0(SP)
1761
+
+-------------+
1762
+
\end{verbatim}
1763
+
%claude:
1764
+
For syscalls, the convention is different: the syscall number
1765
+
goes in [[R0]] (not on the stack), and the [[SWI]] instruction
1766
+
traps into the kernel. The kernel then reads the user's stack
1767
+
to find the syscall arguments. This is why the [[Syscall]]
1768
+
typedef takes a [[ulong*]]---it points to the arguments on
1769
+
the user's stack.
1615
1770
1616
1771
% kencc extensions: anon field. e.g. Lock; but sugar, not that important.
0 commit comments