PKT_TIMEOUT equ 12 ; Initial timeout, timer ticks @ 55 ms
TFTP_BLOCKSIZE_LG2 equ 9 ; log2(bytes/block)
TFTP_BLOCKSIZE equ (1 << TFTP_BLOCKSIZE_LG2)
+%assign USE_PXE_PROVIDED_STACK 1 ; Use stack provided by PXE?
;
; TFTP operation codes
section .text
org 7C00h
-StackBuf equ $
+StackBuf equ $ ; Base of stack if we use our own
;
; Primary entry point.
_start:
jmp 0:_start1 ; Canonicalize address
_start1:
- pushad ; Paranoia... in case of return to PXE
- pushfd ; ... save as much state as possible
+ pushfd ; Paranoia... in case of return to PXE
+ pushad ; ... save as much state as possible
push ds
push es
push fs
mov [InitStack],sp
mov [InitStack+2],ss
+%if USE_PXE_PROVIDED_STACK
+ ; Apparently some platforms go bonkers if we
+ ; set up our own stack...
+ mov [BaseStack],sp
+ mov [BaseStack+4],ss
+%endif
+
cli ; Paranoia
- mov ss,ax
- mov sp,StackBuf
+ lss esp,[BaseStack]
sti ; Stack set up and ready
cld ; Copy upwards
local_boot:
mov si,cs
mov ds,si ; Restore DI
- mov ss,si
- mov esp,StackBuf ; Reset the stack
+ lss esp,[BaseStack]
mov [LocalBootType],ax
call vgaclearmode
mov si,localboot_msg
pop fs
pop es
pop ds
- popfd
popad
mov ax,[cs:LocalBootType]
+ popfd
retf ; Return to PXE
;
mov ax,cs ; Restore CS = DS = ES
mov ds,ax
mov es,ax
- mov ss,ax
- mov sp,StackBuf ; Reset the stack
+ lss esp,[BaseStack]
sti
call cwritestr ; Expects SI -> error msg
al_ok: jmp enter_command ; Return to command prompt
mov ax,cs
mov es,ax
mov ds,ax
- mov ss,ax
- mov sp,StackBuf
+ lss esp,[BaseStack]
sti
.patch: mov si,bailmsg
call writestr ; Returns with AL = 0
jmp .call_loop
.call_done:
- mov bx,0FF00h
+%if USE_PXE_PROVIDED_STACK
+ ; We need to switch to our local stack here...
+ pusha
+ pushf
+
+ mov si,sp
+ mov cx,[InitStack]
+ mov di,StackBuf
+ mov [BaseStack],di
+ mov [BaseStack+4],es
+ sub cx,si
+ sub di,cx
+ mov dx,cx ; New SP
+ ss rep movsb
+
+ cli
+ mov ss,cx ; CX == 0 here
+ mov sp,dx
+
+ popf
+ popa
+%endif
mov dx,[RealBaseMem]
cmp dx,[BIOS_fbm] ; Sanity check
jna .cant_free
- inc bx
; Check that PXE actually unhooked the INT 1Ah chain
movzx eax,word [4*0x1a]
jae .ok
cmp ax,[BIOS_fbm]
jae .cant_free
- ; inc bx
.ok:
mov [BIOS_fbm],dx
;
; Misc initialized (data) variables
;
+ alignb 4, db 0
+BaseStack dd StackBuf ; SS:ESP of base stack
+ dw 0
AppendLen dw 0 ; Bytes in append= command
KbdTimeOut dw 0 ; Keyboard timeout (if any)
CmdLinePtr dw cmd_line_here ; Command line advancing pointer