value of CS at compile time
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:value of CS at compile time
you don't.
if you're writing a .COM file, you just assume CS is set to the program segment by the DOS
if you're writing a real-mode .EXE file, your program might be relocated by the EXE loader, so all you can do is have mov ax,cs ; mov [my_code],ax at run time
If you're writing some pmode program (linux, windows, whatever), your model is usually flat (only one code segment) so you don't care
if you're writing a .COM file, you just assume CS is set to the program segment by the DOS
if you're writing a real-mode .EXE file, your program might be relocated by the EXE loader, so all you can do is have mov ax,cs ; mov [my_code],ax at run time
If you're writing some pmode program (linux, windows, whatever), your model is usually flat (only one code segment) so you don't care
Re:value of CS at compile time
the larger problem is what do I place in the selector word of the IDT?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:value of CS at compile time
you should know where is your code segment in the GDT. just take that selector.
Re:value of CS at compile time
in my bootloader, my GDT looks like this:
[bits 16]
org 0x7C00
start:
jmp boot
GDT
Null_Sel equ $-GDT
dd 0x0
dd 0x0
OS_Code equ $-GDT
dw 0xFFFF ; segment limit
dw 0x0 ; base address
db 0x0 ; base
db 0x9A ; segment data
db 0xCF
db 0x0 ; base
OS_Data equ $-GDT
dw 0xFFFF ; segment limit
dw 0x0 ; base address
db 0x0 ; base
db 0x92 ; segment data
db 0xCF
db 0x0 ; base
GDTEnd
boot:
so how would i calculate the address of OS_Code?
thanks,
Mr Spam
[bits 16]
org 0x7C00
start:
jmp boot
GDT
Null_Sel equ $-GDT
dd 0x0
dd 0x0
OS_Code equ $-GDT
dw 0xFFFF ; segment limit
dw 0x0 ; base address
db 0x0 ; base
db 0x9A ; segment data
db 0xCF
db 0x0 ; base
OS_Data equ $-GDT
dw 0xFFFF ; segment limit
dw 0x0 ; base address
db 0x0 ; base
db 0x92 ; segment data
db 0xCF
db 0x0 ; base
GDTEnd
boot:
so how would i calculate the address of OS_Code?
thanks,
Mr Spam
Re:value of CS at compile time
Hello!
To get the current value of CS in AX do the following instructions:
The value of cs isn't available since compile time. But if you have it in ax you can use it anywhere.
To get the current value of CS in AX do the following instructions:
Code: Select all
push cs
pop ax
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:value of CS at compile time
OS_code is actually computed by the assembler : $ (current_position) - GDT = 8,
so you can safely assume OSCODE==8 in your whole kernel.
so you can safely assume OSCODE==8 in your whole kernel.