Memory problem
Memory problem
I will start by telling you that i _really_ suck on memory stuff with segments:offsets and stuff..
I have done a bootsector that supports FAT12 and loads my kernel.bin.
Becasue the setting of pmode etc. don´t fit into the bootsector code i will do that in the kernel.
I have decided to put the kernel at FFFF:0010 (that i have read is at 1mb in the memory.)
So i have set the A20-gate in the bootloader so i don´t need to move the kernel later.
Now to the problem:
How do i write (in nasm) in the kernel so it will know it´s on FFFF:0010?
I tried all sorts of thing (stupid?) things but i can´t get it working!
I tried something like this (but with the correct address):
[ORG 0]
jmp 07C0h:start ; Goto segment 07C0
start:
; Update the segment registers
mov ax, cs
mov ds, ax
mov es, ax
And i have tried something like this:
[ORG 7C00h]
at the top of the kernel, but i just can´t get it working...
_and_ i have tried:
mov ax, 0x7C0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
with no success... i have tried with diffrent addresses like:
0x0010 and 0xFFFF and 0x00100000(physical address to 1mb)
If i load the kernel to, say 0x0000:0x1000, it is no problem becasue than i can use the code above buy changing 0x7C0 to 0x1000.
So i guess that it dosen´t work becasue the segment isn´t 0x0000....
But i can access the address at 1mb (enable the A20-gate) without having to enter pmode first, right?
I _do_ really suck on memory things..
So do i write (in nasm) in the kernel so it will know it´s on FFFF:0010?
Thanks in advance
/ Christoffer
I have done a bootsector that supports FAT12 and loads my kernel.bin.
Becasue the setting of pmode etc. don´t fit into the bootsector code i will do that in the kernel.
I have decided to put the kernel at FFFF:0010 (that i have read is at 1mb in the memory.)
So i have set the A20-gate in the bootloader so i don´t need to move the kernel later.
Now to the problem:
How do i write (in nasm) in the kernel so it will know it´s on FFFF:0010?
I tried all sorts of thing (stupid?) things but i can´t get it working!
I tried something like this (but with the correct address):
[ORG 0]
jmp 07C0h:start ; Goto segment 07C0
start:
; Update the segment registers
mov ax, cs
mov ds, ax
mov es, ax
And i have tried something like this:
[ORG 7C00h]
at the top of the kernel, but i just can´t get it working...
_and_ i have tried:
mov ax, 0x7C0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
with no success... i have tried with diffrent addresses like:
0x0010 and 0xFFFF and 0x00100000(physical address to 1mb)
If i load the kernel to, say 0x0000:0x1000, it is no problem becasue than i can use the code above buy changing 0x7C0 to 0x1000.
So i guess that it dosen´t work becasue the segment isn´t 0x0000....
But i can access the address at 1mb (enable the A20-gate) without having to enter pmode first, right?
I _do_ really suck on memory things..
So do i write (in nasm) in the kernel so it will know it´s on FFFF:0010?
Thanks in advance
/ Christoffer
RE:Memory problem
hi
Get pm.zip from the web by christopher giese, in it is 12 pm examples , example 5 is to go to unreal mode and copy kernel to alternate memory location, this what most people do so they can put kernel in higher memory.
it is also writen in nasm.
PS. I usest to use nasm,but then some one pointed out that to make your os independent you would not only have to make nasm run on it (556k) but also gcc.
So i moved to fasm ,i carnt tell you how much better it is, not only does it make smaller files but all so it has better error checking ( it show's you the line that has the error instead of a number) plus you need no linker, can make exe or com files, all so i can break my code up into small include files , and to run them just put " include 'myincfile.inc' "
all so it compiles itself and is only 45k
My kernel made in nasm needed only 2 changes to assemble it ,so the simtex is very similar
give it a try.
ASHLEY4.
Get pm.zip from the web by christopher giese, in it is 12 pm examples , example 5 is to go to unreal mode and copy kernel to alternate memory location, this what most people do so they can put kernel in higher memory.
it is also writen in nasm.
PS. I usest to use nasm,but then some one pointed out that to make your os independent you would not only have to make nasm run on it (556k) but also gcc.
So i moved to fasm ,i carnt tell you how much better it is, not only does it make smaller files but all so it has better error checking ( it show's you the line that has the error instead of a number) plus you need no linker, can make exe or com files, all so i can break my code up into small include files , and to run them just put " include 'myincfile.inc' "
all so it compiles itself and is only 45k
My kernel made in nasm needed only 2 changes to assemble it ,so the simtex is very similar
give it a try.
ASHLEY4.
RE:Memory problem
fasm makes smaller files? lol! only if its doing things behind your back, and with an assembler thats NOT what you want it do to.
if you expect someone to have gcc (with its libs is many MEGS huge...) whats wrong wrong with them having a 500kb binary of nasm? since you expect them to have fasm instead... but if they have gcc, then they already has gas.. so why not write in gas instead...
you can also do the include 'myfile.inc' in nasm...
does fasm have the full macro support nasm has? does fasm output ELF objects? win32-ecoff? rdoff? djgpp coff? omf?
if you expect someone to have gcc (with its libs is many MEGS huge...) whats wrong wrong with them having a 500kb binary of nasm? since you expect them to have fasm instead... but if they have gcc, then they already has gas.. so why not write in gas instead...
you can also do the include 'myfile.inc' in nasm...
does fasm have the full macro support nasm has? does fasm output ELF objects? win32-ecoff? rdoff? djgpp coff? omf?
-- Stu --
RE:Memory problem
I agree to what df said, but it is nice to have sutch a small assembler in in your OS.
But i can still write the OS in NASM and then port the code to FASM if i would like to..
****, i sat all night and tried to figre this memory **** out, and then you say that the solution is in pm.zip (witch i forgot to look in).
/ Christoffer
But i can still write the OS in NASM and then port the code to FASM if i would like to..
****, i sat all night and tried to figre this memory **** out, and then you say that the solution is in pm.zip (witch i forgot to look in).
/ Christoffer
RE:Memory problem
Why have a assembler that's writen in C ??????????????????????? (that then needs a assembler gas)
Gas uses AT&T crap like this %%%%%%%%%%%%%%%%%%%%%.
ASHLEY4.
Gas uses AT&T crap like this %%%%%%%%%%%%%%%%%%%%%.
ASHLEY4.
RE:Memory problem
Yeah, that part about nasm _really_ suck! write a assembler in C! what was they thinking!
If i start writing my OS i fasm, and then get a command line working, how easy is it to port to my OS?
/ Christoffer
If i start writing my OS i fasm, and then get a command line working, how easy is it to port to my OS?
/ Christoffer
RE:Memory problem
The person who coded fasm was writing a os,so he made fasm to run on it,he lost the code for the os and did not want to write it all again .
But had the code for fasm ,so thats how it started.It is also ported to MenuetOs you can look at that code and what functions it uses.
fasm also comes with it own asm code and has a forum for os maded in it.
But had the code for fasm ,so thats how it started.It is also ported to MenuetOs you can look at that code and what functions it uses.
fasm also comes with it own asm code and has a forum for os maded in it.
RE:Memory problem
Are you sure that the things i need to set in my kernel (to let it know that it´s loaded at 0xFFFF:0x0010) is in pm.zip?
/ Christoffer
/ Christoffer
RE:Memory problem
It dosn´t matter anymore, i rewrote the bootsector code to load 'loader.sys' that sets up the A20-gate and pmode before starting the 'kernel.sys'.
But i got a question, when i am in pmode in my 'loader.sys'-file, how do i load the file 'kernel.sys' from my FAT12 floppy?
I think that i can use the same code that i used i my bootsector but i will have to rewrite the 'readsector' rutine (that uses a BIOS int), correct?
Where can i find more info on how to load a file from a FAT12 floppy (in pmode) and how to start that program in pmode?
All example code i have (on loading and starting a program with fat12) is in realmode..
PS. Does someone got a nice OS-name idea?
/ Christoffer
But i got a question, when i am in pmode in my 'loader.sys'-file, how do i load the file 'kernel.sys' from my FAT12 floppy?
I think that i can use the same code that i used i my bootsector but i will have to rewrite the 'readsector' rutine (that uses a BIOS int), correct?
Where can i find more info on how to load a file from a FAT12 floppy (in pmode) and how to start that program in pmode?
All example code i have (on loading and starting a program with fat12) is in realmode..
PS. Does someone got a nice OS-name idea?
/ Christoffer
RE:Memory problem
I go in to unreal mode ,then i cam use bios ints and higher memory,(to get in to unreal mode go into pmode set gdt for 4gb and swich back to real mode,leaving gdt set to 4gb) now you can load from floppy in to higher memory and jmp to it and go back to pmode(useing bios int's).
try here for more info:
http://www.df.lth.se/~john_e/gems/gem0022.html
I use a com/exe loader that loads a file from the disk and jmp to it ,this lets me try my code easyer
ASHLEY4.
try here for more info:
http://www.df.lth.se/~john_e/gems/gem0022.html
I use a com/exe loader that loads a file from the disk and jmp to it ,this lets me try my code easyer
ASHLEY4.
RE:Memory problem
hard word, but: stop what you're trying to do now. accessing the floppy from pmode is far more difficult than using bios ints. why don't you select a different location for you kernel and skip over the "loader.sys"-thingy? you can load the kernel directly from the bootloader.
RE:Memory problem
In order to use 0xFFFF:0x0010 which will load your kernel to 1MB, you must enable the A20 gate. Do this in your kernel:
mov ax, 0xFFFF ; ES:BX = 0xFFFF:0x0010
mov es, ax
mov bx, 0x0010
Enter protected mode, setup segment registers and jump to the 1MB address.
jmp 0x0008:0x100000 ; Jump to C kernel
mov ax, 0xFFFF ; ES:BX = 0xFFFF:0x0010
mov es, ax
mov bx, 0x0010
Enter protected mode, setup segment registers and jump to the 1MB address.
jmp 0x0008:0x100000 ; Jump to C kernel
RE:Memory problem
Ok, that seems good..
But i will stick to my 'loader.sys' that will enter Pmode and set the A20-gate before jumping to the kernel.
If i decide to use grub later on, dosn´t grub go into pmode and stuff for me?
If thats the case, then it would be easy just to skip the 'loader.sys' without any changes in my kernel..
/ Christoffer
But i will stick to my 'loader.sys' that will enter Pmode and set the A20-gate before jumping to the kernel.
If i decide to use grub later on, dosn´t grub go into pmode and stuff for me?
If thats the case, then it would be easy just to skip the 'loader.sys' without any changes in my kernel..
/ Christoffer