From b3edf9ff6739a85c0b2a8c0421e5af4125b4bcee Mon Sep 17 00:00:00 2001 From: Jeffrey Cai Date: Mon, 15 Jul 2024 22:29:43 +0800 Subject: [PATCH] Added hrb.lds --- docs/_sidebar.md | 1 + docs/chapters.md | 14 ++++----- docs/hrb_format.md | 13 ++++++++ projects/22_day/harib19e/Makefile | 18 ++++++----- utils/linker_script/hrb.lds | 51 +++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 docs/hrb_format.md create mode 100644 utils/linker_script/hrb.lds diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 075711f6..76b67262 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -6,6 +6,7 @@ - [modifications](modifications.md) - [memory map](memory_map.md) + - [HRB file format](hrb_format.md) - [Q&A](Q&A.md) - [references](references.md) diff --git a/docs/chapters.md b/docs/chapters.md index 20534d9e..8cba3d8e 100644 --- a/docs/chapters.md +++ b/docs/chapters.md @@ -147,13 +147,13 @@ | | 5 | harib18e | 对异常的支持 | | | | 6 | harib18f | 保护操作系统(3) | | | | 7 | harib18g | 保护操作系统(4) | works perfect。重点章节 | -| 22 day | 1 | harib19a | | Started to use mtools. | -| | 2 | harib19b | | [^7] | -| | 3 | harib19c | | | -| | 4 | harib19d | | | -| | 5 | harib19e | | 如作者指出 hrb 文件使用了自定义的格式,并且使用作者开发的工具生成的。引入 app.lds | -| | 6 | harib19f | | | -| | 7 | harib19g | | | +| 22 day | 1 | harib19a | 保护操作系统(5) | Started to use mtools(后记:已全部更新). | +| | 2 | harib19b | 帮助发现 bug | [^7] | +| | 3 | harib19c | 强制结束应用程序 | | +| | 4 | harib19d | 用 C 语言显示字符串(1) | | +| | 5 | harib19e | 用 C 语言显示字符串(2) | 如作者指出 hrb 文件使用了自定义的格式,并且使用作者开发的工具生成的。引入 hrb.lds | +| | 6 | harib19f | 显示窗口 | | +| | 7 | harib19g | 在窗口中描绘字符和方块 | | | 23 day | 1 | harib20a | | | | | 2 | harib20b | | | | | 3 | harib20c | | | diff --git a/docs/hrb_format.md b/docs/hrb_format.md new file mode 100644 index 00000000..34a07f93 --- /dev/null +++ b/docs/hrb_format.md @@ -0,0 +1,13 @@ +# Hrb file format + +From 22.5 + +0x0000 (DWORD) ......请求操作系统为应用程序准备的数据段的大小 +0x0004 (DWORD) ......"Hari"(.hrb 文件的标记) +0x0008 (DWORD) ......数据段内预备空间的大小 +0x000c (DWORD) ......ESP 初始值&数据部分传送目的地址 +0x0010 (DWORD) ......hrb 文件內数据部分的大小 +0×0014 (DWORD) ......hrb 文件内数据部分从哪里开始 +0x0018 (DWORD) ......Oxe9000000 +0x001c (DWORD) ......应用程序运行入口地址 - 0x20 +0x0020 (DWORD) ......malloc 空间的起始地址 diff --git a/projects/22_day/harib19e/Makefile b/projects/22_day/harib19e/Makefile index 44bc478d..8dfad5c3 100644 --- a/projects/22_day/harib19e/Makefile +++ b/projects/22_day/harib19e/Makefile @@ -6,6 +6,8 @@ OBJS_BOOTPACK += stdio.obj string.obj UTILS_FOLDER := ../../../utils include $(UTILS_FOLDER)/platform_config.mk +HRB_LDS := $(UTILS_FOLDER)/linker_script/hrb.lds + NASM = nasm CC = $(GCCPREFIX)gcc AS = $(GCCPREFIX)as @@ -79,7 +81,7 @@ hankaku.obj: hankaku.asm $(NASM) $(NASM_FLAGS) -f elf32 -o $@ $< -l $(basename $@).lst bootpack.hrb: $(OBJS_BOOTPACK) - $(LD) $(LDFLAGS) --oformat binary -o $@ -T bootpack.lds $^ + $(LD) $(LDFLAGS) --oformat binary -o $@ -T $(HRB_LDS) -e STACK_SIZE=3136*1024 $^ haribote.sys: asmhead.bin bootpack.hrb cat asmhead.bin > $@ @@ -93,33 +95,33 @@ hello2.hrb: hello2.nas a.hrb: a_nask.obj a.c $(CC) $(APP_CFLAGS) -c a.c -o a.obj - $(LD) $(APP_LDFLAGS) --oformat binary a.obj a_nask.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary a.obj a_nask.obj -o $@ -T $(HRB_LDS) -e STACK_SIZE=1024 hello3.hrb: a_nask.obj hello3.c $(CC) $(APP_CFLAGS) -c hello3.c -o hello3.obj - $(LD) $(APP_LDFLAGS) --oformat binary hello3.obj a_nask.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary hello3.obj a_nask.obj -o $@ -T $(HRB_LDS) hello4.hrb: a_nask.obj hello4.c $(CC) $(APP_CFLAGS) -c hello4.c -o hello4.obj - $(LD) $(APP_LDFLAGS) --oformat binary hello4.obj a_nask.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary hello4.obj a_nask.obj -o $@ -T $(HRB_LDS) -e STACK_SIZE=1024 hello5.hrb: hello5.nas # In order to use the app.lds for linking, split the nasm command into two steps commands. # $(NASM) $(NASM_FLAGS) -f bin -o $@ $< -l hello5.lst $(NASM) $(NASM_FLAGS) -f elf32 -o hello5.obj $< -l hello5.lst - $(LD) $(APP_LDFLAGS) --oformat binary hello5.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary hello5.obj -o $@ -T $(HRB_LDS) -e STACK_SIZE=1024 bug1.hrb: a_nask.obj bug1.c $(CC) $(APP_CFLAGS) -c bug1.c -o bug1.obj - $(LD) $(APP_LDFLAGS) --oformat binary bug1.obj a_nask.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary bug1.obj a_nask.obj -o $@ -T $(HRB_LDS) bug2.hrb: bug2.c $(CC) $(APP_CFLAGS) -c bug2.c -o bug2.obj - $(LD) $(APP_LDFLAGS) --oformat binary bug2.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary bug2.obj -o $@ -T $(HRB_LDS) bug3.hrb: a_nask.obj bug3.c $(CC) $(APP_CFLAGS) -c bug3.c -o bug3.obj - $(LD) $(APP_LDFLAGS) --oformat binary bug3.obj a_nask.obj -o $@ -T app.lds + $(LD) $(APP_LDFLAGS) --oformat binary bug3.obj a_nask.obj -o $@ -T $(HRB_LDS) haribote.img: ipl10.bin haribote.sys \ hello.hrb hello2.hrb a.hrb hello3.hrb bug1.hrb bug2.hrb bug3.hrb \ diff --git a/utils/linker_script/hrb.lds b/utils/linker_script/hrb.lds new file mode 100644 index 00000000..ce1f9977 --- /dev/null +++ b/utils/linker_script/hrb.lds @@ -0,0 +1,51 @@ +/* +From 22 day section 5 + +0x0000 (DWORD) ......Size of the data segment requested by the operating system for the application +0x0004 (DWORD) ......"Hari" (signature of the .hrb file) +0x0008 (DWORD) ......Size of the pre-allocated space in the data segment +0x000c (DWORD) ......Initial value of ESP & transfer destination address of the data segment +0x0010 (DWORD) ......Size of the data segment in the .hrb file +0x0014 (DWORD) ......Starting point of the data segment in the .hrb file +0x0018 (DWORD) ......0xe9000000 +0x001c (DWORD) ......Entry address of the application - 0x20 +0x0020 (DWORD) ......Starting address of the malloc space +*/ + +OUTPUT_FORMAT("binary"); + +/* Define parameters with default values */ +STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 64 * 1024; +SIGNATURE = 0x69726148; /* 'H' = 0x48, 'a' = 0x61, 'r' = 0x72, 'i' = 0x69 */ +MMAREA_SIZE = 0; +STACK_INIT = DEFINED(STACK_INIT) ? STACK_INIT : 0x310000; +DATA_SIZE = SIZEOF(.data); +DATA_INIT_ADDR = LOADADDR(.data); +CONSTANT_0xE9000000 = 0xE9000000; +ENTRY_ADDR_OFFSET = _HariMain - 0x20; +HEAP_START_ADDR = DEFINED(HEAP_START_ADDR) ? HEAP_START_ADDR : 0; + +SECTIONS +{ + .head 0x0 : { + LONG(STACK_SIZE) + LONG(SIGNATURE) + LONG(MMAREA_SIZE) + LONG(STACK_INIT) + LONG(DATA_SIZE) + LONG(DATA_INIT_ADDR) + LONG(CONSTANT_0xE9000000) + LONG(ENTRY_ADDR_OFFSET) + LONG(HEAP_START_ADDR) + } + + .text : { *(.text) } + + .data STACK_INIT : AT ( ADDR(.text) + SIZEOF(.text) ) { + *(.data) + *(.rodata*) + *(.bss) + } + + /DISCARD/ : { *(.eh_frame) } +} \ No newline at end of file