📄 startmenu.s
字号:
BIOS call "INT 10H Function 03h" to get cursor position Call with %ah = 0x03 %bh = page Returns %ch = starting scan line %cl = ending scan line %dh = row (0 is top) %dl = column (0 is left)**************************************************************************/ .globl console_getxyconsole_getxy: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL xorb %bh, %bh /* set page to 0 */ movb $0x3, %ah int $0x10 /* get cursor position */ DO_REAL_RETURN xor %eax, %eax movb %dl, %ah movb %dh, %al popl %edi popl %esi popl %ebx ret/**************************************************************************console_gotoxy(x,y)BIOS call "INT 10H Function 02h" to set cursor position Call with %ah = 0x02 %bh = page %dh = row (0 is top) %dl = column (0 is left)**************************************************************************/ .globl console_gotoxyconsole_gotoxy: pushl %ebp movl %esp,%ebp pushl %ebx pushl %esi pushl %edi movb 0x8(%ebp), %dl /* %dl = x */ movb 0xC(%ebp), %dh /* %dh = y */ DO_REAL_CALL xorb %bh, %bh /* set page to 0 */ movb $0x2, %ah int $0x10 /* set cursor position */ DO_REAL_RETURN popl %edi popl %esi popl %ebx popl %ebp ret/************************************************************************** * console_setattrib(attr) : Sets the character attributes for character at * current cursor position. * * Bitfields for character's display attribute: * Bit(s) Description * 7 foreground blink * 6-4 background color * 3 foreground bright * 2-0 foreground color * * Values for character color: * Normal Bright * 000b black dark gray * 001b blue light blue * 010b green light green * 011b cyan light cyan * 100b red light red * 101b magenta light magenta * 110b brown yellow * 111b light gray white * * BIOS call "INT 10H Function 08h" to read character and attribute data * Call with %ah = 0x08 * %bh = page * Returns %ah = character attribute * %al = character value * BIOS call "INT 10H Function 09h" to write character and attribute data * Call with %ah = 0x09 * %al = character value * %bh = page * %bl = character attribute * %cx = count to display (???, possible side-effects!!)**************************************************************************/ .globl console_setattribconsole_setattrib: pushl %ebp movl %esp,%ebp pushl %ebx pushl %esi pushl %edi movl 0x8(%ebp), %ecx xorl %ebx, %ebx DO_REAL_CALL movb $0x8, %ah int $0x10 movb $0x9, %ah movb %cl, %bl movw $1, %cx int $0x10 DO_REAL_RETURN popl %edi popl %esi popl %ebx popl %ebp ret/**************************************************************************CONSOLE_PUTC - Print a character on console**************************************************************************/ .globl console_putcconsole_putc: pushl %ebp movl %esp,%ebp pushl %ebx pushl %esi pushl %edi movb 8(%ebp),%cl DO_REAL_CALL movl $1,%ebx movb $0x0e,%ah movb %cl,%al int $0x10 DO_REAL_RETURN popl %edi popl %esi popl %ebx popl %ebp ret/**************************************************************************CONSOLE_GETC - Get a character from console **************************************************************************/ .globl console_getcconsole_getc: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL movb $0x0,%ah int $0x16 movb %al,%bl DO_REAL_RETURN xor %eax,%eax movzbl %bl,%eax popl %edi popl %esi popl %ebx ret/**************************************************************************console_getkey()BIOS call "INT 16H Function 00H" to read character from keyboardCall with %ah = 0x10Return: %ah = keyboard scan code %al = ASCII character **************************************************************************/ .globl console_getkeyconsole_getkey: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL movb $0x0,%ah int $0x16 movw %ax, %bx DO_REAL_RETURN movzwl %bx, %eax popl %edi popl %esi popl %ebx ret/**************************************************************************console_checkkey()if there is a character pending, return it; otherwise return -1BIOS call "INT 16H Function 01H" to check whether a character is pendingCall with %ah = 0x1Return: If key waiting to be input: %ah = keyboard scan code %al = ASCII character Zero flag = clear else Zero flag = set **************************************************************************/ .globl console_checkkeyconsole_checkkey: pushl %ebx pushl %esi pushl %edi xorl %ebx, %ebx DO_REAL_CALL movb $0x1, %ah int $0x16 jz 1f movw %ax, %bx jmp 2f1: movl $0xFFFFFFFF, %ebx2: DO_REAL_RETURN movzwl %bx, %eax popl %edi popl %esi popl %ebx ret/**************************************************************************ISCHAR - Check for keyboard interrupt**************************************************************************/ .globl console_ischarconsole_ischar: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL xorw %bx,%bx movb $0x1,%ah int $0x16 jz 2f movb %al,%bl2: DO_REAL_RETURN movzbl %bl,%eax popl %edi popl %esi popl %ebx ret/**************************************************************************GETSHIFT - Get keyboard shift state**************************************************************************/ .globl console_getshiftconsole_getshift: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL movb $2,%ah int $0x16 andb $0xdf,%al movw %ax,%bx DO_REAL_RETURN movzbl %bl,%eax popl %edi popl %esi popl %ebx ret/**************************************************************************INT10 - Call Interrupt 0x10**************************************************************************/ .globl _int10_int10: push %ebp mov %esp,%ebp push %ebx push %esi push %edi movw 8(%ebp),%si movw 10(%ebp),%bx movw 12(%ebp),%cx movw 14(%ebp),%dx DO_REAL_CALL movw %si,%ax int $0x10 movw %ax,%si DO_REAL_RETURN movl %esi,%eax andl $0xFFFF,%eax movw %ax,int10ret movw %bx,int10ret+2 shl $16,%ebx orl %ebx,%eax movw %cx,int10ret+4 movw %dx,int10ret+6 pop %edi pop %esi pop %ebx pop %ebp ret .globl int10retint10ret: .word 0,0,0,0/**************************************************************************CPU_NAP - Save power by halting the CPU until the next interrupt**************************************************************************/ .globl cpu_napcpu_nap: pushl %ebx pushl %esi pushl %edi DO_REAL_CALL hlt DO_REAL_RETURN popl %edi popl %esi popl %ebx ret/**************************************************************************SETJMP - Save stack context for non-local goto**************************************************************************/ .globl setjmpsetjmp: movl 4(%esp),%ecx movl 0(%esp),%edx movl %edx,0(%ecx) movl %ebx,4(%ecx) movl %esp,8(%ecx) movl %ebp,12(%ecx) movl %esi,16(%ecx) movl %edi,20(%ecx) movl %eax,24(%ecx) movl $0,%eax ret/**************************************************************************LONGJMP - Non-local jump to a saved stack context**************************************************************************/ .globl longjmplongjmp: movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx movl 4(%edx),%ebx movl 8(%edx),%esp movl 12(%edx),%ebp movl 16(%edx),%esi movl 20(%edx),%edi cmpl $0,%eax jne 1f movl $1,%eax1: movl %ecx,0(%esp) ret/**************************************************************************GLOBAL DESCRIPTOR TABLE**************************************************************************/ .align 4_gdt:gdtarg: .word 0x27 /* limit */ .long _gdt /* addr */ .byte 0,0_pmcs: /* 32 bit protected mode code segment */ .word 0xffff,0 .byte 0,0x9f,0xcf,0_pmds: /* 32 bit protected mode data segment */ .word 0xffff,0 .byte 0,0x93,0xcf,0_rmcs: /* 16 bit real mode code segment */ .word 0xffff,(0&0xffff) .byte (0>>16),0x9b,0x00,(0>>24)_rmds: /* 16 bit real mode data segment */ .word 0xffff,(0&0xffff) .byte (0>>16),0x93,0x00,(0>>24)_gdt_end:gdtsave: .long 0,0,0 /* previous GDT */virt_offset: .long 0initsp: .long 0days: .long 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -