[88] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Defines for BOOTVARS struct used by boot menu |
---|
| 3 | ; and drive initialization. |
---|
| 4 | %ifndef BOOTVARS_INC |
---|
| 5 | %define BOOTVARS_INC |
---|
| 6 | |
---|
| 7 | |
---|
[96] | 8 | BOOT_READ_RETRY_TIMES EQU 3 |
---|
| 9 | |
---|
| 10 | |
---|
[3] | 11 | |
---|
[294] | 12 | ; Pre-boot variables. These do not exist after successful boot to OS. |
---|
[3] | 13 | ; Segment is always 0000h, same as BDA segment |
---|
| 14 | struc BOOTVARS |
---|
[221] | 15 | resb 7C00h |
---|
[3] | 16 | .rgbAtaInfo: ; 7C00h, ATA Information for drive detection |
---|
| 17 | .rgbBootSect resb 512 ; 7C00h, Boot sector |
---|
[221] | 18 | resb 256 ; Boot Menu stack |
---|
| 19 | .rgbMnuStack: |
---|
| 20 | .dwPostStack resb 4 ; POST stack pointer when entering INT 19h |
---|
[363] | 21 | .wMagicWord resb 2 ; I wish we didn't need this |
---|
[221] | 22 | .rgBootNfo: ; Array containing BOOTNFO structs |
---|
[3] | 23 | endstruc |
---|
| 24 | |
---|
[363] | 25 | ; Magic WORD to detect when BOOTVARS is available. |
---|
| 26 | BOOTVARS_MAGIC_WORD EQU 1110011001100111b |
---|
[3] | 27 | |
---|
[363] | 28 | |
---|
| 29 | |
---|
[121] | 30 | ;-------------------------------------------------------------------- |
---|
| 31 | ; Stores POST stack pointer to BOOTVARS. |
---|
| 32 | ; |
---|
| 33 | ; STORE_POST_STACK_POINTER |
---|
| 34 | ; Parameters: |
---|
[243] | 35 | ; ES: BDA and Interrupt Vector segment (zero) |
---|
[121] | 36 | ; Returns: |
---|
| 37 | ; Nothing |
---|
| 38 | ; Corrupts registers: |
---|
| 39 | ; Nothing |
---|
| 40 | ;-------------------------------------------------------------------- |
---|
| 41 | %macro STORE_POST_STACK_POINTER 0 |
---|
[243] | 42 | mov [es:BOOTVARS.dwPostStack], sp |
---|
| 43 | mov [es:BOOTVARS.dwPostStack+2], ss |
---|
[121] | 44 | %endmacro |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | ;-------------------------------------------------------------------- |
---|
| 48 | ; Initializes stack for boot menu usage. |
---|
| 49 | ; POST stack is not large enough when DPTs are stored to 30:0h. |
---|
| 50 | ; |
---|
| 51 | ; Note regarding LOAD_BDA_SEGMENT_TO: If you force the use of SP |
---|
| 52 | ; then you also have to unconditionally enable the CLI/STI pair. |
---|
| 53 | ; The reason for this is that only some buggy 808x CPU:s need the |
---|
| 54 | ; CLI/STI instruction pair when changing stacks. Other CPU:s disable |
---|
| 55 | ; interrupts automatically when SS is modified for the duration of |
---|
| 56 | ; the immediately following instruction to give time to change SP. |
---|
| 57 | ; |
---|
| 58 | ; SWITCH_TO_BOOT_MENU_STACK |
---|
| 59 | ; Parameters: |
---|
| 60 | ; Nothing |
---|
| 61 | ; Returns: |
---|
| 62 | ; SS:SP: Pointer to top of Boot Menu stack |
---|
| 63 | ; Corrupts registers: |
---|
| 64 | ; Nothing |
---|
| 65 | ;-------------------------------------------------------------------- |
---|
| 66 | %macro SWITCH_TO_BOOT_MENU_STACK 0 |
---|
| 67 | %ifndef USE_186 |
---|
| 68 | cli ; Disable interrupts |
---|
| 69 | %endif |
---|
| 70 | LOAD_BDA_SEGMENT_TO ss, sp |
---|
| 71 | mov sp, BOOTVARS.rgbMnuStack ; Load offset to stack |
---|
| 72 | %ifndef USE_186 |
---|
| 73 | sti ; Enable interrupts |
---|
| 74 | %endif |
---|
| 75 | %endmacro |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | ;-------------------------------------------------------------------- |
---|
| 79 | ; Restores SS and SP to initial boot loader values. |
---|
| 80 | ; |
---|
[243] | 81 | ; Note! Must return with AX=0 and CF preserved. |
---|
| 82 | ; See Int19hMenu_JumpToBootSector_or_RomBoot. |
---|
[121] | 83 | ; |
---|
| 84 | ; SWITCH_BACK_TO_POST_STACK |
---|
| 85 | ; Parameters: |
---|
[243] | 86 | ; AX: BDA and Interrupt Vector segment (zero) |
---|
[121] | 87 | ; Returns: |
---|
| 88 | ; SS:SP: Ptr to POST stack |
---|
| 89 | ; Corrupts registers: |
---|
[243] | 90 | ; Nothing (not even FLAGS) |
---|
[121] | 91 | ;-------------------------------------------------------------------- |
---|
| 92 | %macro SWITCH_BACK_TO_POST_STACK 0 |
---|
| 93 | %ifndef USE_386 |
---|
[243] | 94 | cli |
---|
| 95 | mov ss, ax |
---|
[121] | 96 | mov sp, [ss:BOOTVARS.dwPostStack] |
---|
| 97 | mov ss, [ss:BOOTVARS.dwPostStack+2] |
---|
[243] | 98 | sti |
---|
[121] | 99 | %else |
---|
[243] | 100 | mov ss, ax |
---|
[121] | 101 | lss sp, [ss:BOOTVARS.dwPostStack] |
---|
[294] | 102 | %endif |
---|
[121] | 103 | %endmacro |
---|
| 104 | |
---|
| 105 | |
---|
[3] | 106 | %endif ; BOOTVARS_INC |
---|