.byte 0b11111010 # Access: present | readable | ring3
.byte 0b10101111 # Flags: page_gran | long_mode, Limit[16:20]
.byte 0x00 # Base[24:32]
+.globl GDT.TSS
.set GDT.TSS, . - GDT
- .short TSS_SIZE & 0xFFFF # Limit[0:16]
+ .short (TSS_SIZE - 1) & 0xFFFF # Limit[0:16]
.short 0x0000 # Base[0:16] # TSS & 0xFFFF
.byte 0x00 # Base[16:24] # (TSS >> 16) & 0xFF
.byte 0b10001001 # Access
- .byte (0b0000 << 4) | ((TSS_SIZE >> 16) & 0xF) # Flags, Limit[16:20]
+ .byte (0b0000 << 4) | (((TSS_SIZE - 1) >> 16) & 0xF) # Flags, Limit[16:20]
.byte 0x00 # Base[24:32] # (TSS >> 24) & 0xFF
+ .int 0 # Base[32:63] # (TSS >> 32) & 0xFFFFFFFF
+ .int 0 # reserved
GDT.PTR:
.short . - GDT - 1
.quad GDT - KERNEL_VMA
or $1 << 31, %eax
mov %eax, %cr0
- # Setup TSS address in GDT
- mov $TSS - KERNEL_VMA, %eax
- shr $0, %eax
- and $0xFFFF, %eax
- mov %ax, GDT.TSS + GDT - KERNEL_VMA + 2
- mov $TSS - KERNEL_VMA, %eax
- shr $16, %eax
- and $0xFF, %eax
- mov %al, GDT.TSS + GDT - KERNEL_VMA + 4
- mov $TSS - KERNEL_VMA, %eax
- shr $24, %eax
- and $0xFF, %eax
- mov %al, GDT.TSS + GDT - KERNEL_VMA + 7
-
# Jump to 64 bits:
lgdt (GDT.PTR - KERNEL_VMA)
jmp $GDT.KERNEL_CODE, $.trampoline
mov $PML4T - KERNEL_VMA, %rax
mov %rax, %cr3
+ # Setup TSS address in GDT
+ movabs $TSS, %rax
+ shr $0, %rax
+ and $0xFFFF, %rax
+ mov %ax, GDT.TSS + GDT + 2
+ movabs $TSS, %rax
+ shr $16, %rax
+ and $0xFF, %rax
+ mov %al, GDT.TSS + GDT + 4
+ movabs $TSS, %rax
+ shr $24, %rax
+ and $0xFF, %rax
+ mov %al, GDT.TSS + GDT + 7
+ movabs $TSS, %rax
+ shr $32, %rax
+ mov %rax, GDT.TSS + GDT + 8
+
call _init
mov %r14, %rsi