Browse Source

remove some stale C++ code. extract more platform-dependent parts

greatbridf 3 months ago
parent
commit
bad164e483

+ 0 - 16
CMakeLists.txt

@@ -35,43 +35,27 @@ add_subdirectory(user-space-program)
 
 set(BOOTLOADER_SOURCES src/boot.s
                        src/mbr.S
-                       src/asm/interrupt.s
                        )
 
 set(KERNEL_MAIN_SOURCES src/kinit.cpp
                         src/kernel/async/lock.cc
                         src/kernel/allocator.cc
-                        src/kernel/process.cpp
                         src/kernel/mem/slab.cc
-                        src/kernel/vga.cpp
                         src/kernel/hw/acpi.cc
                         src/kernel/hw/pci.cc
-                        src/net/ethernet.cc
-                        src/types/crc.cc
                         src/types/libstdcpp.cpp
                         include/defs.hpp
                         include/kernel/async/lock.hpp
-                        include/kernel/interrupt.hpp
-                        include/kernel/process.hpp
                         include/kernel/mem/paging.hpp
                         include/kernel/mem/slab.hpp
                         include/kernel/mem/types.hpp
                         include/kernel/utsname.hpp
-                        include/kernel/vga.hpp
-                        include/kernel/task/forward.hpp
                         include/kernel/hw/acpi.hpp
                         include/kernel/hw/pci.hpp
                         include/kernel/hw/port.hpp
-                        include/kernel/input/keycodes.h
-                        include/net/arp.hpp
-                        include/net/ethernet.hpp
-                        include/net/netdev.hpp
-                        include/types/bitmap.hpp
-                        include/types/buffer.hpp
                         include/types/list.hpp
                         include/types/types.h
                         include/types/allocator.hpp
-                        include/types/cplusplus.hpp
                         include/kernel/log.hpp
                         )
 

+ 244 - 1
arch/src/x86_64/interrupt.rs

@@ -1,9 +1,244 @@
-use core::{arch::asm, pin::Pin, ptr::NonNull};
+use core::{
+    arch::{asm, global_asm},
+    pin::Pin,
+    ptr::NonNull,
+};
 
 use crate::rdmsr;
 
 use super::pause;
 
+global_asm!(
+    r"
+    .set RAX, 0x00
+    .set RBX, 0x08
+    .set RCX, 0x10
+    .set RDX, 0x18
+    .set RDI, 0x20
+    .set RSI, 0x28
+    .set R8, 0x30
+    .set R9, 0x38
+    .set R10, 0x40
+    .set R11, 0x48
+    .set R12, 0x50
+    .set R13, 0x58
+    .set R14, 0x60
+    .set R15, 0x68
+    .set RBP, 0x70
+    .set INT_NO, 0x78
+    .set ERRCODE, 0x80
+    .set RIP, 0x88
+    .set CS, 0x90
+    .set FLAGS, 0x98
+    .set RSP, 0xa0
+    .set SS, 0xa8
+
+    .macro movcfi reg, offset
+    	mov \reg, \offset(%rsp)
+    	.cfi_rel_offset \reg, \offset
+    .endm
+
+    .macro movrst reg, offset
+    	mov \offset(%rsp), \reg
+    	.cfi_restore \reg
+    .endm
+
+    .globl ISR_stub_restore
+    .type ISR_stub_restore @function
+
+    ISR_stub:
+    	.cfi_startproc
+    	.cfi_signal_frame
+    	.cfi_def_cfa_offset 0x18
+    	.cfi_offset %rsp, 0x10
+
+    	cmpq $0x08, 24(%rsp)
+    	je 1f
+    	swapgs
+    
+    1:
+    	sub $0x78, %rsp
+    	.cfi_def_cfa_offset 0x90
+    
+    	movcfi %rax, RAX
+    	movcfi %rbx, RBX
+    	movcfi %rcx, RCX
+    	movcfi %rdx, RDX
+    	movcfi %rdi, RDI
+    	movcfi %rsi, RSI
+    	movcfi %r8,  R8
+    	movcfi %r9,  R9
+    	movcfi %r10, R10
+    	movcfi %r11, R11
+    	movcfi %r12, R12
+    	movcfi %r13, R13
+    	movcfi %r14, R14
+    	movcfi %r15, R15
+    	movcfi %rbp, RBP
+    
+    	mov INT_NO(%rsp), %rax
+    	sub $ISR0, %rax
+    	shr $3, %rax
+    	mov %rax, INT_NO(%rsp)
+    
+    	mov %rsp, %rbx
+    	.cfi_def_cfa_register %rbx
+    
+    	and $~0xf, %rsp
+    	sub $512, %rsp
+    	fxsave (%rsp)
+    
+    	mov %rbx, %rdi
+    	mov %rsp, %rsi
+    	call interrupt_handler
+    
+    ISR_stub_restore:
+    	fxrstor (%rsp)
+    	mov %rbx, %rsp
+    	.cfi_def_cfa_register %rsp
+    
+    	movrst %rax, RAX
+    	movrst %rbx, RBX
+    	movrst %rcx, RCX
+    	movrst %rdx, RDX
+    	movrst %rdi, RDI
+    	movrst %rsi, RSI
+    	movrst %r8,  R8
+    	movrst %r9,  R9
+    	movrst %r10, R10
+    	movrst %r11, R11
+    	movrst %r12, R12
+    	movrst %r13, R13
+    	movrst %r14, R14
+    	movrst %r15, R15
+    	movrst %rbp, RBP
+    
+    	add $0x88, %rsp
+    	.cfi_def_cfa_offset 0x08
+    
+    	cmpq $0x08, 8(%rsp)
+    	je 1f
+    	swapgs
+    
+    1:
+    	iretq
+    	.cfi_endproc
+    
+    .altmacro
+    .macro build_isr_no_err name
+    	.align 8
+    	.globl ISR\name
+    	.type  ISR\name @function
+    	ISR\name:
+    		.cfi_startproc
+    		.cfi_signal_frame
+    		.cfi_def_cfa_offset 0x08
+    		.cfi_offset %rsp, 0x10
+    
+    		.cfi_same_value %rax
+    		.cfi_same_value %rbx
+    		.cfi_same_value %rcx
+    		.cfi_same_value %rdx
+    		.cfi_same_value %rdi
+    		.cfi_same_value %rsi
+    		.cfi_same_value %r8
+    		.cfi_same_value %r9
+    		.cfi_same_value %r10
+    		.cfi_same_value %r11
+    		.cfi_same_value %r12
+    		.cfi_same_value %r13
+    		.cfi_same_value %r14
+    		.cfi_same_value %r15
+    		.cfi_same_value %rbp
+    
+    		push %rbp # push placeholder for error code
+    		.cfi_def_cfa_offset 0x10
+    
+    		call ISR_stub
+    		.cfi_endproc
+    .endm
+    
+    .altmacro
+    .macro build_isr_err name
+    	.align 8
+    	.globl ISR\name
+    	.type  ISR\name @function
+    	ISR\name:
+    		.cfi_startproc
+    		.cfi_signal_frame
+    		.cfi_def_cfa_offset 0x10
+    		.cfi_offset %rsp, 0x10
+    
+    		.cfi_same_value %rax
+    		.cfi_same_value %rbx
+    		.cfi_same_value %rcx
+    		.cfi_same_value %rdx
+    		.cfi_same_value %rdi
+    		.cfi_same_value %rsi
+    		.cfi_same_value %r8
+    		.cfi_same_value %r9
+    		.cfi_same_value %r10
+    		.cfi_same_value %r11
+    		.cfi_same_value %r12
+    		.cfi_same_value %r13
+    		.cfi_same_value %r14
+    		.cfi_same_value %r15
+    		.cfi_same_value %rbp
+    
+    		call ISR_stub
+    		.cfi_endproc
+    .endm
+    
+    build_isr_no_err 0
+    build_isr_no_err 1
+    build_isr_no_err 2
+    build_isr_no_err 3
+    build_isr_no_err 4
+    build_isr_no_err 5
+    build_isr_no_err 6
+    build_isr_no_err 7
+    build_isr_err    8
+    build_isr_no_err 9
+    build_isr_err    10
+    build_isr_err    11
+    build_isr_err    12
+    build_isr_err    13
+    build_isr_err    14
+    build_isr_no_err 15
+    build_isr_no_err 16
+    build_isr_err    17
+    build_isr_no_err 18
+    build_isr_no_err 19
+    build_isr_no_err 20
+    build_isr_err    21
+    build_isr_no_err 22
+    build_isr_no_err 23
+    build_isr_no_err 24
+    build_isr_no_err 25
+    build_isr_no_err 26
+    build_isr_no_err 27
+    build_isr_no_err 28
+    build_isr_err    29
+    build_isr_err    30
+    build_isr_no_err 31
+    
+    .set i, 32
+    .rept 0x80+1
+    	build_isr_no_err %i
+    	.set i, i+1
+    .endr
+    
+    .section .rodata
+    
+    .align 8
+    .globl ISR_START_ADDR
+    .type  ISR_START_ADDR @object
+    ISR_START_ADDR:
+    	.quad ISR0
+    ",
+    options(att_syntax),
+);
+
 /// Saved registers when a trap (interrupt or exception) occurs.
 #[allow(missing_docs)]
 #[repr(C)]
