@micro-os-plus/architecture-riscv 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/CMakeLists.txt +87 -0
  3. package/LICENSE +21 -0
  4. package/README.md +317 -0
  5. package/include/micro-os-plus/architecture-riscv/core-functions-inlines.h +86 -0
  6. package/include/micro-os-plus/architecture-riscv/core-functions.h +105 -0
  7. package/include/micro-os-plus/architecture-riscv/csr-functions-inlines.h +466 -0
  8. package/include/micro-os-plus/architecture-riscv/csr-functions.h +241 -0
  9. package/include/micro-os-plus/architecture-riscv/declarations.h +58 -0
  10. package/include/micro-os-plus/architecture-riscv/defines.h +185 -0
  11. package/include/micro-os-plus/architecture-riscv/device-functions-inlines.h +235 -0
  12. package/include/micro-os-plus/architecture-riscv/device-functions.h +166 -0
  13. package/include/micro-os-plus/architecture-riscv/instructions-inlines.h +172 -0
  14. package/include/micro-os-plus/architecture-riscv/instructions.h +153 -0
  15. package/include/micro-os-plus/architecture-riscv/platform-functions-inlines.h +81 -0
  16. package/include/micro-os-plus/architecture-riscv/platform-functions.h +75 -0
  17. package/include/micro-os-plus/architecture-riscv/plic-functions.h +278 -0
  18. package/include/micro-os-plus/architecture-riscv/semihosting-inlines.h +79 -0
  19. package/include/micro-os-plus/architecture-riscv/types.h +135 -0
  20. package/include/micro-os-plus/architecture.h +38 -0
  21. package/linker-scripts/README.md +7 -0
  22. package/linker-scripts/sections-flash.ld +425 -0
  23. package/linker-scripts/sections-ram.ld +425 -0
  24. package/linker-scripts/sections.ld +377 -0
  25. package/meson.build +46 -0
  26. package/package.json +37 -0
  27. package/src/.gitkeep +0 -0
  28. package/xpack.json +23 -0
