flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Fail RETing |
Author |
|
l4m2 01 Oct 2015, 14:42
Code:
Code: int_page: mov eax, cr2 mov ebx, 1-0x400 .lp: test [ebx+0x7c00], byte 0xff jnz .ok inc ebx jnz .lp jmp int_fault .ok: mov [ebx+0x7c00], byte 0x00 shr eax, 22 mov edx, cr3 shl ebx, 22 mov bl, 10000111b mov [edx+eax*4], ebx iret |
|||
01 Oct 2015, 14:42 |
|
l4m2 01 Oct 2015, 14:48
macro reach ptr { db (ptr)-$ dup 0 }
sti equ cli macro debug x { ;mov [0xb8000+160], byte x } macro displayint y { local x x = y if x < 0 x = -x display '-' end if irp t,10000000000000000000,1000000000000000000,100000000000000000,10000000000000000,1000000000000000,100000000000000,10000000000000,1000000000000,100000000000,10000000000,1000000000,100000000,10000000,1000000,100000,10000,1000,100,10 \{ if x >= t display (x/t) mod 10 + 48 end if \} display x mod 10 + 48 } disknum equ 0x7e00 org 0x7c00 boot: cli lgdt [0x7df8] lidt [segs] mov eax, cr0 inc ax mov cr0, eax jmp pword 8:.main use32 .main: mov ax, 16 mov ds, ax mov es, ax mov ss, ax mov esp, 0xa0000 ;Paging mov eax, cr4 or al, 16 ;PSE mov cr4, eax ;Clear 0x300000 - 0x3fffff xor eax, eax mov ecx, 0x40000 mov edi, 0x300000 cld rep stosd mov eax, 0x00300000 ;In: Nothing mov dword [eax], 10000011b mov cr3, eax ;TSS mov [TSS+4], esp mov eax, ss mov [TSS+8], eax mov ax, 40 ltr ax ;Paging mov eax, cr0 bts eax, 31 mov cr0, eax mov [0xc0000001], byte 7 jmp $ align 8 intCount = (idtend-idt)/8 macro newidt p, t { if p eq int_fault dq 0 else dq ((p)*$1'0000'0001)and $ffff'0000'0000'ffff or ((t) shl 32) or $80000 end if } .gTask equ 0x8d00 .gInt equ 0x8e00 .gInt3 equ 0xee00 .gTrap equ 0x8f00 intb: idt: newidt int_fault, .gInt ;Divide error newidt int_fault, .gInt ;Single-step/debug exception newidt int_fault, .gInt ;Nonmaskable interrupt newidt int_fault, .gInt ;Breakpoint newidt int_fault, .gInt ;Overflow newidt int_fault, .gInt ;Bounds check (BOUND instruction) newidt int_fault, .gInt ;Invalid opcode newidt int_fault, .gInt ;Coprocessor not available newidt int_fault, .gInt ;Double fault newidt int_fault, .gInt ;Coprocessor segment overrun newidt int_fault, .gInt ;Invalid TSS newidt int_fault, .gInt ;Segment not present newidt int_fault, .gInt ;Stack exception newidt int_fault, .gInt ;General protection violation newidt int_page, .gInt ;Page fault idtend: int_page: ;jmp $ int_fault: int_clock: int_keyboard: int_mouse: int_unused: int_user: iret reach 0x7dfe - (segsend-segs) segs: dw 8*intCount dd intb dw 0 dw 0ffffh,0 ; 4Gbytes, start at linear 0 db 0,10011010b,11001111b,0 ; granularity = 64Kbytes, code segment, ring 0, read only,etc... dw 0ffffh,0 ; 4Gbytes, start at linear 0 db 0,10010010b,11001111b,0 ; granularity = 64Kbytes, data segment, ring 0, read/write,etc... dw 0ffffh,0 ; 4Gbytes, start at linear 0 db 0,11111010b,11001111b,0 ; granularity = 64Kbytes, code segment, ring 3, read only,etc... dw 0ffffh,0 ; 4Gbytes, start at linear 0 db 0,11110010b,11001111b,0 ; granularity = 64Kbytes, data segment, ring 3, read/write,etc... TSS = 0x8000-104 dw 104,TSS db 0, 1'11'01001b,00000000b,0 ; TSS dw (segsend-segs)-6 dd segs segsend: dw 0xaa55 org 0x100200 use32 starting: |
|||
01 Oct 2015, 14:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.