Changeset 60291 in vbox for trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm
- Timestamp:
- Apr 1, 2016 8:51:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm
r60218 r60291 41 41 TMPL_BEGIN_TEXT 42 42 43 %if TMPL_BITS == 3244 43 BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32 45 %endif46 44 BS3_EXTERN_CMN Bs3RegCtxConvertToRingX 47 45 BS3_EXTERN_CMN Bs3RegCtxRestore 48 46 BS3_EXTERN_CMN Bs3Panic 47 48 BS3_BEGIN_TEXT16 49 extern Bs3PrintStrN_c16_CX_Bytes_At_DS_SI 49 50 TMPL_BEGIN_TEXT 50 51 … … 73 74 %define VAR_CALLER_DS [xBP - xCB] 74 75 %endif 75 %define VAR_CALLER_BX [xBP - sCB*1 - xCB] 76 %define VAR_CALLER_BX [xBP - sCB*1 - xCB] ; Note! the upper word is not clean on pre-386 (16-bit mode). 76 77 %define VAR_CALLER_AX [xBP - sCB*2 - xCB] 77 78 %define VAR_CALLER_CX [xBP - sCB*3 - xCB] 78 79 %define VAR_CALLER_DX [xBP - sCB*4 - xCB] 79 80 %define VAR_CALLER_SI [xBP - sCB*5 - xCB] 81 %define VAR_CALLER_SI_HI [xBP - sCB*5 - xCB + 2] 80 82 %define VAR_CALLER_DI [xBP - sCB*6 - xCB] 83 %define VAR_CALLER_DI_HI [xBP - sCB*6 - xCB + 2] 81 84 %if TMPL_BITS == 16 82 85 %define VAR_CALLER_EBP [xBP - sCB*7 - xCB] … … 84 87 %define VAR_CALLER_EFLAGS [xBP - sCB*9 - xCB] 85 88 %define VAR_CALLER_MODE [xBP - sCB*9 - xCB*2] 89 %define BP_TOP_STACK_EXPR xBP - sCB*9 - xCB*2 86 90 %else 87 91 %define VAR_CALLER_MODE [xBP - sCB*6 - xCB*2] 92 %define BP_TOP_STACK_EXPR xBP - sCB*6 - xCB*2 88 93 %endif 89 94 push xBP … … 122 127 push bx ; dummy 123 128 push bx 124 push ax ; dummy 129 xor bx, bx 130 push bx ; dummy 125 131 push ax 126 push cx ; dummy132 push bx ; dummy 127 133 push cx 128 push dx ; dummy134 push bx ; dummy 129 135 push dx 130 push si; dummy136 push bx ; dummy 131 137 push si 132 push di; dummy138 push bx ; dummy 133 139 push di 134 140 sub sp, 0ch ; dummy … … 167 173 dw .to_ringX wrt BS3TEXT16 168 174 dw .to_ringX wrt BS3TEXT16 175 dw .restore_ctx wrt BS3TEXT16 169 176 %else 170 177 dd .invalid_syscall wrt FLAT … … 175 182 dd .to_ringX wrt FLAT 176 183 dd .to_ringX wrt FLAT 184 dd .restore_ctx wrt FLAT 177 185 %endif 178 186 … … 238 246 239 247 ; 240 ; Print CX chars from string pointed to by DX:SI in 16-bit and v8086 mode, 241 ; and ESI/RSI in 64-bit and 32-bit mode (flat). 248 ; Prints DX chars from the string pointed to by CX:xSI to the screen. 242 249 ; 243 250 ; We use the vga bios teletype interrupt to do the writing, so we must 244 ; be in some kind of real mode for this to work. 16-bit code segment245 ; requried for the mode switching code.251 ; be in some kind of real mode for this to work. The string must be 252 ; accessible from real mode too. 246 253 ; 247 254 .print_str: 248 ;;%if TMPL_BITS != 64 249 ;; mov bl, byte VAR_CALLER_MODE 250 ;; and bl, BS3_MODE_CODE_MASK 251 ;; cmp bl, BS3_MODE_CODE_V86 252 ;; jne .print_str_not_v8086 253 ;; ;; @todo this gets complicated _fast_. Later. 254 ;;.print_str_not_v8086: 255 ;;%endif 256 int3 255 %if TMPL_BITS != 64 256 push es 257 %endif 258 ; Convert the incoming pointer to real mode (assuming caller checked 259 ; that real mode can access it). 260 call .convert_ptr_arg_to_real_mode_ax_si 261 mov cx, VAR_CALLER_DX 262 263 ; Switch to real mode (no 20h scratch required) 264 %ifndef TMPL_CMN_R86 265 %if TMPL_BITS != 16 266 jmp .print_str_to_16bit 267 BS3_BEGIN_TEXT16 268 .print_str_to_16bit: 269 BS3_SET_BITS TMPL_BITS 270 %endif 271 extern TMPL_NM(Bs3SwitchToRM) 272 call TMPL_NM(Bs3SwitchToRM) 273 BS3_SET_BITS 16 274 %endif 275 ; Call code in Bs3PrintStrN to do the work. 276 mov ds, ax 277 call Bs3PrintStrN_c16_CX_Bytes_At_DS_SI 278 279 ; Switch back (20h param scratch area not required). 280 %ifndef TMPL_CMN_R86 281 extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_rm) 282 call RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_rm) 283 %if TMPL_BITS != 16 284 BS3_SET_BITS TMPL_BITS 285 jmp .print_str_end 286 TMPL_BEGIN_TEXT 287 %endif 288 .print_str_end: 289 %endif 290 %if TMPL_BITS != 64 291 pop es 292 %endif 257 293 jmp .return 258 294 … … 298 334 jmp Bs3Panic 299 335 336 337 ; 338 ; Restore context pointed to by cx:xSI. 339 ; 340 .restore_ctx: 341 call .convert_ptr_arg_to_cx_xSI 342 BS3_ONLY_64BIT_STMT sub rsp, 10h 343 mov xDX, VAR_CALLER_DX 344 push xDX 345 BS3_ONLY_16BIT_STMT push cx 346 push xSI 347 BS3_CALL Bs3RegCtxRestore, 2 348 jmp Bs3Panic 300 349 301 350 ; … … 696 745 697 746 747 ; 748 ; Internal function for converting a syscall pointer parameter (cx:xSI) 749 ; to a pointer we can use here in this context. 750 ; 751 ; Returns the result in cx:xSI. 752 ; @uses xAX, xCX, xDX 753 ; 754 .convert_ptr_arg_to_cx_xSI: 755 call .convert_ptr_arg_to_flat 756 %if TMPL_BITS == 16 757 ; Convert to tiled address. 758 mov si, ax ; offset. 759 shl dx, X86_SEL_SHIFT 760 add dx, BS3_SEL_TILED 761 mov cx, dx 762 %else 763 ; Just supply a flat selector. 764 mov xSI, xAX 765 mov cx, ds 766 %endif 767 ret 768 769 ; 770 ; Internal function for converting a syscall pointer parameter (caller CX:xSI) 771 ; to a real mode pointer. 772 ; 773 ; Returns the result in AX:SI. 774 ; @uses xAX, xCX, xDX 775 ; 776 .convert_ptr_arg_to_real_mode_ax_si: 777 call .convert_ptr_arg_to_flat 778 mov si, ax 779 %if TMPL_BITS == 16 780 mov ax, dx 781 %else 782 shr eax, 16 783 %endif 784 shl ax, 12 785 ret 786 787 ; 788 ; Internal function for the above that wraps the Bs3SelProtFar32ToFlat32 call. 789 ; 790 ; @returns eax (32-bit, 64-bit), dx+ax (16-bit). 791 ; @uses eax, ecx, edx 792 ; 793 .convert_ptr_arg_to_flat: 794 %if TMPL_BITS == 16 795 ; Convert to (32-bit) flat address first. 796 test byte VAR_CALLER_MODE, BS3_MODE_CODE_V86 797 jz .convert_ptr_arg_to_flat_prot_16 798 799 mov ax, VAR_CALLER_CX 800 mov dx, ax 801 shl ax, 4 802 shr dx, 12 803 add ax, VAR_CALLER_SI 804 adc dx, 0 805 ret 806 807 .convert_ptr_arg_to_flat_prot_16: 808 push es 809 push bx 810 push word VAR_CALLER_CX ; selector 811 xor ax, ax 812 test byte VAR_CALLER_MODE, BS3_MODE_CODE_16 813 jnz .caller_is_16_bit 814 mov ax, VAR_CALLER_SI_HI 815 .caller_is_16_bit: 816 push ax ; offset high 817 push word VAR_CALLER_SI ; offset low 818 call Bs3SelProtFar32ToFlat32 819 add sp, 2*3 820 pop bx 821 pop es 822 ret 823 824 %else ; 32 or 64 bit 825 test byte VAR_CALLER_MODE, BS3_MODE_CODE_V86 826 jz .convert_ptr_arg_to_cx_xSI_prot 827 828 ; Convert real mode address to flat address and return it. 829 movzx eax, word VAR_CALLER_CX 830 shl eax, 4 831 movzx edx, word VAR_CALLER_SI 832 add eax, edx 833 ret 834 835 ; Convert to (32-bit) flat address. 836 .convert_ptr_arg_to_cx_xSI_prot: 837 %if TMPL_BITS == 64 838 push r11 839 push r10 840 push r9 841 push r8 842 sub rsp, 10h 843 %endif 844 movzx ecx, word VAR_CALLER_CX 845 push xCX 846 mov eax, VAR_CALLER_SI 847 test byte VAR_CALLER_MODE, BS3_MODE_CODE_16 848 jz .no_masking_offset 849 and eax, 0ffffh 850 .no_masking_offset: 851 push xAX 852 BS3_CALL Bs3SelProtFar32ToFlat32,2 853 add xSP, xCB*2 BS3_ONLY_64BIT(+ 10h) 854 %if TMPL_BITS == 64 855 pop r8 856 pop r9 857 pop r10 858 pop r11 859 %endif 860 %endif 861 ret 862 698 863 BS3_PROC_END_MODE Bs3TrapSystemCallHandler 699 864
Note:
See TracChangeset
for help on using the changeset viewer.