flat assembler
Message board for the users of flat assembler.

Index > Main > Some questions: [edi+ecx*3] | PUSH | RAM limit | IDT PIT

Goto page Previous  1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
how do i convert absolute address to seg:offset and seg:offset to absolute?

its:
Code:
abs = seg * 16 + offset
0x00007DFF = seg * 16 + 0
seg = 0x00007DFF / 16
seg = 0x07DF
; --
abs = seg * 16 + offset
abs = 0x07C0 * 16 + 0xFFFF
abs = 0x0001AA7F    
?

If its right, lets get this abs address range: 0x00007C00 - 0x00007DFF (512 bytes wide). The last address (7DFF) is in a different segment than 7C00, right?

if its right, when i do:
Code:
mov ax,0x07C0
mov ss,ax
mov sp,0xFFFF    

isn't me pointing sp to another segment beyond 0x07C0? that could be dangerous, no? So isn't better to do:
Code:
mov ax,0x07C0
mov ss,ax
mov sp,512-1-2 ; from seg 0x07C0 plus 512-1-2(bios signature) offset    

so i ensure my stack is inside that 512 bytes wide range (hence same seg.).
Post 07 Mar 2011, 12:22
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
it is not absolute, but linear!!!

then
linear = segment*16+offset

segment = linear/16 and 0ffffh
offset = linear -( segment*16)

as i can see, you are planing on RM segments referencing in GDT, then, it is not hard.*
just set bit G to 0 (granularity = 1 byte)
limit=0ffffh
base = segment*16

and you have the replicate of RM segment in PM.

it would be good for you to read some sources, like the one from dexos that supports this feature.
and read some sources about Unreal mode.
Post 07 Mar 2011, 13:00
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
> it is not absolute, but linear!!!
yeah sorry, thats what i meant Razz

> as i can see, you are planing on RM segments referencing in GDT, then, it is not hard.*
> and you have the replicate of RM segment in PM.

sorry but i didnt understand. what do you mean?
Post 07 Mar 2011, 13:10
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
will this work (ok it works, but i wanna know if its right):

Code:
; before here i do the boot, etc.,etc., enter in PM, then jmp here:

use32
align 4

    pmode:

        mov eax,0x10
        mov ds,ax
        mov es,ax
        mov fs,ax
        mov gs,ax
        mov ss,ax
        mov esp,kernel32_stack_addr

; Then i move the kernel to a new address

        mov esi,kernel32
        mov edi,kernel32_addr ; kernel32_addr = 0x0010'0000 (after the RM's 1Mb)
        mov ecx,kernel32_size
        rep movsd

        jmp kernel32_addr       ; Then go to execute kernel!


    kernel32:    ; copying from here ahead... to kernel32_addr 

        hlt
        jmp $      
Post 07 Mar 2011, 16:43
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
if you show us how you define kernel32_addr.
a) if kernel32_addr dd 100000h
then your code is wrong
b) if org 100000h \ kernel32_addr:
or
label kernel32_addr at 100000h
then your code might be correct.


Something to think about: My thinking is that you don't need to move your kernel around. If you load your kernel from a disk then you can already load it at the correct address. And when you have your bootloader and kernel tied together and you manage to load them at some address, you don't need to move anything because it already fits nicely at that address.
If your only concern is that the starting address of your kernel should look good, then go ahead Very Happy
Post 07 Mar 2011, 16:54
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
here:

Code:
kernel_addr = 0x0010'0000 ; The 1Mb right after RM ( the address the kernel starts )    


Quote:
Something to think about: My thinking is that you don't need to move your kernel around. If you load your kernel from a disk then you can already load it at the correct address. And when you have your bootloader and kernel tied together and you manage to load them at some address, you don't need to move anything because it already fits nicely at that address.

But lets suppose my OS get bigger, lets say, 3Mb. There is no space to load it under RM address. So to avoid headaches ahead i just wanna copy it above RM addr, then i can use that RM space to do the routine to copy it out there. What do you think? Smile

_________________
Sorry if bad english.
Post 07 Mar 2011, 17:22
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
loading the kernel above 1MB is not a bad idea, because it lets the real mode bios interface as is, and then, lets you return to rm without problem.
Post 08 Mar 2011, 09:53
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
however, if i load to another place, my variables (db,dd,..) won't lost their references?
Post 08 Mar 2011, 13:22
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
Code:
    x = 11111111b    1001b    0100b
not x = 00000000b    0110b    1011b
; ...
    x = 11111111b    1001b    0100b
neg x = 01111111b    0001b    1100b
    

is that right?

_________________
Sorry if bad english.
Post 09 Mar 2011, 11:36
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
not just reverse bits. 0 became 1, and 1 became 0.
its equivalent to xor by -1.

neg will subtract the value trom 0.
so neg ax is equivalent to:
not ax
inc ax

inc is because when reverse bits (by not) you end up either with too low value or too large value. Its because you subtract from 0 wich is a part of positive half of variable.
Post 09 Mar 2011, 12:48
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
so:
Code:
neg 1111b = 0 - 1111b + 1 = 0001b ?
neg 0100b = 0 - 0100b + 1 = 1100b ?
    


that means negative numbers become positive and positive, negative?
Post 09 Mar 2011, 13:32
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
yes.
Post 09 Mar 2011, 15:13
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
but 0 - 0001b = 1110 + 1 = 1111b this is not -1, but -7.
Post 09 Mar 2011, 16:25
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
no way.

you should consider the MSb as the sign bit, but not as a minus sign, just as an offset.

instead of being equal to 2^n, it is equal to -(2^n) that's why it is a bit sign;

then, in you example, the MSb is equal to -8
-8 + 7 = -1.
it is no more complicated as that.
Post 09 Mar 2011, 16:30
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
i think i got it. You mean 1111b is not -7 but -1 (back to forward):

1110 = -2 (-8+6 = -2)
1101 = -3 (-8+5 = -3)
1100 = -4 (-8+4 = -4)
and so on..

but only if SF is set, right?
Post 09 Mar 2011, 17:19
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
not only if SF is set, just because MSbit is equal to -(2^n)
Post 09 Mar 2011, 20:15
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
question: how do you call the fact processor can process 32/64bit in a single step?

also: lets suppose this code has 4 bytes:
Code:
inc eax
inc ecx
inc ebx    

it means that in a 32 bit CPU it will execute these 3 instructions in single step(clock?)?
Post 11 Mar 2011, 15:12
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
basically, it is paralelism, using pipelines.
Post 11 Mar 2011, 15:56
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee
thanks.

please refresh my mind, a value is stored into memory backward (big endian), and into a register the value stay the same (lil endian), right?
Code:
mov   eax,0x00FF4411  ;   eax = 0x00FF4411
mov [mem],0x00FF4411  ; [mem] = 0x1144FF00

db 0, 1    ; mem = 00, 01
dw 0x1122  ; mem = 22, 11
    
Post 11 Mar 2011, 23:46
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
in fact, the values are not stored backward, only the way we (human) read it is a source of confusion. but in fact, the first byte should be the least significant.

the little endian is the more logical way to store bytes (more logical than big endian)

because, the lower adress is the least significant byte.
Post 12 Mar 2011, 00:25
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.