diff --git a/4.md b/4.md new file mode 100644 index 0000000..e965e6a --- /dev/null +++ b/4.md @@ -0,0 +1,113 @@ +# Memory + +## Default Memory Access Permissions + +The Cortex-M3 memory map has a default configuration for memory access permissions +Default memory access permission is used when either: +* No MPU is present +* MPU is present but disabled +Otherwise MPU will determine +When a memory access is blocked the fault exception takes place immediately. + +```python { cmd matplotlib hide } + +import pymupdf + +from PIL import Image + +doc = pymupdf.open("./pdf/L4.pdf") + +pix = doc[12].get_pixmap() +img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples) +plt.axis('off') +plt.subplots_adjust(left=0, right=1, top=1, bottom=0) +plt.imshow(img) + +plt.show() + +``` + +## MPU(Memory Protection Unit) + +MPU + +Regions can be overlapped only in ARMv7 + +## Bit-Band Operations + +it allows a single load/store opertation to access a **single data bit**. + +Bit-band regions: +* The first 1MB of the SRAM region +* The first 1MB of theperipheral region + +They can be accessed via a separate memory region called the bit-band alias. + +Bit-Banding done transparently by **bus matrix**. + +### Write to Bit-Band Alias + +* Without Bit-Band: +```armasm +LDR R0, =0x20000000 ; Setup address +LDR R1, [R0] ; Read +ORR.W R1, #0x4 ; Modify bit +STR R1, [R0] ; Write back result +``` + +* With Bit-Band: +```armasm +LDR R0, =0x22000008 ; Setup address +MOV R1, #1 ; Setup data +STR R1, [R0] ; Write +``` + + +### Read from the Bit-Band Alias + +To get bit 2 in word data in address `0x20000000`: +* Without +```armasm +LDR R0, =0x20000000 ; Setup address +LDR R1, [R0] ; Read +UBFX.W R1, R1, #2, #1 ; Extract Bit[2] +``` + +* With +```armasm +LDR R0, = 0x22000008 ; Setup address +LDR R1, [R0] ; Read +``` + +### Advantages of using bit-band ops + +* Faster bit operations with fewer instructions +* Prevent a **race condition** problem in bit modification + + +### Usecase in C + +* There is no native support of bit-band ops in most C compilers + * The simplest solution is to separately declare the address and the bit-band alias of a memory location + +```c +#define DEVICE_REGO *((volatile unsigned long *) 0x40000000) +#define DEVICE REGO_BIT0 *((volatile unsigned long *) 0x42000000) +#define DEVICE REGO_BIT1 *((volatile unsigned long *) 0x42000004) +``` + + +## Unaligned Transfers + +Coretex-M3 optionally supports unaligned transfers on single accesses. +Data memory accesses can be defined as aligned or unaligned. + +Unaligned transfers are converted into multiple aligned transfers by the processor's bus interface unit: +* transparent to application programmers +* it takes more clock cycles for a single data access + +Limitations: +* Not supported in load/store multiple instructions +* Stack operations (PUSH/POP) must be aligned +* Exclusive access must be aligned +* Unaligned transfers are not supported in bit-band ops \ No newline at end of file diff --git a/5.md b/5.md new file mode 100644 index 0000000..e16c777 --- /dev/null +++ b/5.md @@ -0,0 +1,31 @@ +# ARM ISA + +## Syntax of Assembly + +* Label: Define a symbol +``` +label: +``` + +* Instruction +* Directive +``` +.directive[;] +``` +* macro_invocation + +## Assembly Expression + +Expressions consist of one or more integer literals or symbol references, combined using operators. Expression can be used as instruction operands or directive argument. + +Assembler evaluates all expression, which means **no rum-time evaluation**. + +Assembly Expressions are +* Constnats +* Symbol References +* Operators + * Unary Operators: `+`, `-`, `~` + * Binary Operators: `+`, `-`, `*`, `/`, `%` + * Binary Logical Operators: `&&`, `||` + * Binary Bitwise Operators: `&`, `|`, `^`, `>>`, `<<` + * Binary Comparison Operators: `<`, `<=`, `>`, `>=`, `==`, `!=` \ No newline at end of file diff --git a/pdf/L4.pdf b/pdf/L4.pdf new file mode 100644 index 0000000..eca84de --- /dev/null +++ b/pdf/L4.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c83bddb6f3ec48cc3941b0cb6d6e1fff18d763c5b592702fe73c932b26c536a8 +size 853485 diff --git a/pdf/L5.pdf b/pdf/L5.pdf new file mode 100644 index 0000000..55e6601 --- /dev/null +++ b/pdf/L5.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0962f248a9d48faf6c6fafebf73edbae636f026a5564075111253e70ac63ae53 +size 483414 diff --git a/pdf/L6.pdf b/pdf/L6.pdf new file mode 100644 index 0000000..a7e2430 --- /dev/null +++ b/pdf/L6.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25b6bfc90f30335dc080b0b20cb5f47d5f35fecde6c7d9ee227363ee61344ac2 +size 741285