Fork me on GitHub

root/include/fiwix/segments.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * fiwix/include/fiwix/segments.h
   3  *
   4  * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #ifndef _FIWIX_SEGMENTS_H
   9 #define _FIWIX_SEGMENTS_H
  10 
  11 #define KERNEL_BASE_ADDR        0xC0000000
  12 #define KERNEL_ENTRY_ADDR       0x100000
  13 
  14 #define KERNEL_CS       0x08    /* kernel code segment */
  15 #define KERNEL_DS       0x10    /* kernel data segment */
  16 #define USER_CS         0x18    /* user code segment */
  17 #define USER_DS         0x20    /* user data segment */
  18 #define TSS             0x28    /* TSS segment */
  19 
  20 
  21 #ifndef ASM_FILE
  22 
  23 #include <fiwix/types.h>
  24 
  25 #define NR_GDT_ENTRIES  6       /* entries in GDT descriptor */
  26 #define NR_IDT_ENTRIES  256     /* entries in IDT descriptor */
  27 
  28 /* low flags of Segment Descriptors */
  29 #define SD_DATA         0x02    /* DATA Read/Write */
  30 #define SD_CODE         0x0A    /* CODE Exec/Read */
  31 
  32 #define SD_32INTRGATE   0x0E    /* 32-bit Interrupt Gate (0D110) */
  33 #define SD_32TRAPGATE   0x0F    /* 32-bit Trap Gate (0D111) */
  34 
  35 #define SD_CD           0x10    /* 0 = system / 1 = code/data */
  36 #define SD_DPL0         0x00    /* priority level 0 (kernel) */
  37 #define SD_DPL3         0x60    /* priority level 3 (user) */
  38 #define SD_PRESENT      0x80    /* segment present or valid */
  39 
  40 /* high flags Segment Descriptors */
  41 #define SD_OPSIZE32     0x04    /* 32-bit code and data segments */
  42 #define SD_PAGE4KB      0x08    /* page granularity (4KB) */
  43 
  44 /* low flags of the TSS Descriptors */
  45 #define SD_TSSPRESENT   0x89    /* TSS present and not busy flag */
  46 
  47 #define USR_PL          3       /* User Privilege Level */
  48 
  49 /* EFLAGS */
  50 #define EF_IOPL         12      /* IOPL bit */
  51 
  52 struct desc_r {
  53         __u16 limit;
  54         __u32 base_addr;
  55 } __attribute__((packed));
  56 
  57 struct seg_desc {
  58         unsigned sd_lolimit : 16;       /* segment limit 0-15 bits */
  59         unsigned sd_lobase  : 24;       /* base address  0-23 bits */
  60         unsigned sd_loflags :  8;       /* flags (P, DPL, S and TYPE) */
  61         unsigned sd_hilimit :  4;       /* segment limit 16-19 bits */
  62         unsigned sd_hiflags :  4;       /* flags (G, DB, 0 and AVL) */
  63         unsigned sd_hibase  :  8;       /* base address 24-31 bits */
  64 } __attribute__((packed));
  65 
  66 struct gate_desc {
  67         unsigned gd_looffset: 16;       /* offset 0-15 bits */
  68         unsigned gd_selector: 16;       /* segment selector */
  69         unsigned gd_flags   : 16;       /* flags (P, DPL, TYPE, 0 and NULL) */
  70         unsigned gd_hioffset: 16;       /* offset 16-31 bits */
  71 } __attribute__((packed));
  72 
  73 void gdt_init(void);
  74 void idt_init(void);
  75 
  76 #endif /* ! ASM_FILE */
  77 
  78 #endif /* _FIWIX_SEGMENTS_H */

/* [previous][next][first][last][top][bottom][index][help] */