From 02980d3422177b086f0607ea0cd0bf7bebec61fd Mon Sep 17 00:00:00 2001 From: Yourtion Date: Mon, 9 May 2016 16:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8C=E8=AF=AD=E8=A8=80=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=882=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 22_day/Makefile | 9 ++++++++- 22_day/console.c | 33 ++++++++++++++++++--------------- 22_day/hello4.c | 4 ++-- 22_day/hello5.nas | 20 ++++++++++++++++++++ 4 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 22_day/hello5.nas diff --git a/22_day/Makefile b/22_day/Makefile index a0f187d..5c8a62b 100644 --- a/22_day/Makefile +++ b/22_day/Makefile @@ -74,6 +74,12 @@ hello4.bim : hello4.obj a_nask.obj Makefile hello4.hrb : hello4.bim Makefile $(BIM2HRB) hello4.bim hello4.hrb 0 +hello5.bim : hello5.obj Makefile + $(OBJ2BIM) @$(RULEFILE) out:hello5.bim stack:1k map:hello5.map hello5.obj + +hello5.hrb : hello5.bim Makefile + $(BIM2HRB) hello5.bim hello5.hrb 0 + bug1.bim : bug1.obj Makefile $(OBJ2BIM) @$(RULEFILE) out:bug1.bim map:bug1.map bug1.obj a_nask.obj @@ -94,7 +100,7 @@ bug3.hrb : bug3.bim Makefile haribote.img : ipl10.bin haribote.sys Makefile \ hello.hrb hello2.hrb a.hrb hello3.hrb bug1.hrb bug2.hrb bug3.hrb \ - hello4.hrb + hello4.hrb hello5.hrb $(EDIMG) imgin:../z_tools/fdimg0at.tek \ wbinimg src:ipl10.bin len:512 from:0 to:0 \ copy from:haribote.sys to:@: \ @@ -108,6 +114,7 @@ haribote.img : ipl10.bin haribote.sys Makefile \ copy from:bug2.hrb to:@: \ copy from:bug3.hrb to:@: \ copy from:hello4.hrb to:@: \ + copy from:hello5.hrb to:@: \ imgout:haribote.img # 其他指令 diff --git a/22_day/console.c b/22_day/console.c index 18b8bf6..6f92944 100644 --- a/22_day/console.c +++ b/22_day/console.c @@ -258,7 +258,7 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; char name[18], *p, *q; struct TASK *task = task_now(); - int i; + int i, segsiz, datsiz, esp, dathrb; /*根据命令行生成文件名*/ for (i = 0; i < 13; i++) { @@ -284,22 +284,25 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) if (finfo != 0) { /*找到文件的情况*/ p = (char *) memman_alloc_4k(memman, finfo->size); - q = (char *) memman_alloc_4k(memman, 64 * 1024); - *((int *) 0xfe8) = (int) p; file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); - set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60); - set_segmdesc(gdt + 1004, 64 * 1024 - 1, (int) q, AR_DATA32_RW + 0x60); - if (finfo->size >= 8 && strncmp(p + 4, "Hari", 4) == 0) { - p[0] = 0xe8; - p[1] = 0x16; - p[2] = 0x00; - p[3] = 0x00; - p[4] = 0x00; - p[5] = 0xcb; - } - start_app(0, 1003 * 8, 64 * 1024, 1004 * 8, &(task->tss.esp0)); + if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) { + segsiz = *((int *) (p + 0x0000)); + esp = *((int *) (p + 0x000c)); + datsiz = *((int *) (p + 0x0010)); + dathrb = *((int *) (p + 0x0014)); + q = (char *) memman_alloc_4k(memman, segsiz); + *((int *) 0xfe8) = (int) q; + set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60); + set_segmdesc(gdt + 1004, segsiz - 1, (int) q, AR_DATA32_RW + 0x60); + for (i = 0; i < datsiz; i++) { + q[esp + i] = p[dathrb + i]; + } + start_app(0x1b, 1003 * 8, esp, 1004 * 8, &(task->tss.esp0)); + memman_free_4k(memman, (int) q, segsiz); + } else { + cons_putstr0(cons, ".hrb file format error.\n"); + } memman_free_4k(memman, (int) p, finfo->size); - memman_free_4k(memman, (int) q, 64 * 1024); cons_newline(cons); return 1; } diff --git a/22_day/hello4.c b/22_day/hello4.c index 269cb9d..7fb73de 100644 --- a/22_day/hello4.c +++ b/22_day/hello4.c @@ -1,8 +1,8 @@ -void api_putstr0(int c); +void api_putstr0(char *s); void api_end(void); void HariMain(void) { - api_putstr0('hello, world\n'); + api_putstr0("hello, world\n"); api_end(); } diff --git a/22_day/hello5.nas b/22_day/hello5.nas new file mode 100644 index 0000000..ee62330 --- /dev/null +++ b/22_day/hello5.nas @@ -0,0 +1,20 @@ +[FORMAT "WCOFF"] +[INSTRSET "i486p"] +[BITS 32] +[FILE "hello5.nas"] + + GLOBAL _HariMain + +[SECTION .text] + +_HariMain: + MOV EDX,2 + MOV EBX,msg + INT 0x40 + MOV EDX,4 + INT 0x40 + +[SECTION .data] + +msg: + DB "hello, world", 0x0a, 0