@@ -36,6 +271,14 @@ pub struct InterruptContext {
     pub ss: u64,
 }
 
+#[allow(missing_docs)]
+#[repr(C)]
+#[derive(Clone, Copy)]
+pub struct ExtendedContext {
+    /// For FPU states
+    data: [u8; 512],
+}
+
 #[repr(C)]
 #[derive(Clone, Copy)]
 struct IDTEntry {

+ 0 - 214
arch/src/x86_64/interrupt.s

@@ -1,214 +0,0 @@
-.text
-
-#define RAX     0x00
-#define RBX     0x08
-#define RCX     0x10
-#define RDX     0x18
-#define RDI     0x20
-#define RSI     0x28
-#define R8      0x30
-#define R9      0x38
-#define R10     0x40
-#define R11     0x48
-#define R12     0x50
-#define R13     0x58
-#define R14     0x60
-#define R15     0x68
-#define RBP     0x70
-#define INT_NO  0x78
-#define ERRCODE 0x80
-#define RIP     0x88
-#define CS      0x90
-#define FLAGS   0x98
-#define RSP     0xa0
-#define SS      0xa8
-
-.macro movcfi reg, offset
-	mov \reg, \offset(%rsp)
-	.cfi_rel_offset \reg, \offset
-.endm
-
-.macro movrst reg, offset
-	mov \offset(%rsp), \reg
-	.cfi_restore \reg
-.endm
-
-ISR_stub:
-	.cfi_startproc
-	.cfi_signal_frame
-	.cfi_def_cfa_offset 0x18
-	.cfi_offset %rsp, 0x10
-
-	sub $0x78, %rsp
-	.cfi_def_cfa_offset 0x90
-
-	movcfi %rax, RAX
-	movcfi %rbx, RBX
-	movcfi %rcx, RCX
-	movcfi %rdx, RDX
-	movcfi %rdi, RDI
-	movcfi %rsi, RSI
-	movcfi %r8,  R8
-	movcfi %r9,  R9
-	movcfi %r10, R10
-	movcfi %r11, R11
-	movcfi %r12, R12
-	movcfi %r13, R13
-	movcfi %r14, R14
-	movcfi %r15, R15
-	movcfi %rbp, RBP
-
-	mov INT_NO(%rsp), %rax
-	sub $ISR0, %rax
-	shr $3, %rax
-	mov %rax, INT_NO(%rsp)
-
-	mov %rsp, %rbx
-	.cfi_def_cfa_register %rbx
-
-	and $~0xf, %rsp
-	sub $512, %rsp
-	fxsave (%rsp)
-
-	mov %rbx, %rdi
-	mov %rsp, %rsi
-	call interrupt_handler
-
-ISR_stub_restore:
-	fxrstor (%rsp)
-	mov %rbx, %rsp
-	.cfi_def_cfa_register %rsp
-
-	movrst %rax, RAX
-	movrst %rbx, RBX
-	movrst %rcx, RCX
-	movrst %rdx, RDX
-	movrst %rdi, RDI
-	movrst %rsi, RSI
-	movrst %r8,  R8
-	movrst %r9,  R9
-	movrst %r10, R10
-	movrst %r11, R11
-	movrst %r12, R12
-	movrst %r13, R13
-	movrst %r14, R14
-	movrst %r15, R15
-	movrst %rbp, RBP
-
-	add $0x88, %rsp
-	.cfi_def_cfa_offset 0x08
-
-	iretq
-	.cfi_endproc
-
-.altmacro
-.macro build_isr_no_err name
-	.align 8
-	.globl ISR\name
-	.type  ISR\name @function
-	ISR\name:
-		.cfi_startproc
-		.cfi_signal_frame
-		.cfi_def_cfa_offset 0x08
-		.cfi_offset %rsp, 0x10
-
-		.cfi_same_value %rax
-		.cfi_same_value %rbx
-		.cfi_same_value %rcx
-		.cfi_same_value %rdx
-		.cfi_same_value %rdi
-		.cfi_same_value %rsi
-		.cfi_same_value %r8
-		.cfi_same_value %r9
-		.cfi_same_value %r10
-		.cfi_same_value %r11
-		.cfi_same_value %r12
-		.cfi_same_value %r13
-		.cfi_same_value %r14
-		.cfi_same_value %r15
-		.cfi_same_value %rbp
-
-		push %rbp # push placeholder for error code
-		.cfi_def_cfa_offset 0x10
-
-		call ISR_stub
-		.cfi_endproc
-.endm
-
-.altmacro
-.macro build_isr_err name
-	.align 8
-	.globl ISR\name
-	.type  ISR\name @function
-	ISR\name:
-		.cfi_startproc
-		.cfi_signal_frame
-		.cfi_def_cfa_offset 0x10
-		.cfi_offset %rsp, 0x10
-
-		.cfi_same_value %rax
-		.cfi_same_value %rbx
-		.cfi_same_value %rcx
-		.cfi_same_value %rdx
-		.cfi_same_value %rdi
-		.cfi_same_value %rsi
-		.cfi_same_value %r8
-		.cfi_same_value %r9
-		.cfi_same_value %r10
-		.cfi_same_value %r11
-		.cfi_same_value %r12
-		.cfi_same_value %r13
-		.cfi_same_value %r14
-		.cfi_same_value %r15
-		.cfi_same_value %rbp
-
-		call ISR_stub
-		.cfi_endproc
-.endm
-
-build_isr_no_err 0
-build_isr_no_err 1
-build_isr_no_err 2
-build_isr_no_err 3
-build_isr_no_err 4
-build_isr_no_err 5
-build_isr_no_err 6
-build_isr_no_err 7
-build_isr_err    8
-build_isr_no_err 9
-build_isr_err    10
-build_isr_err    11
-build_isr_err    12
-build_isr_err    13
-build_isr_err    14
-build_isr_no_err 15
-build_isr_no_err 16
-build_isr_err    17
-build_isr_no_err 18
-build_isr_no_err 19
-build_isr_no_err 20
-build_isr_err    21
-build_isr_no_err 22
-build_isr_no_err 23
-build_isr_no_err 24
-build_isr_no_err 25
-build_isr_no_err 26
-build_isr_no_err 27
-build_isr_no_err 28
-build_isr_err    29
-build_isr_err    30
-build_isr_no_err 31
-
-.set i, 32
-.rept 0x80+1
-	build_isr_no_err %i
-	.set i, i+1
-.endr
-
-.section .rodata
-
-.align 8
-.globl ISR_START_ADDR
-.type  ISR_START_ADDR @object
-ISR_START_ADDR:
-	.quad ISR0

+ 1 - 1
build.rs

@@ -3,7 +3,7 @@ fn main() {
     println!("cargo:rustc-link-lib=static=gblibstdc++");
 
     let headers = [
-        "include/kernel/process.hpp",
+        "rust-headers.hpp",
         "include/kernel/hw/pci.hpp",
     ];
 

+ 0 - 17
include/kernel/input/input_event.h

@@ -1,17 +0,0 @@
-#pragma once
-
-#include <types/types.h>
-
-// keyboard event code
-#define KEY_DOWN 0
-#define KEY_UP 1
-
-struct input_event {
-    enum input_event_type {
-        KEYBOARD,
-    };
-
-    enum input_event_type type;
-    uint32_t code;
-    uint32_t data;
-};

+ 0 - 271
include/kernel/input/keycodes.h

@@ -1,271 +0,0 @@
-#pragma once
-
-// copied from Linux kernel source code
-#define KEY_RESERVED 0
-#define KEY_ESC 1
-#define KEY_1 2
-#define KEY_2 3
-#define KEY_3 4
-#define KEY_4 5
-#define KEY_5 6
-#define KEY_6 7
-#define KEY_7 8
-#define KEY_8 9
-#define KEY_9 10
-#define KEY_0 11
-#define KEY_MINUS 12
-#define KEY_EQUAL 13
-#define KEY_BACKSPACE 14
-#define KEY_TAB 15
-#define KEY_Q 16
-#define KEY_W 17
-#define KEY_E 18
-#define KEY_R 19
-#define KEY_T 20
-#define KEY_Y 21
-#define KEY_U 22
-#define KEY_I 23
-#define KEY_O 24
-#define KEY_P 25
-#define KEY_LEFTBRACE 26
-#define KEY_RIGHTBRACE 27
-#define KEY_ENTER 28
-#define KEY_LEFTCTRL 29
-#define KEY_A 30
-#define KEY_S 31
-#define KEY_D 32
-#define KEY_F 33
-#define KEY_G 34
-#define KEY_H 35
-#define KEY_J 36
-#define KEY_K 37
-#define KEY_L 38
-#define KEY_SEMICOLON 39
-#define KEY_APOSTROPHE 40
-#define KEY_GRAVE 41
-#define KEY_LEFTSHIFT 42
-#define KEY_BACKSLASH 43
-#define KEY_Z 44
-#define KEY_X 45
-#define KEY_C 46
-#define KEY_V 47
-#define KEY_B 48
-#define KEY_N 49
-#define KEY_M 50
-#define KEY_COMMA 51
-#define KEY_DOT 52
-#define KEY_SLASH 53
-#define KEY_RIGHTSHIFT 54
-#define KEY_KPASTERISK 55
-#define KEY_LEFTALT 56
-#define KEY_SPACE 57
-#define KEY_CAPSLOCK 58
-#define KEY_F1 59
-#define KEY_F2 60
-#define KEY_F3 61
-#define KEY_F4 62
-#define KEY_F5 63
-#define KEY_F6 64
-#define KEY_F7 65
-#define KEY_F8 66
-#define KEY_F9 67
-#define KEY_F10 68
-#define KEY_NUMLOCK 69
-#define KEY_SCROLLLOCK 70
-#define KEY_KP7 71
-#define KEY_KP8 72
-#define KEY_KP9 73
-#define KEY_KPMINUS 74
-#define KEY_KP4 75
-#define KEY_KP5 76
-#define KEY_KP6 77
-#define KEY_KPPLUS 78
-#define KEY_KP1 79
-#define KEY_KP2 80
-#define KEY_KP3 81
-#define KEY_KP0 82
-#define KEY_KPDOT 83
-
-#define KEY_ZENKAKUHANKAKU 85
-#define KEY_102ND 86
-#define KEY_F11 87
-#define KEY_F12 88
-#define KEY_RO 89
-#define KEY_KATAKANA 90
-#define KEY_HIRAGANA 91
-#define KEY_HENKAN 92
-#define KEY_KATAKANAHIRAGANA 93
-#define KEY_MUHENKAN 94
-#define KEY_KPJPCOMMA 95
-#define KEY_KPENTER 96
-#define KEY_RIGHTCTRL 97
-#define KEY_KPSLASH 98
-#define KEY_SYSRQ 99
-#define KEY_RIGHTALT 100
-#define KEY_LINEFEED 101
-#define KEY_HOME 102
-#define KEY_UP 103
-#define KEY_PAGEUP 104
-#define KEY_LEFT 105
-#define KEY_RIGHT 106
-#define KEY_END 107
-#define KEY_DOWN 108
-#define KEY_PAGEDOWN 109
-#define KEY_INSERT 110
-#define KEY_DELETE 111
-#define KEY_MACRO 112
-#define KEY_MUTE 113
-#define KEY_VOLUMEDOWN 114
-#define KEY_VOLUMEUP 115
-#define KEY_POWER 116 /* SC System Power Down */
-#define KEY_KPEQUAL 117
-#define KEY_KPPLUSMINUS 118
-#define KEY_PAUSE 119
-#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */
-
-#define KEY_KPCOMMA 121
-#define KEY_HANGEUL 122
-#define KEY_HANGUEL KEY_HANGEUL
-#define KEY_HANJA 123
-#define KEY_YEN 124
-#define KEY_LEFTMETA 125
-#define KEY_RIGHTMETA 126
-#define KEY_COMPOSE 127
-
-#define KEY_STOP 128 /* AC Stop */
-#define KEY_AGAIN 129
-#define KEY_PROPS 130 /* AC Properties */
-#define KEY_UNDO 131  /* AC Undo */
-#define KEY_FRONT 132
-#define KEY_COPY 133  /* AC Copy */
-#define KEY_OPEN 134  /* AC Open */
-#define KEY_PASTE 135 /* AC Paste */
-#define KEY_FIND 136  /* AC Search */
-#define KEY_CUT 137   /* AC Cut */
-#define KEY_HELP 138  /* AL Integrated Help Center */
-#define KEY_MENU 139  /* Menu (show menu) */
-#define KEY_CALC 140  /* AL Calculator */
-#define KEY_SETUP 141
-#define KEY_SLEEP 142  /* SC System Sleep */
-#define KEY_WAKEUP 143 /* System Wake Up */
-#define KEY_FILE 144   /* AL Local Machine Browser */
-#define KEY_SENDFILE 145
-#define KEY_DELETEFILE 146
-#define KEY_XFER 147
-#define KEY_PROG1 148
-#define KEY_PROG2 149
-#define KEY_WWW 150 /* AL Internet Browser */
-#define KEY_MSDOS 151
-#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */
-#define KEY_SCREENLOCK KEY_COFFEE
-#define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */
-#define KEY_DIRECTION KEY_ROTATE_DISPLAY
-#define KEY_CYCLEWINDOWS 154
-#define KEY_MAIL 155
-#define KEY_BOOKMARKS 156 /* AC Bookmarks */
-#define KEY_COMPUTER 157
-#define KEY_BACK 158    /* AC Back */
-#define KEY_FORWARD 159 /* AC Forward */
-#define KEY_CLOSECD 160
-#define KEY_EJECTCD 161
-#define KEY_EJECTCLOSECD 162
-#define KEY_NEXTSONG 163
-#define KEY_PLAYPAUSE 164
-#define KEY_PREVIOUSSONG 165
-#define KEY_STOPCD 166
-#define KEY_RECORD 167
-#define KEY_REWIND 168
-#define KEY_PHONE 169 /* Media Select Telephone */
-#define KEY_ISO 170
-#define KEY_CONFIG 171   /* AL Consumer Control Configuration */
-#define KEY_HOMEPAGE 172 /* AC Home */
-#define KEY_REFRESH 173  /* AC Refresh */
-#define KEY_EXIT 174     /* AC Exit */
-#define KEY_MOVE 175
-#define KEY_EDIT 176
-#define KEY_SCROLLUP 177
-#define KEY_SCROLLDOWN 178
-#define KEY_KPLEFTPAREN 179
-#define KEY_KPRIGHTPAREN 180
-#define KEY_NEW 181  /* AC New */
-#define KEY_REDO 182 /* AC Redo/Repeat */
-
-#define KEY_F13 183
-#define KEY_F14 184
-#define KEY_F15 185
-#define KEY_F16 186
-#define KEY_F17 187
-#define KEY_F18 188
-#define KEY_F19 189
-#define KEY_F20 190
-#define KEY_F21 191
-#define KEY_F22 192
-#define KEY_F23 193
-#define KEY_F24 194
-
-#define KEY_PLAYCD 200
-#define KEY_PAUSECD 201
-#define KEY_PROG3 202
-#define KEY_PROG4 203
-#define KEY_DASHBOARD 204 /* AL Dashboard */
-#define KEY_SUSPEND 205
-#define KEY_CLOSE 206 /* AC Close */
-#define KEY_PLAY 207
-#define KEY_FASTFORWARD 208
-#define KEY_BASSBOOST 209
-#define KEY_PRINT 210 /* AC Print */
-#define KEY_HP 211
-#define KEY_CAMERA 212
-#define KEY_SOUND 213
-#define KEY_QUESTION 214
-#define KEY_EMAIL 215
-#define KEY_CHAT 216
-#define KEY_SEARCH 217
-#define KEY_CONNECT 218
-#define KEY_FINANCE 219 /* AL Checkbook/Finance */
-#define KEY_SPORT 220
-#define KEY_SHOP 221
-#define KEY_ALTERASE 222
-#define KEY_CANCEL 223 /* AC Cancel */
-#define KEY_BRIGHTNESSDOWN 224
-#define KEY_BRIGHTNESSUP 225
-#define KEY_MEDIA 226
-
-#define KEY_SWITCHVIDEOMODE              \
-    227 /* Cycle between available video \
-           outputs (Monitor/LCD/TV-out/etc) */
-#define KEY_KBDILLUMTOGGLE 228
-#define KEY_KBDILLUMDOWN 229
-#define KEY_KBDILLUMUP 230
-
-#define KEY_SEND 231        /* AC Send */
-#define KEY_REPLY 232       /* AC Reply */
-#define KEY_FORWARDMAIL 233 /* AC Forward Msg */
-#define KEY_SAVE 234        /* AC Save */
-#define KEY_DOCUMENTS 235
-
-#define KEY_BATTERY 236
-
-#define KEY_BLUETOOTH 237
-#define KEY_WLAN 238
-#define KEY_UWB 239
-
-#define KEY_UNKNOWN 240
-
-#define KEY_VIDEO_NEXT 241       /* drive next video source */
-#define KEY_VIDEO_PREV 242       /* drive previous video source */
-#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
-#define KEY_BRIGHTNESS_AUTO            \
-    244 /* Set Auto Brightness: manual \
-          brightness control is off,   \
-          rely on ambient */
-#define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO
-#define KEY_DISPLAY_OFF 245 /* display device to off state */
-
-#define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */
-#define KEY_WIMAX KEY_WWAN
-#define KEY_RFKILL 247 /* Key that controls all radios */
-
-#define KEY_MICMUTE 248 /* Mute / unmute the microphone */
-
-/* Code 255 is reserved for special needs of AT keyboard driver */

+ 0 - 38
include/kernel/interrupt.hpp

@@ -1,38 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#include <types/types.h>
-
-struct saved_regs {
-    unsigned long rax;
-    unsigned long rbx;
-    unsigned long rcx;
-    unsigned long rdx;
-    unsigned long rdi;
-    unsigned long rsi;
-    unsigned long r8;
-    unsigned long r9;
-    unsigned long r10;
-    unsigned long r11;
-    unsigned long r12;
-    unsigned long r13;
-    unsigned long r14;
-    unsigned long r15;
-    unsigned long rbp;
-};
-
-struct interrupt_stack {
-    saved_regs regs;
-    unsigned long int_no;
-    unsigned long error_code;
-    uintptr_t v_rip;
-    unsigned long cs;
-    unsigned long flags;
-    uintptr_t rsp;
-    unsigned long ss;
-};
-
-struct mmx_registers {
-    uint8_t data[512]; // TODO: list of content
-};

+ 0 - 2
include/kernel/mem/paging.hpp

@@ -1,12 +1,10 @@
 #pragma once
 
-#include <bit>
 #include <cstddef>
 #include <tuple>
 
 #include <stdint.h>
 
-#include <kernel/interrupt.hpp>
 #include <kernel/mem/paging_asm.h>
 #include <kernel/mem/phys.hpp>
 

+ 0 - 19
include/kernel/process.hpp

@@ -1,19 +0,0 @@
-#pragma once
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <types/allocator.hpp>
-#include <types/cplusplus.hpp>
-#include <types/path.hpp>
-#include <types/types.h>
-
-#include <kernel/interrupt.hpp>
-#include <kernel/mem/paging.hpp>
-#include <kernel/vfs.hpp>
-
-void NORETURN freeze(void);

+ 0 - 7
include/kernel/task/forward.hpp

@@ -1,7 +0,0 @@
-#pragma once
-
-namespace kernel::task {
-
-class thread;
-
-} // namespace kernel::task

+ 0 - 17
include/kernel/vfs.hpp

@@ -1,17 +0,0 @@
-#pragma once
-
-#include <bits/alltypes.h>
-#include <stdint.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#define NODE_MAJOR(node) (((node) >> 8) & 0xFFU)
-#define NODE_MINOR(node) ((node) & 0xFFU)
-
-namespace fs {
-
-constexpr dev_t make_device(uint32_t major, uint32_t minor) {
-    return ((major << 8) & 0xFF00U) | (minor & 0xFFU);
-}
-
-} // namespace fs

+ 0 - 21
include/kernel/vga.hpp

@@ -1,21 +0,0 @@
-#pragma once
-#ifndef _KERNEL_VGA_H_
-#define _KERNEL_VGA_H_
-
-#include <stdint.h>
-
-#define VGA_CHAR_COLOR_WHITE (0x0fU)
-
-struct vga_char {
-    int8_t c;
-    uint8_t color;
-};
-
-#define VGA_MEM ((struct vga_char*)0xb8000)
-#define VGA_SCREEN_WIDTH_IN_CHARS (80U)
-#define VGA_SCREEN_HEIGHT_IN_CHARS (25U)
-
-void vga_put_char(struct vga_char* c);
-void vga_print(const char* str, uint8_t color);
-
-#endif // _KERNEL_VGA_H_

+ 0 - 22
include/net/arp.hpp

@@ -1,22 +0,0 @@
-#pragma once
-
-#include <defs.hpp>
-
-#include <net/ethernet.hpp>
-
-namespace net {
-
-struct PACKED ARPFrame {
-    u16 l2Type;
-    u16 protoType;
-    u8 l2AddrLen;
-    u8 protoAddrLen;
-    u16 op;
-
-    MACAddress srcMAC;
-    u32 srcIP;
-    MACAddress dstMAC;
-    u32 dstIP;
-};
-
-} // namespace net

+ 0 - 22
include/net/ethernet.hpp

@@ -1,22 +0,0 @@
-#pragma once
-
-#include <defs.hpp>
-
-namespace net {
-
-u16 htons(u16 val);
-u32 htonl(u32 val);
-u64 htonll(u64 val);
-
-struct PACKED MACAddress {
-    u8 addr[6];
-};
-
-struct PACKED EthernetHeader {
-    MACAddress dst;
-    MACAddress src;
-    u16 type;
-    u8 payload[];
-};
-
-} // namespace net

+ 0 - 42
include/net/netdev.hpp

@@ -1,42 +0,0 @@
-#pragma once
-
-#include <defs.hpp>
-#include <functional>
-
-#include <stdint.h>
-
-#include <kernel/hw/pci.hpp>
-#include <net/ethernet.hpp>
-
-namespace net {
-
-constexpr unsigned long NETDEV_UP = 0x001;
-constexpr unsigned long NETDEV_DOWN = 0x002;
-
-constexpr unsigned long NETDEV_SPEED_MASK = 0x03c;
-constexpr unsigned long NETDEV_SPEED_UNKNOWN = 0x004;
-constexpr unsigned long NETDEV_SPEED_10M = 0x008;
-constexpr unsigned long NETDEV_SPEED_100M = 0x010;
-constexpr unsigned long NETDEV_SPEED_1000M = 0x020;
-
-class Netdev {
-   protected:
-    unsigned long status;
-    MACAddress mac;
-
-    Netdev(kernel::hw::pci::pci_device& device);
-
-   public:
-    kernel::hw::pci::pci_device& device;
-
-    virtual ~Netdev() = default;
-
-    int setLinkSpeed(unsigned long speedFlag);
-
-    virtual int up() = 0;
-    virtual isize send(const u8* data, usize len) = 0;
-};
-
-int registerNetdev(std::unique_ptr<Netdev> dev);
-
-} // namespace net

+ 0 - 7
include/types/allocator.hpp

@@ -1,13 +1,6 @@
 #pragma once
 #include <cstddef>
-#include <memory>
-#include <new>
-#include <type_traits>
-#include <utility>
 
-#include <stdint.h>
-
-#include <types/cplusplus.hpp>
 #include <types/types.h>
 
 #include <kernel/async/lock.hpp>

+ 0 - 46
include/types/bitmap.hpp

@@ -1,46 +0,0 @@
-#pragma once
-
-#include <cstddef>
-#include <functional>
-
-namespace types {
-
-class bitmap {
-   public:
-    using deleter_type = std::function<void(unsigned char*, std::size_t)>;
-
-   private:
-    deleter_type m_del;
-    std::size_t m_size;
-    unsigned char* m_bm;
-
-    static constexpr std::size_t SZ = sizeof(unsigned char) * 8;
-
-   public:
-    constexpr bitmap(const deleter_type& del, unsigned char* bm,
-                     std::size_t size)
-        : m_del(del), m_size(size), m_bm(bm) {}
-    constexpr bitmap(deleter_type&& del, unsigned char* bm, std::size_t size)
-        : m_del(std::move(del)), m_size(size), m_bm(bm) {}
-
-    explicit constexpr bitmap(std::size_t size)
-        : m_del{[](unsigned char* bm, std::size_t) { delete[] bm; }}
-        , m_size{(size / SZ) + ((size % SZ) ? 1 : 0)}
-        , m_bm{new unsigned char[m_size]{}} {}
-
-    bitmap(const bitmap&) = delete;
-
-    constexpr ~bitmap() { m_del(m_bm, m_size); }
-
-    constexpr bool test(std::size_t n) const {
-        return (m_bm[n / SZ] & (1 << (n % SZ))) != 0;
-    }
-
-    constexpr void set(std::size_t n) { m_bm[n / SZ] |= (1 << (n % SZ)); }
-
-    constexpr void clear(std::size_t n) { m_bm[n / SZ] &= (~(1 << (n % SZ))); }
-
-    constexpr std::size_t size() const noexcept { return m_size; }
-};
-
-} // namespace types

+ 0 - 134
include/types/buffer.hpp

@@ -1,134 +0,0 @@
-#pragma once
-
-#include <memory>
-
-#include <stdint.h>
-#include <stdio.h>
-
-#include <types/allocator.hpp>
-
-namespace types {
-
-template <typename Allocator>
-class basic_buffer {
-   public:
-    using alloc_traits = std::allocator_traits<Allocator>;
-
-   private:
-    char* const start;
-    char* const end;
-    char* base;
-    char* head;
-    size_t count;
-    Allocator alloc{};
-
-   private:
-    constexpr char _get_char(char* ptr) {
-        --count;
-        return *ptr;
-    }
-
-    constexpr void _put_char(char c) {
-        *head = c;
-        ++count;
-    }
-
-    constexpr char* _forward(char* ptr) {
-        if (ptr == end)
-            return start;
-        else
-            return ptr + 1;
-    }
-
-    constexpr char* _backward(char* ptr) {
-        if (ptr == start)
-            return end;
-        else
-            return ptr - 1;
-    }
-
-   public:
-    constexpr basic_buffer(size_t size)
-        : start{alloc_traits::allocate(alloc, size)}
-        , end{start + size - 1}
-        , base{start}
-        , head{start}
-        , count{0} {}
-
-    constexpr basic_buffer(const basic_buffer& buf)
-        : start{alloc_traits::allocate(alloc, buf.end + 1 - buf.start)}
-        , end{(uint32_t)start + (uint32_t)buf.end - (uint32_t)buf.start}
-        , base{(uint32_t)start + (uint32_t)buf.base - (uint32_t)buf.start}
-        , head{(uint32_t)start + (uint32_t)buf.base - (uint32_t)buf.start}
-        , count{buf.count} {}
-
-    constexpr basic_buffer(basic_buffer&& buf)
-        : start{buf.start}
-        , end{buf.end}
-        , base{buf.base}
-        , head{buf.head}
-        , count{buf.count} {}
-
-    constexpr ~basic_buffer() {
-        if (start)
-            alloc_traits::deallocate(alloc, start, end - start);
-    }
-
-    constexpr bool empty(void) const { return count == 0; }
-
-    constexpr bool full(void) const {
-        return count == static_cast<size_t>(end - start + 1);
-    }
-
-    constexpr int front(void) {
-        if (empty())
-            return EOF;
-        return *base;
-    }
-
-    constexpr int back(void) {
-        if (empty())
-            return EOF;
-        return *_backward(head);
-    }
-
-    constexpr int get(void) {
-        if (empty())
-            return EOF;
-
-        char c = _get_char(base);
-        base = _forward(base);
-        return c;
-    }
-
-    constexpr int pop(void) {
-        if (empty())
-            return EOF;
-
-        char c = _get_char(_backward(head));
-        head = _backward(head);
-        return c;
-    }
-
-    constexpr int put(char c) {
-        if (full())
-            return EOF;
-
-        _put_char(c);
-        head = _forward(head);
-        return c;
-    }
-
-    constexpr size_t size(void) const { return count; }
-
-    constexpr size_t avail(void) const { return end - start + 1 - count; }
-
-    constexpr void clear(void) {
-        count = 0;
-        head = base;
-    }
-};
-
-using buffer = basic_buffer<std::allocator<char>>;
-
-} // namespace types

+ 0 - 18
include/types/cplusplus.hpp

@@ -1,18 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-#include <type_traits>
-
-namespace types {
-
-class non_copyable {
-   public:
-    virtual ~non_copyable() = default;
-    non_copyable() = default;
-    non_copyable(const non_copyable&) = delete;
-    non_copyable& operator=(const non_copyable&) = delete;
-};
-
-} // namespace types
-
-#endif

+ 0 - 4
include/types/types.h

@@ -29,7 +29,3 @@
 #define likely(expr) (!!(expr))
 #define unlikely(expr) (!!(expr))
 #endif
-
-#ifdef __cplusplus
-#include <types/cplusplus.hpp>
-#endif

+ 0 - 16
include/types/user_types.hpp

@@ -1,16 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#include <types/types.h>
-
-namespace types {
-
-using ptr32_t = uint32_t;
-
-struct iovec32 {
-    ptr32_t iov_base;
-    ptr32_t iov_len;
-};
-
-} // namespace types

+ 4 - 0
rust-headers.hpp

@@ -0,0 +1,4 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <kernel/mem/paging_asm.h>

+ 0 - 227
src/asm/interrupt.s

@@ -1,227 +0,0 @@
-.text
-
-#define RAX     0x00
-#define RBX     0x08
-#define RCX     0x10
-#define RDX     0x18
-#define RDI     0x20
-#define RSI     0x28
-#define R8      0x30
-#define R9      0x38
-#define R10     0x40
-#define R11     0x48
-#define R12     0x50
-#define R13     0x58
-#define R14     0x60
-#define R15     0x68
-#define RBP     0x70
-#define INT_NO  0x78
-#define ERRCODE 0x80
-#define RIP     0x88
-#define CS      0x90
-#define FLAGS   0x98
-#define RSP     0xa0
-#define SS      0xa8
-
-.macro movcfi reg, offset
-	mov \reg, \offset(%rsp)
-	.cfi_rel_offset \reg, \offset
-.endm
-
-.macro movrst reg, offset
-	mov \offset(%rsp), \reg
-	.cfi_restore \reg
-.endm
-
-.globl ISR_stub_restore
-.type ISR_stub_restore @function
-
-ISR_stub:
-	.cfi_startproc
-	.cfi_signal_frame
-	.cfi_def_cfa_offset 0x18
-	.cfi_offset %rsp, 0x10
-
-	cmpq $0x08, 24(%rsp)
-	je 1f
-	swapgs
-
-1:
-	sub $0x78, %rsp
-	.cfi_def_cfa_offset 0x90
-
-	movcfi %rax, RAX
-	movcfi %rbx, RBX
-	movcfi %rcx, RCX
-	movcfi %rdx, RDX
-	movcfi %rdi, RDI
-	movcfi %rsi, RSI
-	movcfi %r8,  R8
-	movcfi %r9,  R9
-	movcfi %r10, R10
-	movcfi %r11, R11
-	movcfi %r12, R12
-	movcfi %r13, R13
-	movcfi %r14, R14
-	movcfi %r15, R15
-	movcfi %rbp, RBP
-
-	mov INT_NO(%rsp), %rax
-	sub $ISR0, %rax
-	shr $3, %rax
-	mov %rax, INT_NO(%rsp)
-
-	mov %rsp, %rbx
-	.cfi_def_cfa_register %rbx
-
-	and $~0xf, %rsp
-	sub $512, %rsp
-	fxsave (%rsp)
-
-	mov %rbx, %rdi
-	mov %rsp, %rsi
-	call interrupt_handler
-
-ISR_stub_restore:
-	fxrstor (%rsp)
-	mov %rbx, %rsp
-	.cfi_def_cfa_register %rsp
-
-	movrst %rax, RAX
-	movrst %rbx, RBX
-	movrst %rcx, RCX
-	movrst %rdx, RDX
-	movrst %rdi, RDI
-	movrst %rsi, RSI
-	movrst %r8,  R8
-	movrst %r9,  R9
-	movrst %r10, R10
-	movrst %r11, R11
-	movrst %r12, R12
-	movrst %r13, R13
-	movrst %r14, R14
-	movrst %r15, R15
-	movrst %rbp, RBP
-
-	add $0x88, %rsp
-	.cfi_def_cfa_offset 0x08
-
-	cmpq $0x08, 8(%rsp)
-	je 1f
-	swapgs
-
-1:
-	iretq
-	.cfi_endproc
-
-.altmacro
-.macro build_isr_no_err name
-	.align 8
-	.globl ISR\name
-	.type  ISR\name @function
-	ISR\name:
-		.cfi_startproc
-		.cfi_signal_frame
-		.cfi_def_cfa_offset 0x08
-		.cfi_offset %rsp, 0x10
-
-		.cfi_same_value %rax
-		.cfi_same_value %rbx
-		.cfi_same_value %rcx
-		.cfi_same_value %rdx
-		.cfi_same_value %rdi
-		.cfi_same_value %rsi
-		.cfi_same_value %r8
-		.cfi_same_value %r9
-		.cfi_same_value %r10
-		.cfi_same_value %r11
-		.cfi_same_value %r12
-		.cfi_same_value %r13
-		.cfi_same_value %r14
-		.cfi_same_value %r15
-		.cfi_same_value %rbp
-
-		push %rbp # push placeholder for error code
-		.cfi_def_cfa_offset 0x10
-
-		call ISR_stub
-		.cfi_endproc
-.endm
-
-.altmacro
-.macro build_isr_err name
-	.align 8
-	.globl ISR\name
-	.type  ISR\name @function
-	ISR\name:
-		.cfi_startproc
-		.cfi_signal_frame
-		.cfi_def_cfa_offset 0x10
-		.cfi_offset %rsp, 0x10
-
-		.cfi_same_value %rax
-		.cfi_same_value %rbx
-		.cfi_same_value %rcx
-		.cfi_same_value %rdx
-		.cfi_same_value %rdi
-		.cfi_same_value %rsi
-		.cfi_same_value %r8
-		.cfi_same_value %r9
-		.cfi_same_value %r10
-		.cfi_same_value %r11
-		.cfi_same_value %r12
-		.cfi_same_value %r13
-		.cfi_same_value %r14
-		.cfi_same_value %r15
-		.cfi_same_value %rbp
-
-		call ISR_stub
-		.cfi_endproc
-.endm
-
-build_isr_no_err 0
-build_isr_no_err 1
-build_isr_no_err 2
-build_isr_no_err 3
-build_isr_no_err 4
-build_isr_no_err 5
-build_isr_no_err 6
-build_isr_no_err 7
-build_isr_err    8
-build_isr_no_err 9
-build_isr_err    10
-build_isr_err    11
-build_isr_err    12
-build_isr_err    13
-build_isr_err    14
-build_isr_no_err 15
-build_isr_no_err 16
-build_isr_err    17
-build_isr_no_err 18
-build_isr_no_err 19
-build_isr_no_err 20
-build_isr_err    21
-build_isr_no_err 22
-build_isr_no_err 23
-build_isr_no_err 24
-build_isr_no_err 25
-build_isr_no_err 26
-build_isr_no_err 27
-build_isr_no_err 28
-build_isr_err    29
-build_isr_err    30
-build_isr_no_err 31
-
-.set i, 32
-.rept 0x80+1
-	build_isr_no_err %i
-	.set i, i+1
-.endr
-
-.section .rodata
-
-.align 8
-.globl ISR_START_ADDR
-.type  ISR_START_ADDR @object
-ISR_START_ADDR:
-	.quad ISR0

+ 3 - 1
src/driver/ahci/mod.rs

@@ -1,5 +1,6 @@
 use crate::{
     fs::procfs,
+    io::Buffer as _,
     kernel::{
         block::{make_device, BlockDevice},
         interrupt::register_irq_handler,
@@ -92,7 +93,8 @@ impl Device {
                     let port = port.clone();
                     let name = format!("ahci-p{}-stats", port.nport);
                     procfs::populate_root(name.into_bytes().into(), move |buffer| {
-                        writeln!(buffer, "{:?}", port.stats.lock().as_ref()).map_err(|_| EIO)
+                        writeln!(&mut buffer.get_writer(), "{:?}", port.stats.lock().as_ref())
+                            .map_err(|_| EIO)
                     })?;
                 }
 

+ 2 - 1
src/fs/fat32.rs

@@ -5,7 +5,7 @@ use alloc::{
     sync::{Arc, Weak},
     vec::Vec,
 };
-use bindings::{EINVAL, EIO, S_IFDIR, S_IFREG};
+use bindings::{EINVAL, EIO};
 
 use itertools::Itertools;
 
@@ -13,6 +13,7 @@ use crate::{
     io::{Buffer, RawBuffer, UninitBuffer},
     kernel::{
         block::{make_device, BlockDevice, BlockDeviceRequest},
+        constants::{S_IFDIR, S_IFREG},
         mem::{paging::Page, phys::PhysPtr},
         vfs::{
             dentry::Dentry,

+ 3 - 2
src/fs/procfs.rs

@@ -2,7 +2,7 @@ use alloc::{
     collections::btree_map::BTreeMap,
     sync::{Arc, Weak},
 };
-use bindings::{EACCES, ENOTDIR, S_IFDIR, S_IFREG};
+use bindings::{EACCES, ENOTDIR};
 use core::{ops::ControlFlow, sync::atomic::Ordering};
 use itertools::Itertools;
 use lazy_static::lazy_static;
@@ -10,6 +10,7 @@ use lazy_static::lazy_static;
 use crate::{
     io::Buffer,
     kernel::{
+        constants::{S_IFDIR, S_IFREG},
         mem::paging::{Page, PageBuffer},
         vfs::{
             dentry::Dentry,
@@ -272,7 +273,7 @@ impl ProcFsFile for DumpMountsFile {
     }
 
     fn read(&self, buffer: &mut PageBuffer) -> KResult<usize> {
-        dump_mounts(buffer);
+        dump_mounts(&mut buffer.get_writer());
 
         Ok(buffer.len())
     }

+ 2 - 1
src/fs/tmpfs.rs

@@ -1,10 +1,11 @@
 use alloc::sync::{Arc, Weak};
-use bindings::{EINVAL, EIO, EISDIR, S_IFBLK, S_IFCHR, S_IFDIR, S_IFLNK, S_IFREG};
+use bindings::{EINVAL, EIO, EISDIR};
 use core::{ops::ControlFlow, sync::atomic::Ordering};
 use itertools::Itertools;
 
 use crate::{
     io::Buffer,
+    kernel::constants::{S_IFBLK, S_IFCHR, S_IFDIR, S_IFLNK, S_IFREG},
     kernel::vfs::{
         dentry::{dcache, Dentry},
         inode::{define_struct_inode, AtomicIno, Ino, Inode, Mode, WriteOffset},

+ 27 - 40
src/io.rs

@@ -2,7 +2,7 @@ use bindings::EFAULT;
 
 use crate::prelude::*;
 
-use core::{fmt::Write, mem::MaybeUninit};
+use core::mem::MaybeUninit;
 
 #[must_use]
 pub enum FillResult {
@@ -41,6 +41,13 @@ pub trait Buffer {
     fn available(&self) -> usize {
         self.total() - self.wrote()
     }
+
+    fn get_writer(&mut self) -> BufferWrite<'_, Self>
+    where
+        Self: Sized,
+    {
+        BufferWrite(self)
+    }
 }
 
 pub trait BufferFill<T: Copy> {
@@ -57,6 +64,22 @@ impl<T: Copy, B: Buffer + ?Sized> BufferFill<T> for B {
     }
 }
 
+pub struct BufferWrite<'b, B>(&'b mut B)
+where
+    B: Buffer + ?Sized;
+
+impl<'b, B> core::fmt::Write for BufferWrite<'b, B>
+where
+    B: Buffer + ?Sized,
+{
+    fn write_str(&mut self, s: &str) -> core::fmt::Result {
+        match self.0.fill(s.as_bytes()) {
+            Ok(FillResult::Done(_)) => Ok(()),
+            _ => Err(core::fmt::Error),
+        }
+    }
+}
+
 pub struct UninitBuffer<'lt, T: Copy + Sized> {
     data: Box<MaybeUninit<T>>,
     buffer: RawBuffer<'lt>,
@@ -77,10 +100,10 @@ impl<'lt, T: Copy + Sized> UninitBuffer<'lt, T> {
 
     pub fn assume_filled_ref(&self) -> KResult<&T> {
         if !self.buffer.filled() {
-            return Err(EFAULT);
+            Err(EFAULT)
+        } else {
+            Ok(unsafe { self.data.assume_init_ref() })
         }
-
-        Ok(unsafe { self.data.assume_init_ref() })
     }
 
     pub fn assume_init(self) -> Option<T> {
@@ -114,15 +137,6 @@ pub struct RawBuffer<'lt> {
 }
 
 impl<'lt> RawBuffer<'lt> {
-    pub fn new_from_mut<T: Copy + Sized>(buf: &'lt mut T) -> Self {
-        Self {
-            buf: buf as *mut T as *mut u8,
-            tot: core::mem::size_of::<T>(),
-            cur: 0,
-            _phantom: core::marker::PhantomData,
-        }
-    }
-
     pub fn new_from_slice<T: Copy + Sized>(buf: &'lt mut [T]) -> Self {
         Self {
             buf: buf.as_mut_ptr() as *mut u8,
@@ -132,15 +146,6 @@ impl<'lt> RawBuffer<'lt> {
         }
     }
 
-    pub fn new_from_raw(buf: *mut u8, tot: usize) -> Self {
-        Self {
-            buf,
-            tot,
-            cur: 0,
-            _phantom: core::marker::PhantomData,
-        }
-    }
-
     pub fn count(&self) -> usize {
         self.cur
     }
@@ -240,21 +245,3 @@ impl Buffer for ByteBuffer<'_> {
         self.cur
     }
 }
-
-impl Write for RawBuffer<'_> {
-    fn write_str(&mut self, s: &str) -> core::fmt::Result {
-        match self.fill(s.as_bytes()) {
-            Ok(FillResult::Done(_)) => Ok(()),
-            _ => Err(core::fmt::Error),
-        }
-    }
-}
-
-impl Write for dyn Buffer + '_ {
-    fn write_str(&mut self, s: &str) -> core::fmt::Result {
-        match self.fill(s.as_bytes()) {
-            Ok(FillResult::Done(_)) => Ok(()),
-            _ => Err(core::fmt::Error),
-        }
-    }
-}

+ 8 - 0
src/kernel/constants.rs

@@ -14,6 +14,7 @@ pub const SIG_UNBLOCK: u32 = 1;
 pub const SIG_SETMASK: u32 = 2;
 
 pub const SA_SIGINFO: u32 = 4;
+pub const SA_RESTORER: u32 = 0x04000000;
 
 pub const CLOCK_REALTIME: u32 = 0;
 pub const CLOCK_MONOTONIC: u32 = 1;
@@ -21,6 +22,13 @@ pub const CLOCK_MONOTONIC: u32 = 1;
 pub const ENXIO: u32 = 6;
 pub const ENOEXEC: u32 = 8;
 
+pub const S_IFIFO: u32 = 0o010000;
+pub const S_IFCHR: u32 = 0o020000;
+pub const S_IFDIR: u32 = 0o040000;
+pub const S_IFBLK: u32 = 0o060000;
+pub const S_IFREG: u32 = 0o100000;
+pub const S_IFLNK: u32 = 0o120000;
+
 bitflags! {
     #[derive(Debug, Clone, Copy)]
     pub struct UserMmapFlags: u32 {

+ 8 - 5
src/kernel/interrupt.rs

@@ -1,9 +1,9 @@
 use alloc::sync::Arc;
 
-use arch::InterruptContext;
+use arch::{ExtendedContext, InterruptContext};
 use lazy_static::lazy_static;
 
-use crate::bindings::root::{mmx_registers, EINVAL};
+use crate::bindings::root::EINVAL;
 use crate::{driver::Port8, prelude::*};
 
 use super::cpu::current_cpu;
@@ -47,15 +47,18 @@ fn fault_handler(int_stack: &mut InterruptContext) {
 }
 
 #[no_mangle]
-pub extern "C" fn interrupt_handler(int_stack: *mut InterruptContext, mmxregs: *mut mmx_registers) {
+pub extern "C" fn interrupt_handler(
+    int_stack: *mut InterruptContext,
+    ext_ctx: *mut ExtendedContext,
+) {
     let int_stack = unsafe { &mut *int_stack };
-    let mmxregs = unsafe { &mut *mmxregs };
+    let ext_ctx = unsafe { &mut *ext_ctx };
 
     match int_stack.int_no {
         // Fault
         0..0x20 => fault_handler(int_stack),
         // Syscall
-        0x80 => handle_syscall32(int_stack.rax as usize, int_stack, mmxregs),
+        0x80 => handle_syscall32(int_stack.rax as usize, int_stack, ext_ctx),
         // Timer
         0x40 => timer_interrupt(),
         // IRQ

+ 1 - 24
src/kernel/mem/paging.rs

@@ -163,12 +163,6 @@ impl PageBuffer {
         unsafe { core::slice::from_raw_parts(self.page.as_cached().as_ptr::<u8>(), self.offset) }
     }
 
-    pub fn as_mut_slice(&self) -> &mut [u8] {
-        unsafe {
-            core::slice::from_raw_parts_mut(self.page.as_cached().as_ptr::<u8>(), self.offset)
-        }
-    }
-
     fn available_as_slice(&self) -> &mut [u8] {
         unsafe {
             core::slice::from_raw_parts_mut(
@@ -177,23 +171,6 @@ impl PageBuffer {
             )
         }
     }
-
-    pub fn consume(&mut self, len: usize) {
-        self.offset += len;
-    }
-}
-
-impl core::fmt::Write for PageBuffer {
-    fn write_str(&mut self, s: &str) -> core::fmt::Result {
-        if s.len() > self.remaining() {
-            return Err(core::fmt::Error);
-        }
-
-        self.available_as_slice()[..s.len()].copy_from_slice(s.as_bytes());
-        self.consume(s.len());
-
-        Ok(())
-    }
 }
 
 impl Buffer for PageBuffer {
@@ -212,7 +189,7 @@ impl Buffer for PageBuffer {
 
         let len = core::cmp::min(data.len(), self.remaining());
         self.available_as_slice()[..len].copy_from_slice(&data[..len]);
-        self.consume(len);
+        self.offset += len;
 
         if len < data.len() {
             Ok(FillResult::Partial(len))

+ 0 - 7
src/kernel/process.cpp

@@ -1,7 +0,0 @@
-#include <types/types.h>
-
-// TODO: remove this
-void NORETURN freeze(void) {
-    for (;;)
-        asm volatile("cli\n\thlt");
-}

+ 12 - 9
src/kernel/syscall.rs

@@ -1,9 +1,8 @@
 use crate::{
-    bindings::root::{mmx_registers},
     kernel::task::{ProcessList, Signal},
     println_warn,
 };
-use arch::InterruptContext;
+use arch::{ExtendedContext, InterruptContext};
 
 extern crate arch;
 
@@ -148,7 +147,7 @@ macro_rules! syscall32_call {
 macro_rules! define_syscall32 {
     ($name:ident, $handler:ident) => {
         fn $name(_int_stack: &mut $crate::kernel::syscall::arch::InterruptContext,
-            _mmxregs: &mut $crate::bindings::root::mmx_registers) -> usize {
+            _: &mut ::arch::ExtendedContext) -> usize {
             use $crate::kernel::syscall::MapReturnValue;
 
             match $handler() {
@@ -160,7 +159,7 @@ macro_rules! define_syscall32 {
     ($name:ident, $handler:ident, $($arg:ident: $argt:ty),*) => {
         fn $name(
             int_stack: &mut $crate::kernel::syscall::arch::InterruptContext,
-            _mmxregs: &mut $crate::bindings::root::mmx_registers) -> usize {
+            _: &mut ::arch::ExtendedContext) -> usize {
             use $crate::kernel::syscall::syscall32_call;
 
             syscall32_call!(int_stack, $handler, $($arg: $argt),*)
@@ -183,13 +182,13 @@ use super::task::Thread;
 pub(self) use {arg_register, define_syscall32, format_expand, register_syscall, syscall32_call};
 
 pub(self) struct SyscallHandler {
-    handler: fn(&mut InterruptContext, &mut mmx_registers) -> usize,
+    handler: fn(&mut InterruptContext, &mut ExtendedContext) -> usize,
     name: &'static str,
 }
 
 pub(self) fn register_syscall_handler(
     no: usize,
-    handler: fn(&mut InterruptContext, &mut mmx_registers) -> usize,
+    handler: fn(&mut InterruptContext, &mut ExtendedContext) -> usize,
     name: &'static str,
 ) {
     // SAFETY: `SYSCALL_HANDLERS` is never modified after initialization.
@@ -213,7 +212,11 @@ const SYSCALL_HANDLERS_SIZE: usize = 404;
 static mut SYSCALL_HANDLERS: [Option<SyscallHandler>; SYSCALL_HANDLERS_SIZE] =
     [const { None }; SYSCALL_HANDLERS_SIZE];
 
-pub fn handle_syscall32(no: usize, int_stack: &mut InterruptContext, mmxregs: &mut mmx_registers) {
+pub fn handle_syscall32(
+    no: usize,
+    int_stack: &mut InterruptContext,
+    ext_ctx: &mut ExtendedContext,
+) {
     // SAFETY: `SYSCALL_HANDLERS` are never modified after initialization.
     let syscall = unsafe { SYSCALL_HANDLERS.get(no) }.and_then(Option::as_ref);
 
@@ -224,7 +227,7 @@ pub fn handle_syscall32(no: usize, int_stack: &mut InterruptContext, mmxregs: &m
         }
         Some(handler) => {
             arch::enable_irqs();
-            let retval = (handler.handler)(int_stack, mmxregs);
+            let retval = (handler.handler)(int_stack, ext_ctx);
 
             // SAFETY: `int_stack` is always valid.
             int_stack.rax = retval as u64;
@@ -240,6 +243,6 @@ pub fn handle_syscall32(no: usize, int_stack: &mut InterruptContext, mmxregs: &m
     }
 
     if Thread::current().signal_list.has_pending_signal() {
-        Thread::current().signal_list.handle(int_stack, mmxregs);
+        Thread::current().signal_list.handle(int_stack, ext_ctx);
     }
 }

+ 6 - 6
src/kernel/syscall/procops.rs

@@ -1,7 +1,7 @@
 use alloc::borrow::ToOwned;
 use alloc::ffi::CString;
-use arch::InterruptContext;
-use bindings::{mmx_registers, EINVAL, ENOENT, ENOTDIR, ESRCH};
+use arch::{ExtendedContext, InterruptContext};
+use bindings::{EINVAL, ENOENT, ENOTDIR, ESRCH};
 use bitflags::bitflags;
 
 use crate::elf::ParsedElf32;
@@ -104,7 +104,7 @@ fn do_execve(exec: &[u8], argv: Vec<CString>, envp: Vec<CString>) -> KResult<(VA
     }
 }
 
-fn sys_execve(int_stack: &mut InterruptContext, _mmxregs: &mut mmx_registers) -> usize {
+fn sys_execve(int_stack: &mut InterruptContext, _: &mut ExtendedContext) -> usize {
     match (|| -> KResult<()> {
         let exec = int_stack.rbx as *const u8;
         let exec = UserString::new(exec)?;
@@ -458,7 +458,7 @@ define_syscall32!(sys_rt_sigprocmask, do_rt_sigprocmask,
 define_syscall32!(sys_rt_sigaction, do_rt_sigaction,
     signum: u32, act: *const UserSignalAction, oldact: *mut UserSignalAction, sigsetsize: usize);
 
-fn sys_fork(int_stack: &mut InterruptContext, _mmxregs: &mut mmx_registers) -> usize {
+fn sys_fork(int_stack: &mut InterruptContext, _: &mut ExtendedContext) -> usize {
     let mut procs = ProcessList::get().lock();
     let new_thread = Thread::current().new_cloned(procs.as_mut());
     let mut new_int_stack = int_stack.clone();
@@ -469,8 +469,8 @@ fn sys_fork(int_stack: &mut InterruptContext, _mmxregs: &mut mmx_registers) -> u
     new_thread.process.pid as usize
 }
 
-fn sys_sigreturn(int_stack: &mut InterruptContext, mmxregs: &mut mmx_registers) -> usize {
-    let result = Thread::current().signal_list.restore(int_stack, mmxregs);
+fn sys_sigreturn(int_stack: &mut InterruptContext, ext_ctx: &mut ExtendedContext) -> usize {
+    let result = Thread::current().signal_list.restore(int_stack, ext_ctx);
     match result {
         Ok(ret) => ret,
         Err(_) => {

+ 29 - 25
src/kernel/task/signal.rs

@@ -3,19 +3,15 @@ use core::cmp::Reverse;
 use crate::{
     io::BufferFill,
     kernel::{
-        constants::SA_SIGINFO,
+        constants::{SA_RESTORER, SA_SIGINFO},
         user::{dataflow::UserBuffer, UserPointer},
     },
     prelude::*,
 };
 
 use alloc::collections::{binary_heap::BinaryHeap, btree_map::BTreeMap};
-use arch::InterruptContext;
-use bindings::{
-    mmx_registers, EFAULT, EINVAL, SA_RESTORER, SIGABRT, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGILL,
-    SIGKILL, SIGQUIT, SIGSEGV, SIGSTOP, SIGSYS, SIGTRAP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG,
-    SIGWINCH, SIGXCPU, SIGXFSZ,
-};
+use arch::{ExtendedContext, InterruptContext};
+use bindings::{EFAULT, EINVAL};
 
 use super::{ProcessList, Thread};
 
@@ -92,34 +88,42 @@ pub enum RaiseResult {
 
 impl Signal {
     fn is_continue(&self) -> bool {
-        self.0 == SIGCONT
+        self == &Self::SIGCONT
     }
 
     fn is_stop(&self) -> bool {
-        match self.0 {
-            SIGSTOP | SIGTSTP | SIGTTIN | SIGTTOU => true,
+        match self {
+            &Self::SIGSTOP | &Self::SIGTSTP | &Self::SIGTTIN | &Self::SIGTTOU => true,
             _ => false,
         }
     }
 
     fn is_ignore(&self) -> bool {
-        match self.0 {
-            SIGCHLD | SIGURG | SIGWINCH => true,
+        match self {
+            &Self::SIGCHLD | &Self::SIGURG | &Self::SIGWINCH => true,
             _ => false,
         }
     }
 
     pub fn is_now(&self) -> bool {
-        match self.0 {
-            SIGKILL | SIGSTOP => true,
+        match self {
+            &Self::SIGKILL | &Self::SIGSTOP => true,
             _ => false,
         }
     }
 
     pub fn is_coredump(&self) -> bool {
-        match self.0 {
-            SIGQUIT | SIGILL | SIGABRT | SIGFPE | SIGSEGV | SIGBUS | SIGTRAP | SIGSYS | SIGXCPU
-            | SIGXFSZ => true,
+        match self {
+            &Self::SIGQUIT
+            | &Self::SIGILL
+            | &Self::SIGABRT
+            | &Self::SIGFPE
+            | &Self::SIGSEGV
+            | &Self::SIGBUS
+            | &Self::SIGTRAP
+            | &Self::SIGSYS
+            | &Self::SIGXCPU
+            | &Self::SIGXFSZ => true,
             _ => false,
         }
     }
@@ -171,14 +175,14 @@ impl SignalAction {
         signum: u32,
         old_mask: u64,
         int_stack: &mut InterruptContext,
-        mmxregs: &mut mmx_registers,
+        ext_ctx: &mut ExtendedContext,
     ) -> KResult<()> {
         if self.sa_flags & SA_RESTORER as usize == 0 {
             return Err(EINVAL);
         }
 
         const CONTEXT_SIZE: usize = size_of::<InterruptContext>()
-            + size_of::<mmx_registers>()
+            + size_of::<ExtendedContext>()
             + size_of::<usize>() // old_mask
             + size_of::<u32>(); // `sa_handler` argument: `signum`
 
@@ -192,7 +196,7 @@ impl SignalAction {
         stack.copy(&restorer_address)?.ok_or(EFAULT)?; // Restorer address
         stack.copy(&signum)?.ok_or(EFAULT)?; // Restorer address
         stack.copy(&old_mask)?.ok_or(EFAULT)?; // Original signal mask
-        stack.copy(mmxregs)?.ok_or(EFAULT)?; // MMX registers
+        stack.copy(ext_ctx)?.ok_or(EFAULT)?; // MMX registers
         stack.copy(int_stack)?.ok_or(EFAULT)?; // Interrupt stack
 
         int_stack.rip = self.sa_handler as u64;
@@ -335,7 +339,7 @@ impl SignalList {
     /// # Safety
     /// This function might never return. Caller must make sure that local variables
     /// that own resources are dropped before calling this function.
-    pub fn handle(&self, int_stack: &mut InterruptContext, mmxregs: &mut mmx_registers) {
+    pub fn handle(&self, int_stack: &mut InterruptContext, ext_ctx: &mut ExtendedContext) {
         loop {
             let signal = {
                 let signal = match self.inner.lock_irq().pop() {
@@ -353,7 +357,7 @@ impl SignalList {
                             old_mask
                         };
                         let result =
-                            handler.handle(signal.to_signum(), old_mask, int_stack, mmxregs);
+                            handler.handle(signal.to_signum(), old_mask, int_stack, ext_ctx);
                         if result.is_err() {
                             self.inner.lock_irq().set_mask(old_mask);
                         }
@@ -399,14 +403,14 @@ impl SignalList {
     pub fn restore(
         &self,
         int_stack: &mut InterruptContext,
-        mmxregs: &mut mmx_registers,
+        ext_ctx: &mut ExtendedContext,
     ) -> KResult<usize> {
         let old_mask_vaddr = int_stack.rsp as usize;
         let old_mmxregs_vaddr = old_mask_vaddr + size_of::<usize>();
-        let old_int_stack_vaddr = old_mmxregs_vaddr + size_of::<mmx_registers>();
+        let old_int_stack_vaddr = old_mmxregs_vaddr + size_of::<ExtendedContext>();
 
         let old_mask = UserPointer::<u64>::new_vaddr(old_mask_vaddr)?.read()?;
-        *mmxregs = UserPointer::<mmx_registers>::new_vaddr(old_mmxregs_vaddr)?.read()?;
+        *ext_ctx = UserPointer::<ExtendedContext>::new_vaddr(old_mmxregs_vaddr)?.read()?;
         *int_stack = UserPointer::<InterruptContext>::new_vaddr(old_int_stack_vaddr)?.read()?;
 
         self.inner.lock_irq().set_mask(old_mask);

+ 0 - 52
src/kernel/vga.cpp

@@ -1,52 +0,0 @@
-#define _KERNEL_VGA_C_
-
-#include <stdint.h>
-#include <string.h>
-
-#include <kernel/vga.hpp>
-
-static struct vga_char* p_vga_head = VGA_MEM;
-
-static inline void vga_return() {
-    const int32_t offset = p_vga_head - VGA_MEM;
-    p_vga_head -= (offset % VGA_SCREEN_WIDTH_IN_CHARS);
-}
-
-static inline void vga_new_line() {
-    int32_t offset = p_vga_head - VGA_MEM;
-    offset %= VGA_SCREEN_WIDTH_IN_CHARS;
-    p_vga_head += (VGA_SCREEN_WIDTH_IN_CHARS - offset);
-    if ((p_vga_head - VGA_MEM) >= 80 * 25) {
-        p_vga_head = VGA_MEM;
-    }
-}
-
-static inline void real_vga_put_char(struct vga_char* c) {
-    *p_vga_head = *c;
-    ++p_vga_head;
-    if ((p_vga_head - VGA_MEM) == 80 * 25) {
-        p_vga_head = VGA_MEM;
-    }
-}
-
-void vga_put_char(struct vga_char* c) {
-    switch (c->c) {
-        case CR:
-            vga_return();
-            break;
-        case LF:
-            vga_new_line();
-            break;
-        default:
-            real_vga_put_char(c);
-            break;
-    }
-}
-
-void vga_print(const char* str, uint8_t color) {
-    struct vga_char s_c;
-    s_c.color = color;
-    while ((s_c.c = *(str++)) != 0x00) {
-        vga_put_char(&s_c);
-    }
-}

+ 4 - 3
src/kinit.cpp

@@ -6,12 +6,10 @@
 
 #include <kernel/hw/acpi.hpp>
 #include <kernel/hw/pci.hpp>
-#include <kernel/interrupt.hpp>
 #include <kernel/log.hpp>
 #include <kernel/mem/paging.hpp>
 #include <kernel/mem/phys.hpp>
 #include <kernel/mem/types.hpp>
-#include <kernel/process.hpp>
 #include <kernel/utsname.hpp>
 
 using constructor = void (*)();
@@ -148,7 +146,10 @@ extern "C" void NORETURN kernel_init(bootloader_data* data) {
         : "r"(rust_kinit), "g"(kernel_stack_pfn), "r"(kernel_stack_ptr)
         : "memory");
 
-    freeze();
+    for (;;)
+        asm volatile(
+            "cli\n\t"
+            "hlt\n\t");
 }
 
 } // namespace kernel::kinit

+ 0 - 0
src/net/arp.cc


+ 0 - 13
src/net/ethernet.cc

@@ -1,13 +0,0 @@
-#include <net/ethernet.hpp>
-
-u16 net::htons(u16 x) {
-    return __builtin_bswap16(x);
-}
-
-u32 net::htonl(u32 x) {
-    return __builtin_bswap32(x);
-}
-
-u64 net::htonll(u64 x) {
-    return __builtin_bswap64(x);
-}

+ 0 - 55
src/types/crc.cc

@@ -1,55 +0,0 @@
-#include <defs.hpp>
-
-static constexpr u32 poly8_lookup[256] = {
-    0,          0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
-    0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
-    0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
-    0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
-    0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
-    0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
-    0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
-    0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
-    0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
-    0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
-    0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,
-    0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
-    0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
-    0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
-    0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
-    0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
-    0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
-    0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
-    0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,
-    0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
-    0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
-    0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
-    0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,
-    0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
-    0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
-    0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
-    0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
-    0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
-    0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
-    0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
-    0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,
-    0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
-    0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
-    0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
-    0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
-    0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
-    0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
-    0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
-    0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
-    0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
-    0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
-    0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
-    0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
-
-u32 crc32(const u8* buffer, size_t length) {
-    u32 crc = 0xffffffff;
-
-    for (size_t i = 0; i < length; i++)
-        crc = poly8_lookup[(crc ^ buffer[i]) & 0xff] ^ (crc >> 8);
-
-    return ~crc;
-}

+ 4 - 2
src/types/libstdcpp.cpp

@@ -3,7 +3,6 @@
 #include <types/types.h>
 
 #include <kernel/log.hpp>
-#include <kernel/process.hpp>
 
 extern "C" void NORETURN __stack_chk_fail(void) {
     assert(false);
@@ -19,5 +18,8 @@ extern "C" void NORETURN __cxa_pure_virtual(void) {
 
 void NORETURN __assert_fail(const char* statement, const char* file, int line, const char* func) {
     (void)statement, (void)file, (void)line, (void)func;
-    freeze();
+    for (;;)
+        asm volatile(
+            "cli\n\t"
+            "hlt\n\t");
 }