btx.S (138189) | btx.S (146011) |
---|---|
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 * | 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 138189 2004-11-29 11:54:42Z nyan $ | 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 */ | 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#ifdef PC98 | |
75 .set SCR_MAT,0xe1 # Mode/attribute | 74 .set SCR_MAT,0xe1 # Mode/attribute |
76#else 77 .set SCR_MAT,0x7 # Mode/attribute 78#endif | |
79 .set SCR_COL,0x50 # Columns per row 80 .set SCR_ROW,0x19 # Rows per screen 81/* 82 * BIOS Data Area locations. 83 */ | 75 .set SCR_COL,0x50 # Columns per row 76 .set SCR_ROW,0x19 # Rows per screen 77/* 78 * BIOS Data Area locations. 79 */ |
84#ifdef PC98 | |
85 .set BDA_MEM,0x501 # Free memory 86 .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags 87 .set BDA_POS,0x53e # Cursor position | 80 .set BDA_MEM,0x501 # Free memory 81 .set BDA_KEYFLAGS,0x53a # Keyboard shift-state flags 82 .set BDA_POS,0x53e # Cursor position |
88#else 89 .set BDA_MEM,0x413 # Free memory 90 .set BDA_KEYFLAGS,0x417 # Keyboard shift-state flags 91 .set BDA_SCR,0x449 # Video mode 92 .set BDA_POS,0x450 # Cursor position 93 .set BDA_BOOT,0x472 # Boot howto flag 94#endif | |
95/* 96 * Derivations, for brevity. 97 */ 98 .set _ESP0H,MEM_ESP0>>0x8 # Byte 1 of ESP0 99 .set _ESP1H,MEM_ESP1>>0x8 # Byte 1 of ESP1 100 .set _TSSIO,MEM_MAP-MEM_TSS # TSS I/O base 101 .set _TSSLM,MEM_DIR-MEM_TSS-1 # TSS limit 102 .set _IDTLM,MEM_TSS-MEM_IDT-1 # IDT limit --- 125 unchanged lines hidden (view full) --- 228 movw %cx,%ss # stack 229/* 230 * Launch user task. 231 */ 232 movb $SEL_TSS,%cl # Set task 233 ltr %cx # register 234 movl $MEM_USR,%edx # User base address 235 movzwl %ss:BDA_MEM,%eax # Get free memory | 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 |
236#ifdef PC98 | |
237 andl $0x7,%eax 238 incl %eax 239 shll $0x11,%eax # To bytes | 224 andl $0x7,%eax 225 incl %eax 226 shll $0x11,%eax # To bytes |
240#else 241 shll $0xa,%eax # To bytes 242#endif | |
243 subl $0x1000,%eax # Less arg space 244 subl %edx,%eax # Less base 245 movb $SEL_UDATA,%cl # User data selector 246 pushl %ecx # Set SS 247 pushl %eax # Set ESP 248 push $0x202 # Set flags (IF set) 249 push $SEL_UCODE # Set CS 250 pushl btx_hdr+0xc # Set EIP --- 46 unchanged lines hidden (view full) --- 297 * To real-address mode. 298 */ 299 dec %ax # Switch to 300 mov %eax,%cr0 # real mode 301 ljmp $0x0,$exit.2 # Reload CS 302exit.2: xor %ax,%ax # Real mode segment 303 mov %ax,%ss # Reload SS 304 mov %ax,%ds # Address data | 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 |
305#ifdef PC98 | |
306 mov $0x1008,%bx # Set real mode | 289 mov $0x1008,%bx # Set real mode |
307#else 308 mov $0x7008,%bx # Set real mode 309#endif | |
310 callw setpic # IRQ offsets 311 lidt ivtdesc # Set IVT 312/* 313 * Reboot or await reset. 314 */ 315 sti # Enable interrupts 316 testb $0x1,btx_hdr+0x7 # Reboot? 317exit.3: jz exit.3 # No | 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 |
318#ifdef PC98 | |
319 movb $0xa0,%al 320 outb %al,$0x35 321 movb 0,%al 322 outb %al,$0xf0 323exit.4: jmp exit.4 | 298 movb $0xa0,%al 299 outb %al,$0x35 300 movb 0,%al 301 outb %al,$0xf0 302exit.4: jmp exit.4 |
324#else 325 movw $0x1234, BDA_BOOT # Do a warm boot 326 ljmp $0xf000,$0xfff0 # reboot the machine 327#endif | |
328/* 329 * Set IRQ offsets by reprogramming 8259A PICs. 330 */ | 303/* 304 * Set IRQ offsets by reprogramming 8259A PICs. 305 */ |
331#ifdef PC98 | |
332setpic: in $0x02,%al # Save master 333 push %ax # IMR 334 in $0x0a,%al # Save slave 335 push %ax # IMR 336 movb $0x11,%al # ICW1 to 337 outb %al,$0x00 # master, 338 outb %al,$0x08 # slave 339 movb %bl,%al # ICW2 to --- 7 unchanged lines hidden (view full) --- 347 movb $0x1d,%al # ICW4 to 348 outb %al,$0x02 # master, 349 movb $0x9,%al # ICW4 to 350 outb %al,$0x0a # slave 351 pop %ax # Restore slave 352 outb %al,$0x0a # IMR 353 pop %ax # Restore master 354 outb %al,$0x02 # IMR | 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 |
355#else 356setpic: in $0x21,%al # Save master 357 push %ax # IMR 358 in $0xa1,%al # Save slave 359 push %ax # IMR 360 movb $0x11,%al # ICW1 to 361 outb %al,$0x20 # master, 362 outb %al,$0xa0 # slave 363 movb %bl,%al # ICW2 to 364 outb %al,$0x21 # master 365 movb %bh,%al # ICW2 to 366 outb %al,$0xa1 # slave 367 movb $0x4,%al # ICW3 to 368 outb %al,$0x21 # master 369 movb $0x2,%al # ICW3 to 370 outb %al,$0xa1 # slave 371 movb $0x1,%al # ICW4 to 372 outb %al,$0x21 # master, 373 outb %al,$0xa1 # slave 374 pop %ax # Restore slave 375 outb %al,$0xa1 # IMR 376 pop %ax # Restore master 377 outb %al,$0x21 # IMR 378#endif | |
379 retw # To caller 380 .code32 381/* 382 * Initiate return from V86 mode to user mode. 383 */ 384inthlt: hlt # To supervisor mode 385/* 386 * Exception jump table. --- 63 unchanged lines hidden (view full) --- 450 jne except.1 # SS, ESP 451except.2: push $SEL_SDATA # Set up 452 popl %ds # to 453 pushl %ds # address 454 popl %es # data 455 movl %esp,%ebx # Stack frame 456 movl $dmpfmt,%esi # Dump format string 457 movl $MEM_BUF,%edi # Buffer | 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 |
458#ifdef PC98 | |
459 pushl %eax 460 pushl %edx 461wait.1: 462 inb $0x60,%al 463 testb $0x04,%al 464 jz wait.1 465 movb $0xe0,%al 466 outb %al,$0x62 --- 10 unchanged lines hidden (view full) --- 477 inb $0x62,%al 478 inb $0x62,%al 479 movl %edx,%eax 480 shlw $1,%ax 481 movl $BDA_POS,%edx 482 movw %ax,(%edx) 483 popl %edx 484 popl %eax | 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 |
485#endif | |
486 pushl %edi # Dump to 487 call dump # buffer 488 popl %esi # and 489 call putstr # display 490 leal 0x18(%esp,1),%esp # Discard frame 491 popa # Restore 492 popl %es # registers 493 popl %ds # saved --- 252 unchanged lines hidden (view full) --- 746 movl 0x1c(%ebp),%eax # user's saved EAX 747 cmpb $0x87,%ah # is it the memcpy subfunction? 748 jne v86intn.1 # no, keep checking 749 popl %eax # get the stack straight 750 jmp int15_87 # it's our cue 751v86intn.1: cmpw $0x4f53,%ax # is it the delete key callout? 752 jne v86intn.2 # no, handle the int normally 753 movb BDA_KEYFLAGS,%al # get the shift key state | 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 |
754#ifdef PC98 | |
755 andb $0x18,%al # mask off just Ctrl and Alt 756 cmpb $0x18,%al # are both Ctrl and Alt down? | 702 andb $0x18,%al # mask off just Ctrl and Alt 703 cmpb $0x18,%al # are both Ctrl and Alt down? |
757#else 758 andb $0xc,%al # mask off just Ctrl and Alt 759 cmpb $0xc,%al # are both Ctrl and Alt down? 760#endif | |
761 jne v86intn.2 # no, handle the int normally 762 popl %eax # restore EAX 763 jmp reboot # reboot the machine 764v86intn.2: popl %eax # restore EAX 765v86intn.3: subl %edi,%esi # From 766 shrl $0x4,%edi # linear 767 movw %dx,-0x2(%ebx) # Save flags 768 movw %di,-0x4(%ebx) # Save CS --- 20 unchanged lines hidden (view full) --- 789 push $0xc # Int 0x24: IRQ4 790 jmp int_hw # V86 int 0xc 791 push $0xd # Int 0x25: IRQ5 792 jmp int_hw # V86 int 0xd 793 push $0xe # Int 0x26: IRQ6 794 jmp int_hw # V86 int 0xe 795 push $0xf # Int 0x27: IRQ7 796 jmp int_hw # V86 int 0xf | 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 |
797#ifdef PC98 | |
798 push $0x10 # Int 0x28: IRQ8 799 jmp int_hw # V86 int 0x10 800 push $0x11 # Int 0x29: IRQ9 801 jmp int_hw # V86 int 0x11 802 push $0x12 # Int 0x2a: IRQ10 803 jmp int_hw # V86 int 0x12 804 push $0x13 # Int 0x2b: IRQ11 805 jmp int_hw # V86 int 0x13 806 push $0x14 # Int 0x2c: IRQ12 807 jmp int_hw # V86 int 0x14 808 push $0x15 # Int 0x2d: IRQ13 809 jmp int_hw # V86 int 0x15 810 push $0x16 # Int 0x2e: IRQ14 811 jmp int_hw # V86 int 0x16 812 push $0x17 # Int 0x2f: IRQ15 813 jmp int_hw # V86 int 0x17 | 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 |
814#else 815 push $0x70 # Int 0x28: IRQ8 816 jmp int_hw # V86 int 0x70 817 push $0x71 # Int 0x29: IRQ9 818 jmp int_hw # V86 int 0x71 819 push $0x72 # Int 0x2a: IRQ10 820 jmp int_hw # V86 int 0x72 821 push $0x73 # Int 0x2b: IRQ11 822 jmp int_hw # V86 int 0x73 823 push $0x74 # Int 0x2c: IRQ12 824 jmp int_hw # V86 int 0x74 825 push $0x75 # Int 0x2d: IRQ13 826 jmp int_hw # V86 int 0x75 827 push $0x76 # Int 0x2e: IRQ14 828 jmp int_hw # V86 int 0x76 829 push $0x77 # Int 0x2f: IRQ15 830 jmp int_hw # V86 int 0x77 831#endif | |
832/* 833 * Reflect hardware interrupts. 834 */ 835int_hw: testb $0x2,0xe(%esp,1) # V86 mode? 836 jz intusr # No 837 pushl $SEL_SDATA # Address 838 popl %ds # data 839 xchgl %eax,(%esp,1) # Swap EAX, int no --- 318 unchanged lines hidden (view full) --- 1158/* 1159 * Output character AL to the console. 1160 */ 1161putchr: pusha # Save 1162 xorl %ecx,%ecx # Zero for loops 1163 movb $SCR_MAT,%ah # Mode/attribute 1164 movl $BDA_POS,%ebx # BDA pointer 1165 movw (%ebx),%dx # Cursor position | 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 |
1166#ifdef PC98 | |
1167 movl $0xa0000,%edi | 1090 movl $0xa0000,%edi |
1168#else 1169 movl $0xb8000,%edi # Regen buffer (color) 1170 cmpb %ah,BDA_SCR-BDA_POS(%ebx) # Mono mode? 1171 jne putchr.1 # No 1172 xorw %di,%di # Regen buffer (mono) 1173#endif | |
1174putchr.1: cmpb $0xa,%al # New line? 1175 je putchr.2 # Yes | 1091putchr.1: cmpb $0xa,%al # New line? 1092 je putchr.2 # Yes |
1176#ifdef PC98 | |
1177 movw %dx,%cx 1178 movb %al,(%edi,%ecx,1) # Write char 1179 addl $0x2000,%ecx 1180 movb %ah,(%edi,%ecx,1) # Write attr 1181 addw $0x02,%dx 1182 jmp putchr.3 1183putchr.2: movw %dx,%ax 1184 movb $SCR_COL*2,%dl 1185 div %dl 1186 incb %al 1187 mul %dl 1188 movw %ax,%dx 1189putchr.3: cmpw $SCR_ROW*SCR_COL*2,%dx | 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 |
1190#else 1191 xchgl %eax,%ecx # Save char 1192 movb $SCR_COL,%al # Columns per row 1193 mulb %dh # * row position 1194 addb %dl,%al # + column 1195 adcb $0x0,%ah # position 1196 shll %eax # * 2 1197 xchgl %eax,%ecx # Swap char, offset 1198 movw %ax,(%edi,%ecx,1) # Write attr:char 1199 incl %edx # Bump cursor 1200 cmpb $SCR_COL,%dl # Beyond row? 1201 jb putchr.3 # No 1202putchr.2: xorb %dl,%dl # Zero column 1203 incb %dh # Bump row 1204putchr.3: cmpb $SCR_ROW,%dh # Beyond screen? 1205#endif | |
1206 jb putchr.4 # No 1207 leal 2*SCR_COL(%edi),%esi # New top line 1208 movw $(SCR_ROW-1)*SCR_COL/2,%cx # Words to move 1209 rep # Scroll 1210 movsl # screen 1211 movb $0x20,%al # Space | 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 |
1212#ifdef PC98 | |
1213 xorb %ah,%ah | 1112 xorb %ah,%ah |
1214#endif | |
1215 movb $SCR_COL,%cl # Columns to clear 1216 rep # Clear 1217 stosw # line | 1113 movb $SCR_COL,%cl # Columns to clear 1114 rep # Clear 1115 stosw # line |
1218#ifdef PC98 | |
1219 movw $(SCR_ROW-1)*SCR_COL*2,%dx | 1116 movw $(SCR_ROW-1)*SCR_COL*2,%dx |
1220#else 1221 movb $SCR_ROW-1,%dh # Bottom line 1222#endif | |
1223putchr.4: movw %dx,(%ebx) # Update position 1224 popa # Restore 1225 ret # To caller 1226#endif 1227 1228 .p2align 4 1229/* 1230 * Global descriptor table. --- 81 unchanged lines hidden --- | 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 --- |