forked from backup/30dayMakeOS
用API显示字符串
This commit is contained in:
@@ -49,16 +49,20 @@ bootpack.hrb : bootpack.bim Makefile
|
||||
hello.hrb : hello.nas Makefile
|
||||
$(NASK) hello.nas hello.hrb hello.lst
|
||||
|
||||
haribote.sys : asmhead.bin bootpack.hrb hello.hrb Makefile
|
||||
hello2.hrb : hello2.nas Makefile
|
||||
$(NASK) hello2.nas hello2.hrb hello2.lst
|
||||
|
||||
haribote.sys : asmhead.bin bootpack.hrb Makefile
|
||||
copy /B asmhead.bin+bootpack.hrb haribote.sys
|
||||
|
||||
haribote.img : ipl10.bin haribote.sys Makefile
|
||||
haribote.img : ipl10.bin haribote.sys hello.hrb hello2.hrb Makefile
|
||||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
||||
wbinimg src:ipl10.bin len:512 from:0 to:0 \
|
||||
copy from:haribote.sys to:@: \
|
||||
copy from:ipl10.nas to:@: \
|
||||
copy from:make.bat to:@: \
|
||||
copy from:hello.hrb to:@: \
|
||||
copy from:hello2.hrb to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
# 其他指令
|
||||
|
||||
@@ -31,7 +31,7 @@ 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);
|
||||
void asm_hrb_api(void);
|
||||
|
||||
/* fifo.c */
|
||||
struct FIFO32 {
|
||||
@@ -237,12 +237,15 @@ struct CONSOLE {
|
||||
void console_task(struct SHEET *sheet, unsigned int memtotal);
|
||||
void cons_putchar(struct CONSOLE *cons, int chr, char move);
|
||||
void cons_newline(struct CONSOLE *cons);
|
||||
void cons_putstr0(struct CONSOLE *cons, char *s);
|
||||
void cons_putstr1(struct CONSOLE *cons, char *s, int l);
|
||||
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal);
|
||||
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);
|
||||
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
|
||||
void hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
|
||||
|
||||
/* file.c */
|
||||
struct FILEINFO {
|
||||
|
||||
@@ -147,6 +147,23 @@ void cons_newline(struct CONSOLE *cons)
|
||||
return;
|
||||
}
|
||||
|
||||
void cons_putstr0(struct CONSOLE *cons, char *s)
|
||||
{
|
||||
for (; *s != 0; s++) {
|
||||
cons_putchar(cons, *s, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cons_putstr1(struct CONSOLE *cons, char *s, int l)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < l; i++) {
|
||||
cons_putchar(cons, s[i], 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int memtotal)
|
||||
{
|
||||
if (strcmp(cmdline, "mem") == 0) {
|
||||
@@ -160,9 +177,7 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int mem
|
||||
} else if (cmdline[0] != 0) {
|
||||
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);
|
||||
cons_putstr0(cons, "Bad command.\n\n");
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -171,13 +186,9 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, unsigned int mem
|
||||
void cmd_mem(struct CONSOLE *cons, unsigned int memtotal)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
char s[30];
|
||||
sprintf(s, "total %dMB", memtotal / (1024 * 1024));
|
||||
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 30);
|
||||
cons_newline(cons); sprintf(s, "free %dKB", memman_total(memman) / 1024);
|
||||
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 30);
|
||||
cons_newline(cons);
|
||||
cons_newline(cons);
|
||||
char s[60];
|
||||
sprintf(s, "total %dMB\nfree %dKB\n\n", memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
||||
cons_putstr0(cons, s);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -206,15 +217,14 @@ void cmd_dir(struct CONSOLE *cons)
|
||||
}
|
||||
if (finfo[i].name[0] != 0xe5) {
|
||||
if ((finfo[i].type & 0x18) == 0) {
|
||||
sprintf(s, "filename.ext %7d", finfo[i].size);
|
||||
sprintf(s, "filename.ext %7d\n", finfo[i].size);
|
||||
for (j = 0; j < 8; j++) {
|
||||
s[j] = finfo[i].name[j];
|
||||
}
|
||||
s[ 9] = finfo[i].ext[0];
|
||||
s[10] = finfo[i].ext[1];
|
||||
s[11] = finfo[i].ext[2];
|
||||
putfonts8_asc_sht(cons->sht, 8, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 30);
|
||||
cons_newline(cons);
|
||||
cons_putstr0(cons, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,14 +242,11 @@ void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
|
||||
/*找到文件的情况*/
|
||||
p = (char *) memman_alloc_4k(memman, finfo->size);
|
||||
file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
|
||||
for (i = 0; i < finfo->size; i++) {
|
||||
cons_putchar(cons, p[i], 1);
|
||||
}
|
||||
cons_putstr1(cons, p, finfo->size);
|
||||
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);
|
||||
cons_putstr0(cons, "File not found.\n");
|
||||
}
|
||||
cons_newline(cons);
|
||||
return;
|
||||
@@ -287,3 +294,16 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
|
||||
/*没有找到文件的情况*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax)
|
||||
{
|
||||
struct CONSOLE *cons = (struct CONSOLE *) *((int *) 0x0fec);
|
||||
if (edx == 1) {
|
||||
cons_putchar(cons, eax & 0xff, 1);
|
||||
} else if (edx == 2) {
|
||||
cons_putstr0(cons, (char *) ebx);
|
||||
} else if (edx == 3) {
|
||||
cons_putstr1(cons, (char *) ebx, ecx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,7 +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);
|
||||
set_gatedesc(idt + 0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
MOV ECX,msg
|
||||
MOV EDX,1
|
||||
putloop:
|
||||
MOV AL,[CS:ECX]
|
||||
CMP AL,0
|
||||
@@ -9,6 +10,6 @@ putloop:
|
||||
ADD ECX,1
|
||||
JMP putloop
|
||||
fin:
|
||||
RETF
|
||||
RETF
|
||||
msg:
|
||||
DB "hello",0
|
||||
DB "hello",0
|
||||
|
||||
8
20_day/hello2.nas
Normal file
8
20_day/hello2.nas
Normal file
@@ -0,0 +1,8 @@
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
MOV EDX,2
|
||||
MOV EBX,msg
|
||||
INT 0x40
|
||||
RETF
|
||||
msg:
|
||||
DB "hello",0
|
||||
@@ -17,10 +17,10 @@
|
||||
GLOBAL _asm_inthandler27, _asm_inthandler2c
|
||||
GLOBAL _memtest_sub
|
||||
GLOBAL _farjmp, _farcall
|
||||
GLOBAL _asm_cons_putchar
|
||||
GLOBAL _asm_hrb_api
|
||||
EXTERN _inthandler20, _inthandler21
|
||||
EXTERN _inthandler27, _inthandler2c
|
||||
EXTERN _cons_putchar
|
||||
EXTERN _hrb_api
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
@@ -217,14 +217,11 @@ _farcall: ; void farcall(int eip, int cs);
|
||||
CALL FAR [ESP+4] ; eip, cs
|
||||
RET
|
||||
|
||||
_asm_cons_putchar:
|
||||
_asm_hrb_api:
|
||||
STI
|
||||
PUSHAD
|
||||
PUSH 1
|
||||
AND EAX,0xff ; 将AH和EAX的高位置0,将EAX置为已存入字符编码的状态
|
||||
PUSH EAX
|
||||
PUSH DWORD [0x0fec] ; 读取内存并PUSH该值
|
||||
CALL _cons_putchar
|
||||
ADD ESP,12 ; 将栈中的数据丢弃
|
||||
PUSHAD ; 用于保存寄存器值的PUSH
|
||||
PUSHAD ; 用于向hrb_api传值的PUSH
|
||||
CALL _hrb_api
|
||||
ADD ESP,32
|
||||
POPAD
|
||||
IRETD
|
||||
|
||||
Reference in New Issue
Block a user