kinit() not assembling under nasm

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
unknown user

kinit() not assembling under nasm

Post by unknown user »

hi. i'm having some problems getting my pmode/initial-task function to assemble. i'm using nasm, but i don't know enough about nasm to write good nasm code i guess. i'm getting wierd errors like "negative times -114 not allowed", and i didn't even make a times operator negative. can someone tell me what i'm doing wrong?
i tried to post it with the file uploaded, but it told me that a file with the same name was already uploaded, so i'm pasting into here.

Code: Select all

init:
;segment descriptor
struc segment_descriptor
        .seg_length0_15 resw 0 ;low word of segment length
        .base_addr0_15 resw 0 ;low word of base address
        .base_addr16_23 resb 0 ;low byte of high word of base address
        .flags resb 0 ;segment type and misc. flags
        .access resb 0 ;highest nibble of segment length and access flags
        .base_addr24_31 resb 0 ;highest byte of base address
endstruc
;interrupt descriptor
struc interrupt_descriptor
        .offset0_15 resw 0 ;low word of handler offset
        .selector0_15 resw 0 ;segment selector
        .zero_byte resb 0 ;unused
        .flags resb 0 ;flags
        .offset16_31 resw 0 ;high word of handler offset
endstruc
;gdt data
gdt_reg dw gdt_size,0,0
dummy_dscr:
istruc segment_descriptor 
   resw 0
   resw 0
   resb 0
   resb 0
   resb 0
iend
code32_dscr:
istruc segment_descriptor 
   resw 0ffffh
   resw 0
   resw 0
   resb 9ah
   resb 0cfh
   resb 0
iend
data32_dscr:
istruc segment_descriptor 
   resw 0ffffh
   resw 0
   resw 0
   resb 92h
   resb 0cfh
   resb 0
iend
core32_dscr:
istruc segment_descriptor 
   resw 0ffffh
   resw 0
   resw 0
   resb 9ah
   resb 0
   resb 0
iend
data16_dscr:
istruc segment_descriptor 
   resw 0ffffh
   resw 0
   resw 0
   resb 92h
   resb 0
   resb 0
iend
gdt_size=-$(dummy_dscr)
;task selector
taskselector:
task_backlink resw 0,0

task_esp0 resd 0
task_ss0 resw 0,0

task_esp1 resd 0
task_ss1 resw 0,0

task_esp2 resd 0
tasl_ss2 resw 0,0

task_cr3 resd 0
task_eip resd 0
task_eflags resd 0
task_eax resd 0
task_ecx resd 0
task_edx resd 0
task_ebx resd 0
task_esp resd 0
task_ebp resd 0
task_esi resd 0
task_edi resd 0

task_es resw 0,0
task_cs resw 0,0
task_ss resw 0,0
task_ds resw 0,0
task_fs resw 0,0
task_gs resw 0,0

task_idt resw 0,0
task_trap resw 0
task_iomapbase resw 0

task_iobitmap times 128 resb 0
endtaskselector1:
systemtaskselector equ $-gdt_reg
systemtaskdescriptor:
   resw 103 ;limit/length
   resb 0 ;base 0
   resb 0 ;base 0
   resb 10001001b ;p=1, dpl=00, dt=0, available (1,0,0,0,1001)
   resb 01000000b ;g=1, d=1, 0, avl=0, 1111=f: limit/length (1,1,0,0,1111)
   resb 0 ;base 0
endsystaskdesc: 
lgdt [fword ds:gdt_reg]
cli
mov eax,cr0
or al,1
mov cr0,eax
jmp start32
start32:
mov ax, systemtaskselector
ltr ax
ret
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:kinit() not assembling under nasm

Post by Pype.Clicker »

Code: Select all

systemtaskselector equ $-gdt_reg
is the root of your problem, imho ... but as i don't exactly get what the hell you're trying to do with all your structs, etc, i hardly can say what you should write instead.

Code: Select all

gdt_size=-$(dummy_dscr)
looks pretty weird too.

$-<label> is supposed to be the offset from the label to the current position.
unknown user

Re:kinit() not assembling under nasm

Post by unknown user »

errors (with $-dummy_dscr instead of -$dummy_dscr):

Code: Select all

init.asm:37: TIMES value -359 is negative
init.asm:46: TIMES value -351 is negative
init.asm:55: TIMES value -152 is negative
init.asm:64: TIMES value -144 is negative
init.asm:65: parser: instruction expected
init.asm:113: parser: expecting ]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:kinit() not assembling under nasm

Post by Pype.Clicker »

