diff options
Diffstat (limited to 'boot/segdesc.inc')
-rw-r--r-- | boot/segdesc.inc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/boot/segdesc.inc b/boot/segdesc.inc new file mode 100644 index 0000000..b4d14dc --- /dev/null +++ b/boot/segdesc.inc @@ -0,0 +1,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) +} |