As I said this removes the need to hard code stuff. The other such pet peeve of mine is with the gdt:
This is from the wiki:
Code: Select all
reloadSegments:
; Reload CS register containing code selector:
JMP 0x08:reload_CS ; 0x08 points at the new code selector
.reload_CS:
; Reload data segment registers:
MOV AX, 0x10 ; 0x10 points at the new data selector
MOV DS, AX
MOV ES, AX
MOV FS, AX
MOV GS, AX
MOV SS, AX
RET
As you can see here, the long jump has a hardcoded 0x08. Can we remove it? Yeah if we use long return instead. This below is AT&T syntax but does basically the same.
Code: Select all
.global cpu_setgdt
cpu_setgdt:
movl 4(%esp), %eax
lgdt (%eax)
movw 12(%esp), %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss
pushl 8(%esp)
pushl (%esp)
lret
This would be the prototype for the above function:
Code: Select all
void cpu_setgdt(void *pointer, unsigned int code, unsigned int data);
Calling it with code = 0x08 and data = 0x10 would match the example from the wiki.
Do with it as you please. It's just a solution for those who don't like hard coded values.