add riscv64-mycpu

This commit is contained in:
181250012-Chen Lu 2021-07-12 10:31:53 +08:00 committed by Zihao Yu
parent a94708b3b5
commit 1a4ad39176
14 changed files with 333 additions and 266 deletions

View file

View file

@ -0,0 +1,8 @@
.section entry, "ax"
.globl _start
.type _start, @function
_start:
mv s0, zero
la sp, _stack_pointer
jal _trm_init

View file

@ -0,0 +1,5 @@
#include <klib-macros.h>
#define PMEM_SIZE (128 * 1024 * 1024)
#define PMEM_END ((uintptr_t)&_pmem_start + PMEM_SIZE)
extern char _pmem_start;

6
am/src/mycpu/ioe/input.c Normal file
View file

@ -0,0 +1,6 @@
#include <am.h>
void __am_input_keybrd(AM_INPUT_KEYBRD_T *kbd) {
}

33
am/src/mycpu/ioe/ioe.c Normal file
View file

@ -0,0 +1,33 @@
#include <am.h>
#include <klib-macros.h>
void __am_timer_init();
void __am_timer_rtc(AM_TIMER_RTC_T *);
void __am_timer_uptime(AM_TIMER_UPTIME_T *);
void __am_input_keybrd(AM_INPUT_KEYBRD_T *);
void __am_timer_rtc(AM_TIMER_RTC_T *);
static void __am_timer_config(AM_TIMER_CONFIG_T *cfg) { cfg->present = true; cfg->has_rtc = true; }
static void __am_input_config(AM_INPUT_CONFIG_T *cfg) { cfg->present = true; }
typedef void (*handler_t)(void *buf);
static void *lut[128] = {
[AM_TIMER_CONFIG] = __am_timer_config,
[AM_TIMER_RTC ] = __am_timer_rtc,
[AM_TIMER_UPTIME] = __am_timer_uptime,
[AM_INPUT_CONFIG] = __am_input_config,
[AM_INPUT_KEYBRD] = __am_input_keybrd,
};
static void fail(void *buf) { panic("access nonexist register"); }
bool ioe_init() {
for (int i = 0; i < LENGTH(lut); i++)
if (!lut[i]) lut[i] = fail;
__am_timer_init();
return true;
}
void ioe_read (int reg, void *buf) { ((handler_t)lut[reg])(buf); }
void ioe_write(int reg, void *buf) { ((handler_t)lut[reg])(buf); }

13
am/src/mycpu/ioe/timer.c Normal file
View file

@ -0,0 +1,13 @@
#include <am.h>
void __am_timer_init() {
}
void __am_timer_uptime(AM_TIMER_UPTIME_T *uptime) {
}
void __am_timer_rtc(AM_TIMER_RTC_T *rtc) {
}

View file

@ -0,0 +1,33 @@
_pmem_start = 0x80000000;
ENTRY(_start)
SECTIONS {
. = _pmem_start + 0x100000;
.text : {
*(entry)
*(.text*)
}
etext = .;
_etext = .;
.rodata : {
*(.rodata*)
}
.data : {
*(.data)
}
edata = .;
_data = .;
.bss : {
_bss_start = .;
*(.bss*)
*(.sbss*)
*(.scommon)
}
_stack_top = ALIGN(0x1000);
. = _stack_top + 0x8000;
_stack_pointer = .;
end = .;
_end = .;
_heap_start = ALIGN(0x1000);
}

24
am/src/mycpu/trm.c Normal file
View file

@ -0,0 +1,24 @@
#include <am.h>
#include <mycpu.h>
extern char _heap_start;
int main(const char *args);
Area heap = RANGE(&_heap_start, PMEM_END);
#ifndef MAINARGS
#define MAINARGS ""
#endif
static const char mainargs[] = MAINARGS;
void putch(char ch) {
}
void halt(int code) {
while (1);
}
void _trm_init() {
int ret = main(mainargs);
halt(ret);
}