-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmemory.mu4
87 lines (68 loc) · 2.9 KB
/
memory.mu4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
loading PIC18 memory
decimal
( Define the basics of the target's memory.)
2 constant bytes/cell
-d little-endian
ld target/common/memory.mu4 ( generic memory image support)
| Program memory addresses are 22 bits. The PC is 21 bits, but the largest
| PIC18 parts have only 128 KiB of flash.
|
| I've have only compared two subfamilies - PIC18F1xK50 and the PIC18-Q -
| but it seems that there are *standard* regions defined for the flash, but
| not every chip defines all of them.
|
| The 1xK50, for example, defines Flash, User ID, and Config space, and
| folds the device ID and revision ID into one word at 3f_fffe. The -Q series
| defines *all* of the following:
|
| Flash : 00_0000 - 1f_ffff
| User IDs : 20_0000 - 20_001f
| Device info area : 2c_0000 - 2c_00ff
| Config words : 30_0000 - 30_????
| EEPROM : 38_0000 - 38_????
| Device config info: 3c_0000 - 3c_????
| Revision ID : 3f_fffc - 3f_fffd
| Device ID : 3f_fffe - 3f_ffff
| Let's define constants for the origins of each of the Flash areas,
| whether they exist or not.
"20_0000 constant @user-id
"2c_0000 constant @device-info ( unique ID, calibration info)
"30_0000 constant @config
"38_0000 constant @eeprom
"3c_0000 constant @device-config ( erase page size, number of flash pages, etc)
"3f_fffc constant @revision-id
"3f_fffe constant @device-id
( Two memory aspaces: flash/id/config/eeprom, and data [ram + i/o].)
22 make-aspace ( flash/id/config/eeprom)
dup #flash make-image
dup make-region flash
make-region boot
dup 256 make-image ( XXX how big is big enough?)
make-region user-id
dup 256 make-image ( XXX how big is big enough?)
make-region config
#eeprom make-image
make-region eeprom
| XXX Is the flash space choose-image totally chip-specific? Or can we do
| something like this for everything:
-: ( target) ( choose an image from an address in flash space)
dup @user-id u< if drop flash ^ then
dup @config u< if drop user-id ^ then
@eeprom u< if config ^ then
eeprom ;
( Install choose-image in the flash aspace.)
flash 'choose-image !
| Since on some PIC18 families the ram starts at a non-zero offset into
| data space - specifically, at @ram - we want to make sure that the ram
| region - from @ram to @ram #ram + - fits into the ram image, which needs to
| be a power of 2 in size.
|
| The easiest way to do this is to take the larger of @ram and #ram - we
| assume they are both powers of 2! - and double it.
( For the data aspace we keep the default of "drop" for choose-image.)
16 make-aspace ( data: ram + i/o)
@ram #ram max 2* make-image ( ensure that [@ram #ram +] is within the ram image)
make-region ram