xref: /aosp_15_r20/external/coreboot/src/arch/x86/gdt_init.S (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3.code32
4
5.section .init, "ax", @progbits
6
7.section .init._gdt_, "ax", @progbits
8
9	.globl gdt_init
10gdt_init:
11	lgdt	%cs:gdtptr
12	ret
13
14.previous
15	.align	4
16.globl gdtptr
17gdtptr:
18	.word	gdt_end - gdt -1 /* compute the table limit */
19	.long	gdt		 /* we know the offset */
20
21#if ENV_X86_64
22.code64
23.section .init._gdt64_, "ax", @progbits
24	.globl gdt_init64
25gdt_init64:
26	movabs	$gdtptr64, %rax
27	lgdt	(%rax)
28	ret
29
30.previous
31	.align	4
32.globl gdtptr64
33gdtptr64:
34	.word	gdt_end - gdt -1 /* compute the table limit */
35	.quad	gdt		 /* we know the offset */
36#endif
37
38	.align	4
39gdt:
40	/* selgdt 0, unused */
41	.word	0x0000, 0x0000		/* dummy */
42	.byte	0x00, 0x00, 0x00, 0x00
43
44	/* selgdt 0x08, flat code segment */
45	.word	0xffff, 0x0000
46	.byte	0x00, 0x9b, 0xcf, 0x00 /* G=1 and 0x0f, So we get 4Gbytes
47					  for limit */
48
49	/* selgdt 0x10,flat data segment */
50	.word	0xffff, 0x0000
51	.byte	0x00, 0x93, 0xcf, 0x00
52
53	/* selgdt 0x18, flat code segment (64-bit) */
54	.word   0xffff, 0x0000
55	.byte   0x00, 0x9b, 0xaf, 0x00
56
57gdt_end:
58