add files from learning repo
commit
8c0eb4f6f2
|
@ -0,0 +1,35 @@
|
|||
out/*
|
||||
nimcache/
|
||||
nimblecache/
|
||||
htmldocs/
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# out
|
||||
*.o
|
||||
*.elf
|
|
@ -0,0 +1,33 @@
|
|||
SHELL = /bin/bash
|
||||
.DEFAULT_GOAL := build
|
||||
BUILDDIR = build
|
||||
BINDIR = bin
|
||||
OBJECT_FILES = boot.o
|
||||
|
||||
build: clean-objects assemble-stub compile copy-o link
|
||||
|
||||
assemble-stub:
|
||||
mkdir -p $(BUILDDIR)/
|
||||
aarch64-elf-as boot.s -o $(BUILDDIR)/boot.o
|
||||
|
||||
compile:
|
||||
mkdir -p $(BUILDDIR)/
|
||||
nim c -d:release kernel.nim
|
||||
|
||||
copy-o:
|
||||
cp nimcache/*.o build/
|
||||
|
||||
clear, clean:
|
||||
rm -rf $(BUILDDIR) nimcache/ bin/
|
||||
|
||||
clean-objects:
|
||||
rm -rf $(BUILDDIR)/*.o nimcache/*.o
|
||||
|
||||
link:
|
||||
mkdir -p $(BINDIR) && \
|
||||
aarch64-elf-ld -nostdlib -Tlinker.ld -o bin/kernel.elf -O2 $(wildcard build/*.o)
|
||||
|
||||
boot:
|
||||
|
||||
setup-macos:
|
||||
brew install aarch64-elf-binutils aarch64-elf-gcc nim
|
|
@ -0,0 +1,8 @@
|
|||
// QEMU Aarch64 Boot Stub
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
ldr x30, =stack_top
|
||||
mov sp, x30
|
||||
bl kmain
|
||||
b .
|
|
@ -0,0 +1,4 @@
|
|||
import strutil
|
||||
|
||||
proc kmain {.exportc.} =
|
||||
printTxt(cast[seq[char]]("hello world\n"))
|
|
@ -0,0 +1,13 @@
|
|||
/* All this linker script does is allocate memory and */
|
||||
/* prepend the QEMU boot stub to our program */
|
||||
ENTRY(_start)
|
||||
SECTIONS {
|
||||
. = 0x40000000;
|
||||
.startup . : { build/boot.o(.text) }
|
||||
.text : { *(.text) }
|
||||
.data : { *(.data) }
|
||||
.bss : { *(.bss COMMON) }
|
||||
. = ALIGN(8);
|
||||
. += 0x1000; /* 4kB of stack memory */
|
||||
stack_top = .;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
gcc.exe = "aarch64-elf-gcc"
|
||||
gcc.linkerexe = "aarch64-elf-ld"
|
||||
|
||||
--os:standalone
|
||||
--cpu:arm64
|
||||
-d:useMalloc
|
||||
--mm:orc
|
||||
--cc:gcc
|
||||
--index:off
|
||||
--passC:"-w -I$lib -I$LIBRARY_PATH -ffreestanding -O2 -Wall -Wextra"
|
||||
# --passL:"-nostdlib -Tlinker.ld -o kernel.elf -O2"
|
||||
--boundChecks:on
|
||||
--noMain
|
||||
--noLinking
|
||||
--deadCodeElim:on
|
||||
--hints:on
|
||||
--listFullPaths:off
|
||||
--nimcache:"nimcache"
|
|
@ -0,0 +1,10 @@
|
|||
import strutil
|
||||
|
||||
func halt =
|
||||
asm "wfi"
|
||||
|
||||
proc panic*(str: string) =
|
||||
halt()
|
||||
|
||||
proc rawoutput*(str: string) =
|
||||
printTxt(cast[seq[char]](str))
|
|
@ -0,0 +1,5 @@
|
|||
var uart*: ptr uint8 = cast[ptr uint8](0x09000000)
|
||||
|
||||
proc printTxt*(str: seq[char]) =
|
||||
for i in 0..<len(str):
|
||||
uart[] = cast[uint8](str[i])
|
Loading…
Reference in New Issue