This commit is contained in:
op52 2018-12-19 08:33:23 +08:00
parent 548852f8be
commit 10ebd0e3b9
No known key found for this signature in database
GPG Key ID: 326183D9B74E5C87
21 changed files with 646 additions and 1207 deletions

View File

@ -7,8 +7,8 @@ bits 64
; 2 int32: old value
; 3 int32: new value
; RETURNS uint32 value read
global arch_cmp_swp_32
arch_cmp_swp_32:
global cmp_swp_32
cmp_swp_32:
mov eax, esi
lock cmpxchg dword [rdi], edx
ret
@ -19,8 +19,8 @@ ret
; 2 int32: increment value
; 3 int32: new value
; RETURNS uint32 value read
global arch_fet_add_32:
arch_fet_add_32:
global fetch_add_32:
fetch_add_32:
lock xadd dword [rdi], esi
xor rax, rax
mov eax, esi

View File

@ -1,4 +1,4 @@
#include <arch/cpu.h>
#include "cpu.h"
#include <ke/cdef.h>
#define GDT_ENTRY_SIZE 8

41
arch/cpu.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <ke/cdef.h>
void KABI out_8(uint16 port, uint8 data);
void KABI out_16(uint16 port, uint16 data);
void KABI out_32(uint16 port, uint32 data);
uint8 KABI in_8(uint16 port);
uint16 KABI in_16(uint16 port);
uint32 KABI in_32(uint16 port);
void KABI flush_gdt(void *gdt_ptr, uint16 code_slct, uint16 data_slct);
void KABI flush_idt(void *idt_ptr);
void KABI flush_tss(uint16 tss_slct);
void KABI cpuid(uint32 *eax, uint32 *ebx, uint32 *ecx, uint32 *edx);
void KABI read_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
void KABI write_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
void KABI sti();
void KABI cli();
uint64 KABI read_cr8();
void KABI write_cr8(uint64 val);
uint64 KABI read_cr3();
void KABI write_cr3(uint64 val);
void KABI flush_tlb();

View File

