section .data and loading a kernel:
Posted: Tue Mar 12, 2013 12:26 pm
Hello,
I wrote a simple 16 bits piece of code and fail to understand something.
How is the .data section placed correctly in memory?
I have defined this ld script:
Meaning I expect the .data section to be placed at 0x5000
EXTERN __data is correctly filled with 0x5000
In the following code, msg32gdt address is 0x5224 (I wrote it in memory and dumped to know that.)
Note the 24 52 after the DEADBEEF, address is 5224 (mov word [ds:bx +9], msg32gdt)
---------------------------------------
The issue is that the "K16 - Load...." is placed at address 0x14224, so, 0x9000 after where expected.
What are the mecanisms placing the .data section in memory?
Did I mess up my boot sector?
The difference is actually of 0xF000, this is the value I set the stack pointer at, is this impacting? How?
Here's my code:
Thank you!
I wrote a simple 16 bits piece of code and fail to understand something.
How is the .data section placed correctly in memory?
I have defined this ld script:
Code: Select all
OUTPUT_FORMAT(binary)
ENTRY(kmain)
SECTIONS
{
. = 0x1000;
.text : {
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
. = 0x5000;
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
kernelEnd = .;
}
EXTERN __data is correctly filled with 0x5000
In the following code, msg32gdt address is 0x5224 (I wrote it in memory and dumped to know that.)
Code: Select all
00005000 50 44 45 41 44 42 45 45 46 24 52 00 00 00 00 00 |PDEADBEEF$R.....|
Note the 24 52 after the DEADBEEF, address is 5224 (mov word [ds:bx +9], msg32gdt)
Code: Select all
[BITS 16]
[SECTION .data]
msg32gdt: db 'K16 - Loading 32 bits GDT.', 0
The issue is that the "K16 - Load...." is placed at address 0x14224, so, 0x9000 after where expected.
Code: Select all
00014220 00 00 fa f4 4b 31 36 20 2d 20 4c 6f 61 64 69 6e |....K16 - Loadin|
What are the mecanisms placing the .data section in memory?
Did I mess up my boot sector?
The difference is actually of 0xF000, this is the value I set the stack pointer at, is this impacting? How?
Here's my code:
Code: Select all
; init segs in 0x7c0
mov ax, 0x07C0
mov ds, ax
mov es, ax
mov ax, 0x8000 ; stack at 0xFFFF
mov ss, ax
mov sp, 0xf000
;cli
;hlt
; get boot drive
mov [bootdrv], dl
; show msg
mov si, msgload
call asm16_display_writestring
; load kernel
xor ax, ax
int 0x13
push es
mov ax, BASE
mov es, ax
mov bx, 0
mov ah, 2
mov al, KSIZE
mov ch, 0
mov cl, 2
mov dh, 0
mov dl, [bootdrv]
int 0x13
pop es
mov si, msgboot
call asm16_display_writestring
db 0xea
dw 0, BASE
Thank you!