- Timestamp:
- Mar 8, 2016 10:56:04 AM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/bootsectors/bs3kit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm
r58694 r59952 146 146 mov eax, cr4 147 147 mov [BS3_ADDR_REG_SAVE + BS3REGS.cr4], eax 148 mov byte [BS3_ADDR_REG_SAVE + BS3REGS. cBits], 16148 mov byte [BS3_ADDR_REG_SAVE + BS3REGS.bMode], BS3_MODE_RM 149 149 xor eax, eax 150 150 mov [cs:BS3_ADDR_REG_SAVE + BS3REGS.cs], ax -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm
r59949 r59952 28 28 29 29 30 %ifdef TMPL_CMN_R86 31 ; Make sure BS3DATA16 is defined so we can refere to it below. 32 BS3_BEGIN_DATA16 33 BS3_BEGIN_TEXT16 34 %endif 30 BS3_EXTERN_DATA16 g_bBs3CurrentMode 31 BS3_EXTERN_DATA16 g_uBs3CpuDetected 32 TMPL_BEGIN_TEXT 35 33 36 34 … … 49 47 mov xBP, xSP 50 48 %ifndef TMPL_64BIT 49 %define VAR_CALLER_DS [xBP - xCB] 51 50 push ds 52 51 %ifdef TMPL_CMN_R86 … … 56 55 %endif 57 56 pop ds 57 %define VAR_CALLER_BP [xBP] 58 %define VAR_CALLER_DS [xBP - - xCB] 59 %define VAR_CALLER_BX [xBP - xCB*1 - xCB] 60 %define VAR_CALLER_AX [xBP - xCB*2 - xCB] 61 %define VAR_CALLER_CX [xBP - xCB*3 - xCB] 62 %define VAR_CALLER_DX [xBP - xCB*4 - xCB] 63 %define VAR_CALLER_MODE [xBP - xCB*5 - xCB] 64 %else 65 %define VAR_CALLER_BP [xBP] 66 %define VAR_CALLER_BX [xBP - xCB*1] 67 %define VAR_CALLER_AX [xBP - xCB*2] 68 %define VAR_CALLER_CX [xBP - xCB*3] 69 %define VAR_CALLER_DX [xBP - xCB*4] 70 %define VAR_CALLER_MODE [xBP - xCB*5] 58 71 %endif 59 72 push xBX … … 61 74 push xCX 62 75 push xDX 76 77 ; VAR_CALLER_MODE: Save the current mode (important for v8086 with 16-bit kernel). 78 xor xBX, xBX 79 mov bl, [g_bBs3CurrentMode] 80 push xBX 63 81 64 82 ; … … 139 157 140 158 ; 141 ; Print CX chars from string pointed to by DS:[E]DI 159 ; Print CX chars from string pointed to by DX:SI in 16-bit and v8086 mode, 160 ; and ESI/RSI in 64-bit and 32-bit mode (flat). 142 161 ; 143 162 ; We use the vga bios teletype interrupt to do the writing, so we must … … 146 165 ; 147 166 .print_str: 167 push xSI ; we setup ds:xSI to point to the thing. 168 %if TMPL_BITS != 64 169 mov bl, byte VAR_CALLER_MODE 170 and bl, BS3_MODE_CODE_MASK 171 cmp bl, BS3_MODE_CODE_V86 172 jne .print_str_not_v8086 173 ;; @todo this gets complicated _fast_. Later. 174 .print_str_not_v8086: 175 %endif 148 176 int3 149 177 jmp .return … … 154 182 ; 155 183 .to_ring0: 156 int3 157 158 jmp .return 159 184 sub xSP, BS3REGS_size 185 mov xBX, xSP ; xBP = BS3REGS pointer. 186 call .save_context 187 188 189 jmp .return 190 191 ;; @todo the remainder could be implemented in client code using SwitchToRing0 160 192 .to_ring1: 161 193 int3 … … 170 202 jmp .return 171 203 204 172 205 ; 173 206 ; Return. 174 207 ; 175 208 .return: 209 pop xBX ; saved mode 210 %if TMPL_BITS == 16 211 and bl, BS3_MODE_CODE_MASK 212 cmp bl, BS3_MODE_CODE_V86 213 je .return_to_v8086_from_16bit_krnl 214 %endif 176 215 pop xDX 177 216 pop xCX … … 187 226 iret 188 227 %endif 228 229 %if TMPL_BITS == 16 230 .return_to_v8086_from_16bit_krnl: 231 int3 232 jmp .return_to_v8086_from_16bit_krnl 233 %endif 234 235 236 237 ; 238 ; Internal function. ss:xBX = Pointer to register frame (BS3REGS). 239 ; @uses xAX 240 ; 241 .save_context: 242 %if TMPL_BITS == 16 243 cmp byte [g_uBs3CpuDetected], BS3CPU_80386 244 jae .save_context_full 245 246 ; 247 ; 80286 or earlier. 248 ; 249 250 ; Clear the state area first. 251 push di 252 xor di, di 253 .save_context_16_clear_loop: 254 mov word [ss:bx + di], 0 255 mov word [ss:bx + di + 2], 0 256 mov word [ss:bx + di + 4], 0 257 mov word [ss:bx + di + 6], 0 258 add di, 8 259 cmp di, BS3REGS_size 260 jb .save_context_16_clear_loop 261 pop di 262 263 ; Do the 8086/80186/80286 state saving. 264 mov ax, VAR_CALLER_AX 265 mov [ss:bx + BS3REGS.rax], ax 266 mov cx, VAR_CALLER_CX 267 mov [ss:bx + BS3REGS.rcx], ax 268 mov ax, VAR_CALLER_DX 269 mov [ss:bx + BS3REGS.rdx], ax 270 mov ax, VAR_CALLER_BX 271 mov [ss:bx + BS3REGS.rbx], ax 272 mov [ss:bx + BS3REGS.rsi], si 273 mov [ss:bx + BS3REGS.rdi], di 274 mov ax, VAR_CALLER_BP 275 mov [ss:bx + BS3REGS.rbp], ax 276 mov [ss:bx + BS3REGS.es], es 277 mov ax, [xBP + xCB] 278 mov [ss:bx + BS3REGS.rip], ax 279 mov ax, [xBP + xCB*2] 280 mov [ss:bx + BS3REGS.cs], ax 281 and al, X86_SEL_RPL 282 mov [ss:bx + BS3REGS.bCpl], al 283 cmp al, 0 284 je .save_context_16_same 285 mov ax, [xBP + xCB*4] 286 mov [ss:bx + BS3REGS.rsp], ax 287 mov ax, [xBP + xCB*5] 288 mov [ss:bx + BS3REGS.ss], ax 289 jmp .save_context_16_done_stack 290 .save_context_16_same: 291 mov ax, bp 292 add ax, xCB * (1 + 3) 293 mov [ss:bx + BS3REGS.rsp], ax 294 mov ax, ss 295 mov [ss:bx + BS3REGS.ss], ax 296 .save_context_16_done_stack: 297 mov ax, [xBP + xCB*3] 298 mov [ss:bx + BS3REGS.rflags], ax 299 mov al, VAR_CALLER_MODE 300 mov [ss:bx + BS3REGS.bMode], al 301 cmp byte [g_uBs3CpuDetected], BS3CPU_80286 302 jne .save_context_16_return 303 smsw [ss:bx + BS3REGS.cr0] 304 str [ss:bx + BS3REGS.tr] 305 sldt [ss:bx + BS3REGS.ldtr] 306 .save_context_16_return: 307 ret 308 %endif ; TMPL_BITS == 16 309 310 ; 311 ; 80386 or later. 312 ; 313 .save_context_full: 314 315 ; Clear the state area first unless 64-bit mode. 316 %if TMPL_BITS != 64 317 push xDI 318 xor xDI, xDI 319 .save_context_32_clear_loop: 320 mov dword [ss:xBX + xDI], 0 321 mov dword [ss:xBX + xDI + 4], 0 322 add xDI, 8 323 cmp xDI, BS3REGS_size 324 jb .save_context_32_clear_loop 325 pop xDI 326 %endif 327 328 ; Do the 386+ state saving. 329 %if TMPL_BITS == 16 ; save the high word of registered pushed on the stack. 330 mov [ss:bx + BS3REGS.rax], eax 331 mov [ss:bx + BS3REGS.rcx], ecx 332 mov [ss:bx + BS3REGS.rdx], edx 333 mov [ss:bx + BS3REGS.rbx], ebx 334 mov [ss:bx + BS3REGS.rbp], ebp 335 mov [ss:bx + BS3REGS.rsp], esp 336 %endif 337 mov xAX, VAR_CALLER_AX 338 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rax], xAX 339 mov xCX, VAR_CALLER_CX 340 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rcx], xCX 341 mov xAX, VAR_CALLER_DX 342 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rdx], xAX 343 mov xAX, VAR_CALLER_BX 344 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rbx], xAX 345 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rsi], sSI 346 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rdi], sDI 347 mov xAX, VAR_CALLER_BP 348 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rbp], xAX 349 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.es], es 350 mov xAX, [xBP + xCB] 351 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rip], xAX 352 mov ax, [xBP + xCB*2] 353 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cs], ax 354 %if TMPL_MODE != BS3_MODE_RM 355 and al, X86_SEL_RPL 356 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.bCpl], al 357 cmp al, 0 358 je .save_context_full_same 359 mov xAX, [xBP + xCB*4] 360 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rsp], xAX 361 mov ax, [xBP + xCB*5] 362 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.ss], ax 363 jmp .save_context_full_done_stack 364 %else 365 mov byte [BS3_NOT_64BIT(ss:) xBX + BS3REGS.bCpl], 0 366 %endif 367 .save_context_full_same: 368 mov xAX, xBP 369 add xAX, xCB * (1 + 3) 370 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rsp], xAX 371 mov ax, ss 372 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.ss], ax 373 .save_context_full_done_stack: 374 mov xAX, [xBP + xCB*3] 375 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.rflags], xAX 376 mov al, VAR_CALLER_MODE 377 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.bMode], al 378 %if TMPL_BITS == 64 379 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r8], r8 380 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r9], r9 381 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r10], r10 382 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r11], r11 383 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r12], r12 384 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r13], r13 385 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r14], r14 386 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.r15], r15 387 %endif 388 ; Save state according to detected CPU. 389 str [BS3_NOT_64BIT(ss:) xBX + BS3REGS.tr] 390 sldt [BS3_NOT_64BIT(ss:) xBX + BS3REGS.ldtr] 391 cmp byte [g_uBs3CpuDetected], BS3CPU_80286 392 ja .save_context_full_return 393 smsw [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr0] 394 jmp .save_context_full_return 395 396 .save_context_full_386_plus: 397 mov sAX, cr0 398 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr0], sAX 399 mov sAX, cr2 400 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr2], sAX 401 mov sAX, cr3 402 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr3], sAX 403 mov sAX, cr4 404 mov [BS3_NOT_64BIT(ss:) xBX + BS3REGS.cr4], sAX 405 406 .save_context_full_return: 407 ret 408 409 189 410 BS3_PROC_END_MODE Bs3TrapSystemCallHandler 190 411 -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
r59941 r59952 1948 1948 uint16_t tr; 1949 1949 uint16_t ldtr; 1950 uint8_t cBits; 1951 uint8_t abPadding[7]; 1950 uint8_t bMode; /**< BS3_MODE_XXX. */ 1951 uint8_t bCpl; /**< 0-3, 0 is used for real mode. */ 1952 uint8_t abPadding[6]; 1952 1953 BS3REG cr0; 1953 1954 BS3REG cr2; -
trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
r59950 r59952 178 178 %endif 179 179 180 %undef BS3_NOT_64BIT 181 %if %1 == 64 182 %define BS3_NOT_64BIT(a_Expr) 183 %else 184 %define BS3_NOT_64BIT(a_Expr) a_Expr 185 %endif 186 180 187 %undef BS3_IF_16_32_64BIT 181 188 %if %1 == 16 … … 274 281 %else 275 282 %define BS3_ONLY_64BIT(a_Expr) 283 %endif 284 285 ;; For segment overrides and stuff. Follows BS3_SET_BITS. 286 %if ARCH_BITS == 64 287 %define BS3_NOT_64BIT(a_Expr) 288 %else 289 %define BS3_NOT_64BIT(a_Expr) a_Expr 276 290 %endif 277 291 … … 1112 1126 ; 1113 1127 struc BS3REGS 1114 .rax resq 1 1115 .rbx resq 1 1116 .rcx resq 1 1117 .rdx resq 1 1118 .rdi resq 1 1119 .rsi resq 1 1120 .rbp resq 1 1121 .rsp resq 1 1122 .rip resq 1 1123 .r8 resq 1 1124 .r9 resq 1 1125 .r10 resq 1 1126 .r11 resq 1 1127 .r12 resq 1 1128 .r13 resq 1 1129 .r14 resq 1 1130 .r15 resq 1 1131 .rflags resq 1 1132 .cs resw 1 1133 .ds resw 1 1134 .es resw 1 1135 .fs resw 1 1136 .gs resw 1 1137 .ss resw 1 1138 .cBits resb 1 1139 .pad resb 3 1140 .cr0 resq 1 1141 .cr2 resq 1 1142 .cr3 resq 1 1143 .cr4 resq 1 1144 .cr8 resq 1 1128 .rax resq 1 1129 .rcx resq 1 1130 .rdx resq 1 1131 .rbx resq 1 1132 .rsp resq 1 1133 .rbp resq 1 1134 .rsi resq 1 1135 .rdi resq 1 1136 .r8 resq 1 1137 .r9 resq 1 1138 .r10 resq 1 1139 .r11 resq 1 1140 .r12 resq 1 1141 .r13 resq 1 1142 .r14 resq 1 1143 .r15 resq 1 1144 .rflags resq 1 1145 .rip resq 1 1146 .cs resw 1 1147 .ds resw 1 1148 .es resw 1 1149 .fs resw 1 1150 .gs resw 1 1151 .ss resw 1 1152 .tr resw 1 1153 .ldtr resw 1 1154 .bMode resb 1 1155 .bCpl resb 1 1156 .abPadding resb 6 1157 .cr0 resq 1 1158 .cr2 resq 1 1159 .cr3 resq 1 1160 .cr4 resq 1 1161 1145 1162 ;; @todo Add floating point registers when they are active. 1146 1163 endstruc
Note:
See TracChangeset
for help on using the changeset viewer.