Compare commits

..

4 Commits

Author SHA1 Message Date
Yourtion
4d0e2f1af1 当心寄存器 2016-05-03 11:59:06 +08:00
Yourtion
2fb28adf44 为应用程序自由命名 2016-05-03 11:55:45 +08:00
Yourtion
ff3319e083 不随操作系统版本而改变的API 2016-05-03 11:47:17 +08:00
Yourtion
984b2886d0 不结束应用程序 2016-05-03 11:42:02 +08:00
7 changed files with 66 additions and 28 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

@@ -30,6 +30,7 @@ void asm_inthandler27(void);
void asm_inthandler2c(void);
unsigned int memtest_sub(unsigned int start, unsigned int end);
void farjmp(int eip, int cs);
void farcall(int eip, int cs);
void asm_cons_putchar(void);
/* fifo.c */
@@ -241,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,24 +245,45 @@ 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);
file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
set_segmdesc(gdt + 1003, finfo->size - 1, (int) p, AR_CODE32_ER);
farjmp(0, 1003 * 8);
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;
}

14
20_day/hello.nas Normal file
View File

@@ -0,0 +1,14 @@
[INSTRSET "i486p"]
[BITS 32]
MOV ECX,msg
putloop:
MOV AL,[CS:ECX]
CMP AL,0
JE fin
INT 0x40
ADD ECX,1
JMP putloop
fin:
RETF
msg:
DB "hello",0

View File

@@ -1,6 +0,0 @@
[BITS 32]
MOV AL,'A'
CALL 2*8:0xbe3
fin:
HLT
JMP fin

View File

@@ -16,7 +16,7 @@
GLOBAL _asm_inthandler20, _asm_inthandler21
GLOBAL _asm_inthandler27, _asm_inthandler2c
GLOBAL _memtest_sub
GLOBAL _farjmp
GLOBAL _farjmp, _farcall
GLOBAL _asm_cons_putchar
EXTERN _inthandler20, _inthandler21
EXTERN _inthandler27, _inthandler2c
@@ -213,11 +213,18 @@ _farjmp: ; void farjmp(int eip, int cs);
JMP FAR [ESP+4] ; eip, cs
RET
_farcall: ; void farcall(int eip, int cs);
CALL FAR [ESP+4] ; eip, cs
RET
_asm_cons_putchar:
STI
PUSHAD
PUSH 1
AND EAX,0xff ; 将AH和EAX的高位置0将EAX置为已存入字符编码的状态
PUSH EAX
PUSH DWORD [0x0fec] ; 读取内存并PUSH该值
CALL _cons_putchar
ADD ESP,12 ; 将栈中的数据丢弃
RETF
POPAD
IRETD