Memory read errors

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
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Memory read errors

Post by GAT »

I am loading data into RAM at the end of my kernel, currently location 0:242f and up.
an entry looks like this:

Code: Select all

*1 11name0*
(numbers literal, not '1', and without space in between)
My problem is with the second and third byte.
They represent the boundaries of a chunk of free RAM, followed by a label.
They are stored correctly, as seen through a dump, but when I go to retrieve them, I get numbers far off from what I put in.
here is the code:

Code: Select all

	mov si,[tablestart]
.find
	cmp byte [si],'*'
	je .entry
	add si,1
	cmp si,[tablend]
	jge .done
	jmp .find
.entry
	add si,3
	call compare
	jc .found
	jmp .entry
.found
	sub si,1
	mov bx,[si]	
	sub si,1
	mov ax,[si]
.done	
ret

tablestart is 0:242f, tablend is 0:2461
compare just compares a the label pointed to in si to the label in di, both 0 terminated strings, and sets carry if equal.
Any ideas?
Last edited by GAT on Tue Jan 10, 2012 8:47 pm, edited 1 time in total.
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Memory read errors

Post by thepowersgang »

You appear to lack the required knowledge, I suggest you go read up on assembly a bit more. .entry is not used, you are taking the values at tablestart and tableend (instead of the addresses, which is what I assume you intend to do).

I suggest using something like the bochs debugger to single step your code and ensure that it is doing what you expect it to do.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Memory read errors

Post by GAT »

I do want to take the data in tablestart and tablend, I set the value of these at boot to be what I want.
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Memory read errors

Post by thepowersgang »

Ok then, forgive me for my assumption. However, my other points still stand, use the bochs debugger to see exactly what your code is doing, because I suspect you have made a mistake somewhere in that.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Memory read errors

Post by Brendan »

Hi,

If I'm reading this right; at the end of your code "mov bx,[si]" should move the values for the ASCII characters " 1" into BX. These two ASCII characters have the values 0x20 (space character) and 0x31 (one character), so BX would equal 0x3120. After that you decrease SI by one and do "mov ax,[si]" which should load the two ASCII characters "1 " into AX, so AX would equal 0x2031.

Notes:
  • I'm assuming that before any of the code is executed, SI points to the ASCII string "*1 11name0*"
  • I'm assuming that "call compare" doesn't change the value in SI, DS, or the contents of memory
  • I'm assuming that the last 2 reads ("mov bx,[si]" and "mov ax,[si]") are the reads you think are returning something wrong
  • You don't say what values actually are read, so I don't know if you are reading the values 0x3120 and 0x2031 and think they're wrong, or if you're reading completely different values
  • Brendan Trotter does not make, and expressly disclaims any, representations or warranties, express or implied, regarding this code analysis 8)

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Memory read errors

Post by GAT »

Actually, I put the example in ascii, but should be
*☺♂name*
The numbers with spaces just seemed more understandable.
Example:
*☺♂name*
si pointing to the first *, I get
ax = 0xB01
bx = 0x740B

It is the last two reads that I believe are the issue.
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Memory read errors

Post by Brendan »

Hi,
GAT wrote:Actually, I put the example in ascii, but should be
*☺♂name*
The numbers with spaces just seemed more understandable.
Example:
*☺♂name*
si pointing to the first *, I get
ax = 0xB01
bx = 0x740B

It is the last two reads that I believe are the issue.
In that case, your string is the following bytes:
0x2A, 0x01, 0x0B, 0x6E, 0x61, 0x6D, 65, 0x2A

The "mov bx,[si]" would equal 0x6E0B, from:
0x2A, 0x01, 0x0B, 0x6E, 0x61, 0x6D, 65, 0x2A

And the "mov ax,[si]" would equal 0x0B01, from:
0x2A, 0x01, 0x0B, 0x6E, 0x61, 0x6D, 65, 0x2A

The only problem is the value in BX, which should be 0x6E0B and not 0x740B. Are you sure the string isn't something like "*☺♂tame*"?


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
GAT
Member
Member
Posts: 75
Joined: Wed Nov 30, 2011 9:51 pm
Contact:

Re: Memory read errors

Post by GAT »

Got It!
Just had to put si in al and bl. You were right Brendan!
d3: virtualizing kernel in progress
https://github.com/WizardOfHaas/d3/
Post Reply