1/* 2 * Copyright (c) 1998 Robert Nordier 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are freely 6 * permitted provided that the above copyright notice and this 7 * paragraph and the following disclaimer are duplicated in all 8 * such forms. 9 * 10 * This software is provided "AS IS" and without any express or 11 * implied warranties, including, without limitation, the implied 12 * warranties of merchantability and fitness for a particular 13 * purpose. 14 * |
15 * $FreeBSD: head/sys/boot/pc98/btx/btx/btx.S 146011 2005-05-08 14:17:28Z nyan $ |
16 */ 17 18/* 19 * Memory layout. 20 */ 21 .set MEM_BTX,0x1000 # Start of BTX memory 22 .set MEM_ESP0,0x1800 # Supervisor stack 23 .set MEM_BUF,0x1800 # Scratch buffer --- 42 unchanged lines hidden (view full) --- 66 */ 67 .set DMP_X16,0x1 # Word 68 .set DMP_X32,0x2 # Long 69 .set DMP_MEM,0x4 # Memory 70 .set DMP_EOL,0x8 # End of line 71/* 72 * Screen defaults and assumptions. 73 */ |
74 .set SCR_MAT,0xe1 # Mode/attribute |
75 .set SCR_COL,0x50 # Columns per row 76 .set SCR_ROW,0x19 # Rows per screen 77/* 78 * BIOS Data Area locations. 79 */ |
80 .set BDA_MEM,0x501 # Free memory 81 .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags 82 .set BDA_POS,0x53e # Cursor position |
83/* 84 * Derivations, for brevity. 85 */ 86 .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0 87 .set _ESP1H,MEM_ESP1>>0x8 # Byte 1 of ESP1 88 .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base 89 .set _TSSLM,MEM_DIR-MEM_TSS-1 # TSS limit 90 .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit --- 125 unchanged lines hidden (view full) --- 216 movw %cx,%ss # stack 217/* 218 * Launch user task. 219 */ 220 movb $SEL_TSS,%cl # Set task 221 ltr %cx # register 222 movl $MEM_USR,%edx # User base address 223 movzwl %ss:BDA_MEM,%eax # Get free memory |
224 andl $0x7,%eax 225 incl %eax 226 shll $0x11,%eax # To bytes |
227 subl $0x1000,%eax # Less arg space 228 subl %edx,%eax # Less base 229 movb $SEL_UDATA,%cl # User data selector 230 pushl %ecx # Set SS 231 pushl %eax # Set ESP 232 push $0x202 # Set flags (IF set) 233 push $SEL_UCODE # Set CS 234 pushl btx_hdr+0xc # Set EIP --- 46 unchanged lines hidden (view full) --- 281 * To real-address mode. 282 */ 283 dec %ax # Switch to 284 mov %eax,%cr0 # real mode 285 ljmp $0x0,$exit.2 # Reload CS 286exit.2: xor %ax,%ax # Real mode segment 287 mov %ax,%ss # Reload SS 288 mov %ax,%ds # Address data |
289 mov $0x1008,%bx # Set real mode |
290 callw setpic # IRQ offsets 291 lidt ivtdesc # Set IVT 292/* 293 * Reboot or await reset. 294 */ 295 sti # Enable interrupts 296 testb $0x1,btx_hdr+0x7 # Reboot? 297exit.3: jz exit.3 # No |
298 movb $0xa0,%al 299 outb %al,$0x35 300 movb 0,%al 301 outb %al,$0xf0 302exit.4: jmp exit.4 |
303/* 304 * Set IRQ offsets by reprogramming 8259A PICs. 305 */ |
306setpic: in $0x02,%al # Save master 307 push %ax # IMR 308 in $0x0a,%al # Save slave 309 push %ax # IMR 310 movb $0x11,%al # ICW1 to 311 outb %al,$0x00 # master, 312 outb %al,$0x08 # slave 313 movb %bl,%al # ICW2 to --- 7 unchanged lines hidden (view full) --- 321 movb $0x1d,%al # ICW4 to 322 outb %al,$0x02 # master, 323 movb $0x9,%al # ICW4 to 324 outb %al,$0x0a # slave 325 pop %ax # Restore slave 326 outb %al,$0x0a # IMR 327 pop %ax # Restore master 328 outb %al,$0x02 # IMR |
329 retw # To caller 330 .code32 331/* 332 * Initiate return from V86 mode to user mode. 333 */ 334inthlt: hlt # To supervisor mode 335/* 336 * Exception jump table. --- 63 unchanged lines hidden (view full) --- 400 jne except.1 # SS, ESP 401except.2: push $SEL_SDATA # Set up 402 popl %ds # to 403 pushl %ds # address 404 popl %es # data 405 movl %esp,%ebx # Stack frame 406 movl $dmpfmt,%esi # Dump format string 407 movl $MEM_BUF,%edi # Buffer |
408 pushl %eax 409 pushl %edx 410wait.1: 411 inb $0x60,%al 412 testb $0x04,%al 413 jz wait.1 414 movb $0xe0,%al 415 outb %al,$0x62 --- 10 unchanged lines hidden (view full) --- 426 inb $0x62,%al 427 inb $0x62,%al 428 movl %edx,%eax 429 shlw $1,%ax 430 movl $BDA_POS,%edx 431 movw %ax,(%edx) 432 popl %edx 433 popl %eax |
434 pushl %edi # Dump to 435 call dump # buffer 436 popl %esi # and 437 call putstr # display 438 leal 0x18(%esp,1),%esp # Discard frame 439 popa # Restore 440 popl %es # registers 441 popl %ds # saved --- 252 unchanged lines hidden (view full) --- 694 movl 0x1c(%ebp),%eax # user's saved EAX 695 cmpb $0x87,%ah # is it the memcpy subfunction? 696 jne v86intn.1 # no, keep checking 697 popl %eax # get the stack straight 698 jmp int15_87 # it's our cue 699v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout? 700 jne v86intn.2 # no, handle the int normally 701 movb BDA_KEYFLAGS,%al # get the shift key state |
702 andb $0x18,%al # mask off just Ctrl and Alt 703 cmpb $0x18,%al # are both Ctrl and Alt down? |
704 jne v86intn.2 # no, handle the int normally 705 popl %eax # restore EAX 706 jmp reboot # reboot the machine 707v86intn.2: popl %eax # restore EAX 708v86intn.3: subl %edi,%esi # From 709 shrl $0x4,%edi # linear 710 movw %dx,-0x2(%ebx) # Save flags 711 movw %di,-0x4(%ebx) # Save CS --- 20 unchanged lines hidden (view full) --- 732 push $0xc # Int 0x24: IRQ4 733 jmp int_hw # V86 int 0xc 734 push $0xd # Int 0x25: IRQ5 735 jmp int_hw # V86 int 0xd 736 push $0xe # Int 0x26: IRQ6 737 jmp int_hw # V86 int 0xe 738 push $0xf # Int 0x27: IRQ7 739 jmp int_hw # V86 int 0xf |
740 push $0x10 # Int 0x28: IRQ8 741 jmp int_hw # V86 int 0x10 742 push $0x11 # Int 0x29: IRQ9 743 jmp int_hw # V86 int 0x11 744 push $0x12 # Int 0x2a: IRQ10 745 jmp int_hw # V86 int 0x12 746 push $0x13 # Int 0x2b: IRQ11 747 jmp int_hw # V86 int 0x13 748 push $0x14 # Int 0x2c: IRQ12 749 jmp int_hw # V86 int 0x14 750 push $0x15 # Int 0x2d: IRQ13 751 jmp int_hw # V86 int 0x15 752 push $0x16 # Int 0x2e: IRQ14 753 jmp int_hw # V86 int 0x16 754 push $0x17 # Int 0x2f: IRQ15 755 jmp int_hw # V86 int 0x17 |
756/* 757 * Reflect hardware interrupts. 758 */ 759int_hw: testb $0x2,0xe(%esp,1) # V86 mode? 760 jz intusr # No 761 pushl $SEL_SDATA # Address 762 popl %ds # data 763 xchgl %eax,(%esp,1) # Swap EAX, int no --- 318 unchanged lines hidden (view full) --- 1082/* 1083 * Output character AL to the console. 1084 */ 1085putchr: pusha # Save 1086 xorl %ecx,%ecx # Zero for loops 1087 movb $SCR_MAT,%ah # Mode/attribute 1088 movl $BDA_POS,%ebx # BDA pointer 1089 movw (%ebx),%dx # Cursor position |
1090 movl $0xa0000,%edi |
1091putchr.1: cmpb $0xa,%al # New line? 1092 je putchr.2 # Yes |
1093 movw %dx,%cx 1094 movb %al,(%edi,%ecx,1) # Write char 1095 addl $0x2000,%ecx 1096 movb %ah,(%edi,%ecx,1) # Write attr 1097 addw $0x02,%dx 1098 jmp putchr.3 1099putchr.2: movw %dx,%ax 1100 movb $SCR_COL*2,%dl 1101 div %dl 1102 incb %al 1103 mul %dl 1104 movw %ax,%dx 1105putchr.3: cmpw $SCR_ROW*SCR_COL*2,%dx |
1106 jb putchr.4 # No 1107 leal 2*SCR_COL(%edi),%esi # New top line 1108 movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move 1109 rep # Scroll 1110 movsl # screen 1111 movb $0x20,%al # Space |
1112 xorb %ah,%ah |
1113 movb $SCR_COL,%cl # Columns to clear 1114 rep # Clear 1115 stosw # line |
1116 movw $(SCR_ROW-1)*SCR_COL*2,%dx |
1117putchr.4: movw %dx,(%ebx) # Update position 1118 popa # Restore 1119 ret # To caller 1120#endif 1121 1122 .p2align 4 1123/* 1124 * Global descriptor table. --- 81 unchanged lines hidden --- |