@ -1,8 +1,8 @@
#include <ke/cdef.h>
#include <arch/cpu.h>
#include "cpu.h"
#include <arch/mem.h>
#include <arch/intr.h>
#include <arch/trap.h>
#include <arch/mlayout.h>
/**
@ -50,7 +50,7 @@
#define PT_ENTRY_NUM(vaddr) (((vaddr) >> 12) & 0x1FF)
void
arch_write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr)
write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr)
{
if (base == NULL)
{
@ -69,7 +69,7 @@ arch_write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr)
void*
arch_pmap_map(phys_addr paddr, usize size)
pmap_map(phys_addr paddr, usize size)
{
UNREFERENCED(size);
return (void*)(paddr + KERNEL_PMAP_VADDR);

View File

@ -1,5 +1,5 @@
#include <ke/cdef.h>
#include <arch/cpu.h>
#include "cpu.h"
#include <arch/mem.h>
#include <arch/print.h>
#include <ke/clib.h>

548
arch/trap.asm Normal file
View File

@ -0,0 +1,548 @@
%include "asm.inc"
extern intr_dispatcher
global intr_stub_array
section .data
bits 64
intr_stub_array:
dq intr_stub_0
dq intr_stub_1
dq intr_stub_2
dq intr_stub_3
dq intr_stub_4
dq intr_stub_5
dq intr_stub_6
dq intr_stub_7
dq intr_stub_8
dq intr_stub_9
dq intr_stub_10
dq intr_stub_11
dq intr_stub_12
dq intr_stub_13
dq intr_stub_14
dq intr_stub_15
dq intr_stub_16
dq intr_stub_17
dq intr_stub_18
dq intr_stub_19
dq intr_stub_20
dq intr_stub_21
dq intr_stub_22
dq intr_stub_23
dq intr_stub_24
dq intr_stub_25
dq intr_stub_26
dq intr_stub_27
dq intr_stub_28
dq intr_stub_29
dq intr_stub_30
dq intr_stub_31
dq intr_stub_32
dq intr_stub_33
dq intr_stub_34
dq intr_stub_35
dq intr_stub_36
dq intr_stub_37
dq intr_stub_38
dq intr_stub_39
dq intr_stub_40
dq intr_stub_41
dq intr_stub_42
dq intr_stub_43
dq intr_stub_44
dq intr_stub_45
dq intr_stub_46
dq intr_stub_47
dq intr_stub_48
dq intr_stub_49
dq intr_stub_50
dq intr_stub_51
dq intr_stub_52
dq intr_stub_53
dq intr_stub_54
dq intr_stub_55
dq intr_stub_56
dq intr_stub_57
dq intr_stub_58
dq intr_stub_59
dq intr_stub_60
dq intr_stub_61
dq intr_stub_62
dq intr_stub_63
dq intr_stub_64
dq intr_stub_65
dq intr_stub_66
dq intr_stub_67
dq intr_stub_68
dq intr_stub_69
dq intr_stub_70
dq intr_stub_71
dq intr_stub_72
dq intr_stub_73
dq intr_stub_74
dq intr_stub_75
dq intr_stub_76
dq intr_stub_77
dq intr_stub_78
dq intr_stub_79
dq intr_stub_80
dq intr_stub_81
dq intr_stub_82
dq intr_stub_83
dq intr_stub_84
dq intr_stub_85
dq intr_stub_86
dq intr_stub_87
dq intr_stub_88
dq intr_stub_89
dq intr_stub_90
dq intr_stub_91
dq intr_stub_92
dq intr_stub_93
dq intr_stub_94
dq intr_stub_95
dq intr_stub_96
dq intr_stub_97
dq intr_stub_98
dq intr_stub_99
dq intr_stub_100
dq intr_stub_101
dq intr_stub_102
dq intr_stub_103
dq intr_stub_104
dq intr_stub_105
dq intr_stub_106
dq intr_stub_107
dq intr_stub_108
dq intr_stub_109
dq intr_stub_110
dq intr_stub_111
dq intr_stub_112
dq intr_stub_113
dq intr_stub_114
dq intr_stub_115
dq intr_stub_116
dq intr_stub_117
dq intr_stub_118
dq intr_stub_119
dq intr_stub_120
dq intr_stub_121
dq intr_stub_122
dq intr_stub_123
dq intr_stub_124
dq intr_stub_125
dq intr_stub_126
dq intr_stub_127
dq intr_stub_128
dq intr_stub_129
dq intr_stub_130
dq intr_stub_131
dq intr_stub_132
dq intr_stub_133
dq intr_stub_134
dq intr_stub_135
dq intr_stub_136
dq intr_stub_137
dq intr_stub_138
dq intr_stub_139
dq intr_stub_140
dq intr_stub_141
dq intr_stub_142
dq intr_stub_143
dq intr_stub_144
dq intr_stub_145
dq intr_stub_146
dq intr_stub_147
dq intr_stub_148
dq intr_stub_149
dq intr_stub_150
dq intr_stub_151
dq intr_stub_152
dq intr_stub_153
dq intr_stub_154
dq intr_stub_155
dq intr_stub_156
dq intr_stub_157
dq intr_stub_158
dq intr_stub_159
dq intr_stub_160
dq intr_stub_161
dq intr_stub_162
dq intr_stub_163
dq intr_stub_164
dq intr_stub_165
dq intr_stub_166
dq intr_stub_167
dq intr_stub_168
dq intr_stub_169
dq intr_stub_170
dq intr_stub_171
dq intr_stub_172
dq intr_stub_173
dq intr_stub_174
dq intr_stub_175
dq intr_stub_176
dq intr_stub_177
dq intr_stub_178
dq intr_stub_179
dq intr_stub_180
dq intr_stub_181
dq intr_stub_182
dq intr_stub_183
dq intr_stub_184
dq intr_stub_185
dq intr_stub_186
dq intr_stub_187
dq intr_stub_188
dq intr_stub_189
dq intr_stub_190
dq intr_stub_191
dq intr_stub_192
dq intr_stub_193
dq intr_stub_194
dq intr_stub_195
dq intr_stub_196
dq intr_stub_197
dq intr_stub_198
dq intr_stub_199
dq intr_stub_200
dq intr_stub_201
dq intr_stub_202
dq intr_stub_203
dq intr_stub_204
dq intr_stub_205
dq intr_stub_206
dq intr_stub_207
dq intr_stub_208
dq intr_stub_209
dq intr_stub_210
dq intr_stub_211
dq intr_stub_212
dq intr_stub_213
dq intr_stub_214
dq intr_stub_215
dq intr_stub_216
dq intr_stub_217
dq intr_stub_218
dq intr_stub_219
dq intr_stub_220
dq intr_stub_221
dq intr_stub_222
dq intr_stub_223
dq intr_stub_224
dq intr_stub_225
dq intr_stub_226
dq intr_stub_227
dq intr_stub_228
dq intr_stub_229
dq intr_stub_230
dq intr_stub_231
dq intr_stub_232
dq intr_stub_233
dq intr_stub_234
dq intr_stub_235
dq intr_stub_236
dq intr_stub_237
dq intr_stub_238
dq intr_stub_239
dq intr_stub_240
dq intr_stub_241
dq intr_stub_242
dq intr_stub_243
dq intr_stub_244
dq intr_stub_245
dq intr_stub_246
dq intr_stub_247
dq intr_stub_248
dq intr_stub_249
dq intr_stub_250
dq intr_stub_251
dq intr_stub_252
dq intr_stub_253
dq intr_stub_254
dq intr_stub_255
section .text
bits 64
%macro decl_err_intr_stub 1
intr_stub_%1:
; vec
push qword %1
PUSH_REGS
jmp intr_stub
%endmacro
%macro decl_intr_stub 1
intr_stub_%1:
push qword 0 ; push dummy error code to have consistent frame
push qword %1
PUSH_REGS
jmp intr_stub
%endmacro
intr_stub:
mov rsi, rsp
call intr_dispatcher
POP_REGS ; restore registers
add rsp, 16 ; skip error code and vector
iretq
intr_stub_start:
decl_intr_stub 0
decl_intr_stub 1
decl_intr_stub 2
decl_intr_stub 3
decl_intr_stub 4
decl_intr_stub 5
decl_intr_stub 6
decl_intr_stub 7
decl_err_intr_stub 8
decl_intr_stub 9
decl_err_intr_stub 10
decl_err_intr_stub 11
decl_err_intr_stub 12
decl_err_intr_stub 13
decl_err_intr_stub 14
decl_intr_stub 15
decl_intr_stub 16
decl_err_intr_stub 17
decl_intr_stub 18
decl_intr_stub 19
decl_intr_stub 20
decl_intr_stub 21
decl_intr_stub 22
decl_intr_stub 23
decl_intr_stub 24
decl_intr_stub 25
decl_intr_stub 26
decl_intr_stub 27
decl_intr_stub 28
decl_intr_stub 29
decl_intr_stub 30
decl_intr_stub 31
decl_intr_stub 32
decl_intr_stub 33
decl_intr_stub 34
decl_intr_stub 35
decl_intr_stub 36
decl_intr_stub 37
decl_intr_stub 38
decl_intr_stub 39
decl_intr_stub 40
decl_intr_stub 41
decl_intr_stub 42
decl_intr_stub 43
decl_intr_stub 44
decl_intr_stub 45
decl_intr_stub 46
decl_intr_stub 47
decl_intr_stub 48
decl_intr_stub 49
decl_intr_stub 50
decl_intr_stub 51
decl_intr_stub 52
decl_intr_stub 53
decl_intr_stub 54
decl_intr_stub 55
decl_intr_stub 56
decl_intr_stub 57
decl_intr_stub 58
decl_intr_stub 59
decl_intr_stub 60
decl_intr_stub 61
decl_intr_stub 62
decl_intr_stub 63
decl_intr_stub 64
decl_intr_stub 65
decl_intr_stub 66
decl_intr_stub 67
decl_intr_stub 68
decl_intr_stub 69
decl_intr_stub 70
decl_intr_stub 71
decl_intr_stub 72
decl_intr_stub 73
decl_intr_stub 74
decl_intr_stub 75
decl_intr_stub 76
decl_intr_stub 77
decl_intr_stub 78
decl_intr_stub 79
decl_intr_stub 80
decl_intr_stub 81
decl_intr_stub 82
decl_intr_stub 83
decl_intr_stub 84
decl_intr_stub 85
decl_intr_stub 86
decl_intr_stub 87
decl_intr_stub 88
decl_intr_stub 89
decl_intr_stub 90
decl_intr_stub 91
decl_intr_stub 92
decl_intr_stub 93
decl_intr_stub 94
decl_intr_stub 95
decl_intr_stub 96
decl_intr_stub 97
decl_intr_stub 98
decl_intr_stub 99
decl_intr_stub 100
decl_intr_stub 101
decl_intr_stub 102
decl_intr_stub 103
decl_intr_stub 104
decl_intr_stub 105
decl_intr_stub 106
decl_intr_stub 107
decl_intr_stub 108
decl_intr_stub 109
decl_intr_stub 110
decl_intr_stub 111
decl_intr_stub 112
decl_intr_stub 113
decl_intr_stub 114
decl_intr_stub 115
decl_intr_stub 116
decl_intr_stub 117
decl_intr_stub 118
decl_intr_stub 119
decl_intr_stub 120
decl_intr_stub 121
decl_intr_stub 122
decl_intr_stub 123
decl_intr_stub 124
decl_intr_stub 125
decl_intr_stub 126
decl_intr_stub 127
decl_intr_stub 128
decl_intr_stub 129
decl_intr_stub 130
decl_intr_stub 131
decl_intr_stub 132
decl_intr_stub 133
decl_intr_stub 134
decl_intr_stub 135
decl_intr_stub 136
decl_intr_stub 137
decl_intr_stub 138
decl_intr_stub 139
decl_intr_stub 140
decl_intr_stub 141
decl_intr_stub 142
decl_intr_stub 143
decl_intr_stub 144
decl_intr_stub 145
decl_intr_stub 146
decl_intr_stub 147
decl_intr_stub 148
decl_intr_stub 149
decl_intr_stub 150
decl_intr_stub 151
decl_intr_stub 152
decl_intr_stub 153
decl_intr_stub 154
decl_intr_stub 155
decl_intr_stub 156
decl_intr_stub 157
decl_intr_stub 158
decl_intr_stub 159
decl_intr_stub 160
decl_intr_stub 161
decl_intr_stub 162
decl_intr_stub 163
decl_intr_stub 164
decl_intr_stub 165
decl_intr_stub 166
decl_intr_stub 167
decl_intr_stub 168
decl_intr_stub 169
decl_intr_stub 170
decl_intr_stub 171
decl_intr_stub 172
decl_intr_stub 173
decl_intr_stub 174
decl_intr_stub 175
decl_intr_stub 176
decl_intr_stub 177
decl_intr_stub 178
decl_intr_stub 179
decl_intr_stub 180
decl_intr_stub 181
decl_intr_stub 182
decl_intr_stub 183
decl_intr_stub 184
decl_intr_stub 185
decl_intr_stub 186
decl_intr_stub 187
decl_intr_stub 188
decl_intr_stub 189
decl_intr_stub 190
decl_intr_stub 191
decl_intr_stub 192
decl_intr_stub 193
decl_intr_stub 194
decl_intr_stub 195
decl_intr_stub 196
decl_intr_stub 197
decl_intr_stub 198
decl_intr_stub 199
decl_intr_stub 200
decl_intr_stub 201
decl_intr_stub 202
decl_intr_stub 203
decl_intr_stub 204
decl_intr_stub 205
decl_intr_stub 206
decl_intr_stub 207
decl_intr_stub 208
decl_intr_stub 209
decl_intr_stub 210
decl_intr_stub 211
decl_intr_stub 212
decl_intr_stub 213
decl_intr_stub 214
decl_intr_stub 215
decl_intr_stub 216
decl_intr_stub 217
decl_intr_stub 218
decl_intr_stub 219
decl_intr_stub 220
decl_intr_stub 221
decl_intr_stub 222
decl_intr_stub 223
decl_intr_stub 224
decl_intr_stub 225
decl_intr_stub 226
decl_intr_stub 227
decl_intr_stub 228
decl_intr_stub 229
decl_intr_stub 230
decl_intr_stub 231
decl_intr_stub 232
decl_intr_stub 233
decl_intr_stub 234
decl_intr_stub 235
decl_intr_stub 236
decl_intr_stub 237
decl_intr_stub 238
decl_intr_stub 239
decl_intr_stub 240
decl_intr_stub 241
decl_intr_stub 242
decl_intr_stub 243
decl_intr_stub 244
decl_intr_stub 245
decl_intr_stub 246
decl_intr_stub 247
decl_intr_stub 248
decl_intr_stub 249
decl_intr_stub 250
decl_intr_stub 251
decl_intr_stub 252
decl_intr_stub 253
decl_intr_stub 254
decl_intr_stub 255

View File

@ -1,7 +0,0 @@
#!/bin/bash
# Bootstrap debian 9 + clang-6.0 backport environment
# Personal use only
export CC_ENV=clang-6.0
export LD_ENV=lld-6.0
export DAS_ENV=llvm-objdump-6.0
export AS_ENV=nasm

4
gdbq
View File

@ -1,4 +0,0 @@
file out/secxkrnl.elf
set arch i386:x86-64
target remote localhost:1234
break hmain

3
gdbw
View File

@ -1,3 +0,0 @@
disconnect
set arch i386:x86-64:intel
target remote localhost:1234

View File

@ -1,8 +1,8 @@
#pragma once
#include <kern/cdef.h>
#include <ke/cdef.h>
int32 KABI arch_cmp_swp_32(int32* dst, int32 old, int32 val);
int32 KABI cmp_swp_32(int32* dst, int32 old, int32 val);
int32 KABI arch_fet_add_32(int32* dst, int32 val);
int32 KABI fetch_add_32(int32* dst, int32 val);

View File

@ -1,58 +0,0 @@
#pragma once
#include <kern/cdef.h>
#define HAL_CORE_COUNT 1
struct PRAGMA_PACKED hal_gdt_ptr
{
uint16 limit;
uint64 base;
};
struct PRAGMA_PACKED hal_idt_ptr
{
uint16 limit;
uint64 base;
};
/**
* ASM declaration
*/
void KABI hal_cpuid(uint32 *eax, uint32 *ebx, uint32 *ecx, uint32 *edx);
void KABI hal_halt_cpu(void);
void KABI hal_flush_gdt(struct hal_gdt_ptr *gdt_ptr, uint64 code_slct, uint64 data_slct);
void KABI hal_flush_tlb(void);
void KABI hal_flush_idt(struct hal_idt_ptr *idt_ptr);
void KABI hal_read_idt(struct hal_idt_ptr **idt_ptr);
void KABI hal_read_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
void KABI hal_write_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
void KABI hal_write_cr3(uint64 base);
uint64 KABI hal_read_cr3(void);
void KABI hal_write_cr8(uint64 pri);
uint64 KABI hal_read_cr8(void);
int8 HABI hal_read_port_8(uint16 port);
int16 HABI hal_read_port_16(uint16 port);
int32 HABI hal_read_port_32(uint16 port);
void HABI hal_write_port_8(uint16 port, uint8 data);
void HABI hal_write_port_16(uint16 port, uint16 data);
void HABI hal_write_port_32(uint16 port, uint32 data);

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,6 @@
#include <ke/cdef.h>
#include <mm/mm.h>
void
arch_write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr);
void*
arch_pmap_map(phys_addr paddr, usize size);
pmap_map(phys_addr paddr, usize size);

