相关文章:
- 2005-09-08
- 2006-05-22
- 2006-06-27
- 2005-03-19
- 2004-07-13
本文共 6847 字,大约阅读时间需要 22 分钟。
; ; entry.asm ; Copyright (C) 2004, Tian XiangYuan ; .MODEL TINY,C .386p option expr32 option casemap:none cmain PROTO NEAR C .CODE ORG 0100h ;偏移地址 _start: jmp begin nop DB 'TianXiangYuan',0 ;the magic of my os begin: cli mov ax,cs mov ds,ax mov es,ax mov ss,ax mov sp,0FFFFh sti call cmain ;调用C语言写的主函数 mov ax,4c00h ;调用DOS的功能(为了调试),与我们自己的操作系统无关 int 21h |
…… static void InitShell() { } void cmain() { InitShell(); TermShell(); } |
/* *从键盘读一个字符,如果没有输入,则等待;返回值的低字节为asii码,高字节为键盘扫描码 */ static int getch() { int chr=0; __asm { mov ah,00h int 16h mov chr,ax } return chr; } /* *使用TTY模式向屏幕输出一个字符 */ static void putch(unsigned char key) { __asm { mov bh,0 mov al,key mov ah,0Eh int 10h } } #define KEY_BACKSPACE 0x08 #define KEY_ENTER 0x0D #define KEY_NEWLINE 0x0A #define KEY_ESCAPE 0x1B static int printk(const char* str,...) { …… //给大家一点空间,自己实现吧 } static void endline() { putch(KEY_NEWLINE); //Line Feed (LF) putch(KEY_ENTER); //Enter (CR) } static char msg_prompt[]="CMD:"; static void deal_cmd(char* cmd_line,int cmd_len) { …… //也请大家自己实现吧,例如,可以实现help,dir,cls,halt等命令 …… //其实,就是字符串比较的过程 } static void TermShell() { char cmd_line[80]={0,}; int cmd_len=0; endline(); printk(msg_prompt,sizeof(msg_prompt)); for (;;) { cmd_line[cmd_len]=getch(); switch(cmd_line[cmd_len]) { case KEY_ENTER: if (cmd_len>1) deal_cmd(cmd_line,cmd_len); //break; case KEY_ESCAPE: cmd_len=0; endline(); printk(msg_prompt,sizeof(msg_prompt)); break; case KEY_BACKSPACE: if (cmd_len>0) { putch(0x08); putch(' '); putch(0x08); cmd_len--; } break; default: putch(cmd_line[cmd_len]); cmd_len++; } } } |
@echo off set PATH=e:/masm615/bin;e:/msvc15/bin; set AS=e:/masm615/bin/ml.exe set AFLAGS=/AT /W3 /X /Gd /Zp1 /nologo set CC=e:/msvc15/bin/cl.exe set CFLAGS=/Od /G3 /Gd /Gs /Zl /Zp1 /X /W3 /nologo del *.obj *.com *.cod *.dbg *.pdb *.map *.lst %AS% /c %AFLAGS% entry.asm if errorlevel 1 goto error %CC% /c %CFLAGS% /Fc main.c if errorlevel 1 goto error %AS% %AFLAGS% /Fe"boot.com" entry.obj main.obj if errorlevel 1 goto error goto exit :error echo Failure...... :exit pause @echo on |
; ; bootsect.asm ; Copyright(C) 2004, Tian XiangYuan ; .MODEL TINY,C .386p option expr32 option casemap:none SYSSEG EQU 1000h SYSOFF EQU 0100h .CODE ORG 7C00h _start: jmp begin nop DB 'BOOTSECT',0 ;magic pack_size DB 16 DB 0 ;reserved DW 60 ;sectors DW SYSOFF ;buf_addr_off DW SYSSEG ;buf_addr_seg DD 2 ;sector_from DD 0 ;sector_from_high begin: cli mov ax,cs mov ds,ax mov es,ax mov ss,ax mov sp,0FFFFh sti mov cx,msg_load_len ;length lea bp,msg_load ;es:bp call display_msg ; read disk for my OS lea si,pack_size mov dl,80h mov ax,4200h int 13h ;使用LBA方式读硬盘 jc error ; test magic of my os lea si,magic_test ;ds:si mov ax,SYSSEG mov es,ax mov di,SYSOFF add di,3 ;es:di mov cx,magic_test_len cld test_again: cmpsb jnz error loop test_again push SYSSEG push SYSOFF retf ;转入操作系统执行 error: mov ax,cs mov es,ax lea bp,msg_error ;es:bp mov cx,msg_error_len call display_msg failure: hlt jmp failure ;cx : length of message ;es:bp : address of message ;void display_msg(); display_msg PROC NEAR C ;scrollup a line push cx push bp mov ax,0601h mov bh,07h mov cx,0000h ;y/x mov dx,184Fh ;y2/x2, 24/79 int 10h pop bp pop cx ;display message mov ax,1301h mov bx,000Ah ;mov cx,msg_error_len mov dl,0 ;x mov dh,24 ;y ;lea bp,msg_error ;es:bp int 10h ret display_msg endp .DATA msg_load DB 'Loading......',0 msg_load_len DW $ - msg_load msg_error DB 'NO BOOTER,please reboot!',0 msg_error_len DW $ - msg_error magic_test DB 'TianXiangYuan',0 magic_test_len DW $ - magic_test end _start |
@echo off set PATH=e:/masm615/bin; set AS=e:/masm615/bin/ml.exe set AFLAGS=/AT /W3 /WX /Gd /Zp1 /X /nologo del *.obj *.com *.cod *.dbg *.pdb *.map %AS% /c %AFLAGS% bootsect.asm if errorlevel 1 goto error %AS% %AFLAGS% /Fe"bootsect.com" bootsect.obj if errorlevel 1 goto error goto exit :error echo Failure...... :exit pause @echo on |
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1302127