I am having problems with secondary loader (places kernel into HiMem)
I have A20, check and enable routines that are working To the best of my knowlege (the function exits; and if A20 is not enabled it is designed to loop forever, however I have debugged enough to know that the loop is exiting so A20 must therefore be enabled).
the bootloader in the MBR uses a very similar structure and the exact same interupt routine. The bootloader in MBR works flawlessly.
the secondary loader sets carry flag after int 0x13 indicating an error, but I can't for the life of me figure out the error. Been debugging and testing for 3 days now before deciding to post. Any help would be great.
for refference this is my dap structure
Code: Select all
dap: db 0x10
db 0x00
dw 0x0010
ptr1:
dw 0x0010,0xFFFF
db 0x03,0,0,0,0,0,0,0
kernel runs init which reloads kernel into HiMem then transfers control
init then runs again, but if it is in HiMem or errors on HiMem load it just skips load stuff and exits back to main kernel program
Code: Select all
EXPORT _init
;cdelc convention header code here but not shown
_checkSegment ;some code to check if SS = 0xFFFF, indicating HiMem load was successful, (this has been debugged and works)
;if successful skip all the loading stuff and jump to end init.
_checkA20 ;some code follows but left out for space
_enableA20 ;if nessesary, some code follows but left out for space
;endlessly loops to _checkA20 till _checkA20 returns enabled
.loadHiMem:
sti ;ensure interupts enabled
;reset regesters and segments used in previous procedures back to the known requred state
xor ax, ax ;ax = 0
xor dx, dx ;dx =0
mov ds, ax ;ds =0
;push "dap" onto stack (this was for debugging in case the dap structure was not being placed where i expected it durring as86 object file assembly)
;this way i know exactly where and how the dap is set up
mov bx, sp ;save stack pointer to quickly remove the structure
mov ax, ss
mov es, ax ;set up index register
;maped out what the stack structure should look like using "grow down" and little endian. The pushed structure onto stack accordingly
xor ax, ax
push ax
mov ax, #0x0003
push ax
mov ax, #0xFFFF
push ax
mov ax, #0x0010
push ax
mov di, sp ;(ptr1) pointer to jump to after load points to HiMem
push ax
push ax
;exact same interupt routine used in bootloader in MBR, that bootloader works.
mov si, sp ;Already tested and proved as86 defaluts to ds seg reg for operations involving si index register
;sp should point to dap structure on stack.
mov ah, #0x42
mov dl, #0x80
int #0x13
jc .error ;jump to "error handler" if problem durring load
mov ax, #0xFFFF
mov ss, ax ;set up HiMem stack, for check segment routine, and for cdelc convention when kernel restarts in HiMem
mov sp, #0x0FFF
; mov [ptr1], word #0x0010 ;I may or may not have needed this in a past secondary bootloader written completely in assembly
;using fasm, I know the loader isn't even getting this far, it is jumping to the error handler.
seg es ;when using index di, you must specify a segment this is how in as86
jmp far dword [di] ;this was saved while pushing dap onto stack
.endinit:
; cdelc convention footer
pop si
pop di
mov sp, bp
pop bp
ret ;exit _init
.error: ;"error handler"
mov sp, bx ;remove dap from stack
push #0x45 ;print "E" to screen (this is what is happening when init exits)
push #0x8150
push #0xB000
call _putInMemory ;this works with no issues
jmp .endinit ; run kernel anyway, but not in HiMem, this is to ensure OS will boot even if HiMem is for whatever reason not available.
;but i already know that in my "Bochs" setup HiMem is available. This is Mark 2 for my OS, the first design was purely assmebly, this time i am trying to use mainly C for developement.
I can't figure out why int 0x13 is producing an error.
ps, i know my code style may not be perfect, please offer advice, and don't criticize.