Error setting stack by kernel

Asked

Viewed 20 times

0

I always thought I understood about the stack but I realized that no, I’m wanting to understand the stack in practice, so I created this environment

The idea is to set the top of the stack at 7FFFh address because from 8000h onwards is the kernel, after that I will put something in the stack so it will be at address (7FFFh - 2 = 7FFD) since I am in real mode, I will try to access the location by physical address

more when I call the label Configstack it does not work, I did several tests and if I do not call this label everything works normally

[bits 16]
[org 0x8000]

call Main
call End

Main:
    call ConfigStack
    call SetSegment
    call SetVideoMode
    call ClearScreen
ret 

ConfigStack:
    mov ax, 07E0h
    mov ss, ax
    mov sp, 1FEh
ret 

Note: it calls all other labels including End, but I will not show the code because the problem is in Configstack

Clearscreen leaves the screen green to make sure that I have entered the kernel and that it executes all the other Abels, as I said everything works if I do not call Configstack

The stack segment is 07E0h because the bootloader ends in one byte before

| 7C00h | - Beginning of the Bootloader

|--------| - 512 bytes

| 7DFFh | - End of the Bootloader

| 7E00h | - Pile start

| ------ | - 512 bytes

| 7FFFh | - Bottom of the pile

| -------|

| 8000h | Kernel start

  • What platform is that on? Real x86 (16 bit) mode? The question lacks a little more context.

  • The instruction call puts the return address on the stack. If you modify the stack within the subroutine, the ret will return to an indefinite address. Normally, the boot arrow the stack in the main code and right at the start, after normalizing all segment registers.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.