1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 00:16:17 +04:00

user: support riscv64, remove linker scripts

This commit is contained in:
WangRunji 2019-02-18 13:55:37 +08:00
parent b4833e9c49
commit 7691085176
14 changed files with 6 additions and 351 deletions

2
user/Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "linked_list_allocator"
version = "0.6.3"

View File

@ -1,4 +1,4 @@
# arch = {riscv32, x86_64, aarch64}
# arch = {riscv32, riscv64, x86_64, aarch64}
# mode = {debug, release}
arch ?= riscv32
mode ?= debug
@ -24,12 +24,7 @@ endif
.PHONY: all clean build-rust build-c build mksfs sfsimg
# not support riscv64 now
ifeq ($(arch), riscv64)
all:
else
all: $(sfsimg)
endif
build-rust:
@echo Building user rust programs

View File

@ -1,2 +0,0 @@
output/
*.img

View File

@ -1,14 +0,0 @@
#!/bin/bash
ARCH=riscv64
CC=${ARCH}-unknown-elf-gcc
CFLAGS="-nostartfiles -nostdlib -nodefaultlibs -o output/a.out -T ${ARCH}.ld -fno-builtin"
if ! [[ -d output ]]
then
mkdir output
fi
#CFLAGS="${CFLAGS} -DRISCV_QEMU"
${CC} ${CFLAGS} test.c
mksfs zip output ./user-${ARCH}.img

View File

@ -1,43 +0,0 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS {
/* Load programs at this address: "." means the current address */
. = 0x00800020;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
/* The data segment */
.data : {
*(.data)
*(.data.*)
}
.sdata : {
*(.sdata)
*(.sdata.*)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
/DISCARD/ : {
*(.eh_frame .note.GNU-stack .comment)
}
}

View File

@ -1,43 +0,0 @@
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS {
/* Load programs at this address: "." means the current address */
. = 0x800020;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
/* The data segment */
.data : {
*(.data)
*(.data.*)
}
.sdata : {
*(.sdata)
*(.sdata.*)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
/DISCARD/ : {
*(.eh_frame .note.GNU-stack .comment)
}
}

View File

@ -1,87 +0,0 @@
#ifdef RISCV_QEMU
# define SYS_write 64
# define SYS_exit 93
long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long a6) {
register long _0 __asm__("a7") = a0;
register long _1 __asm__("a0") = a1;
register long _2 __asm__("a1") = a2;
register long _3 __asm__("a2") = a3;
register long _4 __asm__("a3") = a4;
register long _5 __asm__("a4") = a5;
register long _6 __asm__("a5") = a6;
__asm__ __volatile__("ecall":::);
return _1;
}
#else
# define SYS_write 103
# define SYS_exit 1
# define SYS_fork 2
# define SYS_putc 30
# define SYS_getpid 18
# define SYS_sleep 11
long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long a6) {
register long _0 __asm__("x10") = a0;
register long _1 __asm__("x11") = a1;
register long _2 __asm__("x12") = a2;
register long _3 __asm__("x13") = a3;
register long _4 __asm__("x14") = a4;
register long _5 __asm__("x15") = a5;
register long _6 __asm__("x16") = a6;
__asm__ __volatile__("ecall":::);
return _0;
}
#endif
const char* welcome_msg = "hello world!\n";
const char* hexch = "0123456789ABCDEF";
void putc(char c) {
syscall(SYS_putc, c, 0, 0, 0, 0, 0);
}
void putstr(const char* s) {
for (; *s; s++)
syscall(SYS_putc, *s, 0, 0, 0, 0, 0);
}
void putint_hex(long v) {
char ch[18];
ch[16] = 'H';
ch[17] = 0;
for (int i = 15; i >= 0; i--) {
ch[i] = hexch[v & 15];
v >>= 4;
}
putstr(ch);
}
void _start() {
putstr(welcome_msg);
putc('\n');
putstr("my pid is ");
long v = syscall(SYS_getpid, 0, 0, 0, 0, 0, 0);
putint_hex(v);
putc('\n');
long v1 = syscall(SYS_fork, 0, 0, 0, 0, 0, 0);
putstr("fork returned: ");
putint_hex(v1);
putc('\n');
if (v1 != 0) {
putstr("parent sleeping");
putc('\n');
syscall(SYS_sleep, 200, 0, 0, 0, 0, 0);
}
putstr("my pid is ");
v = syscall(SYS_getpid, 0, 0, 0, 0, 0, 0);
putint_hex(v);
putc('\n');
putint_hex(v);
putstr(" is exiting");
putc('\n');
syscall(SYS_exit, 0, 0, 0, 0, 0, 0);
}

View File

@ -1,46 +0,0 @@
/* Simple linker script for ucore user-level programs.
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
OUTPUT_ARCH(aarch64)
ENTRY(_start)
SECTIONS {
/* Load programs at this address: "." means the current address */
. = 0xffff000000000000;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
/* The data segment */
.data : {
*(.data)
*(.data.*)
}
.sdata : {
*(.sdata)
*(.sdata.*)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
/DISCARD/ : {
*(.eh_frame .note.GNU-stack .comment)
}
}

View File

@ -1,46 +0,0 @@
/* Simple linker script for ucore user-level programs.
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS {
/* Load programs at this address: "." means the current address */
. = 0x800020;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
/* The data segment */
.data : {
*(.data)
*(.data.*)
}
.sdata : {
*(.sdata)
*(.sdata.*)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
/DISCARD/ : {
*(.eh_frame .note.GNU-stack .comment)
}
}

View File

@ -1,46 +0,0 @@
/* Simple linker script for ucore user-level programs.
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
OUTPUT_ARCH(x86_64)
ENTRY(_start)
SECTIONS {
/* Load programs at this address: "." means the current address */
. = 0x800020;
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
}
PROVIDE(etext = .); /* Define the 'etext' symbol to this value */
.rodata : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
}
/* Adjust the address for the data segment to the next page */
. = ALIGN(0x1000);
/* The data segment */
.data : {
*(.data)
*(.data.*)
}
.sdata : {
*(.sdata)
*(.sdata.*)
}
PROVIDE(edata = .);
.bss : {
*(.bss)
}
PROVIDE(end = .);
/DISCARD/ : {
*(.eh_frame .note.GNU-stack .comment)
}
}

View File

@ -15,7 +15,7 @@
"linker-is-gnu": true,
"pre-link-args": {
"ld.lld": [
"-Tsrc/arch/aarch64/user.ld"
"--image-base=0xffff000000000000"
]
},
"llvm-target": "aarch64-unknown-none",

View File

@ -11,11 +11,6 @@
"max-atomic-width": "32",
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"pre-link-args": {
"ld.lld": [
"-Tsrc/arch/riscv32/user.ld"
]
},
"executables": true,
"panic-strategy": "abort",
"relocation-model": "static",

View File

@ -7,15 +7,10 @@
"os": "none",
"arch": "riscv64",
"cpu": "generic-rv64",
"features": "",
"max-atomic-width": "32",
"features": "+m,+a,+c",
"max-atomic-width": "64",
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"pre-link-args": {
"ld.lld": [
"-Tsrc/arch/riscv32/boot/linker64.ld"
]
},
"executables": true,
"panic-strategy": "abort",
"relocation-model": "static",

View File

@ -9,11 +9,6 @@
"executables": true,
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"pre-link-args": {
"ld.lld": [
"-Tsrc/arch/x86_64/user.ld"
]
},
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float"