OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [examples/] [zephyr/] [v1.6.0-riscv64-base.diff] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
diff --git a/arch/Kconfig b/arch/Kconfig
2
index c574947..200f486 100644
3
--- a/arch/Kconfig
4
+++ b/arch/Kconfig
5
@@ -37,6 +37,10 @@ config NIOS2
6
        bool "Nios II Gen 2 architecture"
7
        select ATOMIC_OPERATIONS_C
8
 
9
+config RISCV64
10
+       bool "RISC-V 64-bits architecture"
11
+       select ATOMIC_OPERATIONS_C
12
+
13
 endchoice
14
 
15
 #
16
diff --git a/arch/riscv64/Kbuild b/arch/riscv64/Kbuild
17
new file mode 100644
18
index 0000000..1573726
19
--- /dev/null
20
+++ b/arch/riscv64/Kbuild
21
@@ -0,0 +1,6 @@
22
+subdir-ccflags-y +=-I$(srctree)/include/drivers
23
+subdir-ccflags-y +=-I$(srctree)/drivers
24
+subdir-asflags-y += $(subdir-ccflags-y)
25
+
26
+obj-y += soc/$(SOC_PATH)/
27
+obj-y += core/
28
diff --git a/arch/riscv64/Kconfig b/arch/riscv64/Kconfig
29
new file mode 100644
30
index 0000000..e551376
31
--- /dev/null
32
+++ b/arch/riscv64/Kconfig
33
@@ -0,0 +1,76 @@
34
+# ARC EM4 options
35
+
36
+#
37
+# Copyright (c) 2014 Wind River Systems, Inc.
38
+#
39
+# Licensed under the Apache License, Version 2.0 (the "License");
40
+# you may not use this file except in compliance with the License.
41
+# You may obtain a copy of the License at
42
+#
43
+#     http://www.apache.org/licenses/LICENSE-2.0
44
+#
45
+# Unless required by applicable law or agreed to in writing, software
46
+# distributed under the License is distributed on an "AS IS" BASIS,
47
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48
+# See the License for the specific language governing permissions and
49
+# limitations under the License.
50
+#
51
+
52
+choice
53
+       prompt "RISC-V SoC Selection"
54
+       depends on RISCV64
55
+
56
+       source "arch/riscv64/soc/*/Kconfig.soc"
57
+endchoice
58
+
59
+
60
+menu "RISC-V Options"
61
+       depends on RISCV64
62
+
63
+config ARCH
64
+       default "riscv64"
65
+
66
+config ARCH_DEFCONFIG
67
+       string
68
+       default "arch/riscv64/defconfig"
69
+
70
+config NUM_IRQS
71
+       int
72
+       prompt "Upper limit of interrupt numbers/IDs used"
73
+       range 1 256
74
+       help
75
+         Interrupts available will be 1 to NUM_IRQS-1.
76
+         Interrupt pin 0 is hardcoded as unused.
77
+
78
+config RISCV_SYSTIMER
79
+       bool "Include System Timer"
80
+       default y
81
+
82
+config UART_RISCV_GNSS
83
+       bool "Include UART"
84
+       default y
85
+
86
+config CONSOLE
87
+       bool "Include Console"
88
+       default y
89
+
90
+config SRAM_SIZE
91
+       int "SRAM Size in kB"
92
+       default 256
93
+       help
94
+       This option specifies the size of the SRAM in kB.  It is normally set
95
+       by the platform's defconfig file and the user should generally avoid
96
+       modifying it via the menu configuration.
97
+
98
+config SRAM_BASE_ADDRESS
99
+       hex "SRAM Base Address"
100
+       default 0x10000000
101
+       help
102
+       This option specifies the base address of the SRAM on the platform.  It
103
+       is normally set by the platform's defconfig file and the user should
104
+       generally avoid modifying it via the menu configuration.
105
+
106
+
107
+source "arch/riscv64/soc/*/Kconfig"
108
+
109
+endmenu
110
diff --git a/arch/riscv64/Makefile b/arch/riscv64/Makefile
111
new file mode 100644
112
index 0000000..107faa8
113
--- /dev/null
114
+++ b/arch/riscv64/Makefile
115
@@ -0,0 +1,12 @@
116
+cflags-y += $(call cc-option,-ffunction-sections,) $(call cc-option,-fdata-sections,)
117
+cflags-$(CONFIG_LTO) = $(call cc-option,-flto,)
118
+
119
+soc_ld_include := -I$(srctree)/arch/$(ARCH)/soc/$(SOC_PATH)
120
+arch_cflags += $(soc_ld_include)
121
+EXTRA_LINKER_CMD_OPT += $(soc_ld_include)
122
+
123
+include $(srctree)/arch/$(ARCH)/soc/$(SOC_PATH)/Makefile
124
+
125
+KBUILD_CFLAGS += $(cflags-y)
126
+KBUILD_CFLAGS += -Wno-unused-function
127
+KBUILD_CXXFLAGS += $(cflags-y)
128
diff --git a/arch/riscv64/_howto_build_riscv b/arch/riscv64/_howto_build_riscv
129
new file mode 100644
130
index 0000000..f82fc8a
131
--- /dev/null
132
+++ b/arch/riscv64/_howto_build_riscv
133
@@ -0,0 +1,4 @@
134
+cd samples/shell
135
+export ZEPHYR_BASE=/home/teeshina/svn/20170117_zephyr16/zephyr
136
+make ARCH=riscv64 CROSS_COMPILE=/home/teeshina/riscv/gnu-toolchain-rv64ima/bin/riscv64-unknown-elf- BOARD=riscv_gnss 2>&1 | tee _err.log
137
+elf2raw64 outdir/riscv_gnss/zephyr.elf -h -f 262144 -l 8 -o fwimage.hex
138
diff --git a/arch/riscv64/core/Makefile b/arch/riscv64/core/Makefile
139
new file mode 100644
140
index 0000000..638187f
141
--- /dev/null
142
+++ b/arch/riscv64/core/Makefile
143
@@ -0,0 +1,6 @@
144
+ccflags-y += -I$(srctree)/kernel/nanokernel/include
145
+ccflags-y +=-I$(srctree)/arch/$(ARCH)/include
146
+ccflags-y += -I$(srctree)/kernel/microkernel/include
147
+
148
+obj-y += cpu_idle.o fatal.o gptimers.o \
149
+       irq_manage.o swap.o new_thread.o memaccess.o
150
diff --git a/arch/riscv64/core/cpu_idle.c b/arch/riscv64/core/cpu_idle.c
151
new file mode 100644
152
index 0000000..5f13ec9
153
--- /dev/null
154
+++ b/arch/riscv64/core/cpu_idle.c
155
@@ -0,0 +1,53 @@
156
+/*
157
+ * Copyright (c) 2014 Wind River Systems, Inc.
158
+ *
159
+ * Licensed under the Apache License, Version 2.0 (the "License");
160
+ * you may not use this file except in compliance with the License.
161
+ * You may obtain a copy of the License at
162
+ *
163
+ *     http://www.apache.org/licenses/LICENSE-2.0
164
+ *
165
+ * Unless required by applicable law or agreed to in writing, software
166
+ * distributed under the License is distributed on an "AS IS" BASIS,
167
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
168
+ * See the License for the specific language governing permissions and
169
+ * limitations under the License.
170
+ */
171
+
172
+/**
173
+ * @file
174
+ * @brief CPU power management
175
+ *
176
+ * CPU power management routines.
177
+ */
178
+
179
+#include <toolchain.h>
180
+#include <sections.h>
181
+#include <arch/cpu.h>
182
+
183
+/*
184
+ * @brief Put the CPU in low-power mode
185
+ *
186
+ * This function always exits with interrupts unlocked.
187
+ *
188
+ * void nanCpuIdle(void)
189
+ */
190
+
191
+void nano_cpu_idle(void) {
192
+    _arch_irq_unlock(0);
193
+}
194
+/*
195
+ * @brief Put the CPU in low-power mode, entered with IRQs locked
196
+ *
197
+ * This function exits with interrupts restored to <key>.
198
+ *
199
+ * void nano_cpu_atomic_idle(unsigned int key)
200
+ */
201
+void nano_cpu_atomic_idle(unsigned int key) {
202
+    _arch_irq_unlock(key);
203
+}
204
+
205
+void sys_arch_reboot(int type) {
206
+       ARG_UNUSED(type);
207
+       //DO_REBOOT();
208
+}
209
diff --git a/arch/riscv64/core/fatal.c b/arch/riscv64/core/fatal.c
210
new file mode 100644
211
index 0000000..967e09a
212
--- /dev/null
213
+++ b/arch/riscv64/core/fatal.c
214
@@ -0,0 +1,59 @@
215
+/*
216
+ * Copyright (c) 2013-2014 Wind River Systems, Inc.
217
+ *
218
+ * Licensed under the Apache License, Version 2.0 (the "License");
219
+ * you may not use this file except in compliance with the License.
220
+ * You may obtain a copy of the License at
221
+ *
222
+ *     http://www.apache.org/licenses/LICENSE-2.0
223
+ *
224
+ * Unless required by applicable law or agreed to in writing, software
225
+ * distributed under the License is distributed on an "AS IS" BASIS,
226
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
227
+ * See the License for the specific language governing permissions and
228
+ * limitations under the License.
229
+ */
230
+
231
+/**
232
+ * @file
233
+ * @brief Nanokernel fatal error handler
234
+ *
235
+ * This module provides the _NanoFatalErrorHandler() routine.
236
+ */
237
+
238
+#include <toolchain.h>
239
+#include <sections.h>
240
+
241
+#include <nanokernel.h>
242
+#include <misc/printk.h>
243
+
244
+const NANO_ESF _default_esf = {
245
+       0xdeaddead, /* placeholder */
246
+};
247
+
248
+
249
+/**
250
+ *
251
+ * @brief Nanokernel fatal error handler
252
+ *
253
+ * This routine is called when a fatal error condition is detected by either
254
+ * hardware or software.
255
+ *
256
+ * The caller is expected to always provide a usable ESF.  In the event that the
257
+ * fatal error does not have a hardware generated ESF, the caller should either
258
+ * create its own or use a pointer to the global default ESF <_default_esf>.
259
+ *
260
+ * @param reason the reason that the handler was called
261
+ * @param pEsf pointer to the exception stack frame
262
+ *
263
+ * @return This function does not return.
264
+ */
265
+FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
266
+                                         const NANO_ESF *pEsf)
267
+{
268
+
269
+#ifdef CONFIG_PRINTK
270
+       printk("***** Unhandled interrupt vector %d occurred! \n", -1);
271
+#endif
272
+    while (1) {}
273
+}
274
\ No newline at end of file
275
diff --git a/arch/riscv64/core/gptimers.c b/arch/riscv64/core/gptimers.c
276
new file mode 100644
277
index 0000000..8e5c856
278
--- /dev/null
279
+++ b/arch/riscv64/core/gptimers.c
280
@@ -0,0 +1,7 @@
281
+#include <stdint.h>
282
+
283
+//
284
+uint32_t _do_read_cpu_timestamp32(void) {
285
+    return 500;//READ32();
286
+}
287
+
288
diff --git a/arch/riscv64/core/irq_manage.c b/arch/riscv64/core/irq_manage.c
289
new file mode 100644
290
index 0000000..fb889ac
291
--- /dev/null
292
+++ b/arch/riscv64/core/irq_manage.c
293
@@ -0,0 +1,113 @@
294
+#include <nanokernel.h>
295
+#include <kernel_structs.h>
296
+#include <misc/__assert.h>
297
+#include <board.h>
298
+#include <sw_isr_table.h>
299
+#include <irq.h>
300
+#include <memaccess.h>
301
+
302
+_IsrTableEntry_t isr_demux_table[CONFIG_NUM_IRQS];
303
+
304
+void run_isr_handler(int idx, void *arg) {
305
+    if (isr_demux_table[idx].isr == 0) {
306
+        return;
307
+    }
308
+    _kernel.nested++;
309
+    ((NANO_EOI_GET_FUNC)isr_demux_table[idx].isr)(isr_demux_table[idx].arg);
310
+    _kernel.nested--;
311
+}
312
+
313
+unsigned int _arch_irq_lock(void) {
314
+    unsigned int ret = READ32(&__IRQCTRL->irq_lock);
315
+    WRITE32(&__IRQCTRL->irq_lock, 1);
316
+    return ret;
317
+}
318
+
319
+void _arch_irq_unlock(unsigned int key) {
320
+    WRITE32(&__IRQCTRL->irq_lock, key);
321
+}
322
+
323
+unsigned int _arch_irq_lock_state() {
324
+    return READ32(&__IRQCTRL->irq_lock);
325
+}
326
+
327
+/**
328
+ *
329
+ * @brief Enable an interrupt line
330
+ *
331
+ * Clear possible pending interrupts on the line, and enable the interrupt
332
+ * line. After this call, the CPU will receive interrupts for the specified
333
+ * <irq>.
334
+ *
335
+ * @return N/A
336
+ */
337
+void _arch_irq_enable(unsigned int irq)
338
+{
339
+       /* before enabling interrupts, ensure that interrupt is cleared */
340
+    uint32_t bit = READ32(&__IRQCTRL->irq_mask);
341
+    bit &= ~(1u << irq);
342
+    WRITE32(&__IRQCTRL->irq_clear, 1u << irq);
343
+    WRITE32(&__IRQCTRL->irq_mask, bit);
344
+}
345
+
346
+/**
347
+ *
348
+ * @brief Disable an interrupt line
349
+ *
350
+ * Disable an interrupt line. After this call, the CPU will stop receiving
351
+ * interrupts for the specified <irq>.
352
+ *
353
+ * @return N/A
354
+ */
355
+void _arch_irq_disable(unsigned int irq)
356
+{
357
+    uint32_t bit = READ32(&__IRQCTRL->irq_mask);
358
+    bit |= (1u << irq);
359
+    WRITE32(&__IRQCTRL->irq_mask, bit);
360
+}
361
+
362
+/*
363
+ * @internal
364
+ *
365
+ * @brief Replace an interrupt handler by another
366
+ *
367
+ * An interrupt's ISR can be replaced at runtime.
368
+ *
369
+ * @return N/A
370
+ */
371
+
372
+void _irq_handler_set(
373
+       unsigned int irq,
374
+       void (*new)(void *arg),
375
+       void *arg
376
+)
377
+{
378
+       int key = irq_lock();
379
+
380
+       __ASSERT(irq < CONFIG_NUM_IRQS, "IRQ number too high");
381
+       isr_demux_table[irq].arg = arg;
382
+    isr_demux_table[irq].isr = new;
383
+
384
+       irq_unlock(key);
385
+}
386
+
387
+/*
388
+ * @brief Connect an ISR to an interrupt line
389
+ *
390
+ * @a isr is connected to interrupt line @a irq, a number greater than or equal
391
+ * 16. No prior ISR can have been connected on @a irq interrupt line since the
392
+ * system booted.
393
+ *
394
+ * This routine will hang if another ISR was connected for interrupt line @a irq
395
+ * and ASSERT_ON is enabled; if ASSERT_ON is disabled, it will fail silently.
396
+ *
397
+ * @return the interrupt line number
398
+ */
399
+int _arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
400
+                            void (*routine)(void *arg), void *parameter,
401
+                            uint32_t flags)
402
+{
403
+       ARG_UNUSED(flags);
404
+       _irq_handler_set(irq, routine, parameter);
405
+       return irq;
406
+}
407
diff --git a/arch/riscv64/core/memaccess.c b/arch/riscv64/core/memaccess.c
408
new file mode 100644
409
index 0000000..52a46bb
410
--- /dev/null
411
+++ b/arch/riscv64/core/memaccess.c
412
@@ -0,0 +1,42 @@
413
+/*
414
+ * Copyright (c) 2016, GNSS Sensor Ltd.
415
+ *
416
+ * Licensed under the Apache License, Version 2.0 (the "License");
417
+ * you may not use this file except in compliance with the License.
418
+ * You may obtain a copy of the License at
419
+ *
420
+ *     http://www.apache.org/licenses/LICENSE-2.0
421
+ *
422
+ * Unless required by applicable law or agreed to in writing, software
423
+ * distributed under the License is distributed on an "AS IS" BASIS,
424
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
425
+ * See the License for the specific language governing permissions and
426
+ * limitations under the License.
427
+ */
428
+
429
+#include <stdint.h>
430
+
431
+uint16_t READ16(volatile uint16_t *addr)
432
+{
433
+    return *addr;
434
+}
435
+
436
+uint32_t READ32(volatile uint32_t *addr)
437
+{
438
+    return *addr;
439
+}
440
+
441
+uint64_t READ64(volatile uint64_t *addr)
442
+{
443
+    return *addr;
444
+}
445
+
446
+void WRITE32(volatile uint32_t *addr, uint32_t val)
447
+{
448
+    *addr = val;
449
+}
450
+
451
+void WRITE64(volatile uint64_t *addr, uint64_t val)
452
+{
453
+    *addr = val;
454
+}
455
diff --git a/arch/riscv64/core/new_thread.c b/arch/riscv64/core/new_thread.c
456
new file mode 100644
457
index 0000000..a8492f7
458
--- /dev/null
459
+++ b/arch/riscv64/core/new_thread.c
460
@@ -0,0 +1,134 @@
461
+/*
462
+ * Copyright (c) 2010-2015 Wind River Systems, Inc.
463
+ *
464
+ * Licensed under the Apache License, Version 2.0 (the "License");
465
+ * you may not use this file except in compliance with the License.
466
+ * You may obtain a copy of the License at
467
+ *
468
+ *     http://www.apache.org/licenses/LICENSE-2.0
469
+ *
470
+ * Unless required by applicable law or agreed to in writing, software
471
+ * distributed under the License is distributed on an "AS IS" BASIS,
472
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
473
+ * See the License for the specific language governing permissions and
474
+ * limitations under the License.
475
+ */
476
+
477
+/**
478
+ * @file
479
+ * @brief Nanokernel thread support primitives
480
+ *
481
+ * This module provides core nanokernel fiber related primitives for the IA-32
482
+ * processor architecture.
483
+ */
484
+
485
+
486
+#include <kernel.h>
487
+#include <nano_internal.h>
488
+#include <kernel_structs.h>
489
+#include <wait_q.h>
490
+#include <string.h>
491
+#include <misc/printk.h>
492
+#include "swap_macros.h"
493
+
494
+#ifdef _WIN32
495
+extern int LIBH_create_thread(char *pStackMem,
496
+                              unsigned stackSize,
497
+                              int priority,
498
+                              unsigned options);
499
+#endif
500
+
501
+#if defined(CONFIG_THREAD_MONITOR)
502
+/*
503
+ * Add a thread to the kernel's list of active threads.
504
+ */
505
+static ALWAYS_INLINE void thread_monitor_init(struct k_thread *thread)
506
+{
507
+       unsigned int key;
508
+
509
+       key = irq_lock();
510
+       thread->next_thread = _kernel.threads;
511
+       _kernel.threads = thread;
512
+       irq_unlock(key);
513
+}
514
+#else
515
+#define thread_monitor_init(thread) \
516
+       do {/* do nothing */     \
517
+       } while ((0))
518
+#endif /* CONFIG_THREAD_MONITOR */
519
+
520
+
521
+struct init_stack_frame {
522
+       /* top of the stack / most recently pushed */
523
+
524
+       /* Used by _thread_entry_wrapper. pulls these off the stack and
525
+        * into argument registers before calling _thread_entry()
526
+        */
527
+       _thread_entry_t entry_point;
528
+       void *arg1;
529
+       void *arg2;
530
+       void *arg3;
531
+
532
+       /* least recently pushed */
533
+};
534
+
535
+
536
+/**
537
+ *
538
+ * @brief Create a new kernel execution thread
539
+ *
540
+ * This function is utilized to create execution threads for both fiber
541
+ * threads and kernel tasks.
542
+ */
543
+extern void _new_thread(char *pStack, size_t stackSize,
544
+                       void (*pEntry)(void *, void *, void *),
545
+                       void *p1, void *p2, void *p3,
546
+                       int prio, unsigned options)
547
+{
548
+
549
+
550
+       _ASSERT_VALID_PRIO(priority, thread_func);
551
+
552
+       struct k_thread *thread;
553
+       unsigned long *pInitialCtx;
554
+
555
+#ifdef CONFIG_INIT_STACKS
556
+       memset(pStack, 0xaa, stackSize);
557
+#endif
558
+
559
+       /* Initialize various struct k_thread members */
560
+       thread = (struct k_thread *)pStack;
561
+       pInitialCtx =
562
+               (unsigned long *)(pStack + stackSize);
563
+
564
+
565
+       _init_thread_base(&thread->base, prio, K_PRESTART, options);
566
+
567
+       /* static threads overwrite it afterwards with real value */
568
+       thread->init_data = NULL;
569
+       thread->fn_abort = NULL;
570
+
571
+#ifdef CONFIG_THREAD_CUSTOM_DATA
572
+       /* Initialize custom data field (value is opaque to kernel) */
573
+       thread->custom_data = NULL;
574
+#endif
575
+       thread->callee_saved.key = 0;
576
+       thread->callee_saved.preemptive = 0;
577
+       /* Leave the rest of thread->callee_saved junk */
578
+
579
+       thread_monitor_init(thread);
580
+
581
+
582
+    //printk("\nInitial context SP = 0x%x\n", (unsigned long)pStack);
583
+    thread->callee_saved.r[COOP_REG_RA/sizeof(uint64_t)] = (uint64_t)_thread_entry;
584
+    thread->callee_saved.r[COOP_REG_MEPC/sizeof(uint64_t)] = (uint64_t)_thread_entry;
585
+    thread->callee_saved.r[COOP_REG_A0/sizeof(uint64_t)] = (uint64_t)pEntry;
586
+    thread->callee_saved.r[COOP_REG_A1/sizeof(uint64_t)] = (uint64_t)p1;
587
+    thread->callee_saved.r[COOP_REG_A2/sizeof(uint64_t)] = (uint64_t)p2;
588
+    thread->callee_saved.r[COOP_REG_A3/sizeof(uint64_t)] = (uint64_t)p3;
589
+    thread->callee_saved.r[COOP_REG_SP/sizeof(uint64_t)] =
590
+        (uint64_t)(pStack + stackSize);
591
+#ifdef _WIN32
592
+    LIBH_create_thread(pStack, (unsigned int)stackSize, prio, options);
593
+#endif
594
+}
595
diff --git a/arch/riscv64/core/offsets/offsets.c b/arch/riscv64/core/offsets/offsets.c
596
new file mode 100644
597
index 0000000..c1cd125
598
--- /dev/null
599
+++ b/arch/riscv64/core/offsets/offsets.c
600
@@ -0,0 +1,37 @@
601
+/*
602
+ * Copyright (c) 2014 Wind River Systems, Inc.
603
+ *
604
+ * Licensed under the Apache License, Version 2.0 (the "License");
605
+ * you may not use this file except in compliance with the License.
606
+ * You may obtain a copy of the License at
607
+ *
608
+ *     http://www.apache.org/licenses/LICENSE-2.0
609
+ *
610
+ * Unless required by applicable law or agreed to in writing, software
611
+ * distributed under the License is distributed on an "AS IS" BASIS,
612
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
613
+ * See the License for the specific language governing permissions and
614
+ * limitations under the License.
615
+ */
616
+
617
+/**
618
+ * @file
619
+ * @brief RISC-V nano kernel structure member offset definition file
620
+ *
621
+ * This module is responsible for the generation of the absolute symbols whose
622
+ * value represents the member offsets for various RISC-V nanokernel
623
+ * structures.
624
+ *
625
+ * All of the absolute symbols defined by this module will be present in the
626
+ * final microkernel or nanokernel ELF image (due to the linker's reference to
627
+ * the _OffsetAbsSyms symbol).
628
+ *
629
+ * INTERNAL
630
+ * It is NOT necessary to define the offset for every member of a structure.
631
+ * Typically, only those members that are accessed by assembly language routines
632
+ * are defined; however, it doesn't hurt to define all fields for the sake of
633
+ * completeness.
634
+ */
635
+
636
+#include <gen_offset.h>
637
+
638
diff --git a/arch/riscv64/core/swap.S b/arch/riscv64/core/swap.S
639
new file mode 100644
640
index 0000000..8ead287
641
--- /dev/null
642
+++ b/arch/riscv64/core/swap.S
643
@@ -0,0 +1,176 @@
644
+/*
645
+ * Copyright (c) 2014-2015 Wind River Systems, Inc.
646
+ *
647
+ * Licensed under the Apache License, Version 2.0 (the "License");
648
+ * you may not use this file except in compliance with the License.
649
+ * You may obtain a copy of the License at
650
+ *
651
+ *     http://www.apache.org/licenses/LICENSE-2.0
652
+ *
653
+ * Unless required by applicable law or agreed to in writing, software
654
+ * distributed under the License is distributed on an "AS IS" BASIS,
655
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
656
+ * See the License for the specific language governing permissions and
657
+ * limitations under the License.
658
+ */
659
+
660
+#define _ASMLANGUAGE
661
+
662
+#include "swap_macros.h"
663
+
664
+/**
665
+ *
666
+ * @brief Initiate a cooperative context switch
667
+ *
668
+ * The _Swap() routine is invoked by various nanokernel services to effect
669
+ * a cooperative context switch.  Prior to invoking _Swap(), the caller
670
+ * disables interrupts via nanoCpuIntLock() and the return 'key' is passed as a
671
+ * parameter to _Swap(). The key is in fact the value stored in the register
672
+ * operand of a CLRI instruction.
673
+ *
674
+ * It stores the intlock key parameter into current->intlock_key.
675
+
676
+ * Given that _Swap() is called to effect a cooperative context switch,
677
+ * the caller-saved integer registers are saved on the stack by the function
678
+ * call preamble to _Swap(). This creates a custom stack frame that will be
679
+ * popped when returning from _Swap(), but is not suitable for handling a return
680
+ * from an exception. Thus, the fact that the thread is pending because of a
681
+ * cooperative call to _Swap() has to be recorded via the _CAUSE_COOP code in
682
+ * the relinquish_cause of the thread's tTCS. The _IrqExit()/_FirqExit() code
683
+ * will take care of doing the right thing to restore the thread status.
684
+ *
685
+ * When _Swap() is invoked, we know the decision to perform a context switch or
686
+ * not has already been taken and a context switch must happen.
687
+ *
688
+ * @return may contain a return value setup by a call to fiberRtnValueSet()
689
+ *
690
+ * C function prototype:
691
+ *
692
+ * unsigned int _Swap (unsigned int key);
693
+ *
694
+ */
695
+
696
+.section ".text"
697
+.globl __start
698
+__start:
699
+       jal _Cstart;
700
+
701
+.section ".text"
702
+.globl _Swap
703
+_Swap:
704
+       _save_context(tp)
705
+       la s0, _kernel
706
+       ld s1,_kernel_offset_to_current(s0)             # s1 = _kernel.current
707
+       addi s2,s1,_thread_offset_to_callee_saved       # s2 = &next_thread->callee_saved
708
+       sd a0,_callee_saved_offset_to_key(s2)           # _kernel.current->callee_saved.key = fl
709
+
710
+        ## Populate default return value
711
+       lw a1,_k_neg_eagain
712
+       sd a1, _callee_saved_offset_to_retval(s2)
713
+
714
+       ## This thread was switched preemptively
715
+       li a1,0
716
+       sd a1,_callee_saved_offset_to_preemptive(s2)
717
+
718
+       jal _get_next_ready_thread
719
+       mv s1,a0
720
+       sd s1,_kernel_offset_to_current(s0)             # _kernel.current = _get_next_ready_thread()
721
+       addi tp,s1,_thread_offset_to_callee_saved       # tp = &next_thread->callee_saved
722
+
723
+       ld a0,_callee_saved_offset_to_key(tp)           # a0 = callee_saved.key
724
+        jal _arch_irq_unlock                           # _arch_irq_unlock(callee_saved.key)
725
+
726
+       _restore_context(tp)
727
+       ld t4,_callee_saved_offset_to_preemptive(tp)
728
+       bnez t4,__swap_preemptive
729
+__swap_cooperative:
730
+       ret
731
+__swap_preemptive:
732
+       ld t4,COOP_REG_MEPC(tp)
733
+       jalr t4
734
+
735
+##
736
+#  _IsrWrapper(int idx, void *)
737
+#       a0 store IRQ index,
738
+#       a1 equals NULL
739
+#
740
+.globl _IsrWrapper
741
+_IsrWrapper:
742
+        addi sp,sp,-32
743
+        sd ra,0(sp)
744
+        sd s0,8(sp)
745
+        sd s1,16(sp)
746
+        sd s2,24(sp)
747
+
748
+       # Grab a reference to _kernel in r10 so we can determine the
749
+       # current irq stack pointer
750
+       #
751
+       la a1,_kernel
752
+
753
+       # Stash a copy of thread's sp in r12 so that we can put it on the IRQ
754
+       # stack
755
+       #
756
+       mv a2,sp
757
+
758
+       # Switch to interrupt stack
759
+       ld sp,_kernel_offset_to_irq_stack(a1)
760
+
761
+       # Store thread stack pointer onto IRQ stack
762
+       addi sp,sp,-8
763
+       sd a2,0(sp)
764
+
765
+       call run_isr_handler
766
+
767
+       ld sp,0(sp)
768
+
769
+       # Check reschedule condition
770
+       jal _get_next_ready_thread
771
+       beqz a0,_IsrExit_ending         # _get_next_ready_thread() == 0 goto ending
772
+
773
+       ## Do not reschedule coop threads (threads that have negative prio)
774
+       ld s1, _thread_offset_to_prio(a0)
775
+       blt  s1,zero,_IsrExit_ending
776
+
777
+       ## Do not reschedule if scheduler is locked
778
+       ld s1, _thread_offset_to_sched_locked(a0)
779
+       bne s1,zero,_IsrExit_ending
780
+
781
+       ## Call into the kernel to see if a scheduling decision is necessary
782
+       mv s1,a0                                # s1 = next_thread
783
+       jal _is_next_thread_current
784
+       bne a0,zero,_IsrExit_ending
785
+
786
+       ## Flag current thread that it was switched preemptively
787
+       la s0, _kernel
788
+       ld s0,_kernel_offset_to_current(s0)             # s0 = _kernel.current
789
+       addi s2,s0,_thread_offset_to_callee_saved       # s2 = &next_thread->callee_saved
790
+       li a0,1
791
+       sd a0,_callee_saved_offset_to_preemptive(s2)
792
+
793
+       # Store IRQ key
794
+        jal _arch_irq_lock_state               # a0 = _arch_irq_lock_state()
795
+        sd a0,_callee_saved_offset_to_key(s2)
796
+
797
+       ##
798
+       # Switch to the new thread.
799
+       #
800
+       addi tp,s1,_thread_offset_to_callee_saved       # tp = &next_thread->callee_saved
801
+
802
+       ld a0,_callee_saved_offset_to_key(tp)           # a0 = callee_saved.key
803
+        jal _arch_irq_unlock                           # _arch_irq_unlock(callee_saved.key)
804
+
805
+       ld t4,_callee_saved_offset_to_preemptive(tp)
806
+       bnez t4,_IsrExit_ending
807
+
808
+       ## Next thread was switched cooperative so,set MEPC to ra
809
+       ld a0,COOP_REG_RA(tp)
810
+       sd a0,COOP_REG_MEPC(tp)
811
+
812
+
813
+_IsrExit_ending:
814
+        ld s2,24(sp)
815
+        ld s1,16(sp)
816
+        ld s0,8(sp)
817
+        ld ra,0(sp)
818
+        addi sp,sp,32
819
+       ret
820
diff --git a/arch/riscv64/core/swap_macros.h b/arch/riscv64/core/swap_macros.h
821
new file mode 100644
822
index 0000000..f520918
823
--- /dev/null
824
+++ b/arch/riscv64/core/swap_macros.h
825
@@ -0,0 +1,159 @@
826
+/* swap_macros.h - helper macros for context switch */
827
+
828
+/*
829
+ * Copyright (c) 2014 Wind River Systems, Inc.
830
+ *
831
+ * Licensed under the Apache License, Version 2.0 (the "License");
832
+ * you may not use this file except in compliance with the License.
833
+ * You may obtain a copy of the License at
834
+ *
835
+ *     http://www.apache.org/licenses/LICENSE-2.0
836
+ *
837
+ * Unless required by applicable law or agreed to in writing, software
838
+ * distributed under the License is distributed on an "AS IS" BASIS,
839
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
840
+ * See the License for the specific language governing permissions and
841
+ * limitations under the License.
842
+ */
843
+
844
+#ifndef _SWAP_MACROS__H_
845
+#define _SWAP_MACROS__H_
846
+
847
+#define tNANO_FIBER_OFFSET   0
848
+#define tNANO_TASK_OFFSET    8
849
+#define tNANO_CURRENT_OFFSET 16
850
+
851
+#define _kernel_offset_to_irq_stack    8
852
+#define _kernel_offset_to_current      16
853
+
854
+#define _timeout_sizeof                48
855
+#define _thread_offset_to_prio         24
856
+#define _thread_offset_to_sched_locked 32
857
+#define _thread_offset_to_callee_saved 96  //_thread_base_sizeof+caller_saved
858
+
859
+#define _callee_saved_offset_to_key        256  //(32*sizeof(uint64_t))
860
+#define _callee_saved_offset_to_retval     264  //(33*sizeof(uint64_t))
861
+#define _callee_saved_offset_to_preemptive 272  //(34*sizeof(uint64_t))
862
+
863
+#define TCS_LINK_OFFSET         0
864
+#define TCS_FLAGS_OFFSET        8
865
+#define TCS_INTLOCK_OFFSET      16
866
+#define TCS_COOP_REGS_OFFSET    24
867
+
868
+/**
869
+ * Saved by callee function registers:
870
+ *      s0..s11, sp, tp
871
+ */
872
+
873
+/** Return address */
874
+#define COOP_REG_RA         0//(0*sizeof(uint64_t))
875
+/** Saved registers */
876
+#define COOP_REG_S0         8//(1*sizeof(uint64_t))
877
+#define COOP_REG_S1         16//(2*sizeof(uint64_t))
878
+#define COOP_REG_S2         24//(3*sizeof(uint64_t))
879
+#define COOP_REG_S3         32//(4*sizeof(uint64_t))
880
+#define COOP_REG_S4         40//(5*sizeof(uint64_t))
881
+#define COOP_REG_S5         48//(6*sizeof(uint64_t))
882
+#define COOP_REG_S6         56//(7*sizeof(uint64_t))
883
+#define COOP_REG_S7         64//(8*sizeof(uint64_t))
884
+#define COOP_REG_S8         72//(9*sizeof(uint64_t))
885
+#define COOP_REG_S9         80//(10*sizeof(uint64_t))
886
+#define COOP_REG_S10        88//(11*sizeof(uint64_t))
887
+#define COOP_REG_S11        96//(12*sizeof(uint64_t))
888
+/** Stack pointer */
889
+#define COOP_REG_SP         104//(13*sizeof(uint64_t))
890
+/** Thread pointer */
891
+#define COOP_REG_TP         112//(14*sizeof(uint64_t))
892
+#define COOP_REG_MEPC       COOP_REG_TP//(14*sizeof(uint64_t))
893
+/** Return values */
894
+#define COOP_REG_V0         120//(15*sizeof(uint64_t))
895
+#define COOP_REG_V1         128//(16*sizeof(uint64_t))
896
+/** Function Arguments */
897
+#define COOP_REG_A0         136//(17*sizeof(uint64_t))
898
+#define COOP_REG_A1         144//(18*sizeof(uint64_t))
899
+#define COOP_REG_A2         152//(19*sizeof(uint64_t))
900
+#define COOP_REG_A3         160//(20*sizeof(uint64_t))
901
+#define COOP_REG_A4         168//(21*sizeof(uint64_t))
902
+#define COOP_REG_A5         176//(22*sizeof(uint64_t))
903
+#define COOP_REG_A6         184//(23*sizeof(uint64_t))
904
+#define COOP_REG_A7         192//(24*sizeof(uint64_t))
905
+/** Temporary registers */
906
+#define COOP_REG_T0         200//(25*sizeof(uint64_t))
907
+#define COOP_REG_T1         208//(26*sizeof(uint64_t))
908
+#define COOP_REG_T2         216//(27*sizeof(uint64_t))
909
+#define COOP_REG_T3         224//(28*sizeof(uint64_t))
910
+#define COOP_REG_T4         232//(29*sizeof(uint64_t))
911
+/** Global pointer */
912
+#define COOP_REG_GP         240//(30*sizeof(uint64_t))
913
+
914
+#define COOP_REGS_TOTAL     32
915
+#define COOP_STACKFRAME_SIZE (COOP_REGS_TOTAL*sizeof(uint64_t))
916
+
917
+
918
+#define _save_context(TO) \
919
+  sd ra, COOP_REG_RA(TO); \
920
+  sd s0, COOP_REG_S0(TO); \
921
+  sd s1, COOP_REG_S1(TO); \
922
+  sd s2, COOP_REG_S2(TO); \
923
+  sd s3, COOP_REG_S3(TO); \
924
+  sd s4, COOP_REG_S4(TO); \
925
+  sd s5, COOP_REG_S5(TO); \
926
+  sd s6, COOP_REG_S6(TO); \
927
+  sd s7, COOP_REG_S7(TO); \
928
+  sd s8, COOP_REG_S8(TO); \
929
+  sd s9, COOP_REG_S9(TO); \
930
+  sd s10, COOP_REG_S10(TO); \
931
+  sd s11, COOP_REG_S11(TO); \
932
+  sd sp, COOP_REG_SP(TO); \
933
+  sd x16, COOP_REG_V0(TO); \
934
+  sd x17, COOP_REG_V1(TO); \
935
+  sd a0, COOP_REG_A0(TO); \
936
+  sd a1, COOP_REG_A1(TO); \
937
+  sd a2, COOP_REG_A2(TO); \
938
+  sd a3, COOP_REG_A3(TO); \
939
+  sd a4, COOP_REG_A4(TO); \
940
+  sd a5, COOP_REG_A5(TO); \
941
+  sd a6, COOP_REG_A6(TO); \
942
+  sd a7, COOP_REG_A7(TO); \
943
+  sd t0, COOP_REG_T0(TO); \
944
+  sd t1, COOP_REG_T1(TO); \
945
+  sd t2, COOP_REG_T2(TO); \
946
+  sd t3, COOP_REG_T3(TO); \
947
+  sd t4, COOP_REG_T4(TO); \
948
+  sd gp, COOP_REG_GP(TO);
949
+
950
+
951
+#define _restore_context(FROM) \
952
+  ld ra, COOP_REG_RA(FROM); \
953
+  ld s0, COOP_REG_S0(FROM); \
954
+  ld s1, COOP_REG_S1(FROM); \
955
+  ld s2, COOP_REG_S2(FROM); \
956
+  ld s3, COOP_REG_S3(FROM); \
957
+  ld s4, COOP_REG_S4(FROM); \
958
+  ld s5, COOP_REG_S5(FROM); \
959
+  ld s6, COOP_REG_S6(FROM); \
960
+  ld s7, COOP_REG_S7(FROM); \
961
+  ld s8, COOP_REG_S8(FROM); \
962
+  ld s9, COOP_REG_S9(FROM); \
963
+  ld s10, COOP_REG_S10(FROM); \
964
+  ld s11, COOP_REG_S11(FROM); \
965
+  ld sp, COOP_REG_SP(FROM); \
966
+  ld x16, COOP_REG_V0(FROM); \
967
+  ld x17, COOP_REG_V1(FROM); \
968
+  ld a0, COOP_REG_A0(FROM); \
969
+  ld a1, COOP_REG_A1(FROM); \
970
+  ld a2, COOP_REG_A2(FROM); \
971
+  ld a3, COOP_REG_A3(FROM); \
972
+  ld a4, COOP_REG_A4(FROM); \
973
+  ld a5, COOP_REG_A5(FROM); \
974
+  ld a6, COOP_REG_A6(FROM); \
975
+  ld a7, COOP_REG_A7(FROM); \
976
+  ld t0, COOP_REG_T0(FROM); \
977
+  ld t1, COOP_REG_T1(FROM); \
978
+  ld t2, COOP_REG_T2(FROM); \
979
+  ld t3, COOP_REG_T3(FROM); \
980
+  ld t4, COOP_REG_T4(FROM); \
981
+  ld gp, COOP_REG_GP(FROM);
982
+
983
+
984
+#endif /*  _SWAP_MACROS__H_ */
985
diff --git a/arch/riscv64/defconfig b/arch/riscv64/defconfig
986
new file mode 100644
987
index 0000000..e69de29
988
diff --git a/arch/riscv64/include/kernel_arch_data.h b/arch/riscv64/include/kernel_arch_data.h
989
new file mode 100644
990
index 0000000..ef8242b
991
--- /dev/null
992
+++ b/arch/riscv64/include/kernel_arch_data.h
993
@@ -0,0 +1,84 @@
994
+/*
995
+ * Copyright (c) 2016 Gnss Sensor Ltd
996
+ *
997
+ * Licensed under the Apache License, Version 2.0 (the "License");
998
+ * you may not use this file except in compliance with the License.
999
+ * You may obtain a copy of the License at
1000
+ *
1001
+ *     http://www.apache.org/licenses/LICENSE-2.0
1002
+ *
1003
+ * Unless required by applicable law or agreed to in writing, software
1004
+ * distributed under the License is distributed on an "AS IS" BASIS,
1005
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1006
+ * See the License for the specific language governing permissions and
1007
+ * limitations under the License.
1008
+ */
1009
+
1010
+#ifndef __KERNEL_ARCH__DATA_H__
1011
+#define __KERNEL_ARCH__DATA_H__
1012
+
1013
+#include <stdint.h>
1014
+#include <toolchain.h>
1015
+#include <sections.h>
1016
+#include <arch/cpu.h>
1017
+
1018
+#ifndef _ASMLANGUAGE
1019
+#include <kernel.h>
1020
+#include <nano_internal.h>
1021
+#include <stdint.h>
1022
+#include <misc/util.h>
1023
+#include <misc/dlist.h>
1024
+#endif
1025
+
1026
+#ifdef __cplusplus
1027
+extern "C" {
1028
+#endif
1029
+
1030
+struct _caller_saved {
1031
+       /*
1032
+        * Nothing here, the exception code puts all the caller-saved
1033
+        * registers onto the stack.
1034
+        */
1035
+    int empty_;
1036
+};
1037
+
1038
+typedef struct _caller_saved _caller_saved_t;
1039
+
1040
+struct _callee_saved {
1041
+    uint64_t r[32];
1042
+       /* IRQ status before irq_lock() and call to _Swap() */
1043
+       uint64_t key;
1044
+
1045
+       /* Return value of _Swap() */
1046
+       uint64_t retval;
1047
+
1048
+    /* I actually do not understand where preemptive tasks switch occurs,
1049
+     * so use this flag stores the latest method of switch 0=coop; 1=preemp.
1050
+     * It allows properly switch cooperative/preemtive threads independently
1051
+     * of its priority
1052
+     */
1053
+    uint64_t preemptive;
1054
+};
1055
+
1056
+typedef struct _callee_saved _callee_saved_t;
1057
+
1058
+struct _thread_arch {
1059
+       /* nothing for now */
1060
+    unsigned int empty_;
1061
+};
1062
+
1063
+typedef struct _thread_arch _thread_arch_t;
1064
+
1065
+struct _kernel_arch {
1066
+       /* nothing for now */
1067
+    int empty_;
1068
+};
1069
+
1070
+typedef struct _kernel_arch _kernel_arch_t;
1071
+
1072
+
1073
+#ifdef __cplusplus
1074
+}
1075
+#endif
1076
+
1077
+#endif /* __KERNEL_ARCH__DATA_H__ */
1078
diff --git a/arch/riscv64/include/kernel_arch_func.h b/arch/riscv64/include/kernel_arch_func.h
1079
new file mode 100644
1080
index 0000000..55046ab
1081
--- /dev/null
1082
+++ b/arch/riscv64/include/kernel_arch_func.h
1083
@@ -0,0 +1,74 @@
1084
+/*
1085
+ * Copyright (c) 2016 Gnss Sensor Ltd
1086
+ *
1087
+ * Licensed under the Apache License, Version 2.0 (the "License");
1088
+ * you may not use this file except in compliance with the License.
1089
+ * You may obtain a copy of the License at
1090
+ *
1091
+ *     http://www.apache.org/licenses/LICENSE-2.0
1092
+ *
1093
+ * Unless required by applicable law or agreed to in writing, software
1094
+ * distributed under the License is distributed on an "AS IS" BASIS,
1095
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1096
+ * See the License for the specific language governing permissions and
1097
+ * limitations under the License.
1098
+ */
1099
+
1100
+/**
1101
+ * @file
1102
+ * @brief Private kernel definitions
1103
+ *
1104
+ * This file contains private kernel function/macro definitions and various
1105
+ * other definitions for the Nios II processor architecture.
1106
+ *
1107
+ * This file is also included by assembly language files which must #define
1108
+ * _ASMLANGUAGE before including this header file.  Note that kernel
1109
+ * assembly source files obtains structure offset values via "absolute
1110
+ * symbols" in the offsets.o module.
1111
+ */
1112
+
1113
+#ifndef _kernel_arch_func__h_
1114
+#define _kernel_arch_func__h_
1115
+
1116
+#include <stdint.h>
1117
+#include <toolchain.h>
1118
+
1119
+#ifdef __cplusplus
1120
+extern "C" {
1121
+#endif
1122
+
1123
+#ifndef _ASMLANGUAGE
1124
+
1125
+void nano_cpu_idle(void);
1126
+void nano_cpu_atomic_idle(unsigned int key);
1127
+
1128
+extern char _interrupt_stack[];
1129
+
1130
+static ALWAYS_INLINE void nanoArchInit(void)
1131
+{
1132
+       _kernel.irq_stack = _interrupt_stack + CONFIG_ISR_STACK_SIZE;
1133
+}
1134
+
1135
+static ALWAYS_INLINE void
1136
+_set_thread_return_value(struct k_thread *thread, unsigned int value)
1137
+{
1138
+       thread->callee_saved.retval = value;
1139
+}
1140
+
1141
+static inline void _IntLibInit(void)
1142
+{
1143
+       /* No special initialization of the interrupt subsystem required */
1144
+}
1145
+
1146
+FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
1147
+                                         const NANO_ESF * esf);
1148
+
1149
+#define _is_in_isr() (_kernel.nested != 0)
1150
+
1151
+#endif /* _ASMLANGUAGE */
1152
+
1153
+#ifdef __cplusplus
1154
+}
1155
+#endif
1156
+
1157
+#endif /* _kernel_arch_func__h_ */
1158
diff --git a/arch/riscv64/include/kernel_event_logger_arch.h b/arch/riscv64/include/kernel_event_logger_arch.h
1159
new file mode 100644
1160
index 0000000..b6b8e67
1161
--- /dev/null
1162
+++ b/arch/riscv64/include/kernel_event_logger_arch.h
1163
@@ -0,0 +1,46 @@
1164
+/*
1165
+ * Copyright (c) 2015 Intel Corporation
1166
+ *
1167
+ * Licensed under the Apache License, Version 2.0 (the "License");
1168
+ * you may not use this file except in compliance with the License.
1169
+ * You may obtain a copy of the License at
1170
+ *
1171
+ *     http://www.apache.org/licenses/LICENSE-2.0
1172
+ *
1173
+ * Unless required by applicable law or agreed to in writing, software
1174
+ * distributed under the License is distributed on an "AS IS" BASIS,
1175
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1176
+ * See the License for the specific language governing permissions and
1177
+ * limitations under the License.
1178
+ */
1179
+
1180
+/**
1181
+ * @file
1182
+ * @brief Kernel event logger support for ARM
1183
+ */
1184
+
1185
+#ifndef __KERNEL_EVENT_LOGGER_ARCH_H__
1186
+#define __KERNEL_EVENT_LOGGER_ARCH_H__
1187
+
1188
+#ifdef __cplusplus
1189
+extern "C" {
1190
+#endif
1191
+
1192
+/**
1193
+ * @brief Get the identification of the current interrupt.
1194
+ *
1195
+ * This routine obtain the key of the interrupt that is currently processed
1196
+ * if it is called from a ISR context.
1197
+ *
1198
+ * @return The key of the interrupt that is currently being processed.
1199
+ */
1200
+int _sys_current_irq_key_get(void)
1201
+{
1202
+       return 0;
1203
+}
1204
+
1205
+#ifdef __cplusplus
1206
+}
1207
+#endif
1208
+
1209
+#endif /* __KERNEL_EVENT_LOGGER_ARCH_H__ */
1210
diff --git a/arch/riscv64/include/memaccess.h b/arch/riscv64/include/memaccess.h
1211
new file mode 100644
1212
index 0000000..564762b
1213
--- /dev/null
1214
+++ b/arch/riscv64/include/memaccess.h
1215
@@ -0,0 +1,16 @@
1216
+/**
1217
+ * @file Access methods declaration to the memory mapped devices.
1218
+ */
1219
+
1220
+#ifndef _RISCV_CORE_MEMACCESS_H_
1221
+#define _RISCV_CORE_MEMACCESS_H_
1222
+
1223
+#include <stdint.h>
1224
+
1225
+extern uint16_t READ16(volatile uint16_t *addr);
1226
+extern uint32_t READ32(volatile uint32_t *addr);
1227
+extern uint64_t READ64(volatile uint64_t *addr);
1228
+extern void WRITE32(volatile uint32_t *addr, uint32_t val);
1229
+extern void WRITE64(volatile uint64_t *addr, uint64_t val);
1230
+
1231
+#endif  // _RISCV_CORE_MEMACCESS_H_
1232
diff --git a/arch/riscv64/include/offsets_short_arch.h b/arch/riscv64/include/offsets_short_arch.h
1233
new file mode 100644
1234
index 0000000..d28ff64
1235
--- /dev/null
1236
+++ b/arch/riscv64/include/offsets_short_arch.h
1237
@@ -0,0 +1,4 @@
1238
+#ifndef __OFFSETS_SHORT_ARCH_H__
1239
+#define __OFFSETS_SHORT_ARCH_H__
1240
+
1241
+#endif  // __OFFSETS_SHORT_ARCH_H__
1242
diff --git a/arch/riscv64/soc/riscv_gnss/Kbuild b/arch/riscv64/soc/riscv_gnss/Kbuild
1243
new file mode 100644
1244
index 0000000..d035736
1245
--- /dev/null
1246
+++ b/arch/riscv64/soc/riscv_gnss/Kbuild
1247
@@ -0,0 +1,8 @@
1248
+ccflags-y +=-I$(srctree)/arch/riscv64/include
1249
+ccflags-y +=-I$(srctree)/include
1250
+ccflags-y +=-I$(srctree)/include/drivers
1251
+ccflags-y +=-I$(srctree)/drivers
1252
+
1253
+asflags-y := ${ccflags-y}
1254
+
1255
+obj-y += soc.o
1256
diff --git a/arch/riscv64/soc/riscv_gnss/Kconfig.defconfig b/arch/riscv64/soc/riscv_gnss/Kconfig.defconfig
1257
new file mode 100644
1258
index 0000000..31da98c
1259
--- /dev/null
1260
+++ b/arch/riscv64/soc/riscv_gnss/Kconfig.defconfig
1261
@@ -0,0 +1,33 @@
1262
+# Kconfig - Atmel SAM3 family processor configuration options
1263
+
1264
+#
1265
+# Copyright (c) 2016 Intel Corporation.
1266
+# Copyright (c) 2014-2015 Wind River Systems, Inc.
1267
+#
1268
+# Licensed under the Apache License, Version 2.0 (the "License");
1269
+# you may not use this file except in compliance with the License.
1270
+# You may obtain a copy of the License at
1271
+#
1272
+#     http://www.apache.org/licenses/LICENSE-2.0
1273
+#
1274
+# Unless required by applicable law or agreed to in writing, software
1275
+# distributed under the License is distributed on an "AS IS" BASIS,
1276
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1277
+# See the License for the specific language governing permissions and
1278
+# limitations under the License.
1279
+#
1280
+
1281
+if SOC_RISCV_GNSS
1282
+
1283
+config SOC
1284
+       default riscv_gnss
1285
+
1286
+config NUM_IRQS
1287
+       int
1288
+       default 6
1289
+
1290
+config SYS_CLOCK_HW_CYCLES_PER_SEC
1291
+       int
1292
+       default 40000000
1293
+
1294
+endif # SOC_RISCV_GNSS
1295
diff --git a/arch/riscv64/soc/riscv_gnss/Kconfig.soc b/arch/riscv64/soc/riscv_gnss/Kconfig.soc
1296
new file mode 100644
1297
index 0000000..84626cb
1298
--- /dev/null
1299
+++ b/arch/riscv64/soc/riscv_gnss/Kconfig.soc
1300
@@ -0,0 +1,5 @@
1301
+
1302
+config SOC_RISCV_GNSS
1303
+       bool "RISC-V SOC by Gnss Sensor Ltd"
1304
+       help
1305
+       Synthezable SoC based on open ISA RISC-V.
1306
diff --git a/arch/riscv64/soc/riscv_gnss/Makefile b/arch/riscv64/soc/riscv_gnss/Makefile
1307
new file mode 100644
1308
index 0000000..3caaddb
1309
--- /dev/null
1310
+++ b/arch/riscv64/soc/riscv_gnss/Makefile
1311
@@ -0,0 +1,6 @@
1312
+
1313
+arch-cflags += $(call cc-option,-mthumb -march=rv64ima -Wunused-function -Wint-to-pointer-cast)
1314
+
1315
+KBUILD_AFLAGS += $(arch-cflags)
1316
+KBUILD_CXXFLAGS += $(arch-cflags)
1317
+KBUILD_CFLAGS += $(arch-cflags)
1318
diff --git a/arch/riscv64/soc/riscv_gnss/linker.ld b/arch/riscv64/soc/riscv_gnss/linker.ld
1319
new file mode 100644
1320
index 0000000..6a68292
1321
--- /dev/null
1322
+++ b/arch/riscv64/soc/riscv_gnss/linker.ld
1323
@@ -0,0 +1,24 @@
1324
+/*
1325
+ * Copyright (c) 2014-2015 Wind River Systems, Inc.
1326
+ *
1327
+ * Licensed under the Apache License, Version 2.0 (the "License");
1328
+ * you may not use this file except in compliance with the License.
1329
+ * You may obtain a copy of the License at
1330
+ *
1331
+ *     http://www.apache.org/licenses/LICENSE-2.0
1332
+ *
1333
+ * Unless required by applicable law or agreed to in writing, software
1334
+ * distributed under the License is distributed on an "AS IS" BASIS,
1335
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1336
+ * See the License for the specific language governing permissions and
1337
+ * limitations under the License.
1338
+ */
1339
+
1340
+/*
1341
+ * generate a symbol to mark the start of the device initialization objects for
1342
+ * the specified level, then link all of those objects (sorted by priority);
1343
+ * ensure the objects aren't discarded if there is no direct reference to them
1344
+ */
1345
+
1346
+#include <arch/riscv64/linker.ld>
1347
+
1348
diff --git a/arch/riscv64/soc/riscv_gnss/soc.c b/arch/riscv64/soc/riscv_gnss/soc.c
1349
new file mode 100644
1350
index 0000000..72639bd
1351
--- /dev/null
1352
+++ b/arch/riscv64/soc/riscv_gnss/soc.c
1353
@@ -0,0 +1,254 @@
1354
+/*
1355
+ * Copyright (c) 2016, GNSS Sensor Ltd.
1356
+ *
1357
+ * Licensed under the Apache License, Version 2.0 (the "License");
1358
+ * you may not use this file except in compliance with the License.
1359
+ * You may obtain a copy of the License at
1360
+ *
1361
+ *     http://www.apache.org/licenses/LICENSE-2.0
1362
+ *
1363
+ * Unless required by applicable law or agreed to in writing, software
1364
+ * distributed under the License is distributed on an "AS IS" BASIS,
1365
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1366
+ * See the License for the specific language governing permissions and
1367
+ * limitations under the License.
1368
+ */
1369
+
1370
+/**
1371
+ * @file
1372
+ * @brief System/hardware module for GNSS RISC-V family processor
1373
+ *
1374
+ * This module provides routines to initialize and support board-level hardware
1375
+ * for the GNSS RISC-V family processor.
1376
+ */
1377
+
1378
+#include <stdint.h>
1379
+#include <errno.h>
1380
+#include <nanokernel.h>
1381
+#include <device.h>
1382
+#include <init.h>
1383
+#include <soc.h>
1384
+#include <misc/printk.h>
1385
+#include <misc/shell.h>
1386
+#include <sw_isr_table.h>
1387
+#include <memaccess.h>
1388
+
1389
+#define SHELL_SOC "soc"
1390
+
1391
+extern void _IsrWrapper(int idx, void *arg);
1392
+
1393
+typedef union DescriptorTableType {
1394
+    union DescriptorItemType {
1395
+        MasterConfigType mst;
1396
+        SlaveConfigType slv;
1397
+    } *item;
1398
+    uint8_t *buf;
1399
+} DescriptorTableType;
1400
+
1401
+const char *const VENDOR_NAME = "GNSS Sensor Ltd.";
1402
+
1403
+const char *const MST_DID_EMPTY_NAME = "Empty master slot";
1404
+const char *const SLV_DID_EMPTY_NAME = "Empty slave slot";
1405
+
1406
+const char *const UNKOWN_ID_NAME = "Unknown";
1407
+
1408
+static const char *const GNSS_SENSOR_MST_DEVICE_NAMES[] = {
1409
+    "Rocket Cached TileLink",           // 0x500
1410
+    "Rocket Uncached TileLink",         // 0x501
1411
+    "Gaisler Ethernet MAC with DMA",    // 0x502
1412
+    "Gaisler Ethernet EDCL with DMA",   // 0x503
1413
+    "Reserved",                         // 0x504
1414
+    "RISC-V River CPU",                 // 0x505
1415
+};
1416
+
1417
+static const char *const GNSS_SENSOR_SLV_DEVICE_NAMES[] = {
1418
+    "GNSS Engine stub",         // 0x68
1419
+    "Reserved",                 // 0x69
1420
+    "Reserved",                 // 0x6a
1421
+    "Reserved",                 // 0x6b
1422
+    "Reserved",                 // 0x6c
1423
+    "Reserved",                 // 0x6d
1424
+    "Reserved",                 // 0x6e
1425
+    "Reserved",                 // 0x6f
1426
+    "Reserved",                 // 0x70
1427
+    "Boot ROM",                 // 0x71
1428
+    "FW Image ROM",             // 0x72
1429
+    "Internal SRAM",            // 0x73
1430
+    "Plug'n'Play support",      // 0x74
1431
+    "SD Controller",            // 0x75
1432
+    "Generic GPIO",             // 0x76
1433
+    "RF front-end controller",  // 0x77
1434
+    "GNSS Engine",              // 0x78
1435
+    "GPS FSE",                  // 0x79
1436
+    "Generic UART",             // 0x7a
1437
+    "Accelerometer",            // 0x7b
1438
+    "Gyroscope",                // 0x7c
1439
+    "Interrupt Controller",     // 0x7d
1440
+    "Reserved",                 // 0x7e
1441
+    "Ethernet MAC",             // 0x7f
1442
+    "Debug Support Unit (DSU)", // 0x80
1443
+    "GP Timers"                 // 0x81
1444
+};
1445
+
1446
+/**
1447
+ * @brief Get technology name
1448
+ */
1449
+const char *const get_tech_name(uint32_t tech)
1450
+{
1451
+    switch (tech) {
1452
+    case TECH_INFERRED: return "inferred";
1453
+    case TECH_VIRTEX6: return "Virtex6";
1454
+    case TECH_KINTEX7: return "Kintex7";
1455
+    default:;
1456
+    }
1457
+    return "unknown";
1458
+}
1459
+
1460
+/**
1461
+ * @brief Get device Vendor name by its ID
1462
+ */
1463
+static const char *get_vendor_name(uint16_t vid)
1464
+{
1465
+    if (vid != VENDOR_GNSSSENSOR) {
1466
+        return UNKOWN_ID_NAME;
1467
+    }
1468
+    return VENDOR_NAME;
1469
+}
1470
+
1471
+/**
1472
+ * @brief Get device Name by Vendor ID and Device ID
1473
+ */
1474
+static const char *get_device_name(uint16_t vid, uint16_t did)
1475
+{
1476
+    if (vid != VENDOR_GNSSSENSOR) {
1477
+        return UNKOWN_ID_NAME;
1478
+    }
1479
+    if (did == MST_DID_EMPTY) {
1480
+        return MST_DID_EMPTY_NAME;
1481
+    }
1482
+    if (did == SLV_DID_EMPTY) {
1483
+        return SLV_DID_EMPTY_NAME;
1484
+    }
1485
+    if (did >= GNSSSENSOR_ENGINE_STUB && did <= GNSSSENSOR_GPTIMERS) {
1486
+        return GNSS_SENSOR_SLV_DEVICE_NAMES[did - GNSSSENSOR_ENGINE_STUB];
1487
+    }
1488
+    if (did >= RISCV_CACHED_TILELINK && did <= RISCV_RIVER_CPU) {
1489
+        return GNSS_SENSOR_MST_DEVICE_NAMES[did - RISCV_CACHED_TILELINK];
1490
+    }
1491
+    return UNKOWN_ID_NAME;
1492
+}
1493
+
1494
+/**
1495
+ * @brief Print Plug'n'Play information
1496
+ *
1497
+ * This function reads information from the PNP slave device that is mapped
1498
+ * into hardcoded address __PNP (0xFFFFF000).
1499
+ */
1500
+static int shell_cmd_soc_info(int argc, char *argv[])
1501
+{
1502
+    printk("RISC-V synthesizable SoC platform available for download at:\n");
1503
+    printk("    https://github.com/sergeykhbr/riscv_vhdl\n\n");
1504
+    printk("Author: Sergey Khabarov - sergeykhbr@gmail.com\n");
1505
+    return 0;
1506
+}
1507
+
1508
+/**
1509
+ * @brief Print Plug'n'Play information
1510
+ *
1511
+ * This function reads information from the PNP slave device that is mapped
1512
+ * into hardcoded address __PNP (0xFFFFF000).
1513
+ */
1514
+static int shell_cmd_soc_pnp(int argc, char *argv[])
1515
+{
1516
+    uint32_t slaves_total, tech, hwid;
1517
+    uint16_t vid, did;
1518
+    adr_type xaddr, xmask, xsize;
1519
+    volatile uint32_t *iter;
1520
+    MasterDescrWord mcfg;
1521
+    int mst_cnt=0, slv_cnt=0;
1522
+
1523
+    tech = READ32(&__PNP->tech);
1524
+    slaves_total = (tech >> 8) & 0xff;
1525
+    printk("# RISC-V:  Rocket-Chip demonstration design\n");
1526
+    hwid = READ32(&__PNP->hwid);
1527
+    printk("# HW id:   0x%x\n", hwid);
1528
+    hwid = READ32(&__PNP->fwid);
1529
+    printk("# FW id:   0x%x\n", hwid);
1530
+    printk("# Target technology: %s\n", get_tech_name(tech & 0xFF));
1531
+
1532
+    iter = (volatile uint32_t *)__PNP->cfg_table;
1533
+    mcfg.val = READ32(iter);
1534
+    while (mcfg.bits.descrtype != PNP_CFG_TYPE_INVALID) {
1535
+        if (mcfg.bits.descrtype == PNP_CFG_TYPE_MASTER) {
1536
+            MasterConfigType *pmst = (MasterConfigType *)iter;
1537
+            vid = READ16(&pmst->vid);
1538
+            did = READ16(&pmst->did);
1539
+            printk("# AXI4: mst%d: %s    %s\n", mst_cnt++,
1540
+                get_vendor_name(vid), get_device_name(vid, did));
1541
+        } else {
1542
+            SlaveConfigType *pslv = (SlaveConfigType *)iter;
1543
+            vid = READ16(&pslv->vid);
1544
+            did = READ16(&pslv->did);
1545
+            printk("# AXI4: slv%d: %s    %s\n", slv_cnt++,
1546
+                get_vendor_name(vid), get_device_name(vid, did));
1547
+
1548
+            xaddr = READ32(&pslv->xaddr);
1549
+            xmask = READ32(&pslv->xmask);
1550
+            xmask ^= 0xFFFFFFFF;
1551
+            xsize = xmask + 1;
1552
+
1553
+
1554
+            printk("#    %x...%x, size = ",
1555
+                (unsigned long)xaddr, (unsigned long)(xaddr + xmask));
1556
+            if (xsize < 1024) {
1557
+                printk("%d bytes\n", (int)xsize);
1558
+            } else if (xsize < 1024*1024) {
1559
+                printk("%d KB\n", (int)(xsize >> 10));
1560
+            } else {
1561
+                printk("%d MB\n", (int)(xsize >> 20));
1562
+            }
1563
+        }
1564
+
1565
+        iter = (volatile uint32_t *)((uint8_t *)iter + mcfg.bits.descrsize);
1566
+        mcfg.val = READ32(iter);
1567
+    }
1568
+    return 0;
1569
+}
1570
+
1571
+/**
1572
+ * @brief Check hardware target configuration is it inferred or not.
1573
+ *
1574
+ * inferred hardware target is used for RTL simulation of the whole SOC design.
1575
+ */
1576
+uint32_t soc_is_rtl_simulation()
1577
+{
1578
+    uint32_t tech = READ32(&__PNP->tech);
1579
+    return (tech & 0xff) == TECH_INFERRED ? 1: 0;
1580
+}
1581
+
1582
+/**
1583
+ *
1584
+ * @brief perform basic hardware initialization
1585
+ *
1586
+ * Hardware initialized:
1587
+ * - interrupt unit
1588
+ *
1589
+ * RETURNS: N/A
1590
+ */
1591
+static int riscv_gnss_soc_init(struct device *arg)
1592
+{
1593
+    ARG_UNUSED(arg);
1594
+    WRITE64(&__IRQCTRL->isr_table, (uint64_t)_IsrWrapper);
1595
+    WRITE32(&__IRQCTRL->irq_lock, 0);
1596
+    return 0;
1597
+}
1598
+
1599
+struct shell_cmd soc_commands[] = {
1600
+    { "info", shell_cmd_soc_info, "Show SoC RTL download link" },
1601
+    { "pnp", shell_cmd_soc_pnp, "Show Plug'n'Play information" },
1602
+    { NULL, NULL }
1603
+};
1604
+
1605
+SYS_INIT(riscv_gnss_soc_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
1606
+
1607
+SHELL_REGISTER(SHELL_SOC, soc_commands);
1608
diff --git a/arch/riscv64/soc/riscv_gnss/soc.h b/arch/riscv64/soc/riscv_gnss/soc.h
1609
new file mode 100644
1610
index 0000000..9206f41
1611
--- /dev/null
1612
+++ b/arch/riscv64/soc/riscv_gnss/soc.h
1613
@@ -0,0 +1,132 @@
1614
+/*
1615
+ * Copyright (c) 2016, GNSS Sensor Ltd.
1616
+ *
1617
+ * Licensed under the Apache License, Version 2.0 (the "License");
1618
+ * you may not use this file except in compliance with the License.
1619
+ * You may obtain a copy of the License at
1620
+ *
1621
+ *     http://www.apache.org/licenses/LICENSE-2.0
1622
+ *
1623
+ * Unless required by applicable law or agreed to in writing, software
1624
+ * distributed under the License is distributed on an "AS IS" BASIS,
1625
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1626
+ * See the License for the specific language governing permissions and
1627
+ * limitations under the License.
1628
+ */
1629
+
1630
+/**
1631
+ * @file SoC configuration macros for the GNSS Sensor Risc-V family processors.
1632
+ */
1633
+
1634
+#ifndef _RISCV_SOC_GNSS_H_
1635
+#define _RISCV_SOC_GNSS_H_
1636
+
1637
+#include <device.h>
1638
+#include <misc/util.h>
1639
+#include <drivers/rand32.h>
1640
+
1641
+#include "soc_registers.h"
1642
+
1643
+#define VENDOR_GNSSSENSOR        0x00F1
1644
+
1645
+#define MST_DID_EMPTY            0x7755
1646
+#define SLV_DID_EMPTY            0x5577     /// Dummy device
1647
+
1648
+/// Known master device IDs
1649
+#define RISCV_CACHED_TILELINK    0x0500
1650
+#define RISCV_UNCACHED_TILELINK  0x0501
1651
+#define GAISLER_ETH_MAC_MASTER   0x0502
1652
+#define GAISLER_ETH_EDCL_MASTER  0x0503
1653
+#define RISCV_RIVER_CPU          0x0505
1654
+/// Known slave device IDs
1655
+#define GNSSSENSOR_BOOTROM       0x0071     /// Boot ROM Device ID
1656
+#define GNSSSENSOR_FWIMAGE       0x0072     /// FW ROM image Device ID
1657
+#define GNSSSENSOR_SRAM          0x0073     /// Internal SRAM block Device ID
1658
+#define GNSSSENSOR_PNP           0x0074     /// Configuration Registers Module Device ID provided by gnsslib
1659
+#define GNSSSENSOR_SPI_FLASH     0x0075     /// SD-card controller Device ID provided by gnsslib
1660
+#define GNSSSENSOR_GPIO          0x0076     /// General purpose IOs Device ID provided by gnsslib
1661
+#define GNSSSENSOR_RF_CONTROL    0x0077     /// RF front-end controller Device ID provided by gnsslib
1662
+#define GNSSSENSOR_ENGINE        0x0078     /// GNSS Engine Device ID provided by gnsslib
1663
+#define GNSSSENSOR_ENGINE_STUB   0x0068     /// GNSS Engine stub
1664
+#define GNSSSENSOR_FSE_V2        0x0079     /// Fast Search Engines Device ID provided by gnsslib
1665
+#define GNSSSENSOR_UART          0x007a     /// rs-232 UART Device ID
1666
+#define GNSSSENSOR_ACCELEROMETER 0x007b     /// Accelerometer Device ID provided by gnsslib
1667
+#define GNSSSENSOR_GYROSCOPE     0x007c     /// Gyroscope Device ID provided by gnsslib
1668
+#define GNSSSENSOR_IRQCTRL       0x007d     /// Interrupt controller
1669
+#define GNSSSENSOR_ETHMAC        0x007f
1670
+#define GNSSSENSOR_DSU           0x0080
1671
+#define GNSSSENSOR_GPTIMERS      0x0081
1672
+
1673
+#define PNP_CFG_TYPE_INVALID     0
1674
+#define PNP_CFG_TYPE_MASTER      1
1675
+#define PNP_CFG_TYPE_SLAVE       2
1676
+
1677
+#define TECH_INFERRED       0
1678
+#define TECH_VIRTEX6        36
1679
+#define TECH_KINTEX7        49
1680
+
1681
+
1682
+
1683
+#define ADDR_NASTI_SLAVE_FWIMAGE    0x00100000
1684
+#define ADDR_NASTI_SLAVE_SRAM       0x10000000
1685
+#define ADDR_NASTI_SLAVE_GPIO       0x80000000
1686
+#define ADDR_NASTI_SLAVE_UART1      0x80001000
1687
+#define ADDR_NASTI_SLAVE_IRQCTRL    0x80002000
1688
+#define ADDR_NASTI_SLAVE_GNSSENGINE 0x80003000
1689
+#define ADDR_NASTI_SLAVE_RFCTRL     0x80004000
1690
+#define ADDR_NASTI_SLAVE_GPTIMERS   0x80005000
1691
+#define ADDR_NASTI_SLAVE_FSEGPS     0x8000a000
1692
+#define ADDR_NASTI_SLAVE_ETHMAC     0x80040000
1693
+#define ADDR_NASTI_SLAVE_PNP        0xfffff000
1694
+
1695
+/* Interrupts pins assignments */
1696
+#define CFG_IRQ_UNUSED      0
1697
+#define CFG_IRQ_UART1       1
1698
+#define CFG_IRQ_ETH         2
1699
+#define CFG_IRQ_SYS_TIMER   3
1700
+#define CFG_IRQ_MISS_ACCESS 4
1701
+#define CFG_IRQ_GNSS_ENGINE 5
1702
+
1703
+/* Use this general purpose timer as a system timer */
1704
+#define CFG_SYS_TIMER_IDX 0
1705
+
1706
+/* PNP */
1707
+#define PNP_CONFIG_DEFAULT_BYTES 16
1708
+
1709
+/* uart configuration settings */
1710
+#define UART_IRQ_FLAGS 0    // used in console driver
1711
+
1712
+
1713
+#ifndef _ASMLANGUAGE
1714
+
1715
+typedef uint64_t adr_type;
1716
+
1717
+
1718
+typedef void (*IRQ_HANDLER)(void *arg);
1719
+
1720
+
1721
+#define __PNP  ((volatile struct pnp_map *)ADDR_NASTI_SLAVE_PNP)
1722
+/** @todo remove hardcoded addresses except __PNP. */
1723
+#define __UART1        ((volatile struct uart_map *)ADDR_NASTI_SLAVE_UART1)
1724
+#define __IRQCTRL      ((volatile struct irqctrl_map *)ADDR_NASTI_SLAVE_IRQCTRL)
1725
+#define __TIMERS ((volatile struct gptimers_map *)ADDR_NASTI_SLAVE_GPTIMERS)
1726
+
1727
+/**
1728
+ * @brief Print Plug'n'Play information
1729
+ *
1730
+ * Each devices in a SOC implements sideband signals that are connected to
1731
+ * PNP module. These signals provide such information as Vendor/Device IDs,
1732
+ * memory address and allocated memory range.
1733
+ */
1734
+extern void soc_print_pnp();
1735
+
1736
+/**
1737
+ * @brief Check hardware target configuration is it inferred or not.
1738
+ *
1739
+ * inferred hardware target is used for RTL simulation of the whole SOC design.
1740
+ */
1741
+extern uint32_t soc_is_rtl_simulation();
1742
+
1743
+#endif /* !_ASMLANGUAGE */
1744
+
1745
+#endif /* _RISCV_SOC_GNSS_H_ */
1746
diff --git a/arch/riscv64/soc/riscv_gnss/soc_registers.h b/arch/riscv64/soc/riscv_gnss/soc_registers.h
1747
new file mode 100644
1748
index 0000000..4bbb4d6
1749
--- /dev/null
1750
+++ b/arch/riscv64/soc/riscv_gnss/soc_registers.h
1751
@@ -0,0 +1,114 @@
1752
+/*
1753
+ * Copyright (c) 2016, GNSS Sensor Ltd.
1754
+ *
1755
+ * Licensed under the Apache License, Version 2.0 (the "License");
1756
+ * you may not use this file except in compliance with the License.
1757
+ * You may obtain a copy of the License at
1758
+ *
1759
+ *     http://www.apache.org/licenses/LICENSE-2.0
1760
+ *
1761
+ * Unless required by applicable law or agreed to in writing, software
1762
+ * distributed under the License is distributed on an "AS IS" BASIS,
1763
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1764
+ * See the License for the specific language governing permissions and
1765
+ * limitations under the License.
1766
+ */
1767
+
1768
+/**
1769
+ * @file SoC configuration macros for the Atmel SAM3 family processors.
1770
+ *
1771
+ * Refer to the datasheet for more information about these registers.
1772
+ */
1773
+
1774
+#ifndef _RISCV_GNSS_SOC_REGS_H_
1775
+#define _RISCV_GNSS_SOC_REGS_H_
1776
+
1777
+typedef struct MasterDescrWordBits {
1778
+    uint32_t descrsize : 8;
1779
+    uint32_t descrtype : 2;
1780
+    uint32_t rsrv : 14;
1781
+    uint32_t master_idx : 8;
1782
+} MasterDescrWordBits;
1783
+
1784
+typedef union MasterDescrWord {
1785
+    MasterDescrWordBits bits;
1786
+    uint32_t val;
1787
+} MasterDescrWord;
1788
+
1789
+typedef struct MasterConfigType {
1790
+    MasterDescrWord descr;
1791
+    uint16_t did;
1792
+    uint16_t vid;
1793
+} MasterConfigType;
1794
+
1795
+typedef struct SlaveDescrWordBits {
1796
+    uint32_t descrsize : 8;
1797
+    uint32_t descrtype : 2;
1798
+    uint32_t bar_total : 2;
1799
+    uint32_t rsrv1 : 4;
1800
+    uint32_t irq_idx : 8;
1801
+    uint32_t rsrv2 : 8;
1802
+} SlaveDescrWordBits;
1803
+
1804
+typedef union SlaveDescrWord {
1805
+    SlaveDescrWordBits bits;
1806
+    uint32_t val;
1807
+} SlaveDescrWord;
1808
+
1809
+typedef struct SlaveConfigType {
1810
+    SlaveDescrWord descr;
1811
+    uint16_t did;
1812
+    uint16_t vid;
1813
+    uint32_t xmask;
1814
+    uint32_t xaddr;
1815
+} SlaveConfigType;
1816
+
1817
+typedef struct pnp_map {
1818
+    volatile uint32_t hwid;         /// Read only HW ID
1819
+    volatile uint32_t fwid;         /// Read/Write Firmware ID
1820
+    volatile uint32_t tech;         /// Read only technology index
1821
+    volatile uint32_t rsrv1;        ///
1822
+    volatile uint64_t idt;          ///
1823
+    volatile uint64_t malloc_addr;  /// debuggind memalloc pointer
1824
+    volatile uint64_t malloc_size;  /// debugging memalloc size
1825
+    volatile uint64_t fwdbg1;       /// FW debug register
1826
+    volatile uint64_t rsrv[2];
1827
+    uint8_t cfg_table[(1 << 12) - 0x40];    /// 0xfffff040: RO: PNP configuration
1828
+} pnp_map;
1829
+
1830
+typedef struct uart_map {
1831
+    volatile uint32_t status;
1832
+    volatile uint32_t scaler;
1833
+    uint32_t rsrv[2];
1834
+    volatile uint32_t data;
1835
+} uart_map;
1836
+
1837
+
1838
+typedef struct irqctrl_map {
1839
+    volatile uint32_t irq_mask;     // 0x00: [RW] 1=disable; 0=enable
1840
+    volatile uint32_t irq_pending;  // 0x04: [RW]
1841
+    volatile uint32_t irq_clear;    // 0x08: [WO]
1842
+    volatile uint32_t irq_rise;     // 0x0C: [WO]
1843
+    volatile uint64_t isr_table;    // 0x10: [RW]
1844
+    volatile uint64_t dbg_cause;    // 0x18:
1845
+    volatile uint64_t dbg_epc;      // 0x20:
1846
+    volatile uint32_t irq_lock;     // 0x28: interrupts wait while lock=1
1847
+    volatile uint32_t irq_cause_idx;// 0x2c:
1848
+} irqctrl_map;
1849
+
1850
+
1851
+typedef struct gptimer_type {
1852
+    volatile uint32_t control;      // [0] = count_ena; [1] = irq_ena
1853
+    volatile uint32_t rsv1;
1854
+    volatile uint64_t cur_value;
1855
+    volatile uint64_t init_value;
1856
+} gptimer_type;
1857
+
1858
+typedef struct gptimers_map {
1859
+    volatile uint64_t highcnt;
1860
+    volatile uint32_t pending;
1861
+    uint32_t rsv1[13];
1862
+    gptimer_type tmr[2];
1863
+} gptimer_map;
1864
+
1865
+#endif /* _RISCV_GNSS_SOC_REGS_H_ */
1866
diff --git a/boards/riscv64/riscv_gnss/Kconfig.board b/boards/riscv64/riscv_gnss/Kconfig.board
1867
new file mode 100644
1868
index 0000000..f6662ef
1869
--- /dev/null
1870
+++ b/boards/riscv64/riscv_gnss/Kconfig.board
1871
@@ -0,0 +1,6 @@
1872
+
1873
+config  BOARD_RISCV_GNSS
1874
+        bool "RISC-V based FPGA SoC"
1875
+        depends on SOC_RISCV_GNSS
1876
+       help
1877
+       The RISC-v VHDL FPGA development boards
1878
diff --git a/boards/riscv64/riscv_gnss/Kconfig.defconfig b/boards/riscv64/riscv_gnss/Kconfig.defconfig
1879
new file mode 100644
1880
index 0000000..8e55bc5
1881
--- /dev/null
1882
+++ b/boards/riscv64/riscv_gnss/Kconfig.defconfig
1883
@@ -0,0 +1,22 @@
1884
+
1885
+if BOARD_RISCV_GNSS
1886
+
1887
+config BOARD
1888
+        default riscv_gnss
1889
+
1890
+config CONSOLE
1891
+       def_bool y
1892
+
1893
+config UART_CONSOLE
1894
+       def_bool y
1895
+
1896
+config UART_INTERRUPT_DRIVEN
1897
+       def_bool y
1898
+
1899
+config CONSOLE_HANDLER_SHELL
1900
+       def_bool y
1901
+
1902
+config STDOUT_CONSOLE
1903
+       def_bool y
1904
+
1905
+endif # BOARD_RISCV_GNSS
1906
diff --git a/boards/riscv64/riscv_gnss/Makefile b/boards/riscv64/riscv_gnss/Makefile
1907
new file mode 100644
1908
index 0000000..7414f8c
1909
--- /dev/null
1910
+++ b/boards/riscv64/riscv_gnss/Makefile
1911
@@ -0,0 +1,6 @@
1912
+ccflags-y += -I$(srctree)/include/drivers
1913
+ccflags-y += -I$(srctree)/drivers
1914
+asflags-y := ${ccflags-y}
1915
+
1916
+# Force kbuild to make empty built-in.o if necessary
1917
+obj- := dummy.o
1918
diff --git a/boards/riscv64/riscv_gnss/board.h b/boards/riscv64/riscv_gnss/board.h
1919
new file mode 100644
1920
index 0000000..55029f6
1921
--- /dev/null
1922
+++ b/boards/riscv64/riscv_gnss/board.h
1923
@@ -0,0 +1,22 @@
1924
+/*
1925
+ * Copyright (c) 2015 Intel Corporation
1926
+ *
1927
+ * Licensed under the Apache License, Version 2.0 (the "License");
1928
+ * you may not use this file except in compliance with the License.
1929
+ * You may obtain a copy of the License at
1930
+ *
1931
+ *     http://www.apache.org/licenses/LICENSE-2.0
1932
+ *
1933
+ * Unless required by applicable law or agreed to in writing, software
1934
+ * distributed under the License is distributed on an "AS IS" BASIS,
1935
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1936
+ * See the License for the specific language governing permissions and
1937
+ * limitations under the License.
1938
+ */
1939
+
1940
+#ifndef __INC_BOARD_H
1941
+#define __INC_BOARD_H
1942
+
1943
+#include <soc.h>
1944
+
1945
+#endif /* __INC_BOARD_H */
1946
diff --git a/boards/riscv64/riscv_gnss/riscv_gnss_defconfig b/boards/riscv64/riscv_gnss/riscv_gnss_defconfig
1947
new file mode 100644
1948
index 0000000..f5ac997
1949
--- /dev/null
1950
+++ b/boards/riscv64/riscv_gnss/riscv_gnss_defconfig
1951
@@ -0,0 +1,39 @@
1952
+CONFIG_RISCV64=y
1953
+CONFIG_SOC_RISCV_GNSS=y
1954
+CONFIG_BOARD_RISCV_GNSS=y
1955
+CONFIG_PRINTK=y
1956
+CONFIG_STDOUT_CONSOLE=y
1957
+CONFIG_ENABLE_SHELL=y
1958
+xCONFIG_KERNEL_DEBUG=y
1959
+CONFIG_CONSOLE=y
1960
+CONFIG_EARLY_CONSOLE=y
1961
+CONFIG_UART_INTERRUPT_DRIVEN=y
1962
+CONFIG_BOOT_BANNER=y
1963
+CONFIG_CONSOLE_HAS_DRIVER=y
1964
+CONFIG_CONSOLE_HANDLER=y
1965
+CONFIG_CONSOLE_HANDLER_SHELL=y
1966
+CONFIG_CONSOLE_HANDLER_SHELL_STACKSIZE=2000
1967
+CONFIG_UART_CONSOLE=y
1968
+CONFIG_UART_CONSOLE_ON_DEV_NAME="UART_0"
1969
+CONFIG_NUM_COOP_PRIORITIES=16
1970
+CONFIG_NUM_PREEMPT_PRIORITIES=15
1971
+CONFIG_ISR_STACK_SIZE=2048
1972
+CONFIG_PRIORITY_CEILING=0
1973
+CONFIG_NUM_IRQS=6
1974
+CONFIG_SYS_CLOCK_EXISTS=y
1975
+CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=40000000
1976
+CONFIG_SYS_CLOCK_TICKS_PER_SEC=200
1977
+CONFIG_NANO_TIMEOUTS=y
1978
+CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
1979
+CONFIG_SYSTEM_WORKQUEUE_PRIORITY=-1
1980
+CONFIG_OFFLOAD_WORKQUEUE_STACK_SIZE=2048
1981
+CONFIG_OFFLOAD_WORKQUEUE_PRIORITY=-1
1982
+CONFIG_KERNEL_EVENT_LOGGER_BUFFER_SIZE=128
1983
+CONFIG_MAIN_THREAD_PRIORITY=0
1984
+CONFIG_MAIN_STACK_SIZE=2048
1985
+CONFIG_IDLE_STACK_SIZE=1024
1986
+CONFIG_SYSTEM_CLOCK_INIT_PRIORITY=0
1987
+CONFIG_KERNEL_INIT_PRIORITY_DEFAULT=40
1988
+CONFIG_ERRNO=y
1989
+CONFIG_NUM_MBOX_ASYNC_MSGS=10
1990
+CONFIG_NUM_PIPE_ASYNC_MSGS=10
1991
diff --git a/drivers/console/shells/kernel_service.c b/drivers/console/shells/kernel_service.c
1992
index 30bf90d..80b96a6 100644
1993
--- a/drivers/console/shells/kernel_service.c
1994
+++ b/drivers/console/shells/kernel_service.c
1995
@@ -14,6 +14,7 @@
1996
  * limitations under the License.
1997
  */
1998
 
1999
+#include <kernel_version.h>
2000
 #include <misc/printk.h>
2001
 #include <misc/shell.h>
2002
 #include <init.h>
2003
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
2004
index 6bfd267..7b2d020 100644
2005
--- a/drivers/serial/Kconfig
2006
+++ b/drivers/serial/Kconfig
2007
@@ -87,4 +87,6 @@ source "drivers/serial/Kconfig.cc32xx"
2008
 
2009
 source "drivers/serial/Kconfig.cmsdk_apb"
2010
 
2011
+source "drivers/serial/Kconfig.gnss"
2012
+
2013
 endif
2014
diff --git a/drivers/serial/Kconfig.gnss b/drivers/serial/Kconfig.gnss
2015
new file mode 100644
2016
index 0000000..9465075
2017
--- /dev/null
2018
+++ b/drivers/serial/Kconfig.gnss
2019
@@ -0,0 +1,7 @@
2020
+menuconfig UART_RISCV_GNSS
2021
+       bool "RISC-V GNSS board UART driver"
2022
+       default y
2023
+       help
2024
+       Enable the UART driver, built in generic CPU designs generated from
2025
+       VHDL.
2026
+
2027
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
2028
index 13d56c3..d3366be 100644
2029
--- a/drivers/serial/Makefile
2030
+++ b/drivers/serial/Makefile
2031
@@ -12,3 +12,4 @@ obj-$(CONFIG_UART_NRF5)         += uart_nrf5.o
2032
 obj-$(CONFIG_UART_ALTERA_JTAG)  += uart_altera_jtag.o
2033
 obj-$(CONFIG_UART_CC32XX)      += uart_cc32xx.o
2034
 obj-$(CONFIG_UART_CMSDK_APB)   += uart_cmsdk_apb.o
2035
+obj-$(CONFIG_UART_RISCV_GNSS)  += uart_gnss.o
2036
diff --git a/drivers/serial/uart_gnss.c b/drivers/serial/uart_gnss.c
2037
new file mode 100644
2038
index 0000000..d39af24
2039
--- /dev/null
2040
+++ b/drivers/serial/uart_gnss.c
2041
@@ -0,0 +1,267 @@
2042
+/*
2043
+ * Copyright (c) 2016, GNSS Sensor Ltd.
2044
+ *
2045
+ * Licensed under the Apache License, Version 2.0 (the "License");
2046
+ * you may not use this file except in compliance with the License.
2047
+ * You may obtain a copy of the License at
2048
+ *
2049
+ *     http://www.apache.org/licenses/LICENSE-2.0
2050
+ *
2051
+ * Unless required by applicable law or agreed to in writing, software
2052
+ * distributed under the License is distributed on an "AS IS" BASIS,
2053
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2054
+ * See the License for the specific language governing permissions and
2055
+ * limitations under the License.
2056
+ */
2057
+
2058
+#include <nanokernel.h>
2059
+#include <arch/cpu.h>
2060
+#include <sections.h>
2061
+#include <misc/__assert.h>
2062
+#include <stdint.h>
2063
+#include <misc/util.h>
2064
+#include <string.h>
2065
+#include <board.h>
2066
+#include <init.h>
2067
+#include <uart.h>
2068
+#include <irq.h>
2069
+#include <memaccess.h>
2070
+
2071
+#define UART_STATUS_TX_FULL     0x00000001
2072
+#define UART_STATUS_TX_EMPTY    0x00000002
2073
+#define UART_STATUS_RX_FULL     0x00000010
2074
+#define UART_STATUS_RX_EMPTY    0x00000020
2075
+#define UART_STATUS_ERR_PARITY  0x00000100
2076
+#define UART_STATUS_ERR_STOPBIT 0x00000200
2077
+#define UART_CONTROL_RX_IRQ_ENA 0x00002000
2078
+#define UART_CONTROL_TX_IRQ_ENA 0x00004000
2079
+#define UART_CONTROL_PARITY_ENA 0x00008000
2080
+
2081
+
2082
+static struct uart_driver_api uart_gnss_driver_api;
2083
+/* Device data structure */
2084
+struct uart_gnss_dev_data_t {
2085
+       uint32_t baud_rate;     /* Baud rate */
2086
+
2087
+#ifdef CONFIG_UART_INTERRUPT_DRIVEN
2088
+       uart_irq_callback_t     cb;     /**< Callback function pointer */
2089
+#endif
2090
+};
2091
+
2092
+static struct uart_gnss_dev_data_t uart_gnss_dev_data_0 = {
2093
+       115200,  // .baud_rate
2094
+    NULL
2095
+};
2096
+
2097
+
2098
+/**
2099
+ * @brief Interrupt service routine.
2100
+ *
2101
+ * This simply calls the callback function, if one exists.
2102
+ *
2103
+ * @param arg Argument to ISR.
2104
+ *
2105
+ * @return N/A
2106
+ */
2107
+void uart_gnss_isr(void *arg) {
2108
+    struct device *dev = (struct device *)arg;
2109
+    struct uart_gnss_dev_data_t *data =
2110
+        (struct uart_gnss_dev_data_t *)dev->driver_data;
2111
+    if (data->cb) {
2112
+        data->cb(dev);
2113
+    }
2114
+}
2115
+
2116
+/*
2117
+ * @brief Output a character to serial port
2118
+ *
2119
+ * @param dev UART device struct
2120
+ * @param c character to output
2121
+ */
2122
+unsigned char uart_gnss_poll_out(struct device *dev, unsigned char c)
2123
+{
2124
+       /* wait for transmitter to ready to accept a character */
2125
+    uint32_t status = READ32(&__UART1->status);
2126
+       while (status & UART_STATUS_TX_FULL) {
2127
+        status = READ32(&__UART1->status);
2128
+       }
2129
+       WRITE32(&__UART1->data, c);
2130
+       return c;
2131
+}
2132
+
2133
+static int uart_gnss_poll_in(struct device *dev, unsigned char *c)
2134
+{
2135
+       return -ENOTSUP;
2136
+
2137
+}
2138
+
2139
+/**
2140
+ * @brief Read data from FIFO
2141
+ *
2142
+ * @param dev UART device struct
2143
+ * @param rx_data Pointer to data container
2144
+ * @param size Container size
2145
+ *
2146
+ * @return Number of bytes read
2147
+ */
2148
+static int uart_gnss_fifo_read(struct device *dev, uint8_t *rx_data,
2149
+                                   const int size)
2150
+{
2151
+       uint32_t status = READ32(&__UART1->status);
2152
+       uint8_t num_rx = 0;
2153
+
2154
+       while ((size - num_rx > 0) && ((status & UART_STATUS_RX_EMPTY) == 0)) {
2155
+               rx_data[num_rx++] = (uint8_t)READ32(&__UART1->data);
2156
+        status = READ32(&__UART1->status);
2157
+       }
2158
+
2159
+       return num_rx;
2160
+}
2161
+
2162
+void uart_gnss_irq_tx_enable(struct device *dev) {
2163
+       uint32_t status = READ32(&__UART1->status);
2164
+    status |= UART_CONTROL_TX_IRQ_ENA;
2165
+    WRITE32(&__UART1->status, status);
2166
+}
2167
+
2168
+void uart_gnss_irq_tx_disable(struct device *dev) {
2169
+       uint32_t status = READ32(&__UART1->status);
2170
+    status &= ~UART_CONTROL_TX_IRQ_ENA;
2171
+    WRITE32(&__UART1->status, status);
2172
+}
2173
+
2174
+void uart_gnss_irq_rx_enable(struct device *dev) {
2175
+       uint32_t status = READ32(&__UART1->status);
2176
+    status |= UART_CONTROL_RX_IRQ_ENA;
2177
+    WRITE32(&__UART1->status, status);
2178
+}
2179
+
2180
+void uart_gnss_irq_rx_disable(struct device *dev) {
2181
+       uint32_t status = READ32(&__UART1->status);
2182
+    status &= ~UART_CONTROL_RX_IRQ_ENA;
2183
+    WRITE32(&__UART1->status, status);
2184
+}
2185
+
2186
+int uart_gnss_irq_tx_empty(struct device *dev) {
2187
+       uint32_t status = READ32(&__UART1->status);
2188
+       return ((status & UART_STATUS_TX_EMPTY) ? 1: 0);
2189
+}
2190
+
2191
+/**
2192
+ * @brief Check if Rx IRQ has been raised
2193
+ *
2194
+ * @param dev UART device struct
2195
+ *
2196
+ * @return 1 if an IRQ is ready, 0 otherwise
2197
+ */
2198
+static int uart_gnss_irq_rx_ready(struct device *dev)
2199
+{
2200
+       uint32_t status = READ32(&__UART1->status);
2201
+
2202
+       return ((status & UART_STATUS_RX_EMPTY) ? 0: 1);
2203
+}
2204
+
2205
+
2206
+/**
2207
+ * @brief Check if Tx or Rx IRQ is pending
2208
+ *
2209
+ * @param dev UART device struct
2210
+ *
2211
+ * @return 1 if a Tx or Rx IRQ is pending, 0 otherwise
2212
+ */
2213
+static int uart_gnss_irq_is_pending(struct device *dev)
2214
+{
2215
+       /* Look only at Tx and Rx data interrupt flags */
2216
+       return uart_gnss_irq_rx_ready(dev);
2217
+}
2218
+
2219
+
2220
+/**
2221
+ * @brief Update IRQ status
2222
+ *
2223
+ * @param dev UART device struct
2224
+ *
2225
+ * @return Always 1
2226
+ */
2227
+static int uart_gnss_irq_update(struct device *dev)
2228
+{
2229
+       return 1;
2230
+}
2231
+
2232
+/**
2233
+ * @brief Set the callback function pointer for IRQ.
2234
+ *
2235
+ * @param dev UART device struct
2236
+ * @param cb Callback function pointer.
2237
+ *
2238
+ * @return N/A
2239
+ */
2240
+ static void uart_gnss_irq_callback_set(struct device *dev,
2241
+                                        uart_irq_callback_t cb)
2242
+{
2243
+       struct uart_gnss_dev_data_t * const dev_data = dev->driver_data;
2244
+       dev_data->cb = cb;
2245
+}
2246
+
2247
+static struct uart_driver_api uart_gnss_driver_api = {
2248
+       uart_gnss_poll_in,  // poll_in
2249
+       uart_gnss_poll_out, // poll_out
2250
+       NULL,//int (*err_check)(struct device *dev);
2251
+
2252
+#ifdef CONFIG_UART_INTERRUPT_DRIVEN
2253
+       NULL,//int (*fifo_fill)(struct device *dev, const uint8_t *tx_data, int len);
2254
+       uart_gnss_fifo_read,
2255
+       uart_gnss_irq_tx_enable,
2256
+       uart_gnss_irq_tx_disable,
2257
+       NULL,//int (*irq_tx_ready)(struct device *dev);
2258
+       uart_gnss_irq_rx_enable,
2259
+       uart_gnss_irq_rx_disable,
2260
+       uart_gnss_irq_tx_empty,
2261
+       uart_gnss_irq_rx_ready,
2262
+       NULL,//void (*irq_err_enable)(struct device *dev);
2263
+       NULL,//void (*irq_err_disable)(struct device *dev);
2264
+       uart_gnss_irq_is_pending,
2265
+       uart_gnss_irq_update,
2266
+    uart_gnss_irq_callback_set,
2267
+#endif
2268
+
2269
+#ifdef CONFIG_UART_LINE_CTRL
2270
+       NULL,//int (*line_ctrl_set)(struct device *dev, uint32_t ctrl, uint32_t val);
2271
+#endif
2272
+
2273
+#ifdef CONFIG_UART_DRV_CMD
2274
+       NULL,//int (*drv_cmd)(struct device *dev, uint32_t cmd, uint32_t p);
2275
+#endif
2276
+};
2277
+
2278
+/**
2279
+ * @brief Initialize fake serial port
2280
+ *
2281
+ * @param dev UART device struct
2282
+ *
2283
+ * @return DEV_OK
2284
+ */
2285
+static int uart_gnss_init(struct device *dev)
2286
+{
2287
+       dev->driver_api = &uart_gnss_driver_api;
2288
+    dev->driver_data = &uart_gnss_dev_data_0;
2289
+
2290
+    // Speed-up RTL simulation avoidig long polling of the status register.
2291
+    if (soc_is_rtl_simulation() != 0) {
2292
+        WRITE32(&__UART1->scaler, 20);
2293
+    } else {
2294
+        WRITE32(&__UART1->scaler, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC/115200/2);
2295
+    }
2296
+
2297
+#ifdef CONFIG_UART_INTERRUPT_DRIVEN
2298
+    uart_gnss_irq_rx_enable(dev);
2299
+       IRQ_CONNECT(CFG_IRQ_UART1, CFG_IRQ_UART1, uart_gnss_isr, dev, UART_IRQ_FLAGS);
2300
+       irq_enable(CFG_IRQ_UART1);
2301
+#endif
2302
+       return 0;
2303
+}
2304
+
2305
+
2306
+DEVICE_INIT(uart_gnss0, "UART_0", &uart_gnss_init,
2307
+                       NULL, NULL,
2308
+                       PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
2309
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
2310
index 205407c..b2a1c54 100644
2311
--- a/drivers/timer/Makefile
2312
+++ b/drivers/timer/Makefile
2313
@@ -4,6 +4,7 @@ obj-$(CONFIG_HPET_TIMER) += hpet.o
2314
 obj-$(CONFIG_LOAPIC_TIMER) += loapic_timer.o
2315
 obj-$(CONFIG_ARCV2_TIMER) += arcv2_timer0.o
2316
 obj-$(CONFIG_ALTERA_AVALON_TIMER) += altera_avalon_timer.o
2317
+obj-$(CONFIG_RISCV_SYSTIMER) += riscv_systimer.o
2318
 
2319
 _CORTEX_M_SYSTICK_AND_GDB_INFO_yy = y
2320
 obj-$(CONFIG_CORTEX_M_SYSTICK) += cortex_m_systick.o
2321
diff --git a/drivers/timer/riscv_systimer.c b/drivers/timer/riscv_systimer.c
2322
new file mode 100644
2323
index 0000000..469be9a
2324
--- /dev/null
2325
+++ b/drivers/timer/riscv_systimer.c
2326
@@ -0,0 +1,148 @@
2327
+#include <nanokernel.h>
2328
+#include <arch/cpu.h>
2329
+#include <device.h>
2330
+#include <drivers/system_timer.h>
2331
+#include <soc.h>
2332
+#include <memaccess.h>
2333
+
2334
+/* running total of timer count */
2335
+static uint32_t __noinit cycles_per_tick;
2336
+static uint32_t accumulated_cycle_count;
2337
+
2338
+#define GPTIMER_CONTROL_COUNT_ENA   0x1
2339
+#define GPTIMER_CONTROL_IRQ_ENA     0x2
2340
+
2341
+/**
2342
+ *
2343
+ * @brief Read the platform's timer hardware
2344
+ *
2345
+ * This routine returns the current time in terms of timer hardware clock
2346
+ * cycles.
2347
+ *
2348
+ * @return up counter of elapsed clock cycles
2349
+ *
2350
+ * \INTERNAL WARNING
2351
+ * If this routine is ever enhanced to return all 64 bits of the counter
2352
+ * it will need to call _hpetMainCounterAtomic().
2353
+ */
2354
+
2355
+uint32_t k_cycle_get_32(void)
2356
+{
2357
+    //return (uint32_t)READ64(&__TIMERS->tmr[CFG_SYS_TIMER_IDX].cur_value);
2358
+       return (uint32_t)READ64(&__TIMERS->highcnt);
2359
+}
2360
+
2361
+uint64_t k_cycle_get_64(void)
2362
+{
2363
+       return READ64(&__TIMERS->highcnt);
2364
+}
2365
+
2366
+#if defined(CONFIG_SYSTEM_CLOCK_DISABLE)
2367
+/**
2368
+ *
2369
+ * @brief Stop announcing ticks into the kernel
2370
+ *
2371
+ * This routine disables timer interrupt generation and delivery.
2372
+ * Note that the timer's counting cannot be stopped by software.
2373
+ *
2374
+ * @return N/A
2375
+ */
2376
+void sys_clock_disable(void)
2377
+{
2378
+       unsigned int key;  /* interrupt lock level */
2379
+       uint32_t control; /* timer control register value */
2380
+
2381
+       key = irq_lock();
2382
+
2383
+       /* disable interrupt generation */
2384
+
2385
+       control = timer0_control_register_get();
2386
+       timer0_control_register_set(control & ~_ARC_V2_TMR_CTRL_IE);
2387
+
2388
+       irq_unlock(key);
2389
+
2390
+       /* disable interrupt in the interrupt controller */
2391
+
2392
+       irq_disable(CONFIG_ARCV2_TIMER0_INT_LVL);
2393
+}
2394
+#endif /* CONFIG_SYSTEM_CLOCK_DISABLE */
2395
+
2396
+
2397
+#ifdef CONFIG_TICKLESS_IDLE
2398
+static INLINE void update_accumulated_count(void)
2399
+{
2400
+       accumulated_cycle_count += (_sys_idle_elapsed_ticks * cycles_per_tick);
2401
+}
2402
+#else /* CONFIG_TICKLESS_IDLE */
2403
+static INLINE void update_accumulated_count(void)
2404
+{
2405
+       accumulated_cycle_count += cycles_per_tick;
2406
+}
2407
+#endif /* CONFIG_TICKLESS_IDLE */
2408
+
2409
+/**
2410
+ *
2411
+ * @brief System clock periodic tick handler
2412
+ *
2413
+ * This routine handles the system clock periodic tick interrupt. It always
2414
+ * announces one tick.
2415
+ *
2416
+ * @return N/A
2417
+ */
2418
+void _timer_int_handler(void *unused)
2419
+{
2420
+       ARG_UNUSED(unused);
2421
+
2422
+       /* clear the interrupt by writing 0 to IP bit of the control register */
2423
+    WRITE32(&__IRQCTRL->irq_clear, (1u << CFG_IRQ_SYS_TIMER));
2424
+    WRITE32(&__TIMERS->pending, 0);
2425
+
2426
+#if defined(CONFIG_TICKLESS_IDLE)
2427
+       timer0_limit_register_set(cycles_per_tick - 1);
2428
+
2429
+       _sys_idle_elapsed_ticks = 1;
2430
+#endif
2431
+
2432
+       update_accumulated_count();
2433
+       _sys_clock_tick_announce();
2434
+}
2435
+
2436
+/*
2437
+ * @brief initialize the tickless idle feature
2438
+ *
2439
+ * This routine initializes the tickless idle feature.
2440
+ *
2441
+ * @return N/A
2442
+ */
2443
+static void tickless_idle_init(void) {}
2444
+
2445
+int _sys_clock_driver_init(struct device *device) {
2446
+       ARG_UNUSED(device);
2447
+
2448
+       /* ensure that the timer will not generate interrupts */
2449
+    WRITE32(&__TIMERS->tmr[CFG_SYS_TIMER_IDX].control, 0);
2450
+
2451
+    sys_clock_hw_cycles_per_tick = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC /
2452
+                                    sys_clock_ticks_per_sec;
2453
+       cycles_per_tick = sys_clock_hw_cycles_per_tick;
2454
+    accumulated_cycle_count = 0;
2455
+
2456
+       IRQ_CONNECT(CFG_IRQ_SYS_TIMER, 0, _timer_int_handler, 0, 0);
2457
+
2458
+       /*
2459
+        * Set the reload value to achieve the configured tick rate, enable the
2460
+        * counter and interrupt generation.
2461
+        */
2462
+
2463
+       tickless_idle_init();
2464
+
2465
+    WRITE64(&__TIMERS->tmr[CFG_SYS_TIMER_IDX].init_value, cycles_per_tick - 1);
2466
+    WRITE32(&__TIMERS->tmr[CFG_SYS_TIMER_IDX].control,
2467
+        GPTIMER_CONTROL_COUNT_ENA | GPTIMER_CONTROL_IRQ_ENA);
2468
+
2469
+       /* everything has been configured: safe to enable the interrupt */
2470
+
2471
+       irq_enable(CFG_IRQ_SYS_TIMER);
2472
+
2473
+    return 0;
2474
+}
2475
diff --git a/include/arch/cpu.h b/include/arch/cpu.h
2476
index 11f5b8e..513f101 100644
2477
--- a/include/arch/cpu.h
2478
+++ b/include/arch/cpu.h
2479
@@ -27,6 +27,8 @@
2480
 #include <arch/arc/arch.h>
2481
 #elif defined(CONFIG_NIOS2)
2482
 #include <arch/nios2/arch.h>
2483
+#elif defined(CONFIG_RISCV64)
2484
+#include <arch/riscv64/arch.h>
2485
 #else
2486
 #error "Unknown Architecture"
2487
 #endif
2488
diff --git a/include/arch/riscv64/arch.h b/include/arch/riscv64/arch.h
2489
new file mode 100644
2490
index 0000000..1dc50b5
2491
--- /dev/null
2492
+++ b/include/arch/riscv64/arch.h
2493
@@ -0,0 +1,288 @@
2494
+/*
2495
+ * Copyright (c) 2014 Wind River Systems, Inc.
2496
+ *
2497
+ * Licensed under the Apache License, Version 2.0 (the "License");
2498
+ * you may not use this file except in compliance with the License.
2499
+ * You may obtain a copy of the License at
2500
+ *
2501
+ *     http://www.apache.org/licenses/LICENSE-2.0
2502
+ *
2503
+ * Unless required by applicable law or agreed to in writing, software
2504
+ * distributed under the License is distributed on an "AS IS" BASIS,
2505
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2506
+ * See the License for the specific language governing permissions and
2507
+ * limitations under the License.
2508
+ */
2509
+
2510
+/**
2511
+ * @file
2512
+ * @brief RISC-V specific nanokernel interface header
2513
+ *
2514
+ * This header contains the ARC specific nanokernel interface.  It is
2515
+ * included by the nanokernel interface architecture-abstraction header
2516
+ * (nanokernel/cpu.h)
2517
+ */
2518
+
2519
+#ifndef _RISCV_ARCH__H_
2520
+#define _RISCV_ARCH__H_
2521
+
2522
+#ifdef __cplusplus
2523
+extern "C" {
2524
+#endif
2525
+
2526
+/* APIs need to support non-byte addressible architectures */
2527
+
2528
+#define OCTET_TO_SIZEOFUNIT(X) (X)
2529
+#define SIZEOFUNIT_TO_OCTET(X) (X)
2530
+
2531
+#include <sw_isr_table.h>
2532
+#include <stdint.h>
2533
+#include <toolchain.h>
2534
+#include "asm_inline.h"
2535
+
2536
+#define STACK_ALIGN  8
2537
+
2538
+#ifdef _ASMLANGUAGE
2539
+
2540
+
2541
+#else // !_ASMLANGUAGE
2542
+/** interrupt/exception/error related definitions */
2543
+typedef void (*NANO_EOI_GET_FUNC) (void *);
2544
+
2545
+/**
2546
+ * @brief Disable all interrupts on the CPU (inline)
2547
+ *
2548
+ * This routine disables interrupts.  It can be called from either interrupt,
2549
+ * task or fiber level.  This routine returns an architecture-dependent
2550
+ * lock-out key representing the "interrupt disable state" prior to the call;
2551
+ * this key can be passed to irq_unlock() to re-enable interrupts.
2552
+ *
2553
+ * The lock-out key should only be used as the argument to the irq_unlock()
2554
+ * API.  It should never be used to manually re-enable interrupts or to inspect
2555
+ * or manipulate the contents of the source register.
2556
+ *
2557
+ * This function can be called recursively: it will return a key to return the
2558
+ * state of interrupt locking to the previous level.
2559
+ *
2560
+ * WARNINGS
2561
+ * Invoking a kernel routine with interrupts locked may result in
2562
+ * interrupts being re-enabled for an unspecified period of time.  If the
2563
+ * called routine blocks, interrupts will be re-enabled while another
2564
+ * thread executes, or while the system is idle.
2565
+ *
2566
+ * The "interrupt disable state" is an attribute of a thread.  Thus, if a
2567
+ * fiber or task disables interrupts and subsequently invokes a kernel
2568
+ * routine that causes the calling thread to block, the interrupt
2569
+ * disable state will be restored when the thread is later rescheduled
2570
+ * for execution.
2571
+ *
2572
+ * @return An architecture-dependent lock-out key representing the
2573
+ * "interrupt disable state" prior to the call.
2574
+ *
2575
+ */
2576
+
2577
+extern unsigned int _arch_irq_lock(void);
2578
+
2579
+
2580
+/**
2581
+ *
2582
+ * @brief Enable all interrupts on the CPU (inline)
2583
+ *
2584
+ * This routine re-enables interrupts on the CPU.  The @a key parameter
2585
+ * is an architecture-dependent lock-out key that is returned by a previous
2586
+ * invocation of irq_lock().
2587
+ *
2588
+ * This routine can be called from either interrupt, task or fiber level.
2589
+ *
2590
+ * @return N/A
2591
+ *
2592
+ */
2593
+
2594
+extern void _arch_irq_unlock(unsigned int key);
2595
+
2596
+/**
2597
+ *
2598
+ * @brief Read interrupts state on the CPU (inline)
2599
+ *
2600
+ * This routine check interrupts on the CPU.
2601
+  * This routine can be called from either interrupt, task or fiber level.
2602
+ *
2603
+ * @return N/A
2604
+ *
2605
+ */
2606
+
2607
+extern unsigned int _arch_irq_lock_state();
2608
+
2609
+/**
2610
+ *
2611
+ * @brief Enable an interrupt line
2612
+ *
2613
+ * Clear possible pending interrupts on the line, and enable the interrupt
2614
+ * line. After this call, the CPU will receive interrupts for the specified
2615
+ * <irq>.
2616
+ *
2617
+ * @return N/A
2618
+ */
2619
+extern void _arch_irq_enable(unsigned int irq);
2620
+
2621
+/**
2622
+ *
2623
+ * @brief Disable an interrupt line
2624
+ *
2625
+ * Disable an interrupt line. After this call, the CPU will stop receiving
2626
+ * interrupts for the specified <irq>.
2627
+ *
2628
+ * @return N/A
2629
+ */
2630
+extern void _arch_irq_disable(unsigned int irq);
2631
+
2632
+/**
2633
+ * Configure a dynamic interrupt.
2634
+ *
2635
+ * @param irq IRQ line number
2636
+ * @param priority Interrupt priority
2637
+ * @param routine Interrupt service routine
2638
+ * @param parameter ISR parameter
2639
+ * @param flags Arch-specific IRQ configuration flags
2640
+ *
2641
+ * @return The vector assigned to this interrupt
2642
+ */
2643
+int _arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
2644
+                            void (*routine)(void *parameter), void *parameter,
2645
+                            uint32_t flags);
2646
+
2647
+
2648
+/**
2649
+ * Configure a static interrupt.
2650
+ *
2651
+ * All arguments must be computable by the compiler at build time; if this
2652
+ * can't be done use irq_connect_dynamic() instead.
2653
+ *
2654
+ * Internally this function does a few things:
2655
+ *
2656
+ * 1. The enum statement has no effect but forces the compiler to only
2657
+ * accept constant values for the irq_p parameter, very important as the
2658
+ * numerical IRQ line is used to create a named section.
2659
+ *
2660
+ * 2. An instance of _IsrTableEntry is created containing the ISR and its
2661
+ * parameter. If you look at how _sw_isr_table is created, each entry in the
2662
+ * array is in its own section named by the IRQ line number. What we are doing
2663
+ * here is to override one of the default entries (which points to the
2664
+ * spurious IRQ handler) with what was supplied here.
2665
+ *
2666
+ * 3. The priority level for the interrupt is configured by a call to
2667
+ * _irq_priority_set()
2668
+ *
2669
+ * @param irq_p IRQ line number
2670
+ * @param priority_p Interrupt priority
2671
+ * @param isr_p Interrupt service routine
2672
+ * @param isr_param_p ISR parameter
2673
+ * @param flags_p IRQ triggering options (currently unused)
2674
+ *
2675
+ * @return The vector assigned to this interrupt
2676
+ */
2677
+#define _ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
2678
+       _arch_irq_connect_dynamic(irq_p, priority_p, isr_p, isr_param_p, \
2679
+                                 flags_p)
2680
+
2681
+
2682
+
2683
+/**
2684
+ * The NANO_SOFT_IRQ macro must be used as the value for the @a irq parameter
2685
+ * to NANO_CPU_INT_REGSITER when connecting to an interrupt that does not
2686
+ * correspond to any IRQ line (such as spurious vector or SW IRQ)
2687
+ */
2688
+#define NANO_SOFT_IRQ  ((unsigned int) (-1))
2689
+
2690
+/**
2691
+ * @brief Nanokernel Exception Stack Frame
2692
+ *
2693
+ * A pointer to an "exception stack frame" (ESF) is passed as an argument
2694
+ * to exception handlers registered via nanoCpuExcConnect().  As the system
2695
+ * always operates at ring 0, only the EIP, CS and EFLAGS registers are pushed
2696
+ * onto the stack when an exception occurs.
2697
+ *
2698
+ * The exception stack frame includes the volatile registers (EAX, ECX, and
2699
+ * EDX) as well as the 5 non-volatile registers (EDI, ESI, EBX, EBP and ESP).
2700
+ * Those registers are pushed onto the stack by _ExcEnt().
2701
+ */
2702
+
2703
+typedef struct nanoEsf {
2704
+       unsigned int esp;
2705
+       unsigned int ebp;
2706
+       unsigned int ebx;
2707
+       unsigned int esi;
2708
+       unsigned int edi;
2709
+       unsigned int edx;
2710
+       unsigned int eax;
2711
+       unsigned int ecx;
2712
+       unsigned int errorCode;
2713
+       unsigned int eip;
2714
+       unsigned int cs;
2715
+       unsigned int eflags;
2716
+} NANO_ESF;
2717
+
2718
+/**
2719
+ * @brief Nanokernel "interrupt stack frame" (ISF)
2720
+ *
2721
+ * An "interrupt stack frame" (ISF) as constructed by the processor
2722
+ * and the interrupt wrapper function _IntEnt().  As the system always operates
2723
+ * at ring 0, only the EIP, CS and EFLAGS registers are pushed onto the stack
2724
+ * when an interrupt occurs.
2725
+ *
2726
+ * The interrupt stack frame includes the volatile registers EAX, ECX, and EDX
2727
+ * pushed on the stack by _IntEnt().
2728
+ */
2729
+
2730
+typedef struct nanoIsf {
2731
+       unsigned int edx;
2732
+       unsigned int ecx;
2733
+       unsigned int eax;
2734
+       unsigned int eip;
2735
+       unsigned int cs;
2736
+       unsigned int eflags;
2737
+} NANO_ISF;
2738
+
2739
+
2740
+/*
2741
+ * Reason codes passed to both _NanoFatalErrorHandler()
2742
+ * and _SysFatalErrorHandler().
2743
+ */
2744
+
2745
+/** Unhandled exception/interrupt */
2746
+#define _NANO_ERR_SPURIOUS_INT          (0)
2747
+/** Page fault */
2748
+#define _NANO_ERR_PAGE_FAULT            (1)
2749
+/** General protection fault */
2750
+#define _NANO_ERR_GEN_PROT_FAULT        (2)
2751
+/** Invalid task exit */
2752
+#define _NANO_ERR_INVALID_TASK_EXIT  (3)
2753
+/** Stack corruption detected */
2754
+#define _NANO_ERR_STACK_CHK_FAIL        (4)
2755
+/** Kernel Allocation Failure */
2756
+#define _NANO_ERR_ALLOCATION_FAIL    (5)
2757
+/** Unhandled exception */
2758
+#define _NANO_ERR_CPU_EXCEPTION                (6)
2759
+
2760
+
2761
+#include <stddef.h>    /* for size_t */
2762
+
2763
+extern void    nano_cpu_idle(void);
2764
+
2765
+/** Nanokernel provided routine to report any detected fatal error. */
2766
+extern FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason,
2767
+                                                const NANO_ESF * pEsf);
2768
+/** User provided routine to handle any detected fatal error post reporting. */
2769
+extern FUNC_NORETURN void _SysFatalErrorHandler(unsigned int reason,
2770
+                                               const NANO_ESF * pEsf);
2771
+/** Dummy ESF for fatal errors that would otherwise not have an ESF */
2772
+extern const NANO_ESF _default_esf;
2773
+
2774
+#endif  // _ASMLANGUAGE/!_ASMLANGUAGE
2775
+
2776
+#ifdef __cplusplus
2777
+}
2778
+#endif
2779
+
2780
+
2781
+#endif /* _RISCV_ARCH__H_ */
2782
diff --git a/include/arch/riscv64/asm_inline.h b/include/arch/riscv64/asm_inline.h
2783
new file mode 100644
2784
index 0000000..9724134
2785
--- /dev/null
2786
+++ b/include/arch/riscv64/asm_inline.h
2787
@@ -0,0 +1,33 @@
2788
+/*
2789
+ * Copyright (c) 2016 Intel Corporation
2790
+ *
2791
+ * Licensed under the Apache License, Version 2.0 (the "License");
2792
+ * you may not use this file except in compliance with the License.
2793
+ * You may obtain a copy of the License at
2794
+ *
2795
+ *     http://www.apache.org/licenses/LICENSE-2.0
2796
+ *
2797
+ * Unless required by applicable law or agreed to in writing, software
2798
+ * distributed under the License is distributed on an "AS IS" BASIS,
2799
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2800
+ * See the License for the specific language governing permissions and
2801
+ * limitations under the License.
2802
+ */
2803
+
2804
+#ifndef _ASM_INLINE_PUBLIC_H
2805
+#define _ASM_INLINE_PUBLIC_H
2806
+
2807
+/*
2808
+ * The file must not be included directly
2809
+ * Include kernel.h instead
2810
+ */
2811
+
2812
+#if defined(__GNUC__)
2813
+#include <arch/riscv64/asm_inline_gcc.h>
2814
+#elif defined _WIN32
2815
+#include <arch/riscv64/asm_inline_cl.h>
2816
+#else
2817
+#include <arch/riscv64/asm_inline_other.h>
2818
+#endif
2819
+
2820
+#endif /* _ASM_INLINE_PUBLIC_H */
2821
diff --git a/include/arch/riscv64/asm_inline_cl.h b/include/arch/riscv64/asm_inline_cl.h
2822
new file mode 100644
2823
index 0000000..8a67967
2824
--- /dev/null
2825
+++ b/include/arch/riscv64/asm_inline_cl.h
2826
@@ -0,0 +1,64 @@
2827
+/*
2828
+ * Copyright (c) 2015, Wind River Systems, Inc.
2829
+ *
2830
+ * Licensed under the Apache License, Version 2.0 (the "License");
2831
+ * you may not use this file except in compliance with the License.
2832
+ * You may obtain a copy of the License at
2833
+ *
2834
+ *     http://www.apache.org/licenses/LICENSE-2.0
2835
+ *
2836
+ * Unless required by applicable law or agreed to in writing, software
2837
+ * distributed under the License is distributed on an "AS IS" BASIS,
2838
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2839
+ * See the License for the specific language governing permissions and
2840
+ * limitations under the License.
2841
+ */
2842
+
2843
+/* Either public functions or macros or invoked by public functions */
2844
+
2845
+#ifndef _ASM_INLINE_GCC_PUBLIC_CL_H
2846
+#define _ASM_INLINE_GCC_PUBLIC_CL_H
2847
+
2848
+#include <stdint.h>
2849
+#include <toolchain.h>
2850
+
2851
+#ifdef __cplusplus
2852
+extern "C" {
2853
+#endif
2854
+
2855
+/*
2856
+ * The file must not be included directly
2857
+ * Include arch/cpu.h instead
2858
+ */
2859
+
2860
+
2861
+/**
2862
+ *
2863
+ * @brief find least significant bit set in a 32-bit word
2864
+ *
2865
+ * This routine finds the first bit set starting from the least significant bit
2866
+ * in the argument passed in and returns the index of that bit.  Bits are
2867
+ * numbered starting at 1 from the least significant bit.  A return value of
2868
+ * zero indicates that the value passed is zero.
2869
+ *
2870
+ * @return least significant bit set, 0 if @a op is 0
2871
+ */
2872
+
2873
+static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
2874
+{
2875
+       unsigned int ret = 1;
2876
+    if (op == 0) {
2877
+        return 0;
2878
+    }
2879
+       while ((op & 1) == 0) {
2880
+        op >>= 1;
2881
+               ret++;
2882
+       }
2883
+       return ret;
2884
+}
2885
+
2886
+#ifdef __cplusplus
2887
+}
2888
+#endif
2889
+
2890
+#endif /* _ASM_INLINE_GCC_PUBLIC_CL_H */
2891
diff --git a/include/arch/riscv64/asm_inline_gcc.h b/include/arch/riscv64/asm_inline_gcc.h
2892
new file mode 100644
2893
index 0000000..11a5961
2894
--- /dev/null
2895
+++ b/include/arch/riscv64/asm_inline_gcc.h
2896
@@ -0,0 +1,57 @@
2897
+/* ARM Cortex-M GCC specific public inline assembler functions and macros */
2898
+
2899
+/*
2900
+ * Copyright (c) 2015, Wind River Systems, Inc.
2901
+ *
2902
+ * Licensed under the Apache License, Version 2.0 (the "License");
2903
+ * you may not use this file except in compliance with the License.
2904
+ * You may obtain a copy of the License at
2905
+ *
2906
+ *     http://www.apache.org/licenses/LICENSE-2.0
2907
+ *
2908
+ * Unless required by applicable law or agreed to in writing, software
2909
+ * distributed under the License is distributed on an "AS IS" BASIS,
2910
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2911
+ * See the License for the specific language governing permissions and
2912
+ * limitations under the License.
2913
+ */
2914
+
2915
+/* Either public functions or macros or invoked by public functions */
2916
+
2917
+#ifndef _ASM_INLINE_GCC_PUBLIC_GCC_H
2918
+#define _ASM_INLINE_GCC_PUBLIC_GCC_H
2919
+
2920
+#ifdef __cplusplus
2921
+extern "C" {
2922
+#endif
2923
+
2924
+/*
2925
+ * The file must not be included directly
2926
+ * Include arch/cpu.h instead
2927
+ */
2928
+
2929
+#ifdef _ASMLANGUAGE
2930
+
2931
+#else /* !_ASMLANGUAGE */
2932
+#include <stdint.h>
2933
+
2934
+static ALWAYS_INLINE unsigned int find_lsb_set(uint32_t op)
2935
+{
2936
+       unsigned int ret = 1;
2937
+    if (op == 0) {
2938
+        return 0;
2939
+    }
2940
+       while ((op & 1) == 0) {
2941
+        op >>= 1;
2942
+               ret++;
2943
+       }
2944
+       return ret;
2945
+}
2946
+
2947
+#endif /* _ASMLANGUAGE */
2948
+
2949
+#ifdef __cplusplus
2950
+}
2951
+#endif
2952
+
2953
+#endif /* _ASM_INLINE_GCC_PUBLIC_GCC_H */
2954
diff --git a/include/arch/riscv64/linker.ld b/include/arch/riscv64/linker.ld
2955
new file mode 100644
2956
index 0000000..f4ee018
2957
--- /dev/null
2958
+++ b/include/arch/riscv64/linker.ld
2959
@@ -0,0 +1,130 @@
2960
+/*
2961
+ * Copyright (c) 2014-2015 Wind River Systems, Inc.
2962
+ *
2963
+ * Licensed under the Apache License, Version 2.0 (the "License");
2964
+ * you may not use this file except in compliance with the License.
2965
+ * You may obtain a copy of the License at
2966
+ *
2967
+ *     http://www.apache.org/licenses/LICENSE-2.0
2968
+ *
2969
+ * Unless required by applicable law or agreed to in writing, software
2970
+ * distributed under the License is distributed on an "AS IS" BASIS,
2971
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2972
+ * See the License for the specific language governing permissions and
2973
+ * limitations under the License.
2974
+ */
2975
+
2976
+/**
2977
+ * @brief Common parts of the linker scripts for the RISC-V targets.
2978
+ */
2979
+
2980
+#define _LINKER
2981
+#define _ASMLANGUAGE
2982
+
2983
+#include <autoconf.h>
2984
+#include <sections.h>
2985
+
2986
+#include <linker-defs.h>
2987
+#include <linker-tool.h>
2988
+
2989
+/* physical address of RAM */
2990
+#define ROMABLE_REGION SRAM
2991
+#define RAMABLE_REGION SRAM
2992
+
2993
+MEMORY {
2994
+       SRAM  (rwx) : ORIGIN = CONFIG_SRAM_BASE_ADDRESS,  LENGTH = CONFIG_SRAM_SIZE*1k
2995
+}
2996
+
2997
+SECTIONS {
2998
+       GROUP_START(ROMABLE_REGION)
2999
+
3000
+       SECTION_PROLOGUE(_TEXT_SECTION_NAME,,ALIGN(8)) {
3001
+               _image_rom_start = .;
3002
+               _image_text_start = .;
3003
+
3004
+               *(.text)
3005
+               *(".text.*")
3006
+               *(.gnu.linkonce.t.*)
3007
+
3008
+               _image_text_end = .;
3009
+       } GROUP_LINK_IN(ROMABLE_REGION)
3010
+
3011
+#include <linker/common-rom.ld>
3012
+
3013
+       SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) {
3014
+               *(.rodata)
3015
+               *(".rodata.*")
3016
+               *(.gnu.linkonce.r.*)
3017
+       } GROUP_LINK_IN(ROMABLE_REGION)
3018
+
3019
+       _image_rom_end = .;
3020
+       __data_rom_start = ALIGN(4);    /* XIP imaged DATA ROM start addr */
3021
+
3022
+       GROUP_END(ROMABLE_REGION)
3023
+
3024
+       GROUP_START(RAMABLE_REGION)
3025
+
3026
+       SECTION_PROLOGUE(_DATA_SECTION_NAME,,) {
3027
+
3028
+               _image_ram_start = .;
3029
+               __data_ram_start = .;
3030
+               *(.data)
3031
+               *(".data.*")
3032
+
3033
+
3034
+
3035
+               KEEP(*(._sw_isr_table))
3036
+               KEEP(*(.isr_demux_table))
3037
+
3038
+       } GROUP_LINK_IN(RAMABLE_REGION)
3039
+
3040
+#include <linker/common-ram.ld>
3041
+
3042
+       __data_ram_end = .;
3043
+
3044
+       SECTION_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),) {
3045
+               /*
3046
+                * For performance, BSS section is assumed to be 4 byte aligned and
3047
+                * a multiple of 4 bytes
3048
+                */
3049
+               . = ALIGN(4);
3050
+               __bss_start = .;
3051
+               *(.bss)
3052
+               *(".bss.*")
3053
+               COMMON_SYMBOLS
3054
+               /*
3055
+                * BSP clears this memory in words only and doesn't clear any
3056
+                * potential left over bytes.
3057
+                */
3058
+               __bss_end = ALIGN(4);
3059
+       } GROUP_LINK_IN(RAMABLE_REGION)
3060
+
3061
+       SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),) {
3062
+               /*
3063
+                * This section is used for non-initialized objects that
3064
+                * will not be cleared during the boot process.
3065
+                */
3066
+               *(.noinit)
3067
+               *(".noinit.*")
3068
+
3069
+       } GROUP_LINK_IN(RAMABLE_REGION)
3070
+
3071
+       /* Define linker symbols */
3072
+       _image_ram_end = .;
3073
+       _end = .; /* end of image */
3074
+       __bss_num_words = (__bss_end - __bss_start) >> 2;
3075
+
3076
+       GROUP_END(RAMABLE_REGION)
3077
+
3078
+       /* Data Closely Coupled Memory (DCCM) */
3079
+       GROUP_START(DCCM)
3080
+       GROUP_END(DCCM)
3081
+
3082
+       SECTION_PROLOGUE(initlevel_error, (OPTIONAL),)
3083
+       {
3084
+               DEVICE_INIT_UNDEFINED_SECTION()
3085
+       }
3086
+       ASSERT(SIZEOF(initlevel_error) == 0, "Undefined initialization levels used.")
3087
+
3088
+       }
3089
+
3090
diff --git a/include/drivers/console/uart_console.h b/include/drivers/console/uart_console.h
3091
index eea285c..e290886 100644
3092
--- a/include/drivers/console/uart_console.h
3093
+++ b/include/drivers/console/uart_console.h
3094
@@ -27,7 +27,7 @@ extern "C" {
3095
 
3096
 #define MAX_LINE_LEN 256
3097
 struct uart_console_input {
3098
-       int _unused;
3099
+       void *_unused;
3100
        char line[MAX_LINE_LEN];
3101
 };
3102
 
3103
diff --git a/include/kernel.h b/include/kernel.h
3104
index d49f878..4d322ae 100644
3105
--- a/include/kernel.h
3106
+++ b/include/kernel.h
3107
@@ -29,6 +29,7 @@
3108
 #include <sections.h>
3109
 #include <atomic.h>
3110
 #include <errno.h>
3111
+#include <irq.h>
3112
 #include <misc/__assert.h>
3113
 #include <misc/dlist.h>
3114
 #include <misc/slist.h>
3115
@@ -650,7 +651,11 @@ struct _timeout {
3116
        sys_dlist_t node;
3117
        struct k_thread *thread;
3118
        sys_dlist_t *wait_q;
3119
+#ifdef CONFIG_RISCV64
3120
+       int64_t delta_ticks_from_prev;
3121
+#else
3122
        int32_t delta_ticks_from_prev;
3123
+#endif
3124
        _timeout_func_t func;
3125
 };
3126
 
3127
diff --git a/include/kernel_version.h b/include/kernel_version.h
3128
index 9e2ed5e..4392e88 100644
3129
--- a/include/kernel_version.h
3130
+++ b/include/kernel_version.h
3131
@@ -19,6 +19,8 @@
3132
 #ifndef _kernel_version__h_
3133
 #define _kernel_version__h_
3134
 
3135
+#include <stdint.h>
3136
+
3137
 #ifdef __cplusplus
3138
 extern "C" {
3139
 #endif
3140
diff --git a/include/linker-defs.h b/include/linker-defs.h
3141
index f9df709..f6d5478 100644
3142
--- a/include/linker-defs.h
3143
+++ b/include/linker-defs.h
3144
@@ -41,6 +41,8 @@
3145
 /* Nothing yet to include */
3146
 #elif defined(CONFIG_NIOS2)
3147
 /* Nothing yet to include */
3148
+#elif defined(CONFIG_RISCV64)
3149
+/* Nothing yet to include */
3150
 #else
3151
 #error Arch not supported.
3152
 #endif
3153
diff --git a/include/linker-tool-gcc.h b/include/linker-tool-gcc.h
3154
index 782bd2e..3a354e2 100644
3155
--- a/include/linker-tool-gcc.h
3156
+++ b/include/linker-tool-gcc.h
3157
@@ -39,6 +39,8 @@
3158
        #endif
3159
 #elif defined(CONFIG_NIOS2)
3160
        OUTPUT_FORMAT("elf32-littlenios2", "elf32-bignios2", "elf32-littlenios2")
3161
+#elif defined(CONFIG_RISCV64)
3162
+       OUTPUT_FORMAT("elf64-littleriscv", "elf64-littleriscv", "elf64-littleriscv")
3163
 #else
3164
        #error Arch not supported.
3165
 #endif
3166
diff --git a/include/misc/shell.h b/include/misc/shell.h
3167
index 158f96f..3a0be96 100644
3168
--- a/include/misc/shell.h
3169
+++ b/include/misc/shell.h
3170
@@ -16,6 +16,9 @@
3171
  * limitations under the License.
3172
  */
3173
 
3174
+#ifndef __MISC_SHELL_H__
3175
+#define __MISC_SHELL_H__
3176
+
3177
 #ifdef __cplusplus
3178
 extern "C" {
3179
 #endif
3180
@@ -126,3 +129,4 @@ static inline int shell_run(struct device *dev) { return 0; }
3181
 }
3182
 #endif
3183
 
3184
+#endif  // __MISC_SHELL_H__
3185
diff --git a/include/toolchain/common.h b/include/toolchain/common.h
3186
index 518c12f..b298969 100644
3187
--- a/include/toolchain/common.h
3188
+++ b/include/toolchain/common.h
3189
@@ -86,6 +86,10 @@
3190
 
3191
     #define PERFOPT_ALIGN .balign 4
3192
 
3193
+  #elif defined(CONFIG_RISCV64)
3194
+
3195
+    #define PERFOPT_ALIGN .balign  8
3196
+
3197
   #else
3198
 
3199
     #error Architecture unsupported
3200
diff --git a/include/toolchain/gcc.h b/include/toolchain/gcc.h
3201
index 4cf420f..c516f02 100644
3202
--- a/include/toolchain/gcc.h
3203
+++ b/include/toolchain/gcc.h
3204
@@ -279,6 +279,11 @@ A##a:
3205
                ",%0"                              \
3206
                "\n\t.type\t" #name ",%%object" :  : "n"(value))
3207
 
3208
+#elif defined(CONFIG_RISCV64)
3209
+
3210
+#define GEN_ABSOLUTE_SYM(name, value) \
3211
+       __asm__(".globl\t" #name "\n")
3212
+
3213
 #else
3214
 #error processor architecture not supported
3215
 #endif
3216
diff --git a/kernel/unified/atomic_c.c b/kernel/unified/atomic_c.c
3217
index b8f2a19..981765a 100644
3218
--- a/kernel/unified/atomic_c.c
3219
+++ b/kernel/unified/atomic_c.c
3220
@@ -31,6 +31,7 @@
3221
 #include <atomic.h>
3222
 #include <toolchain.h>
3223
 #include <arch/cpu.h>
3224
+#include <irq.h>
3225
 
3226
 /**
3227
  *
3228
diff --git a/kernel/unified/idle.c b/kernel/unified/idle.c
3229
index b6e36a3..83588b1 100644
3230
--- a/kernel/unified/idle.c
3231
+++ b/kernel/unified/idle.c
3232
@@ -154,6 +154,11 @@ void idle(void *unused1, void *unused2, void *unused3)
3233
                (void)irq_lock();
3234
                _sys_power_save_idle(_get_next_timeout_expiry());
3235
 
3236
+#ifdef CONFIG_RISCV64
3237
+               // I didn't understood where preemptive switch must occurs
3238
+               k_yield();
3239
+#else
3240
                IDLE_YIELD_IF_COOP();
3241
+#endif
3242
        }
3243
 }
3244
diff --git a/kernel/unified/include/kernel_structs.h b/kernel/unified/include/kernel_structs.h
3245
index 8ec5d99..f29402b 100644
3246
--- a/kernel/unified/include/kernel_structs.h
3247
+++ b/kernel/unified/include/kernel_structs.h
3248
@@ -150,6 +150,9 @@ struct _kernel {
3249
 
3250
        /* nested interrupt count */
3251
        uint32_t nested;
3252
+#ifdef CONFIG_RISCV64
3253
+       uint32_t dummy_align8;
3254
+#endif
3255
 
3256
        /* interrupt stack pointer base */
3257
        char *irq_stack;
3258
diff --git a/kernel/unified/init.c b/kernel/unified/init.c
3259
index 67e12d0..ad64cf3 100644
3260
--- a/kernel/unified/init.c
3261
+++ b/kernel/unified/init.c
3262
@@ -370,7 +370,11 @@ FUNC_NORETURN void _Cstart(void)
3263
 #else
3264
        /* floating point is NOT used during nanokernel init */
3265
 
3266
+#ifdef CONFIG_RISCV64
3267
+       char __stack dummy_stack[sizeof(struct k_thread)];
3268
+#else
3269
        char __stack dummy_stack[_K_THREAD_NO_FLOAT_SIZEOF];
3270
+#endif
3271
        void *dummy_thread = dummy_stack;
3272
 #endif
3273
 
3274
diff --git a/lib/libc/minimal/include/sys/types.h b/lib/libc/minimal/include/sys/types.h
3275
index 25a2fec..60d88ff 100644
3276
--- a/lib/libc/minimal/include/sys/types.h
3277
+++ b/lib/libc/minimal/include/sys/types.h
3278
@@ -28,6 +28,8 @@ typedef int ssize_t;
3279
 typedef int ssize_t;
3280
 #elif defined(__NIOS2__)
3281
 typedef int ssize_t;
3282
+#elif defined(CONFIG_RISCV64)
3283
+typedef long long ssize_t;
3284
 #else
3285
 #error "The minimal libc library does not recognize the architecture!\n"
3286
 #endif
3287
@@ -45,6 +47,8 @@ typedef int off_t;
3288
 typedef int off_t;
3289
 #elif defined(__NIOS2__)
3290
 typedef int off_t;
3291
+#elif defined(CONFIG_RISCV64)
3292
+typedef long long off_t;
3293
 #else
3294
 #error "The minimal libc library does not recognize the architecture!\n"
3295
 #endif
3296
diff --git a/scripts/gen_offset_header/Makefile b/scripts/gen_offset_header/Makefile
3297
index 8e6f3b3..9458eb8 100644
3298
--- a/scripts/gen_offset_header/Makefile
3299
+++ b/scripts/gen_offset_header/Makefile
3300
@@ -1,4 +1,7 @@
3301
 HOSTCFLAGS_gen_offset_header.o += -DKERNEL_VERSION=0 -Wall -Werror -g
3302
+ifeq ($(ARCH),riscv64)
3303
+HOSTCFLAGS_gen_offset_header.o += -DARCH_64BITS
3304
+endif
3305
 HOSTCFLAGS_gen_idt.o += -Wno-unused-result
3306
 
3307
 hostprogs-y    += gen_offset_header
3308
diff --git a/scripts/gen_offset_header/elf.h b/scripts/gen_offset_header/elf.h
3309
index 449e6ad..da86c85 100644
3310
--- a/scripts/gen_offset_header/elf.h
3311
+++ b/scripts/gen_offset_header/elf.h
3312
@@ -28,9 +28,16 @@
3313
 extern "C" {
3314
 #endif
3315
 
3316
+#ifdef ARCH_64BITS
3317
+#include <inttypes.h>
3318
+typedef uint64_t   Elf32_Addr;
3319
+typedef uint64_t   Elf32_Off;
3320
+typedef uint64_t   Elf32_DWord;
3321
+#else
3322
 typedef unsigned int    Elf32_Addr;
3323
-typedef unsigned short  Elf32_Half;
3324
 typedef unsigned int    Elf32_Off;
3325
+#endif
3326
+typedef unsigned short  Elf32_Half;
3327
 typedef int             Elf32_Sword;
3328
 typedef unsigned int    Elf32_Word;
3329
 
3330
@@ -168,14 +175,26 @@ typedef struct
3331
        {
3332
        Elf32_Word      sh_name;
3333
        Elf32_Word      sh_type;        /* SHT_... */
3334
+#ifdef ARCH_64BITS
3335
+       Elf32_DWord     sh_flags;       /* SHF_... */
3336
+       Elf32_Addr      sh_addr;
3337
+       Elf32_Off       sh_offset;
3338
+       Elf32_DWord     sh_size;
3339
+#else
3340
        Elf32_Word      sh_flags;       /* SHF_... */
3341
        Elf32_Addr      sh_addr;
3342
        Elf32_Off       sh_offset;
3343
        Elf32_Word      sh_size;
3344
+#endif
3345
        Elf32_Word      sh_link;
3346
        Elf32_Word      sh_info;
3347
+#ifdef ARCH_64BITS
3348
+       Elf32_DWord     sh_addralign;
3349
+       Elf32_DWord     sh_entsize;
3350
+#else
3351
        Elf32_Word      sh_addralign;
3352
        Elf32_Word      sh_entsize;
3353
+#endif
3354
 } Elf32_Shdr;
3355
 
3356
 #define SHDRSZ sizeof(Elf32_Shdr)
3357
@@ -228,11 +247,19 @@ typedef struct
3358
 typedef struct
3359
        {
3360
        Elf32_Word      st_name;
3361
+#ifdef ARCH_64BITS
3362
+       unsigned char   st_info;
3363
+       unsigned char   st_other;
3364
+       Elf32_Half      st_shndx;
3365
+       Elf32_Addr      st_value;
3366
+       Elf32_DWord     st_size;
3367
+#else
3368
        Elf32_Addr      st_value;
3369
        Elf32_Word      st_size;
3370
        unsigned char   st_info;
3371
        unsigned char   st_other;
3372
        Elf32_Half      st_shndx;
3373
+#endif
3374
        } Elf32_Sym;
3375
 
3376
 #define STN_UNDEF      0
3377
@@ -300,10 +327,17 @@ typedef struct
3378
        Elf32_Off       p_offset;
3379
        Elf32_Addr      p_vaddr;
3380
        Elf32_Addr      p_paddr;
3381
+#ifdef ARCH_64BITS
3382
+       Elf32_DWord     p_filesz;
3383
+       Elf32_DWord     p_memsz;
3384
+       Elf32_DWord     p_flags;
3385
+       Elf32_DWord     p_align;
3386
+#else
3387
        Elf32_Word      p_filesz;
3388
        Elf32_Word      p_memsz;
3389
        Elf32_Word      p_flags;
3390
        Elf32_Word      p_align;
3391
+#endif
3392
        } Elf32_Phdr;
3393
 
3394
 #define PHDRSZ sizeof(Elf32_Phdr)
3395
diff --git a/scripts/gen_offset_header/gen_offset_header.c b/scripts/gen_offset_header/gen_offset_header.c
3396
index 7f72fed..fd22f25 100644
3397
--- a/scripts/gen_offset_header/gen_offset_header.c
3398
+++ b/scripts/gen_offset_header/gen_offset_header.c
3399
@@ -259,11 +259,19 @@ static int ehdrLoad(int fd)
3400
 
3401
        /* 64-bit ELF module not supported (for now) */
3402
 
3403
+#ifdef ARCH_64BITS
3404
+       if (ehdr.e_ident[EI_CLASS] != ELFCLASS64)
3405
+       {
3406
+               fprintf(stderr, "ELF32 class not supported\n");
3407
+               return -1;
3408
+       }
3409
+#else
3410
        if (ehdr.e_ident[EI_CLASS] != ELFCLASS32)
3411
        {
3412
                fprintf(stderr, "ELF64 class not supported\n");
3413
                return -1;
3414
        }
3415
+#endif
3416
 
3417
        /*
3418
         * Dynamically determine the endianess of the host (in the absence of
3419
@@ -341,7 +349,7 @@ static int shdrsLoad(int fd)
3420
  * @param pSymTblSize ptr to symbol table size
3421
  * @returns 0 if found, -1 if not
3422
  */
3423
-static int symTblFind(unsigned *pSymTblOffset, unsigned *pSymTblSize)
3424
+static int symTblFind(Elf32_Off *pSymTblOffset, unsigned *pSymTblSize)
3425
 {
3426
        unsigned  ix;    /* loop index */
3427
 
3428
@@ -534,8 +542,13 @@ static void headerAbsoluteSymbolsDump(int fd, FILE *fp, Elf32_Off symTblOffset,
3429
                                        (strstr(&pStringTable[aSym.st_name],
3430
                                                 STRUCT_SIZ_SUFFIX) != NULL))
3431
                        {
3432
+#ifdef ARCH_64BITS
3433
+                               fprintf(fp, "#define\t%s\t0x%" PRIx64 "\n",
3434
+                                               &pStringTable[aSym.st_name], aSym.st_value);
3435
+#else
3436
                                fprintf(fp, "#define\t%s\t0x%X\n",
3437
                                                &pStringTable[aSym.st_name], aSym.st_value);
3438
+#endif
3439
                        }
3440
                }
3441
        }

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.