-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052eed9
commit 9d3dab5
Showing
8 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.o | ||
*.elf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
BUILDDIR = build | ||
|
||
all: githooks $(BUILDDIR)/kernel.elf | ||
|
||
githooks: | hooks | ||
@git config core.hooksPath hooks/ | ||
|
||
$(BUILDDIR): | ||
@mkdir $(BUILDDIR) | ||
|
||
clean: | ||
@$(RM) -rf $(BUILDDIR) | ||
|
||
CC = $(CROSS_PREFIX)gcc | ||
|
||
SRCS = $(wildcard src/*.S src/*.c) | ||
OBJS = $(patsubst src/%.S,$(BUILDDIR)/%.o,$(SRCS)) | ||
OBJS := $(patsubst src/%.c,$(BUILDDIR)/%.o,$(OBJS)) | ||
|
||
CFLAGS = -I include/ -mcmodel=medany | ||
LDFLAGS = -ffreestanding -nostdlib | ||
|
||
$(BUILDDIR)/%.o: src/%.S | $(BUILDDIR) | ||
@printf " CCAS\t$(@F)\n" | ||
@$(CC) $< -c -o $@ $(CFLAGS) | ||
|
||
$(BUILDDIR)/%.o: src/%.c | $(BUILDDIR) | ||
@printf " CC\t$(@F)\n" | ||
@$(CC) $< -c -o $@ $(CFLAGS) | ||
|
||
$(BUILDDIR)/kernel.elf: $(OBJS) kernel.ld | $(BUILDDIR) | ||
@printf " CCLD\t$(@F)\n" | ||
@$(CC) $(OBJS) -o $@ -T kernel.ld $(LDFLAGS) | ||
|
||
run: $(BUILDDIR)/kernel.elf | ||
@qemu-system-riscv64 -M virt -nographic -kernel $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#include <stdnoreturn.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#define KSTACK_BASE 0x88000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
|
||
typedef uint8_t u8; | ||
typedef uint16_t u16; | ||
typedef uint32_t u32; | ||
typedef uint64_t u64; | ||
|
||
typedef int8_t i8; | ||
typedef int16_t i16; | ||
typedef int32_t i32; | ||
typedef int64_t i64; | ||
|
||
typedef uintptr_t usize; | ||
typedef intptr_t ssize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
ENTRY(_start) | ||
|
||
SECTIONS { | ||
. = 0x80200000; | ||
|
||
.init : { | ||
*(.init .init.*) | ||
} | ||
|
||
.text : { | ||
*(.text .text.*) | ||
} | ||
|
||
.rodata : { | ||
*(.rodata .rodata.*) | ||
} | ||
|
||
.data : { | ||
*(.data .data.*) | ||
} | ||
|
||
.sdata : { | ||
*(.sdata .sdata.*) | ||
} | ||
|
||
.sbss : { | ||
*(.sbss .sbss.*) | ||
} | ||
|
||
.bss : { | ||
*(.bss .bss.*) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <config.h> | ||
|
||
.section .init | ||
|
||
.global _start | ||
_start: | ||
li sp, KSTACK_BASE | ||
tail kmain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <attribs.h> | ||
#include <types.h> | ||
|
||
noreturn void kmain(void) { | ||
volatile u8 *uart = (volatile u8 *) 0x10000000; | ||
const char *s = "Hello, world!\n"; | ||
|
||
for (int i = 0; s[i] != '\0'; i++) | ||
*uart = s[i]; | ||
|
||
while (true) | ||
; | ||
} |