Where to stack and load the kernel

I am new to the development of the operating system, and I am curious about the problem I encountered when developing my own bootloader. My operating system will be recorded in assembly and will run in 16-bit real mode.

I know what a stack is, and I get the impression that it is growing down in memory. Correct me if I am wrong. I know how to load the base core into memory from a floppy disk, and I do not think this is a problem.

The problem I am facing is that I am not sure where to put the stack and load my kernel into memory. I tried to create my stack like this and I have problems:

mov ax, 0x0000
mov ss, ax
mov sp, 0xFFFF

I load my kernel in 0x1000:0x0000. When I PUSH and later POP changes the registers in my function print, my kernel will just enter a second time call print. This is my function print:

print:
    push ax
    push bx
    push cx

    mov al, [si]
    cmp al, 0
    je p_Done

    cmp al, 9
    je p_Tab

    mov ah, 0xE
    int 0x10

    cmp al, 10
    je p_NewLine
   p_Return:
    inc si
    jmp print
  p_Tab:
    xor cx, cx
   p_Tab_Repeat:
    cmp cx, 8
    je p_Return
    mov ah, 0xE
    mov al, " "
    int 0x10
    inc cx
    jmp p_Tab_Repeat
  p_NewLine:
    xor bx, bx
    mov ah, 0x3
    int 0x10

    mov dl, 0x00
    mov ah, 0x2
    int 0x10
    jmp p_Return
  p_Done:
    pop cx
    pop bx
    pop ax
    ret

These are the lines I want to display:

db "Kernel successfully loaded!", 10, 0
db 9, "Lmao, just a tab test!", 10, 0

This is the result that I get when my kernel starts ( _- this is the cursor):

Kernel successfully loaded!
_

It successfully prints the first line, but hangs while printing the second. If I remove the PUSH and POP statements, that will be fine. Why does my kernel freeze when I try to save and restore registers in my function print? Where should I place my stack and where to load the kernel?

+4
source share
1 answer

, , . , , PUSHes POP , , . , RET . , , / . undefined.

​​ , :

print:
    push ax
    push bx
    push cx

    ... snip out code for brevity  

    jmp print

- print . PUSHes POP . , , , :

print:
    push ax
    push bx
    push cx

.prloop:
    ... snip out code for brevity  

    jmp .prloop

.prloop , . . .prloop .


, / . @RossRidge, SP 0xFFFF , (0xFFFF = -1). X86 , x86.

: SS: SP 0x1000: 0x0000 , 0x1000: 0xFFFF 0x1000: 0x0000. 16- 0x1000: 0xFFFE.


​​ 0x00520 0x90000, . 0x90000 0xA0000 . , 0x9C000 0xA0000. BIOS BIOS (EBDA). 0x00000 0x00520 , , BIOS (BDA) 32 , .

+6

All Articles