Initial commit
This commit is contained in:
commit
d4849c9840
|
@ -0,0 +1 @@
|
||||||
|
kernel
|
|
@ -0,0 +1,13 @@
|
||||||
|
CODE=src/
|
||||||
|
CC=riscv64-unknown-elf-gcc
|
||||||
|
CFLAGS=-march=rv64gc -mabi=lp64d -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -Tkernel.ld -g -Wall -Wextra
|
||||||
|
EMU=qemu-system-riscv64
|
||||||
|
EFLAGS=-machine virt -cpu rv64 -bios opensbi-riscv64-generic-fw_dynamic.bin -m 256m -nographic -global virtio-mmio.force-legacy=false -s #-S
|
||||||
|
|
||||||
|
.PHONY: all clean run
|
||||||
|
|
||||||
|
all: $(CODE)*.s $(CODE)*.c
|
||||||
|
$(CC) $(CFLAGS) $? -o kernel
|
||||||
|
|
||||||
|
run:
|
||||||
|
$(EMU) $(EFLAGS) -kernel kernel
|
|
@ -0,0 +1,44 @@
|
||||||
|
OUTPUT_ARCH( "riscv" )
|
||||||
|
OUTPUT_FORMAT( "elf64-littleriscv" )
|
||||||
|
ENTRY( _start )
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* text: text code section */
|
||||||
|
. = 0x80200000;
|
||||||
|
PROVIDE(text_start = .);
|
||||||
|
.text : { *(.text) }
|
||||||
|
|
||||||
|
/* data: Initialized data segment */
|
||||||
|
.gnu_build_id : { *(.note.gnu.build-id) }
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(data_start = .);
|
||||||
|
.data : { *(.data) }
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(ro_data_start = .);
|
||||||
|
.rodata : { *(.rodata) }
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(sdata_start = .);
|
||||||
|
.sdata : { *(.sdata) }
|
||||||
|
.debug : { *(.debug) }
|
||||||
|
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(stack_start = .);
|
||||||
|
. += 0x4000;
|
||||||
|
PROVIDE(stack_top = .);
|
||||||
|
|
||||||
|
/* Heap */
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(heap_bottom = .);
|
||||||
|
. += 0x80000;
|
||||||
|
|
||||||
|
/* Pages */
|
||||||
|
. = ALIGN(4096);
|
||||||
|
PROVIDE(pages_bottom = .);
|
||||||
|
|
||||||
|
/* End of uninitalized data segement */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
.section .text
|
||||||
|
.global _start
|
||||||
|
|
||||||
|
# a0 - current hart id
|
||||||
|
# a1 - pointer to flattened device tree
|
||||||
|
|
||||||
|
_start:
|
||||||
|
# Initialise stack pointer
|
||||||
|
|
||||||
|
la sp, stack_top
|
||||||
|
mv fp, sp
|
||||||
|
|
||||||
|
j kinit
|
||||||
|
|
||||||
|
finish:
|
||||||
|
j finish
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "opensbi.h"
|
||||||
|
|
||||||
|
void kinit(unsigned long long hartid, void* fdt) {
|
||||||
|
sbi_console_putchar('a');
|
||||||
|
|
||||||
|
while(1);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef OPENSBI_H
|
||||||
|
#define OPENSBI_H
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SBIRET_ERROR_CODE_SUCCESS = 0,
|
||||||
|
SBIRET_ERROR_CODE_FAILED = -1,
|
||||||
|
SBIRET_ERROR_CODE_UNSUPPORTED = -2,
|
||||||
|
SBIRET_ERROR_CODE_INVALID_PARAMETER = -3,
|
||||||
|
SBIRET_ERROR_CODE_DENIED = -4,
|
||||||
|
SBIRET_ERROR_CODE_INVALID_ADDRESS = -5,
|
||||||
|
SBIRET_ERROR_CODE_ALREADY_AVAILABLE = -6
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sbiret {
|
||||||
|
unsigned long error;
|
||||||
|
unsigned long value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// sbi_console_putchar(char) -> void
|
||||||
|
// Puts a character onto the UART port.
|
||||||
|
void sbi_console_putchar(char);
|
||||||
|
|
||||||
|
// sbi_console_getchar() -> int
|
||||||
|
// Puts a character onto the UART port.
|
||||||
|
int sbi_console_getchar();
|
||||||
|
|
||||||
|
#endif /* OPENSBI_H */
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
.section .text
|
||||||
|
|
||||||
|
.global sbi_console_putchar
|
||||||
|
.global sbi_console_getchar
|
||||||
|
|
||||||
|
# EIDs are stored in a7
|
||||||
|
# FIDs are stored in a6
|
||||||
|
|
||||||
|
# sbi_console_putchar(char) -> void
|
||||||
|
# Puts a character onto the UART port.
|
||||||
|
|
||||||
|
sbi_console_putchar:
|
||||||
|
li a6, 0
|
||||||
|
li a7, 1
|
||||||
|
ecall
|
||||||
|
ret
|
||||||
|
|
||||||
|
# sbi_console_getchar() -> int
|
||||||
|
# Gets a character from the UART port.
|
||||||
|
|
||||||
|
sbi_console_getchar:
|
||||||
|
li a6, 0
|
||||||
|
li a7, 2
|
||||||
|
ecall
|
||||||
|
ret
|
||||||
|
|
Reference in New Issue