1 /*
2  * Copyright (c) 2015 Stefan Kristiansson
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <lk/reg.h>
9 #include <kernel/thread.h>
10 #include <dev/uart.h>
11 #include <dev/timer/or1k_ticktimer.h>
12 #include <platform.h>
13 #include <platform/interrupts.h>
14 #include <platform/debug.h>
15 #include <platform/timer.h>
16 #include <platform/or1ksim.h>
17 #include <sys/types.h>
18 #include <target/debugconfig.h>
19 #if WITH_KERNEL_VM
20 #include <kernel/vm.h>
21 #endif
22 
23 struct mmu_initial_mapping mmu_initial_mappings[] = {
24     /* 32 MB of RAM space */
25     {
26         .phys = 0x0,
27         .virt = KERNEL_BASE,
28         .size = 32*1024*1024,
29         .flags = 0,
30         .name = "memory"
31     },
32 
33     /* peripherals */
34     {
35         .phys = 0x90000000,
36         .virt = 0x90000000,
37         .size = 0x04000000,
38         .flags = MMU_INITIAL_MAPPING_FLAG_DEVICE,
39         .name = "peripherals"
40     },
41 
42     /* identity map to let the boot code run */
43     {
44         .phys = 0,
45         .virt = 0,
46         .size = 1024*1024*1024,
47         .flags = MMU_INITIAL_MAPPING_TEMPORARY
48     },
49 
50     /* null entry to terminate the list */
51     { 0 }
52 };
53 
54 static pmm_arena_t ram_arena = {
55     .name = "ram",
56     .base = 0,
57     .size = MEMSIZE,
58     .flags = PMM_ARENA_FLAG_KMAP
59 };
60 
platform_dputc(char c)61 void platform_dputc(char c) {
62     if (c == '\n')
63         uart_putc(DEBUG_UART, '\r');
64     uart_putc(DEBUG_UART, c);
65 }
66 
platform_dgetc(char * c,bool wait)67 int platform_dgetc(char *c, bool wait) {
68     int _c;
69 
70     if ((_c = uart_getc(DEBUG_UART, false)) < 0)
71         return -1;
72 
73     *c = _c;
74     return 0;
75 }
76 
platform_early_init(void)77 void platform_early_init(void) {
78     uart_init_early();
79     or1k_ticktimer_init(TIMER_CLOCK_FREQ);
80 #if WITH_KERNEL_VM
81     pmm_add_arena(&ram_arena);
82 #endif
83 }
84