/*
* This file is part of the Corax operating system.
- * Copyright (C) 2016 Matthias Kruk
+ * Copyright (C) 2016-2019 Matthias Kruk
*
* Corax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define SD_TYPE_CALL_GATE 0x8c00
#define SD_TYPE_TRAP_GATE 0x8f00
+#define DPL(n) ((n) << 13)
#define DPL_KERNEL 0
#define DPL_DRIVER (1 << 13)
#define DPL_SYSTEM (2 << 13)
#define RPL_SYSTEM 2
#define RPL_USER 3
-#define KERNEL_DATA 0x10
-#define KERNEL_CODE 0x08
+#define SEGM_CS(n) (0x10 * (n) + 0x08 | (n))
+#define SEGM_DS(n) (0x10 * (n) + 0x10 | (n))
-#define USER_DATA 0x23
-#define USER_CODE 0x1b
+#define KERNEL_CODE SEGM_CS(RPL_KERNEL)
+#define KERNEL_DATA SEGM_DS(RPL_KERNEL)
+#define DRIVER_CODE SEGM_CS(RPL_DRIVER)
+#define DRIVER_DATA SEGM_DS(RPL_DRIVER)
+#define SYSTEM_CODE SEGM_CS(RPL_SYSTEM)
+#define SYSTEM_DATA SEGM_DS(RPL_SYSTEM)
+#define USER_CODE SEGM_CS(RPL_USER)
+#define USER_DATA SEGM_DS(RPL_USER)
#define GDT_ENTRIES 16
#define IDT_ENTRIES 256
#define TSS_OFFSET (IDT_OFFSET + (IDT_ENTRIES * 8))
#define TSS_SIZE 102
-#define TSS_SEL (0x28 | RPL_USER)
+#define TSS_SEL (0x48 | RPL_USER)
#define CR0_PG_BIT 0x80000000
#define CR4_PSE_BIT 0x00000010
#define EXC_VECTOR0 0x00
#define INT_VECTOR0 0x40
-#define SYS_VECTOR0 0xCC
+#define SYS_VECTOR0 SYS_VECTOR_CORAX
+
+#define SYS_VECTOR_CORAX 0xCC
+
+#if FEATURE(POSIX)
+#define SYS_VECTOR_POSIX 0x80
+#endif /* FEATURE(POSIX) */
#define NUM_EXC_VECTORS 21
#if CONFIG_APIC == 1
#endif /* CONFIG_APIC */
#define NUM_SYS_VECTORS 1
-#define CORAX_SYS_VECTOR 0xCC
-
/* i8259 definitions */
#define PIC1_BASE 0x20
#define PIC1_COMM PIC1_BASE
/*
* This file is part of the Corax operating system.
- * Copyright (C) 2016 Matthias Kruk
+ * Copyright (C) 2016-2019 Matthias Kruk
*
* Corax is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#endif /* CONFIG_APIC */
.extern _sys_entryCC
+#if FEATURE(POSIX)
+.extern _sys_entryPX
+#endif /* FEATURE(POSIX) */
/* this table is used to fill the IDT in arch_init(),
saves us ~260B of memory, compared with an unrolled loop */
movl $_cpu, %eax
addl $GDT_OFFSET, %eax
+
+ /* create zero entry */
movl $0, (%eax)
movl $0, 4(%eax)
- addl $8, %eax
+ /* create code segments */
+ addl $8, %eax
movl $DPL_KERNEL, 16(%esp)
movl $0xffffffff, 12(%esp)
movl $0, 8(%esp)
movl %eax, (%esp)
call _segment_descriptor_set
- movl $SD_TYPE_DATA, 4(%esp)
- addl $8, (%esp)
- call _segment_descriptor_set
+ addl $16, (%esp)
+ movl $DPL_DRIVER, 16(%esp)
+ call _segment_descriptor_set
- movl $DPL_USER, 16(%esp)
- addl $16, (%esp)
- call _segment_descriptor_set
+ addl $16, (%esp)
+ movl $DPL_SYSTEM, 16(%esp)
+ call _segment_descriptor_set
- movl $SD_TYPE_CODE, 4(%esp)
- subl $8, (%esp)
- call _segment_descriptor_set
+ addl $16, (%esp)
+ movl $DPL_USER, 16(%esp)
+ call _segment_descriptor_set
- addl $16, (%esp)
+ /* create data segments */
+ subl $40, (%esp)
+ movl $DPL_KERNEL, 16(%esp)
+ movl $SD_TYPE_DATA, 4(%esp)
+ call _segment_descriptor_set
+
+ addl $16, (%esp)
+ movl $DPL_DRIVER, 16(%esp)
+ call _segment_descriptor_set
+
+ addl $16, (%esp)
+ movl $DPL_SYSTEM, 16(%esp)
+ call _segment_descriptor_set
+
+ addl $16, (%esp)
+ movl $DPL_USER, 16(%esp)
+ call _segment_descriptor_set
+
+ /* add TSS entry */
+ addl $8, (%esp)
movl $SD_TYPE_TSS, 4(%esp)
movl $_cpu, %eax
addl $TSS_OFFSET, %eax
movl $TSS_SIZE, 12(%esp)
call _segment_descriptor_set
- movw $GDT_ENTRIES, %ax
- shlw $3, %ax
- addw $1, %ax
+ movw $((GDT_ENTRIES * 8) + 1), %ax
movw %ax, (%esp)
movl $_cpu, %eax
addl $GDT_OFFSET, %eax
movw %ax, %ss
ljmp $KERNEL_CODE, $_update_cs
.local _update_cs
- _update_cs:
+_update_cs:
movw $TSS_SEL, %ax
ltr %ax
_idt_fill_done:
*/
+#if FEATURE(POSIX)
+ /* add an entry for POSIX syscalls */
+ movl $_sys_entryPX, 12(%esp)
+ movl $_cpu, %eax
+ addl $(IDT_OFFSET + (SYS_VECTOR_POSIX * 8)), %eax
+ movl %eax, (%esp)
+ call _segment_descriptor_set
+#endif /* FEATURE(POSIX) */
+
/* add an entry for Corax syscalls */
+ movl $DPL_SYSTEM, 16(%esp)
movl $_sys_entryCC, 12(%esp)
- addl $((SYS_VECTOR0 - (INT_VECTOR0 + NUM_INT_VECTORS)) * 8), (%esp)
+ movl $_cpu, %eax
+ addl $(IDT_OFFSET + (SYS_VECTOR_CORAX * 8)), %eax
+ movl %eax, (%esp)
call _segment_descriptor_set
movw $((IDT_ENTRIES * 8) + 1), (%esp)