Compare commits

...

2 Commits

Author SHA1 Message Date
Yourtion
02980d3422 用C语言显示字符串(2) 2016-05-09 16:28:13 +08:00
Yourtion
c718be8fd3 用C语言显示字符串(1) 2016-05-09 13:48:34 +08:00
5 changed files with 73 additions and 16 deletions

View File

@@ -67,6 +67,19 @@ hello3.bim : hello3.obj a_nask.obj Makefile
hello3.hrb : hello3.bim Makefile
$(BIM2HRB) hello3.bim hello3.hrb 0
hello4.bim : hello4.obj a_nask.obj Makefile
$(OBJ2BIM) @$(RULEFILE) out:hello4.bim stack:1k map:hello4.map \
hello4.obj a_nask.obj
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
@@ -86,7 +99,8 @@ bug3.hrb : bug3.bim Makefile
$(BIM2HRB) bug3.bim bug3.hrb 0
haribote.img : ipl10.bin haribote.sys Makefile \
hello.hrb hello2.hrb a.hrb hello3.hrb bug1.hrb bug2.hrb bug3.hrb
hello.hrb hello2.hrb a.hrb hello3.hrb bug1.hrb bug2.hrb bug3.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:@: \
@@ -99,6 +113,8 @@ haribote.img : ipl10.bin haribote.sys Makefile \
copy from:bug1.hrb to:@: \
copy from:bug2.hrb to:@: \
copy from:bug3.hrb to:@: \
copy from:hello4.hrb to:@: \
copy from:hello5.hrb to:@: \
imgout:haribote.img
# 其他指令

View File

@@ -4,6 +4,7 @@
[FILE "a_nask.nas"] ; 源文件名信息
GLOBAL _api_putchar
GLOBAL _api_putstr0
GLOBAL _api_end
[SECTION .text]
@@ -13,6 +14,15 @@ _api_putchar: ; void api_putchar(int c);
MOV AL,[ESP+4] ; c
INT 0x40
RET
_api_putstr0: ; void api_putstr0(char *s);
PUSH EBX
MOV EDX,2
MOV EBX,[ESP+8] ; s
INT 0x40
POP EBX
RET
_api_end: ; void api_end(void);
MOV EDX,4
INT 0x40

View File

@@ -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;
}

8
22_day/hello4.c Normal file
View File

@@ -0,0 +1,8 @@
void api_putstr0(char *s);
void api_end(void);
void HariMain(void)
{
api_putstr0("hello, world\n");
api_end();
}

20
22_day/hello5.nas Normal file
View File

@@ -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