Reputation: 5647
I have a simple kernel in development along with a bootloader. Before the boot loader goes into protected mode, I would like to use interrupts to retrieve the amount of memory on the system (int 0x12) and then set the value held by a label to the amount of ram that I retrieved. Once the kernel has loaded (in protected mode) I would like to access the data.
At first was going to use the following structure:
; sysinfo.asm
RAM: dd 0 ; declare RAM as a 4 byte label
; boot.asm
%include "sysinfo.asm"
; bootloader code here
xor ax, ax
int 0x12
mov [RAM], ax
; go into protected mode and launch kernel
; kernel.asm
%include "sysinfo.asm"
mov ax, [RAM]
; print ax
However as I expected to happen, since the RAM label in boot1.asm and the RAM label in kernel.asm are totally different, they don't point to the same address, how could I do this?
Upvotes: 1
Views: 156
Reputation: 1298
I recommend defining a structure that holds the information gathered in loading process and then pass the address of the structure to kernel in some of the registers.
sysinfo.asm:
struc BootInfo
.ram resd 1
; .. some other useful information ...
endstruc
boot.asm:
%include "sysinfo.asm"
bootinfo: istruc BootInfo
at ram, dd 0
iend
; ....
xor ax, ax
int 0x12
mov [bootinfo + BootInfo.ram], ax ; set amount of ram
; ...
mov edx, bootinfo ; pass address of BootInfo in some register
; goto kernel code
kernel.asm:
%include "sysinfo.asm"
; Address of BootInfo in edx
mov eax, [edx + BootInfo.ram] ; get ram to eax
; ...
Upvotes: 1
Reputation: 2642
Two different names in two different files; or is it three ? Whatever
The first one...
RAM: dd 0 ; declare RAM as a 4 byte label
Becomes...
Boot_Dot_Asm_RAM: dd 0 ; declare RAM as a 4 byte label
The second one Becomes...
Kernal_Dot_Asm_RAM: dd 0 ; declare RAM as a 4 byte label
You can do this with "conditional assembly".
If you need pointers on that, just ask.
Upvotes: 0