Skip to content

Commit

Permalink
Added hrb.lds
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc2017 committed Jul 15, 2024
1 parent 873e649 commit b3edf9f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions docs/chapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | | |
Expand Down
13 changes: 13 additions & 0 deletions docs/hrb_format.md
Original file line number Diff line number Diff line change
@@ -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 空间的起始地址
18 changes: 10 additions & 8 deletions projects/22_day/harib19e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 > $@
Expand All @@ -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 \
Expand Down
51 changes: 51 additions & 0 deletions utils/linker_script/hrb.lds
Original file line number Diff line number Diff line change
@@ -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) }
}

0 comments on commit b3edf9f

Please sign in to comment.