ready for ics2021

This commit is contained in:
Zihao Yu 2021-08-07 11:28:08 +08:00
parent 3cf0ee6d42
commit 30e5cd0c7e
72 changed files with 252 additions and 339 deletions

View file

@ -65,13 +65,10 @@ LINKAGE = $(OBJS) \
## 3. General Compilation Flags
### Enable Ccache acceleration when available
CCACHE = $(if $(shell which ccache),ccache,)
### (Cross) compilers, e.g., mips-linux-gnu-g++
AS = $(CCACHE) $(CROSS_COMPILE)gcc
CC = $(CCACHE) $(CROSS_COMPILE)gcc
CXX = $(CCACHE) $(CROSS_COMPILE)g++
AS = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
@ -81,11 +78,10 @@ READELF = $(CROSS_COMPILE)readelf
INC_PATH += $(WORK_DIR)/include $(addsuffix /include/, $(addprefix $(AM_HOME)/, $(LIBS)))
INCFLAGS += $(addprefix -I, $(INC_PATH))
CFLAGS += -O2 -MMD -Wall -Werror -ggdb $(INCFLAGS) \
CFLAGS += -O2 -MMD -Wall -Werror $(INCFLAGS) \
-D__ISA__=\"$(ISA)\" -D__ISA_$(shell echo $(ISA) | tr a-z A-Z)__ \
-D__ARCH__=$(ARCH) -D__ARCH_$(shell echo $(ARCH) | tr a-z A-Z | tr - _) \
-D__PLATFORM__=$(PLATFORM) -D__PLATFORM_$(shell echo $(PLATFORM) | tr a-z A-Z | tr - _) \
-DISA_H=\"$(ISA).h\" \
-DARCH_H=\"arch/$(ARCH).h\" \
-fno-asynchronous-unwind-tables -fno-builtin -fno-stack-protector \
-Wno-main
@ -100,7 +96,7 @@ ASFLAGS += -MMD $(INCFLAGS)
### Fall back to native gcc/binutils if there is no cross compiler
ifeq ($(wildcard $(shell which $(CC))),)
$(info # $(CC) not found; fall back to default gcc and binutils)
CROSS_COMPILE :=
CROSS_COMPILE :=
endif
## 5. Compilation Rules

View file

@ -2,6 +2,7 @@
#define __ARCH_H__
struct Context {
// TODO: fix the order of these members to match trap.S
uintptr_t hi, gpr[32], epc, cause, lo, status;
void *pdir;
};

View file

@ -2,7 +2,8 @@
#define ARCH_H__
struct Context {
uintptr_t epc, cause, gpr[32], status;
// TODO: fix the order of these members to match trap.S
uintptr_t mepc, mcause, gpr[32], mstatus;
void *pdir;
};

View file

@ -3,14 +3,12 @@
struct Context {
// TODO: fix the order of these members to match trap.S
uintptr_t epc, cause, gpr[32], status;
uintptr_t mepc, mcause, gpr[32], mstatus;
};
#define GPR1 gpr[0]
#define GPR1 gpr[17] // a7
#define GPR2 gpr[0]
#define GPR3 gpr[0]
#define GPR4 gpr[0]
#define GPRx gpr[0]
#endif

View file

@ -2,7 +2,8 @@
#define ARCH_H__
struct Context {
uintptr_t epc, cause, gpr[32], status;
// TODO: fix the order of these members to match trap.S
uintptr_t mepc, mcause, gpr[32], mstatus;
void *pdir;
};
@ -11,5 +12,4 @@ struct Context {
#define GPR3 gpr[0]
#define GPR4 gpr[0]
#define GPRx gpr[0]
#endif

View file

@ -2,6 +2,13 @@
#define ARCH_H__
struct Context {
uintptr_t gpr[1];
};
#define GPR1 gpr[0]
#define GPR2 gpr[0]
#define GPR3 gpr[0]
#define GPR4 gpr[0]
#define GPRx gpr[0]
#endif

View file

@ -2,6 +2,7 @@
#define ARCH_H__
struct Context {
// TODO: fix the order of these members to match trap.S
uintptr_t esi, ebx, eax, eip, edx, eflags, ecx, cs, esp, edi, ebp;
void *cr3;
int irq;

View file

@ -1,5 +1,5 @@
#include <am.h>
#include <mips32.h>
#include <mips/mips32.h>
#include <klib.h>
static Context* (*user_handler)(Event, Context*) = NULL;

View file

@ -1,5 +1,4 @@
#include <am.h>
#include <mips32.h>
#include <nemu.h>
#define USER_SPACE RANGE(0x40000000, 0x80000000)

View file

@ -8,6 +8,7 @@ void __am_timer_init();
void __am_gpu_init();
void __am_input_init();
void __am_audio_init();
void __am_disk_init();
void __am_input_config(AM_INPUT_CONFIG_T *);
void __am_timer_config(AM_TIMER_CONFIG_T *);
void __am_timer_rtc(AM_TIMER_RTC_T *);
@ -20,8 +21,10 @@ void __am_audio_config(AM_AUDIO_CONFIG_T *);
void __am_audio_ctrl(AM_AUDIO_CTRL_T *);
void __am_audio_status(AM_AUDIO_STATUS_T *);
void __am_audio_play(AM_AUDIO_PLAY_T *);
void __am_disk_config(AM_DISK_CONFIG_T *cfg);
void __am_disk_status(AM_DISK_STATUS_T *stat);
void __am_disk_blkio(AM_DISK_BLKIO_T *io);
static void __am_uart_config(AM_UART_CONFIG_T *cfg) { cfg->present = false; }
static void __am_disk_config(AM_DISK_CONFIG_T *cfg) { cfg->present = false; }
static void __am_net_config (AM_NET_CONFIG_T *cfg) { cfg->present = false; }
typedef void (*handler_t)(void *buf);
@ -40,6 +43,8 @@ static void *lut[128] = {
[AM_AUDIO_STATUS] = __am_audio_status,
[AM_AUDIO_PLAY ] = __am_audio_play,
[AM_DISK_CONFIG ] = __am_disk_config,
[AM_DISK_STATUS ] = __am_disk_status,
[AM_DISK_BLKIO ] = __am_disk_blkio,
[AM_NET_CONFIG ] = __am_net_config,
};
@ -59,6 +64,7 @@ void __am_ioe_init() {
__am_gpu_init();
__am_input_init();
__am_audio_init();
__am_disk_init();
ioe_init_done = true;
}

41
am/src/native/ioe/disk.c Normal file
View file

@ -0,0 +1,41 @@
#include <am.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define BLKSZ 512
static int disk_size = 0;
static FILE *fp = NULL;
void __am_disk_init() {
const char *diskimg = getenv("diskimg");
if (diskimg) {
fp = fopen(diskimg, "r+");
if (fp) {
fseek(fp, 0, SEEK_END);
disk_size = (ftell(fp) + 511) / 512;
rewind(fp);
}
}
}
void __am_disk_config(AM_DISK_CONFIG_T *cfg) {
cfg->present = (fp != NULL);
cfg->blksz = BLKSZ;
cfg->blkcnt = disk_size;
}
void __am_disk_status(AM_DISK_STATUS_T *stat) {
stat->ready = 1;
}
void __am_disk_blkio(AM_DISK_BLKIO_T *io) {
if (fp) {
fseek(fp, io->blkno * BLKSZ, SEEK_SET);
int ret;
if (io->write) ret = fwrite(io->buf, io->blkcnt * BLKSZ, 1, fp);
else ret = fread(io->buf, io->blkcnt * BLKSZ, 1, fp);
assert(ret == 1);
}
}

View file

@ -1,51 +0,0 @@
#define concat_temp(x, y) x ## y
#define concat(x, y) concat_temp(x, y)
#define MAP(c, f) c(f)
#define REGS(f) \
f( 1) f( 3) f( 4) f( 5) f( 6) f( 7) f( 8) f( 9) \
f(10) f(11) f(12) f(13) f(14) f(15) f(16) f(17) f(18) f(19) \
f(20) f(21) f(22) f(23) f(24) f(25) f(26) f(27) f(28) f(29) \
f(30) f(31)
#define PUSH(n) sw concat(x, n), (n * 4)(sp);
#define POP(n) lw concat(x, n), (n * 4)(sp);
#define CONTEXT_SIZE ((32 + 3) * 4)
#define OFFSET_SP ( 2 * 4)
#define OFFSET_CAUSE (32 * 4)
#define OFFSET_STATUS (33 * 4)
#define OFFSET_EPC (34 * 4)
.globl __am_asm_trap
__am_asm_trap:
addi sp, sp, -CONTEXT_SIZE
MAP(REGS, PUSH)
mv t0, sp
addi t0, t0, CONTEXT_SIZE
sw t0, OFFSET_SP(sp)
csrr t0, scause
csrr t1, sstatus
csrr t2, sepc
sw t0, OFFSET_CAUSE(sp)
sw t1, OFFSET_STATUS(sp)
sw t2, OFFSET_EPC(sp)
mv a0, sp
jal __am_irq_handle
lw t1, OFFSET_STATUS(sp)
lw t2, OFFSET_EPC(sp)
csrw sstatus, t1
csrw sepc, t2
MAP(REGS, POP)
addi sp, sp, CONTEXT_SIZE
sret

View file

@ -1,73 +0,0 @@
#include <am.h>
#include <nemu.h>
#include <klib.h>
static AddrSpace kas = {};
static void* (*pgalloc_usr)(int) = NULL;
static void (*pgfree_usr)(void*) = NULL;
static int vme_enable = 0;
static Area segments[] = { // Kernel memory mappings
NEMU_PADDR_SPACE
};
#define USER_SPACE RANGE(0x40000000, 0x80000000)
static inline void set_satp(void *pdir) {
asm volatile("csrw satp, %0" : : "r"(0x80000000 | ((uintptr_t)pdir >> 12)));
}
static inline uintptr_t get_satp() {
uintptr_t satp;
asm volatile("csrr %0, satp" : "=r"(satp));
return satp << 12;
}
bool vme_init(void* (*pgalloc_f)(int), void (*pgfree_f)(void*)) {
pgalloc_usr = pgalloc_f;
pgfree_usr = pgfree_f;
kas.ptr = pgalloc_f(PGSIZE);
int i;
for (i = 0; i < LENGTH(segments); i ++) {
void *va = segments[i].start;
for (; va < segments[i].end; va += PGSIZE) {
map(&kas, va, va, 0);
}
}
set_satp(kas.ptr);
vme_enable = 1;
return true;
}
void protect(AddrSpace *as) {
PTE *updir = (PTE*)(pgalloc_usr(PGSIZE));
as->ptr = updir;
as->area = USER_SPACE;
as->pgsize = PGSIZE;
// map kernel space
memcpy(updir, kas.ptr, PGSIZE);
}
void unprotect(AddrSpace *as) {
}
void __am_get_cur_as(Context *c) {
c->pdir = (vme_enable ? (void *)get_satp() : NULL);
}
void __am_switch(Context *c) {
if (vme_enable && c->pdir != NULL) {
set_satp(c->pdir);
}
}
void map(AddrSpace *as, void *va, void *pa, int prot) {
}
Context *ucontext(AddrSpace *as, Area kstack, void *entry) {
return NULL;
}

View file

@ -1,46 +0,0 @@
#include <am.h>
#include <nemu.h>
#include <klib.h>
static Context* (*user_handler)(Event, Context*) = NULL;
Context* __am_irq_handle(Context *c) {
if (user_handler) {
Event ev = {0};
switch (c->cause) {
default: ev.event = EVENT_ERROR; break;
}
c = user_handler(ev, c);
assert(c != NULL);
}
return c;
}
extern void __am_asm_trap(void);
bool cte_init(Context*(*handler)(Event, Context*)) {
// initialize exception entry
asm volatile("csrw stvec, %0" : : "r"(__am_asm_trap));
// register event handler
user_handler = handler;
return true;
}
Context *kcontext(Area kstack, void (*entry)(void *), void *arg) {
return NULL;
}
void yield() {
asm volatile("li a7, -1; ecall");
}
bool ienabled() {
return false;
}
void iset(bool enable) {
}

View file

@ -1,51 +0,0 @@
#define concat_temp(x, y) x ## y
#define concat(x, y) concat_temp(x, y)
#define MAP(c, f) c(f)
#define REGS(f) \
f( 1) f( 3) f( 4) f( 5) f( 6) f( 7) f( 8) f( 9) \
f(10) f(11) f(12) f(13) f(14) f(15) f(16) f(17) f(18) f(19) \
f(20) f(21) f(22) f(23) f(24) f(25) f(26) f(27) f(28) f(29) \
f(30) f(31)
#define PUSH(n) sd concat(x, n), (n * 8)(sp);
#define POP(n) ld concat(x, n), (n * 8)(sp);
#define CONTEXT_SIZE ((32 + 3) * 8)
#define OFFSET_SP ( 2 * 8)
#define OFFSET_CAUSE (32 * 8)
#define OFFSET_STATUS (33 * 8)
#define OFFSET_EPC (34 * 8)
.globl __am_asm_trap
__am_asm_trap:
addi sp, sp, -CONTEXT_SIZE
MAP(REGS, PUSH)
mv t0, sp
addi t0, t0, CONTEXT_SIZE
sd t0, OFFSET_SP(sp)
csrr t0, scause
csrr t1, sstatus
csrr t2, sepc
sd t0, OFFSET_CAUSE(sp)
sd t1, OFFSET_STATUS(sp)
sd t2, OFFSET_EPC(sp)
mv a0, sp
jal __am_irq_handle
ld t1, OFFSET_STATUS(sp)
ld t2, OFFSET_EPC(sp)
csrw sstatus, t1
csrw sepc, t2
MAP(REGS, POP)
addi sp, sp, CONTEXT_SIZE
sret

View file

@ -3,7 +3,8 @@
#include <klib-macros.h>
#include ISA_H // "x86.h", "mips32.h", ...
#include ISA_H // the macro `ISA_H` is defined in CFLAGS
// it will be expanded as "x86/x86.h", "mips/mips32.h", ...
#if defined(__ISA_X86__)
# define nemu_trap(code) asm volatile (".byte 0xd6" : :"a"(code))
@ -15,22 +16,22 @@
# error unsupported ISA __ISA__
#endif
#ifdef __ARCH_X86_NEMU
# define SERIAL_PORT 0x3f8
# define KBD_ADDR 0x60
# define RTC_ADDR 0x48
# define VGACTL_ADDR 0x100
# define AUDIO_ADDR 0x200
#if defined(__ARCH_X86_NEMU)
# define DEVICE_BASE 0x0
#else
# define SERIAL_PORT 0xa10003f8
# define KBD_ADDR 0xa1000060
# define RTC_ADDR 0xa1000048
# define VGACTL_ADDR 0xa1000100
# define AUDIO_ADDR 0xa1000200
# define DEVICE_BASE 0xa0000000
#endif
#define FB_ADDR 0xa0000000
#define AUDIO_SBUF_ADDR 0xa0800000
#define MMIO_BASE 0xa0000000
#define SERIAL_PORT (DEVICE_BASE + 0x00003f8)
#define KBD_ADDR (DEVICE_BASE + 0x0000060)
#define RTC_ADDR (DEVICE_BASE + 0x0000048)
#define VGACTL_ADDR (DEVICE_BASE + 0x0000100)
#define AUDIO_ADDR (DEVICE_BASE + 0x0000200)
#define DISK_ADDR (DEVICE_BASE + 0x0000300)
#define FB_ADDR (MMIO_BASE + 0x1000000)
#define AUDIO_SBUF_ADDR (MMIO_BASE + 0x1200000)
extern char _pmem_start;
#define PMEM_SIZE (128 * 1024 * 1024)
@ -38,7 +39,7 @@ extern char _pmem_start;
#define NEMU_PADDR_SPACE \
RANGE(&_pmem_start, PMEM_END), \
RANGE(FB_ADDR, FB_ADDR + 0x200000), \
RANGE(0xa1000000, 0xa1000000 + 0x1000) /* serial, rtc, screen, keyboard */
RANGE(MMIO_BASE, MMIO_BASE + 0x1000) /* serial, rtc, screen, keyboard */
typedef uintptr_t PTE;

View file

@ -0,0 +1,12 @@
#include <am.h>
#include <nemu.h>
void __am_disk_config(AM_DISK_CONFIG_T *cfg) {
cfg->present = false;
}
void __am_disk_status(AM_DISK_STATUS_T *stat) {
}
void __am_disk_blkio(AM_DISK_BLKIO_T *io) {
}

View file

@ -14,11 +14,13 @@ void __am_audio_config(AM_AUDIO_CONFIG_T *);
void __am_audio_ctrl(AM_AUDIO_CTRL_T *);
void __am_audio_status(AM_AUDIO_STATUS_T *);
void __am_audio_play(AM_AUDIO_PLAY_T *);
void __am_disk_config(AM_DISK_CONFIG_T *cfg);
void __am_disk_status(AM_DISK_STATUS_T *stat);
void __am_disk_blkio(AM_DISK_BLKIO_T *io);
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; }
static void __am_uart_config(AM_UART_CONFIG_T *cfg) { cfg->present = false; }
static void __am_disk_config(AM_DISK_CONFIG_T *cfg) { cfg->present = false; }
static void __am_net_config (AM_NET_CONFIG_T *cfg) { cfg->present = false; }
typedef void (*handler_t)(void *buf);
@ -37,6 +39,8 @@ static void *lut[128] = {
[AM_AUDIO_STATUS] = __am_audio_status,
[AM_AUDIO_PLAY ] = __am_audio_play,
[AM_DISK_CONFIG ] = __am_disk_config,
[AM_DISK_STATUS ] = __am_disk_status,
[AM_DISK_BLKIO ] = __am_disk_blkio,
[AM_NET_CONFIG ] = __am_net_config,
};

View file

@ -6,7 +6,7 @@ static Context* (*user_handler)(Event, Context*) = NULL;
Context* __am_irq_handle(Context *c) {
if (user_handler) {
Event ev = {0};
switch (c->cause) {
switch (c->mcause) {
default: ev.event = EVENT_ERROR; break;
}

View file

@ -1,5 +1,5 @@
#include <am.h>
#include <riscv32.h>
#include <riscv/riscv.h>
#include <klib.h>
static Context* (*user_handler)(Event, Context*) = NULL;
@ -7,7 +7,7 @@ static Context* (*user_handler)(Event, Context*) = NULL;
Context* __am_irq_handle(Context *c) {
if (user_handler) {
Event ev = {0};
switch (c->cause) {
switch (c->mcause) {
default: ev.event = EVENT_ERROR; break;
}
@ -22,7 +22,7 @@ extern void __am_asm_trap(void);
bool cte_init(Context*(*handler)(Event, Context*)) {
// initialize exception entry
asm volatile("csrw stvec, %0" : : "r"(__am_asm_trap));
asm volatile("csrw mtvec, %0" : : "r"(__am_asm_trap));
// register event handler
user_handler = handler;

61
am/src/riscv/nemu/trap.S Normal file
View file

@ -0,0 +1,61 @@
#define concat_temp(x, y) x ## y
#define concat(x, y) concat_temp(x, y)
#define MAP(c, f) c(f)
#if __riscv_xlen == 32
#define LOAD lw
#define STORE sw
#define XLEN 4
#else
#define LOAD ld
#define STORE sd
#define XLEN 8
#endif
#define REGS(f) \
f( 1) f( 3) f( 4) f( 5) f( 6) f( 7) f( 8) f( 9) \
f(10) f(11) f(12) f(13) f(14) f(15) f(16) f(17) f(18) f(19) \
f(20) f(21) f(22) f(23) f(24) f(25) f(26) f(27) f(28) f(29) \
f(30) f(31)
#define PUSH(n) STORE concat(x, n), (n * XLEN)(sp);
#define POP(n) LOAD concat(x, n), (n * XLEN)(sp);
#define CONTEXT_SIZE ((32 + 3 + 1) * XLEN)
#define OFFSET_SP ( 2 * XLEN)
#define OFFSET_CAUSE (32 * XLEN)
#define OFFSET_STATUS (33 * XLEN)
#define OFFSET_EPC (34 * XLEN)
.align 3
.globl __am_asm_trap
__am_asm_trap:
addi sp, sp, -CONTEXT_SIZE
MAP(REGS, PUSH)
csrr t0, mcause
csrr t1, mstatus
csrr t2, mepc
STORE t0, OFFSET_CAUSE(sp)
STORE t1, OFFSET_STATUS(sp)
STORE t2, OFFSET_EPC(sp)
# set mstatus.MPRV to pass difftest
li a0, (1 << 17)
or t1, t1, a0
csrw mstatus, t1
mv a0, sp
jal __am_irq_handle
LOAD t1, OFFSET_STATUS(sp)
LOAD t2, OFFSET_EPC(sp)
csrw mstatus, t1
csrw mepc, t2
MAP(REGS, POP)
addi sp, sp, CONTEXT_SIZE
mret

View file

@ -14,7 +14,7 @@ static Area segments[] = { // Kernel memory mappings
#define USER_SPACE RANGE(0x40000000, 0x80000000)
static inline void set_satp(void *pdir) {
uintptr_t mode = 8ull << 60;
uintptr_t mode = 1ul << (__riscv_xlen - 1);
asm volatile("csrw satp, %0" : : "r"(mode | ((uintptr_t)pdir >> 12)));
}

View file

@ -1,5 +1,5 @@
#ifndef RISCV32_H__
#define RISCV32_H__
#ifndef RISCV_H__
#define RISCV_H__
#include <stdint.h>
@ -16,5 +16,19 @@ static inline void outl(uintptr_t addr, uint32_t data) { *(volatile uint32_t *)a
#define PTE_W 0x04
#define PTE_X 0x08
#define PTE_U 0x10
#define PTE_A 0x40
#define PTE_D 0x80
enum { MODE_U, MODE_S, MODE_M = 3 };
#define MSTATUS_MXR (1 << 19)
#define MSTATUS_SUM (1 << 18)
#if __riscv_xlen == 64
#define MSTATUS_SXL (2ull << 34)
#define MSTATUS_UXL (2ull << 32)
#else
#define MSTATUS_SXL 0
#define MSTATUS_UXL 0
#endif
#endif

View file

@ -1,20 +0,0 @@
#ifndef RISCV64_H__
#define RISCV64_H__
#include <stdint.h>
static inline uint8_t inb(uintptr_t addr) { return *(volatile uint8_t *)addr; }
static inline uint16_t inw(uintptr_t addr) { return *(volatile uint16_t *)addr; }
static inline uint32_t inl(uintptr_t addr) { return *(volatile uint32_t *)addr; }
static inline void outb(uintptr_t addr, uint8_t data) { *(volatile uint8_t *)addr = data; }
static inline void outw(uintptr_t addr, uint16_t data) { *(volatile uint16_t *)addr = data; }
static inline void outl(uintptr_t addr, uint32_t data) { *(volatile uint32_t *)addr = data; }
#define PTE_V 0x01
#define PTE_R 0x02
#define PTE_W 0x04
#define PTE_X 0x08
#define PTE_U 0x10
#endif

View file

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

View file

@ -1,5 +1,5 @@
#include <am.h>
#include <x86.h>
#include <x86/x86.h>
#include <klib.h>
#define NR_IRQ 256 // IDT size

View file

@ -1,6 +1,6 @@
#include <stdint.h>
#include <elf.h>
#include <x86.h>
#include <x86/x86.h>
#define SECTSIZE 512
#define ARGSIZE 1024

View file

@ -1,4 +1,4 @@
#include <x86.h>
#include <x86/x86.h>
#include "x86-qemu.h"
.code32

View file

@ -1,4 +1,4 @@
#include <x86.h>
#include <x86/x86.h>
#define PML4_ADDR 0x1000
#define PDPT_ADDR 0x2000

View file

@ -363,7 +363,7 @@ uint32_t __inline __builtin_clzll(uint64_t value) {
#include <am.h>
#if !defined(__riscv) || defined(__riscv_m)
#if !defined(__ARCH_RISCV64_MYCPU)
/* Returns: a / b */
COMPILER_RT_ABI di_int

View file

@ -1,5 +1,5 @@
CROSS_COMPILE := riscv64-linux-gnu-
COMMON_FLAGS := -fno-pic -march=rv64g -mcmodel=medany
COMMON_FLAGS := -fno-pic -march=rv64g -mcmodel=medany -mstrict-align
CFLAGS += $(COMMON_FLAGS) -static
ASFLAGS += $(COMMON_FLAGS) -O0
LDFLAGS += -melf64lriscv

View file

@ -1,3 +1,8 @@
include $(AM_HOME)/scripts/isa/mips32.mk
include $(AM_HOME)/scripts/platform/nemu.mk
LDFLAGS += --defsym=_pmem_start=0x80000000
CFLAGS += -DISA_H=\"mips/mips32.h\"
AM_SRCS += mips/nemu/start.S \
mips/nemu/cte.c \
mips/nemu/trap.S \
mips/nemu/vme.c

View file

@ -9,6 +9,7 @@ AM_SRCS := native/trm.c \
native/ioe/timer.c \
native/ioe/gpu.c \
native/ioe/audio.c \
native/ioe/disk.c \
CFLAGS += -fpie
ASFLAGS += -fpie -pie

View file

@ -1,23 +1,21 @@
AM_SRCS := nemu/trm.c \
nemu/ioe/ioe.c \
nemu/ioe/timer.c \
nemu/ioe/input.c \
nemu/ioe/gpu.c \
nemu/ioe/audio.c \
nemu/isa/$(ISA)/cte.c \
nemu/isa/$(ISA)/trap.S \
nemu/isa/$(ISA)/vme.c \
nemu/mpe.c \
nemu/isa/$(ISA)/start.S
AM_SRCS := platform/nemu/trm.c \
platform/nemu/ioe/ioe.c \
platform/nemu/ioe/timer.c \
platform/nemu/ioe/input.c \
platform/nemu/ioe/gpu.c \
platform/nemu/ioe/audio.c \
platform/nemu/ioe/disk.c \
platform/nemu/mpe.c
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -T $(AM_HOME)/scripts/platform/nemu.ld --defsym=_entry_offset=0x100000
LDFLAGS += -T $(AM_HOME)/scripts/linker.ld \
--defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += --gc-sections -e _start
NEMUFLAGS += -b -l $(shell dirname $(IMAGE).elf)/nemu-log.txt $(IMAGE).bin
NEMUFLAGS += -b -l $(shell dirname $(IMAGE).elf)/nemu-log.txt
CFLAGS += -DMAINARGS=\"$(mainargs)\"
CFLAGS += -I$(AM_HOME)/am/src/nemu/include
.PHONY: $(AM_HOME)/am/src/nemu/trm.c
CFLAGS += -I$(AM_HOME)/am/src/platform/nemu/include
.PHONY: $(AM_HOME)/am/src/platform/nemu/trm.c
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt
@ -25,7 +23,7 @@ image: $(IMAGE).elf
@$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(IMAGE).elf $(IMAGE).bin
run: image
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) run ARGS="$(NEMUFLAGS)"
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) run ARGS="$(NEMUFLAGS)" IMG=$(IMAGE).bin
gdb: image
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) gdb ARGS="$(NEMUFLAGS)"
$(MAKE) -C $(NEMU_HOME) ISA=$(ISA) gdb ARGS="$(NEMUFLAGS)" IMG=$(IMAGE).bin

View file

@ -1,3 +1,8 @@
include $(AM_HOME)/scripts/isa/riscv32.mk
include $(AM_HOME)/scripts/platform/nemu.mk
LDFLAGS += --defsym=_pmem_start=0x80000000
CFLAGS += -DISA_H=\"riscv/riscv.h\"
AM_SRCS += riscv/nemu/start.S \
riscv/nemu/cte.c \
riscv/nemu/trap.S \
riscv/nemu/vme.c

View file

@ -4,23 +4,23 @@ CFLAGS += $(COMMON_FLAGS) -static
ASFLAGS += $(COMMON_FLAGS) -O0
LDFLAGS += -melf64lriscv
AM_SRCS := mycpu/start.S \
mycpu/trm.c \
mycpu/libgcc/muldi3.S \
mycpu/libgcc/div.S \
mycpu/ioe.c \
mycpu/timer.c \
mycpu/input.c \
mycpu/cte.c \
mycpu/trap.S \
mycpu/vme.c \
mycpu/mpe.c
AM_SRCS := riscv/mycpu/start.S \
riscv/mycpu/trm.c \
riscv/mycpu/libgcc/muldi3.S \
riscv/mycpu/libgcc/div.S \
riscv/mycpu/ioe.c \
riscv/mycpu/timer.c \
riscv/mycpu/input.c \
riscv/mycpu/cte.c \
riscv/mycpu/trap.S \
platform/dummy/vme.c \
platform/dummy/mpe.c
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -T $(AM_HOME)/scripts/platform/nemu.ld --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += -T $(AM_HOME)/scripts/linker.ld --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0
LDFLAGS += --gc-sections -e _start
CFLAGS += -DMAINARGS=\"$(mainargs)\"
.PHONY: $(AM_HOME)/am/src/mycpu/trm.c
.PHONY: $(AM_HOME)/am/src/riscv/mycpu/trm.c
image: $(IMAGE).elf
@$(OBJDUMP) -d $(IMAGE).elf > $(IMAGE).txt

View file

@ -1,3 +1,8 @@
include $(AM_HOME)/scripts/isa/riscv64.mk
include $(AM_HOME)/scripts/platform/nemu.mk
LDFLAGS += --defsym=_pmem_start=0x80000000
CFLAGS += -DISA_H=\"riscv/riscv.h\"
AM_SRCS += riscv/nemu/start.S \
riscv/nemu/cte.c \
riscv/nemu/trap.S \
riscv/nemu/vme.c

View file

@ -1,19 +1,19 @@
include $(AM_HOME)/scripts/isa/riscv64.mk
AM_SRCS := spike/trm.c \
spike/ioe.c \
spike/timer.c \
spike/start.S \
spike/htif.S \
AM_SRCS := riscv/spike/trm.c \
riscv/spike/ioe.c \
riscv/spike/timer.c \
riscv/spike/start.S \
riscv/spike/htif.S \
platform/dummy/cte.c \
platform/dummy/vme.c \
platform/dummy/mpe.c \
CFLAGS += -fdata-sections -ffunction-sections
LDFLAGS += -T $(AM_HOME)/am/src/spike/linker.ld
LDFLAGS += -T $(AM_HOME)/am/src/riscv/spike/linker.ld
LDFLAGS += --gc-sections -e _start
CFLAGS += -DMAINARGS=\"$(mainargs)\"
.PHONY: $(AM_HOME)/am/src/spike/trm.c
.PHONY: $(AM_HOME)/am/src/riscv/spike/trm.c
image: $(IMAGE).elf

View file

@ -1,4 +1,10 @@
include $(AM_HOME)/scripts/isa/x86.mk
include $(AM_HOME)/scripts/platform/nemu.mk
CFLAGS += -mstringop-strategy=loop
LDFLAGS += --defsym=_pmem_start=0x0
CFLAGS += -mstringop-strategy=loop -DISA_H=\"x86/x86.h\"
# overwrite _pmem_start and _entry_offset defined in nemu.mk
LDFLAGS += --defsym=_pmem_start=0x0 --defsym=_entry_offset=0x100000
AM_SRCS += x86/nemu/start.S \
x86/nemu/cte.c \
x86/nemu/trap.S \
x86/nemu/vme.c