FUCKKKK
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
CC := clang
|
||||
LD := ld.lld
|
||||
|
||||
ROOT := ../../../..
|
||||
OUT := $(ROOT)/SYSTEM/system/deshab64/tools/hello.elf
|
||||
|
||||
CFLAGS := -target x86_64-unknown-none -std=c11 -ffreestanding -fno-builtin -fno-stack-protector -fpie -mno-red-zone -mno-sse -mno-sse2 -mno-mmx -msoft-float -m64 -Wall -Wextra -I../../include -O2
|
||||
LDFLAGS := -nostdlib -static -pie -z max-page-size=0x1000 -T linker.ld
|
||||
|
||||
C_SOURCES := main.c
|
||||
OBJECTS := $(C_SOURCES:.c=.o)
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUT)
|
||||
|
||||
$(OUT): $(OBJECTS) linker.ld
|
||||
@mkdir -p "$(dir $(OUT))"
|
||||
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
powershell -NoProfile -Command "Get-ChildItem -Path . -Recurse -Filter *.o | Remove-Item -Force; if (Test-Path '$(OUT)') { Remove-Item '$(OUT)' -Force }"
|
||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
ENTRY(dsk_entry)
|
||||
|
||||
PHDRS
|
||||
{
|
||||
text PT_LOAD FLAGS(5);
|
||||
rodata PT_LOAD FLAGS(4);
|
||||
data PT_LOAD FLAGS(6);
|
||||
dynamic PT_DYNAMIC FLAGS(4);
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x1000;
|
||||
.text : ALIGN(4K) { *(.text*) } :text
|
||||
.rodata : ALIGN(4K) { *(.rodata*) } :rodata
|
||||
.data : ALIGN(4K) {
|
||||
*(.data*)
|
||||
*(.data.rel.ro*)
|
||||
*(COMMON)
|
||||
} :data
|
||||
.rela.dyn : ALIGN(8) { *(.rela.dyn*) } :data
|
||||
.dynamic : ALIGN(8) { *(.dynamic*) } :data :dynamic
|
||||
.bss : ALIGN(4K) {
|
||||
*(.bss*)
|
||||
} :data
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* hello-app - Deshab SDK 最小应用示例
|
||||
*
|
||||
* 展示完整的应用入口契约:校验 magic -> 初始化上下文 -> 绘制 UI -> 等待退出。
|
||||
* 构建产物:SYSTEM/system/deshab64/tools/hello.elf
|
||||
*/
|
||||
#include "../../../firstInit/ascii_bitmaps.c"
|
||||
#include "deshab/deshab.h"
|
||||
#include "deshab/font.h"
|
||||
|
||||
static dsb_app_context g_ac;
|
||||
|
||||
void dsk_entry(const dsk_boot_context *ctx) {
|
||||
/* 1. 校验启动上下文 magic */
|
||||
if (ctx->magic != DSK_BOOT_MAGIC) return;
|
||||
|
||||
/* 2. 初始化应用上下文(framebuffer + block + kernel_api) */
|
||||
dsb_app_init(&g_ac, ctx);
|
||||
|
||||
/* 3. 清屏 */
|
||||
dsb_fill_bg(&g_ac, DSB_BG_PRIMARY);
|
||||
|
||||
/* 4. 标题栏 + 状态栏 */
|
||||
dsb_draw_titlebar(&g_ac, "HelloApp", (i64)g_ac.fb_w);
|
||||
dsb_draw_statusbar(&g_ac, "Esc to exit", (i64)g_ac.fb_w, (i64)g_ac.fb_h);
|
||||
|
||||
/* 5. 居中显示欢迎文字 */
|
||||
const char *msg = "Hello, Deshab!";
|
||||
i64 msg_w = (i64)dsb_strlen(msg) * 12;
|
||||
i64 x = ((i64)g_ac.fb_w - msg_w) / 2;
|
||||
i64 y = ((i64)g_ac.fb_h) / 2;
|
||||
dsb_draw_string(&g_ac, msg, x, y, DSB_TEXT_PRIMARY, DSB_BG_PRIMARY, 12);
|
||||
|
||||
/* 6. 等待 Esc 键退出 */
|
||||
for (;;) {
|
||||
u8 st = dsb_inb(0x64);
|
||||
if (st & 1) {
|
||||
u8 sc = dsb_inb(0x60);
|
||||
if (sc == 1) break; /* Esc make code */
|
||||
}
|
||||
__asm__ volatile("pause");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,50 @@
|
||||
/* hello-driver - Deshab SDK 最小驱动示例
|
||||
*
|
||||
* 展示 DKM 驱动三符号契约:driver_desc + driver_init + driver_exit。
|
||||
* 构建方式:clang -c main.c -o hello.o && ld.lld -r -o hello.drv hello.o
|
||||
* 注册方式:在 SYSTEM/driver/manifest.json 添加条目
|
||||
*/
|
||||
#include "deshab/driver.h"
|
||||
#include "deshab/serial.h"
|
||||
|
||||
static const dkm_log_api *g_log = 0;
|
||||
|
||||
static const char *const g_depends[] = { 0 };
|
||||
static const char *const g_provides[] = { "hello" };
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
const dkm_driver_desc driver_desc = {
|
||||
.magic = DKM_DRIVER_MAGIC,
|
||||
.abi_version = DKM_ABI_VERSION,
|
||||
.desc_size = sizeof(dkm_driver_desc),
|
||||
.name = "hello",
|
||||
.version = "1.0",
|
||||
.vendor = "Deshab",
|
||||
.driver_class = DKM_CLASS_MISC,
|
||||
.stage = 3,
|
||||
.flags = 0,
|
||||
.priority = 100,
|
||||
.depends = g_depends,
|
||||
.depends_count = 0,
|
||||
.provides = g_provides,
|
||||
.provides_count = 1,
|
||||
.min_kernel_abi = DKM_KERNEL_API_VERSION,
|
||||
.feature_bits = 0,
|
||||
};
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
int driver_init(const dkm_kernel_api *api, dkm_driver_handle *handle) {
|
||||
(void)handle;
|
||||
if (!api || !api->log) return -1;
|
||||
g_log = api->log;
|
||||
g_log->info("[hello] init");
|
||||
g_log->info("[hello] driver ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
int driver_exit(dkm_driver_handle *handle) {
|
||||
(void)handle;
|
||||
if (g_log) g_log->info("[hello] exit");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user