asm problems [FIXED]

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
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

asm problems [FIXED]

Post by GLneo »

hi all, why does

Code: Select all

EXTERN bss
EXTERN bsslength
mov edi, bss
mov ecx, bsslength
xor eax, eax
rep stosd
( should clear bss ) crashes my kernel, when "rep stosd" is run my kernel breaks, with out it it boots but i don't think the bss is cleared. this above code works on qemu but not on bochs or a real pc, anyone know why?

my link script is here: http://lemonos.cvs.sourceforge.net/lemo ... iew=markup
( it's where bss and bsslength are defined )

o and bochs says this:

Code: Select all

00004441948i[CPU  ] write_virtual_checks(): write beyond limit, r/w
thx
Last edited by GLneo on Wed Feb 21, 2007 10:29 am, edited 1 time in total.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

did you print the values of bss and bsslength this to verify the correctness of the values. I had a similar problem that the divide didn't work so i manuallly did the divide in code and worked perfectly. also make sure that the direction is ok cld statement and the ds or es is properly setup.
Author of COBOS
User avatar
proxy
Member
Member
Posts: 108
Joined: Wed Jan 19, 2005 12:00 am
Contact:

Post by proxy »

could be be because length is in bytes and your are storing dwords...thus you are clearing 4 times the amount of data as needed.

just add a "shr ecx, 2" before the rep movsd (effectively divides by 4) and i think you will be fine.

**EDIT: scratch that, your length is in dwords, dunno what's wrong :(
**EDIT2: perhaps you need a "cld" to make sure addresses are incrementing and not decrementing?

proxy
Last edited by proxy on Mon Dec 15, 2014 8:39 am, edited 1 time in total.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

If bsslength + base of segment > limit then you get an error. Since you have the same item...

Is this in rmode, pmode or lmode?

As said before, it could be the direction bit but I doubt it since I think bochs cleans it as well...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Do you have paging setup properly and enabled? otherwise you'll be clearing miles beyond end of memory at 0xC01xxxxx ...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

ok, i set e,f,g(s):

Code: Select all

mov ax, 10h
mov ds, ax
mov ss, ax
mov es, ax  ; added
mov fs, ax  ; added
mov gs, ax  ; added
now it boots... but i still have other problems, i'll report them if i cant figure them out :wink:

thx all!

p.s. what is this: "cld" ?
m
Member
Member
Posts: 67
Joined: Sat Nov 25, 2006 6:33 am
Location: PRC

Post by m »

CLD:Clear the direction flag(DF) in the (E)FLAG.(i.e. Set Bit 10 to 0.)

If this flag is set,the SI and DI will be decremented when executing most of the string instructions(e.g. MOVS family,CMPS family,STOS and LODS family etc.).When the operands are 8-bit ones,they will be decremented by 1 at every loop,and 16-bit for 2,and 32-bit for 4,etc.,respectively.If the DF is cleared,they will be incremented with an appropriate value.
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

O, thx!
Post Reply