View File

@ -1,12 +1,5 @@
#pragma once
#include <ke/cdef.h>
#include <arch/print.h>
void
arch_printf(const char *format, ...);
void
arch_cls(void);
void
arch_print_init(void);
aprintf(const char *format, ...);

34
inc/arch/trap.h Normal file
View File

@ -0,0 +1,34 @@
#pragma once
/**
* Trap frame
*/
struct trap_frame
{
uint64 gs;
uint64 fs;
uint64 es;
uint64 ds;
uint64 r15;
uint64 r14;
uint64 r13;
uint64 r12;
uint64 r11;
uint64 r10;
uint64 r9;
uint64 r8;
uint64 rsi;
uint64 rdi;
uint64 rbp;
uint64 rdx;
uint64 rcx;
uint64 rbx;
uint64 rax;
uint64 vec;
uint64 error_code;
uint64 rip;
uint64 cs;
uint64 rflags;
uint64 rsp;
uint64 ss;
};

View File

@ -1,6 +1,6 @@
#include <kern/cdef.h>
#include <kern/assert.h>
#include <kern/print.h>
#include <ke/cdef.h>
#include <ke/assert.h>
#include <ke/print.h>
void kassert_ex(const char *expr_str, const char *file, int32 line, int32 expr)
{

View File

@ -1,5 +1,5 @@
#include <kern/atree.h>
#include <kern/clib.h>
#include <ke/atree.h>
#include <ke/clib.h>
static struct atree_node *
atree_node_max(struct atree_node *node)

View File

@ -1,7 +1,7 @@
#include <kern/balloc.h>
#include <mm/balloc.h>
#include <math.h>
#include <kern/clib.h>
#include <kern/bitmap.h>
#include <ke/clib.h>
#include <ke/bitmap.h>
// for each size
// we have - bitmap representing each frame_size