mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-05 02:53:19 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b33125f047 | ||
|
|
4d0e2f1af1 | ||
|
|
2fb28adf44 | ||
|
|
ff3319e083 | ||
|
|
984b2886d0 | ||
|
|
a381fbedc3 |
@@ -46,19 +46,23 @@ 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
|
||||
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:hlt.hrb to:@: \
|
||||
copy from:hello.hrb to:@: \
|
||||
copy from:hello2.hrb to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
# 其他指令
|
||||
|
||||
@@ -30,7 +30,8 @@ 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 asm_cons_putchar(void);
|
||||
void farcall(int eip, int cs);
|
||||
void asm_hrb_api(void);
|
||||
|
||||
/* fifo.c */
|
||||
struct FIFO32 {
|
||||
@@ -236,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);
|
||||
void cmd_hlt(struct CONSOLE *cons, int *fat);
|
||||
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) {
|
||||
@@ -157,13 +174,11 @@ 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) {
|
||||
/*不是命令,不是应用程序,也不是空行*/
|
||||
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,37 +242,68 @@ 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
/*没有找到文件的情况*/
|
||||
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);
|
||||
}
|
||||
cons_newline(cons);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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_hrb_api, 2 * 8, AR_INTGATE32);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
15
20_day/hello.nas
Normal file
15
20_day/hello.nas
Normal file
@@ -0,0 +1,15 @@
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
MOV ECX,msg
|
||||
MOV EDX,1
|
||||
putloop:
|
||||
MOV AL,[CS:ECX]
|
||||
CMP AL,0
|
||||
JE fin
|
||||
INT 0x40
|
||||
ADD ECX,1
|
||||
JMP putloop
|
||||
fin:
|
||||
RETF
|
||||
msg:
|
||||
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
|
||||
@@ -1,6 +0,0 @@
|
||||
[BITS 32]
|
||||
MOV AL,'A'
|
||||
CALL 0xbe3
|
||||
fin:
|
||||
HLT
|
||||
JMP fin
|
||||
@@ -16,11 +16,11 @@
|
||||
GLOBAL _asm_inthandler20, _asm_inthandler21
|
||||
GLOBAL _asm_inthandler27, _asm_inthandler2c
|
||||
GLOBAL _memtest_sub
|
||||
GLOBAL _farjmp
|
||||
GLOBAL _asm_cons_putchar
|
||||
GLOBAL _farjmp, _farcall
|
||||
GLOBAL _asm_hrb_api
|
||||
EXTERN _inthandler20, _inthandler21
|
||||
EXTERN _inthandler27, _inthandler2c
|
||||
EXTERN _cons_putchar
|
||||
EXTERN _hrb_api
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
@@ -213,11 +213,15 @@ _farjmp: ; void farjmp(int eip, int cs);
|
||||
JMP FAR [ESP+4] ; eip, cs
|
||||
RET
|
||||
|
||||
_asm_cons_putchar:
|
||||
PUSH 1
|
||||
AND EAX,0xff ; 将AH和EAX的高位置0,将EAX置为已存入字符编码的状态
|
||||
PUSH EAX
|
||||
PUSH DWORD [0x0fec] ; 读取内存并PUSH该值
|
||||
CALL _cons_putchar
|
||||
ADD ESP,12 ; 将栈中的数据丢弃
|
||||
_farcall: ; void farcall(int eip, int cs);
|
||||
CALL FAR [ESP+4] ; eip, cs
|
||||
RET
|
||||
|
||||
_asm_hrb_api:
|
||||
STI
|
||||
PUSHAD ; 用于保存寄存器值的PUSH
|
||||
PUSHAD ; 用于向hrb_api传值的PUSH
|
||||
CALL _hrb_api
|
||||
ADD ESP,32
|
||||
POPAD
|
||||
IRETD
|
||||
|
||||
Reference in New Issue
Block a user