one think you should do is declare "GDTREG" *after* your GDt so that the gdt size can be computed when the GDTREG is assembled (and no longer need 2 passes).

i also think you get "resb" wrong:

while 'db <value>' reserves a byte in the current section and give it the declared <value>, "resb <amount>" reserves <amount> bytes and doesn't give them any value.

thus "resb 0" does nothing but generating problems.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:kinit() not assembling under nasm

Post by df »

the old nasm (0.97 or 98) used to give me mega problems with istrtuc so much so i stopped using istruc . it was too much hassle.
-- Stu --
unknown user

Re:kinit() not assembling under nasm

Post by unknown user »

Pype.Clicker wrote: while 'db <value>' reserves a byte in the current section and give it the declared <value>, "resb <amount>" reserves <amount> bytes and doesn't give them any value.

thus "resb 0" does nothing but generating problems.
ah. ok. that's probably the problem ^^;. people on EFnet #asm keep telling me that db doesn't reserve a byte in nasm. shame on them.
Tim

Re:kinit() not assembling under nasm

Post by Tim »

The people in Freenode #osdev wouldn't have told you that. :)
unknown user

Re:kinit() not assembling under nasm

Post by unknown user »

ok. i took out all the istrucs and fixed everything else, but there's one problem. nasm doesn't recognize the metacommand "fword".
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:kinit() not assembling under nasm

Post by Pype.Clicker »

no, and there's no need for a fword, anyway. If you want to make a lgdt command or something alike, just use lgdt[memory address].

size information in nasm are only required when you use a memory operand and a constant operand, so that nasm know what size your memory operand is.
unknown user

Re:kinit() not assembling under nasm

Post by unknown user »

i fixed it, but i'm getting even more errors. current code:

Code: Select all

init:
;segment descriptor
struc segment_descriptor
        .seg_length0_15 dw 0 ;low word of segment length
        .base_addr0_15 dw 0 ;low word of base address
        .base_addr16_23 db 0 ;low byte of high word of base address
        .flags db 0 ;segment type and misc. flags
        .access db 0 ;highest nibble of segment length and access flags
        .base_addr24_31 db 0 ;highest byte of base address
endstruc
;interrupt descriptor
struc interrupt_descriptor
        .offset0_15 dw 0 ;low word of handler offset
        .selector0_15 dw 0 ;segment selector
        .zero_byte db 0 ;unused
        .flags db 0 ;flags
        .offset16_31 dw 0 ;high word of handler offset
endstruc
;gdt data
gdt_reg:
        dw 0x00ff
        dd gdt_reg
        dw 0
        dw 0x0000,0x0000,0x0000,0x0000
        dw 0xffff,0x0000,0x9b00,0x00ef
        dw 0xffff,0x0000,0x9300,0x008f
gdt_reg_end:
;task selector
taskselector:
task_backlink dw 0,0

task_esp0 dd 0
task_ss0 dw 0,0

task_esp1 dd 0
task_ss1 dw 0,0

task_esp2 dd 0
tasl_ss2 dw 0,0

task_cr3 dd 0
task_eip dd 0
task_eflags dd 0
task_eax dd 0
task_ecx dd 0
task_edx dd 0
task_ebx dd 0
task_esp dd 0
task_ebp dd 0
task_esi dd 0
task_edi dd 0

task_es dw 0,0
task_cs dw 0,0
task_ss dw 0,0
task_ds dw 0,0
task_fs dw 0,0
task_gs dw 0,0

task_idt dw 0,0
task_trap dw 0
task_iomapbase dw 0

task_iobitmap times 128 db 0
endtaskselector1:
systemtaskselector equ $-taskselector
systemtaskdescriptor:
   dw 103 ;limit/length
   db 0 ;base 0
   db 0 ;base 0
   db 10001001b ;p=1, dpl=00, dt=0, available (1,0,0,0,1001)
   db 01000000b ;g=1, d=1, 0, avl=0, 1111=f: limit/length (1,1,0,0,1111)
   db 0 ;base 0
endsystaskdesc: 
lgdt [gdt_reg]
cli
mov eax,cr0
or al,1
mov cr0,eax
jmp start32
start32:
mov ax, [systemtaskselector]
ltr ax
ret
unknown user

Re:kinit() not assembling under nasm

Post by unknown user »

got it to assemble. thanks, guys ^^;.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:kinit() not assembling under nasm

Post by Pype.Clicker »

if you have a few sheet of paper to use, i would suggest you to print the NASM manual and go through it if you plan to use assembler for a bit more than just the bootloader. Nasm's preprocessor is *very* powerful (much more than GCC's one, for instance)
Post Reply