Trying to get print function to work at higher memory addres

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
beyondsociety

Trying to get print function to work at higher memory addres

Post by beyondsociety »

Im trying to load my kernel to a memory address above 1MB and I have successfully done so. I have noticed that my print routine works at 1MB but if I try it at 2MB, it doesnt print anything.

How would I get my print routine to work at a higher memory address?
thooot

Re:Trying to get print function to work at higher memory add

Post by thooot »

Have you changed where it thinks it is being loaded in your linking script? That is, does your compiler know that the code will be loaded to a different address?
beyondsociety

Re:Trying to get print function to work at higher memory add

Post by beyondsociety »

Have you changed where it thinks it is being loaded in your linking script? That is, does your compiler know that the code will be loaded to a different address?
Yes I have. I even have the linker print out a memory map and then I checked to see if it was linking my addresses correctly and it was.

Do I have to add a load address to the VIDEO ram memory address?
For exxample:
Video = 0xB8000 for color monitor
Video = 0xB8000 + 0x200000 (where code is loaded to, 2MB)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Trying to get print function to work at higher memory add

Post by Pype.Clicker »

that basically depend on how you set up your GDT. If the main data descriptor is 0-based, you have nothing special to do ... If not (i.e. if you have DS.base == 1MB), then you have to adjust accesses to video memory with 0xb8000 - DS.base ...
beyondsociety

Re:Trying to get print function to work at higher memory add

Post by beyondsociety »

that basically depend on how you set up your GDT. If the main data descriptor is 0-based, you have nothing special to do ... If not (i.e. if you have DS.base == 1MB), then you have to adjust accesses to video memory with 0xb8000 - DS.base ...
They are are zero-based.

To load my kernel to a higher address than 1MB, I enable the a20 gate and load the kernel using the int 13h (read sectors function)

Code: Select all

load_sectors:
 
mov bx, 0xffff            ; ES:Bx = 0xffff:0x0020 (kernel loaded at 2MB)
mov es, bx
mov bx, 0x0020

mov ah, 0x02              ; Read disk sectors function
mov al, 0x17              ; Read 18 sectors (0x00 + 0x17 = 0x18 sectors)
mov ch, 0x00              ; Track 0x00
mov cl, 0x02              ; Sector 0x02
mov dh, 0x00              ; Head 0x00
mov dl, [DriveNumber]     ; Drive number (0x00 = Floppy, 0x80 = Hard Drive)
        
int 13h
or al, al                 ; Check for error code 
jc load_sectors           ; If there was an error, try again
Then I enter protected mode and load kernel to 2MB

Code: Select all

jmp 0x08:0x200000     ; Jump to C kernel
Then I add 2MB to the load address of the linker.ld and compile and test it. It will boot fine but nothing will display.

What could be the problem?
thooot

Re:Trying to get print function to work at higher memory add

Post by thooot »

Doesn't 0xffff:0x0020 = 0x100010? So your kernel isn't being loaded at 2MB. You should probably load it somewhere in low memory off of disk and then move it up to 2MB.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Trying to get print function to work at higher memory add

Post by Pype.Clicker »

beyondsociety wrote: To load my kernel to a higher address than 1MB, I enable the a20 gate and load the kernel using the int 13h (read sectors function)

Then I add 2MB to the load address of the linker.ld and compile and test it. It will boot fine but nothing will display.

What could be the problem?
<gandalf>Fool of a Took!</gandalf>
0xffff:0x0020 is certainly not 2MB. Check out Perica's tutorial about realmode addressing if it's not obvious... Only unreal mode can take you up to 2MB. Under real mode, all you can get is 0x0001ffef by cheating with the address formation.
And even under unreal mode, you cannot have the BIOS load anything directly above that barrier because it will only use the lowest 16 bits of memory operands.

What i would recommend is that you first load your kernel below 640KB area and then, either using a manual copy loop in unreal mode or calling the 'memory move' function of INT 15h, you send the kernel at its definitive location (whatever it is).
Post Reply