summaryrefslogtreecommitdiff
path: root/boot/segdesc.inc
blob: b4d14dcc990f822d2b74816d2962e37eb027d6dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; segment type
SEG_ACCESSED     = 0001b
SEG_CODE_READ    = 0010b
SEG_DATA_WRITE   = 0010b
SEG_CODE_CONFORM = 0100b
SEG_DATA_EXPDOWN = 0100b
SEG_EXECUTE      = 1000b

; privilege level
SEG_PRIV0 = (00b shl 0x05)
SEG_PRIV1 = (01b shl 0x05)
SEG_PRIV2 = (10b shl 0x05)
SEG_PRIV3 = (11b shl 0x05)

; other flags
SEG_DESCTYPE = (1b shl 0x04) ; descriptor type
SEG_PRES     = (1b shl 0x07) ; present
SEG_SAVL     = (1b shl 0x0C) ; available for system use
SEG_LONG     = (1b shl 0x0D) ; long mode
SEG_SIZE     = (1b shl 0x0E) ; size
SEG_GRAN     = (1b shl 0x0F) ; granularity

; segment descriptor flag sets for convenience
GDT_CODE_32 = SEG_DESCTYPE or SEG_PRES or SEG_SIZE or SEG_GRAN or SEG_EXECUTE or SEG_CODE_READ
GDT_DATA_32 = SEG_DESCTYPE or SEG_PRES or SEG_SIZE or SEG_GRAN or SEG_DATA_WRITE
GDT_CODE_64 = SEG_DESCTYPE or SEG_PRES or SEG_LONG or SEG_EXECUTE or SEG_CODE_READ
GDT_DATA_64 = SEG_DESCTYPE or SEG_PRES or SEG_LONG or SEG_DATA_WRITE

struc seg_desc base*, limit*, flag* {
	assert 0x0 <= limit & limit <= 0x000fffff
	assert 0x0 <= base  & base  <= 0xffffffff
	assert (flag or 0xf0ff) = 0xf0ff

	. dq ((limit shl 0x20) and 0x000f000000000000) or \
	     ((flag  shl 0x28) and 0x00f0ff0000000000) or \
	     ((base  shl 0x10) and 0x000000ff00000000) or \
	     ((base  shl 0x20) and 0xff00000000000000) or \
	     ((base  shl 0x10) and 0x00000000ffff0000) or \
	     ((limit shl 0x00) and 0x000000000000ffff)
}