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.
[global gdt_flush] ; make 'gdt_flush' accessible from C code
[extern gp] ; tells the assembler to look at C code for 'gp'
; this function does the same thing of the 'start' one, this time with
; the real GDT
gdt_flush:
lgdt [gp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2
If I used the extern keyword in C, I would declare the variable exactly as it was originally declared. So if it wasn't a pointer, it wouldn't be declared as a pointer when I used the extern keyword. However, in the above assembly code, gp is actually a pointer, right? Otherwise we'd be calling lgdt gp instead of lgdt [gp].
assembler doesn't really care if that's a pointer or not.
assembly instruction syntax generally doesn't depend on what the variable type is - in reality, a variable type is dependent on how you use it in the instructions.
in this case gp is a pointer to gdt structure, so your assumption is correct, this time.
Using an extern simply means that you don't have to define that particular label in the current source file. It still acts as if it were a label.
"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 ]
Every name, variable function or otherwise in C is just a number referring to where in memory it is stored, the type you associate with it defines the amount of space that is actually reserved there. In assembly every use of a label results in it being substituted with the corresponding address. The only difference is that assembly knows no data types.
; space for an entire struct
bar: times LENGTH_OF_MYSTRUCT_T DB 0
; space for just a pointer
foo: DD 0
(...)
extern bar
extern foo
; write at foo, the address of bar
mov [foo], bar
; copy to the location stored in foo, the content of bar.
; note the two memory indirections for foo and only one for bar.
mov edi, [foo]; mov esi, bar; mov ecx, LENGTH_OF_MYSTRUCT_T; rep movsb es:[edi], ds:[esi];
"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 ]