Compare commits

...

2 Commits

Author SHA1 Message Date
Yourtion
2fb28adf44 为应用程序自由命名 2016-05-03 11:55:45 +08:00
Yourtion
ff3319e083 不随操作系统版本而改变的API 2016-05-03 11:47:17 +08:00
7 changed files with 55 additions and 32 deletions

View File

@@ -46,10 +46,10 @@ bootpack.bim : $(OBJS_BOOTPACK) Makefile
bootpack.hrb : bootpack.bim Makefile
$(BIM2HRB) bootpack.bim bootpack.hrb 0
hlt.hrb : hlt.nas Makefile
$(NASK) hlt.nas hlt.hrb hlt.lst
hello.hrb : hello.nas Makefile
$(NASK) hello.nas hello.hrb hello.lst
haribote.sys : asmhead.bin bootpack.hrb hlt.hrb Makefile
haribote.sys : asmhead.bin bootpack.hrb hello.hrb Makefile
copy /B asmhead.bin+bootpack.hrb haribote.sys
haribote.img : ipl10.bin haribote.sys Makefile
@@ -58,7 +58,7 @@ haribote.img : ipl10.bin haribote.sys Makefile
copy from:haribote.sys to:@: \
copy from:ipl10.nas to:@: \
copy from:make.bat to:@: \
copy from:hlt.hrb to:@: \
copy from:hello.hrb to:@: \
imgout:haribote.img
# 其他指令

View File

@@ -242,7 +242,7 @@ void cmd_mem(struct CONSOLE *cons, unsigned int memtotal);
void cmd_cls(struct CONSOLE *cons);
void cmd_dir(struct CONSOLE *cons);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cmd_hlt(struct CONSOLE *cons, int *fat);
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
/* file.c */
struct FILEINFO {

View File

@@ -157,13 +157,13 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int mem
cmd_dir(cons);
} else if (strncmp(cmdline, "type ", 5) == 0) {
cmd_type(cons, fat, cmdline);
} else if (strcmp(cmdline, "hlt") == 0) {
cmd_hlt(cons, fat);
} else if (cmdline[0] != 0) {
/*不是命令,也不是空行*/
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12);
cons_newline(cons);
cons_newline(cons);
if (cmd_app(cons, fat, cmdline) == 0) {
/*不是命令,不是应用程序,也不是空行*/
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "Bad command.", 12);
cons_newline(cons);
cons_newline(cons);
}
}
return;
}
@@ -245,12 +245,35 @@ void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
return;
}
void cmd_hlt(struct CONSOLE *cons, int *fat)
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct FILEINFO *finfo = file_search("HLT.HRB", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
struct FILEINFO *finfo;
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
char *p;
char name[18], *p;
int i;
/*根据命令行生成文件名*/
for (i = 0; i < 13; i++) {
if (cmdline[i] <= ' ') {
break;
}
name[i] = cmdline[i];
}
name[i] = 0; /*暂且将文件名的后面置为0*/
/*寻找文件 */
finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
if (finfo == 0 && name[i -1]!= '.') {
/*由于找不到文件,故在文件名后面加上“.hrb”后重新寻找*/
name[i ] = '.';
name[i + 1] = 'H';
name[i + 2] = 'R';
name[i + 3] = 'B';
name[i + 4] = 0;
finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
}
if (finfo != 0) {
/*找到文件的情况*/
p = (char *) memman_alloc_4k(memman, finfo->size);
@@ -258,11 +281,9 @@ void cmd_hlt(struct CONSOLE *cons, int *fat)
set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER);
farcall(0, 1003 * 8);
memman_free_4k(memman, (int) p, finfo->size);
} else {
/*没有找到文件的情况*/
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, "File not found.", 15);
cons_newline(cons);
return 1;
}
cons_newline(cons);
return;
/*没有找到文件的情况*/
return 0;
}

View File

@@ -27,6 +27,7 @@ void init_gdtidt(void)
set_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);
set_gatedesc(idt + 0x40, (int) asm_cons_putchar, 2 * 8, AR_INTGATE32);
return;
}

12
20_day/hello.nas Normal file
View File

@@ -0,0 +1,12 @@
[BITS 32]
MOV AL,'h'
INT 0x40
MOV AL,'e'
INT 0x40
MOV AL,'l'
INT 0x40
MOV AL,'l'
INT 0x40
MOV AL,'o'
INT 0x40
RETF

View File

@@ -1,12 +0,0 @@
[BITS 32]
MOV AL,'h'
CALL 2*8:0xbe8
MOV AL,'e'
CALL 2*8:0xbe8
MOV AL,'l'
CALL 2*8:0xbe8
MOV AL,'l'
CALL 2*8:0xbe8
MOV AL,'o'
CALL 2*8:0xbe8
RETF

View File

@@ -218,10 +218,11 @@ _farcall: ; void farcall(int eip, int cs);
RET
_asm_cons_putchar:
STI
PUSH 1
AND EAX,0xff ; 将AH和EAX的高位置0将EAX置为已存入字符编码的状态
PUSH EAX
PUSH DWORD [0x0fec] ; 读取内存并PUSH该值
CALL _cons_putchar
ADD ESP,12 ; 将栈中的数据丢弃
RETF
IRETD