Commit Diff


commit - a70d1e4b24bdbdbd747748a81665e1d45f1258f0
commit + 986015452b0226be1a802ce0d713871752e3de04
blob - 4ddf4f2b5d040e0c877f3ab43fc1db2de20e61e8
blob + 210d8e6b2ecb429b7112ce6106163429f7816805
--- Makefile
+++ Makefile
@@ -1,19 +1,34 @@
 ARCH		= aarch64
 TARGET		= ${ARCH}-none-elf
+BOARD       ?=qemu_virt
 
-CC			= clang
+BIN			= /usr/local/bin/
+
+AS			= ${BIN}clang
 ASFLAGS		= -target ${TARGET}
-ASRC        = boot.S
+ASFILES		= boot.o
 
-OBJS        = ${ASRC:.S=.o}
+CXX			= ${BIN}clang++
+CXXFLAGS	= -target ${TARGET} -Wall -Wextra -nostdlib -fno-exceptions
+CXXFLAGS    += -ffreestanding -mgeneral-regs-only
+CXXFLAGS    += -Iinclude -DBOARD_${BOARD}
+CXXFILES	= kernel.cc uart_${BOARD}.cc
 
+OBJS        = ${ASFILES:.S=.o} ${CXXFILES:.cc=.o}
+LD			= ${BIN}ld.lld
+
 .PHONY:	clean
 
-all: boot.o
+all: squat.img
 
-clean:
-	rm -rf *.o
+squat.img: squat.elf
+	llvm-objcopy squat.elf -O binary squat.img
 
-.SUFFIXES: .S.o
+squat.elf: linker.ld ${OBJS}
+	${LD} -T linker.ld -o squat.elf ${OBJS}
+
 .S.o:
-	${CC} ${ASFLAGS} -c $< -o $@
+	${AS} ${ASFLAGS} -c boot.S -o boot.o
+
+clean:
+	rm -rf *.o squat.elf squat.img
blob - /dev/null
blob + 6692c22ae33b354e645ef0a84cdf03618d2afaab (mode 644)
--- /dev/null
+++ include/hw.h
@@ -0,0 +1,28 @@
+// hw.h
+
+#pragma once
+
+
+#include "stdint.h"
+
+
+namespace Hw
+{
+
+
+inline void 
+write32(uintptr_t ptr, uint32_t value)
+{
+    *reinterpret_cast<uint32_t *>(ptr) = value;
+}
+
+
+inline uint32_t 
+read32(uintptr_t ptr)
+{
+    return *reinterpret_cast<const uint32_t *>(ptr);
+}
+
+
+}   // namespace Hw
+
blob - /dev/null
blob + 1a9e1e5f60ccb449e0ce7b96f9e7f1b1b121c96d (mode 644)
--- /dev/null
+++ include/stdint.h
@@ -0,0 +1,15 @@
+// stdint.h
+
+#pragma once
+
+typedef signed char         int8_t;
+typedef unsigned char       uint8_t;
+typedef short               int16_t;
+typedef unsigned short      uint16_t;
+typedef int                 int32_t;
+typedef unsigned int        uint32_t;
+typedef long long           int64_t;
+typedef unsigned long long  uint64_t;
+
+typedef unsigned long       uintptr_t;
+typedef long                intptr_t;
blob - /dev/null
blob + d7a104bbfdcf25e3c85f03e5e252d47860b12dd2 (mode 644)
--- /dev/null
+++ kernel.cc
@@ -0,0 +1,33 @@
+// kernel.cc
+
+#ifdef BOARD_qemu_virt
+#include "uart_qemu_virt.h"
+#endif // BOARD_
+
+
+namespace 
+{
+
+/*
+void
+uart_send_string(Board::Uart &uart, const char *szContent)
+{
+    const char *szCurrent = szContent;
+    while (*szCurrent)
+        uart.send(*szCurrent);
+}
+*/
+
+}
+
+
+extern "C"
+void
+kernel_entry_point()
+{
+    Board::Uart uart;
+    // uart_send_string(uart, "Test ECHO mode\r\n");
+
+    for (; ; )
+        ; // uart.send(uart.recv());
+}
blob - /dev/null
blob + 635fccb4acd8223f03c3600f2f9a0252178222c2 (mode 644)
--- /dev/null
+++ linker.ld
@@ -0,0 +1,13 @@
+SECTIONS
+{
+    .text.boot : { *(.text.boot) }
+    .text      : { *(.text) }
+    .rodata    : { *(.rodata) }
+    .data      : { *(.data) }
+    .          = ALIGN(32);
+    bss_begin  = .;
+    .bss       : { *(.bss*) }
+    .          = ALIGN(32);
+    bss_end    = .;
+    /DISCARD/ : { *(.gnu*) *(.dynsym) *(.hash) *(.dynstr) *(.openbsd*) }
+}
blob - /dev/null
blob + cd825d51e1f10e3a4fd945438eb19be7fadb115d (mode 644)
--- /dev/null
+++ uart_qemu_virt.cc
@@ -0,0 +1,37 @@
+// uart_qemu_virt.cc
+
+
+#include <hw.h>
+#include "uart_qemu_virt.h"
+
+
+namespace Board
+{
+
+
+namespace
+{
+
+// constexpr uintptr_t UART_BASE = 0xffffffffc9000000ULL;
+
+}
+
+
+Uart::Uart()
+{
+}
+
+
+// void
+// Uart::send(uint8_t value)
+// {
+// }
+
+
+// uint8_t
+// Uart::recv()
+// {
+// }
+
+
+}   // namespace Board
blob - /dev/null
blob + 3cc750465caea9040243a244ec1f82092b16806e (mode 644)
--- /dev/null
+++ uart_qemu_virt.h
@@ -0,0 +1,22 @@
+// uart_qemu_virt.h
+
+#pragma once
+
+#include <stdint.h>
+
+
+namespace Board
+{
+
+
+class Uart
+{
+public:
+    Uart();
+
+    void send(uint8_t value);
+    uint8_t recv();
+};
+
+
+}   // namespace Board