@@ -0,0 +1,105 @@
1
+ /*
2
+ * This file is part of the µOS++ distribution.
3
+ * (https://github.com/micro-os-plus/)
4
+ * Copyright (c) 2017 Liviu Ionescu.
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software
7
+ * for any purpose is hereby granted, under the terms of the MIT license.
8
+ *
9
+ * If a copy of the license was not distributed with this file, it can
10
+ * be obtained from https://opensource.org/licenses/MIT/.
11
+ */
12
+
13
+ #ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_CORE_FUNCTIONS_H_
14
+ #define MICRO_OS_PLUS_ARCHITECTURE_RISCV_CORE_FUNCTIONS_H_
15
+
16
+ // ----------------------------------------------------------------------------
17
+
18
+ #include <stdint.h>
19
+
20
+ // ----------------------------------------------------------------------------
21
+ // RISC-V core support functions.
22
+
23
+ #if defined(__cplusplus)
24
+ extern "C"
25
+ {
26
+ #endif // defined(__cplusplus)
27
+
28
+ // --------------------------------------------------------------------------
29
+ // Support functions.
30
+
31
+ uint32_t
32
+ riscv_core_get_running_frequency_hz (void);
33
+
34
+ void
35
+ riscv_core_update_running_frequency (void);
36
+
37
+ static void
38
+ riscv_core_enable_machine_external_interrupts (void);
39
+
40
+ static void
41
+ riscv_core_disable_machine_external_interrupts (void);
42
+
43
+ /**
44
+ * Hardware trap entry point (assembly).
45
+ */
46
+ void
47
+ riscv_trap_entry (void);
48
+
49
+ // --------------------------------------------------------------------------
50
+
51
+ #if defined(__cplusplus)
52
+ }
53
+ #endif // defined(__cplusplus)
54
+
55
+ // ============================================================================
56
+
57
+ #if defined(__cplusplus)
58
+
59
+ // ----------------------------------------------------------------------------
60
+
61
+ namespace riscv
62
+ {
63
+ namespace core
64
+ {
65
+ // ------------------------------------------------------------------------
66
+ // Support functions.
67
+
68
+ /**
69
+ * Get the previously computed CPU frequency.
70
+ */
71
+ uint32_t
72
+ running_frequency_hz (void);
73
+
74
+ /**
75
+ * Compute the CPU frequency. Call this after changing the
76
+ * clock settings.
77
+ */
78
+ void
79
+ update_running_frequency (void);
80
+
81
+ /**
82
+ * @brief Enable external interrupts (used by PLIC).
83
+ */
84
+ void
85
+ enable_machine_external_interrupts (void);
86
+
87
+ /**
88
+ * @brief Disable external interrupts (used by PLIC).
89
+ */
90
+ void
91
+ disable_machine_external_interrupts (void);
92
+
93
+ // ------------------------------------------------------------------------
94
+ } // namespace core
95
+ } // namespace riscv
96
+
97
+ // ----------------------------------------------------------------------------
98
+
99
+ #endif // defined(__cplusplus)
100
+
101
+ // ----------------------------------------------------------------------------
102
+
103
+ #endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_CORE_FUNCTIONS_H_
104
+
105
+ // ----------------------------------------------------------------------------
@@ -0,0 +1,466 @@
1
+ /*
2
+ * This file is part of the µOS++ distribution.
3
+ * (https://github.com/micro-os-plus/)
4
+ * Copyright (c) 2017 Liviu Ionescu.
5
+ *
6
+ * Permission to use, copy, modify, and/or distribute this software
7
+ * for any purpose is hereby granted, under the terms of the MIT license.
8
+ *
9
+ * If a copy of the license was not distributed with this file, it can
10
+ * be obtained from https://opensource.org/licenses/MIT/.
11
+ */
12
+
13
+ #ifndef MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_INLINES_H_
14
+ #define MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_INLINES_H_
15
+
16
+ // ----------------------------------------------------------------------------
17
+
18
+ #include <stdint.h>
19
+
20
+ // ----------------------------------------------------------------------------
21
+ // Inline implementations for the RISC-V core support functions.
22
+
23
+ #if defined(__cplusplus)
24
+ extern "C"
25
+ {
26
+ #endif // defined(__cplusplus)
27
+
28
+ // --------------------------------------------------------------------------
29
+
30
+ #if 0
31
+ // Not available, due to ISA limitations (no 'r' to pass the CSR,
32
+ // mandatory on -O0, even when called with constants).
33
+
34
+ inline riscv_architecture_register_t
35
+ __attribute__((always_inline))
36
+ riscv_csr_read (uint32_t reg)
37
+ {
38
+ riscv_architecture_register_t tmp;
39
+
40
+ __asm__ volatile (
41
+ "csrr %[r],%[csr]"
42
+
43
+ : [r] "=rm"(tmp) /* Outputs */
44
+ : [csr] "ri"(reg) /* Inputs */
45
+ : /* Clobbers */
46
+ );
47
+ return tmp;
48
+ }
49
+
50
+ #endif
51
+
52
+ // --------------------------------------------------------------------------
53
+
54
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
55
+ riscv_csr_read_mstatus (void)
56
+ {
57
+ riscv_architecture_register_t tmp;
58
+
59
+ __asm__ volatile(
60
+
61
+ "csrr %[r],mstatus"
62
+
63
+ : [r] "=r"(tmp) /* Outputs */
64
+ : /* Inputs */
65
+ : /* Clobbers */
66
+ );
67
+
68
+ return tmp;
69
+ }
70
+
71
+ static inline __attribute__ ((always_inline)) void
72
+ riscv_csr_write_mstatus (riscv_architecture_register_t value)
73
+ {
74
+ __asm__ volatile(
75
+
76
+ "csrw mstatus,%[v]"
77
+
78
+ : /* Outputs */
79
+ : [v] "rK"(value) /* Inputs */
80
+ : /* Clobbers */
81
+ );
82
+ }
83
+
84
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
85
+ riscv_csr_clear_mstatus_bits (riscv_architecture_register_t mask)
86
+ {
87
+ riscv_architecture_register_t tmp;
88
+
89
+ __asm__ volatile(
90
+
91
+ "csrrc %[r],mstatus,%[v]"
92
+
93
+ : [r] "=r"(tmp) /* Outputs */
94
+ : [v] "rK"(mask) /* Inputs */
95
+ : /* Clobbers */
96
+ );
97
+
98
+ return tmp;
99
+ }
100
+
101
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
102
+ riscv_csr_set_mstatus_bits (riscv_architecture_register_t mask)
103
+ {
104
+ riscv_architecture_register_t tmp;
105
+
106
+ __asm__ volatile(
107
+
108
+ "csrrs %[r],mstatus,%[v]"
109
+
110
+ : [r] "=r"(tmp) /* Outputs */
111
+ : [v] "rK"(mask) /* Inputs */
112
+ : /* Clobbers */
113
+ );
114
+
115
+ return tmp;
116
+ }
117
+
118
+ // --------------------------------------------------------------------------
119
+
120
+ /**
121
+ * Read `mtvec` CSR.
122
+ */
123
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
124
+ riscv_csr_read_mtvec (void)
125
+ {
126
+ riscv_architecture_register_t tmp;
127
+
128
+ __asm__ volatile(
129
+
130
+ "csrr %[r],mtvec"
131
+
132
+ : [r] "=r"(tmp) /* Outputs */
133
+ : /* Inputs */
134
+ : /* Clobbers */
135
+ );
136
+
137
+ return tmp;
138
+ }
139
+
140
+ /**
141
+ * Write `mtvec` CSR.
142
+ */
143
+ static inline __attribute__ ((always_inline)) void
144
+ riscv_csr_write_mtvec (riscv_architecture_register_t value)
145
+ {
146
+ __asm__ volatile(
147
+
148
+ "csrw mtvec,%[v]"
149
+
150
+ : /* Outputs */
151
+ : [v] "rK"(value) /* Inputs */
152
+ : /* Clobbers */
153
+ );
154
+ }
155
+
156
+ // --------------------------------------------------------------------------
157
+
158
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
159
+ riscv_csr_read_mcause (void)
160
+ {
161
+ riscv_architecture_register_t tmp;
162
+
163
+ __asm__ volatile(
164
+
165
+ "csrr %[r],mcause"
166
+
167
+ : [r] "=r"(tmp) /* Outputs */
168
+ : /* Inputs */
169
+ : /* Clobbers */
170
+ );
171
+
172
+ return tmp;
173
+ }
174
+
175
+ // --------------------------------------------------------------------------
176
+
177
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
178
+ riscv_csr_read_mie (void)
179
+ {
180
+ riscv_architecture_register_t tmp;
181
+
182
+ __asm__ volatile(
183
+
184
+ "csrr %[r],mie"
185
+
186
+ : [r] "=r"(tmp) /* Outputs */
187
+ : /* Inputs */
188
+ : /* Clobbers */
189
+ );
190
+
191
+ return tmp;
192
+ }
193
+
194
+ static inline __attribute__ ((always_inline)) void
195
+ riscv_csr_write_mie (riscv_architecture_register_t value)
196
+ {
197
+ __asm__ volatile(
198
+
199
+ "csrw mie,%[v]"
200
+
201
+ : /* Outputs */
202
+ : [v] "rK"(value) /* Inputs */
203
+ : /* Clobbers */
204
+ );
205
+ }
206
+
207
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
208
+ riscv_csr_clear_mie_bits (riscv_architecture_register_t mask)
209
+ {
210
+ riscv_architecture_register_t tmp;
211
+
212
+ __asm__ volatile(
213
+
214
+ "csrrc %[r],mie,%[v]"
215
+
216
+ : [r] "=r"(tmp) /* Outputs */
217
+ : [v] "rK"(mask) /* Inputs */
218
+ : /* Clobbers */
219
+ );
220
+
221
+ return tmp;
222
+ }
223
+
224
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
225
+ riscv_csr_set_mie_bits (riscv_architecture_register_t mask)
226
+ {
227
+ riscv_architecture_register_t tmp;
228
+
229
+ __asm__ volatile(
230
+
231
+ "csrrs %[r],mie,%[v]"
232
+
233
+ : [r] "=r"(tmp) /* Outputs */
234
+ : [v] "rK"(mask) /* Inputs */
235
+ : /* Clobbers */
236
+ );
237
+
238
+ return tmp;
239
+ }
240
+
241
+ // --------------------------------------------------------------------------
242
+
243
+ #if __riscv_xlen == 64
244
+
245
+ /**
246
+ * Read `mcycle` CSR.
247
+ */
248
+ static inline __attribute__ ((always_inline)) uint64_t
249
+ riscv_csr_read_mcycle (void)
250
+ {
251
+ riscv_architecture_register_t tmp;
252
+
253
+ __asm__ volatile(
254
+
255
+ "csrr %[r],mcycle"
256
+
257
+ : [r] "=rm"(tmp) /* Outputs */
258
+ : /* Inputs */
259
+ : /* Clobbers */
260
+ );
261
+ return tmp;
262
+ }
263
+
264
+ #endif // __riscv_xlen == 64
265
+
266
+ static inline __attribute__ ((always_inline)) uint32_t
267
+ riscv_csr_read_mcycle_low (void)
268
+ {
269
+ #if __riscv_xlen == 32
270
+
271
+ uint32_t tmp;
272
+
273
+ __asm__ volatile(
274
+
275
+ "csrr %[r],mcycle"
276
+
277
+ : [r] "=rm"(tmp) /* Outputs */
278
+ : /* Inputs */
279
+ : /* Clobbers */
280
+ );
281
+ return tmp;
282
+
283
+ #elif __riscv_xlen == 64
284
+
285
+ return (uint32_t)riscv_csr_read_mcycle ();
286
+
287
+ #endif // __riscv_xlen
288
+ }
289
+
290
+ static inline __attribute__ ((always_inline)) uint32_t
291
+ riscv_csr_read_mcycle_high (void)
292
+ {
293
+ #if __riscv_xlen == 32
294
+
295
+ uint32_t tmp;
296
+
297
+ __asm__ volatile(
298
+
299
+ "csrr %[r],mcycleh"
300
+
301
+ : [r] "=rm"(tmp) /* Outputs */
302
+ : /* Inputs */
303
+ : /* Clobbers */
304
+ );
305
+ return tmp;
306
+
307
+ #elif __riscv_xlen == 64
308
+
309
+ return (uint32_t) (riscv_csr_read_mcycle () >> 32);
310
+
311
+ #endif // __riscv_xlen
312
+ }
313
+
314
+ // --------------------------------------------------------------------------
315
+
316
+ static inline __attribute__ ((always_inline)) riscv_architecture_register_t
317
+ riscv_csr_read_mhartid (void)
318
+ {
319
+ riscv_architecture_register_t tmp;
320
+
321
+ __asm__ volatile(
322
+
323
+ "csrr %[r],mhartid"
324
+
325
+ : [r] "=r"(tmp) /* Outputs */
326
+ : /* Inputs */
327
+ : /* Clobbers */
328
+ );
329
+ return tmp;
330
+ }
331
+
332
+ // --------------------------------------------------------------------------
333
+
334
+ #if defined(__cplusplus)
335
+ }
336
+ #endif // defined(__cplusplus)
337
+
338
+ // ============================================================================
339
+
340
+ #if defined(__cplusplus)
341
+
342
+ // ----------------------------------------------------------------------------
343
+
344
+ namespace riscv
345
+ {
346
+ namespace csr
347
+ {
348
+ // ------------------------------------------------------------------------
349
+
350
+ inline __attribute__ ((always_inline)) architecture::register_t
351
+ mstatus (void)
352
+ {
353
+ return riscv_csr_read_mstatus ();
354
+ }
355
+
356
+ inline __attribute__ ((always_inline)) void
357
+ mstatus (architecture::register_t value)
358
+ {
359
+ riscv_csr_write_mstatus (value);
360
+ }
361
+
362
+ inline __attribute__ ((always_inline)) void
363
+ clear_mstatus_bits (architecture::register_t mask)
364
+ {
365
+ riscv_csr_clear_mstatus_bits (mask);
366
+ }
367
+
368
+ inline __attribute__ ((always_inline)) void
369
+ set_mstatus_bits (architecture::register_t mask)
370
+ {
371
+ riscv_csr_set_mstatus_bits (mask);
372
+ }
373
+
374
+ // ------------------------------------------------------------------------
375
+
376
+ inline __attribute__ ((always_inline)) architecture::register_t
377
+ mtvec (void)
378
+ {
379
+ return riscv_csr_read_mtvec ();
380
+ }
381
+
382
+ inline __attribute__ ((always_inline)) void
383
+ mtvec (architecture::register_t value)
384
+ {
385
+ riscv_csr_write_mtvec (value);
386
+ }
387
+
388
+ // ------------------------------------------------------------------------
389
+
390
+ inline __attribute__ ((always_inline)) architecture::register_t
391
+ mcause (void)
392
+ {
393
+ return riscv_csr_read_mcause ();
394
+ }
395
+
396
+ // ------------------------------------------------------------------------
397
+
398
+ inline __attribute__ ((always_inline)) architecture::register_t
399
+ mie (void)
400
+ {
401
+ return riscv_csr_read_mie ();
402
+ }
403
+
404
+ inline __attribute__ ((always_inline)) void
405
+ mie (architecture::register_t value)
406
+ {
407
+ riscv_csr_write_mie (value);
408
+ }
409
+
410
+ inline __attribute__ ((always_inline)) void
411
+ clear_mie_bits (architecture::register_t mask)
412
+ {
413
+ riscv_csr_clear_mie_bits (mask);
414
+ }
415
+
416
+ inline __attribute__ ((always_inline)) void
417
+ set_mie_bits (architecture::register_t mask)
418
+ {
419
+ riscv_csr_set_mie_bits (mask);
420
+ }
421
+
422
+ // ------------------------------------------------------------------------
423
+
424
+ #if __riscv_xlen == 64
425
+
426
+ inline __attribute__ ((always_inline)) uint64_t
427
+ mcycle (void)
428
+ {
429
+ return riscv_csr_read_mcycle ();
430
+ }
431
+
432
+ #endif // __riscv_xlen == 64
433
+
434
+ inline __attribute__ ((always_inline)) uint32_t
435
+ mcycle_low (void)
436
+ {
437
+ return riscv_csr_read_mcycle_low ();
438
+ }
439
+
440
+ inline __attribute__ ((always_inline)) uint32_t
441
+ mcycle_high (void)
442
+ {
443
+ return riscv_csr_read_mcycle_high ();
444
+ }
445
+
446
+ // ------------------------------------------------------------------------
447
+
448
+ inline __attribute__ ((always_inline)) architecture::register_t
449
+ mhartid (void)
450
+ {
451
+ return riscv_csr_read_mhartid ();
452
+ }
453
+
454
+ // ------------------------------------------------------------------------
455
+ } // namespace csr
456
+ } // namespace riscv
457
+
458
+ // ----------------------------------------------------------------------------
459
+
460
+ #endif // defined(__cplusplus)
461
+
462
+ // ----------------------------------------------------------------------------
463
+
464
+ #endif // MICRO_OS_PLUS_ARCHITECTURE_RISCV_CSR_FUNCTIONS_INLINES_H_
465
+
466
+ // ----------------------------------------------------------------------------