├── Makefile ├── README.md ├── apic.inc ├── bitmap.inc ├── bomb.inc ├── clear.inc ├── client.inc ├── color.inc ├── copyright.inc ├── errno.inc ├── fonts.inc ├── grub.cfg ├── help.inc ├── hostname.inc ├── init.inc ├── invopcode.inc ├── kbd.inc ├── kernel.inc ├── kfs_5.asm ├── kill.inc ├── login.inc ├── md5.inc ├── paging.py ├── print.inc ├── reboot.inc ├── resolution.inc ├── segvtest.inc ├── server.inc ├── shell.inc ├── showpid.inc ├── shutdown.inc ├── sigint.inc ├── signal.inc ├── signal_enum.inc ├── sockpoc.inc ├── sqrt.inc ├── system.inc ├── teletype.inc ├── uid.inc ├── uname.inc ├── usertest.inc ├── vdso.inc └── vm86.inc /Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: all debug clean 3 | 4 | AS = fasm 5 | DEFINE = 6 | SRC = kfs_5.asm system.inc kernel.inc bitmap.inc apic.inc init.inc login.inc kbd.inc fonts.inc teletype.inc\ 7 | shell.inc copyright.inc help.inc sigint.inc uid.inc uname.inc reboot.inc shutdown.inc hostname.inc\ 8 | color.inc resolution.inc clear.inc usertest.inc segvtest.inc kill.inc vdso.inc vm86.inc signal.inc\ 9 | sockpoc.inc client.inc server.inc sqrt.inc md5.inc bomb.inc invopcode.inc showpid.inc print.inc 10 | ELF = kfs_5 11 | CFG = grub.cfg 12 | ISO = iso 13 | 14 | TARGET = achiu-au.iso 15 | 16 | ifeq ($(MAKECMDGOALS),debug) 17 | DEFINE = -dDEBUG="" 18 | endif 19 | 20 | all: $(TARGET) ; 21 | debug: $(TARGET) ; 22 | 23 | $(TARGET): $(SRC) 24 | @$(AS) $(DEFINE) -m100000 $< $(ELF) 25 | @mkdir -p $(ISO)/boot/grub 26 | @cp $(ELF) $(ISO)/boot 27 | @cp grub.cfg $(ISO)/boot/grub 28 | @grub-mkrescue -o $@ $(ISO) 29 | 30 | clean: 31 | @rm -rf $(ISO) $(TARGET) $(ELF) 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **Unix-Like OS** 2 | 3 | Un système d'exploitation éducatif inspiré des premières implémentations de **Unix**. 4 | Ce projet vise à reproduire les fonctionnalités fondamentales de Unix, notamment la gestion des comptes utilisateurs, la pagination mémoire, et les fonctionnalités essentielles d’un système d’exploitation, le tout développé entièrement en **assembleur**. 5 | 6 | --- 7 | 8 | ## **Fonctionnalités** 9 | - 🌐 **Environnement minimaliste de type Unix** : Interface simplifiée et fonctions essentielles. 10 | - 👥 **Gestion des comptes utilisateurs** : Prise en charge de comptes de base avec des privilèges utilisateur simples. 11 | - 🛠️ **Pagination mémoire** : Implémentation de mécanismes de gestion de mémoire pour une meilleure allocation et isolation. 12 | - 💻 **Développement bas niveau** : Codé entièrement en assembleur avec **Flat Assembler (FASM)** et pris en charge par **GRUB 2.06** comme bootloader. 13 | 14 | --- 15 | 16 | ## **Prérequis** 17 | Pour construire et exécuter ce système d’exploitation, vous aurez besoin de : 18 | - **Flat Assembler (FASM)** : Pour compiler le code assembleur. 19 | - **GRUB 2.06** : Pour le chargement du noyau. 20 | - Un environnement Linux ou tout autre système prenant en charge la compilation GRUB et l’assemblage FASM. 21 | 22 | --- 23 | 24 | ## **Installation et Compilation** 25 | 26 | ### **1. Préparation de GRUB** 27 | Pour configurer et compiler GRUB 2.06 pour ce projet, suivez les étapes suivantes : 28 | ```bash 29 | ./configure --target=x86_64 --disable-werror 30 | make 31 | ``` 32 | -------------------------------------------------------------------------------- /apic.inc: -------------------------------------------------------------------------------- 1 | 2 | enum _EDGE_TRIGGER, _LEVEL_TRIGGER 3 | enum _LOW_POLARITY, _HIGH_POLARITY 4 | struct _interrupt_mapping _irq*, _gsi*, _trigger*, _polarity*, _vector* 5 | assert ((_strinit) | ((_vector) >= 8H)) 6 | .irq: db (_irq) ; old PC-AT IRQ 7 | .gsi: dd (_gsi) 8 | .trigger: db (_trigger) 9 | .polarity: db (_polarity) 10 | .vector: db (_vector) 11 | ends 12 | 13 | _DEFAULT_ISA_TRIGGER = _EDGE_TRIGGER 14 | _DEFAULT_ISA_POLARITY = (not (_LOW_POLARITY or _HIGH_POLARITY)) 15 | _interrupt_mapping_table: 16 | _pit _interrupt_mapping 0H, 0H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _pit_irq.vector 17 | _keyboard _interrupt_mapping 1H, 1H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _keyboard_irq.vector 18 | _com2 _interrupt_mapping 3H, 3H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _com2_irq.vector 19 | _com1 _interrupt_mapping 4H, 4H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _com1_irq.vector 20 | _lpt2 _interrupt_mapping 5H, 5H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _lpt2_irq.vector 21 | _floppy _interrupt_mapping 6H, 6H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _floppy_irq.vector 22 | _lpt1 _interrupt_mapping 7H, 7H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _lpt1_irq.vector 23 | _rtc _interrupt_mapping 8H, 8H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _rtc_irq.vector 24 | _vga_retrace _interrupt_mapping 9H, 9H, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _vga_retrace_irq.vector 25 | _mouse _interrupt_mapping 00CH, 00CH, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _mouse_irq.vector 26 | _fpu _interrupt_mapping 00DH, 00DH, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _fpu_irq.vector 27 | _hdd _interrupt_mapping 00EH, 00EH, _DEFAULT_ISA_TRIGGER, _DEFAULT_ISA_POLARITY, _hdd_irq.vector 28 | _interrupt_mapping_table_end: 29 | 30 | _soft_enable_apic: 31 | or dword [_PAE_LOCAL_APIC+_SPURIOUS_INTERRUPT_VECTOR_REGISTER], _SPURIOUS_APIC_ENABLE 32 | ret 33 | 34 | _soft_disable_apic: 35 | and dword [_PAE_LOCAL_APIC+_SPURIOUS_INTERRUPT_VECTOR_REGISTER], (not _SPURIOUS_APIC_ENABLE) 36 | ret 37 | 38 | _hard_disable_apic: 39 | ret 40 | 41 | _acpi_find_sdt_table: 42 | ; in: 43 | ; ebx - RSDT table 44 | ; edx - SDT signature 45 | ; out: 46 | ; ebx - target SDT table 47 | ; cf - set if table not found 48 | ; preserves: esi, edi, ebp 49 | push esi edi 50 | cmp dword [ebx+_acpi_sdt_header.signature], _RSDT 51 | jnz _acpi_find_sdt_table_exit 52 | mov edi, ebx 53 | call _acpi_sdt_checksum 54 | jc _acpi_find_sdt_table_exit+1H 55 | mov ecx, dword [ebx+_acpi_sdt_header.length] 56 | sub ecx, _acpi_sdt_header.sizeof 57 | shr ecx, 2H 58 | jecxz _acpi_find_sdt_table_exit 59 | lea esi, [ebx+_acpi_sdt_header.sizeof] 60 | _acpi_find_sdt_table_loop: 61 | lodsd 62 | cmp dword [eax+_acpi_sdt_header.signature], edx 63 | jnz _acpi_find_sdt_table_update 64 | mov edi, eax 65 | mov ebx, ecx 66 | call _acpi_sdt_checksum 67 | xchg edi, ebx 68 | jnc _acpi_find_sdt_table_exit+1H 69 | mov ecx, edi 70 | _acpi_find_sdt_table_update: 71 | loop _acpi_find_sdt_table_loop 72 | _acpi_find_sdt_table_exit: 73 | stc 74 | pop edi esi 75 | ret 76 | 77 | enum _LOCAL_APIC_ACCESS_READ, _LOCAL_APIC_ACCESS_WRITE 78 | _local_apic_access_register: 79 | ; in: 80 | ; ebx - access kind 81 | ; ecx - kind of register to write 82 | ; edx:eax - data to be written (edx is written iff x2APIC is enabled and ICR register is trageted) 83 | ; out: 84 | ; eax = read register (if ebx = _LOCAL_APIC_ACCESS_READ else unmodified) 85 | ; ecx = value such that this function can be called twice to access to the same register 86 | ; cf - set if error 87 | ; preserves: ebx, esi, edi, ebp 88 | cmp ebx, (_LOCAL_APIC_ACCESS_WRITE + 1H) 89 | cmc 90 | jc _local_apic_access_register_exit 91 | test byte [_singleton.apic], 1H 92 | stc 93 | jz _local_apic_access_register_exit 94 | test byte [_singleton.x2apic], 1H 95 | jnz _local_apic_access_register_x2apic 96 | cmp ecx, _SELF_IPI_MSR 97 | jz _local_apic_access_register_exit 98 | cmp bl, _LOCAL_APIC_ACCESS_READ 99 | jz _local_apic_access_register_read 100 | mov dword [_LOCAL_APIC+ecx], eax 101 | jmp _local_apic_access_register_exit 102 | _local_apic_access_register_read: 103 | mov eax, dword [_LOCAL_APIC+ecx] 104 | jmp _local_apic_access_register_exit 105 | _local_apic_access_register_x2apic: 106 | mov word [_local_apic_access_register_execute], _RDMSR 107 | cmp bl, _LOCAL_APIC_ACCESS_WRITE 108 | jnz _local_apic_access_register_sanitize 109 | mov word [_local_apic_access_register_execute], _WRMSR 110 | _local_apic_access_register_sanitize: 111 | cmp ecx, _DESTINATION_FORMAT_REGISTER 112 | jz _local_apic_access_register_exit ; silently ignored 113 | cmp ecx, _SELF_IPI_MSR 114 | jz _local_apic_access_register_write 115 | cmp ecx, _INTERRUPT_COMMAND_REGISTER_HIGH 116 | jnz _local_apic_access_register_shift 117 | mov ecx, _INTERRUPT_COMMAND_REGISTER_MSR 118 | jmp _local_apic_access_register_write+2H 119 | _local_apic_access_register_shift: 120 | shr ecx, _X2APIC_MSR_SHIFT 121 | _local_apic_access_register_write: 122 | xor edx, edx 123 | add ecx, _LOCAL_APIC_BASE_MSR 124 | _local_apic_access_register_execute: 125 | dw 0H 126 | sub ecx, _LOCAL_APIC_BASE_MSR 127 | cmp ecx, _SELF_IPI_MSR 128 | jz _local_apic_access_register_exit 129 | shl ecx, _X2APIC_MSR_SHIFT 130 | _local_apic_access_register_exit: 131 | ret 132 | 133 | _io_apic_irq_count: 134 | ; out: 135 | ; eax - number of IRQ attached to the target IO APIC 136 | ; cf - set if there are no io apic in the system 137 | ; note: [_PAE_IO_APIC] - point to valid io apic registers set 138 | ; preserves: ebx, ecx, edx, esi, edi, ebp 139 | cmp byte [_io_apic_count], 0H 140 | stc 141 | jz _io_apic_irq_count_exit 142 | mov byte [_PAE_IO_APIC+_INDEX_REGISTER], _IO_APIC_VERSION_REGISTER 143 | mov eax, dword [_PAE_IO_APIC+_DATA_REGISTER] 144 | and eax, _IO_APIC_VERSION_IRQ_RT_MASK 145 | shr eax, _IO_APIC_VERSION_IRQ_RT_SHIFT 146 | inc eax 147 | _io_apic_irq_count_exit: 148 | ret 149 | 150 | _io_apic_reset_rt: 151 | ; out: cf - set if there are no io apic in the system 152 | ; preserves: ecx 153 | push ecx 154 | call _io_apic_irq_count 155 | jc _io_apic_reset_rt_exit 156 | xor ecx, ecx 157 | _io_apic_reset_rt_loop: 158 | cmp ecx, eax 159 | jae _io_apic_reset_rt_exit 160 | lea edx, [_REDIRECTION_TABLE_BASE+ecx*2H] 161 | _io_apic_reset_rt_reset: 162 | mov byte [_PAE_IO_APIC+_INDEX_REGISTER], dl 163 | mov dword [_PAE_IO_APIC+_DATA_REGISTER], _APIC_MASK 164 | inc dl 165 | cmp dl, 2H 166 | jb _io_apic_reset_rt_reset 167 | inc ecx 168 | jmp _io_apic_reset_rt_loop 169 | _io_apic_reset_rt_exit: 170 | pop ecx 171 | ret 172 | 173 | _io_apic_irq_connect: 174 | ; in: 175 | ; ebx - madt table (point to the current io apic entry) 176 | ; ecx - remain madt size 177 | ; out: cf - set if there are no io apic in the system 178 | ; preserves: ebx, ecx, ebp 179 | push ebx ecx ebp 180 | call _io_apic_irq_count 181 | jc _io_apic_irq_connect_exit 182 | mov ebp, dword [ebx+_madt_io_apic.gsi_base] 183 | add eax, ebp 184 | _io_apic_irq_connect_loop: 185 | mov dl, byte [ebx+_madt_prefix.type] 186 | cmp dl, _MADT_INTERRUPT_OVERRIDE 187 | jz _io_apic_irq_connect_interrupt 188 | cmp dl, _MADT_NMI 189 | jnz _io_apic_irq_connect_update 190 | jmp _io_apic_irq_connect_mapping 191 | _io_apic_irq_connect_interrupt: 192 | mov dl, byte [ebx+_madt_interrupt_override.irq] 193 | mov edi, _interrupt_mapping_table 194 | _io_apic_irq_connect_mapping: 195 | cmp dl, byte [edi+_interrupt_mapping.irq] 196 | jnz _io_apic_irq_connect_advance 197 | movzx edx, word [ebx+_madt_interrupt_override.flags] 198 | mov esi, edx 199 | and edx, _INTERRUPT_EL_MASK 200 | shr edx, _INTERRUPT_EL_SHIFT 201 | cmp dl, _INTERRUPT_EL_LEVEL 202 | mov edx, esi 203 | jnz _io_apic_irq_connect_copy 204 | mov byte [edi+_interrupt_mapping.trigger], _LEVEL_TRIGGER 205 | mov byte [edi+_interrupt_mapping.polarity], _LOW_POLARITY 206 | and edx, _INTERRUPT_PO_MASK 207 | shr edx, _INTERRUPT_PO_SHIFT 208 | cmp dl, _INTERRUPT_PO_HIGH 209 | jnz _io_apic_irq_connect_copy 210 | mov byte [edi+_interrupt_mapping.polarity], _HIGH_POLARITY 211 | _io_apic_irq_connect_copy: 212 | lea esi, [ebx+_madt_interrupt_override.gsi] 213 | add edi, _interrupt_mapping.gsi 214 | movsd 215 | jmp _io_apic_irq_connect_update 216 | _io_apic_irq_connect_advance: 217 | cmp edi, _interrupt_mapping_table_end 218 | jae _io_apic_irq_connect_update 219 | add edi, _interrupt_mapping.sizeof 220 | jmp _io_apic_irq_connect_mapping 221 | _io_apic_irq_connect_update: 222 | movzx edx, byte [ebx+_madt_prefix.length] 223 | add ebx, edx 224 | sub ecx, edx 225 | jnz _io_apic_irq_connect_loop 226 | mov edi, _interrupt_mapping_table 227 | _io_apic_irq_connect_redirection: 228 | mov edx, dword [edi+_interrupt_mapping.gsi] 229 | cmp edx, eax 230 | jae _io_apic_irq_connect_iterate 231 | sub edx, ebp 232 | jc _io_apic_irq_connect_iterate 233 | lea edx, [_REDIRECTION_TABLE_BASE+edx*2H+1H] 234 | mov byte [_IO_APIC+_INDEX_REGISTER], dl 235 | mov dword [_IO_APIC+_DATA_REGISTER], (_XAPIC_MESSAGE_BROADCAST shl (_XAPIC_DESTINATION_SHIFT - 020H)) 236 | dec dl 237 | mov byte [_IO_APIC+_INDEX_REGISTER], dl 238 | mov dl, byte [edi+_interrupt_mapping.vector] 239 | or edx, _APIC_DELIVERY_FIXED 240 | cmp byte [edi+_interrupt_mapping.trigger], _EDGE_TRIGGER 241 | jz _io_apic_irq_connect_activate 242 | or edx, _APIC_LEVEL_TRIGGER 243 | cmp byte [edi+_interrupt_mapping.polarity], _HIGH_POLARITY 244 | jz _io_apic_irq_connect_activate 245 | or edx, _APIC_POLARITY_LOW 246 | _io_apic_irq_connect_activate: 247 | mov dword [_IO_APIC+_DATA_REGISTER], edx 248 | _io_apic_irq_connect_iterate: 249 | cmp edi, _interrupt_mapping_table_end 250 | jae _io_apic_irq_connect_exit 251 | add edi, _interrupt_mapping.sizeof 252 | jmp _io_apic_irq_connect_redirection 253 | _io_apic_irq_connect_exit: 254 | pop ebp ecx ebx 255 | ret 256 | 257 | ;_acpi_parse_madt: 258 | ; ret 259 | 260 | -------------------------------------------------------------------------------- /bitmap.inc: -------------------------------------------------------------------------------- 1 | 2 | _BITMAP_UNIT = 4H 3 | assert ((bsf _BITMAP_UNIT) = (bsr _BITMAP_UNIT)) 4 | struct _bitmap _size* 5 | .next: dd (.table) 6 | .last: dd ((.table + (_size)) - _BITMAP_UNIT) 7 | .free: dd ((_size) shl 3H) 8 | .table: db (_size) dup (not 0H) 9 | ends 10 | 11 | _bitmap_search: 12 | ; in: 13 | ; eax - bitmap pointer 14 | ; ebx - start of bitmap dword index where to count, 0H if _bitmap.next is desired 15 | ; ecx - count of consecutive 1B to search 16 | ; edx - end of bitmap dword index where to count, 0H if _bitmap.last is desired 17 | ; esi - (>0H) when aligned to the lsb of ecx (useless if ecx = 1H) 18 | ; out: 19 | ; ebx - cf not set, bitmap dword index where the sequence of 1B reside 20 | ; edx - cf not set, index in the byte where the first 1B occurs 21 | ; cf - set if not found 22 | ; preserves: eax, ecx, edi, esi, ebp 23 | push esi edi ebp ecx 24 | test ecx, ecx 25 | jz _bitmap_search_carry 26 | test esi, esi 27 | mov esi, 1H 28 | jz _bitmap_search_position 29 | bsf esi, ecx 30 | xchg esi, ecx 31 | xor edi, edi 32 | inc edi 33 | shl edi, cl 34 | mov ecx, esi 35 | mov esi, edi 36 | _bitmap_search_position: 37 | call _bitmap_search_sanitize 38 | jc _bitmap_search_carry+1H 39 | cmp ebx, dword [eax+_bitmap.next] 40 | ja _bitmap_search_specialized 41 | cmp edx, dword [eax+_bitmap.last] 42 | jnz _bitmap_search_specialized 43 | cmp ecx, dword [eax+_bitmap.free] 44 | ja _bitmap_search_carry 45 | jmp _bitmap_search_next 46 | _bitmap_search_specialized: 47 | push ebx edx 48 | call _bitmap_bit_count 49 | pop edx ebx 50 | cmp ecx, dword [esp] 51 | jb _bitmap_search_carry+1H 52 | _bitmap_search_next: 53 | xor edx, edx 54 | mov ecx, edx 55 | jmp _bitmap_search_scan 56 | _bitmap_search_loop: 57 | lea edi, [esi-1H] 58 | and ecx, edi 59 | sub edi, ecx 60 | jz _bitmap_search_reset 61 | mov ecx, edi 62 | call _bitmap_search_proceed 63 | jc _bitmap_search_carry+1H 64 | loop $-7H 65 | _bitmap_search_reset: 66 | xor ecx, ecx 67 | _bitmap_search_advance: 68 | call _bitmap_search_proceed 69 | jc _bitmap_search_carry+1H 70 | _bitmap_search_scan: 71 | bt dword [ebx], edx 72 | jnc _bitmap_search_loop 73 | test ecx, ecx 74 | jnz _bitmap_search_counter 75 | mov edi, edx 76 | _bitmap_search_counter: 77 | inc ecx 78 | cmp ecx, dword [esp] 79 | jb _bitmap_search_advance 80 | lea ecx, [ecx+edi-1H] 81 | shr ecx, 3H 82 | and cl, (not (_BITMAP_UNIT - 1H)) 83 | sub ebx, ecx 84 | mov edx, edi 85 | clc 86 | jmp _bitmap_search_carry+1H 87 | _bitmap_search_carry: 88 | stc 89 | pop ecx ebp edi esi 90 | ret 91 | _bitmap_search_proceed: 92 | inc edx 93 | cmp edx, (_BITMAP_UNIT shl 3H) 94 | jb _bitmap_search_sanitize_exit 95 | xor edx, edx 96 | _bitmap_search_proceed_advance: 97 | add ebx, _BITMAP_UNIT 98 | _bitmap_search_proceed_overflow: 99 | cmp ebx, ebp 100 | cmova ebx, ebp 101 | ja _bitmap_search_sanitize_exit 102 | jmp _bitmap_search_sanitize_exit-1H 103 | _bitmap_search_sanitize: 104 | lea ebp, [eax+_bitmap.table] 105 | test ebx, ebx 106 | jnz _bitmap_search_sanitize_first 107 | mov ebx, dword [eax+_bitmap.next] 108 | _bitmap_search_sanitize_first: 109 | cmp ebx, ebp 110 | jb _bitmap_search_sanitize_exit+1H 111 | test edx, edx 112 | jnz _bitmap_search_sanitize_second 113 | mov edx, dword [eax+_bitmap.last] 114 | jmp _bitmap_search_sanitize_ensure 115 | _bitmap_search_sanitize_second: 116 | cmp edx, dword [eax+_bitmap.last] 117 | ja _bitmap_search_sanitize_exit 118 | _bitmap_search_sanitize_ensure: 119 | cmp ebx, edx 120 | ja _bitmap_search_sanitize_exit 121 | mov ebp, edx 122 | stc 123 | _bitmap_search_sanitize_exit: 124 | cmc 125 | ret 126 | 127 | enum _BITMAP_RESET, _BITMAP_SET 128 | _bitmap_update: 129 | ; in: 130 | ; eax - bitmap pointer 131 | ; ebx - bitmap dword index where the sequence of 1B reside 132 | ; ecx - count of consecutive bit to update 133 | ; edx - index in the byte where the first 1B occurs 134 | ; edi - action to take 135 | ; out: 136 | ; edx - the total number of bit changed when cf = 0H 137 | ; cf - invalid action parameter or ebx overflow directly 138 | ; preserves: eax, ebx, ecx, edi, esi, ebp 139 | push ebx ecx esi ebp 0H 140 | jecxz _bitmap_update_exit 141 | mov ebp, dword [eax+_bitmap.last] 142 | call _bitmap_update_validity 143 | jc _bitmap_update_carry+1H 144 | cmp edi, _BITMAP_SET 145 | ja _bitmap_update_carry 146 | jnz _bitmap_update_sanitize 147 | cmp ebx, dword [eax+_bitmap.next] 148 | jae _bitmap_update_sanitize 149 | mov dword [eax+_bitmap.next], ebx 150 | _bitmap_update_sanitize: 151 | push eax 152 | xor eax, eax 153 | clc 154 | _bitmap_update_loop: 155 | jc _bitmap_udpate_next 156 | mov esi, _bitmap_update_bit_switch 157 | cmp ecx, (_BITMAP_UNIT shl 3H) 158 | jb _bitmap_update_call 159 | mov esi, _bitmap_update_switch 160 | sub ecx, ((_BITMAP_UNIT shl 3H) - 1H) 161 | add edx, (_BITMAP_UNIT shl 3H) 162 | _bitmap_update_call: 163 | call dword [esi+edi*4H] 164 | add eax, dword [esp+4H] 165 | xor esi, esi 166 | mov dword [esp+4H], esi ; reset the counter 167 | jc _bitmap_udpate_restore 168 | call _bitmap_search_proceed 169 | loop _bitmap_update_loop 170 | _bitmap_udpate_next: 171 | mov edx, eax 172 | mov esi, eax 173 | clc 174 | _bitmap_udpate_restore: 175 | pop eax 176 | jc _bitmap_update_carry+1H 177 | cmp edi, _BITMAP_RESET 178 | jnz _bitmap_update_exit 179 | mov ecx, ebx 180 | neg esi 181 | _bitmap_update_remove: 182 | cmp ecx, dword [eax+_bitmap.next] 183 | jbe _bitmap_update_padding 184 | cmp dword [ecx], 0H 185 | jnz _bitmap_update_exit 186 | sub ecx, _BITMAP_UNIT 187 | jmp _bitmap_update_remove 188 | _bitmap_update_padding: 189 | mov dword [eax+_bitmap.next], ebx 190 | _bitmap_update_exit: 191 | add dword [eax+_bitmap.free], esi 192 | clc 193 | jmp _bitmap_update_carry+1H 194 | _bitmap_update_carry: 195 | stc 196 | pop ecx ebp esi ecx ebx 197 | ret 198 | _bitmap_update_bit_switch: 199 | dd _bitmap_update_bit_reset 200 | dd _bitmap_update_bit_set 201 | _bitmap_update_switch: 202 | dd _bitmap_update_reset 203 | dd _bitmap_update_set 204 | _bitmap_update_bit_reset: 205 | btr dword [ebx], edx 206 | jmp _bitmap_update_bit_return 207 | _bitmap_update_bit_set: 208 | bts dword [ebx], edx 209 | cmc 210 | _bitmap_update_bit_return: 211 | setc byte [esp+8H] 212 | ret 213 | _bitmap_update_reset: 214 | call _bitmap_update_count_bit 215 | mov dword [ebx], 0H 216 | ret 217 | _bitmap_update_set: 218 | call _bitmap_update_count_bit 219 | mov dword [ebx], not 0H 220 | sub byte [esp+8H], (_BITMAP_UNIT shl 3H) 221 | neg byte [esp+8H] 222 | ret 223 | _bitmap_update_validity: 224 | call _bitmap_search_proceed_overflow 225 | jc _bitmap_update_validity_exit 226 | cmp edx, (_BITMAP_UNIT shl 3H) 227 | cmc 228 | _bitmap_update_validity_exit: 229 | ret 230 | _bitmap_update_count_bit: 231 | test byte [_singleton.popcnt], 1H 232 | jz _bitmap_update_count_bit_next 233 | popcnt esi, dword [ebx] 234 | mov dword [esp+8H], esi 235 | ret 236 | _bitmap_update_count_bit_next: 237 | xor esi, esi 238 | xchg esi, ebx 239 | rept 4H i:0H 240 | { 241 | mov bl, byte [esi+i] 242 | mov bl, byte [_bitmap_bit_count_table+ebx] 243 | add byte [esp+00CH], bl 244 | } 245 | mov ebx, esi 246 | _bitmap_update_count_bit_exit: 247 | ret 248 | 249 | _bitmap_match: 250 | ; in: 251 | ; eax - bitmap pointer 252 | ; ebx - bitmap dword index where the sequence of 1B reside 253 | ; ecx - count of consecutive bit to test 254 | ; edx - index in the byte where the first 1B occurs 255 | ; edi - kind of pattern to match 256 | ; out: 257 | ; cf - set when match occurs 258 | ; preserves: eax, ebx, ecx, edx, esi, edi, ebp 259 | pushad 260 | mov ebp, dword [eax+_bitmap.last] 261 | call _bitmap_update_validity 262 | jc _bitmap_match_exit 263 | shl edi, 2H 264 | cmp edi, (_BITMAP_SET shl 2H) 265 | ja _bitmap_match_exit 266 | _bitmap_match_loop: 267 | mov esi, _bitmap_match_bit_switch 268 | cmp ecx, (_BITMAP_UNIT shl 3H) 269 | jb _bitmap_match_call 270 | sub ecx, ((_BITMAP_UNIT shl 3H) - 1H) 271 | add edx, (_BITMAP_UNIT shl 3H) 272 | mov esi, _bitmap_match_switch 273 | _bitmap_match_call: 274 | call dword [esi+edi] 275 | jnz _bitmap_match_exit 276 | call _bitmap_search_proceed 277 | jc _bitmap_match_exit 278 | loop _bitmap_match_loop 279 | stc 280 | jmp _bitmap_match_exit+1H 281 | _bitmap_match_exit: 282 | clc 283 | popad 284 | ret 285 | _bitmap_match_bit_switch: 286 | dd _bitmap_match_bit_reset 287 | dd _bitmap_match_bit_set 288 | _bitmap_match_switch: 289 | dd _bitmap_match_reset 290 | dd _bitmap_match_set 291 | _bitmap_match_bit_set: 292 | bt dword [ebx], edx 293 | cmc 294 | jmp _bitmap_match_bit_reset+3H 295 | _bitmap_match_bit_reset: 296 | bt dword [ebx], edx 297 | sbb esi, esi ; ZF = not CF 298 | ret 299 | _bitmap_match_reset: 300 | cmp dword [ebx], 0H 301 | ret 302 | _bitmap_match_set: 303 | cmp dword [ebx], not 0H 304 | ret 305 | 306 | _bitmap_set_to_reset: 307 | mov edi, _BITMAP_SET 308 | jmp _bitmap_inverse 309 | _bitmap_reset_to_set: 310 | mov edi, _BITMAP_RESET 311 | _bitmap_inverse: 312 | ; in: 313 | ; eax - bitmap pointer 314 | ; ebx - bitmap dword index where the sequence of 1B reside 315 | ; ecx - count of consecutive bit to test 316 | ; edx - index in the byte where the first 1B occurs 317 | ; edi - kind of pattern to match in _bitmap_match 318 | ; out: cf - set when the target bitmap substring is not the inverse of the wanted result 319 | ; preserves: eax, ebx, ecx, esi, ebp 320 | ; note: call _bitmap_match first and if a match result then call _bitmap_update with the inverse of edi 321 | call _bitmap_match 322 | jnc _bitmap_inverse_exit 323 | not edi 324 | and edi, 1H 325 | call _bitmap_update 326 | jc _bitmap_inverse_exit+1H 327 | cmp ecx, edx 328 | clc 329 | jz _bitmap_inverse_exit+1H 330 | _bitmap_inverse_exit: 331 | cmc 332 | ret 333 | 334 | _bitmap_bit_count: 335 | ; in: 336 | ; eax - bitmap pointer 337 | ; ebx - start of bitmap dword index where to count, 0H if _bitmap.next is desired 338 | ; edx - end of bitmap dword index where to count, 0H if _bitmap.last is desired 339 | ; out: 340 | ; ecx - the number of bit set in the bitmap. 341 | ; cf - carry set when argument ill-formed or the bitmap was too huge 342 | ; preserves: eax, edi, esi, ebp 343 | push edi ebp 344 | call _bitmap_search_sanitize 345 | jc _bitmap_bit_count_carry+1H 346 | test byte [_singleton.popcnt], 1H 347 | setnz al 348 | movzx edi, al 349 | mov edi, dword [_bitmap_bit_count_switch+edi*4H] 350 | xor ecx, ecx 351 | _bitmap_bit_count_loop: 352 | test dword [ebx], 0H 353 | jz _bitmap_bit_count_next 354 | call edi 355 | add ecx, edx 356 | jc _bitmap_bit_count_carry+1H 357 | _bitmap_bit_count_next: 358 | call _bitmap_search_proceed_advance 359 | jnc _bitmap_bit_count_loop 360 | _bitmap_bit_count_exit: 361 | clc 362 | jmp _bitmap_bit_count_exit+1H 363 | _bitmap_bit_count_carry: 364 | stc 365 | pop ebp edi 366 | ret 367 | _bitmap_bit_count_switch: 368 | dd _bitmap_bit_count_simple 369 | dd _bitmap_bit_count_feature 370 | _bitmap_bit_count_simple: 371 | xor eax, eax 372 | xor edx, edx 373 | rept 4H i:0H 374 | { 375 | mov al, byte [ebx+i] 376 | add dl, byte [_bitmap_bit_count_table+eax] 377 | } 378 | ret 379 | _bitmap_bit_count_feature: 380 | popcnt edx, dword [ebx] 381 | ret 382 | _bitmap_bit_count_table: 383 | db 0H, 1H, 1H, 2H, 1H, 2H, 2H, 3H, 1H, 2H, 2H, 3H, 2H, 3H, 3H, 4H 384 | db 1H, 2H, 2H, 3H, 2H, 3H, 3H, 4H, 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H 385 | db 1H, 2H, 2H, 3H, 2H, 3H, 3H, 4H, 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H 386 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 387 | db 1H, 2H, 2H, 3H, 2H, 3H, 3H, 4H, 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H 388 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 389 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 390 | db 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H, 4H, 5H, 5H, 6H, 5H, 6H, 6H, 7H 391 | db 1H, 2H, 2H, 3H, 2H, 3H, 3H, 4H, 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H 392 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 393 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 394 | db 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H, 4H, 5H, 5H, 6H, 5H, 6H, 6H, 7H 395 | db 2H, 3H, 3H, 4H, 3H, 4H, 4H, 5H, 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H 396 | db 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H, 4H, 5H, 5H, 6H, 5H, 6H, 6H, 7H 397 | db 3H, 4H, 4H, 5H, 4H, 5H, 5H, 6H, 4H, 5H, 5H, 6H, 5H, 6H, 6H, 7H 398 | db 4H, 5H, 5H, 6H, 5H, 6H, 6H, 7H, 5H, 6H, 6H, 7H, 6H, 7H, 7H, 8H 399 | 400 | _bitmap_init: 401 | ; in: 402 | ; eax - bitmap pointer object 403 | ; ebx - expansion kind 404 | ; ecx - bitmap size 405 | ; out: same as _bitmap_resize 406 | ; preserves: eax, esi, ebp 407 | mov edi, ebx 408 | lea ebx, [eax+_bitmap.table] 409 | lea edx, [ebx-_BITMAP_UNIT] 410 | mov dword [eax+_bitmap.next], ebx 411 | mov dword [eax+_bitmap.last], edx 412 | ; fallthrough ; 413 | 414 | enum _BITMAP_EXPAND_ZERO, _BITMAP_EXPAND_ONE 415 | _bitmap_resize: 416 | ; in: 417 | ; eax - bitmap pointer 418 | ; ecx - new desired size 419 | ; edi - desired action on expansion 420 | ; out: 421 | ; edi - pointer to the byte just after the table expanded 422 | ; cf - set when ebx is not aligned on the _BITMAP_UNIT or edi ill formed 423 | ; preserves: eax, esi, ebp 424 | test ecx, (_BITMAP_UNIT - 1H) 425 | jnz _bitmap_resize_exit 426 | cmp edi, (_BITMAP_EXPAND_ONE + 1H) 427 | jae _bitmap_resize_exit 428 | mov edx, dword [eax+_bitmap.last] 429 | add edx, _BITMAP_UNIT 430 | mov ebx, edx 431 | sub edx, dword [eax+_bitmap.next] 432 | cmp ecx, edx 433 | jz _bitmap_resize_exit-1H 434 | sub ecx, edx 435 | jns _bitmap_resize_expand 436 | add dword [eax+_bitmap.last], ecx 437 | xor ebx, ebx 438 | mov edx, ebx 439 | call _bitmap_bit_count 440 | mov dword [eax+_bitmap.free], ecx 441 | mov edi, dword [eax+_bitmap.last] 442 | add edi, _BITMAP_UNIT 443 | jmp _bitmap_resize_exit-1H 444 | _bitmap_resize_expand: 445 | mov edx, eax 446 | xor eax, eax 447 | cmp edi, _BITMAP_EXPAND_ZERO 448 | mov edi, ebx 449 | mov ebx, 0H 450 | jz _bitmap_resize_perform 451 | lea ebx, [ecx*8H] 452 | dec eax 453 | _bitmap_resize_perform: 454 | shr ecx, 2H 455 | rep stosd 456 | mov eax, edx 457 | lea edx, [edi-_BITMAP_UNIT] 458 | mov dword [eax+_bitmap.last], edx 459 | add dword [eax+_bitmap.free], ebx 460 | stc 461 | _bitmap_resize_exit: 462 | cmc 463 | ret 464 | -------------------------------------------------------------------------------- /bomb.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _bomb:: 4 | _bomb_start: 5 | xor eax, eax 6 | mov al, _SYSCALL_FORK 7 | int 030H 8 | test eax, eax 9 | jns _bomb_start 10 | xor eax, eax 11 | mov al, _SYSCALL_EXIT 12 | xor ebx, ebx 13 | int 030H 14 | _bomb.sizeof = ($ - $$) 15 | end virtual 16 | -------------------------------------------------------------------------------- /clear.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _clear:: 4 | rept 0E00H {nop} 5 | xor eax, eax 6 | mov al, _SYSCALL_ARGCPY 7 | int 030H 8 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 9 | jz _clear_start 10 | xor eax, eax 11 | mov al, _SYSCALL_WRITE 12 | mov ebx, _TELETYPE_CURRENT 13 | mov ecx, _clear_invalid 14 | mov edx, _clear_invalid.sizeof 15 | mov ebx, (not 0H) 16 | jmp _clear_exit 17 | _clear_start: 18 | xor eax, eax 19 | mov al, _SYSCALL_WRITE 20 | mov ebx, _TELETYPE_CURRENT 21 | mov ecx, _clear_clear 22 | mov edx, _clear_clear.sizeof 23 | int 030H 24 | ; XXX Termios 25 | xor ebx, ebx 26 | _clear_exit: 27 | xor eax, eax 28 | mov al, _SYSCALL_EXIT 29 | int 030H 30 | _clear_invalid string "clear invalid usage", 00AH 31 | _clear_clear string _ESCAPE, _ESCAPE_CLEAR 32 | _clear.sizeof = ($ - $$) 33 | end virtual 34 | -------------------------------------------------------------------------------- /client.inc: -------------------------------------------------------------------------------- 1 | 2 | _CLIENT_BUFFER = 040H 3 | 4 | virtual at _USER_CODE_VIRTUAL 5 | _client:: 6 | rept 0500H { nop } 7 | xor eax, eax 8 | mov al, _SYSCALL_ARGCPY 9 | int 030H 10 | mov ebp, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 11 | xor eax, eax 12 | mov al, _SYSCALL_SPGRP 13 | int 030H 14 | test eax, eax 15 | js _client_exit 16 | mov al, _SYSCALL_GPID 17 | int 030H 18 | push eax 19 | xor eax, eax 20 | mov al, _SYSCALL_IOCTL 21 | mov ebx, _TELETYPE_CURRENT 22 | mov ecx, TIOCSPGRP 23 | mov edx, esp 24 | int 030H 25 | lea edi, [esp+4H-_CLIENT_BUFFER] 26 | _client_loop: 27 | xor eax, eax 28 | mov al, _SYSCALL_ALIVE 29 | mov ebx, ebp 30 | xor ecx, ecx 31 | mov cl, _SERVER_PORT 32 | int 030H 33 | test eax, eax 34 | js _client_exit 35 | xor eax, eax 36 | mov al, _SYSCALL_WRITE 37 | mov ebx, _TELETYPE_CURRENT 38 | mov ecx, _client_prompt 39 | mov edx, _client_prompt.sizeof 40 | int 030H 41 | xor eax, eax 42 | mov al, _SYSCALL_READ 43 | mov ebx, _TELETYPE_CURRENT 44 | mov ecx, edi 45 | xor edx, edx 46 | mov dl, _CLIENT_BUFFER 47 | int 030H 48 | test eax, eax 49 | jz _client_loop 50 | mov esi, eax 51 | cmp byte [edi+eax-1H], 00AH 52 | jnz $+3H 53 | dec esi 54 | mov edx, edi 55 | xor eax, eax 56 | mov al, _SYSCALL_SEND 57 | mov ebx, ebp 58 | xor ecx, ecx 59 | mov cl, _SERVER_PORT 60 | int 030H 61 | jmp _client_loop 62 | _client_exit: 63 | xor eax, eax 64 | mov al, _SYSCALL_EXIT 65 | xor ebx, ebx 66 | int 030H 67 | 68 | _client_send string "HELLO" 69 | _client_prompt string "$> " 70 | _client_sending string "You are about to send the string " 71 | _client.sizeof = ($ - $$) 72 | end virtual 73 | -------------------------------------------------------------------------------- /color.inc: -------------------------------------------------------------------------------- 1 | 2 | struct _color_field _string*, _length*, _escape*, _categorie*, _payload* 3 | .string: dd (_string) 4 | .length: dd (_length) 5 | .escape: db (_escape) 6 | .categorie: db (_categorie) 7 | .payload: dw (_payload) 8 | ends 9 | 10 | irp _kind*, fg,bg 11 | { 12 | _user_code _#_kind 13 | xor eax, eax 14 | mov al, _SYSCALL_ARGCPY 15 | int 030H 16 | mov edx, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 17 | test edx, edx 18 | jnz _#_kind#_start 19 | _#_kind#_error: 20 | xor eax, eax 21 | mov al, _SYSCALL_WRITE 22 | mov ebx, _TELETYPE_CURRENT 23 | mov ecx, _#_kind#_invalid 24 | mov edx, _#_kind#_invalid.sizeof 25 | int 030H 26 | mov ebx, (not 0H) 27 | jmp _#_kind#_exit 28 | _#_kind#_start: 29 | mov ebp, ((_#_kind#_color_table_end - _#_kind#_color_table) / _color_field.sizeof) 30 | mov ebx, _#_kind#_color_table 31 | _#_kind#_loop: 32 | mov edi, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 33 | mov esi, dword [ebx+_color_field.string] 34 | mov ecx, dword [ebx+_color_field.length] 35 | jecxz _#_kind#_loop_update 36 | cmp ecx, edx 37 | ja _#_kind#_loop_update 38 | rep cmpsb 39 | jz _#_kind#_loop_continue 40 | _#_kind#_loop_update: 41 | add ebx, _color_field.sizeof 42 | dec ebp 43 | jnz _#_kind#_loop 44 | jmp _#_kind#_error 45 | _#_kind#_loop_continue: 46 | sub edx, dword [ebx+_color_field.length] 47 | jz _#_kind#_loop_display 48 | mov ecx, edx 49 | mov al, 020H 50 | repz scasb 51 | jnz _#_kind#_error 52 | _#_kind#_loop_display: 53 | xor eax, eax 54 | mov al, _SYSCALL_WRITE 55 | lea ecx, [ebx+_color_field.escape] 56 | xor edx, edx 57 | mov dl, 4H 58 | mov ebx, _TELETYPE_CURRENT 59 | int 030H 60 | xor ebx, ebx 61 | _#_kind#_exit: 62 | xor eax, eax 63 | mov al, _SYSCALL_EXIT 64 | int 030H 65 | 66 | _#_kind#_color_string_0 string "black" 67 | _#_kind#_color_string_1 string "blue" 68 | _#_kind#_color_string_2 string "green" 69 | _#_kind#_color_string_3 string "cyan" 70 | _#_kind#_color_string_4 string "red" 71 | _#_kind#_color_string_5 string "magenta" 72 | _#_kind#_color_string_6 string "brown" 73 | _#_kind#_color_string_7 string "light" 74 | 75 | match =fg, _kind \{ define _categorie _ESCAPE_CHANGE_FOREGROUND \} 76 | match =bg, _kind \{ define _categorie _ESCAPE_CHANGE_BACKGROUND \} 77 | 78 | _#_kind#_color_table: 79 | _#_kind#_color_0 _color_field _#_kind#_color_string_0, _#_kind#_color_string_0.sizeof, _ESCAPE, _categorie, "00" 80 | _#_kind#_color_1 _color_field _#_kind#_color_string_1, _#_kind#_color_string_1.sizeof, _ESCAPE, _categorie, "01" 81 | _#_kind#_color_2 _color_field _#_kind#_color_string_2, _#_kind#_color_string_2.sizeof, _ESCAPE, _categorie, "02" 82 | _#_kind#_color_3 _color_field _#_kind#_color_string_3, _#_kind#_color_string_3.sizeof, _ESCAPE, _categorie, "03" 83 | _#_kind#_color_4 _color_field _#_kind#_color_string_4, _#_kind#_color_string_4.sizeof, _ESCAPE, _categorie, "04" 84 | _#_kind#_color_5 _color_field _#_kind#_color_string_5, _#_kind#_color_string_5.sizeof, _ESCAPE, _categorie, "05" 85 | _#_kind#_color_6 _color_field _#_kind#_color_string_6, _#_kind#_color_string_6.sizeof, _ESCAPE, _categorie, "06" 86 | _#_kind#_color_7 _color_field _#_kind#_color_string_7, _#_kind#_color_string_7.sizeof, _ESCAPE, _categorie, "07" 87 | _#_kind#_color_table_end: 88 | 89 | _#_kind#_invalid string `_kind, " invalid usage", 00AH 90 | end _user_code 91 | } 92 | -------------------------------------------------------------------------------- /copyright.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _copyright 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _copyright_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _copyright_invalid 12 | mov edx, _copyright_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _copyright_exit 16 | _copyright_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_WRITE 19 | mov ebx, _TELETYPE_CURRENT 20 | mov ecx, _copyright_display 21 | mov edx, _copyright_display.sizeof 22 | int 030H 23 | xor ebx, ebx 24 | _copyright_exit: 25 | xor eax, eax 26 | mov al, _SYSCALL_EXIT 27 | int 030H 28 | _copyright_display string\ 29 | "Copyright achiu-au@42", 00AH,\ 30 | "License MIT, this kernel is for educational purpose only", 00AH 31 | _copyright_invalid string "copyright invalid usage", 00AH 32 | end _user_code 33 | -------------------------------------------------------------------------------- /errno.inc: -------------------------------------------------------------------------------- 1 | 2 | enum EPERM:1H, ENOENT, ESRCH, EINTR, EIO, ENXIO, E2BIG, ENOEXEC, EBADF, ECHILD, EAGAIN, ENOMEM,\ 3 | EACCES, EFAULT, ENOTBLK, EBUSY, EEXIST, EXDEV, ENODEV, ENOTDIR, EISDIR, EINVAL, ENFILE, EMFILE,\ 4 | ENOTTY, ETXTBSY, EFBIG, ENOSPC, ESPIPE, EROFS, EMLINK, EPIPE, EDOM, ERANGE, ENOSYS 5 | -------------------------------------------------------------------------------- /fonts.inc: -------------------------------------------------------------------------------- 1 | 2 | ; UNSCII font can be found here: http://viznut.fi/unscii/ 3 | 4 | macro _glyph [_translate*] 5 | { 6 | common local _value, _char, _string 7 | forward 8 | _string = (`_translate) 9 | _value = 0H 10 | while (_string) 11 | _value = ((_value) shl 1H) 12 | _char = ((_string) and 0FFH) 13 | if ((_char) = "@") 14 | _value = ((_value) or 1H) 15 | else if ((_char) <> ".") 16 | assert (0H) 17 | end if 18 | _string = ((_string) shr 8H) 19 | end while 20 | db (_value) 21 | } 22 | 23 | struct _fonts _source*, _width*, _height*, _btposw*, _btposh* 24 | .source: dd (_source) 25 | .width: db (_width) 26 | .height: db (_height) 27 | .btposw: db (_btposw) 28 | .btposh: db (_btposh) 29 | ends 30 | 31 | _default_font_8x8 _fonts _font_unscii_8x8, 8H, 8H, (bsf 8H), (bsf 8H) 32 | _default_font_8x16 _fonts _font_unscii_8x16, 8H, 010H, (bsf 8H), (bsf 010H) 33 | 34 | _font_unscii_8x8: 35 | _glyph\ 36 | ........,\ 37 | ........,\ 38 | ........,\ 39 | ........,\ 40 | ........,\ 41 | ........,\ 42 | ........,\ 43 | ........,\ 44 | ...@@...,\ 45 | ...@@...,\ 46 | ...@@...,\ 47 | ...@@...,\ 48 | ...@@...,\ 49 | ........,\ 50 | ...@@...,\ 51 | ........,\ 52 | .@@..@@.,\ 53 | .@@..@@.,\ 54 | .@@..@@.,\ 55 | ........,\ 56 | ........,\ 57 | ........,\ 58 | ........,\ 59 | ........,\ 60 | .@@.@@..,\ 61 | .@@.@@..,\ 62 | @@@@@@@.,\ 63 | .@@.@@..,\ 64 | @@@@@@@.,\ 65 | .@@.@@..,\ 66 | .@@.@@..,\ 67 | ........,\ 68 | ...@@...,\ 69 | ..@@@@@.,\ 70 | .@@.....,\ 71 | ..@@@@..,\ 72 | .....@@.,\ 73 | .@@@@@..,\ 74 | ...@@...,\ 75 | ........,\ 76 | ........,\ 77 | @@...@@.,\ 78 | @@..@@..,\ 79 | ...@@...,\ 80 | ..@@....,\ 81 | .@@..@@.,\ 82 | @@...@@.,\ 83 | ........,\ 84 | ..@@@...,\ 85 | .@@.@@..,\ 86 | ..@@@...,\ 87 | .@@@.@@.,\ 88 | @@.@@@..,\ 89 | @@..@@..,\ 90 | .@@@.@@.,\ 91 | ........,\ 92 | ...@@...,\ 93 | ...@@...,\ 94 | ..@@....,\ 95 | ........,\ 96 | ........,\ 97 | ........,\ 98 | ........,\ 99 | ........,\ 100 | ....@@..,\ 101 | ...@@...,\ 102 | ..@@....,\ 103 | ..@@....,\ 104 | ..@@....,\ 105 | ...@@...,\ 106 | ....@@..,\ 107 | ........,\ 108 | ..@@....,\ 109 | ...@@...,\ 110 | ....@@..,\ 111 | ....@@..,\ 112 | ....@@..,\ 113 | ...@@...,\ 114 | ..@@....,\ 115 | ........,\ 116 | ........,\ 117 | .@@..@@.,\ 118 | ..@@@@..,\ 119 | @@@@@@@@,\ 120 | ..@@@@..,\ 121 | .@@..@@.,\ 122 | ........,\ 123 | ........,\ 124 | ........,\ 125 | ...@@...,\ 126 | ...@@...,\ 127 | .@@@@@@.,\ 128 | ...@@...,\ 129 | ...@@...,\ 130 | ........,\ 131 | ........,\ 132 | ........,\ 133 | ........,\ 134 | ........,\ 135 | ........,\ 136 | ........,\ 137 | ...@@...,\ 138 | ...@@...,\ 139 | ..@@....,\ 140 | ........,\ 141 | ........,\ 142 | ........,\ 143 | .@@@@@@.,\ 144 | ........,\ 145 | ........,\ 146 | ........,\ 147 | ........,\ 148 | ........,\ 149 | ........,\ 150 | ........,\ 151 | ........,\ 152 | ........,\ 153 | ...@@...,\ 154 | ...@@...,\ 155 | ........,\ 156 | ......@@,\ 157 | .....@@.,\ 158 | ....@@..,\ 159 | ...@@...,\ 160 | ..@@....,\ 161 | .@@.....,\ 162 | @@......,\ 163 | ........,\ 164 | ..@@@@..,\ 165 | .@@..@@.,\ 166 | .@@.@@@.,\ 167 | .@@@.@@.,\ 168 | .@@..@@.,\ 169 | .@@..@@.,\ 170 | ..@@@@..,\ 171 | ........,\ 172 | ...@@...,\ 173 | ..@@@...,\ 174 | ...@@...,\ 175 | ...@@...,\ 176 | ...@@...,\ 177 | ...@@...,\ 178 | .@@@@@@.,\ 179 | ........,\ 180 | ..@@@@..,\ 181 | .@@..@@.,\ 182 | ....@@..,\ 183 | ...@@...,\ 184 | ..@@....,\ 185 | .@@.....,\ 186 | .@@@@@@.,\ 187 | ........,\ 188 | ..@@@@..,\ 189 | .@@..@@.,\ 190 | .....@@.,\ 191 | ...@@@..,\ 192 | .....@@.,\ 193 | .@@..@@.,\ 194 | ..@@@@..,\ 195 | ........,\ 196 | ...@@@..,\ 197 | ..@@@@..,\ 198 | .@@.@@..,\ 199 | @@..@@..,\ 200 | @@@@@@@.,\ 201 | ....@@..,\ 202 | ....@@..,\ 203 | ........,\ 204 | .@@@@@@.,\ 205 | .@@.....,\ 206 | .@@@@@..,\ 207 | .....@@.,\ 208 | .....@@.,\ 209 | .@@..@@.,\ 210 | ..@@@@..,\ 211 | ........,\ 212 | ...@@@..,\ 213 | ..@@....,\ 214 | .@@.....,\ 215 | .@@@@@..,\ 216 | .@@..@@.,\ 217 | .@@..@@.,\ 218 | ..@@@@..,\ 219 | ........,\ 220 | .@@@@@@.,\ 221 | .....@@.,\ 222 | .....@@.,\ 223 | ....@@..,\ 224 | ...@@...,\ 225 | ...@@...,\ 226 | ...@@...,\ 227 | ........,\ 228 | ..@@@@..,\ 229 | .@@..@@.,\ 230 | .@@..@@.,\ 231 | ..@@@@..,\ 232 | .@@..@@.,\ 233 | .@@..@@.,\ 234 | ..@@@@..,\ 235 | ........,\ 236 | ..@@@@..,\ 237 | .@@..@@.,\ 238 | .@@..@@.,\ 239 | ..@@@@@.,\ 240 | .....@@.,\ 241 | ....@@..,\ 242 | ..@@@...,\ 243 | ........,\ 244 | ........,\ 245 | ...@@...,\ 246 | ...@@...,\ 247 | ........,\ 248 | ........,\ 249 | ...@@...,\ 250 | ...@@...,\ 251 | ........,\ 252 | ........,\ 253 | ...@@...,\ 254 | ...@@...,\ 255 | ........,\ 256 | ........,\ 257 | ...@@...,\ 258 | ...@@...,\ 259 | ..@@....,\ 260 | ....@@..,\ 261 | ...@@...,\ 262 | ..@@....,\ 263 | .@@.....,\ 264 | ..@@....,\ 265 | ...@@...,\ 266 | ....@@..,\ 267 | ........,\ 268 | ........,\ 269 | ........,\ 270 | .@@@@@@.,\ 271 | ........,\ 272 | .@@@@@@.,\ 273 | ........,\ 274 | ........,\ 275 | ........,\ 276 | .@@.....,\ 277 | ..@@....,\ 278 | ...@@...,\ 279 | ....@@..,\ 280 | ...@@...,\ 281 | ..@@....,\ 282 | .@@.....,\ 283 | ........,\ 284 | ..@@@@..,\ 285 | .@@..@@.,\ 286 | .....@@.,\ 287 | ....@@..,\ 288 | ...@@...,\ 289 | ........,\ 290 | ...@@...,\ 291 | ........,\ 292 | .@@@@@..,\ 293 | @@...@@.,\ 294 | @@.@@@@.,\ 295 | @@.@@@@.,\ 296 | @@.@@@@.,\ 297 | @@......,\ 298 | .@@@@@..,\ 299 | ........,\ 300 | ...@@...,\ 301 | ..@@@@..,\ 302 | .@@..@@.,\ 303 | .@@..@@.,\ 304 | .@@@@@@.,\ 305 | .@@..@@.,\ 306 | .@@..@@.,\ 307 | ........,\ 308 | .@@@@@..,\ 309 | .@@..@@.,\ 310 | .@@..@@.,\ 311 | .@@@@@..,\ 312 | .@@..@@.,\ 313 | .@@..@@.,\ 314 | .@@@@@..,\ 315 | ........,\ 316 | ..@@@@..,\ 317 | .@@..@@.,\ 318 | .@@.....,\ 319 | .@@.....,\ 320 | .@@.....,\ 321 | .@@..@@.,\ 322 | ..@@@@..,\ 323 | ........,\ 324 | .@@@@...,\ 325 | .@@.@@..,\ 326 | .@@..@@.,\ 327 | .@@..@@.,\ 328 | .@@..@@.,\ 329 | .@@.@@..,\ 330 | .@@@@...,\ 331 | ........,\ 332 | .@@@@@@.,\ 333 | .@@.....,\ 334 | .@@.....,\ 335 | .@@@@@..,\ 336 | .@@.....,\ 337 | .@@.....,\ 338 | .@@@@@@.,\ 339 | ........,\ 340 | .@@@@@@.,\ 341 | .@@.....,\ 342 | .@@.....,\ 343 | .@@@@@..,\ 344 | .@@.....,\ 345 | .@@.....,\ 346 | .@@.....,\ 347 | ........,\ 348 | ..@@@@..,\ 349 | .@@..@@.,\ 350 | .@@.....,\ 351 | .@@.@@@.,\ 352 | .@@..@@.,\ 353 | .@@..@@.,\ 354 | ..@@@@@.,\ 355 | ........,\ 356 | .@@..@@.,\ 357 | .@@..@@.,\ 358 | .@@..@@.,\ 359 | .@@@@@@.,\ 360 | .@@..@@.,\ 361 | .@@..@@.,\ 362 | .@@..@@.,\ 363 | ........,\ 364 | .@@@@@@.,\ 365 | ...@@...,\ 366 | ...@@...,\ 367 | ...@@...,\ 368 | ...@@...,\ 369 | ...@@...,\ 370 | .@@@@@@.,\ 371 | ........,\ 372 | .....@@.,\ 373 | .....@@.,\ 374 | .....@@.,\ 375 | .....@@.,\ 376 | .....@@.,\ 377 | .@@..@@.,\ 378 | ..@@@@..,\ 379 | ........,\ 380 | @@...@@.,\ 381 | @@..@@..,\ 382 | @@.@@...,\ 383 | @@@@....,\ 384 | @@.@@...,\ 385 | @@..@@..,\ 386 | @@...@@.,\ 387 | ........,\ 388 | .@@.....,\ 389 | .@@.....,\ 390 | .@@.....,\ 391 | .@@.....,\ 392 | .@@.....,\ 393 | .@@.....,\ 394 | .@@@@@@.,\ 395 | ........,\ 396 | @@...@@.,\ 397 | @@@.@@@.,\ 398 | @@@@@@@.,\ 399 | @@.@.@@.,\ 400 | @@...@@.,\ 401 | @@...@@.,\ 402 | @@...@@.,\ 403 | ........,\ 404 | @@...@@.,\ 405 | @@@..@@.,\ 406 | @@@@.@@.,\ 407 | @@.@@@@.,\ 408 | @@..@@@.,\ 409 | @@...@@.,\ 410 | @@...@@.,\ 411 | ........,\ 412 | ..@@@@..,\ 413 | .@@..@@.,\ 414 | .@@..@@.,\ 415 | .@@..@@.,\ 416 | .@@..@@.,\ 417 | .@@..@@.,\ 418 | ..@@@@..,\ 419 | ........,\ 420 | .@@@@@..,\ 421 | .@@..@@.,\ 422 | .@@..@@.,\ 423 | .@@@@@..,\ 424 | .@@.....,\ 425 | .@@.....,\ 426 | .@@.....,\ 427 | ........,\ 428 | ..@@@@..,\ 429 | .@@..@@.,\ 430 | .@@..@@.,\ 431 | .@@..@@.,\ 432 | .@@..@@.,\ 433 | .@@.@@..,\ 434 | ..@@.@@.,\ 435 | ........,\ 436 | .@@@@@..,\ 437 | .@@..@@.,\ 438 | .@@..@@.,\ 439 | .@@@@@..,\ 440 | .@@.@@..,\ 441 | .@@..@@.,\ 442 | .@@..@@.,\ 443 | ........,\ 444 | ..@@@@..,\ 445 | .@@..@@.,\ 446 | .@@.....,\ 447 | ..@@@@..,\ 448 | .....@@.,\ 449 | .@@..@@.,\ 450 | ..@@@@..,\ 451 | ........,\ 452 | .@@@@@@.,\ 453 | ...@@...,\ 454 | ...@@...,\ 455 | ...@@...,\ 456 | ...@@...,\ 457 | ...@@...,\ 458 | ...@@...,\ 459 | ........,\ 460 | .@@..@@.,\ 461 | .@@..@@.,\ 462 | .@@..@@.,\ 463 | .@@..@@.,\ 464 | .@@..@@.,\ 465 | .@@..@@.,\ 466 | ..@@@@..,\ 467 | ........,\ 468 | .@@..@@.,\ 469 | .@@..@@.,\ 470 | .@@..@@.,\ 471 | .@@..@@.,\ 472 | .@@..@@.,\ 473 | ..@@@@..,\ 474 | ...@@...,\ 475 | ........,\ 476 | @@...@@.,\ 477 | @@...@@.,\ 478 | @@...@@.,\ 479 | @@.@.@@.,\ 480 | @@@@@@@.,\ 481 | @@@.@@@.,\ 482 | @@...@@.,\ 483 | ........,\ 484 | @@....@@,\ 485 | .@@..@@.,\ 486 | ..@@@@..,\ 487 | ...@@...,\ 488 | ..@@@@..,\ 489 | .@@..@@.,\ 490 | @@....@@,\ 491 | ........,\ 492 | @@....@@,\ 493 | .@@..@@.,\ 494 | ..@@@@..,\ 495 | ...@@...,\ 496 | ...@@...,\ 497 | ...@@...,\ 498 | ...@@...,\ 499 | ........,\ 500 | .@@@@@@.,\ 501 | .....@@.,\ 502 | ....@@..,\ 503 | ...@@...,\ 504 | ..@@....,\ 505 | .@@.....,\ 506 | .@@@@@@.,\ 507 | ........,\ 508 | ..@@@@..,\ 509 | ..@@....,\ 510 | ..@@....,\ 511 | ..@@....,\ 512 | ..@@....,\ 513 | ..@@....,\ 514 | ..@@@@..,\ 515 | ........,\ 516 | @@......,\ 517 | .@@.....,\ 518 | ..@@....,\ 519 | ...@@...,\ 520 | ....@@..,\ 521 | .....@@.,\ 522 | ......@@,\ 523 | ........,\ 524 | ..@@@@..,\ 525 | ....@@..,\ 526 | ....@@..,\ 527 | ....@@..,\ 528 | ....@@..,\ 529 | ....@@..,\ 530 | ..@@@@..,\ 531 | ........,\ 532 | ...@....,\ 533 | ..@@@...,\ 534 | .@@.@@..,\ 535 | @@...@@.,\ 536 | ........,\ 537 | ........,\ 538 | ........,\ 539 | ........,\ 540 | ........,\ 541 | ........,\ 542 | ........,\ 543 | ........,\ 544 | ........,\ 545 | ........,\ 546 | ........,\ 547 | @@@@@@@@,\ 548 | ...@@...,\ 549 | ....@@..,\ 550 | .....@@.,\ 551 | ........,\ 552 | ........,\ 553 | ........,\ 554 | ........,\ 555 | ........,\ 556 | ........,\ 557 | ........,\ 558 | ..@@@@..,\ 559 | .....@@.,\ 560 | ..@@@@@.,\ 561 | .@@..@@.,\ 562 | ..@@@@@.,\ 563 | ........,\ 564 | .@@.....,\ 565 | .@@.....,\ 566 | .@@@@@..,\ 567 | .@@..@@.,\ 568 | .@@..@@.,\ 569 | .@@..@@.,\ 570 | .@@@@@..,\ 571 | ........,\ 572 | ........,\ 573 | ........,\ 574 | ..@@@@..,\ 575 | .@@.....,\ 576 | .@@.....,\ 577 | .@@.....,\ 578 | ..@@@@..,\ 579 | ........,\ 580 | .....@@.,\ 581 | .....@@.,\ 582 | ..@@@@@.,\ 583 | .@@..@@.,\ 584 | .@@..@@.,\ 585 | .@@..@@.,\ 586 | ..@@@@@.,\ 587 | ........,\ 588 | ........,\ 589 | ........,\ 590 | ..@@@@..,\ 591 | .@@..@@.,\ 592 | .@@@@@@.,\ 593 | .@@.....,\ 594 | ..@@@@..,\ 595 | ........,\ 596 | ...@@@..,\ 597 | ..@@....,\ 598 | .@@@@@..,\ 599 | ..@@....,\ 600 | ..@@....,\ 601 | ..@@....,\ 602 | ..@@....,\ 603 | ........,\ 604 | ........,\ 605 | ........,\ 606 | ..@@@@@.,\ 607 | .@@..@@.,\ 608 | .@@..@@.,\ 609 | ..@@@@@.,\ 610 | .....@@.,\ 611 | .@@@@@..,\ 612 | .@@.....,\ 613 | .@@.....,\ 614 | .@@@@@..,\ 615 | .@@..@@.,\ 616 | .@@..@@.,\ 617 | .@@..@@.,\ 618 | .@@..@@.,\ 619 | ........,\ 620 | ...@@...,\ 621 | ........,\ 622 | ..@@@...,\ 623 | ...@@...,\ 624 | ...@@...,\ 625 | ...@@...,\ 626 | ...@@@@.,\ 627 | ........,\ 628 | ........,\ 629 | ........,\ 630 | ....@@..,\ 631 | ....@@..,\ 632 | ....@@..,\ 633 | ....@@..,\ 634 | ....@@..,\ 635 | .@@@@...,\ 636 | .@@.....,\ 637 | .@@.....,\ 638 | .@@..@@.,\ 639 | .@@.@@..,\ 640 | .@@@@...,\ 641 | .@@.@@..,\ 642 | .@@..@@.,\ 643 | ........,\ 644 | ..@@@...,\ 645 | ...@@...,\ 646 | ...@@...,\ 647 | ...@@...,\ 648 | ...@@...,\ 649 | ...@@...,\ 650 | ...@@@@.,\ 651 | ........,\ 652 | ........,\ 653 | ........,\ 654 | @@..@@..,\ 655 | @@@@@@@.,\ 656 | @@.@.@@.,\ 657 | @@.@.@@.,\ 658 | @@...@@.,\ 659 | ........,\ 660 | ........,\ 661 | ........,\ 662 | .@@@@@..,\ 663 | .@@..@@.,\ 664 | .@@..@@.,\ 665 | .@@..@@.,\ 666 | .@@..@@.,\ 667 | ........,\ 668 | ........,\ 669 | ........,\ 670 | ..@@@@..,\ 671 | .@@..@@.,\ 672 | .@@..@@.,\ 673 | .@@..@@.,\ 674 | ..@@@@..,\ 675 | ........,\ 676 | ........,\ 677 | ........,\ 678 | .@@@@@..,\ 679 | .@@..@@.,\ 680 | .@@..@@.,\ 681 | .@@@@@..,\ 682 | .@@.....,\ 683 | .@@.....,\ 684 | ........,\ 685 | ........,\ 686 | ..@@@@@.,\ 687 | .@@..@@.,\ 688 | .@@..@@.,\ 689 | ..@@@@@.,\ 690 | .....@@.,\ 691 | .....@@.,\ 692 | ........,\ 693 | ........,\ 694 | .@@@@@..,\ 695 | .@@..@@.,\ 696 | .@@.....,\ 697 | .@@.....,\ 698 | .@@.....,\ 699 | ........,\ 700 | ........,\ 701 | ........,\ 702 | ..@@@@@.,\ 703 | .@@.....,\ 704 | ..@@@@..,\ 705 | .....@@.,\ 706 | .@@@@@..,\ 707 | ........,\ 708 | ..@@....,\ 709 | ..@@....,\ 710 | .@@@@@@.,\ 711 | ..@@....,\ 712 | ..@@....,\ 713 | ..@@....,\ 714 | ...@@@@.,\ 715 | ........,\ 716 | ........,\ 717 | ........,\ 718 | .@@..@@.,\ 719 | .@@..@@.,\ 720 | .@@..@@.,\ 721 | .@@..@@.,\ 722 | ..@@@@@.,\ 723 | ........,\ 724 | ........,\ 725 | ........,\ 726 | .@@..@@.,\ 727 | .@@..@@.,\ 728 | .@@..@@.,\ 729 | ..@@@@..,\ 730 | ...@@...,\ 731 | ........,\ 732 | ........,\ 733 | ........,\ 734 | @@...@@.,\ 735 | @@...@@.,\ 736 | @@.@.@@.,\ 737 | .@@@@@..,\ 738 | .@@.@@..,\ 739 | ........,\ 740 | ........,\ 741 | ........,\ 742 | @@...@@.,\ 743 | .@@.@@..,\ 744 | ..@@@...,\ 745 | .@@.@@..,\ 746 | @@...@@.,\ 747 | ........,\ 748 | ........,\ 749 | ........,\ 750 | .@@..@@.,\ 751 | .@@..@@.,\ 752 | .@@..@@.,\ 753 | ..@@@@@.,\ 754 | .....@@.,\ 755 | ..@@@@..,\ 756 | ........,\ 757 | ........,\ 758 | .@@@@@@.,\ 759 | ....@@..,\ 760 | ...@@...,\ 761 | ..@@....,\ 762 | .@@@@@@.,\ 763 | ........,\ 764 | ....@@@.,\ 765 | ...@@...,\ 766 | ...@@...,\ 767 | .@@@....,\ 768 | ...@@...,\ 769 | ...@@...,\ 770 | ....@@@.,\ 771 | ........,\ 772 | ...@@...,\ 773 | ...@@...,\ 774 | ...@@...,\ 775 | ...@@...,\ 776 | ...@@...,\ 777 | ...@@...,\ 778 | ...@@...,\ 779 | ........,\ 780 | .@@@....,\ 781 | ...@@...,\ 782 | ...@@...,\ 783 | ....@@@.,\ 784 | ...@@...,\ 785 | ...@@...,\ 786 | .@@@....,\ 787 | ........,\ 788 | .@@@.@@.,\ 789 | @@.@@@..,\ 790 | ........,\ 791 | ........,\ 792 | ........,\ 793 | ........,\ 794 | ........,\ 795 | ........ 796 | 797 | _font_unscii_8x16: 798 | _glyph\ 799 | ........,\ 800 | ........,\ 801 | ........,\ 802 | ........,\ 803 | ........,\ 804 | ........,\ 805 | ........,\ 806 | ........,\ 807 | ........,\ 808 | ........,\ 809 | ........,\ 810 | ........,\ 811 | ........,\ 812 | ........,\ 813 | ........,\ 814 | ........,\ 815 | ........,\ 816 | ...@@...,\ 817 | ...@@...,\ 818 | ...@@...,\ 819 | ...@@...,\ 820 | ...@@...,\ 821 | ...@@...,\ 822 | ...@@...,\ 823 | ...@@...,\ 824 | ........,\ 825 | ........,\ 826 | ...@@...,\ 827 | ...@@...,\ 828 | ........,\ 829 | ........,\ 830 | ........,\ 831 | ........,\ 832 | .@@..@@.,\ 833 | .@@..@@.,\ 834 | .@@..@@.,\ 835 | ........,\ 836 | ........,\ 837 | ........,\ 838 | ........,\ 839 | ........,\ 840 | ........,\ 841 | ........,\ 842 | ........,\ 843 | ........,\ 844 | ........,\ 845 | ........,\ 846 | ........,\ 847 | ........,\ 848 | ........,\ 849 | .@@.@@..,\ 850 | .@@.@@..,\ 851 | .@@.@@..,\ 852 | @@@@@@@.,\ 853 | .@@.@@..,\ 854 | .@@.@@..,\ 855 | .@@.@@..,\ 856 | @@@@@@@.,\ 857 | .@@.@@..,\ 858 | .@@.@@..,\ 859 | .@@.@@..,\ 860 | ........,\ 861 | ........,\ 862 | ........,\ 863 | ........,\ 864 | ...@@...,\ 865 | ...@@...,\ 866 | ..@@@@..,\ 867 | .@@..@@.,\ 868 | .@@.....,\ 869 | ..@@....,\ 870 | ...@@...,\ 871 | ....@@..,\ 872 | .....@@.,\ 873 | .@@..@@.,\ 874 | ..@@@@..,\ 875 | ...@@...,\ 876 | ...@@...,\ 877 | ........,\ 878 | ........,\ 879 | ........,\ 880 | ........,\ 881 | .....@@.,\ 882 | @@...@@.,\ 883 | @@..@@..,\ 884 | @@..@@..,\ 885 | ...@@...,\ 886 | ...@@...,\ 887 | ..@@....,\ 888 | ..@@....,\ 889 | .@@..@@.,\ 890 | .@@..@@.,\ 891 | @@...@@.,\ 892 | @@......,\ 893 | ........,\ 894 | ........,\ 895 | ........,\ 896 | ........,\ 897 | ..@@@...,\ 898 | .@@.@@..,\ 899 | .@@.@@..,\ 900 | ..@@@...,\ 901 | ..@@....,\ 902 | .@@@@.@.,\ 903 | @@.@@@@.,\ 904 | @@..@@..,\ 905 | @@..@@..,\ 906 | @@..@@..,\ 907 | .@@@.@@.,\ 908 | ........,\ 909 | ........,\ 910 | ........,\ 911 | ........,\ 912 | ...@@...,\ 913 | ...@@...,\ 914 | ...@@...,\ 915 | ..@@....,\ 916 | ........,\ 917 | ........,\ 918 | ........,\ 919 | ........,\ 920 | ........,\ 921 | ........,\ 922 | ........,\ 923 | ........,\ 924 | ........,\ 925 | ........,\ 926 | ........,\ 927 | ........,\ 928 | ....@@..,\ 929 | ...@@...,\ 930 | ...@@...,\ 931 | ..@@....,\ 932 | ..@@....,\ 933 | ..@@....,\ 934 | ..@@....,\ 935 | ..@@....,\ 936 | ..@@....,\ 937 | ..@@....,\ 938 | ...@@...,\ 939 | ...@@...,\ 940 | ....@@..,\ 941 | ........,\ 942 | ........,\ 943 | ........,\ 944 | ..@@....,\ 945 | ...@@...,\ 946 | ...@@...,\ 947 | ....@@..,\ 948 | ....@@..,\ 949 | ....@@..,\ 950 | ....@@..,\ 951 | ....@@..,\ 952 | ....@@..,\ 953 | ....@@..,\ 954 | ...@@...,\ 955 | ...@@...,\ 956 | ..@@....,\ 957 | ........,\ 958 | ........,\ 959 | ........,\ 960 | ........,\ 961 | ........,\ 962 | ........,\ 963 | .@@..@@.,\ 964 | .@@..@@.,\ 965 | ..@@@@..,\ 966 | @@@@@@@@,\ 967 | ..@@@@..,\ 968 | .@@..@@.,\ 969 | .@@..@@.,\ 970 | ........,\ 971 | ........,\ 972 | ........,\ 973 | ........,\ 974 | ........,\ 975 | ........,\ 976 | ........,\ 977 | ........,\ 978 | ........,\ 979 | ...@@...,\ 980 | ...@@...,\ 981 | ...@@...,\ 982 | .@@@@@@.,\ 983 | ...@@...,\ 984 | ...@@...,\ 985 | ...@@...,\ 986 | ........,\ 987 | ........,\ 988 | ........,\ 989 | ........,\ 990 | ........,\ 991 | ........,\ 992 | ........,\ 993 | ........,\ 994 | ........,\ 995 | ........,\ 996 | ........,\ 997 | ........,\ 998 | ........,\ 999 | ........,\ 1000 | ........,\ 1001 | ..@@@...,\ 1002 | ...@@...,\ 1003 | ...@@...,\ 1004 | ..@@....,\ 1005 | .@@.....,\ 1006 | ........,\ 1007 | ........,\ 1008 | ........,\ 1009 | ........,\ 1010 | ........,\ 1011 | ........,\ 1012 | ........,\ 1013 | ........,\ 1014 | .@@@@@@.,\ 1015 | ........,\ 1016 | ........,\ 1017 | ........,\ 1018 | ........,\ 1019 | ........,\ 1020 | ........,\ 1021 | ........,\ 1022 | ........,\ 1023 | ........,\ 1024 | ........,\ 1025 | ........,\ 1026 | ........,\ 1027 | ........,\ 1028 | ........,\ 1029 | ........,\ 1030 | ........,\ 1031 | ........,\ 1032 | ........,\ 1033 | ...@@...,\ 1034 | ...@@...,\ 1035 | ...@@...,\ 1036 | ........,\ 1037 | ........,\ 1038 | ........,\ 1039 | ......@@,\ 1040 | ......@@,\ 1041 | .....@@.,\ 1042 | .....@@.,\ 1043 | ....@@..,\ 1044 | ....@@..,\ 1045 | ...@@...,\ 1046 | ...@@...,\ 1047 | ..@@....,\ 1048 | ..@@....,\ 1049 | .@@.....,\ 1050 | .@@.....,\ 1051 | @@......,\ 1052 | @@......,\ 1053 | ........,\ 1054 | ........,\ 1055 | ........,\ 1056 | ........,\ 1057 | ..@@@...,\ 1058 | .@@.@@..,\ 1059 | @@...@@.,\ 1060 | @@...@@.,\ 1061 | @@..@@@.,\ 1062 | @@.@.@@.,\ 1063 | @@@..@@.,\ 1064 | @@...@@.,\ 1065 | @@...@@.,\ 1066 | .@@.@@..,\ 1067 | ..@@@...,\ 1068 | ........,\ 1069 | ........,\ 1070 | ........,\ 1071 | ........,\ 1072 | ........,\ 1073 | ...@@...,\ 1074 | ..@@@...,\ 1075 | .@@@@...,\ 1076 | ...@@...,\ 1077 | ...@@...,\ 1078 | ...@@...,\ 1079 | ...@@...,\ 1080 | ...@@...,\ 1081 | ...@@...,\ 1082 | ...@@...,\ 1083 | .@@@@@@.,\ 1084 | ........,\ 1085 | ........,\ 1086 | ........,\ 1087 | ........,\ 1088 | ........,\ 1089 | ..@@@@..,\ 1090 | .@@..@@.,\ 1091 | .@@..@@.,\ 1092 | .....@@.,\ 1093 | .....@@.,\ 1094 | ....@@..,\ 1095 | ...@@...,\ 1096 | ..@@....,\ 1097 | .@@.....,\ 1098 | .@@.....,\ 1099 | .@@@@@@.,\ 1100 | ........,\ 1101 | ........,\ 1102 | ........,\ 1103 | ........,\ 1104 | ........,\ 1105 | ..@@@@..,\ 1106 | .@@..@@.,\ 1107 | .@@..@@.,\ 1108 | .....@@.,\ 1109 | .....@@.,\ 1110 | ...@@@..,\ 1111 | .....@@.,\ 1112 | .....@@.,\ 1113 | .@@..@@.,\ 1114 | .@@..@@.,\ 1115 | ..@@@@..,\ 1116 | ........,\ 1117 | ........,\ 1118 | ........,\ 1119 | ........,\ 1120 | ........,\ 1121 | ....@@..,\ 1122 | ...@@@..,\ 1123 | ..@@@@..,\ 1124 | .@@.@@..,\ 1125 | @@..@@..,\ 1126 | @@..@@..,\ 1127 | @@@@@@@.,\ 1128 | ....@@..,\ 1129 | ....@@..,\ 1130 | ....@@..,\ 1131 | ....@@..,\ 1132 | ........,\ 1133 | ........,\ 1134 | ........,\ 1135 | ........,\ 1136 | ........,\ 1137 | .@@@@@@.,\ 1138 | .@@.....,\ 1139 | .@@.....,\ 1140 | .@@.....,\ 1141 | .@@@@@..,\ 1142 | .....@@.,\ 1143 | .....@@.,\ 1144 | .....@@.,\ 1145 | .@@..@@.,\ 1146 | .@@..@@.,\ 1147 | ..@@@@..,\ 1148 | ........,\ 1149 | ........,\ 1150 | ........,\ 1151 | ........,\ 1152 | ........,\ 1153 | ...@@@..,\ 1154 | ..@@....,\ 1155 | .@@.....,\ 1156 | .@@.....,\ 1157 | .@@@@@..,\ 1158 | .@@..@@.,\ 1159 | .@@..@@.,\ 1160 | .@@..@@.,\ 1161 | .@@..@@.,\ 1162 | .@@..@@.,\ 1163 | ..@@@@..,\ 1164 | ........,\ 1165 | ........,\ 1166 | ........,\ 1167 | ........,\ 1168 | ........,\ 1169 | .@@@@@@.,\ 1170 | .....@@.,\ 1171 | .....@@.,\ 1172 | .....@@.,\ 1173 | ....@@..,\ 1174 | ....@@..,\ 1175 | ...@@...,\ 1176 | ...@@...,\ 1177 | ...@@...,\ 1178 | ...@@...,\ 1179 | ...@@...,\ 1180 | ........,\ 1181 | ........,\ 1182 | ........,\ 1183 | ........,\ 1184 | ........,\ 1185 | ..@@@@..,\ 1186 | .@@..@@.,\ 1187 | .@@..@@.,\ 1188 | .@@..@@.,\ 1189 | .@@@.@@.,\ 1190 | ..@@@@..,\ 1191 | .@@.@@@.,\ 1192 | .@@..@@.,\ 1193 | .@@..@@.,\ 1194 | .@@..@@.,\ 1195 | ..@@@@..,\ 1196 | ........,\ 1197 | ........,\ 1198 | ........,\ 1199 | ........,\ 1200 | ........,\ 1201 | ..@@@@..,\ 1202 | .@@..@@.,\ 1203 | .@@..@@.,\ 1204 | .@@..@@.,\ 1205 | .@@..@@.,\ 1206 | ..@@@@@.,\ 1207 | .....@@.,\ 1208 | .....@@.,\ 1209 | .....@@.,\ 1210 | ....@@..,\ 1211 | ..@@@...,\ 1212 | ........,\ 1213 | ........,\ 1214 | ........,\ 1215 | ........,\ 1216 | ........,\ 1217 | ........,\ 1218 | ...@@...,\ 1219 | ...@@...,\ 1220 | ...@@...,\ 1221 | ........,\ 1222 | ........,\ 1223 | ........,\ 1224 | ........,\ 1225 | ...@@...,\ 1226 | ...@@...,\ 1227 | ...@@...,\ 1228 | ........,\ 1229 | ........,\ 1230 | ........,\ 1231 | ........,\ 1232 | ........,\ 1233 | ........,\ 1234 | ...@@...,\ 1235 | ...@@...,\ 1236 | ...@@...,\ 1237 | ........,\ 1238 | ........,\ 1239 | ........,\ 1240 | ........,\ 1241 | ..@@@...,\ 1242 | ...@@...,\ 1243 | ...@@...,\ 1244 | ..@@....,\ 1245 | .@@.....,\ 1246 | ........,\ 1247 | ........,\ 1248 | ........,\ 1249 | ........,\ 1250 | .....@@.,\ 1251 | ....@@..,\ 1252 | ...@@...,\ 1253 | ..@@....,\ 1254 | .@@.....,\ 1255 | ..@@....,\ 1256 | ...@@...,\ 1257 | ....@@..,\ 1258 | .....@@.,\ 1259 | ........,\ 1260 | ........,\ 1261 | ........,\ 1262 | ........,\ 1263 | ........,\ 1264 | ........,\ 1265 | ........,\ 1266 | ........,\ 1267 | ........,\ 1268 | .@@@@@@.,\ 1269 | ........,\ 1270 | ........,\ 1271 | ........,\ 1272 | .@@@@@@.,\ 1273 | ........,\ 1274 | ........,\ 1275 | ........,\ 1276 | ........,\ 1277 | ........,\ 1278 | ........,\ 1279 | ........,\ 1280 | ........,\ 1281 | ........,\ 1282 | .@@.....,\ 1283 | ..@@....,\ 1284 | ...@@...,\ 1285 | ....@@..,\ 1286 | .....@@.,\ 1287 | ....@@..,\ 1288 | ...@@...,\ 1289 | ..@@....,\ 1290 | .@@.....,\ 1291 | ........,\ 1292 | ........,\ 1293 | ........,\ 1294 | ........,\ 1295 | ........,\ 1296 | ..@@@@..,\ 1297 | .@@..@@.,\ 1298 | .@@..@@.,\ 1299 | .....@@.,\ 1300 | ....@@..,\ 1301 | ...@@...,\ 1302 | ...@@...,\ 1303 | ...@@...,\ 1304 | ........,\ 1305 | ........,\ 1306 | ...@@...,\ 1307 | ...@@...,\ 1308 | ........,\ 1309 | ........,\ 1310 | ........,\ 1311 | ........,\ 1312 | ........,\ 1313 | .@@@@@..,\ 1314 | @@...@@.,\ 1315 | @@...@@.,\ 1316 | @@...@@.,\ 1317 | @@.@@@@.,\ 1318 | @@.@@@@.,\ 1319 | @@.@@@@.,\ 1320 | @@.@@@..,\ 1321 | @@......,\ 1322 | @@......,\ 1323 | .@@@@@..,\ 1324 | ........,\ 1325 | ........,\ 1326 | ........,\ 1327 | ........,\ 1328 | ........,\ 1329 | ...@@...,\ 1330 | ..@@@@..,\ 1331 | .@@..@@.,\ 1332 | .@@..@@.,\ 1333 | .@@..@@.,\ 1334 | .@@@@@@.,\ 1335 | .@@..@@.,\ 1336 | .@@..@@.,\ 1337 | .@@..@@.,\ 1338 | .@@..@@.,\ 1339 | .@@..@@.,\ 1340 | ........,\ 1341 | ........,\ 1342 | ........,\ 1343 | ........,\ 1344 | ........,\ 1345 | .@@@@@..,\ 1346 | .@@..@@.,\ 1347 | .@@..@@.,\ 1348 | .@@..@@.,\ 1349 | .@@.@@..,\ 1350 | .@@@@...,\ 1351 | .@@.@@..,\ 1352 | .@@..@@.,\ 1353 | .@@..@@.,\ 1354 | .@@..@@.,\ 1355 | .@@@@@..,\ 1356 | ........,\ 1357 | ........,\ 1358 | ........,\ 1359 | ........,\ 1360 | ........,\ 1361 | ..@@@@..,\ 1362 | .@@..@@.,\ 1363 | .@@..@@.,\ 1364 | .@@.....,\ 1365 | .@@.....,\ 1366 | .@@.....,\ 1367 | .@@.....,\ 1368 | .@@.....,\ 1369 | .@@..@@.,\ 1370 | .@@..@@.,\ 1371 | ..@@@@..,\ 1372 | ........,\ 1373 | ........,\ 1374 | ........,\ 1375 | ........,\ 1376 | ........,\ 1377 | .@@@@...,\ 1378 | .@@.@@..,\ 1379 | .@@..@@.,\ 1380 | .@@..@@.,\ 1381 | .@@..@@.,\ 1382 | .@@..@@.,\ 1383 | .@@..@@.,\ 1384 | .@@..@@.,\ 1385 | .@@..@@.,\ 1386 | .@@.@@..,\ 1387 | .@@@@...,\ 1388 | ........,\ 1389 | ........,\ 1390 | ........,\ 1391 | ........,\ 1392 | ........,\ 1393 | .@@@@@@.,\ 1394 | .@@.....,\ 1395 | .@@.....,\ 1396 | .@@.....,\ 1397 | .@@.....,\ 1398 | .@@@@@..,\ 1399 | .@@.....,\ 1400 | .@@.....,\ 1401 | .@@.....,\ 1402 | .@@.....,\ 1403 | .@@@@@@.,\ 1404 | ........,\ 1405 | ........,\ 1406 | ........,\ 1407 | ........,\ 1408 | ........,\ 1409 | .@@@@@@.,\ 1410 | .@@.....,\ 1411 | .@@.....,\ 1412 | .@@.....,\ 1413 | .@@@@@..,\ 1414 | .@@.....,\ 1415 | .@@.....,\ 1416 | .@@.....,\ 1417 | .@@.....,\ 1418 | .@@.....,\ 1419 | .@@.....,\ 1420 | ........,\ 1421 | ........,\ 1422 | ........,\ 1423 | ........,\ 1424 | ........,\ 1425 | ..@@@@..,\ 1426 | .@@..@@.,\ 1427 | .@@..@@.,\ 1428 | .@@.....,\ 1429 | .@@.....,\ 1430 | .@@.@@@.,\ 1431 | .@@..@@.,\ 1432 | .@@..@@.,\ 1433 | .@@..@@.,\ 1434 | .@@..@@.,\ 1435 | ..@@@@@.,\ 1436 | ........,\ 1437 | ........,\ 1438 | ........,\ 1439 | ........,\ 1440 | ........,\ 1441 | .@@..@@.,\ 1442 | .@@..@@.,\ 1443 | .@@..@@.,\ 1444 | .@@..@@.,\ 1445 | .@@..@@.,\ 1446 | .@@@@@@.,\ 1447 | .@@..@@.,\ 1448 | .@@..@@.,\ 1449 | .@@..@@.,\ 1450 | .@@..@@.,\ 1451 | .@@..@@.,\ 1452 | ........,\ 1453 | ........,\ 1454 | ........,\ 1455 | ........,\ 1456 | ........,\ 1457 | .@@@@@@.,\ 1458 | ...@@...,\ 1459 | ...@@...,\ 1460 | ...@@...,\ 1461 | ...@@...,\ 1462 | ...@@...,\ 1463 | ...@@...,\ 1464 | ...@@...,\ 1465 | ...@@...,\ 1466 | ...@@...,\ 1467 | .@@@@@@.,\ 1468 | ........,\ 1469 | ........,\ 1470 | ........,\ 1471 | ........,\ 1472 | ........,\ 1473 | .....@@.,\ 1474 | .....@@.,\ 1475 | .....@@.,\ 1476 | .....@@.,\ 1477 | .....@@.,\ 1478 | .....@@.,\ 1479 | .....@@.,\ 1480 | .....@@.,\ 1481 | .@@..@@.,\ 1482 | .@@..@@.,\ 1483 | ..@@@@..,\ 1484 | ........,\ 1485 | ........,\ 1486 | ........,\ 1487 | ........,\ 1488 | ........,\ 1489 | @@...@@.,\ 1490 | @@...@@.,\ 1491 | @@..@@..,\ 1492 | @@..@@..,\ 1493 | @@.@@...,\ 1494 | @@@@....,\ 1495 | @@.@@...,\ 1496 | @@..@@..,\ 1497 | @@..@@..,\ 1498 | @@...@@.,\ 1499 | @@...@@.,\ 1500 | ........,\ 1501 | ........,\ 1502 | ........,\ 1503 | ........,\ 1504 | ........,\ 1505 | .@@.....,\ 1506 | .@@.....,\ 1507 | .@@.....,\ 1508 | .@@.....,\ 1509 | .@@.....,\ 1510 | .@@.....,\ 1511 | .@@.....,\ 1512 | .@@.....,\ 1513 | .@@.....,\ 1514 | .@@.....,\ 1515 | .@@@@@@.,\ 1516 | ........,\ 1517 | ........,\ 1518 | ........,\ 1519 | ........,\ 1520 | ........,\ 1521 | @@...@@.,\ 1522 | @@@.@@@.,\ 1523 | @@@.@@@.,\ 1524 | @@@@@@@.,\ 1525 | @@.@.@@.,\ 1526 | @@.@.@@.,\ 1527 | @@...@@.,\ 1528 | @@...@@.,\ 1529 | @@...@@.,\ 1530 | @@...@@.,\ 1531 | @@...@@.,\ 1532 | ........,\ 1533 | ........,\ 1534 | ........,\ 1535 | ........,\ 1536 | ........,\ 1537 | ........,\ 1538 | @@...@@.,\ 1539 | @@...@@.,\ 1540 | @@@..@@.,\ 1541 | @@@@.@@.,\ 1542 | @@.@@@@.,\ 1543 | @@..@@@.,\ 1544 | @@...@@.,\ 1545 | @@...@@.,\ 1546 | @@...@@.,\ 1547 | @@...@@.,\ 1548 | ........,\ 1549 | ........,\ 1550 | ........,\ 1551 | ........,\ 1552 | ........,\ 1553 | ..@@@@..,\ 1554 | .@@..@@.,\ 1555 | .@@..@@.,\ 1556 | .@@..@@.,\ 1557 | .@@..@@.,\ 1558 | .@@..@@.,\ 1559 | .@@..@@.,\ 1560 | .@@..@@.,\ 1561 | .@@..@@.,\ 1562 | .@@..@@.,\ 1563 | ..@@@@..,\ 1564 | ........,\ 1565 | ........,\ 1566 | ........,\ 1567 | ........,\ 1568 | ........,\ 1569 | .@@@@@..,\ 1570 | .@@..@@.,\ 1571 | .@@..@@.,\ 1572 | .@@..@@.,\ 1573 | .@@..@@.,\ 1574 | .@@@@@..,\ 1575 | .@@.....,\ 1576 | .@@.....,\ 1577 | .@@.....,\ 1578 | .@@.....,\ 1579 | .@@.....,\ 1580 | ........,\ 1581 | ........,\ 1582 | ........,\ 1583 | ........,\ 1584 | ........,\ 1585 | ..@@@@..,\ 1586 | .@@..@@.,\ 1587 | .@@..@@.,\ 1588 | .@@..@@.,\ 1589 | .@@..@@.,\ 1590 | .@@..@@.,\ 1591 | .@@..@@.,\ 1592 | .@@..@@.,\ 1593 | .@@..@@.,\ 1594 | .@@..@@.,\ 1595 | ..@@@@..,\ 1596 | ....@@..,\ 1597 | .....@@.,\ 1598 | ........,\ 1599 | ........,\ 1600 | ........,\ 1601 | .@@@@@..,\ 1602 | .@@..@@.,\ 1603 | .@@..@@.,\ 1604 | .@@..@@.,\ 1605 | .@@..@@.,\ 1606 | .@@@@@..,\ 1607 | .@@.@@..,\ 1608 | .@@..@@.,\ 1609 | .@@..@@.,\ 1610 | .@@..@@.,\ 1611 | .@@..@@.,\ 1612 | ........,\ 1613 | ........,\ 1614 | ........,\ 1615 | ........,\ 1616 | ........,\ 1617 | ..@@@@..,\ 1618 | .@@..@@.,\ 1619 | .@@..@@.,\ 1620 | .@@.....,\ 1621 | ..@@....,\ 1622 | ...@@...,\ 1623 | ....@@..,\ 1624 | .....@@.,\ 1625 | .@@..@@.,\ 1626 | .@@..@@.,\ 1627 | ..@@@@..,\ 1628 | ........,\ 1629 | ........,\ 1630 | ........,\ 1631 | ........,\ 1632 | ........,\ 1633 | .@@@@@@.,\ 1634 | ...@@...,\ 1635 | ...@@...,\ 1636 | ...@@...,\ 1637 | ...@@...,\ 1638 | ...@@...,\ 1639 | ...@@...,\ 1640 | ...@@...,\ 1641 | ...@@...,\ 1642 | ...@@...,\ 1643 | ...@@...,\ 1644 | ........,\ 1645 | ........,\ 1646 | ........,\ 1647 | ........,\ 1648 | ........,\ 1649 | .@@..@@.,\ 1650 | .@@..@@.,\ 1651 | .@@..@@.,\ 1652 | .@@..@@.,\ 1653 | .@@..@@.,\ 1654 | .@@..@@.,\ 1655 | .@@..@@.,\ 1656 | .@@..@@.,\ 1657 | .@@..@@.,\ 1658 | .@@..@@.,\ 1659 | ..@@@@..,\ 1660 | ........,\ 1661 | ........,\ 1662 | ........,\ 1663 | ........,\ 1664 | ........,\ 1665 | .@@..@@.,\ 1666 | .@@..@@.,\ 1667 | .@@..@@.,\ 1668 | .@@..@@.,\ 1669 | .@@..@@.,\ 1670 | .@@..@@.,\ 1671 | .@@..@@.,\ 1672 | ..@@@@..,\ 1673 | ..@@@@..,\ 1674 | ...@@...,\ 1675 | ...@@...,\ 1676 | ........,\ 1677 | ........,\ 1678 | ........,\ 1679 | ........,\ 1680 | ........,\ 1681 | @@...@@.,\ 1682 | @@...@@.,\ 1683 | @@...@@.,\ 1684 | @@...@@.,\ 1685 | @@...@@.,\ 1686 | @@.@.@@.,\ 1687 | @@.@.@@.,\ 1688 | @@@@@@@.,\ 1689 | @@@.@@@.,\ 1690 | @@@.@@@.,\ 1691 | @@...@@.,\ 1692 | ........,\ 1693 | ........,\ 1694 | ........,\ 1695 | ........,\ 1696 | ........,\ 1697 | @@....@@,\ 1698 | @@....@@,\ 1699 | .@@..@@.,\ 1700 | ..@@@@..,\ 1701 | ...@@...,\ 1702 | ...@@...,\ 1703 | ...@@...,\ 1704 | ..@@@@..,\ 1705 | .@@..@@.,\ 1706 | @@....@@,\ 1707 | @@....@@,\ 1708 | ........,\ 1709 | ........,\ 1710 | ........,\ 1711 | ........,\ 1712 | ........,\ 1713 | @@....@@,\ 1714 | @@....@@,\ 1715 | .@@..@@.,\ 1716 | .@@..@@.,\ 1717 | ..@@@@..,\ 1718 | ...@@...,\ 1719 | ...@@...,\ 1720 | ...@@...,\ 1721 | ...@@...,\ 1722 | ...@@...,\ 1723 | ...@@...,\ 1724 | ........,\ 1725 | ........,\ 1726 | ........,\ 1727 | ........,\ 1728 | ........,\ 1729 | .@@@@@@.,\ 1730 | .....@@.,\ 1731 | .....@@.,\ 1732 | ....@@..,\ 1733 | ....@@..,\ 1734 | ...@@...,\ 1735 | ..@@....,\ 1736 | ..@@....,\ 1737 | .@@.....,\ 1738 | .@@.....,\ 1739 | .@@@@@@.,\ 1740 | ........,\ 1741 | ........,\ 1742 | ........,\ 1743 | ........,\ 1744 | ..@@@@..,\ 1745 | ..@@....,\ 1746 | ..@@....,\ 1747 | ..@@....,\ 1748 | ..@@....,\ 1749 | ..@@....,\ 1750 | ..@@....,\ 1751 | ..@@....,\ 1752 | ..@@....,\ 1753 | ..@@....,\ 1754 | ..@@....,\ 1755 | ..@@....,\ 1756 | ..@@@@..,\ 1757 | ........,\ 1758 | ........,\ 1759 | @@......,\ 1760 | @@......,\ 1761 | .@@.....,\ 1762 | .@@.....,\ 1763 | ..@@....,\ 1764 | ..@@....,\ 1765 | ...@@...,\ 1766 | ...@@...,\ 1767 | ....@@..,\ 1768 | ....@@..,\ 1769 | .....@@.,\ 1770 | .....@@.,\ 1771 | ......@@,\ 1772 | ......@@,\ 1773 | ........,\ 1774 | ........,\ 1775 | ........,\ 1776 | ..@@@@..,\ 1777 | ....@@..,\ 1778 | ....@@..,\ 1779 | ....@@..,\ 1780 | ....@@..,\ 1781 | ....@@..,\ 1782 | ....@@..,\ 1783 | ....@@..,\ 1784 | ....@@..,\ 1785 | ....@@..,\ 1786 | ....@@..,\ 1787 | ....@@..,\ 1788 | ..@@@@..,\ 1789 | ........,\ 1790 | ........,\ 1791 | ........,\ 1792 | ...@....,\ 1793 | ..@@@...,\ 1794 | .@@.@@..,\ 1795 | .@@.@@..,\ 1796 | @@...@@.,\ 1797 | @@...@@.,\ 1798 | ........,\ 1799 | ........,\ 1800 | ........,\ 1801 | ........,\ 1802 | ........,\ 1803 | ........,\ 1804 | ........,\ 1805 | ........,\ 1806 | ........,\ 1807 | ........,\ 1808 | ........,\ 1809 | ........,\ 1810 | ........,\ 1811 | ........,\ 1812 | ........,\ 1813 | ........,\ 1814 | ........,\ 1815 | ........,\ 1816 | ........,\ 1817 | ........,\ 1818 | ........,\ 1819 | ........,\ 1820 | ........,\ 1821 | ........,\ 1822 | @@@@@@@@,\ 1823 | ........,\ 1824 | ...@@...,\ 1825 | ...@@...,\ 1826 | ....@@..,\ 1827 | .....@@.,\ 1828 | ........,\ 1829 | ........,\ 1830 | ........,\ 1831 | ........,\ 1832 | ........,\ 1833 | ........,\ 1834 | ........,\ 1835 | ........,\ 1836 | ........,\ 1837 | ........,\ 1838 | ........,\ 1839 | ........,\ 1840 | ........,\ 1841 | ........,\ 1842 | ........,\ 1843 | ........,\ 1844 | ........,\ 1845 | ..@@@@..,\ 1846 | .....@@.,\ 1847 | ..@@@@@.,\ 1848 | .@@..@@.,\ 1849 | .@@..@@.,\ 1850 | .@@..@@.,\ 1851 | ..@@@@@.,\ 1852 | ........,\ 1853 | ........,\ 1854 | ........,\ 1855 | ........,\ 1856 | ........,\ 1857 | .@@.....,\ 1858 | .@@.....,\ 1859 | .@@.....,\ 1860 | .@@.....,\ 1861 | .@@@@@..,\ 1862 | .@@..@@.,\ 1863 | .@@..@@.,\ 1864 | .@@..@@.,\ 1865 | .@@..@@.,\ 1866 | .@@..@@.,\ 1867 | .@@@@@..,\ 1868 | ........,\ 1869 | ........,\ 1870 | ........,\ 1871 | ........,\ 1872 | ........,\ 1873 | ........,\ 1874 | ........,\ 1875 | ........,\ 1876 | ........,\ 1877 | ..@@@@..,\ 1878 | .@@..@@.,\ 1879 | .@@.....,\ 1880 | .@@.....,\ 1881 | .@@.....,\ 1882 | .@@..@@.,\ 1883 | ..@@@@..,\ 1884 | ........,\ 1885 | ........,\ 1886 | ........,\ 1887 | ........,\ 1888 | ........,\ 1889 | .....@@.,\ 1890 | .....@@.,\ 1891 | .....@@.,\ 1892 | .....@@.,\ 1893 | ..@@@@@.,\ 1894 | .@@..@@.,\ 1895 | .@@..@@.,\ 1896 | .@@..@@.,\ 1897 | .@@..@@.,\ 1898 | .@@..@@.,\ 1899 | ..@@@@@.,\ 1900 | ........,\ 1901 | ........,\ 1902 | ........,\ 1903 | ........,\ 1904 | ........,\ 1905 | ........,\ 1906 | ........,\ 1907 | ........,\ 1908 | ........,\ 1909 | ..@@@@..,\ 1910 | .@@..@@.,\ 1911 | .@@..@@.,\ 1912 | .@@@@@@.,\ 1913 | .@@.....,\ 1914 | .@@.....,\ 1915 | ..@@@@..,\ 1916 | ........,\ 1917 | ........,\ 1918 | ........,\ 1919 | ........,\ 1920 | ........,\ 1921 | ...@@@@.,\ 1922 | ..@@....,\ 1923 | ..@@....,\ 1924 | ..@@....,\ 1925 | .@@@@@@.,\ 1926 | ..@@....,\ 1927 | ..@@....,\ 1928 | ..@@....,\ 1929 | ..@@....,\ 1930 | ..@@....,\ 1931 | ..@@....,\ 1932 | ........,\ 1933 | ........,\ 1934 | ........,\ 1935 | ........,\ 1936 | ........,\ 1937 | ........,\ 1938 | ........,\ 1939 | ........,\ 1940 | ........,\ 1941 | ..@@@@@.,\ 1942 | .@@..@@.,\ 1943 | .@@..@@.,\ 1944 | .@@..@@.,\ 1945 | .@@..@@.,\ 1946 | .@@..@@.,\ 1947 | ..@@@@@.,\ 1948 | .....@@.,\ 1949 | .....@@.,\ 1950 | .@@@@@..,\ 1951 | ........,\ 1952 | ........,\ 1953 | .@@.....,\ 1954 | .@@.....,\ 1955 | .@@.....,\ 1956 | .@@.....,\ 1957 | .@@@@@..,\ 1958 | .@@..@@.,\ 1959 | .@@..@@.,\ 1960 | .@@..@@.,\ 1961 | .@@..@@.,\ 1962 | .@@..@@.,\ 1963 | .@@..@@.,\ 1964 | ........,\ 1965 | ........,\ 1966 | ........,\ 1967 | ........,\ 1968 | ........,\ 1969 | ...@@...,\ 1970 | ...@@...,\ 1971 | ........,\ 1972 | ........,\ 1973 | .@@@@...,\ 1974 | ...@@...,\ 1975 | ...@@...,\ 1976 | ...@@...,\ 1977 | ...@@...,\ 1978 | ...@@...,\ 1979 | ...@@@@.,\ 1980 | ........,\ 1981 | ........,\ 1982 | ........,\ 1983 | ........,\ 1984 | ........,\ 1985 | ....@@..,\ 1986 | ....@@..,\ 1987 | ........,\ 1988 | ........,\ 1989 | ....@@..,\ 1990 | ....@@..,\ 1991 | ....@@..,\ 1992 | ....@@..,\ 1993 | ....@@..,\ 1994 | ....@@..,\ 1995 | ....@@..,\ 1996 | ....@@..,\ 1997 | ....@@..,\ 1998 | .@@@@...,\ 1999 | ........,\ 2000 | ........,\ 2001 | .@@.....,\ 2002 | .@@.....,\ 2003 | .@@.....,\ 2004 | .@@.....,\ 2005 | .@@..@@.,\ 2006 | .@@..@@.,\ 2007 | .@@.@@..,\ 2008 | .@@@@...,\ 2009 | .@@.@@..,\ 2010 | .@@..@@.,\ 2011 | .@@..@@.,\ 2012 | ........,\ 2013 | ........,\ 2014 | ........,\ 2015 | ........,\ 2016 | ........,\ 2017 | .@@@@...,\ 2018 | ...@@...,\ 2019 | ...@@...,\ 2020 | ...@@...,\ 2021 | ...@@...,\ 2022 | ...@@...,\ 2023 | ...@@...,\ 2024 | ...@@...,\ 2025 | ...@@...,\ 2026 | ...@@...,\ 2027 | ...@@@@.,\ 2028 | ........,\ 2029 | ........,\ 2030 | ........,\ 2031 | ........,\ 2032 | ........,\ 2033 | ........,\ 2034 | ........,\ 2035 | ........,\ 2036 | ........,\ 2037 | @@..@@..,\ 2038 | @@@@@@@.,\ 2039 | @@.@.@@.,\ 2040 | @@.@.@@.,\ 2041 | @@.@.@@.,\ 2042 | @@.@.@@.,\ 2043 | @@...@@.,\ 2044 | ........,\ 2045 | ........,\ 2046 | ........,\ 2047 | ........,\ 2048 | ........,\ 2049 | ........,\ 2050 | ........,\ 2051 | ........,\ 2052 | ........,\ 2053 | .@@@@@..,\ 2054 | .@@..@@.,\ 2055 | .@@..@@.,\ 2056 | .@@..@@.,\ 2057 | .@@..@@.,\ 2058 | .@@..@@.,\ 2059 | .@@..@@.,\ 2060 | ........,\ 2061 | ........,\ 2062 | ........,\ 2063 | ........,\ 2064 | ........,\ 2065 | ........,\ 2066 | ........,\ 2067 | ........,\ 2068 | ........,\ 2069 | ..@@@@..,\ 2070 | .@@..@@.,\ 2071 | .@@..@@.,\ 2072 | .@@..@@.,\ 2073 | .@@..@@.,\ 2074 | .@@..@@.,\ 2075 | ..@@@@..,\ 2076 | ........,\ 2077 | ........,\ 2078 | ........,\ 2079 | ........,\ 2080 | ........,\ 2081 | ........,\ 2082 | ........,\ 2083 | ........,\ 2084 | ........,\ 2085 | .@@@@@..,\ 2086 | .@@..@@.,\ 2087 | .@@..@@.,\ 2088 | .@@..@@.,\ 2089 | .@@..@@.,\ 2090 | .@@..@@.,\ 2091 | .@@@@@..,\ 2092 | .@@.....,\ 2093 | .@@.....,\ 2094 | .@@.....,\ 2095 | ........,\ 2096 | ........,\ 2097 | ........,\ 2098 | ........,\ 2099 | ........,\ 2100 | ........,\ 2101 | ..@@@@@.,\ 2102 | .@@..@@.,\ 2103 | .@@..@@.,\ 2104 | .@@..@@.,\ 2105 | .@@..@@.,\ 2106 | .@@..@@.,\ 2107 | ..@@@@@.,\ 2108 | .....@@.,\ 2109 | .....@@.,\ 2110 | .....@@.,\ 2111 | ........,\ 2112 | ........,\ 2113 | ........,\ 2114 | ........,\ 2115 | ........,\ 2116 | ........,\ 2117 | .@@@@@..,\ 2118 | .@@..@@.,\ 2119 | .@@..@@.,\ 2120 | .@@.....,\ 2121 | .@@.....,\ 2122 | .@@.....,\ 2123 | .@@.....,\ 2124 | ........,\ 2125 | ........,\ 2126 | ........,\ 2127 | ........,\ 2128 | ........,\ 2129 | ........,\ 2130 | ........,\ 2131 | ........,\ 2132 | ........,\ 2133 | ..@@@@@.,\ 2134 | .@@.....,\ 2135 | .@@.....,\ 2136 | ..@@@@..,\ 2137 | .....@@.,\ 2138 | .....@@.,\ 2139 | .@@@@@..,\ 2140 | ........,\ 2141 | ........,\ 2142 | ........,\ 2143 | ........,\ 2144 | ........,\ 2145 | ........,\ 2146 | ..@@....,\ 2147 | ..@@....,\ 2148 | ..@@....,\ 2149 | .@@@@@@.,\ 2150 | ..@@....,\ 2151 | ..@@....,\ 2152 | ..@@....,\ 2153 | ..@@....,\ 2154 | ..@@....,\ 2155 | ...@@@@.,\ 2156 | ........,\ 2157 | ........,\ 2158 | ........,\ 2159 | ........,\ 2160 | ........,\ 2161 | ........,\ 2162 | ........,\ 2163 | ........,\ 2164 | ........,\ 2165 | .@@..@@.,\ 2166 | .@@..@@.,\ 2167 | .@@..@@.,\ 2168 | .@@..@@.,\ 2169 | .@@..@@.,\ 2170 | .@@..@@.,\ 2171 | ..@@@@@.,\ 2172 | ........,\ 2173 | ........,\ 2174 | ........,\ 2175 | ........,\ 2176 | ........,\ 2177 | ........,\ 2178 | ........,\ 2179 | ........,\ 2180 | ........,\ 2181 | .@@..@@.,\ 2182 | .@@..@@.,\ 2183 | .@@..@@.,\ 2184 | .@@..@@.,\ 2185 | .@@..@@.,\ 2186 | ..@@@@..,\ 2187 | ...@@...,\ 2188 | ........,\ 2189 | ........,\ 2190 | ........,\ 2191 | ........,\ 2192 | ........,\ 2193 | ........,\ 2194 | ........,\ 2195 | ........,\ 2196 | ........,\ 2197 | @@...@@.,\ 2198 | @@...@@.,\ 2199 | @@.@.@@.,\ 2200 | @@.@.@@.,\ 2201 | @@.@.@@.,\ 2202 | .@@@@@..,\ 2203 | .@@.@@..,\ 2204 | ........,\ 2205 | ........,\ 2206 | ........,\ 2207 | ........,\ 2208 | ........,\ 2209 | ........,\ 2210 | ........,\ 2211 | ........,\ 2212 | ........,\ 2213 | @@...@@.,\ 2214 | @@...@@.,\ 2215 | .@@.@@..,\ 2216 | ..@@@...,\ 2217 | .@@.@@..,\ 2218 | @@...@@.,\ 2219 | @@...@@.,\ 2220 | ........,\ 2221 | ........,\ 2222 | ........,\ 2223 | ........,\ 2224 | ........,\ 2225 | ........,\ 2226 | ........,\ 2227 | ........,\ 2228 | ........,\ 2229 | .@@..@@.,\ 2230 | .@@..@@.,\ 2231 | .@@..@@.,\ 2232 | .@@..@@.,\ 2233 | .@@..@@.,\ 2234 | .@@..@@.,\ 2235 | ..@@@@@.,\ 2236 | .....@@.,\ 2237 | .....@@.,\ 2238 | ..@@@@..,\ 2239 | ........,\ 2240 | ........,\ 2241 | ........,\ 2242 | ........,\ 2243 | ........,\ 2244 | ........,\ 2245 | .@@@@@@.,\ 2246 | .....@@.,\ 2247 | ....@@..,\ 2248 | ...@@...,\ 2249 | ..@@....,\ 2250 | .@@.....,\ 2251 | .@@@@@@.,\ 2252 | ........,\ 2253 | ........,\ 2254 | ........,\ 2255 | ........,\ 2256 | ....@@@.,\ 2257 | ...@@...,\ 2258 | ...@@...,\ 2259 | ...@@...,\ 2260 | ...@@...,\ 2261 | ...@@...,\ 2262 | @@@@....,\ 2263 | ...@@...,\ 2264 | ...@@...,\ 2265 | ...@@...,\ 2266 | ...@@...,\ 2267 | ...@@...,\ 2268 | ....@@@.,\ 2269 | ........,\ 2270 | ........,\ 2271 | ...@@...,\ 2272 | ...@@...,\ 2273 | ...@@...,\ 2274 | ...@@...,\ 2275 | ...@@...,\ 2276 | ...@@...,\ 2277 | ...@@...,\ 2278 | ...@@...,\ 2279 | ...@@...,\ 2280 | ...@@...,\ 2281 | ...@@...,\ 2282 | ...@@...,\ 2283 | ...@@...,\ 2284 | ...@@...,\ 2285 | ........,\ 2286 | ........,\ 2287 | ........,\ 2288 | @@@.....,\ 2289 | ..@@....,\ 2290 | ..@@....,\ 2291 | ..@@....,\ 2292 | ..@@....,\ 2293 | ..@@....,\ 2294 | ...@@@@.,\ 2295 | ..@@....,\ 2296 | ..@@....,\ 2297 | ..@@....,\ 2298 | ..@@....,\ 2299 | ..@@....,\ 2300 | @@@.....,\ 2301 | ........,\ 2302 | ........,\ 2303 | ........,\ 2304 | .@@@..@.,\ 2305 | @@.@.@@.,\ 2306 | @..@@@..,\ 2307 | ........,\ 2308 | ........,\ 2309 | ........,\ 2310 | ........,\ 2311 | ........,\ 2312 | ........,\ 2313 | ........,\ 2314 | ........,\ 2315 | ........,\ 2316 | ........,\ 2317 | ........,\ 2318 | ........ 2319 | -------------------------------------------------------------------------------- /grub.cfg: -------------------------------------------------------------------------------- 1 | 2 | menuentry "achiu-au - OS" { 3 | multiboot /boot/kfs_5 4 | } 5 | -------------------------------------------------------------------------------- /help.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _help 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _help_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _help_invalid 12 | mov edx, _help_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _help_exit 16 | _help_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_WRITE 19 | mov ebx, _TELETYPE_CURRENT 20 | mov ecx, _help_command 21 | mov edx, _help_command.sizeof 22 | int 030H 23 | xor ebx, ebx 24 | _help_exit: 25 | xor eax, eax 26 | mov al, _SYSCALL_EXIT 27 | int 030H 28 | _help_command string\ 29 | "achiu-au, KFS version 1.0.5", 00AH,\ 30 | "To switch TTY enter CTRL+Fn or left/right window", 00AH,\ 31 | "help - display help", 00AH,\ 32 | "copyright - show the copyright", 00AH,\ 33 | "clear - clear the current screen and the history", 00AH,\ 34 | "fg/bg c - change foreground/background to c", 00AH,\ 35 | " * [black,blue,green,cyan,red,magenta,brown,light]", 00AH,\ 36 | "copy ""str"" - copy the string to the clipboard", 00AH,\ 37 | " * to include "" in string, double it", 00AH,\ 38 | "usertest - test new stuff (segfault, undefined opcode ...)", 00AH,\ 39 | "invopcode - show if signal invalid opcode works", 00AH,\ 40 | "segvtest - experiment a segmentation fault", 00AH,\ 41 | "bomb - test fork bomb", 00AH,\ 42 | "sigint - use sigint to quit the program", 00AH,\ 43 | "showpid - show parent and process pid", 00AH,\ 44 | "sockpoc - test the server - client idiom", 00AH,\ 45 | "sqrt - simple routine to test if sse is present", 00AH,\ 46 | "md5 hash - hash input string to md5", 00AH,\ 47 | "kill signal pid - send the signal to the process", 00AH,\ 48 | "uid - show the current uid", 00AH,\ 49 | "uname - show the version of the OS", 00AH,\ 50 | "hostname - show the hostname", 00AH,\ 51 | "history on/off - enable/disable history", 00AH,\ 52 | "print str - print in loop a string", 00AH,\ 53 | "resolution x y - try to change to resolution with the given value", 00AH,\ 54 | "reboot - reboot the machine", 00AH,\ 55 | "shutdown - shutdown the machine", 00AH,\ 56 | "exit - exit the shell", 00AH 57 | _help_invalid string "help invalid usage", 00AH 58 | end _user_code 59 | 60 | -------------------------------------------------------------------------------- /hostname.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _hostname 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _hostname_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _hostname_invalid 12 | mov edx, _hostname_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _hostname_start_exit 16 | _hostname_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_WRITE 19 | mov ebx, _TELETYPE_CURRENT 20 | mov ecx, _hostname_value 21 | mov edx, _hostname_value.sizeof 22 | int 030H 23 | xor ebx, ebx 24 | _hostname_start_exit: 25 | xor eax, eax 26 | mov al, _SYSCALL_EXIT 27 | int 030H 28 | _hostname_value string "CP/M2 Workstation", 00AH 29 | _hostname_invalid string "hostname invalid usage", 00AH 30 | end _user_code 31 | -------------------------------------------------------------------------------- /init.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _init 3 | match,DEBUG 4 | { 5 | xor eax, eax 6 | mov al, _SYSCALL_SHA1 7 | int 030H 8 | 9 | ;xor eax, eax 10 | ;mov al, _SYSCALL_AESENC_ECB 11 | ;lea ebx, [esp-010H] 12 | ;mov dword [ebx], "HELO" 13 | ;mov ebx, _aes_test 14 | ;mov ecx, 010H 15 | ;mov edx, _aes_key 16 | ;int 030H 17 | 18 | jmp $ 19 | 20 | _aes_test: 21 | db 032H, 088H, 031H, 0E0H 22 | db 043H, 05AH, 031H, 037H 23 | db 0F6H, 030H, 098H, 007H 24 | db 0A8H, 08DH, 0A2H, 034H 25 | 26 | _aes_key: 27 | db 02BH, 028H, 0ABH, 009H 28 | db 07EH, 0AEH, 0F7H, 0CFH 29 | db 015H, 0D2H, 015H, 04FH 30 | db 016H, 0A6H, 088H, 03CH 31 | } 32 | xor eax, eax 33 | mov al, _SYSCALL_FORK 34 | int 030H 35 | test eax, eax 36 | jnz _init_parent 37 | xor ecx, ecx 38 | mov cl, _TELETYPE_COUNT 39 | _init_parent_teletype: 40 | mov eax, _SYSCALL_FORK 41 | int 030H 42 | test eax, eax 43 | jnz _init_parent_loop 44 | lea esi, [ecx-_TELETYPE_COUNT] 45 | neg esi 46 | mov eax, _SYSCALL_SSID 47 | int 030H 48 | mov dword [esp-4H], eax 49 | mov eax, _SYSCALL_IOCTL 50 | mov ebx, esi 51 | mov ecx, TIOCSCTTY 52 | xor edx, edx 53 | int 030H 54 | xor eax, eax 55 | mov al, _SYSCALL_IOCTL 56 | mov ebx, esi 57 | mov ecx, TIOCSPGRP 58 | lea edx, [esp-4H] 59 | int 030H 60 | mov eax, _SYSCALL_EXEC 61 | mov ebx, _login_payload 62 | mov ecx, _login.sizeof 63 | int 030H 64 | _init_parent_loop: 65 | loop _init_parent_teletype 66 | xor eax, eax 67 | mov al, _SYSCALL_EXIT 68 | xor ebx, ebx 69 | int 030H 70 | _init_parent: 71 | xor eax, eax 72 | mov al, _SYSCALL_WAITPID 73 | mov ebx, _WAIT_ALL 74 | xor ecx, ecx 75 | xor edx, edx 76 | mov dl, (WEXITED or WNOHANG) 77 | int 030H 78 | jmp _init_parent 79 | _extract _login 80 | end _user_code 81 | 82 | -------------------------------------------------------------------------------- /invopcode.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _invopcode 3 | ud2 4 | xor eax, eax 5 | mov al, _SYSCALL_EXIT 6 | xor ebx, ebx 7 | int 030H 8 | end _user_code 9 | 10 | -------------------------------------------------------------------------------- /kbd.inc: -------------------------------------------------------------------------------- 1 | 2 | _KEYBOARD_CONTROL = 064H 3 | _KEYBOARD_ENCODER = 060H 4 | _KEYBOARD_CONTROL_STATUS_OUT = 1B 5 | _KEYBOARD_CONTROL_STATUS_IN = 010B 6 | _KEYBOARD_CONTROL_READ_COMMAND = 020H 7 | _KEYBOARD_CONTROL_ENABLE_KEYBOARD = 0AEH 8 | _KEYBOARD_ENCODER_SET_LED = 0EDH 9 | _KEYBOARD_ENCODER_SET_SCAN_CODE = 0F0H 10 | _KEYBOARD_ENCODER_ENABLE_KEYBOARD = 0F4H 11 | _XT_SCAN_CODE = 2H 12 | _XT_BREAK_CODE = 080H 13 | _EXTENDED_1_CODE = 0E0H 14 | _EXTENDED_2_CODE = 0E1H 15 | _ESCAPE = 01BH 16 | 17 | enum _KEY_NULL, _KEY_ESC, _KEY_1, _KEY_2, _KEY_3, _KEY_4, _KEY_5, _KEY_6, _KEY_7, _KEY_8, _KEY_9, _KEY_0,\ 18 | _KEY_MINUS, _KEY_EQUAL, _KEY_BACKSPACE, _KEY_TAB, _KEY_Q, _KEY_W, _KEY_E, _KEY_R, _KEY_T, _KEY_Y,\ 19 | _KEY_U, _KEY_I, _KEY_O, _KEY_P, _KEY_LEFT_BRACK, _KEY_RIGHT_BRACK, _KEY_ENTER, _KEY_KEYPAD_ENTER:&,\ 20 | _KEY_LEFT_CTRL, _KEY_RIGHT_CTRL:&, _KEY_PAUSE_1:&, _KEY_A, _KEY_S, _KEY_D, _KEY_F, _KEY_G, _KEY_H, _KEY_J,\ 21 | _KEY_K, _KEY_L, _KEY_SEMICOLON, _KEY_QUOTE, _KEY_BACK_TICK, _KEY_LEFT_SHIFT, _KEY_PRINT_SCREEN_1:&, _KEY_BACKSLASH,\ 22 | _KEY_Z, _KEY_X, _KEY_C, _KEY_V, _KEY_B, _KEY_N, _KEY_M, _KEY_COMMA, _KEY_DOT, _KEY_SLASH, _KEY_KEYPAD_SLASH:&,\ 23 | _KEY_RIGHT_SHIFT, _KEY_KEYPAD_STAR, _KEY_PRINT_SCREEN_2:&, _KEY_LEFT_ALT, _KEY_RIGHT_ALT:&, _KEY_SPACE,\ 24 | _KEY_CAPS_LOCK, _KEY_F1, _KEY_F2, _KEY_F3, _KEY_F4, _KEY_F5, _KEY_F6, _KEY_F7, _KEY_F8, _KEY_F9, _KEY_F10,\ 25 | _KEY_KEYPAD_NUM_LOCK, _KEY_PAUSE_2:&, _KEY_SCROLL_LOCK, _KEY_HOME, _KEY_KEYPAD_7:&, _KEY_UP_ARROW, _KEY_KEYPAD_8:&,\ 26 | _KEY_PAGE_UP, _KEY_KEYPAD_9:&, _KEY_KEYPAD_MINUS, _KEY_LEFT_ARROW, _KEY_KEYPAD_4:&, _KEY_KEYPAD_5, _KEY_RIGHT_ARROW,\ 27 | _KEY_KEYPAD_6:&, _KEY_KEYPAD_PLUS, _KEY_END, _KEY_KEYPAD_1:&, _KEY_DOWN_ARROW, _KEY_KEYPAD_2:&, _KEY_PAGE_DOWN,\ 28 | _KEY_KEYPAD_3:&, _KEY_INSERT, _KEY_KEYPAD_0:&, _KEY_DELETE, _KEY_KEYPAD_DOT:&, _KEY_F11:057H, _KEY_F12,\ 29 | _KEY_LEFT_GUI:05BH, _KEY_RIGHT_GUI, _KEY_APPS, _KEY_PRINT_SCREEN, _KEY_PAUSE 30 | 31 | enum _ESC_ESC:080H, _ESC_LEFT_ARROW, _ESC_RIGHT_ARROW, _ESC_UP_ARROW, _ESC_DOWN_ARROW, _ESC_F1, _ESC_F2,\ 32 | _ESC_F3, _ESC_F4, _ESC_F5, _ESC_F6, _ESC_F7, _ESC_F8, _ESC_F9, _ESC_F10, _ESC_F11, _ESC_F12,\ 33 | _ESC_PAGE_UP, _ESC_PAGE_DOWN, _ESC_HOME, _ESC_END, _ESC_INSERT, _ESC_DELETE 34 | 35 | _keyboard_control_wait_output_full: 36 | in al, _KEYBOARD_CONTROL 37 | test al, _KEYBOARD_CONTROL_STATUS_OUT 38 | jz _keyboard_control_wait_output_full 39 | ret 40 | 41 | _keyboard_control_wait_input_empty: 42 | in al, _KEYBOARD_CONTROL 43 | test al, _KEYBOARD_CONTROL_STATUS_IN 44 | jnz _keyboard_control_wait_input_empty 45 | ret 46 | 47 | enum & _KEY_MAKE_CODE, _KEY_NOTIFY 48 | _keyboard_driver: 49 | ; out: 50 | ; eax - ascii character in al and scan code in ah (except for _ESCAPE) 51 | ; cf - set if the key pressed was not a notifiable key 52 | ; note: al = _KEY_NULL when no "printable" character has been entered 53 | ; preserves: esi, edi, ebp 54 | call _keyboard_control_wait_output_full 55 | xor eax, eax 56 | xor ecx, ecx 57 | in al, _KEYBOARD_ENCODER 58 | xchg al, ah 59 | mov dl, _KEY_MAKE_CODE 60 | cmp ah, _EXTENDED_1_CODE 61 | jz _keyboard_driver_extended 62 | cmp ah, _EXTENDED_2_CODE 63 | jz _keyboard_driver_extended 64 | test ah, _XT_BREAK_CODE 65 | jz _keyboard_driver_extended_action 66 | xor dl, dl 67 | xor ah, _XT_BREAK_CODE 68 | _keyboard_driver_extended_action: 69 | mov bl, byte [_current_keyboard.extended] 70 | test dl, _KEY_MAKE_CODE 71 | jnz _keyboard_driver_extended_perform 72 | mov byte [_current_keyboard.extended], _KEY_NULL 73 | _keyboard_driver_extended_perform: 74 | cmp bl, _EXTENDED_1_CODE 75 | jz _keyboard_driver_handle_extended_1 76 | cmp bl, _EXTENDED_2_CODE 77 | jz _keyboard_driver_handle_extended_2 78 | jmp _keyboard_driver_make_code 79 | _keyboard_driver_extended: 80 | mov byte [_current_keyboard.extended], ah 81 | jmp _keyboard_driver_exit 82 | _keyboard_driver_handle_extended_1: 83 | cmp ah, _KEY_RIGHT_CTRL 84 | mov ebx, _current_keyboard.right_ctrl 85 | jz _keyboard_driver_insert_state 86 | cmp ah, _KEY_RIGHT_ALT 87 | mov ebx, _current_keyboard.right_alt 88 | jz _keyboard_driver_insert_state 89 | test dl, dl 90 | jz _keyboard_driver_exit 91 | cmp ah, _KEY_PRINT_SCREEN_1 92 | jz _keyboard_driver_exit 93 | or dl, _KEY_NOTIFY 94 | cmp ah, _KEY_PRINT_SCREEN_2 95 | jnz _keyboard_driver_handle_extended_1_numlock 96 | mov ah, _KEY_PRINT_SCREEN 97 | jmp _keyboard_driver_exit 98 | _keyboard_driver_handle_extended_1_numlock: 99 | cmp ah, _KEY_KEYPAD_SLASH 100 | jz _keyboard_driver_only_numlock 101 | cmp ah, _KEY_KEYPAD_ENTER 102 | jz _keyboard_driver_only_numlock 103 | mov cl, _ESCAPE 104 | irp _kind*, LEFT_ARROW,RIGHT_ARROW,UP_ARROW,DOWN_ARROW,INSERT,HOME,END,PAGE_UP,PAGE_DOWN 105 | { 106 | cmp ah, _KEY_#_kind 107 | mov ch, _ESC_#_kind 108 | cmovz eax, ecx 109 | if (((_KEY_#_kind) = _KEY_LEFT_ARROW) | ((_KEY_#_kind) = _KEY_RIGHT_ARROW) |\ 110 | ((_KEY_#_kind) = _KEY_UP_ARROW) | ((_KEY_#_kind) = _KEY_DOWN_ARROW)) 111 | jz _keyboard_driver_handle_extended_1_arrow 112 | else 113 | jz _keyboard_driver_exit 114 | end if 115 | } 116 | xor al, al 117 | jmp _keyboard_driver_exit 118 | _keyboard_driver_handle_extended_1_arrow: 119 | call _keyboard_driver_scroll_activated 120 | jc _keyboard_driver_exit 121 | irp _kind*, LEFT_ARROW,RIGHT_ARROW,UP_ARROW,DOWN_ARROW 122 | { 123 | cmp ah, _ESC_#_kind 124 | match =LEFT_ARROW, _kind \{ mov ch, _ESC_HOME \} 125 | match =RIGHT_ARROW, _kind \{ mov ch, _ESC_END \} 126 | match =UP_ARROW, _kind \{ mov ch, _ESC_PAGE_UP \} 127 | match =DOWN_ARROW, _kind \{ mov ch, _ESC_PAGE_DOWN \} 128 | cmovz eax, ecx 129 | jz _keyboard_driver_exit 130 | } 131 | _keyboard_driver_handle_extended_2: 132 | cmp ah, _KEY_PAUSE_2 133 | jnz _keyboard_driver_exit 134 | or dl, _KEY_NOTIFY 135 | mov ah, _KEY_PAUSE 136 | jmp _keyboard_driver_exit 137 | _keyboard_driver_make_code: 138 | cmp ah, _KEY_LEFT_CTRL 139 | mov ebx, _current_keyboard.left_ctrl 140 | jz _keyboard_driver_insert_state 141 | cmp ah, _KEY_LEFT_SHIFT 142 | mov ebx, _current_keyboard.left_shift 143 | jz _keyboard_driver_insert_state 144 | cmp ah, _KEY_RIGHT_SHIFT 145 | mov ebx, _current_keyboard.right_shift 146 | jz _keyboard_driver_insert_state 147 | cmp ah, _KEY_LEFT_ALT 148 | mov ebx, _current_keyboard.left_alt 149 | jz _keyboard_driver_insert_state 150 | test dl, dl 151 | jz _keyboard_driver_exit 152 | cmp ah, _KEY_CAPS_LOCK 153 | mov ebx, _current_keyboard.caps_lock 154 | jz _keyboard_driver_invert_state 155 | cmp ah, _KEY_KEYPAD_NUM_LOCK 156 | mov ebx, _current_keyboard.num_lock 157 | jz _keyboard_driver_invert_state 158 | cmp ah, _KEY_SCROLL_LOCK 159 | mov ebx, _current_keyboard.scroll_lock 160 | jz _keyboard_driver_invert_state 161 | or dl, _KEY_NOTIFY 162 | mov cl, _ESCAPE 163 | irp _kind*, ESC,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12 164 | { 165 | cmp ah, _KEY_#_kind 166 | mov ch, _ESC_#_kind 167 | cmovz eax, ecx 168 | jz _keyboard_driver_exit 169 | } 170 | _keyboard_driver_keypad: 171 | irp _kind*, 0,1,2,3,4,5,6,7,8,9,DOT,MINUS,PLUS,STAR 172 | { 173 | cmp ah, _KEY_KEYPAD_#_kind 174 | jz _keyboard_driver_only_numlock 175 | } 176 | jmp _keyboard_driver_translate 177 | _keyboard_driver_only_numlock: 178 | call _keyboard_driver_num_activated 179 | jnc _keyboard_driver_translate 180 | xor dl, _KEY_NOTIFY 181 | jmp _keyboard_driver_exit 182 | _keyboard_driver_translate: 183 | mov ebx, _keyboard_translation_table 184 | mov al, ah 185 | xlatb 186 | call _keyboard_driver_shift_pressed 187 | jc _keyboard_driver_case_update 188 | mov ch, ah 189 | irp _kind*, 060H,031H,032H,033H,034H,035H,036H,037H,038H,039H,030H,02DH,03DH,05BH,05DH,05CH,03BH,027H,02CH,02EH,02FH 190 | { 191 | cmp al, _kind 192 | match =060H, _kind \{ mov cl, 07EH \} 193 | match =031H, _kind \{ mov cl, 021H \} 194 | match =032H, _kind \{ mov cl, 040H \} 195 | match =033H, _kind \{ mov cl, 023H \} 196 | match =034H, _kind \{ mov cl, 024H \} 197 | match =035H, _kind \{ mov cl, 025H \} 198 | match =036H, _kind \{ mov cl, 05EH \} 199 | match =037H, _kind \{ mov cl, 026H \} 200 | match =038H, _kind \{ mov cl, 02AH \} 201 | match =039H, _kind \{ mov cl, 028H \} 202 | match =030H, _kind \{ mov cl, 029H \} 203 | match =02DH, _kind \{ mov cl, 05FH \} 204 | match =03DH, _kind \{ mov cl, 02BH \} 205 | match =05BH, _kind \{ mov cl, 07BH \} 206 | match =05DH, _kind \{ mov cl, 07DH \} 207 | match =05CH, _kind \{ mov cl, 07CH \} 208 | match =03BH, _kind \{ mov cl, 03AH \} 209 | match =027H, _kind \{ mov cl, 022H \} 210 | match =02CH, _kind \{ mov cl, 03CH \} 211 | match =02EH, _kind \{ mov cl, 03EH \} 212 | match =02FH, _kind \{ mov cl, 03FH \} 213 | cmovz eax, ecx 214 | jz _keyboard_driver_transform 215 | } 216 | jmp _keyboard_driver_case_convert 217 | _keyboard_driver_case_update: 218 | call _keyboard_driver_caps_activated 219 | jc _keyboard_driver_transform 220 | _keyboard_driver_case_convert: 221 | cmp al, 061H 222 | jc _keyboard_driver_transform 223 | cmp al, 07AH 224 | ja _keyboard_driver_transform 225 | and al, (not 020H) 226 | _keyboard_driver_transform: 227 | call _keyboard_driver_ctrl_pressed 228 | jc _keyboard_driver_exit 229 | call _keyboard_driver_control_character 230 | _keyboard_driver_exit: 231 | test dl, _KEY_NOTIFY 232 | jmp _convert_zero_carry 233 | 234 | _keyboard_driver_insert_state: 235 | ; in: 236 | ; ebx - state in keyboard to change 237 | ; dl - make code or break code 238 | mov byte [ebx], dl 239 | and byte [ebx], (not _KEY_NOTIFY) 240 | jmp _keyboard_driver_exit 241 | _keyboard_driver_invert_state: 242 | ; in: ebx - state in keyboard to change 243 | ; note: must be called to invert the state of a lock key 244 | xor byte [ebx], _KEY_MAKE_CODE 245 | call _keyboard_driver_update_led 246 | jmp _keyboard_driver_exit 247 | 248 | _keyboard_driver_control_character: 249 | cmp al, 041H 250 | jc _keyboard_driver_control_character_reset 251 | cmp al, 05AH 252 | ja _keyboard_driver_control_character_upper 253 | sub al, 040H 254 | jmp _keyboard_driver_control_character_exit 255 | _keyboard_driver_control_character_upper: 256 | cmp al, 061H 257 | jc _keyboard_driver_control_character_reset 258 | cmp al, 07AH 259 | ja _keyboard_driver_control_character_reset 260 | sub al, 060H 261 | jmp _keyboard_driver_control_character_exit 262 | _keyboard_driver_control_character_reset: 263 | xor al, al 264 | _keyboard_driver_control_character_exit: 265 | ret 266 | 267 | _keyboard_driver_update_led: 268 | push eax edx 269 | call _keyboard_driver_scroll_activated 270 | setnc al 271 | call _keyboard_driver_num_activated 272 | setnc cl 273 | shl cl, 1H 274 | call _keyboard_driver_caps_activated 275 | setnc dl 276 | shl dl, 2H 277 | or dl, cl 278 | or dl, al 279 | call _keyboard_control_wait_input_empty 280 | mov al, _KEYBOARD_ENCODER_SET_LED 281 | out _KEYBOARD_ENCODER, al 282 | call _keyboard_control_wait_input_empty 283 | mov al, dl 284 | out _KEYBOARD_ENCODER, al 285 | pop edx eax 286 | ret 287 | 288 | irp _kind*, ctrl,shift,alt 289 | { 290 | _keyboard_driver_#_kind#_pressed: 291 | ; out: cf - set if it's not pressed 292 | test byte [_current_keyboard.left_#_kind], _KEY_MAKE_CODE 293 | jnz _convert_zero_carry 294 | test byte [_current_keyboard.right_#_kind], _KEY_MAKE_CODE 295 | jmp _convert_zero_carry 296 | } 297 | 298 | irp _kind*, scroll,num,caps 299 | { 300 | _keyboard_driver_#_kind#_activated: 301 | ; out: cf - set if it's not pressed 302 | test byte [_current_keyboard.#_kind#_lock], _KEY_MAKE_CODE 303 | jmp _convert_zero_carry 304 | } 305 | 306 | _keyboard_translation_table: 307 | db 000H, 01BH, 031H, 032H 308 | db 033H, 034H, 035H, 036H 309 | db 037H, 038H, 039H, 030H 310 | db 02DH, 03DH, 07FH, 009H 311 | db 071H, 077H, 065H, 072H 312 | db 074H, 079H, 075H, 069H 313 | db 06FH, 070H, 05BH, 05DH 314 | db 00DH, 000H, 061H, 073H 315 | db 064H, 066H, 067H, 068H 316 | db 06AH, 06BH, 06CH, 03BH 317 | db 027H, 060H, 000H, 05CH 318 | db 07AH, 078H, 063H, 076H 319 | db 062H, 06EH, 06DH, 02CH 320 | db 02EH, 02FH, 000H, 02AH 321 | db 000H, 020H, 000H, 01BH 322 | db 01BH, 01BH, 01BH, 01BH 323 | db 01BH, 01BH, 01BH, 01BH 324 | db 01BH, 000H, 000H, 037H 325 | db 038H, 039H, 02DH, 034H 326 | db 035H, 036H, 02BH, 031H 327 | db 032H, 033H, 030H, 02EH 328 | times (0FFH - ($ - _keyboard_translation_table)) db 0H 329 | 330 | -------------------------------------------------------------------------------- /kfs_5.asm: -------------------------------------------------------------------------------- 1 | 2 | _KERNEL_START = 0A00000H 3 | assert (~(_KERNEL_START and _PAGE_OFFSET_MASK)) 4 | 5 | format ELF executable 3H at _KERNEL_START 6 | entry _kernel_etablish 7 | use32 8 | 9 | _kernel_start: 10 | 11 | include "system.inc" 12 | 13 | _GRUB1_MAGIC = 01BADB002H 14 | _GRUB2_MAGIC = 0E85250D6H 15 | _GRUB1_FLAGS = 0H 16 | _GRUB1_MULTIBOOT = 02BADB002H 17 | _GRUB2_MULTIBOOT = 036D76289H 18 | _GRUB2_ARCHITECTURE = 0H 19 | macro __grub_multiboot _version* 20 | { 21 | local _current, _checksum 22 | assert (((_version) = 1H) | ((_version) = 2H)) 23 | segment executable writable readable 24 | align 8H 25 | _grub_header_start: 26 | dd _GRUB#_version#_MAGIC 27 | _checksum = _GRUB#_version#_MAGIC 28 | if ((_version) = 1H) 29 | dd _GRUB1_FLAGS 30 | _checksum = ((_checksum) + _GRUB#_version#_FLAGS) 31 | else 32 | dd _GRUB2_ARCHITECTURE 33 | dd (_grub_header_end - _grub_header_start) 34 | _checksum = ((_checksum) + _GRUB2_ARCHITECTURE + (_grub_header_end - _grub_header_start)) 35 | end if 36 | dd (-(_checksum)) 37 | if ((_version) = 2H) 38 | dw 0H 39 | dw 0H 40 | dd 8H 41 | end if 42 | _grub_header_end: 43 | } 44 | 45 | _MULTIBOOT_MEM = (1H shl 0H) 46 | _MULTIBOOT_DEV = (1H shl 1H) 47 | _MULTIBOOT_CMD = (1H shl 2H) 48 | struct _multiboot_info _flags*, _mem_lower*, _mem_upper*, _boot_devices*, _cmdline*, _mods_count*, _mods_addr* 49 | .flags: dd 0H 50 | .mem_lower: dd (_mem_lower) 51 | .mem_upper: dd (_mem_upper) 52 | .boot_devices: dd (_boot_devices) 53 | .cmdline: dd (_cmdline) 54 | .mods_count: dd (_mods_count) 55 | .mods_addr: dd (_mods_addr) 56 | ends 57 | 58 | __grub_multiboot 1 59 | 60 | _VESA_SIGNATURE = "VESA" 61 | _VBE2_SIGNATURE = "VBE2" 62 | struct _vbe_info_block _signature*, _version*, _oem_string*, _capabilities*, _video_mode*, _total_memory*, _oem_software*, _oem_vendor*, _oem_product*, _oem_revision* 63 | .signature: dd (_signature) 64 | .version: dw (_version) 65 | .oem_string: dd (_oem_string) 66 | .capabilities: dd (_capabilities) 67 | .video_mode: dd (_video_mode) 68 | .total_memory: dw (_total_memory) 69 | .oem_software: dw (_oem_revision) 70 | .oem_vendor: dd (_oem_vendor) 71 | .oem_product: dd (_oem_product) 72 | .oem_revision: dd (_oem_revision) 73 | .reserved: db 0DEH dup 0H 74 | .oem_data: db 100H dup 0H 75 | ends 76 | 77 | _VBE_ATTRIBUTE_SUPPORT = (1H shl 0H) 78 | _VBE_ATTRIBUTE_RESERVED = (1H shl 1H) 79 | _VBE_ATTRIBUTE_TTY_OUTPUT = (1H shl 2H) 80 | _VBE_ATTRIBUTE_COLOR = (1H shl 3H) 81 | _VBE_ATTRIBUTE_GRAPHICS = (1H shl 4H) 82 | _VBE_ATTRIBUTE_LINEAR = (1H shl 7H) 83 | 84 | _VBE_MEMORY_MODEL_TEXT = 0H 85 | _VBE_MEMORY_MODEL_CGA = 1H 86 | _VBE_MEMORY_MODEL_HERCULES = 2H 87 | _VBE_MEMORY_MODEL_PLANAR = 3H 88 | _VBE_MEMORY_MODEL_PACKED = 4H 89 | _VBE_MEMORY_MODEL_NON_CHAIN = 5H 90 | _VBE_MEMORY_MODEL_DIRECT = 6H 91 | _VBE_MEMORY_MODEL_YUV = 7H 92 | 93 | _VBE_ENABLE_FRAMEBUFFER = (1H shl 00EH) 94 | 95 | struct _mode_info_block _mode_attributes*, _wina_attributes*, _winb_attributes*, _win_granularity*, _win_size*, _wina_segment*, _winb_segment*,\ 96 | _win_function*, _bytes_scanline*, _x_resolution*, _y_resolution*, _x_char_size*, _y_char_size*, _number_planes*, _bits_pixel*, _number_blanks*,\ 97 | _memory_model*, _bank_size*, _number_pages*, _red_size*, _red_position*, _green_size*, _green_position*, _blue_size*, _blue_position*,\ 98 | _rsvd_size*, _rsvd_position, _direct_info*, _physical*, _lin_bytes_scanline*, _bank_number_pages*, _lin_number_pages*,\ 99 | _lin_red_size*, _lin_red_position*, _lin_green_size*, _lin_green_position*, _lin_blue_size*, _lin_blue_position*,\ 100 | _lin_rsvd_size*, _lin_rsvd_position*, _max_pixel_clock* 101 | .mode_attributes: dw (_mode_attributes) 102 | .wina_attributes: db (_wina_attributes) 103 | .winb_attributes: db (_winb_attributes) 104 | .win_granularity: dw (_win_granularity) 105 | .win_size: dw (_win_size) 106 | .wina_segment: dw (_wina_segment) 107 | .winb_segment: dw (_winb_segment) 108 | .win_function: dd (_win_function) 109 | .bytes_scanline: dw (_bytes_scanline) 110 | .x_resolution: dw (_x_resolution) 111 | .y_resolution: dw (_y_resolution) 112 | .x_char_size: db (_x_char_size) 113 | .y_char_size: db (_y_char_size) 114 | .number_planes: db (_number_planes) 115 | .bits_pixel: db (_bits_pixel) 116 | .number_blanks: db (_number_blanks) 117 | .memory_model: db (_memory_model) 118 | .bank_size: db (_bank_size) 119 | .number_pages: db (_number_pages) 120 | .reserved_0: db 0H 121 | .red_size: db (_red_size) 122 | .red_position: db (_red_position) 123 | .green_size: db (_green_size) 124 | .green_position: db (_green_position) 125 | .blue_size: db (_blue_size) 126 | .blue_position: db (_blue_position) 127 | .rsvd_size: db (_rsvd_size) 128 | .rsvd_position: db (_rsvd_position) 129 | .direct_info: db (_direct_info) 130 | .physical: dd (_physical) 131 | .reserved_1: dd 0H 132 | .reserved_2: dw 0H 133 | .lin_bytes_scanline:dw (_lin_bytes_scanline) 134 | .bank_number_pages: db (_bank_number_pages) 135 | .lin_number_pages: db (_lin_number_pages) 136 | .lin_red_size: db (_lin_red_size) 137 | .lin_red_position: db (_lin_red_position) 138 | .lin_green_size: db (_lin_green_size) 139 | .lin_green_position:db (_lin_green_position) 140 | .lin_blue_size: db (_lin_blue_size) 141 | .lin_blue_position: db (_lin_blue_position) 142 | .lin_rsvd_size: db (_lin_rsvd_size) 143 | .lin_rsvd_position: db (_lin_rsvd_position) 144 | .max_pixel_clock: dd (_max_pixel_clock) 145 | .reserved_3: db 0BDH dup 0H 146 | ends 147 | 148 | _MP_FLOATING_POINTER = "_MP_" 149 | struct _mp_floating_pointer _signature*, _physical_address*, _length*, _spec_rev*,\ 150 | _checksum*, _mp_feature_1*, _mp_feature_2* 151 | .signature: dd (_signature) 152 | .physical_address: dd (_physical_address) 153 | .length: db (_length) 154 | .spec_rev: db (_spec_rev) 155 | .checksum: db (_checksum) 156 | .mp_feature_1: db (_mp_feature_1) 157 | .mp_feature_2: db (_mp_feature_2) 158 | .mp_feature_3: db 0H 159 | .mp_feature_4: db 0H 160 | .mp_feature_5: db 0H 161 | ends 162 | 163 | _mp_floating_pointer_base: dd 0H 164 | _mp_floating_pointer_found: db 0H 165 | 166 | struct _mp_configuration_table _signature*, _base_length*, _spec_rev*, _checksum*, _oem_id*,\ 167 | _product_id*, _oem_table*, _oem_length*, _entry_count*, _local_apic*, _extended_length*, _extended_checksum* 168 | .signature: dd (_signature) 169 | .base_length: dw (_base_length) 170 | .spec_rev: db (_spec_rev) 171 | .checksum: db (_checksum) 172 | .oem_id: dq (_oem_id) 173 | .product_id: dq ((_product_id) and 0FFFFFFFFFFFFFFFFH) 174 | dd ((_product_id) shr 040H) 175 | .oem_table: dd (_oem_table) 176 | .oem_length: dw (_oem_length) 177 | .entry_count: dw (_entry_count) 178 | .local_apic: dd (_local_apic) 179 | .extended_length: dw (_extended_length) 180 | .extended_checksum: db (_extended_checksum) 181 | .reserved: db 0H 182 | ends 183 | 184 | _PROCESSOR_ENTRY = 0H 185 | _BUS_ENTRY = 1H 186 | _IO_APIC_ENTRY = 2H 187 | _IO_INTERRUPT_ENTRY = 3H 188 | _LOCAL_INTERRUPT_ENTRY = 4H 189 | 190 | _PROCESSOR_FLAGS_EN = (1H shl 0H) 191 | _PROCESSOR_FLAGS_BP = (1H shl 1H) 192 | struct _processor_entry _local_apic_id*, _local_apic_version*, _cpu_flags*, _cpu_signature*, _feature_flags* 193 | .type: db (_PROCESSOR_ENTRY) 194 | .local_apic_id: db (_local_apic_id) 195 | .local_apic_version:db (_local_apic_version) 196 | .cpu_flags: db (_cpu_flags) 197 | .cpu_signature: dd (_cpu_signature) 198 | .feature_flags: dd (_feature_flags) 199 | .reserved: dq 0H 200 | ends 201 | 202 | struct _bus_entry _bus_id*, _bus_string* 203 | .type: db (_BUS_ENTRY) 204 | .bus_id: db (_bus_id) 205 | .bus_string: dd ((_bus_string) and 0FFFFFFFFH) 206 | dw ((_bus_string) shr 020H) 207 | ends 208 | 209 | _IO_APIC_FLAGS_EN = (1H shl 0H) 210 | struct _io_apic_entry _io_apic_id*, _io_apic_version*, _io_apic_flags*, _io_apic_address* 211 | .type: db (_IO_APIC_ENTRY) 212 | .io_apic_id: db (_io_apic_id) 213 | .io_apic_version: db (_io_apic_version) 214 | .io_apic_flags: db (_io_apic_flags) 215 | .io_apic_address: dd (_io_apic_address) 216 | ends 217 | 218 | _INTERRUPT_INT = 0H 219 | _INTERRUPT_NMI = 1H 220 | _INTERRUPT_SMI = 2H 221 | _INTERRUPT_EXTINT = 3H 222 | _INTERRUPT_PO _bitwise 011B, 0H 223 | _INTERRUPT_PO_CONFORM = 000B ; only relevant when EL = LEVEL, default to low 224 | _INTERRUPT_PO_HIGH = 001B 225 | _INTERRUPT_PO_LOW = 011B 226 | _INTERRUPT_EL _bitwise 011B, 2H 227 | _INTERRUPT_EL_CONFORM = 000B ; default to edge 228 | _INTERRUPT_EL_EDGE = 001B 229 | _INTERRUPT_EL_LEVEL = 011B 230 | 231 | irp _kind, io,local 232 | { 233 | struct _#_kind#_interrupt_entry _interrupt_type*, _#_kind#_interrupt_flags*, _source_bus_id*,\ 234 | _source_bus_irq*, _destination_#_kind#_apic_id*, _destination_#_kind#_apic_intin* 235 | .type: db (_IO_INTERRUPT_ENTRY) 236 | .interrupt_type: db (_interrupt_type) 237 | .#_kind#_interrupt_flags: dw (_#_kind#_interrupt_flags) 238 | .source_bus_id: db (_source_bus_id) 239 | .source_bus_irq: db (_source_bus_irq) 240 | .destination_#_kind#_apic_id: db (_destination_#_kind#_apic_id) 241 | .destination_#_kind#_apic_intin: db (_destination_#_kind#_apic_intin) 242 | ends_ 243 | } 244 | 245 | struct _mp_predicate _procentry*, _busentry*, _ioapicentry*, _iointentry*, _lcintentry* 246 | .procentry: dd (_procentry) 247 | .busentry: dd (_busentry) 248 | .ioapicentry: dd (_ioapicentry) 249 | .iointentry: dd (_iointentry) 250 | .lcintentry: dd (_lcintentry) 251 | ends 252 | assert (((_mp_predicate.procentry shr 2H) = _PROCESSOR_ENTRY) & ((_mp_predicate.busentry shr 2H) = _BUS_ENTRY) &\ 253 | ((_mp_predicate.ioapicentry shr 2H) = _IO_APIC_ENTRY) & ((_mp_predicate.iointentry shr 2H) = _IO_INTERRUPT_ENTRY) &\ 254 | ((_mp_predicate.lcintentry shr 2H) = _LOCAL_INTERRUPT_ENTRY)) 255 | 256 | _RSDP = "RSD PTR " 257 | struct _rsdp_descriptor _signature*, _checksum*, _oemid*, _revision*, _rsdt_address* 258 | .signature: dq (_signature) 259 | .checksum: db (_checksum) 260 | .oemid: dd ((_oemid) and 0FFFFFFFFH) 261 | dw ((_oemid) shr 020H) 262 | .revision: db (_revision) 263 | .rsdt_address: dd (_rsdt_address) 264 | ends 265 | 266 | struct _rsdp_descriptor_extended _signature*, _checksum*, _oemid*, _revision*, _rsdt_address*,\ 267 | _length*, _xsdt_address*, _extended_checksum* 268 | .legacy _rsdp_descriptor _signature, _checksum, _oemid, _revision, _rsdt_address 269 | .length: dd (_length) 270 | .xsdt_address: dq (_xsdt_address) 271 | .extended_checksum: db (_extended_checksum) 272 | .reserved: db 3H dup 0H 273 | ends 274 | 275 | _rsdp_descriptor_base: dd 0H 276 | _rsdp_descriptor_found: db 0H 277 | 278 | struct _acpi_sdt_header _signature*, _length*, _revision*, _checksum*, _oem_id*, _oem_table_id*,\ 279 | _oem_revision*, _creator_id*, _creator_revision* 280 | .signature: dd (_signature) 281 | .length: dd (_length) 282 | .revision: db (_revision) 283 | .checksum: db (_checksum) 284 | .oem_id: dd ((_oem_id) and 0FFFFFFFFH) 285 | dw ((_oem_id) shr 020H) 286 | .oem_table_id: dq (_oem_table_id) 287 | .oem_revision: dd (_oem_revision) 288 | .creator_id: dd (_creator_id) 289 | .creator_revision: dd (_creator_revision) 290 | ends 291 | 292 | _PCAT_COMPAT = (1H shl 0H) 293 | struct _madt_header _signature*, _length*, _revision*, _checksum*, _oem_id*, _oem_table_id*,\ 294 | _oem_revision*, _creator_id*, _creator_revision*, _local_apic*, _flags* 295 | .common _acpi_sdt_header _signature, _length, _revision, _checksum, _oem_id, _oem_table_id,\ 296 | _oem_revision, _creator_id, _creator_revision 297 | .local_apic: dd (_local_apic) 298 | .flags: dd (_flags) 299 | ends 300 | 301 | enum _MADT_PROCESSOR_LOCAL_APIC, _MADT_IO_APIC, _MADT_INTERRUPT_OVERRIDE, _MADT_NMI, _MADT_LOCAL_APIC_NMI,\ 302 | _MADT_LOCAL_APIC_OVERRIDE, _MADT_IO_SAPIC, _MADT_LOCAL_SAPIC, _MADT_PLATFORM_INTERRUPT, _MADT_PROCESSOR_LOCAL_X2APIC,\ 303 | _MADT_LOCAL_X2APIC_NMI, _MADT_GICC, _MADT_GICD, _MADT_MSI, _MADT_GICR, _MADT_ITS 304 | 305 | struct _madt_prefix _type*, _length* 306 | .type: db (_type) 307 | .length: db (_length) 308 | ends 309 | 310 | _MADT_LOCAL_APIC_FLAGS_ENABLED = (1H shl 0H) 311 | _MADT_LOCAL_APIC_FLAGS_ONLINE_CAPABLE = (1H shl 1H) 312 | struct _madt_processor_local_apic _length*, _acpi_id*, _apic_id*, _flags* 313 | .prefix _madt_prefix _MADT_PROCESSOR_LOCAL_APIC, (_length) 314 | .acpi_id: db (_acpi_id) 315 | .apic_id: db (_apic_id) 316 | .flags: dd (_flags) 317 | ends 318 | 319 | struct _madt_io_apic _length*, _io_apic_id*, _io_apic_address*, _gsi_base* 320 | .prefix _madt_prefix _MADT_IO_APIC, (_length) 321 | .io_apic_id: db (_io_apic_id) 322 | .reserved: db 0H 323 | .io_apic_address: dd (_io_apic_address) 324 | .gsi_base: dd (_gsi_base) 325 | ends 326 | 327 | struct _madt_interrupt_override _length*, _bus*, _irq*, _gsi*, _flags* 328 | .type: db (_MADT_INTERRUPT_OVERRIDE) 329 | .length: db (_length) 330 | .bus: db (_bus) 331 | .irq: db (_irq) 332 | .gsi: dd (_gsi) 333 | .flags: dw (_flags) 334 | ends 335 | 336 | struct _madt_nmi _length*, _flags*, _gsi* 337 | .type: db (_MADT_NMI) 338 | .length: db (_length) 339 | .flags: dw (_flags) 340 | .gsi: dd (_gsi) 341 | ends 342 | 343 | struct _madt_local_apic_nmi _length*, _apic_id*, _flags*, _lint* 344 | .type: db (_MADT_LOCAL_APIC_NMI) 345 | .length: db (_length) 346 | .acpi_id: db (_apic_id) 347 | .flags: dw (_flags) 348 | .lint: db (_lint) 349 | ends 350 | 351 | struct _matd_local_apic_override _length*, _local_apic_address* 352 | .type: db (_MADT_LOCAL_APIC_OVERRIDE) 353 | .length: db (_length) 354 | .reserved: db 0H 355 | .local_apic_address: dd (_local_apic_address) 356 | ends 357 | 358 | struct _madt_io_sapic _length*, _io_sapic_id*, _gsi_base*, _io_sapic_address* 359 | .type: db (_MADT_IO_SAPIC) 360 | .length: db (_length) 361 | .io_sapic_id: db (_io_sapic_id) 362 | .reserved: db 0H 363 | .gsi_base: dd (_gsi_base) 364 | .io_sapic_address: dq (_io_sapic_address) 365 | ends 366 | 367 | struct _madt_local_sapic _length*, _acpi_id*, _local_sapic_id*, _local_sapic_eid*, _flags*, _acpi_uid_value* 368 | .type: db (_MADT_LOCAL_SAPIC) 369 | .length: db (_length) 370 | .acpid_id: db (_acpi_id) 371 | .local_sapic_id: db (_local_sapic_id) 372 | .local_sapic_eid: db (_local_sapic_eid) 373 | .reserved: db 0H dup 3H 374 | .flags: dd (_flags) 375 | .acpi_uid_value: dd (_acpi_uid_value) 376 | .acpi_uid_string: 377 | ends 378 | 379 | struct _madt_platform_interrupt _length*, _flags*, _processor_id*, _processor_eid*, _io_sapic_vector*, _gsi* 380 | .type: db (_MADT_PLATFORM_INTERRUPT) 381 | .length: db (_length) 382 | .flags: dw (_flags) 383 | .interrupt_type: 384 | .processor_id: db (_processor_id) 385 | .processor_eid: db (_processor_eid) 386 | .io_sapic_vector: db (_io_sapic_vector) 387 | .gsi: dd (_gsi) 388 | ends 389 | 390 | _RSDT = "RSDT" 391 | _MADT = "APIC" 392 | _BERT = "BERT" 393 | _CPEP = "CPEP" 394 | _DSDT = "DSDT" 395 | _ECDT = "ECDT" 396 | _EINJ = "EINJ" 397 | _ERST = "ERST" 398 | 399 | _KERNEL_IDENTITY = (_KERNEL_START + _kernel_size) 400 | if (_KERNEL_IDENTITY and (_PSE_PAGE_FRAME_SIZE - 1H)) 401 | _KERNEL_IDENTITY = (_KERNEL_IDENTITY + _PSE_PAGE_FRAME_SIZE) 402 | end if 403 | _KERNEL_IDENTITY = (_KERNEL_IDENTITY / _PSE_PAGE_FRAME_SIZE) 404 | if (~(_KERNEL_IDENTITY)) 405 | _KERNEL_IDENTITY = 1H 406 | end if 407 | 408 | _PAE_KERNEL_IDENTITY = (_KERNEL_IDENTITY * (_TABLE_ENTRY_COUNT / _PAE_TABLE_ENTRY_COUNT)) 409 | 410 | _page_table _default_directory_mapping 411 | repeat _KERNEL_IDENTITY 412 | PT_pe (_default_table_mapping + ((% - 1H) * _PAGE_FRAME_SIZE)), (_PE_PRESENT or _PE_READ_WRITE) 413 | end repeat 414 | PT_pe _default_table_mapping, (_PE_PRESENT or _PE_READ_WRITE), (_KERNEL_VIRTUAL shr _PAGE_DIRECTORY_SHIFT) 415 | repeat (_KERNEL_IDENTITY - 1H) 416 | PT_pe (_default_table_mapping + (% * _PAGE_FRAME_SIZE)), (_PE_PRESENT or _PE_READ_WRITE) 417 | end repeat 418 | end _page_table 419 | 420 | _default_table_mapping: 421 | 422 | repeat _KERNEL_IDENTITY 423 | _index = (% - 1H) 424 | rept _TABLE_ENTRY_COUNT i:0H 425 | { _PT_pe ((_index shl _PAGE_DIRECTORY_SHIFT) + ((i) shl _PAGE_TABLE_SHIFT)), (_PE_READ_WRITE or _PE_PRESENT) } 426 | end repeat 427 | 428 | ; 1th gen paging 429 | 430 | ;page_table _page_directory 431 | ; rept 080H i:1H { PT_pe _identity_page_table_#i, _PE_PRESENT or _PE_READ_WRITE } 432 | ; PT_pe _kernel_page_table, _PE_PRESENT or _PE_READ_WRITE, _KERNEL_VIRTUAL_INDEX 433 | ;PT_null _TEMP_1_INDEX 434 | ;T_null 435 | ; PT_pe _page_directory, _PE_PRESENT or _PE_READ_WRITE 436 | ;end page_table 437 | 438 | ;page_table _kernel_page_table 439 | ;repeat _TABLE_ENTRY_COUNT 440 | ; PT_pe ((0H shl _PAGE_DIRECTORY_SHIFT) + ((% - 1H) shl _PAGE_TABLE_SHIFT)), _PE_PRESENT or _PE_READ_WRITE 441 | ;end repeat 442 | ;end page_table 443 | 444 | ;rept 080H i:1H 445 | ;{ 446 | ; page_table _identity_page_table_#i 447 | ; repeat _TABLE_ENTRY_COUNT 448 | ; PT_pe (((i - 1H) shl _PAGE_DIRECTORY_SHIFT) + ((% - 1H) shl _PAGE_TABLE_SHIFT)), _PE_PRESENT or _PE_READ_WRITE 449 | ; end repeat 450 | ; end page_table 451 | ;} 452 | 453 | ; 2th gen paging PAE 454 | 455 | ;page_table _pdpt, 1H 456 | ; PT_pe _pae_directory_identity, _PE_PRESENT 457 | ; PT_pe _pae_empty_1, _PE_PRESENT 458 | ; PT_pe _pae_empty_2, _PE_PRESENT 459 | ; PT_pe _pae_directory_kernel, _PE_PRESENT 460 | ; PT_pe _pdpt, (_PTE_PAT or _PE_READ_WRITE or _PE_PRESENT) 461 | ;end page_table 462 | 463 | ;rept 080H i:1H 464 | ;{ 465 | ; page_table _pae_table_identity_#i, 1H 466 | ; repeat _PAE_TABLE_ENTRY_COUNT 467 | ; PT_pe (((i - 1H) shl _PAE_PAGE_DIRECTORY_SHIFT) + ((% - 1H) shl _PAGE_TABLE_SHIFT)), \ 468 | ; _PE_READ_WRITE or _PE_PRESENT 469 | ; end repeat 470 | ; end page_table 471 | ;} 472 | 473 | ;page_table _pae_directory_identity, 1H 474 | ; rept 080H i:1H { PT_pe _pae_table_identity_#i, _PE_USER or _PE_READ_WRITE or _PE_PRESENT } 475 | ;end page_table 476 | 477 | ;page_table _pae_empty_1, 1H 478 | ;end page_table 479 | 480 | ;page_table _pae_empty_2, 1H 481 | ;end page_table 482 | 483 | ;page_table _pae_directory_kernel, 1H 484 | ; PT_pe _pae_table_kernel_1, _PE_READ_WRITE or _PE_PRESENT 485 | ; PT_pe _pae_table_kernel_2, _PE_READ_WRITE or _PE_PRESENT 486 | ; PT_null _PAE_TEMP_1_INDEX 487 | ; PT_null 488 | ; PT_null 489 | ; PT_null 490 | ; PT_null 491 | ; PT_pe _pae_directory_kernel, _PE_READ_WRITE or _PE_PRESENT 492 | ; PT_pe _pdpt, _PE_READ_WRITE or _PE_PRESENT 493 | ;end page_table 494 | 495 | ;rept 2H i:1H 496 | ;{ 497 | ; page_table _pae_table_kernel_#i, 1H 498 | ; repeat _PAE_TABLE_ENTRY_COUNT 499 | ; PT_pe (((i - 1H) shl _PAE_PAGE_DIRECTORY_SHIFT) + ((% - 1H) shl _PAGE_TABLE_SHIFT)),\ 500 | ; _PE_USER or _PE_READ_WRITE or _PE_PRESENT 501 | ; end repeat 502 | ; end page_table 503 | ;} 504 | 505 | ; Real identity mapping 506 | 507 | _VIRTUAL_REAL_PROTECTION = (_PE_USER or _PE_READ_WRITE or _PE_PRESENT) 508 | 509 | _page_table _pae_real_pgdir, pae 510 | PT_pe _pae_real_pgtable, _VIRTUAL_REAL_PROTECTION 511 | end _page_table 512 | 513 | macro _real_identity _wraparound* 514 | { 515 | local _items, _overflow 516 | _overflow = 020H 517 | _items = (_FIRST_MEGABYTE shr _PAGE_TABLE_SHIFT) 518 | if (~(_wraparound)) 519 | _items = (_items + _overflow) 520 | end if 521 | repeat (_items) 522 | PT_pe (_PAGE_FRAME_SIZE * (% - 1H)), _VIRTUAL_REAL_PROTECTION 523 | end repeat 524 | if (_wraparound) 525 | repeat (_overflow) 526 | PT_pe (_PAGE_FRAME_SIZE * (% - 1H)), _VIRTUAL_REAL_PROTECTION 527 | end repeat 528 | end if 529 | } 530 | 531 | _page_table _pae_real_pgtable, pae 532 | _real_identity 0H 533 | end _page_table 534 | 535 | _page_table _real_pgtable 536 | _real_identity 0H 537 | end _page_table 538 | 539 | _kernel_magic: dd 0H 540 | 541 | _kernel_disable_nmi: 542 | mov al, _CMOS_DISABLE_NMI 543 | out _CMOS_SELECT, al 544 | ret 545 | 546 | _kernel_enable_nmi: 547 | xor al, al 548 | out _CMOS_SELECT, al 549 | ret 550 | 551 | _kernel_reset_fpu: 552 | ret 553 | 554 | _zero_checksum_check: 555 | ; in: 556 | ; ecx - count of byte to add 557 | ; edi - base struct pointer 558 | ; out: cf - set when the sum does not equal to 0H 559 | ; preserves: ebx, edx, esi, edi, ebp 560 | xor al, al 561 | add al, byte [edi+ecx-1H] 562 | loop _zero_checksum_check+2H 563 | test al, al 564 | jz $+3H 565 | stc 566 | ret 567 | 568 | _mp_floating_checksum: 569 | movzx ecx, byte [edi+_mp_floating_pointer.length] 570 | shl ecx, 4H 571 | jmp _zero_checksum_check 572 | 573 | _acpi_rsdp_checksum: 574 | ; note: revision = 0H when ACPI 1.0 is present, otherwise it's 2H for subsequent version 575 | xor ecx, ecx 576 | mov cl, _rsdp_descriptor.sizeof 577 | cmp byte [edi+_rsdp_descriptor.revision], 0H 578 | jz _zero_checksum_check 579 | mov cl, _rsdp_descriptor_extended.sizeof 580 | cmp byte [edi+_rsdp_descriptor.revision], 2H 581 | jz _zero_checksum_check 582 | stc 583 | ret 584 | 585 | _acpi_sdt_checksum: 586 | mov ecx, dword [edi+_acpi_sdt_header.length] 587 | jmp _zero_checksum_check 588 | 589 | _kernel_find_table: 590 | ; in: 591 | ; eax - first part magic number 592 | ; ebx - destination base pointer 593 | ; ecx - how to treat edx 594 | ; edx - second part magic number (if ecx = (not 0H)) 595 | ; esi - functor to check checksum (must only modify eax,ecx) 596 | ; preserves: eax, ebx, ecx, edx, esi, ebp 597 | xor edi, edi 598 | _kernel_find_table_loop: 599 | scasd 600 | jnz _kernel_find_table_update 601 | jecxz _kernel_find_table_save 602 | cmp edx, dword [edi] 603 | jz _kernel_find_table_save 604 | _kernel_find_table_update: 605 | add edi, (010H - 4H) 606 | cmp edi, _FIRST_MEGABYTE 607 | jae _kernel_find_table_exit 608 | jmp _kernel_find_table_loop 609 | _kernel_find_table_save: 610 | lea edi, [edi-4H] 611 | mov dword [ebx], edi 612 | push eax ecx 613 | call esi 614 | pop ecx eax 615 | lea edi, [edi+4H] 616 | jc _kernel_find_table_update 617 | _kernel_find_table_exit: 618 | ret 619 | 620 | _store_entry_physical = (_store_entry - _KERNEL_VIRTUAL) 621 | 622 | _kernel_1th_paging: 623 | ; note: (((400H^2H)*4H)+(400H*4H)) to identity map all memory 624 | mov ecx, _KERNEL_VIRTUAL_INDEX 625 | assert (_KERNEL_VIRTUAL_INDEX <> 0H) 626 | mov edi, _FIRST_MEGABYTE 627 | mov eax, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE + _PE_READ_WRITE + _PE_PRESENT) 628 | _kernel_1th_paging_pd: 629 | call _store_entry_physical 630 | add eax, _PAGE_FRAME_SIZE 631 | loop _kernel_1th_paging_pd 632 | mov eax, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE + _PE_READ_WRITE + _PE_PRESENT) 633 | mov cl, _KERNEL_IDENTITY 634 | _kernel_1th_paging_supervisor: ; set the kernel mapping as well as the recursive entry 635 | call _store_entry_physical 636 | add eax, _PAGE_FRAME_SIZE 637 | loop _kernel_1th_paging_supervisor 638 | mov edi, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE - 4H) 639 | mov eax, (_FIRST_MEGABYTE + _PE_READ_WRITE + _PE_PRESENT) 640 | call _store_entry_physical 641 | mov ecx, (_KERNEL_VIRTUAL_INDEX * _TABLE_ENTRY_COUNT) 642 | mov edi, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE) 643 | mov eax, (_PE_READ_WRITE + _PE_PRESENT) 644 | _kernel_1th_paging_pt: 645 | call _store_entry_physical 646 | add eax, _PAGE_FRAME_SIZE 647 | loop _kernel_1th_paging_pt 648 | ret 649 | 650 | _kernel_2th_paging: 651 | ; note: ((((200H^2H)*8H)*4H)+(4H*8H)) to identity map all memory 652 | mov edi, _FIRST_MEGABYTE 653 | mov eax, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE + _PE_PRESENT) 654 | xor edx, edx 655 | xor ecx, ecx 656 | mov cl, _PAE_PDPT_ENTRY_COUNT 657 | _kernel_2th_paging_pdpt: 658 | call _store_entry_physical 659 | add eax, _PAGE_FRAME_SIZE 660 | loop _kernel_2th_paging_pdpt 661 | mov eax, (_FIRST_MEGABYTE + _PE_READ_WRITE + _PE_PRESENT) 662 | call _store_entry_physical ; fifth slot technique 663 | mov ecx, ((_KERNEL_VIRTUAL shr _PAE_PAGE_DIRECTORY_POINTER_SHIFT) * _PAE_TABLE_ENTRY_COUNT) 664 | mov edi, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE) 665 | mov eax, (_FIRST_MEGABYTE + (_PAGE_FRAME_SIZE * (_PAE_PDPT_ENTRY_COUNT + 1H)) + _PE_READ_WRITE + _PE_PRESENT) 666 | _kernel_2th_paging_pd: 667 | call _store_entry_physical 668 | add eax, _PAGE_FRAME_SIZE 669 | loop _kernel_2th_paging_pd 670 | mov eax, (_FIRST_MEGABYTE + (_PAGE_FRAME_SIZE * (_PAE_PDPT_ENTRY_COUNT + 1H)) + _PE_READ_WRITE + _PE_PRESENT) 671 | mov cl, _PAE_KERNEL_IDENTITY 672 | _kernel_2th_paging_supervisor: 673 | call _store_entry_physical 674 | add eax, _PAGE_FRAME_SIZE 675 | loop _kernel_2th_paging_supervisor 676 | mov edi, (_FIRST_MEGABYTE + (_PAGE_FRAME_SIZE * (_PAE_PDPT_ENTRY_COUNT + 1H)) - ((_PAE_PDPT_ENTRY_COUNT + 1H) shl 3H)) 677 | mov eax, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE + _PE_READ_WRITE + _PE_PRESENT) 678 | mov cl, _PAE_PDPT_ENTRY_COUNT 679 | _kernel_2th_paging_recursive: 680 | call _store_entry_physical 681 | add eax, _PAGE_FRAME_SIZE 682 | loop _kernel_2th_paging_recursive 683 | mov eax, (_FIRST_MEGABYTE + _PE_READ_WRITE + _PE_PRESENT) 684 | call _store_entry_physical 685 | mov ecx, ((_KERNEL_VIRTUAL shr _PAE_PAGE_DIRECTORY_SHIFT) * _PAE_TABLE_ENTRY_COUNT) 686 | mov eax, (_PE_READ_WRITE + _PE_PRESENT) 687 | _kernel_2th_paging_pt: 688 | call _store_entry_physical 689 | add eax, _PAGE_FRAME_SIZE 690 | loop _kernel_2th_paging_pt 691 | ret 692 | 693 | _kernel_3th_paging: 694 | mov edi, _FIRST_MEGABYTE 695 | mov eax, (_FIRST_MEGABYTE + _PAGE_FRAME_SIZE + _PE_READ_WRITE + _PE_PRESENT) 696 | xor edx, edx 697 | call _store_entry_physical 698 | mov edi, (_FIRST_MEGABYTE + (_PML4_HIGHER_HALF shl 3H)) 699 | call _store_entry_physical 700 | mov eax, (_FIRST_MEGABYTE + _PE_READ_WRITE + _PE_PRESENT) 701 | mov edi, (_FIRST_MEGABYTE + ((_PML4_TABLE_ENTRY_COUNT - 1H) shl 3H)) 702 | call _store_entry_physical 703 | mov eax, (_FIRST_MEGABYTE + (_PAGE_FRAME_SIZE shl 1H) + _PE_READ_WRITE + _PE_PRESENT) 704 | xor ecx, ecx 705 | mov cl, 3H 706 | _kernel_3th_paging_pdpt: 707 | call _store_entry_physical 708 | add eax, _PAGE_FRAME_SIZE 709 | loop _kernel_3th_paging_pdpt 710 | mov edi, (_FIRST_MEGABYTE + (_PAGE_FRAME_SIZE shl 1H)) 711 | mov ecx, (_PAE_TABLE_ENTRY_COUNT * 3H) 712 | _kernel_3th_paging_pd: 713 | call _store_entry_physical 714 | add eax, _PAGE_FRAME_SIZE 715 | loop _kernel_3th_paging_pd 716 | mov ecx, ((_PAE_TABLE_ENTRY_COUNT shl 1H) * 3H) 717 | mov eax, (_PE_READ_WRITE + _PE_PRESENT) 718 | _kernel_3th_paging_pt: 719 | call _store_entry_physical 720 | add eax, _PAGE_FRAME_SIZE 721 | loop _kernel_3th_paging_pt 722 | ret 723 | 724 | _kernel_refresh_paging: 725 | ; in: 726 | ; eax - cr4 flags 727 | ; ebx - memory cache policy 728 | ; esi - predicate to call for paging table setup 729 | mov edx, cr0 730 | and edx, (not _CR0_PG) 731 | mov cr0, edx 732 | mov cr4, eax 733 | or ebx, _FIRST_MEGABYTE 734 | mov cr3, ebx 735 | call esi 736 | mov edx, cr0 737 | or edx, _CR0_PG 738 | mov cr0, edx 739 | ret 740 | 741 | _descriptor_table __o 742 | $DT_null 743 | ;_kernel_code_64_segment DT_dte _DE_L or _DE_G, _DE_PRESENT or _DPL0 or _DE_EXECUTABLE, 0H, 0FFFFFH 744 | __m DT_dte _DE_L or _DE_G, _DE_PRESENT or _DPL1 or _DE_EXECUTABLE, 01111H, 0FFFFFH 745 | __w DT_dte _DE_B or _DE_G, _DE_PRESENT or _DPL1 or _DE_WRITABLE, 01111H, 00FFFFFH 746 | _fs_gs_test DT_dte 0H, _DE_PRESENT, 0H, 0H 747 | end _descriptor_table 748 | 749 | __j: 750 | mov edx, cr0 751 | and edx, (not _CR0_PG) 752 | mov cr0, edx 753 | mov eax, _FIRST_MEGABYTE 754 | mov cr3, eax 755 | mov eax, cr4 756 | or eax, _CR4_PAE 757 | mov cr4, eax 758 | mov ecx, _EFER 759 | rdmsr 760 | or eax, _EFER_LME or _EFER_SCE 761 | wrmsr 762 | mov eax, cr0 763 | or eax, _CR0_PG 764 | mov cr0, eax 765 | _load_descriptor_table gdt, __o 766 | jmp 8H:__k 767 | ;pushd __w.selector + _RPL1 768 | ;pushd 0100H 769 | ;pushd __m.selector + _RPL1 770 | ;pushd __k 771 | ;retfd 772 | 773 | __k: 774 | use64 775 | mov rax, "WELCOME " 776 | jmp $ 777 | 778 | mov ax, _RPL1 779 | mov ss, ax 780 | push 0H 781 | 782 | mov rax, 0H 783 | mov cr8, rax 784 | 785 | mov rax, (_LONG_MODE_CANONICAL or (_PML4_HIGHER_HALF shl _PML4_SHIFT)) 786 | mov rbx, qword [rax] 787 | mov ax, _fs_gs_test.selector 788 | mov fs, ax 789 | mov gs, ax 790 | mov qword [fs:0H], 050H 791 | mov ecx, _FS_BASE 792 | rdmsr 793 | mov ecx, _KERNEL_GS_BASE 794 | mov eax, 0C0DEH 795 | wrmsr 796 | swapgs 797 | jmp $ 798 | 799 | use32 800 | 801 | _kernel_etablish: 802 | mov dword [_kernel_magic], eax 803 | call _kernel_disable_nmi 804 | _kernel_setup: 805 | org (_KERNEL_VIRTUAL + _kernel_setup) 806 | mov esi, _default_directory_mapping 807 | mov cr3, esi 808 | mov esi, cr0 809 | or esi, (_CR0_PG or _CR0_WP) ; or _CR0_MP or _CR0_NE) 810 | and esi, (not (_CR0_CD or _CR0_NW or _CR0_AM or _CR0_TS or _CR0_EM)) 811 | mov cr0, esi 812 | wbinvd 813 | mov edi, _kernel_setup_linear 814 | jmp edi ; clear prefetch queue 815 | _kernel_setup_linear: 816 | mov edi, _FIRST_MEGABYTE 817 | mov ecx, (_KERNEL_START - _FIRST_MEGABYTE) 818 | call _clear_string 819 | ;call _kernel_3th_paging 820 | ;jmp __j 821 | cmp dword [_kernel_magic], _GRUB1_MULTIBOOT 822 | jnz _kernel_error 823 | mov eax, dword [ebx+_multiboot_info.flags] 824 | test eax, _MULTIBOOT_MEM 825 | jz _kernel_error 826 | mov ecx, dword [ebx+_multiboot_info.mem_upper] 827 | add ecx, dword [ebx+_multiboot_info.mem_lower] 828 | shr ecx, 2H 829 | mov dword [_memory_size], ecx 830 | mov eax, _frame 831 | mov ebx, dword [_frame.next] 832 | xor edx, edx 833 | mov edi, _BITMAP_SET 834 | call _bitmap_update 835 | mov eax, _MP_FLOATING_POINTER 836 | xor ecx, ecx 837 | mov ebx, _mp_floating_pointer_base 838 | mov esi, _mp_floating_checksum 839 | call _kernel_find_table 840 | setnc byte [_mp_floating_pointer_found] 841 | mov eax, (_RSDP and 0FFFFFFFFH) 842 | mov edx, (_RSDP shr 020H) 843 | not ecx 844 | mov ebx, _rsdp_descriptor_base 845 | mov esi, _acpi_rsdp_checksum 846 | call _kernel_find_table 847 | setnc byte [_rsdp_descriptor_found] 848 | mov esi, _singleton 849 | call _cpuid_detection 850 | jc _kernel_error 851 | test byte [_singleton.apic], 1H 852 | jz _kernel_setup_feature 853 | mov ecx, _IA32_APIC_BASE 854 | rdmsr 855 | or eax, _APIC_BASE_EN 856 | wrmsr 857 | _kernel_setup_feature: 858 | mov eax, cr4 859 | or eax, (_CR4_PSE or _CR4_PGE or _CR4_PCE or _CR4_DE) 860 | and eax, (not _CR4_TSD) 861 | test byte [_singleton.fxsr], 1H 862 | jz $+5H 863 | or eax, _CR4_OSFXSR 864 | test byte [_singleton.sse], 1H 865 | jz $+5H 866 | or eax, _CR4_OSXMMEXCPT 867 | test byte [_singleton.xsave], 1H 868 | jz _kernel_setup_security 869 | or eax, _CR4_OSXSAVE 870 | inc byte [_singleton.osxsave] 871 | _kernel_setup_security: 872 | if (_UMIP_ALLOW) 873 | test byte [_singleton.umip], 1H 874 | jz $+5H 875 | or eax, _CR4_UMIP 876 | end if 877 | test byte [_singleton.smap], 1H 878 | jz $+5H 879 | or eax, _CR4_SMAP 880 | test byte [_singleton.smep], 1H 881 | jz $+5H 882 | or eax, _CR4_SMEP 883 | test byte [_singleton.pae], 1H 884 | jz $+5H 885 | or eax, _CR4_PAE 886 | test byte [_singleton.vme], 1H 887 | jz $+5H 888 | or eax, _CR4_VME 889 | if (_VMX_ALLOW) 890 | test byte [_singleton.vmx], 1H 891 | jz $+5H 892 | or eax, _CR4_VMXE 893 | end if 894 | test byte [_singleton.mce], 1H 895 | jz $+5H 896 | or eax, _CR4_MCE 897 | mov esi, _kernel_1th_paging 898 | test byte [_singleton.pae], 1H 899 | jz $+7H 900 | mov esi, _kernel_2th_paging 901 | xor ebx, ebx 902 | mov bl, _MEMORY_WB 903 | call _kernel_refresh_paging 904 | test byte [_singleton.pat], 1H 905 | jz _kernel_setup_mtrr 906 | mov ecx, _IA32_CR_PAT 907 | rdmsr 908 | mov eax, ((_PAT_UCM shl _PAT_PA3) or (_PAT_UC shl _PAT_PA2) or (_PAT_WT shl _PAT_PA1) or (_PAT_WB shl _PAT_PA0)) 909 | mov edx, ((_PAT_WC shl (_PAT_PA5 shr 020H)) or (_PAT_WP shl (_PAT_PA4 shr 020H))) 910 | wrmsr 911 | _kernel_setup_mtrr: 912 | test byte [_singleton.mtrr], 1H 913 | jz _kernel_setup_launch 914 | mov ecx, _MTRR_CAP 915 | rdmsr 916 | test eax, _MTRR_CAP_FIX 917 | jz $+8H 918 | inc byte [_singleton.fixmtrr] 919 | test eax, _MTRR_CAP_WC 920 | jz $+8H 921 | inc byte [_singleton.wc] 922 | test eax, _MTRR_CAP_SMRR 923 | jz $+8H 924 | inc byte [_singleton.smrr] 925 | and eax, _MTRR_CAP_VCNT_MASK 926 | mov byte [_singleton.varmtrr], al 927 | mov ecx, _MTRR_DEF_TYPE 928 | rdmsr 929 | mov eax, (_MTRR_DEF_TYPE_E or _MTRR_TYPE_WB) 930 | test byte [_singleton.fixmtrr], 1H 931 | jz $+5H 932 | or eax, _MTRR_DEF_TYPE_FE 933 | wrmsr 934 | _kernel_setup_launch: 935 | jmp _kernel_entry 936 | 937 | _kernel_error_message string "B O O T E R R O R " 938 | _kernel_error: 939 | cli 940 | call _kernel_disable_nmi 941 | mov esi, _kernel_error_message 942 | mov edi, _LEGACY_TEXTMODE 943 | xor ecx, ecx 944 | mov cl, _kernel_error_message.sizeof 945 | rep movsb 946 | _kernel_error_hang: 947 | hlt 948 | jmp _kernel_error_hang 949 | 950 | include "kernel.inc" 951 | 952 | _kernel_end: 953 | 954 | _kernel_size = ((_kernel_end - _KERNEL_VIRTUAL) - _kernel_start) 955 | 956 | -------------------------------------------------------------------------------- /kill.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _kill:: 4 | xor eax, eax 5 | mov al, _SYSCALL_ARGCPY 6 | int 030H 7 | mov ecx, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 8 | test ecx, ecx 9 | jnz _kill_start 10 | _kill_error: 11 | xor eax, eax 12 | mov al, _SYSCALL_WRITE 13 | mov ebx, _TELETYPE_CURRENT 14 | mov ecx, _kill_invalid 15 | mov edx, _kill_invalid.sizeof 16 | int 030H 17 | mov ebx, (not 0H) 18 | jmp _kill_exit 19 | _kill_start: 20 | mov esi, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 21 | call _vdso_atoi 22 | jc _kill_error 23 | jecxz _kill_error 24 | mov ebp, eax 25 | mov al, 020H 26 | mov edi, esi 27 | rep scasb 28 | lea esi, [edi-1H] 29 | inc ecx 30 | call _vdso_atoi 31 | jc _kill_error 32 | mov edi, esi 33 | mov esi, eax 34 | jecxz _kill_send 35 | mov al, 020H 36 | rep scasb 37 | jnz _kill_error 38 | _kill_send: 39 | xor eax, eax 40 | mov al, _SYSCALL_KILL 41 | mov ebx, esi 42 | mov ecx, ebp 43 | int 030H 44 | xor ebx, ebx 45 | _kill_exit: 46 | xor eax, eax 47 | mov al, _SYSCALL_EXIT 48 | int 030H 49 | _kill_invalid string "kill invalid usage", 00AH 50 | _kill.sizeof = ($ - $$) 51 | end virtual 52 | 53 | -------------------------------------------------------------------------------- /login.inc: -------------------------------------------------------------------------------- 1 | 2 | _USERNAME_MAX = 010H 3 | _PASSWORD_MAX = _MD5_DIGEST 4 | 5 | struct _record _username*, _password*, _uid* 6 | .username string _username 7 | times (_USERNAME_MAX - .username.sizeof) db 0H 8 | .password string _password 9 | times (_PASSWORD_MAX - .password.sizeof) db 0H 10 | .uid: dd (_uid) 11 | ends 12 | 13 | _TELETYPE_ID = _USER_STACK_VIRTUAL 14 | 15 | _user_code _login 16 | ;rept 400H { nop } 17 | xor eax, eax 18 | mov al, _SYSCALL_WRITE 19 | mov ebx, _TELETYPE_CURRENT 20 | mov ecx, _login_clear 21 | mov edx, _login_clear.sizeof 22 | int 030H 23 | mov eax, _SYSCALL_WRITE 24 | mov ebx, _TELETYPE_CURRENT 25 | mov ecx, _login_newline 26 | mov edx, 1H 27 | int 030H 28 | mov eax, _SYSCALL_UNAME 29 | lea ebx, [esp-(_UNAME_SIZE+1H)] 30 | int 030H 31 | mov word [ebx+eax], 020H 32 | mov ecx, ebx 33 | lea edx, [eax+1H] 34 | mov eax, _SYSCALL_WRITE 35 | mov ebx, _TELETYPE_CURRENT 36 | int 030H 37 | mov eax, _SYSCALL_IOCTL 38 | mov ebx, _TELETYPE_CURRENT 39 | mov ecx, TIOCGTTYID 40 | mov edx, _TELETYPE_ID 41 | int 030H 42 | mov eax, dword [edx] 43 | add al, (030H + 1H) 44 | lea ebx, [esp-_login_tty.sizeof] 45 | mov edi, ebx 46 | mov esi, _login_tty 47 | mov ecx, _login_tty.sizeof 48 | rep movsb 49 | mov byte [ebx+4H], al 50 | mov eax, _SYSCALL_WRITE 51 | mov ecx, ebx 52 | mov ebx, _TELETYPE_CURRENT 53 | mov edx, _login_tty.sizeof 54 | int 030H 55 | mov eax, _SYSCALL_WRITE 56 | mov ebx, _TELETYPE_CURRENT 57 | mov ecx, _login_newline 58 | mov edx, 2H 59 | int 030H 60 | mov eax, _SYSCALL_AMAP 61 | xor ebx, ebx 62 | xor ecx, ecx 63 | mov cl, 1H 64 | mov edx, (_PROT_READ or _PROT_WRITE) 65 | xor esi, esi 66 | int 030H 67 | mov ebp, eax 68 | mov eax, _SYSCALL_GUID 69 | int 030H 70 | _login_start: 71 | call _login_termios_restore 72 | xor al, al 73 | mov edi, ebp 74 | mov ecx, _record.sizeof 75 | rep stosb 76 | xor eax, eax 77 | mov al, _SYSCALL_WRITE 78 | mov ebx, _TELETYPE_CURRENT 79 | mov ecx, _login_username 80 | mov edx, _login_username.sizeof 81 | int 030H 82 | xor eax, eax 83 | mov al, _SYSCALL_READ 84 | mov ebx, _TELETYPE_CURRENT 85 | lea ecx, [ebp+_record.username] 86 | xor edx, edx 87 | mov dl, _USERNAME_MAX 88 | int 030H 89 | test eax, eax 90 | jz $+7H 91 | mov byte [ecx+eax-1H], 0H 92 | call _login_tcgets 93 | and word [edx+_termios.lflag], (not ECHO) 94 | call _login_tcsetsf 95 | xor eax, eax 96 | mov al, _SYSCALL_WRITE 97 | mov ebx, _TELETYPE_CURRENT 98 | mov ecx, _login_password 99 | mov edx, _login_password.sizeof 100 | int 030H 101 | xor eax, eax 102 | mov al, _SYSCALL_READ 103 | mov ebx, _TELETYPE_CURRENT 104 | lea ecx, [ebp+_record.password] 105 | xor edx, edx 106 | mov dl, _PASSWORD_MAX 107 | 108 | mov esi, ebp 109 | 110 | int 030H 111 | mov esi, eax 112 | test eax, eax 113 | jz $+8H 114 | mov byte [ecx+eax-1H], 0H 115 | dec esi 116 | mov ebx, ecx 117 | mov edx, ecx 118 | mov ecx, esi 119 | xor eax, eax 120 | mov al, _SYSCALL_MD5 121 | int 030H 122 | mov ebx, _login_record 123 | mov edx, ((_login_record_end - _login_record) / _record.sizeof) 124 | _login_loop: 125 | mov edi, ebx 126 | mov esi, ebp 127 | mov ecx, _record.uid 128 | assert (_record.uid) 129 | rep cmpsb 130 | jz _login_found 131 | dec edx 132 | jz _login_mismatch 133 | add ebx, _record.sizeof 134 | jmp _login_loop 135 | _login_found: 136 | xor eax, eax 137 | mov al, _SYSCALL_FORK 138 | int 030H 139 | test eax, eax 140 | jz _login_shell 141 | mov ebx, eax 142 | xor eax, eax 143 | mov al, _SYSCALL_WAITPID 144 | xor ecx, ecx 145 | mov edx, WEXITED 146 | int 030H 147 | jp _login_start 148 | _login_shell: 149 | mov esi, ebx 150 | call _login_termios_restore 151 | mov eax, _SYSCALL_SSID 152 | int 030H 153 | mov dword [esp-4H], eax 154 | mov eax, _SYSCALL_IOCTL 155 | mov ebx, dword [_TELETYPE_ID] 156 | mov ecx, TIOCSCTTY 157 | int 030H 158 | xor eax, eax 159 | mov al, _SYSCALL_IOCTL 160 | mov ebx, dword [_TELETYPE_ID] 161 | mov ecx, TIOCSPGRP 162 | lea edx, [esp-4H] 163 | int 030H 164 | mov eax, _SYSCALL_SUID 165 | mov ebx, dword [esi+_record.uid] 166 | int 030H 167 | mov eax, _SYSCALL_EXEC 168 | mov ebx, _shell_payload 169 | mov ecx, _shell.sizeof 170 | int 030H 171 | mov eax, _SYSCALL_EXIT 172 | int 030H 173 | _login_mismatch: 174 | mov eax, _SYSCALL_WRITE 175 | mov ebx, _TELETYPE_CURRENT 176 | mov ecx, _login_incorrect 177 | mov edx, _login_incorrect.sizeof 178 | int 030H 179 | jmp _login_start 180 | 181 | _login_termios_restore: 182 | call _login_tcgets 183 | or dword [edx+_termios.oflag], OPOST 184 | or word [edx+_termios.iflag], (ICRNL or ISTRIP or IXON) 185 | or word [edx+_termios.lflag], (ICANON or ECHO or ECHOE or ECHOK or IEXTEN) 186 | ;or word [edx+_termios.lflag], (TOSTOP) 187 | and word [edx+_termios.lflag], (not ISIG) 188 | jmp _login_tcsetsf 189 | 190 | _login_tcgets: 191 | ; out: edx - termios data pointer 192 | xor eax, eax 193 | mov al, _SYSCALL_IOCTL 194 | mov ebx, _TELETYPE_CURRENT 195 | mov ecx, TCGETS 196 | lea edx, [esp-_termios.sizeof] 197 | int 030H 198 | ret 199 | 200 | _login_tcsetsf: 201 | ; in: edx - termios data pointer 202 | xor eax, eax 203 | mov al, _SYSCALL_IOCTL 204 | mov ebx, _TELETYPE_CURRENT 205 | mov ecx, TCSETSF 206 | int 030H 207 | ret 208 | 209 | _login_record: 210 | _maoko _record "maoko", "E13F65CB8405426C5DF4D661DEEE221E", _ROOT_UID 211 | _louis _record "louis", "AEBD920A5BF16E5B4518162A29EA728A", _ROOT_UID 212 | _guest _record "guest", "084E0343A0486FF05530DF6C705C8BB4", _GUEST_UID 213 | _login_record_end: 214 | 215 | _login_username string "login: " 216 | _login_password string "password: " 217 | _login_incorrect string "login incorrect", 00AH 218 | _login_newline: dw 00A0AH 219 | _login_tty string "(tty_)" 220 | _login_clear string _ESCAPE, _ESCAPE_CLEAR 221 | ;align 010H 222 | ;_login_aes_key string "AssemblyIsBetter" 223 | ;assert (_login_aes_key.sizeof = 010H) 224 | _extract _shell 225 | end _user_code 226 | 227 | -------------------------------------------------------------------------------- /md5.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _md5 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | mov ebp, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 7 | test ebp, ebp 8 | jnz _md5_hash 9 | xor eax, eax 10 | mov al, _SYSCALL_WRITE 11 | mov ebx, _TELETYPE_CURRENT 12 | mov ecx, _md5_invalid 13 | mov edx, (_md5_invalid.sizeof + 1H) 14 | int 030H 15 | mov ebx, (not 0H) 16 | jmp _md5_exit 17 | _md5_hash: 18 | xor eax, eax 19 | mov al, _SYSCALL_WRITE 20 | mov ebx, _TELETYPE_CURRENT 21 | mov ecx, _md5_head 22 | mov edx, _md5_head.sizeof 23 | int 030H 24 | xor eax, eax 25 | mov al, _SYSCALL_WRITE 26 | mov ecx, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 27 | mov edx, ebp 28 | int 030H 29 | xor eax, eax 30 | mov al, _SYSCALL_WRITE 31 | mov ecx, _md5_tail 32 | mov edx, _md5_tail.sizeof 33 | int 030H 34 | xor eax, eax 35 | mov al, _SYSCALL_MD5 36 | mov ebx, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 37 | mov ecx, ebp 38 | lea edx, [esp-_MD5_DIGEST] 39 | int 030H 40 | xor eax, eax 41 | mov al, _SYSCALL_WRITE 42 | mov ebx, _TELETYPE_CURRENT 43 | lea ecx, [esp-_MD5_DIGEST] 44 | mov edx, _MD5_DIGEST 45 | int 030H 46 | xor eax, eax 47 | mov al, _SYSCALL_WRITE 48 | mov ebx, _TELETYPE_CURRENT 49 | mov ecx, _md5_newline 50 | xor edx, edx 51 | inc dl 52 | int 030H 53 | xor ebx, ebx 54 | _md5_exit: 55 | xor eax, eax 56 | mov al, _SYSCALL_EXIT 57 | int 030H 58 | _md5_head string "md5(""" 59 | _md5_tail string """) = " 60 | _md5_invalid string "md5 invalid usage" 61 | _md5_newline: db 00AH 62 | _md5.sizeof = ($ - $$) 63 | end _user_code 64 | -------------------------------------------------------------------------------- /paging.py: -------------------------------------------------------------------------------- 1 | 2 | # HELPER FUNCTION FOR PAGING 3 | 4 | def _dump_1th_paging(address): 5 | print("OFFSET =", hex(address & 0xFFF)) 6 | print("PAGE TABLE INDEX =", hex((address >> 0xC) & 0x3FF)) 7 | print("PAGE DIRECTORY INDEX =", hex((address >> 0x16) & 0x3FF)); 8 | 9 | def _dump_2th_paging(address): 10 | print("OFFSET =", hex(address & 0xFFF)) 11 | print("PAGE TABLE INDEX =", hex((address >> 0xC) & 0x1FF)) 12 | print("PAGE DIRECTORY INDEX =", hex((address >> 0x15) & 0x1FF)); 13 | print("PAGE DIRECTORY POINTER INDEX =", hex((address >> 0x1E) & 0x3)); 14 | 15 | def _dump_3th_paging(address): 16 | print("OFFSET =", hex(address & 0xFFF)) 17 | print("PAGE TABLE INDEX =", hex((address >> 0xC) & 0x1FF)) 18 | print("PAGE DIRECTORY INDEX =", hex((address >> 0x15) & 0x1FF)); 19 | print("PAGE DIRECTORY POINTER INDEX =", hex((address >> 0x1E) & 0x1FF)); 20 | print("PAGE LEVEL MAP 4 INDEX =", hex((address >> 0x27) & 0x1FF)); 21 | _canonical = (address >> 0x30) 22 | _extend = (address & (0x1 << 0x2F)) 23 | if ((_canonical == 0xFFFF) and (_extend)): print("HIGHER HALF") 24 | elif ((_canonical == 0x00) and (not _extend)): print("LOWER HALF") 25 | else: print("INVALID") 26 | 27 | _dump_2th_paging(0x00000000ffdfb000) 28 | -------------------------------------------------------------------------------- /print.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _print 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | mov ebp, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 7 | test ebp, ebp 8 | jnz _print_string 9 | xor eax, eax 10 | mov al, _SYSCALL_WRITE 11 | mov ebx, _TELETYPE_CURRENT 12 | mov ecx, _print_invalid 13 | mov edx, _print_invalid.sizeof 14 | int 030H 15 | jmp _print_exit 16 | _print_string: 17 | mov ecx, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 18 | mov edx, ebp 19 | _print_loop: 20 | xor eax, eax 21 | mov al, _SYSCALL_WRITE 22 | int 030H 23 | test eax, eax 24 | jns _print_loop 25 | _print_exit: 26 | xor eax, eax 27 | mov al, _SYSCALL_EXIT 28 | int 030H 29 | _print_invalid string "print need an arguments", 00AH 30 | end _user_code 31 | -------------------------------------------------------------------------------- /reboot.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _reboot 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _reboot_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _reboot_invalid 12 | mov edx, _reboot_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _reboot_exit 16 | _reboot_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_REBOOT 19 | mov ebx, _REBOOT_MAGIC1 20 | mov ecx, _REBOOT_MAGIC2 21 | mov edx, _REBOOT_CMD_RESTART 22 | int 030H 23 | xor eax, eax 24 | mov al, _SYSCALL_WRITE 25 | mov ebx, _TELETYPE_CURRENT 26 | mov ecx, _reboot_permission 27 | mov edx, _reboot_permission.sizeof 28 | int 030H 29 | xor ebx, ebx 30 | _reboot_exit: 31 | xor eax, eax 32 | mov al, _SYSCALL_EXIT 33 | int 030H 34 | _reboot_permission string "reboot permission denied", 00AH 35 | _reboot_invalid string "reboot invalid usage", 00AH 36 | end _user_code 37 | -------------------------------------------------------------------------------- /resolution.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _resolution:: 4 | xor eax, eax 5 | mov al, _SYSCALL_ARGCPY 6 | int 030H 7 | mov ecx, dword [_USER_SHELL_ARGUMENT_VIRTUAL] 8 | test ecx, ecx 9 | jnz _resolution_start 10 | _resolution_error: 11 | xor eax, eax 12 | mov al, _SYSCALL_WRITE 13 | mov ebx, _TELETYPE_CURRENT 14 | mov ecx, _resolution_invalid 15 | mov edx, _resolution_invalid.sizeof 16 | int 030H 17 | mov ebx, (not 0H) 18 | jmp _resolution_exit 19 | _resolution_start: 20 | mov esi, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 21 | call _vdso_atoi 22 | jc _resolution_error 23 | jecxz _resolution_error 24 | mov ebp, eax 25 | mov al, 020H 26 | mov edi, esi 27 | rep scasb 28 | lea esi, [edi-1H] 29 | inc ecx 30 | call _vdso_atoi 31 | jc _resolution_error 32 | mov edi, esi 33 | mov esi, eax 34 | jecxz _resolution_change 35 | mov al, 020H 36 | rep scasb 37 | jnz _resolution_error 38 | _resolution_change: 39 | xor eax, eax 40 | mov al, _SYSCALL_IOCTL 41 | mov ebx, _TELETYPE_CURRENT 42 | xor ecx, ecx 43 | mov cl, TIOCSWINSZ 44 | lea edx, [esp-_winsize.sizeof] 45 | mov word [edx+_winsize.ws_xpixel], bp 46 | mov word [edx+_winsize.ws_ypixel], si 47 | int 030H 48 | test eax, eax 49 | jns _resolution_exit-2H 50 | xor eax, eax 51 | mov al, _SYSCALL_WRITE 52 | mov ebx, _TELETYPE_CURRENT 53 | mov ecx, _resolution_permission 54 | mov edx, _resolution_permission.sizeof 55 | int 030H 56 | xor ebx, ebx 57 | _resolution_exit: 58 | xor eax, eax 59 | mov al, _SYSCALL_EXIT 60 | int 030H 61 | _resolution_permission string "resolution permission denied", 00AH 62 | _resolution_invalid string "resolution invalid usage", 00AH 63 | _resolution.sizeof = ($ - $$) 64 | end virtual 65 | -------------------------------------------------------------------------------- /segvtest.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _segvtest 3 | mov dword [0H], 0DEADC0DEH 4 | end _user_code 5 | -------------------------------------------------------------------------------- /server.inc: -------------------------------------------------------------------------------- 1 | 2 | macro _print_error _string* 3 | { 4 | xor eax, eax 5 | mov al, _SYSCALL_WRITE 6 | mov ebx, _TELETYPE_CURRENT 7 | mov ecx, _string 8 | mov edx, _string#.sizeof 9 | int 030H 10 | } 11 | 12 | _SERVER_BUFFER = 0100H 13 | _SERVER_PORT = 050H 14 | 15 | virtual at _USER_CODE_VIRTUAL 16 | _server:: 17 | rept 0123H { nop } 18 | 19 | xor eax, eax 20 | mov al, _SYSCALL_OPEN 21 | int 030H 22 | test eax, eax 23 | js _server_filde_error 24 | mov ebp, eax 25 | xor eax, eax 26 | mov al, _SYSCALL_BIND 27 | mov ebx, ebp 28 | xor ecx, ecx 29 | mov cl, _SERVER_PORT 30 | int 030H 31 | test eax, eax 32 | js _server_bind_error 33 | lea edi, [esp-_SERVER_BUFFER-1H] 34 | _server_loop: 35 | xor eax, eax 36 | mov al, _SYSCALL_WRITE 37 | mov ebx, _TELETYPE_CURRENT 38 | mov ecx, _server_listen 39 | mov edx, _server_listen.sizeof 40 | int 030H 41 | xor eax, eax 42 | mov al, _SYSCALL_LISTEN 43 | mov ebx, _SERVER_PORT 44 | int 030H 45 | xor eax, eax 46 | mov al, _SYSCALL_RECEIVE 47 | mov ebx, ebp 48 | mov ecx, edi 49 | mov edx, _SERVER_BUFFER 50 | int 030H 51 | mov esi, eax 52 | 53 | mov byte [edi+esi], 00AH 54 | cmp esi, 4H 55 | jnz _server_print 56 | mov edx, dword [edi] 57 | cmp edx, "QUIT" 58 | jnz _server_print 59 | xor ebx, ebx 60 | jmp _server_exit 61 | _server_print: 62 | xor eax, eax 63 | mov al, _SYSCALL_WRITE 64 | mov ebx, _TELETYPE_CURRENT 65 | mov ecx, _server_receive 66 | mov edx, _server_receive.sizeof 67 | int 030H 68 | 69 | xor eax, eax 70 | mov al, _SYSCALL_WRITE 71 | mov ebx, _TELETYPE_CURRENT 72 | mov ecx, edi 73 | lea edx, [esi+1H] 74 | int 030H 75 | 76 | jmp _server_loop 77 | 78 | _server_filde_error: 79 | _print_error _server_filde 80 | jmp _server_error 81 | _server_bind_error: 82 | _print_error _server_bind 83 | _server_error: 84 | xor ebx, ebx 85 | not ebx 86 | _server_exit: 87 | xor eax, eax 88 | mov al, _SYSCALL_EXIT 89 | int 030H 90 | 91 | _server_filde string "The server can't open a socket", 00AH 92 | _server_bind string "The server can't bind to port 80", 00AH 93 | _server_listen string "Server listening on port 80 ...", 00AH 94 | _server_receive string "You have received the string : " 95 | _server.sizeof = ($ - $$) 96 | end virtual 97 | 98 | -------------------------------------------------------------------------------- /shell.inc: -------------------------------------------------------------------------------- 1 | 2 | _ORIGINAL_TERMIOS = _USER_STACK_VIRTUAL 3 | 4 | _SHELL_BUFFER_INTERNAL = 0DEAD000H 5 | _USER_COMMAND_SIZE = 200H 6 | 7 | struct _line_instance _buffer*, _length* 8 | .buffer: db _buffer 9 | times (_USER_COMMAND_SIZE - ($ - .buffer)) db 0H 10 | .length: dd (_length) 11 | ends 12 | 13 | define _SIZE_HISTORY 010H 14 | struct _shell_aggregate _buffer*, _length*, _cpybuf*, _cpylen*, _cursor*, _insert*, _hstste*, _hstidx*, _hstcnt*, _tmpbuf*, _tmplen*,\ 15 | _ws_row*, _ws_col*, _ws_xpixel*, _ws_ypixel*, _pid*, _tty*, _wait* 16 | .command _line_instance (_buffer), (_length) 17 | .copy _line_instance (_cpybuf), (_cpylen) 18 | .cursor: dd (_cursor) 19 | .insert: db (_insert) 20 | .hstste: db (_hstste) 21 | .hstidx: db (_hstidx) 22 | .hstcnt: db (_hstcnt) 23 | .hsttlb: 24 | rept _SIZE_HISTORY i:0H \{ dd .history_\#i \} 25 | rept _SIZE_HISTORY i:0H \{ .history_\#i _line_instance 0H, 0H \} 26 | .temporary _line_instance (_tmpbuf), (_tmplen) 27 | .winsize _winsize _ws_row, _ws_col, _ws_xpixel, _ws_ypixel 28 | .pid: dd (_pid) 29 | .tty: dd (_tty) 30 | .wait: dd (_wait) 31 | ends 32 | 33 | virtual at _USER_CODE_VIRTUAL 34 | _shell:: 35 | ;rept 400H { nop } 36 | call _shell_allocate_struct 37 | call _shell_set_raw_mode 38 | xor eax, eax 39 | mov al, _SYSCALL_SIGNAL 40 | mov ebx, SIGHUP 41 | mov ecx, _shell_sighup 42 | int 030H 43 | xor eax, eax 44 | mov al, _SYSCALL_SIGNAL 45 | mov ebx, SIGINT 46 | mov ecx, _shell_sigint_handler 47 | int 030H 48 | xor eax, eax 49 | mov al, _SYSCALL_GPID 50 | int 030H 51 | mov dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.pid], eax 52 | call _shell_enable_history 53 | _shell_restart: 54 | call _shell_prompt 55 | _shell_loop: 56 | call _shell_read_one_character 57 | cmp al, 00DH 58 | jz _shell_process_command 59 | cmp al, 07FH 60 | jz _shell_remove 61 | cmp al, _ESCAPE 62 | jz _shell_escape 63 | cmp al, 1H ; ctrl-A 64 | mov ecx, _shell_begin_cursor 65 | jz _shell_predicate 66 | cmp al, 5H ; ctrl-E 67 | mov ecx, _shell_end_cursor 68 | jz _shell_predicate 69 | cmp al, 00BH ; ctrl-K 70 | mov ecx, _shell_truncate 71 | jz _shell_predicate 72 | cmp al, 016H ; ctrl-V 73 | jnz _shell_save 74 | mov eax, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.copy.buffer) 75 | mov ebx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.copy.length] 76 | jmp _shell_insert 77 | _shell_escape: 78 | call _shell_read_one_character 79 | cmp al, _ESC_LEFT_ARROW 80 | mov ecx, _shell_cursor_backward 81 | jz _shell_predicate 82 | cmp al, _ESC_RIGHT_ARROW 83 | mov ecx, _shell_cursor_forward 84 | jz _shell_predicate 85 | cmp al, _ESC_UP_ARROW 86 | mov ecx, _shell_move_up_history 87 | jz _shell_predicate 88 | cmp al, _ESC_DOWN_ARROW 89 | mov ecx, _shell_move_down_history 90 | jz _shell_predicate 91 | 92 | jmp _shell_loop 93 | _shell_save: 94 | mov eax, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.insert) 95 | xor ebx, ebx 96 | inc bl 97 | _shell_insert: 98 | call _shell_command_insert 99 | jmp _shell_loop 100 | _shell_predicate: 101 | call ecx 102 | jmp _shell_loop 103 | _shell_remove: 104 | call _shell_command_remove 105 | jmp _shell_loop 106 | 107 | _shell_process_command: 108 | call _shell_print_newline 109 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 110 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.command.buffer) 111 | call _shell_skip_whitespace 112 | jz _shell_process_command_validate 113 | irp _kind*, help,copyright,uid,uname,shutdown,reboot,hostname,fg,bg,resolution,clear,sigint,usertest,segvtest,kill,sockpoc,sqrt,md5,bomb,invopcode,showpid,print 114 | { 115 | mov eax, _shell_#_kind#.sizeof 116 | mov ebx, _#_kind#_payload 117 | mov esi, _shell_#_kind 118 | mov ebp, _#_kind#.sizeof 119 | call _shell_parse_command 120 | jnc _shell_process_command_validate 121 | } 122 | push _shell_process_command_validate 123 | irp _kind*, history,copy,exit 124 | { 125 | mov eax, _shell_#_kind#.sizeof 126 | mov esi, _shell_#_kind 127 | call _shell_word_compare 128 | jnc _shell_#_kind#_command 129 | } 130 | lea esp, [esp+4H] 131 | call _shell_command_unknown 132 | _shell_process_command_validate: 133 | call _shell_save_history 134 | xor eax, eax 135 | mov ecx, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 136 | mov dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length], eax 137 | mov dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor], eax 138 | mov edi, _SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer 139 | rep stosb 140 | jmp _shell_restart 141 | 142 | _shell_set_raw_mode: 143 | xor eax, eax 144 | mov al, _SYSCALL_IOCTL 145 | mov ebx, _TELETYPE_CURRENT 146 | mov ecx, TCGETS 147 | lea edx, [esp-_termios.sizeof] 148 | int 030H 149 | and dword [edx+_termios.iflag], (not (ICRNL or ISTRIP or IXON)) 150 | and dword [edx+_termios.oflag], (not OPOST) 151 | and dword [edx+_termios.lflag], (not (ECHO or ICANON or IEXTEN or ISIG)) 152 | mov byte [edx+_termios.vmin], 0H 153 | xor eax, eax 154 | mov al, _SYSCALL_IOCTL 155 | mov ebx, _TELETYPE_CURRENT 156 | mov ecx, TCSETSF 157 | int 030H 158 | ret 159 | 160 | _shell_set_cook_mode: 161 | xor eax, eax 162 | mov al, _SYSCALL_IOCTL 163 | mov ebx, _TELETYPE_CURRENT 164 | mov ecx, TCGETS 165 | lea edx, [esp-_termios.sizeof] 166 | int 030H 167 | or dword [edx+_termios.oflag], OPOST 168 | or dword [edx+_termios.iflag], (ICRNL or ISTRIP or IXON) 169 | or dword [edx+_termios.lflag], (ECHO or ICANON or IEXTEN or ISIG) 170 | xor eax, eax 171 | mov al, _SYSCALL_IOCTL 172 | mov ebx, _TELETYPE_CURRENT 173 | mov ecx, TCSETSF 174 | int 030H 175 | ret 176 | 177 | _shell_prompt: 178 | xor eax, eax 179 | mov al, _SYSCALL_GUID 180 | int 030H 181 | cmp eax, _ROOT_UID 182 | jz _shell_prompt_root 183 | mov ecx, _shell_user 184 | mov edx, _shell_user.sizeof 185 | jmp _shell_prompt_display 186 | _shell_prompt_root: 187 | mov ecx, _shell_root 188 | mov edx, _shell_root.sizeof 189 | _shell_prompt_display: 190 | xor eax, eax 191 | mov al, _SYSCALL_WRITE 192 | mov ebx, _TELETYPE_CURRENT 193 | int 030H 194 | xor eax, eax 195 | mov al, _SYSCALL_WRITE 196 | mov ebx, _TELETYPE_CURRENT 197 | mov ecx, _shell_space 198 | mov edx, _shell_space.sizeof 199 | int 030H 200 | ret 201 | 202 | _shell_command_shift: 203 | jecxz _shell_command_shift_exit 204 | rep movsb 205 | _shell_command_shift_exit: 206 | cld 207 | ret 208 | 209 | _shell_command_remove: 210 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 211 | jecxz _shell_command_remove_exit 212 | lea edi, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+ecx-1H] 213 | lea esi, [edi+1H] 214 | mov edx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 215 | mov ebx, edx 216 | xchg edx, ecx 217 | sub ecx, edx 218 | push ebx edi ecx 219 | call _shell_command_shift 220 | call _shell_cursor_backward 221 | mov ebx, dword [esp+8H] 222 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+ebx-1H], 020H 223 | call _shell_hide_save_cursor 224 | pop ecx edi 225 | xor eax, eax 226 | mov al, _SYSCALL_WRITE 227 | mov ebx, _TELETYPE_CURRENT 228 | lea edx, [ecx+1H] 229 | mov ecx, edi 230 | int 030H 231 | call _shell_restore_show_cursor 232 | pop ebx 233 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+ebx-1H], 0H 234 | dec dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 235 | _shell_command_remove_exit: 236 | ret 237 | 238 | _shell_command_insert: 239 | ; in: 240 | ; eax - input buffer 241 | ; ebx - number of character to insert 242 | ; preserves: eax, ebp 243 | push eax ebp 244 | mov ecx, _USER_COMMAND_SIZE 245 | mov edx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 246 | sub ecx, edx ; remain length in the buffer 247 | jbe _shell_command_insert_exit 248 | cmp ebx, ecx 249 | cmovb ecx, ebx 250 | test ecx, ecx 251 | jz _shell_command_insert_exit 252 | lea esi, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+edx-1H] 253 | lea edi, [esi+ecx] 254 | mov ebp, ecx 255 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 256 | sub edx, ecx 257 | xchg ecx, edx ; size of string to shift 258 | mov ebx, ecx 259 | std 260 | call _shell_command_shift 261 | mov ecx, ebp 262 | add dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor], ecx 263 | add dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length], ecx 264 | mov esi, eax 265 | lea edi, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+edx] 266 | mov edx, edi 267 | rep movsb 268 | mov esi, ebx 269 | xor eax, eax 270 | mov al, _SYSCALL_WRITE 271 | mov ecx, edx 272 | mov edx, ebp 273 | mov ebx, _TELETYPE_CURRENT 274 | int 030H 275 | test esi, esi 276 | jz _shell_command_insert_exit 277 | lea edi, [ecx+ebp] 278 | call _shell_hide_save_cursor 279 | xor eax, eax 280 | mov al, _SYSCALL_WRITE 281 | mov ecx, edi 282 | mov edx, esi 283 | int 030H 284 | call _shell_restore_show_cursor 285 | _shell_command_insert_exit: 286 | pop ebp eax 287 | ret 288 | 289 | _shell_read_one_character: 290 | xor eax, eax 291 | mov al, _SYSCALL_READ 292 | mov ebx, _TELETYPE_CURRENT 293 | mov ecx, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.insert) 294 | xor edx, edx 295 | inc dl 296 | int 030H 297 | movzx eax, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.insert] 298 | ret 299 | 300 | _shell_cursor_forward: 301 | ; preserves: esi, edi, ebp 302 | mov eax, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 303 | cmp eax, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 304 | jae _shell_cursor_forward_exit 305 | inc dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 306 | call _shell_get_winsize 307 | movzx esi, word [ebx+_winsize.ws_row] 308 | movzx edi, word [ebx+_winsize.ws_col] 309 | call _shell_request_cursor_position 310 | dec edi 311 | cmp edx, edi 312 | jnz _shell_cursor_forward_escape 313 | mov ebp, edx 314 | call _shell_hide_cursor 315 | xor eax, eax 316 | mov al, _SYSCALL_WRITE 317 | mov ebx, _TELETYPE_CURRENT 318 | mov ecx, _move_down 319 | mov edx, _move_down.sizeof 320 | int 030H 321 | call _shell_get_first_column 322 | jmp _shell_cursor_forward_exit 323 | _shell_cursor_forward_escape: 324 | xor eax, eax 325 | mov al, _SYSCALL_WRITE 326 | mov ebx, _TELETYPE_CURRENT 327 | mov ecx, _move_right 328 | mov edx, _move_right.sizeof 329 | int 030H 330 | _shell_cursor_forward_exit: 331 | ret 332 | 333 | _shell_cursor_backward: 334 | ; preserves: esi, edi 335 | mov eax, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 336 | test eax, eax 337 | jz _shell_cursor_backward_exit 338 | dec dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 339 | call _shell_request_cursor_position 340 | test dx, dx 341 | jnz _shell_cursor_backward_escape 342 | xor eax, eax 343 | call _shell_hide_cursor 344 | mov al, _SYSCALL_WRITE 345 | mov ebx, _TELETYPE_CURRENT 346 | mov ecx, _move_up 347 | mov edx, _move_up.sizeof 348 | int 030H 349 | call _shell_get_winsize 350 | movzx ebp, word [ebx+_winsize.ws_col] 351 | dec ebp 352 | call _shell_get_last_column 353 | jmp _shell_cursor_backward_exit 354 | _shell_cursor_backward_escape: 355 | xor eax, eax 356 | mov al, _SYSCALL_WRITE 357 | mov ebx, _TELETYPE_CURRENT 358 | mov ecx, _move_left 359 | mov edx, _move_left.sizeof 360 | int 030H 361 | _shell_cursor_backward_exit: 362 | ret 363 | 364 | _shell_allocate_struct: 365 | xor eax, eax 366 | mov al, _SYSCALL_AMAP 367 | mov ebx, _SHELL_BUFFER_INTERNAL 368 | mov ecx, _shell_aggregate.sizeof 369 | mov edx, (_PROT_READ or _PROT_WRITE) 370 | mov esi, _AMAP_FIXED 371 | int 030H 372 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.hsttlb) 373 | lea eax, [edi+_SIZE_HISTORY*4H] 374 | mov ecx, _SIZE_HISTORY 375 | jecxz _shell_allocate_struct_exit 376 | _shell_allocate_struct_loop: 377 | stosd 378 | add eax, _line_instance.sizeof 379 | loop _shell_allocate_struct_loop 380 | _shell_allocate_struct_exit: 381 | ret 382 | 383 | _shell_request_cursor_position: 384 | ; out: 385 | ; eax - row position 386 | ; edx - column position 387 | push edi ebp 388 | xor eax, eax 389 | mov al, _SYSCALL_WRITE 390 | mov ebx, _TELETYPE_CURRENT 391 | mov ecx, _position_cursor 392 | mov edx, _position_cursor.sizeof 393 | int 030H 394 | _shell_request_cursor_position_loop: 395 | call _shell_read_one_character 396 | cmp al, _ESCAPE 397 | jnz _shell_request_cursor_position_loop 398 | call _shell_read_one_character 399 | cmp al, _ESCAPE_CURSOR_RECEIVE 400 | jnz _shell_request_cursor_position_loop 401 | xor ebp, ebp 402 | xor edi, edi 403 | _shell_request_cursor_position_convert: 404 | call _shell_read_one_character 405 | cmp edi, 4H 406 | jz _shell_request_cursor_position_update 407 | sub al, 030H 408 | cmp al, 9H 409 | jbe _shell_request_cursor_position_or 410 | sub al, 7H 411 | _shell_request_cursor_position_or: 412 | shl ebp, 4H 413 | or ebp, eax 414 | _shell_request_cursor_position_update: 415 | inc edi 416 | cmp edi, 8H 417 | jbe _shell_request_cursor_position_convert 418 | xor eax, eax 419 | mov al, _SYSCALL_IOCTL 420 | mov ebx, _TELETYPE_CURRENT 421 | mov ecx, TCFLSH 422 | int 030H 423 | movzx edx, bp 424 | shr ebp, 010H 425 | movzx eax, bp 426 | pop ebp edi 427 | ret 428 | 429 | _shell_get_winsize: 430 | xor eax, eax 431 | mov al, _SYSCALL_IOCTL 432 | mov ebx, _TELETYPE_CURRENT 433 | mov ecx, TIOCGWINSZ 434 | mov edx, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.winsize) 435 | int 030H 436 | mov ebx, edx 437 | ret 438 | 439 | _shell_get_last_column: 440 | ; in: ebp - count 441 | call _shell_cursor_forward_escape 442 | dec ebp 443 | jnz _shell_get_last_column 444 | jmp _shell_show_cursor 445 | 446 | _shell_get_first_column: 447 | ; in: ebp - count 448 | call _shell_cursor_backward_escape 449 | dec ebp 450 | jnz _shell_get_first_column 451 | jmp _shell_show_cursor 452 | 453 | _shell_save_cursor: 454 | xor eax, eax 455 | mov al, _SYSCALL_WRITE 456 | mov ebx, _TELETYPE_CURRENT 457 | mov ecx, _save_cursor 458 | mov edx, _save_cursor.sizeof 459 | int 030H 460 | ret 461 | 462 | _shell_restore_cursor: 463 | xor eax, eax 464 | mov al, _SYSCALL_WRITE 465 | mov ebx, _TELETYPE_CURRENT 466 | mov ecx, _restore_cursor 467 | mov edx, _restore_cursor.sizeof 468 | int 030H 469 | ret 470 | 471 | _shell_hide_cursor: 472 | xor eax, eax 473 | mov al, _SYSCALL_WRITE 474 | mov ebx, _TELETYPE_CURRENT 475 | mov ecx, _hide_cursor 476 | mov edx, _hide_cursor.sizeof 477 | int 030H 478 | ret 479 | 480 | _shell_show_cursor: 481 | xor eax, eax 482 | mov al, _SYSCALL_WRITE 483 | mov ebx, _TELETYPE_CURRENT 484 | mov ecx, _show_cursor 485 | mov edx, _show_cursor.sizeof 486 | int 030H 487 | ret 488 | 489 | _shell_skip_whitespace: 490 | ; in: 491 | ; ecx - buffer length 492 | ; edi - buffer 493 | ; out: 494 | ; ecx - updated 495 | ; edi - updated 496 | ; zf - if no whitespace character has been found 497 | test ecx, ecx 498 | jz _shell_skip_whitespace_empty 499 | mov al, 020H 500 | repz scasb 501 | jz _shell_skip_whitespace_empty 502 | lea edi, [edi-1H] 503 | lea ecx, [ecx+1H] 504 | _shell_skip_whitespace_empty: 505 | ret 506 | 507 | _shell_word_compare: 508 | ; in: 509 | ; eax - size of the tested string 510 | ; ecx - size of the command buffer entered by the user 511 | ; edi - command buffer 512 | ; esi - tested string 513 | ; out: cf - set when no match 514 | push edi ecx 515 | xor edx, edx 516 | sub ecx, eax 517 | jc _shell_word_compare_error 518 | setz dl 519 | xchg eax, ecx 520 | repz cmpsb 521 | jnz _shell_word_compare_error 522 | test dl, dl 523 | jnz _shell_word_compare_match 524 | cmp byte [edi], 020H 525 | jnz _shell_word_compare_error 526 | _shell_word_compare_match: 527 | add esp, 8H 528 | clc 529 | mov ecx, eax 530 | ret 531 | _shell_word_compare_error: 532 | stc 533 | pop ecx edi 534 | ret 535 | 536 | _shell_parse_command: 537 | ; in: 538 | ; eax - size of the tested string 539 | ; ebx - user program payload 540 | ; ecx - size of the command buffer entered by the user 541 | ; edi - command buffer 542 | ; esi - tested string 543 | ; ebp - user program payload size 544 | call _shell_word_compare 545 | jc _shell_parse_command_exit 546 | call _shell_skip_whitespace 547 | mov dword [_USER_SHELL_ARGUMENT_VIRTUAL], ecx ; the count of character in the argument immediately after the first argument 548 | mov esi, edi 549 | mov edi, (_USER_SHELL_ARGUMENT_VIRTUAL + 4H) 550 | rep movsb 551 | mov esi, ebx 552 | mov edx, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.tty) 553 | xor eax, eax 554 | mov al, _SYSCALL_IOCTL 555 | mov ebx, _TELETYPE_CURRENT 556 | mov ecx, TIOCGTTYID 557 | int 030H 558 | mov edx, dword [edx] 559 | xor eax, eax 560 | mov al, _SYSCALL_FORK 561 | int 030H 562 | test eax, eax 563 | jz _shell_parse_command_child 564 | mov ebx, eax 565 | xor eax, eax 566 | mov al, _SYSCALL_SPGID 567 | xor ecx, ecx 568 | int 030H 569 | call _shell_take_terminal_control 570 | 571 | push edx 572 | xor eax, eax 573 | mov al, _SYSCALL_WAITPID 574 | mov ebx, _WAIT_ALL 575 | xor ecx, ecx 576 | mov ecx, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.wait) 577 | xor edx, edx 578 | mov dl, (WEXITED or WSTOPPED) 579 | int 030H 580 | pop edx 581 | 582 | push eax 583 | mov eax, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.pid] 584 | call _shell_take_terminal_control 585 | call _shell_set_raw_mode 586 | pop ebp 587 | 588 | cmp byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.wait], _WSTOPPED 589 | clc 590 | jnz _shell_parse_command_exit 591 | xor eax, eax 592 | mov al, _SYSCALL_WRITE 593 | mov ebx, _TELETYPE_CURRENT 594 | mov ecx, _shell_stopped_1 595 | mov edx, _shell_stopped_1.sizeof 596 | int 030H 597 | 598 | mov eax, ebp 599 | call _vdso_itoa 600 | 601 | xor eax, eax 602 | mov al, _SYSCALL_WRITE 603 | mov edx, ecx 604 | mov ecx, ebx 605 | mov ebx, _TELETYPE_CURRENT 606 | int 030H 607 | 608 | xor eax, eax 609 | mov al, _SYSCALL_WRITE 610 | mov ebx, _TELETYPE_CURRENT 611 | mov ecx, _shell_stopped_2 612 | mov edx, _shell_stopped_2.sizeof 613 | int 030H 614 | 615 | call _shell_print_newline 616 | jmp _shell_parse_command_exit 617 | _shell_parse_command_child: 618 | xor eax, eax 619 | mov al, _SYSCALL_GPID 620 | int 030H 621 | mov edi, eax 622 | push 0H 623 | mov edx, esp 624 | _shell_parse_command_child_again: 625 | xor eax, eax 626 | mov al, _SYSCALL_IOCTL 627 | mov ebx, _TELETYPE_CURRENT 628 | mov ecx, TIOCGPGRP 629 | int 030H 630 | cmp dword [edx], edi 631 | jnz _shell_parse_command_child_again 632 | add esp, 4H 633 | call _shell_set_cook_mode 634 | xor eax, eax 635 | mov al, _SYSCALL_EXEC 636 | mov ebx, esi 637 | mov ecx, ebp 638 | int 030H 639 | _shell_parse_command_child_exit: 640 | xor eax, eax 641 | mov al, _SYSCALL_EXIT 642 | int 030H 643 | _shell_parse_command_exit: 644 | ret 645 | 646 | _shell_take_terminal_control: 647 | ; in: 648 | ; eax - fg id 649 | ; edx - tty id 650 | ; out: cf - set on error 651 | push eax edx 652 | xor eax, eax 653 | mov al, _SYSCALL_IOCTL 654 | mov ebx, dword [esp] 655 | mov ecx, TIOCSPGRP 656 | lea edx, [esp+4H] 657 | int 030H 658 | test eax, eax 659 | jns _shell_take_terminal_control_exit 660 | stc 661 | _shell_take_terminal_control_exit: 662 | pop edx eax 663 | ret 664 | 665 | _shell_copy_line_instance: 666 | mov ecx, (_line_instance.sizeof shr 2H) 667 | rep movsd 668 | ret 669 | 670 | _shell_clear_line_instance: 671 | mov ecx, (_line_instance.sizeof shr 2H) 672 | xor eax, eax 673 | rep stosd 674 | ret 675 | 676 | _shell_backup_command_to_history: 677 | mov edi, eax 678 | mov esi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.command) 679 | jmp _shell_copy_line_instance 680 | 681 | _shell_save_indexed_history: 682 | mov eax, dword [(_SHELL_BUFFER_INTERNAL+_shell_aggregate.hsttlb)+eax*4H] 683 | jmp _shell_backup_command_to_history 684 | 685 | _shell_save_history: 686 | if (_SIZE_HISTORY) 687 | cmp byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstste], 0H 688 | jz _shell_save_history_exit 689 | xor ebx, ebx 690 | movzx eax, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt] 691 | cmp eax, _SIZE_HISTORY 692 | jb _shell_save_history_update 693 | inc bl 694 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.hsttlb) 695 | mov edx, dword [edi] 696 | lea esi, [edi+4H] 697 | mov ecx, (_SIZE_HISTORY - 1H) 698 | mov eax, ecx 699 | rep movsd 700 | mov dword [edi], edx 701 | _shell_save_history_update: 702 | call _shell_save_indexed_history 703 | test bl, bl 704 | jnz _shell_save_history_exit 705 | inc byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt] 706 | _shell_save_history_exit: 707 | mov al, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt] 708 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx], al 709 | end if 710 | ret 711 | 712 | _shell_import_command_from_history: 713 | push eax 714 | call _shell_begin_cursor 715 | pop eax 716 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.command) 717 | mov esi, eax 718 | call _shell_copy_line_instance 719 | call _shell_hide_save_cursor 720 | xor eax, eax 721 | mov al, _SYSCALL_WRITE 722 | mov ebx, _TELETYPE_CURRENT 723 | mov ecx, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.command.buffer) 724 | mov edx, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 725 | int 030H 726 | call _shell_restore_show_cursor 727 | jmp _shell_end_cursor 728 | 729 | _shell_move_up_history: 730 | cmp byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstste], 0H 731 | jz _shell_move_up_history_exit 732 | movzx ecx, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx] 733 | jecxz _shell_move_up_history_exit 734 | push ecx 735 | cmp cl, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt] 736 | jnz _shell_move_up_history_refresh 737 | mov eax, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.temporary) 738 | call _shell_backup_command_to_history 739 | jmp _shell_move_up_history_erase 740 | _shell_move_up_history_refresh: 741 | mov eax, dword [esp] 742 | call _shell_save_indexed_history 743 | _shell_move_up_history_erase: 744 | call _shell_erase_whole_line 745 | pop eax 746 | mov eax, dword [(_SHELL_BUFFER_INTERNAL+_shell_aggregate.hsttlb-4H)+eax*4H] 747 | call _shell_import_command_from_history 748 | dec byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx] 749 | _shell_move_up_history_exit: 750 | ret 751 | 752 | _shell_move_down_history: 753 | cmp byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstste], 0H 754 | jz _shell_move_down_history_exit 755 | mov cl, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx] 756 | mov dl, byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt] 757 | cmp cl, dl 758 | jae _shell_move_down_history_exit 759 | pushw cx dx 760 | movzx eax, byte [esp+2H] 761 | call _shell_save_indexed_history 762 | call _shell_erase_whole_line 763 | popw dx cx 764 | inc cl 765 | cmp cl, dl 766 | jz _shell_move_down_history_temporary 767 | movzx eax, cl 768 | mov eax, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hsttlb+eax*4H] 769 | jmp _shell_move_down_history_import 770 | _shell_move_down_history_temporary: 771 | mov eax, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.temporary) 772 | _shell_move_down_history_import: 773 | call _shell_import_command_from_history 774 | inc byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx] 775 | _shell_move_down_history_exit: 776 | ret 777 | 778 | _shell_begin_cursor: 779 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 780 | jecxz _shell_begin_cursor_exit 781 | _shell_begin_cursor_loop: 782 | push ecx 783 | call _shell_cursor_backward 784 | pop ecx 785 | dec ecx 786 | jnz _shell_begin_cursor_loop 787 | _shell_begin_cursor_exit: 788 | ret 789 | 790 | _shell_end_cursor: 791 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 792 | sub ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 793 | jz _shell_end_cursor_exit 794 | _shell_end_cursor_loop: 795 | push ecx 796 | call _shell_cursor_forward 797 | pop ecx 798 | dec ecx 799 | jnz _shell_end_cursor_loop 800 | _shell_end_cursor_exit: 801 | ret 802 | 803 | _shell_truncate: 804 | mov ecx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 805 | mov ebx, dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.cursor] 806 | sub ecx, ebx 807 | jz _shell_truncate_exit 808 | lea edi, [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.buffer+ebx] 809 | push ebx edi ecx 810 | mov al, 020H 811 | rep stosb 812 | call _shell_hide_save_cursor 813 | xor eax, eax 814 | mov al, _SYSCALL_WRITE 815 | mov ebx, _TELETYPE_CURRENT 816 | mov ecx, dword [esp+4H] 817 | mov edx, dword [esp] 818 | int 030H 819 | call _shell_restore_show_cursor 820 | pop ecx edi 821 | xor al, al 822 | rep stosb 823 | pop dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.command.length] 824 | _shell_truncate_exit: 825 | ret 826 | 827 | _shell_erase_whole_line: 828 | call _shell_begin_cursor 829 | jmp _shell_truncate 830 | 831 | _shell_command_unknown: 832 | xor eax, eax 833 | mov al, _SYSCALL_WRITE 834 | mov ebx, _TELETYPE_CURRENT 835 | mov ecx, _shell_invalid 836 | mov edx, _shell_invalid.sizeof 837 | int 030H 838 | ret 839 | 840 | _shell_enable_history: 841 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstste], (not 0H) 842 | ret 843 | 844 | _shell_disable_history: 845 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstste], 0H 846 | jmp _shell_clear_history 847 | 848 | _shell_clear_history: 849 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstcnt], 0H 850 | mov byte [_SHELL_BUFFER_INTERNAL+_shell_aggregate.hstidx], 0H 851 | ret 852 | 853 | _shell_ensure_no_params: 854 | call _shell_skip_whitespace 855 | jz _shell_ensure_no_params_exit 856 | xor eax, eax 857 | mov al, _SYSCALL_WRITE 858 | mov ebx, _TELETYPE_CURRENT 859 | mov ecx, _shell_bad_params 860 | mov edx, _shell_bad_params.sizeof 861 | int 030H 862 | stc 863 | jmp $+3H 864 | _shell_ensure_no_params_exit: 865 | clc 866 | ret 867 | 868 | _shell_exit_command: 869 | call _shell_ensure_no_params 870 | jc _shell_exit_command_exit 871 | xor eax, eax 872 | mov al, _SYSCALL_EXIT 873 | xor ebx, ebx 874 | int 030H 875 | _shell_exit_command_exit: 876 | ret 877 | 878 | _shell_history_command: 879 | call _shell_skip_whitespace 880 | jz _shell_history_command_error 881 | irp _kind*, on,off 882 | { 883 | mov eax, _shell_history_#_kind#.sizeof 884 | mov esi, _shell_history_#_kind 885 | call _shell_word_compare 886 | match =on, _kind \{ jnc _shell_history_command_on \} 887 | match =off, _kind \{ jnc _shell_history_command_off \} 888 | } 889 | jmp _shell_history_command_error 890 | _shell_history_command_on: 891 | call _shell_ensure_no_params 892 | jc _shell_history_command_exit 893 | call _shell_enable_history 894 | jmp _shell_history_command_exit 895 | _shell_history_command_off: 896 | call _shell_ensure_no_params 897 | jc _shell_history_command_exit 898 | call _shell_disable_history 899 | jmp _shell_history_command_exit 900 | _shell_history_command_error: 901 | xor eax, eax 902 | mov al, _SYSCALL_WRITE 903 | mov ebx, _TELETYPE_CURRENT 904 | mov ecx, _shell_history_invalid 905 | mov edx, _shell_history_invalid.sizeof 906 | int 030H 907 | _shell_history_command_exit: 908 | ret 909 | 910 | _shell_parse_string: 911 | push edi ecx 912 | cmp ecx, 2H 913 | jb _shell_parse_string_carry 914 | mov esi, edi 915 | dec ecx 916 | lodsb 917 | call _shell_parse_string_delim 918 | jnz _shell_parse_string_carry 919 | mov dl, al 920 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.temporary.buffer) 921 | mov ebx, ecx 922 | _shell_parse_string_loop: 923 | lodsb 924 | cmp al, dl 925 | jnz _shell_parse_string_store 926 | dec ecx 927 | jecxz _shell_parse_string_save 928 | lodsb 929 | cmp al, dl 930 | jnz _shell_parse_string_adjust_pointer 931 | dec ebx 932 | _shell_parse_string_store: 933 | stosb 934 | loop _shell_parse_string_loop 935 | jmp _shell_parse_string_carry 936 | _shell_parse_string_adjust_pointer: 937 | dec esi 938 | _shell_parse_string_save: 939 | sub ebx, ecx 940 | dec ebx 941 | mov dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.temporary.length], ebx 942 | mov edi, esi 943 | add esp, 8H 944 | clc 945 | jmp _shell_parse_string_exit 946 | _shell_parse_string_carry: 947 | pop ecx edi 948 | stc 949 | _shell_parse_string_exit: 950 | ret 951 | 952 | _shell_parse_string_delim: 953 | cmp al, 022H 954 | jz _shell_parse_string_delim_exit 955 | cmp al, 027H 956 | _shell_parse_string_delim_exit: 957 | ret 958 | 959 | _shell_copy_command: 960 | call _shell_skip_whitespace 961 | jz _shell_copy_command_error 962 | call _shell_parse_string 963 | jc _shell_copy_command_word 964 | _shell_copy_command_sanitize: 965 | call _shell_ensure_no_params 966 | jc _shell_copy_command_exit 967 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.copy) 968 | mov esi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.temporary) 969 | call _shell_copy_line_instance 970 | jmp _shell_copy_command_exit 971 | _shell_copy_command_word: 972 | mov esi, edi 973 | mov al, 020H 974 | repnz scasb 975 | jnz _shell_copy_command_extract 976 | dec edi 977 | inc ecx 978 | _shell_copy_command_extract: 979 | push edi ecx 980 | mov ecx, edi 981 | sub ecx, esi 982 | mov dword [_SHELL_BUFFER_INTERNAL+_shell_aggregate.temporary.length], ecx 983 | mov edi, (_SHELL_BUFFER_INTERNAL + _shell_aggregate.temporary.buffer) 984 | rep movsb 985 | pop ecx edi 986 | jmp _shell_copy_command_sanitize 987 | _shell_copy_command_error: 988 | xor eax, eax 989 | mov al, _SYSCALL_WRITE 990 | mov ebx, _TELETYPE_CURRENT 991 | mov ecx, _shell_copy_invalid 992 | mov edx, _shell_copy_invalid.sizeof 993 | int 030H 994 | call _shell_print_newline 995 | _shell_copy_command_exit: 996 | ret 997 | 998 | _shell_print_newline: 999 | xor eax, eax 1000 | mov al, _SYSCALL_WRITE 1001 | mov ebx, _TELETYPE_CURRENT 1002 | mov ecx, _shell_newline 1003 | mov edx, _shell_newline.sizeof 1004 | int 030H 1005 | ret 1006 | 1007 | _shell_hide_save_cursor: 1008 | call _shell_hide_cursor 1009 | jmp _shell_save_cursor 1010 | 1011 | _shell_restore_show_cursor: 1012 | call _shell_restore_cursor 1013 | jmp _shell_show_cursor 1014 | 1015 | _shell_sighup: 1016 | ret 1017 | 1018 | _shell_sigint_handler: 1019 | ret 1020 | 1021 | _shell_root string "#" 1022 | _shell_user string "$" 1023 | _shell_space string " " 1024 | _shell_newline string 00DH, 00AH 1025 | 1026 | _shell_help string "help" 1027 | _shell_copyright string "copyright" 1028 | _shell_uid string "uid" 1029 | _shell_kill string "kill" 1030 | _shell_hostname string "hostname" 1031 | _shell_uname string "uname" 1032 | _shell_shutdown string "shutdown" 1033 | _shell_reboot string "reboot" 1034 | _shell_fg string "fg" 1035 | _shell_bg string "bg" 1036 | _shell_resolution string "resolution" 1037 | _shell_clear string "clear" 1038 | 1039 | _shell_copy string "copy" 1040 | _shell_copy_invalid string "copy syntax error" 1041 | 1042 | _shell_exit string "exit" 1043 | _shell_exit_invalid string "exit error", 00DH, 00AH 1044 | _shell_history string "history" 1045 | _shell_history_on string "on" 1046 | _shell_history_off string "off" 1047 | _shell_history_invalid string "history syntax error", 00DH, 00AH 1048 | 1049 | _shell_invalid string "invalid command", 00DH, 00AH 1050 | 1051 | _shell_bad_params string "bad parameter", 00DH, 00AH 1052 | 1053 | _shell_sigint string "sigint" 1054 | _shell_usertest string "usertest" 1055 | _shell_segvtest string "segvtest" 1056 | 1057 | _shell_sqrt string "sqrt" 1058 | _shell_sockpoc string "sockpoc" 1059 | _shell_md5 string "md5" 1060 | 1061 | _shell_bomb string "bomb" 1062 | 1063 | _shell_invopcode string "invopcode" 1064 | 1065 | _shell_showpid string "showpid" 1066 | 1067 | _shell_print string "print" 1068 | 1069 | _shell_stopped_1 string "process stopped [PID " 1070 | _shell_stopped_2 string "]" 1071 | 1072 | _move_up string _ESCAPE, _ESCAPE_MOVE_UP 1073 | _move_down string _ESCAPE, _ESCAPE_MOVE_DOWN 1074 | _move_left string _ESCAPE, _ESCAPE_MOVE_LEFT 1075 | _move_right string _ESCAPE, _ESCAPE_MOVE_RIGHT 1076 | 1077 | _save_cursor string _ESCAPE, _ESCAPE_SAVE_CURSOR 1078 | _restore_cursor string _ESCAPE, _ESCAPE_RESTORE_CURSOR 1079 | 1080 | _hide_cursor string _ESCAPE, _ESCAPE_DISABLE_CURSOR 1081 | _show_cursor string _ESCAPE, _ESCAPE_ENABLE_CURSOR 1082 | 1083 | _position_cursor string _ESCAPE, _ESCAPE_CURSOR_POSITION 1084 | 1085 | _extract _help 1086 | _extract _copyright 1087 | _extract _uid 1088 | _extract _kill 1089 | _extract _uname 1090 | _extract _hostname 1091 | _extract _shutdown 1092 | _extract _bomb 1093 | _extract _reboot 1094 | _extract _fg 1095 | _extract _bg 1096 | _extract _resolution 1097 | _extract _clear 1098 | _extract _sigint 1099 | _extract _usertest 1100 | _extract _segvtest 1101 | _extract _sockpoc 1102 | _extract _sqrt 1103 | _extract _md5 1104 | _extract _invopcode 1105 | _extract _showpid 1106 | _extract _print 1107 | 1108 | _shell.sizeof = ($ - $$) 1109 | end virtual 1110 | 1111 | -------------------------------------------------------------------------------- /showpid.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _showpid 3 | xor eax, eax 4 | mov al, _SYSCALL_WRITE 5 | mov ebx, _TELETYPE_CURRENT 6 | mov ecx, _parent_pid 7 | mov edx, _parent_pid.sizeof 8 | int 030H 9 | xor eax, eax 10 | mov al, _SYSCALL_GPPID 11 | int 030H 12 | call _vdso_itoa 13 | mov edx, ecx 14 | mov ecx, ebx 15 | mov ebx, _TELETYPE_CURRENT 16 | xor eax, eax 17 | mov al, _SYSCALL_WRITE 18 | int 030H 19 | xor eax, eax 20 | mov al, _SYSCALL_WRITE 21 | mov ecx, _newline 22 | xor edx, edx 23 | inc dl 24 | int 030H 25 | xor eax, eax 26 | mov al, _SYSCALL_WRITE 27 | mov ecx, _process_pid 28 | mov edx, _process_pid.sizeof 29 | int 030H 30 | xor eax, eax 31 | mov al, _SYSCALL_GPID 32 | int 030H 33 | call _vdso_itoa 34 | mov edx, ecx 35 | mov ecx, ebx 36 | mov ebx, _TELETYPE_CURRENT 37 | xor eax, eax 38 | mov al, _SYSCALL_WRITE 39 | int 030H 40 | xor eax, eax 41 | mov al, _SYSCALL_WRITE 42 | mov ecx, _newline 43 | xor edx, edx 44 | inc dl 45 | int 030H 46 | xor eax, eax 47 | mov al, _SYSCALL_EXIT 48 | int 030H 49 | _process_pid string "Process pid: " 50 | _parent_pid string "Parent pid: " 51 | _newline string 00AH 52 | end _user_code 53 | 54 | -------------------------------------------------------------------------------- /shutdown.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _shutdown:: 4 | xor eax, eax 5 | mov al, _SYSCALL_ARGCPY 6 | int 030H 7 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 8 | jz _shutdown_start 9 | xor eax, eax 10 | mov al, _SYSCALL_WRITE 11 | mov ebx, _TELETYPE_CURRENT 12 | mov ecx, _shutdown_invalid 13 | mov edx, _shutdown_invalid.sizeof 14 | int 030H 15 | mov ebx, (not 0H) 16 | jmp _shutdown_exit 17 | _shutdown_start: 18 | xor eax, eax 19 | mov al, _SYSCALL_REBOOT 20 | mov ebx, _REBOOT_MAGIC1 21 | mov ecx, _REBOOT_MAGIC2 22 | mov edx, _REBOOT_CMD_HALT 23 | int 030H 24 | xor eax, eax 25 | mov al, _SYSCALL_WRITE 26 | mov ebx, _TELETYPE_CURRENT 27 | mov ecx, _shutdown_permission 28 | mov edx, _shutdown_permission.sizeof 29 | int 030H 30 | xor ebx, ebx 31 | _shutdown_exit: 32 | xor eax, eax 33 | mov al, _SYSCALL_EXIT 34 | int 030H 35 | _shutdown_permission string "shutdown permission denied", 00AH 36 | _shutdown_invalid string "shutdown invalid usage", 00AH 37 | _shutdown.sizeof = ($ - $$) 38 | end virtual 39 | -------------------------------------------------------------------------------- /sigint.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _sigint 3 | xor eax, eax 4 | mov al, _SYSCALL_SIGNAL 5 | mov ebx, SIGCONT 6 | mov ecx, _sigint_sigcont 7 | int 030H 8 | xor eax, eax 9 | mov al, _SYSCALL_SIGNAL 10 | mov ebx, SIGTTOU 11 | mov ecx, _sigint_sigttou 12 | int 030H 13 | xor eax, eax 14 | mov al, _SYSCALL_WRITE 15 | mov ebx, _TELETYPE_CURRENT 16 | mov ecx, _sigint_info 17 | mov edx, _sigint_info.sizeof 18 | int 030H 19 | jmp $ 20 | 21 | _sigint_sigcont: 22 | xor eax, eax 23 | mov al, _SYSCALL_WRITE 24 | mov ebx, _TTY1 25 | mov ecx, _sigint_cont 26 | mov edx, _sigint_cont.sizeof 27 | int 030H 28 | ret 29 | 30 | _sigint_sigttou: 31 | ret 32 | 33 | _sigint_info string "you must use CTRL-C to quit this software", 00AH 34 | _sigint_cont string "SIGINT continued", 00AH 35 | end _user_code 36 | -------------------------------------------------------------------------------- /signal.inc: -------------------------------------------------------------------------------- 1 | 2 | _send_signal_current: 3 | mov ebx, dword [_current] 4 | _send_signal: 5 | ; in: 6 | ; eax - target signal 7 | ; ebx - process object pointer 8 | ; out: cf - bad signal or no enough privilege to send the signal 9 | ; preserves: ebx, esi, edi, ebp 10 | ; note: SIGCONT is send even if uid are different but are in the same session 11 | push ebx edi 12 | mov edx, eax 13 | inc dword [ebx+_process.sigcnt] 14 | test edx, edx 15 | jz _send_signal_carry 16 | cmp edx, _SIGNALS 17 | jae _send_signal_carry 18 | call _uid_enough_permission 19 | jo _send_signal_cont 20 | jnc _send_signal_carry 21 | cmp edx, SIGCONT 22 | jnz _send_signal_queue 23 | jmp _send_signal_wake 24 | _send_signal_cont: 25 | cmp edx, SIGCONT 26 | jnz _send_signal_carry 27 | _send_signal_wake: 28 | call _default_action_cont 29 | _send_signal_queue: 30 | ; XXX handle SIGKILL and SIGSTOP 31 | lea ebx, [ebx+_process.pending] 32 | mov eax, edx 33 | xchg eax, ebx 34 | call _send_signal_set 35 | jmp _send_signal_carry+1H 36 | _send_signal_carry: 37 | stc 38 | pop edi ebx 39 | ret 40 | _send_signal_set: 41 | ; in: 42 | ; eax - pending signal bitmap object pointer 43 | ; ebx - signal 44 | ; preserves: eax, esi, ebp 45 | call _convert_signal_bitmask 46 | xor ecx, ecx 47 | inc cl 48 | mov edi, _BITMAP_SET 49 | call _bitmap_update 50 | ret 51 | 52 | _send_signal_process_group_current: 53 | mov ebx, dword [_current] 54 | mov ebx, dword [ebx+_process.grpdesc] 55 | _send_signal_process_group: 56 | ; in: 57 | ; eax - target signal 58 | ; ebx - _process_group_descriptor object pointer 59 | ; preserves: ebx, esi, edi, ebp 60 | push ebx esi ebp 61 | test eax, eax 62 | jz _send_signal_process_group_exit 63 | cmp eax, _SIGNALS 64 | jae _send_signal_process_group_exit 65 | mov ebp, eax 66 | lea eax, [ebx+_process_group_descriptor.prclist] 67 | mov ecx, _process.pgroup 68 | xor edx, edx 69 | mov dl, (_LIST_FORWARD or _LIST_SAVE_ALL) 70 | mov esi, _send_signal_process_group_iterate 71 | call _find_list 72 | _send_signal_process_group_exit: 73 | cmc 74 | pop ebp esi ebx 75 | ret 76 | _send_signal_process_group_iterate: 77 | mov eax, ebp 78 | jmp _send_signal 79 | 80 | _handle_signal: 81 | ; out: cf - set if the handler is inaccesible for the user 82 | ; preserves: esi, edi, ebp 83 | push esi edi ebp 84 | push 0H ; _signal_context pointer pointer 85 | mov ebp, dword [_current] 86 | lea eax, dword [ebp+_process.pending] 87 | xor ebx, ebx 88 | mov edx, ebx 89 | lea ecx, [ebx+1H] 90 | call _bitmap_search 91 | jc _handle_signal_exit 92 | push edx 93 | mov edi, _BITMAP_RESET 94 | call _bitmap_update 95 | pop edx 96 | sub ebx, dword [eax+_bitmap.next] 97 | lea eax, dword [ebp+_process.sigmask] 98 | add ebx, dword [eax+_bitmap.next] 99 | mov edi, _BITMAP_SET 100 | call _bitmap_match 101 | jc _handle_signal_exit 102 | call _convert_bitmask_signal 103 | mov edi, ebx 104 | cmp edi, SIGKILL 105 | jz _handle_signal_default 106 | cmp edi, SIGSTOP 107 | jz _handle_signal_default 108 | shl ebx, (bsf _signal_context.sizeof) 109 | lea ebx, [ebp+_process.signals+ebx] 110 | mov dword [esp], ebx 111 | cmp byte [ebx+_signal_context.assign], 0H 112 | jz _handle_signal_default 113 | mov ebx, dword [ebx+_signal_context.handler] 114 | mov esi, ebx 115 | call _memory_accessible 116 | jnc _handle_signal_user 117 | _handle_signal_default: 118 | mov esi, dword [_signal_default_table+edi*4H] 119 | mov eax, edi 120 | mov ebx, ebp 121 | call esi 122 | jmp _handle_signal_exit 123 | _handle_signal_user: 124 | mov eax, dword [esp] 125 | cmp byte [eax+_signal_context.nested], 0H 126 | jz _handle_signal_sigframe 127 | lea eax, dword [ebp+_process.pending] 128 | mov ebx, edi 129 | call _send_signal_set 130 | jmp _handle_signal_exit+1H 131 | _handle_signal_sigframe: 132 | cmp byte [eax+_signal_context.newfrm], 0H 133 | jnz _handle_signal_copy 134 | push edi 135 | xor eax, eax 136 | mov al, _ALLOCATION_VIRTUAL 137 | mov edi, _frame_cache 138 | call _allocate_from_cache 139 | pop edi 140 | jc _handle_signal_exit+1H 141 | mov eax, dword [esp] 142 | mov dword [eax+_signal_context.sigframe], ebx 143 | mov byte [eax+_signal_context.newfrm], (not 0H) 144 | _handle_signal_copy: 145 | inc byte [ebp+_process.signst] 146 | mov bl, byte [ebp+_process.signst] 147 | mov byte [eax+_signal_context.nested], bl 148 | push esi edi 149 | mov esi, dword [ebp+_process.retframe] 150 | mov edi, dword [eax+_signal_context.sigframe] 151 | mov ecx, _x86_register.sizeof 152 | call _copy_string 153 | pop edi esi 154 | mov ebp, dword [ebp+_process.retframe] 155 | mov ebx, dword [ebp+_x86_register.esp] 156 | sub ebx, 4H 157 | call _memory_accessible_userspace 158 | jc _handle_signal_exit+1H 159 | mov dword [ebx], _vdso_sigret 160 | mov dword [ebp+_x86_register.esp], ebx 161 | mov dword [ebp+_x86_register.eip], esi 162 | mov dword [ebp+_x86_register.eax], edi 163 | _handle_signal_exit: 164 | clc 165 | lea esp, [esp+4H] 166 | pop ebp edi esi 167 | ret 168 | _signal_default_table: 169 | dd _panic ; signal begin with 1H 170 | dd _default_action_term 171 | dd _default_action_term 172 | dd _default_action_core 173 | dd _default_action_core 174 | dd _default_action_core 175 | dd _default_action_core 176 | dd _default_action_core 177 | dd _default_action_core 178 | dd _default_action_core 179 | dd _default_action_term 180 | dd _default_action_term 181 | dd _default_action_core 182 | dd _default_action_term 183 | dd _default_action_term 184 | dd _default_action_term 185 | dd _default_action_term 186 | dd _default_action_term 187 | dd _default_action_ign 188 | dd _default_action_cont 189 | dd _default_action_stop 190 | dd _default_action_stop 191 | dd _default_action_stop 192 | dd _default_action_stop 193 | _signal_default_table_end: 194 | 195 | _default_action_term: 196 | ; in: 197 | ; eax - signal number 198 | ; ebx - current process 199 | mov byte [ebx+_process.extsig], al 200 | jmp _syscall_exit 201 | 202 | _segmentation_fault string "Segmentation fault", 00AH 203 | _illegal_instruction string "Illegal instruction", 00AH 204 | _abort string "Aborted", 00AH 205 | _bus_fault string "Bus error", 00AH 206 | _segmentation_core: 207 | mov eax, SIGSEGV 208 | _default_action_core: 209 | ; in: 210 | ; eax - signal number 211 | ; ebx - current process 212 | mov byte [ebx+_process.extsig], al 213 | cmp dword [ebx+_process.pid], _INIT_PID 214 | ja _default_action_switch 215 | mov byte [ebx+_process.panic], (not 0H) 216 | _default_action_switch: 217 | mov ebx, _TELETYPE_CURRENT 218 | cmp eax, SIGSEGV 219 | mov ecx, _segmentation_fault 220 | mov edx, _segmentation_fault.sizeof 221 | jz _default_action_core_display 222 | cmp eax, SIGILL 223 | mov ecx, _illegal_instruction 224 | mov edx, _illegal_instruction.sizeof 225 | jz _default_action_core_display 226 | cmp eax, SIGABRT 227 | mov ecx, _abort 228 | mov edx, _abort.sizeof 229 | jz _default_action_core_display 230 | cmp eax, SIGBUS 231 | mov ecx, _bus_fault 232 | mov edx, _bus_fault.sizeof 233 | jnz _default_action_core_exit 234 | _default_action_core_display: 235 | call _syscall_write 236 | _default_action_core_exit: 237 | jmp _syscall_exit 238 | 239 | _default_action_ign: 240 | ; in: 241 | ; eax - signal number 242 | ; ebx - current process 243 | ret 244 | 245 | _wakeup_parent: 246 | ; in: ebx - child process object pointer 247 | ; preserves: ebx, edx, esi, edi, ebp 248 | push ebx edx 249 | cmp ebx, dword [_initproc] 250 | jz _wakeup_parent_exit 251 | mov eax, dword [ebx+_process.parent] 252 | mov eax, dword [eax+_process.channel] ; don't wakeup if the parent is in the STOP state 253 | call _wakeup_channel 254 | _wakeup_parent_exit: 255 | pop edx ebx 256 | ret 257 | 258 | _default_action_cont: 259 | ; in: 260 | ; eax - signal number 261 | ; ebx - current process 262 | ; preserves: ebx, edx, esi, edi, ebp 263 | cmp dword [ebx+_process.state], _PROCESS_STOP 264 | jnz _default_action_cont_exit 265 | mov dword [ebx+_process.state], _PROCESS_RUN 266 | mov byte [ebx+_process.waitable], _PROCESS_WAITABLE 267 | mov eax, dword [ebx+_process.grpdesc] 268 | dec dword [eax+_process_group_descriptor.stopped] 269 | call _wakeup_parent 270 | _default_action_cont_exit: 271 | ret 272 | 273 | _default_action_stop: 274 | ; in: 275 | ; eax - signal number 276 | ; ebx - current process 277 | cmp dword [ebx+_process.state], _PROCESS_STOP 278 | jz _default_action_stop_sleep 279 | mov dword [ebx+_process.state], _PROCESS_STOP 280 | mov byte [ebx+_process.waitable], _PROCESS_WAITABLE 281 | mov byte [ebx+_process.sigstp], al 282 | mov eax, dword [ebx+_process.grpdesc] 283 | inc dword [eax+_process_group_descriptor.stopped] 284 | call _wakeup_parent 285 | _default_action_stop_sleep: 286 | call _sleep_channel 287 | jmp _switch_mapping_user 288 | ; XXX sure to need switch user mapping ?? 289 | -------------------------------------------------------------------------------- /signal_enum.inc: -------------------------------------------------------------------------------- 1 | 2 | ; SIGHUP=1 3 | ; SIGINT=2 4 | ; SIGQUIT=3 5 | ; SIGILL=4 6 | ; SIGTRAP=5 7 | ; SIGABRT=6 8 | ; SIGIOT=7 9 | ; SIGBUS=8 10 | ; SIGFPE=9 11 | ; SIGKILL=10 12 | ; SIGUSR1=11 13 | ; SIGSEGV=12 14 | ; SIGUSR2=13 15 | ; SIGPIPE=14 16 | ; SIGALRM=15 17 | ; SIGTERM=16 18 | ; SIGSTKFLT=17 19 | ; SIGCHLD=18 20 | ; SIGCONT=19 21 | ; SIGSTOP=20 22 | ; SGTSTP=21 23 | ; SIGTTIN=22 24 | ; SIGTTOU=23 25 | 26 | enum SIGHUP:1H, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT, SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2,\ 27 | SIGPIPE, SIGALRM, SIGTERM, SIGSTKFLT, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, _SIGNALS:& 28 | 29 | -------------------------------------------------------------------------------- /sockpoc.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _sockpoc:: 4 | xor eax, eax 5 | mov al, _SYSCALL_ARGCPY 6 | int 030H 7 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 8 | jz _sockpoc_start 9 | xor eax, eax 10 | mov al, _SYSCALL_WRITE 11 | mov ebx, _TELETYPE_CURRENT 12 | mov ecx, _sockpoc_invalid 13 | mov edx, _sockpoc_invalid.sizeof 14 | int 030H 15 | xor ebx, ebx 16 | not ebx 17 | jmp _sockpoc_terminate 18 | _sockpoc_start: 19 | xor eax, eax 20 | mov al, _SYSCALL_WRITE 21 | mov ebx, _TELETYPE_CURRENT 22 | mov ecx, _sockpoc_launch_server 23 | mov edx, _sockpoc_launch_server.sizeof 24 | int 030H 25 | xor eax, eax 26 | mov al, _SYSCALL_FORK 27 | int 030H 28 | test eax, eax 29 | jnz _sockpoc_launch 30 | mov al, _SYSCALL_EXEC 31 | mov ebx, _server_payload 32 | mov ecx, _server.sizeof 33 | int 030H 34 | jmp _sockpoc_terminate-2H 35 | _sockpoc_launch: 36 | mov dword [_USER_SHELL_ARGUMENT_VIRTUAL], eax 37 | xor eax, eax 38 | mov al, _SYSCALL_WRITE 39 | mov ebx, _TELETYPE_CURRENT 40 | mov ecx, _sockpoc_launch_client 41 | mov edx, _sockpoc_launch_client.sizeof 42 | int 030H 43 | xor eax, eax 44 | mov al, _SYSCALL_FORK 45 | int 030H 46 | test eax, eax 47 | jnz _sockpoc_wait 48 | xor eax, eax 49 | mov al, _SYSCALL_EXEC 50 | mov ebx, _client_payload 51 | mov ecx, _client.sizeof 52 | int 030H 53 | jmp _sockpoc_terminate-2H 54 | _sockpoc_wait: 55 | xor eax, eax 56 | mov al, _SYSCALL_WAIT 57 | xor ebx, ebx 58 | int 030H 59 | xor ebx, ebx 60 | _sockpoc_terminate: 61 | xor eax, eax 62 | mov al, _SYSCALL_EXIT 63 | int 030H 64 | _extract _client, _server 65 | _sockpoc_invalid string "sockpoc invalid usage", 00AH 66 | _sockpoc_launch_server string "*** Starting the server ***", 00AH 67 | _sockpoc_launch_client string "*** Starting the client ***", 00AH 68 | _sockpoc.sizeof = ($ - $$) 69 | end virtual 70 | 71 | -------------------------------------------------------------------------------- /sqrt.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_CODE_VIRTUAL 3 | _sqrt:: 4 | xor eax, eax 5 | mov al, _SYSCALL_ARGCPY 6 | int 030H 7 | xor eax, eax 8 | mov al, _CPUID_LEAF_PROCESSOR_INFO 9 | cpuid 10 | test edx, _CPUID_EDX_SSE 11 | jnz _sqrt_compute 12 | xor eax, eax 13 | mov al, _SYSCALL_WRITE 14 | mov ebx, _TELETYPE_CURRENT 15 | mov ecx, _sqrt_sse 16 | mov edx, _sqrt_sse.sizeof 17 | int 030H 18 | mov ebx, (not 0H) 19 | jmp _sqrt_exit 20 | _sqrt_compute: 21 | xor ebx, ebx 22 | movd xmm0, eax 23 | sqrtps xmm0, xmm0 24 | _sqrt_exit: 25 | xor eax, eax 26 | mov al, _SYSCALL_EXIT 27 | int 030H 28 | _sqrt_invalid string "sqrt invalid usage", 00AH 29 | _sqrt_sse string "SSE not supported", 00AH 30 | _sqrt.sizeof = ($ - $$) 31 | end virtual 32 | 33 | -------------------------------------------------------------------------------- /teletype.inc: -------------------------------------------------------------------------------- 1 | 2 | enum & _SET_FONT_FORCE 3 | _teletype_set_font: 4 | ; in: 5 | ; ebx - teletype object pointer 6 | ; ecx - flags (force change font even if it's the same) 7 | ; esi - fonts object pointer 8 | ; out: cf - set when width/height are not power of two 9 | ; preserves: ebx, edi, esi, ebp 10 | push edi 11 | cmp ecx, (_SET_FONT_FORCE + 1H) 12 | cmc 13 | jc _teletype_set_font_exit 14 | test cl, _SET_FONT_FORCE 15 | jnz _teletype_set_font_force 16 | cmp dword [ebx+_teletype.fonts], esi 17 | jz _teletype_set_font_exit 18 | _teletype_set_font_force: 19 | mov eax, esi 20 | lea edi, [ebx+_teletype.fonts] 21 | mov ecx, _fonts.sizeof 22 | call _copy_string 23 | mov esi, eax 24 | movzx eax, byte [esi+_fonts.width] 25 | call _is_power_two 26 | jc _teletype_set_font_exit 27 | movzx eax, byte [esi+_fonts.height] 28 | call _is_power_two 29 | jc _teletype_set_font_exit 30 | movzx eax, byte [esi+_fonts.width] 31 | movzx edx, byte [esi+_fonts.height] 32 | bsf eax, eax 33 | bsf edx, edx 34 | mov byte [esi+_fonts.btposw], al 35 | mov byte [esi+_fonts.btposh], dl 36 | mov cl, al 37 | mov ax, word [_current_modeinfo.x_resolution] 38 | shr ax, cl 39 | stc 40 | jz _teletype_set_font_exit 41 | mov word [ebx+_teletype.xgrid], ax 42 | mov cl, dl 43 | mov dx, word [_current_modeinfo.y_resolution] 44 | shr dx, cl 45 | stc 46 | jz _teletype_set_font_exit 47 | mov word [ebx+_teletype.ygrid], dx 48 | movzx eax, word [_current_modeinfo.bytes_scanline] 49 | shl eax, cl 50 | mov dword [ebx+_teletype.scroll], eax 51 | call _teletype_clear 52 | _teletype_set_font_exit: 53 | pop edi 54 | ret 55 | 56 | _teletype_remap_frame_buffer: 57 | ; in: ebx - teletype object pointer 58 | ; preserves: eax, ebx, edx, edi, ebp 59 | push eax ebx edx edi 60 | cmp ebx, dword [_current_teletype] 61 | jnz _teletype_remap_frame_buffer_exit 62 | mov esi, dword [_current] 63 | cmp byte [esi+_process.refresh], 0H 64 | mov byte [esi+_process.refresh], 0H 65 | jz _teletype_remap_frame_buffer_exit 66 | xor ecx, ecx 67 | mov cl, _REGEN_4MB_PAGE 68 | test byte [_singleton.pae], 1H 69 | jz _teletype_remap_frame_buffer_remap 70 | shl ecx, ((_PAGE_DIRECTORY_SHIFT - _PAGE_TABLE_SHIFT) - (_PAE_PAGE_DIRECTORY_SHIFT - _PAE_PAGE_TABLE_SHIFT)) 71 | _teletype_remap_frame_buffer_remap: 72 | xor eax, eax 73 | mov al, (_DEALLOCATION_VIRTUAL or _DEALLOCATION_PSE or _DEALLOCATION_SHARING) 74 | mov ebx, dword [ebx+_teletype.video] 75 | and ebx, (not _PSE_OFFSET_MASK) 76 | call _unmap_virtual_address 77 | jc _teletype_remap_frame_buffer_exit 78 | xor eax, eax 79 | mov al, (_ALLOCATION_VIRTUAL or _ALLOCATION_PSE) 80 | call _allocate_kernel_frame 81 | _teletype_remap_frame_buffer_exit: 82 | pop edi edx ebx eax 83 | ret 84 | 85 | _teletype_buffer_target: 86 | ; in: ebx - teletype object pointer 87 | ; out: 88 | ; edi - target buffer (regen or video) 89 | ; zf - set when the video video ram is selected 90 | ; preserves: eax, ebx, ecx, edx, esi, ebp 91 | mov edi, dword [ebx+_teletype.video] 92 | cmp ebx, dword [_current_teletype] 93 | jz _teletype_buffer_target_exit 94 | mov edi, dword [ebx+_teletype.regen] 95 | _teletype_buffer_target_exit: 96 | ret 97 | 98 | _teletype_clear: 99 | ; in: ebx - teletype object pointer 100 | ; out: cf - set on error 101 | ; preserves: ebx, ecx, esi, edi, ebp 102 | push ecx esi edi 103 | xor eax, eax 104 | mov byte [ebx+_teletype.cursor], al 105 | mov word [ebx+_teletype.xlinear], ax 106 | mov word [ebx+_teletype.ylinear], ax 107 | mov word [ebx+_teletype.xsaved], ax 108 | mov word [ebx+_teletype.ysaved], ax 109 | call _teletype_buffer_target 110 | jnz _teletype_clear_perform 111 | mov eax, dword [_current] 112 | cmp byte [eax+_process.refresh], 0H ; if the cursor is already set jump for set the cursor 113 | jz _teletype_clear_perform 114 | call _teletype_remap_frame_buffer 115 | _teletype_clear_perform: 116 | mov ecx, dword [_vbe_frame_amount] 117 | call _clear_string 118 | mov byte [ebx+_teletype.cursor], (not 0H) ; and set the cursor to the top left 119 | call _teletype_redraw_cursor 120 | pop edi esi ecx 121 | ret 122 | 123 | _teletype_erase_character: 124 | ; in: 125 | ; ebx - teletype object pointer 126 | ; ecx - count of position to move backward 127 | ; preserves: ebx, esi, ebp 128 | jecxz _teletype_erase_character_exit 129 | _teletype_erase_character_loop: 130 | mov al, _TELETYPE_BACKSPACE 131 | xor edx, edx 132 | call _teletype_write_character 133 | jc _teletype_erase_character_exit 134 | mov al, 020H 135 | xor edi, edi 136 | call _teletype_write_character 137 | jc _teletype_erase_character_exit 138 | loop _teletype_erase_character_loop 139 | _teletype_erase_character_exit: 140 | ret 141 | 142 | _teletype_set_color: 143 | ; in: 144 | ; eax - forground color 145 | ; ebx - teletype object pointer 146 | ; edx - background color 147 | mov dword [ebx+_teletype.foregnd], eax 148 | mov dword [ebx+_teletype.backgnd], edx 149 | ret 150 | 151 | _teletype_redraw_cursor: 152 | ; in: ebx - teletype object pointer 153 | ; out: cf - set on error 154 | ; preserves: ebx, ebp 155 | cmp byte [ebx+_teletype.cursor], 0H 156 | jz _teletype_redraw_cursor_exit 157 | xor eax, eax 158 | mov edx, _teletype_write_character_cursor 159 | call _teletype_write_character_foreach 160 | _teletype_redraw_cursor_exit: 161 | ret 162 | 163 | _teletype_update_cursor: 164 | ; in: 165 | ; ebx - teletype object pointer 166 | ; ebp - predicate direction pointer 167 | ; out: 168 | ; preserves: ebx, ecx, esi, edi, ebp 169 | push ecx esi edi 170 | call _teletype_redraw_cursor 171 | jc _teletype_update_cursor_exit 172 | call ebp 173 | call _teletype_redraw_cursor 174 | _teletype_update_cursor_exit: 175 | pop edi esi ecx 176 | ret 177 | 178 | _teletype_internal_buffer_full: 179 | ; in: ebx - teletype object pointer 180 | ; out: cf - set if overflow 181 | cmp word [ebx+_teletype.index], _PAGE_FRAME_SIZE 182 | jmp _convert_zero_carry 183 | 184 | _teletype_reset_canonical: 185 | mov word [ebx+_teletype.ceidx], 0H 186 | mov byte [ebx+_teletype.eoi], 0H 187 | ret 188 | 189 | _teletype_switch: 190 | ; in: ebx - target teletype object pointer 191 | ; preserves: eax, ebx, ebp 192 | push ebp 193 | mov ebp, dword [_current_teletype] 194 | cmp ebx, ebp 195 | jz _teletype_switch_exit 196 | mov esi, dword [ebp+_teletype.video] 197 | mov edi, dword [ebp+_teletype.regen] 198 | mov ecx, dword [_vbe_frame_amount] 199 | call _copy_string 200 | mov esi, dword [ebx+_teletype.regen] 201 | mov edi, dword [ebx+_teletype.video] 202 | mov ecx, dword [_vbe_frame_amount] 203 | call _copy_string 204 | mov dword [_current_teletype], ebx 205 | _teletype_switch_exit: 206 | pop ebp 207 | ret 208 | 209 | enum & _TELETYPE_UPDATE_CURSOR 210 | _teletype_write_character: 211 | ; in: 212 | ; al - target character 213 | ; ebx - teletype object pointer 214 | ; edx - control character mask (only useful when al is a control character) 215 | ; edi - flags 216 | ; out: 217 | ; cf - set on error 218 | ; preserves: eax, ebx, ecx, esi, edi, ebp 219 | push eax ecx esi ebp 220 | push edi ; flags 221 | push 0H ; is printable ? 222 | call _teletype_remap_frame_buffer 223 | jc _teletype_write_character_exit 224 | cmp edi, (_TELETYPE_UPDATE_CURSOR + 1H) 225 | cmc 226 | jc _teletype_write_character_exit 227 | mov ebp, _teletype_write_character_forward 228 | cmp al, 07FH 229 | jae _teletype_write_character_special 230 | cmp al, 020H 231 | jae _teletype_write_character_printable 232 | _teletype_write_character_special: 233 | mov edi, _TELETYPE_UPDATE_CURSOR 234 | mov dword [esp+4H], edi 235 | cmp al, 07FH 236 | jae _teletype_write_character_escape 237 | mov cl, al 238 | mov ebp, 1H 239 | shl ebp, cl 240 | and ebp, edx 241 | jz _teletype_write_character_control 242 | _teletype_write_character_escape: 243 | lea esi, [eax+040H] 244 | and esi, 07FH 245 | mov al, 05EH 246 | call _teletype_write_character 247 | jc _teletype_write_character_exit 248 | mov eax, esi 249 | call _teletype_write_character 250 | jmp _teletype_write_character_exit 251 | _teletype_write_character_control: 252 | mov byte [esp], (not 0H) 253 | cmp al, _TELETYPE_BACKSPACE 254 | mov ebp, _teletype_direction_backward 255 | jz _teletype_write_character_printable 256 | cmp al, _TELETYPE_TABULATION 257 | jz _teletype_write_character_tabulation 258 | cmp al, _TELETYPE_NEWLINE 259 | mov ebp, _teletype_write_character_newline 260 | jz _teletype_write_character_printable 261 | cmp al, _TELETYPE_CARRIAGE 262 | mov ebp, _teletype_write_character_carriage 263 | clc 264 | jnz _teletype_write_character_exit 265 | _teletype_write_character_printable: 266 | mov esi, dword [ebx+_teletype.fonts.source] 267 | sub al, 020H 268 | movzx eax, al 269 | mov cl, byte [ebx+_teletype.fonts.btposh] 270 | shl eax, cl 271 | add esi, eax 272 | call _teletype_redraw_cursor 273 | jc _teletype_write_character_exit 274 | _teletype_write_character_display: 275 | cmp byte [esp], 0H 276 | jnz _teletype_write_character_invoke 277 | xor eax, eax 278 | mov al, (_TELETYPE_WRITE_TEMPLATE or _TELETYPE_SAVE_ALL) 279 | mov edx, _teletype_write_character_glyph 280 | call _teletype_write_character_foreach 281 | jc _teletype_write_character_exit 282 | _teletype_write_character_invoke: 283 | test byte [esp+4H], _TELETYPE_UPDATE_CURSOR 284 | jz _teletype_write_character_redraw 285 | call ebp 286 | jc _teletype_write_character_exit 287 | _teletype_write_character_redraw: 288 | call _teletype_redraw_cursor 289 | jmp _teletype_write_character_exit 290 | _teletype_write_character_tabulation: 291 | movzx ecx, byte [ebx+_teletype.tabulation] 292 | mov al, 020H 293 | mov edi, _TELETYPE_UPDATE_CURSOR 294 | test ecx, ecx 295 | jnz _teletype_write_character_tabulation_loop 296 | inc cl 297 | _teletype_write_character_tabulation_loop: 298 | call _teletype_write_character 299 | jc _teletype_write_character_exit 300 | loop _teletype_write_character_tabulation_loop 301 | _teletype_write_character_exit: 302 | lea esp, [esp+4H] 303 | pop edi ebp esi ecx eax 304 | ret 305 | 306 | _teletype_write_character_forward: 307 | ; preserves: ebx, esi, edi, ebp 308 | call _teletype_direction_forward 309 | jnc _teletype_write_character_forward_exit+3H ; skip all pop 310 | mov word [ebx+_teletype.xlinear], 0H 311 | _teletype_write_character_forward_nextline: 312 | push esi edi ebp 313 | call _teletype_direction_downward 314 | jnc _teletype_write_character_forward_exit 315 | xor eax, eax 316 | xor edx, edx 317 | call _teletype_write_character_position 318 | jc _teletype_write_character_forward_exit 319 | mov esi, edi 320 | xor eax, eax 321 | movzx edx, word [ebx+_teletype.ylinear] 322 | call _teletype_write_character_position 323 | jc _teletype_write_character_forward_exit 324 | mov ebp, edi 325 | sub edi, esi 326 | mov ecx, edi 327 | xor eax, eax 328 | xor edx, edx 329 | inc dl 330 | call _teletype_write_character_position 331 | jc _teletype_write_character_forward_exit 332 | xchg esi, edi 333 | call _copy_string 334 | mov edi, ebp 335 | mov ecx, dword [ebx+_teletype.scroll] 336 | call _clear_string 337 | _teletype_write_character_forward_exit: 338 | pop ebp edi esi 339 | ret 340 | 341 | _teletype_write_character_newline: 342 | call _teletype_write_character_forward_nextline 343 | test byte [ebx+_teletype.termios.oflag], OPOST 344 | jnz _teletype_write_character_carriage 345 | ret 346 | _teletype_write_character_carriage: 347 | mov word [ebx+_teletype.xlinear], 0H 348 | ret 349 | 350 | _teletype_write_character_position: 351 | ; in: 352 | ; eax - x linear in the framebuffer 353 | ; ebx - teletype object pointer 354 | ; edx - y linear in the framebuffer 355 | ; out: edi - framebuffer location 356 | ; preserves: ebx, ecx, esi, ebp 357 | push ecx 358 | mov cl, byte [ebx+_teletype.fonts.btposh] 359 | shl edx, cl 360 | movzx ecx, word [_current_modeinfo.bytes_scanline] 361 | imul edx, ecx 362 | jc _teletype_write_character_position_exit 363 | mov cl, byte [ebx+_teletype.fonts.btposw] 364 | shl eax, cl 365 | call _bsf_bits_pixel 366 | shl eax, cl 367 | add eax, edx 368 | call _teletype_buffer_target 369 | add edi, eax 370 | _teletype_write_character_position_exit: 371 | pop ecx 372 | ret 373 | 374 | enum & _TELETYPE_WRITE_TEMPLATE, _TELETYPE_SAVE_ALL 375 | _teletype_write_character_foreach: 376 | ; in: 377 | ; eax - write foreach flags 378 | ; ebx - teletype object pointer 379 | ; edx - predicate to call on each character scanline (functor must preserve all register except edi) 380 | ; out: cf - set on error 381 | ; preserves: eax, ebx, edx, ebp 382 | ; note: 383 | ; on predicate call all register must be preserved except eax when _TELETYPE_WRITE_TEMPLATE is specified 384 | ; cf is set also to indicate if a match occurs character '@' in fonts.inc 385 | push eax ebp edx 386 | cmp eax, ((_TELETYPE_WRITE_TEMPLATE or _TELETYPE_SAVE_ALL) + 1H) 387 | cmc 388 | jc _teletype_write_character_foreach_exit 389 | movzx eax, word [ebx+_teletype.xlinear] 390 | movzx edx, word [ebx+_teletype.ylinear] 391 | call _teletype_write_character_position 392 | jc _teletype_write_character_foreach_exit 393 | movzx ecx, byte [ebx+_teletype.fonts.width] 394 | movzx ebp, byte [ebx+_teletype.fonts.height] 395 | _teletype_write_character_foreach_loop: 396 | xor eax, eax 397 | lea edx, [ecx-1H] 398 | test byte [esp+8H], _TELETYPE_WRITE_TEMPLATE 399 | jz _teletype_write_character_foreach_btst 400 | lodsb 401 | _teletype_write_character_foreach_btst: 402 | test byte [esp+8H], _TELETYPE_SAVE_ALL 403 | jnz _teletype_write_character_foreach_save_all 404 | bt ax, dx 405 | call dword [esp] 406 | jmp _teletype_write_character_foreach_decrement 407 | _teletype_write_character_foreach_save_all: 408 | bt ax, dx 409 | pusha 410 | call dword [esp+_PUSHA_TOTAL] 411 | mov dword [esp+_PUSHA_EDI], edi 412 | popa 413 | _teletype_write_character_foreach_decrement: 414 | dec edx 415 | test byte [esp+8H], _TELETYPE_WRITE_TEMPLATE 416 | test edx, edx 417 | jns _teletype_write_character_foreach_btst 418 | dec ebp 419 | jz _teletype_write_character_foreach_exit 420 | movzx eax, word [_current_modeinfo.bytes_scanline] 421 | lea edi, [edi+eax] 422 | mov edx, ecx 423 | call _bsf_bits_pixel 424 | mov eax, edx 425 | shl eax, cl 426 | mov ecx, edx 427 | sub edi, eax 428 | jmp _teletype_write_character_foreach_loop 429 | _teletype_write_character_foreach_exit: 430 | pop edx ebp eax 431 | ret 432 | 433 | _teletype_write_character_glyph: 434 | mov eax, dword [ebx+_teletype.backgnd] 435 | jnc _teletype_write_character_glyph_store 436 | mov eax, dword [ebx+_teletype.foregnd] 437 | _teletype_write_character_glyph_store: 438 | cmp byte [ebx+_teletype.legacy], 0H 439 | jz $+5H 440 | stosb 441 | jmp $+3H 442 | stosd 443 | ret 444 | 445 | _CURSOR_COLOR_RGB = _RGB_WHITE 446 | _CURSOR_COLOR_VGA = _VGA_WHITE 447 | _teletype_write_character_cursor: 448 | mov eax, dword [ebx+_teletype.foregnd] 449 | cmp byte [edi], al 450 | jnz _teletype_write_character_cursor_color 451 | cmp byte [ebx+_teletype.legacy], 0H 452 | jnz _teletype_write_character_cursor_exit 453 | cmp dword [edi], eax 454 | jz _teletype_write_character_cursor_exit 455 | _teletype_write_character_cursor_color: 456 | mov eax, dword [ebx+_teletype.backgnd] 457 | cmp byte [ebx+_teletype.legacy], 0H 458 | jz _teletype_write_character_cursor_vbe 459 | cmp byte [edi], _CURSOR_COLOR_VGA 460 | jz _teletype_write_character_cursor_exit 461 | xor eax, eax 462 | mov al, _CURSOR_COLOR_VGA 463 | jmp _teletype_write_character_cursor_exit 464 | _teletype_write_character_cursor_vbe: 465 | cmp dword [edi], _CURSOR_COLOR_RGB 466 | jz _teletype_write_character_cursor_exit 467 | mov eax, _CURSOR_COLOR_RGB 468 | _teletype_write_character_cursor_exit: 469 | jmp _teletype_write_character_glyph_store 470 | 471 | _teletype_direction_downward: 472 | ; out: cf - set when overflow 473 | mov ax, word [ebx+_teletype.ygrid] 474 | dec ax 475 | cmp word [ebx+_teletype.ylinear], ax 476 | cmc 477 | jc _teletype_direction_downward_exit 478 | inc word [ebx+_teletype.ylinear] 479 | _teletype_direction_downward_exit: 480 | ret 481 | 482 | _teletype_direction_forward: 483 | ; out: cf - set when overflow 484 | mov ax, word [ebx+_teletype.xgrid] 485 | dec ax 486 | cmp word [ebx+_teletype.xlinear], ax 487 | cmc 488 | jc _teletype_direction_forward_exit 489 | inc word [ebx+_teletype.xlinear] 490 | _teletype_direction_forward_exit: 491 | ret 492 | 493 | _teletype_direction_upward: 494 | cmp word [ebx+_teletype.ylinear], 0H 495 | jz _teletype_direction_upward_exit 496 | dec word [ebx+_teletype.ylinear] 497 | _teletype_direction_upward_exit: 498 | ret 499 | 500 | _teletype_direction_backward: 501 | cmp word [ebx+_teletype.xlinear], 0H 502 | jz _teletype_direction_backward_exit 503 | dec word [ebx+_teletype.xlinear] 504 | _teletype_direction_backward_exit: 505 | ret 506 | 507 | _teletype_direction_reset: 508 | mov word [ebx+_teletype.xlinear], 0H 509 | mov word [ebx+_teletype.ylinear], 0H 510 | ret 511 | 512 | _teletype_erase_internal: 513 | ; in: 514 | ; ebx - teletype object pointer 515 | ; ecx - count of byte to delete 516 | ; out: cf - set on error 517 | ; preserves: ebx 518 | jecxz _teletype_erase_internal_exit 519 | cmp word [ebx+_teletype.index], 0H 520 | jz _teletype_erase_internal_exit 521 | movzx esi, word [ebx+_teletype.index] 522 | cmp ecx, esi 523 | cmova ecx, esi 524 | dec esi 525 | add esi, dword [ebx+_teletype.input] 526 | _teletype_erase_internal_loop: 527 | std 528 | lodsb 529 | cld 530 | mov ebp, ecx 531 | xor ecx, ecx 532 | cmp al, _TELETYPE_TABULATION 533 | mov cl, 4H 534 | jz _teletype_erase_internal_backspace 535 | cmp al, 020H 536 | jb _teletype_erase_internal_special 537 | cmp al, 07FH 538 | jae _teletype_erase_internal_special 539 | mov cl, 1H 540 | jnz _teletype_erase_internal_backspace 541 | _teletype_erase_internal_special: 542 | xor cl, cl 543 | test dword [ebx+_teletype.termios.lflag], ECHOCTL 544 | jz _teletype_erase_internal_backspace 545 | mov cl, 2H 546 | _teletype_erase_internal_backspace: 547 | test dword [ebx+_teletype.termios.lflag], ECHO 548 | jz teletype_erase_internal_update 549 | call _teletype_erase_character 550 | jc _teletype_erase_internal_exit 551 | teletype_erase_internal_update: 552 | dec word [ebx+_teletype.index] 553 | mov ecx, ebp 554 | loop _teletype_erase_internal_loop 555 | _teletype_erase_internal_exit: 556 | ret 557 | 558 | _teletype_insert_character: 559 | ; in: 560 | ; al - byte wanted to be inserted 561 | ; ebx - teletype object pointer 562 | ; preserves: eax, ebx, ecx, edx, esi, ebp 563 | call _teletype_internal_buffer_full 564 | jc _teletype_insert_character_exit 565 | movzx edi, word [ebx+_teletype.index] 566 | add edi, dword [ebx+_teletype.input] 567 | stosb 568 | inc word [ebx+_teletype.index] 569 | clc 570 | _teletype_insert_character_exit: 571 | ret 572 | 573 | _teletype_send_signal: 574 | ; in: 575 | ; eax - signal kind 576 | ; ebx - teletype object pointer 577 | ; out: cf - set if bad signal or teletype not a controling terminal and not have a foreground group 578 | ; preserves: ebx, esi, edi, ebp 579 | ; note: send the signal to all the process in the "foreground" group 580 | push ebx esi ebp 581 | cmp byte [ebx+_teletype.control], 0H 582 | jz _teletype_send_signal_exit 583 | cmp byte [ebx+_teletype.fground], 0H 584 | jz _teletype_send_signal_exit 585 | mov ebp, eax 586 | mov eax, dword [ebx+_teletype.grpdesc] 587 | lea eax, [eax+_process_group_descriptor.prclist] 588 | xor ecx, ecx 589 | mov cl, _process.pgroup 590 | xor edx, edx 591 | mov dl, (_LIST_FORWARD or _LIST_SAVE_ALL) 592 | mov esi, _send_signal_process_group_iterate 593 | call _find_list 594 | _teletype_send_signal_exit: 595 | cmc 596 | pop ebp esi ebx 597 | ret 598 | -------------------------------------------------------------------------------- /uid.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _uid 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _uid_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _uid_invalid 12 | mov edx, _uid_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _uid_exit 16 | _uid_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_GUID 19 | int 030H 20 | cmp eax, _ROOT_UID 21 | mov ebx, _uid_root 22 | mov ecx, _uid_root.sizeof 23 | jz _uid_display 24 | call _uid_itoa 25 | _uid_display: 26 | xor eax, eax 27 | mov al, _SYSCALL_WRITE 28 | mov edx, ecx 29 | mov ecx, ebx 30 | mov ebx, _TELETYPE_CURRENT 31 | int 030H 32 | xor ebx, ebx 33 | _uid_exit: 34 | xor eax, eax 35 | mov al, _SYSCALL_EXIT 36 | int 030H 37 | _uid_itoa: 38 | ; in: eax - target number 39 | ; out: 40 | ; ebx - pointer to the string 41 | ; ecx - count 42 | pop esi 43 | std 44 | mov ebx, eax 45 | lea edi, [esp-1H] 46 | mov al, 00AH 47 | stosb 48 | xor ecx, ecx 49 | inc cl 50 | mov eax, ebx 51 | xor edx, edx 52 | xor ebp, ebp 53 | mov ebp, 00AH 54 | _uid_itoa_loop: 55 | div ebp 56 | xchg edx, eax 57 | add al, 030H 58 | stosb 59 | xor eax, eax 60 | xchg edx, eax 61 | inc ecx 62 | test eax, eax 63 | jnz _uid_itoa_loop 64 | lea ebx, [edi+1H] 65 | jmp esi 66 | _uid_invalid string "uid invalide usage", 00AH 67 | _uid_root string "root", 00AH 68 | end _user_code 69 | 70 | -------------------------------------------------------------------------------- /uname.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _uname 3 | xor eax, eax 4 | mov al, _SYSCALL_ARGCPY 5 | int 030H 6 | cmp dword [_USER_SHELL_ARGUMENT_VIRTUAL], 0H 7 | jz _uname_start 8 | xor eax, eax 9 | mov al, _SYSCALL_WRITE 10 | mov ebx, _TELETYPE_CURRENT 11 | mov ecx, _uname_invalid 12 | mov edx, _uname_invalid.sizeof 13 | int 030H 14 | mov ebx, (not 0H) 15 | jmp _uname_exit 16 | _uname_start: 17 | xor eax, eax 18 | mov al, _SYSCALL_UNAME 19 | lea ebx, [esp-_UNAME_SIZE] 20 | int 030H 21 | mov edx, eax 22 | xor eax, eax 23 | mov al, _SYSCALL_WRITE 24 | mov ecx, ebx 25 | mov ebx, _TELETYPE_CURRENT 26 | int 030H 27 | xor eax, eax 28 | mov al, _SYSCALL_WRITE 29 | mov ecx, _uname_newline 30 | mov edx, _uname_newline.sizeof 31 | int 030H 32 | xor ebx, ebx 33 | _uname_exit: 34 | xor eax, eax 35 | mov al, _SYSCALL_EXIT 36 | int 030H 37 | _uname_invalid string "uname invalid usage" 38 | _uname_newline string 00AH 39 | end _user_code 40 | -------------------------------------------------------------------------------- /usertest.inc: -------------------------------------------------------------------------------- 1 | 2 | _user_code _usertest 3 | xor eax, eax 4 | mov al, _SYSCALL_WRITE 5 | mov ebx, _TELETYPE_CURRENT 6 | mov ecx, _usertest_example 7 | mov edx, _usertest_example.sizeof 8 | int 030H 9 | _user_test_loop: 10 | xor eax, eax 11 | mov al, _SYSCALL_WRITE 12 | mov ecx, _usertest_a 13 | mov edx, _usertest_a.sizeof 14 | int 030H 15 | jmp _user_test_loop 16 | xor eax, eax 17 | mov al, _SYSCALL_EXIT 18 | xor ebx, ebx 19 | int 030H 20 | _usertest_example string "Hello, World!!", 00AH 21 | _usertest_a string "a" 22 | end _user_code 23 | -------------------------------------------------------------------------------- /vdso.inc: -------------------------------------------------------------------------------- 1 | 2 | virtual at _USER_VDSO_VIRTUAL 3 | _vdso:: 4 | _vdso_sigret: 5 | xor eax, eax 6 | mov al, _SYSCALL_SIGRET 7 | int 030H 8 | _vdso_sysenter: 9 | pop ebp edx ecx 10 | int 030H 11 | ret 12 | 13 | _vdso_itoa: 14 | ; in: eax - target number 15 | ; out: 16 | ; ebx - pointer to the string 17 | ; ecx - count 18 | pop esi 19 | std 20 | lea edi, [esp-1H] 21 | xor ecx, ecx 22 | xor edx, edx 23 | mov ebp, 00AH 24 | _vdso_itoa_loop: 25 | div ebp 26 | xchg edx, eax 27 | add al, 030H 28 | stosb 29 | xor eax, eax 30 | xchg edx, eax 31 | inc ecx 32 | test eax, eax 33 | jnz _vdso_itoa_loop 34 | lea ebx, [edi+1H] 35 | cld 36 | jmp esi 37 | 38 | _vdso_atoi: 39 | ; in: 40 | ; esi - source string 41 | ; ecx - size of string 42 | ; out: 43 | ; eax - number 44 | ; esi - updated 45 | ; ecx - updated 46 | ; cf - if not a number or overflow 47 | xor eax, eax 48 | cdq 49 | jecxz _vdso_atoi_exit 50 | lodsb 51 | call _vdso_is_digit 52 | jc _vdso_atoi_revert+1H 53 | jmp _vdso_atoi_mulitiply 54 | _vdso_atoi_loop: 55 | lodsb 56 | call _vdso_is_digit 57 | jc _vdso_atoi_revert 58 | _vdso_atoi_mulitiply: 59 | imul edx, edx, 00AH 60 | add edx, eax 61 | jc _vdso_atoi_exit 62 | loop _vdso_atoi_loop 63 | jmp _vdso_atoi_exit 64 | _vdso_atoi_revert: 65 | clc 66 | dec esi 67 | _vdso_atoi_exit: 68 | mov eax, edx 69 | ret 70 | 71 | _vdso_is_digit: 72 | sub al, 030H 73 | jc _vdso_is_digit_exit 74 | cmp al, 00AH 75 | cmc 76 | _vdso_is_digit_exit: 77 | ret 78 | 79 | _vdso.sizeof = ($ - $$) 80 | end virtual 81 | -------------------------------------------------------------------------------- /vm86.inc: -------------------------------------------------------------------------------- 1 | 2 | _GENERAL_FAULT = 00DH 3 | _vm86_monitor: 4 | ; in: [esp+4H] - last retframe 5 | ; out: cf - set if the fault was not caused by a sensitive instruction (cli/sti/pushf/popf/iret/int) or for hlt 6 | lea esi, [esp+4H] 7 | movzx eax, word [esi+_x86_register.eip] 8 | movzx ebx, word [esi+_x86_register.cs] 9 | _real_segment edx, ebx:eax 10 | mov ebp, ebx 11 | mov ebx, edx 12 | movzx eax, word [esi+_x86_register.esp] 13 | movzx edi, word [esi+_x86_register.ss] 14 | _real_segment edi, edi:eax 15 | xor edx, edx 16 | cmp dword [esi+_x86_register.trap], _GENERAL_FAULT 17 | jnz _vm86_monitor_examine 18 | xor ecx, ecx 19 | mov cl, 010H 20 | _vm86_monitor_loop: 21 | call _vm86_monitor_prefix 22 | jnc _vm86_monitor_examine 23 | cmp byte [ebx], _OPERAND_SIZE 24 | jnz _vm86_monitor_update 25 | mov dl, (not 0H) 26 | _vm86_monitor_update: 27 | inc ebx 28 | loop _vm86_monitor_loop 29 | _vm86_monitor_examine: 30 | push _vm86_monitor_ip 31 | cmp dword [esi+_x86_register.trap], _GENERAL_FAULT 32 | jnz _vm86_monitor_int 33 | cmp byte [ebx], _PUSHF 34 | jz _vm86_monitor_pushf 35 | cmp byte [ebx], _POPF 36 | jz _vm86_monitor_popf 37 | cmp byte [ebx], _INT 38 | jz _vm86_monitor_int 39 | cmp byte [ebx], _IRET 40 | jz _vm86_monitor_iret 41 | cmp byte [ebx], _STI 42 | jz _vm86_monitor_sti 43 | cmp byte [ebx], _CLI 44 | jz _vm86_monitor_cli 45 | cmp byte [ebx], _HLT 46 | jz _vm86_monitor_hlt 47 | pop eax 48 | stc 49 | jmp _vm86_monitor_exit 50 | _vm86_monitor_ip: 51 | sub ebx, ebp 52 | mov dword [esi+_x86_register.eip], ebx 53 | clc 54 | _vm86_monitor_exit: 55 | ret 56 | _vm86_monitor_prefix: 57 | irp _prefix*, _REP,_REPNZ,_CS,_DS,_ES,_SS,_FS,_GS,_LOCK,_OPERAND_SIZE,_ADDRESS_SIZE 58 | { 59 | cmp byte [ebx], _prefix 60 | jz _convert_zero_carry 61 | } 62 | clc 63 | ret 64 | 65 | _vm86_monitor_pushf: 66 | inc ebx 67 | mov eax, dword [esi+_x86_register.eflags] 68 | test eax, _EFLAGS_VIF 69 | jz _vm86_monitor_pushf_size 70 | or eax, _EFLAGS_IF 71 | _vm86_monitor_pushf_size: 72 | and eax, (not (_EFLAGS_VM or _EFLAGS_RF)) 73 | or eax, (011B shl _EFLAGS_IOPL) 74 | test dl, dl 75 | jz _vm86_monitor_pushf_word 76 | and eax, (not (_EFLAGS_VIF or _EFLAGS_VIP)) ; hide the fact that the real mode program run in a vm ;) 77 | sub word [esi+_x86_register.esp], 4H 78 | mov dword [edi-4H], eax 79 | ret 80 | _vm86_monitor_pushf_word: 81 | sub word [esi+_x86_register.esp], 2H 82 | mov word [edi-2H], ax 83 | ret 84 | 85 | _vm86_monitor_popf: 86 | inc ebx 87 | mov ecx, dword [esi+_x86_register.eflags] 88 | and ecx, (_EFLAGS_VIP or _EFLAGS_IF) 89 | test dl, dl 90 | jz _vm86_monitor_popf_word 91 | mov eax, dword [edi] 92 | add word [esi+_x86_register.esp], 4H 93 | jmp _vm86_monitor_popf_next 94 | _vm86_monitor_popf_word: 95 | movzx eax, word [edi] 96 | add word [esi+_x86_register.esp], 2H 97 | _vm86_monitor_popf_next: 98 | and eax, (not (011B shl _EFLAGS_IOPL)) 99 | or eax, _EFLAGS_VM 100 | test eax, _EFLAGS_IF 101 | jz _vm86_monitor_popf_if 102 | or eax, _EFLAGS_VIF 103 | _vm86_monitor_popf_if: 104 | or eax, ecx 105 | mov dword [esi+_x86_register.eflags], eax 106 | ret 107 | 108 | _vm86_monitor_iret: 109 | xor ebp, ebp 110 | test dl, dl 111 | jz _vm86_monitor_iret_word 112 | mov eax, dword [edi] 113 | mov bp, 4H 114 | jmp _vm86_monitor_iret_next 115 | _vm86_monitor_iret_word: 116 | movzx eax, word [edi] 117 | mov bp, 2H 118 | _vm86_monitor_iret_next: 119 | mov cx, word [edi+ebp] 120 | mov dword [esi+_x86_register.eip], eax 121 | mov word [esi+_x86_register.cs], cx 122 | shl ebp, 1H 123 | add word [esi+_x86_register.esp], bp 124 | add edi, ebp 125 | call _vm86_monitor_popf 126 | mov dword [esp], _vm86_monitor_exit-1H 127 | ret 128 | 129 | _vm86_monitor_int: 130 | xor dl, dl 131 | call _vm86_monitor_pushf 132 | mov dx, word [esi+_x86_register.cs] 133 | mov word [edi-4H], dx 134 | lea edx, [ebx+1H] 135 | movzx eax, byte [ebx] 136 | cmp dword [esi+_x86_register.trap], _GENERAL_FAULT 137 | jz _vm86_monitor_int_compute 138 | mov eax, dword [esi+_x86_register.trap] 139 | sub edx, 2H 140 | sub ebx, 2H 141 | _vm86_monitor_int_compute: 142 | sub edx, ebp 143 | mov word [edi-6H], dx 144 | movzx edx, word [eax*4H] 145 | mov cx, word [eax*4H+2H] 146 | mov word [esi+_x86_register.eip], dx 147 | mov word [esi+_x86_register.cs], cx 148 | sub word [esi+_x86_register.esp], 4H 149 | mov dword [esp], _vm86_monitor_exit-1H 150 | _vm86_monitor_cli: 151 | inc ebx 152 | mov eax, dword [esi+_x86_register.eflags] 153 | test byte [_singleton.vme], 1H 154 | jnz _vm86_monitor_cli_vme 155 | mov edx, dword [_current] 156 | xor al, al 157 | mov byte [edx+_process.vif], al 158 | ret 159 | _vm86_monitor_cli_vme: 160 | and eax, (not _EFLAGS_VIF) 161 | mov dword [esi+_x86_register.eflags], eax 162 | ret 163 | 164 | _vm86_monitor_sti: 165 | inc ebx 166 | mov eax, dword [esi+_x86_register.eflags] 167 | test byte [_singleton.vme], 1H 168 | jnz _vm86_monitor_sti_vme 169 | mov edx, dword [_current] 170 | mov al, 1H 171 | mov byte [edx+_process.vif], al 172 | ret 173 | _vm86_monitor_sti_vme: 174 | or eax, _EFLAGS_VIF 175 | mov dword [esi+_x86_register.eflags], eax 176 | ret 177 | 178 | _vm86_monitor_hlt: 179 | jmp _execute_real_terminate 180 | --------------------------------------------------------------------------------