wswan:guide:memory_management
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wswan:guide:memory_management [2024/12/27 19:43] – asie | wswan:guide:memory_management [2025/08/15 10:33] (current) – [Advanced section names] asie | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| * The combined segmentation and banking benefits from a ROM layouting scheme which takes it into account. | * The combined segmentation and banking benefits from a ROM layouting scheme which takes it into account. | ||
| - | ===== Addressing RAM and ROM ===== | + | ===== Addressing RAM and ROM in C ===== |
| In a C environment, | In a C environment, | ||
| Line 13: | Line 13: | ||
| <code C> | <code C> | ||
| - | // The variable below will be stored in IRAM, even if it's declared const. | + | // The variable below will be stored in IRAM, even if it's declared |
| static const uint16_t table_iram[] = {0, 1, 2, 3}; | static const uint16_t table_iram[] = {0, 1, 2, 3}; | ||
| - | // The variable below will now be stored in ROM instead of IRAM. | + | // The variable below will now be stored in ROM instead of IRAM, as it is read-only and far. |
| static const uint16_t __far table[] = {0, 1, 2, 3}; | static const uint16_t __far table[] = {0, 1, 2, 3}; | ||
| + | |||
| + | // As will this one, except it's not static, so you can reference it in a .h file... | ||
| + | const uint16_t __far global_table[] = {0, 1, 2, 3}; | ||
| + | |||
| + | // ... like so. | ||
| + | extern const uint16_t __far global_table[]; | ||
| void process_table_iram(uint16_t *tbl); // This function can accept pointers to IRAM only. | void process_table_iram(uint16_t *tbl); // This function can accept pointers to IRAM only. | ||
| Line 33: | Line 39: | ||
| * '' | * '' | ||
| - | ===== Placing | + | ===== Addressing RAM and ROM in assembly |
| + | |||
| + | The linker places code and data in RAM and ROM using sections. These sections are used by default by the C compiler: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | Note that these act as prefixes - '' | ||
| + | |||
| + | To address RAM and ROM in assembly, one can use these very same sections manually. | ||
| + | |||
| + | < | ||
| + | .section .fartext.my_rom_code_segment, | ||
| + | .section .farrodata.my_rom_data_segment, | ||
| + | .section .text.my_ram_code, | ||
| + | .section .data.my_ram_data, | ||
| + | </ | ||
| + | |||
| + | The quoted component at the end, like ''" | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | All section flags are listed in [[https:// | ||
| - | By default, as discussed above, the following types of code and data will be placed into the following locations by the linker: | + | ===== Advanced section names ===== |
| - | * Code ('' | + | What if you want to place your code or data in a specific area of RAM? On the WonderSwan, especially the Color model, there are [[https:// |
| - | * Data without such a modifier ('' | + | |
| - | However, on the WonderSwan, especially the Color model, there are [[https:// | + | To make this possible, Wonderful' |
| <code C> | <code C> | ||
| Line 72: | Line 105: | ||
| with the following optional arguments: | with the following optional arguments: | ||
| - | * **bank index** - the index of a bank, padded to the top of ROM. | + | * **bank index** - the index of a bank, in hexadecimal, padded to the top of ROM. For example, '' |
| - | * **offset** - the absolute offset within a bank or memory location. | + | * **offset** - the absolute offset within a bank or memory location, in hexademical. For example, '' |
| Note that the linker requires // | Note that the linker requires // | ||
wswan/guide/memory_management.1735328606.txt.gz · Last modified: by asie
