diff --git a/asm/x86-unknown-none/old/cpuid.inc b/asm/x86-unknown-none/cpuid.asm similarity index 60% rename from asm/x86-unknown-none/old/cpuid.inc rename to asm/x86-unknown-none/cpuid.asm index 1c2c62b3bc635e0d8a612f907586e9bff0af73ef..a1c4f755dce6ebb1df29f15c983407d876ad218c 100644 --- a/asm/x86-unknown-none/old/cpuid.inc +++ b/asm/x86-unknown-none/cpuid.asm @@ -1,4 +1,94 @@ -features_edx: +SECTION .text +USE16 + +cpuid_required_features: + .edx equ cpuid_edx.fpu | cpuid_edx.sse | cpuid_edx.pae | cpuid_edx.pse | cpuid_edx.pge | cpuid_edx.fxsr + .ecx equ cpuid_ecx.xsave + +cpuid_check: + mov eax, 1 + cpuid + + and edx, cpuid_required_features.edx + cmp edx, cpuid_required_features.edx + jne .error + + and ecx, cpuid_required_features.ecx + cmp ecx, cpuid_required_features.ecx + jne .error + + ret + +.error: + push edx + push ecx + + mov si, .msg_features + call print + + mov si, .msg_line + call print + + mov si, .msg_ecx + call print + + pop ebx + push ebx + shr ebx, 16 + call print_hex + + pop ebx + call print_hex + + mov si, .msg_must_contain + call print + + mov ebx, cpuid_required_features.ecx + shr ebx, 16 + call print_hex + + mov ebx, cpuid_required_features.ecx + call print_hex + + mov si, .msg_line + call print + + mov si, .msg_edx + call print + + pop ebx + push ebx + rol ebx, 16 + call print_hex + + pop ebx + call print_hex + + mov si, .msg_must_contain + call print + + mov ebx, cpuid_required_features.edx + shr ebx, 16 + call print_hex + + mov ebx, cpuid_required_features.edx + call print_hex + + mov si, .msg_line + call print + +.halt: + cli + hlt + jmp .halt + +.msg_features: db "Required CPU features are not present",0 +.msg_line: db 13,10,0 +.msg_ecx: db "ECX ",0 +.msg_edx: db "EDX ",0 +.msg_must_contain: db " must contain ",0 + +cpuid_edx: .fpu equ 1 << 0 .vme equ 1 << 1 .de equ 1 << 2 @@ -30,7 +120,7 @@ features_edx: .ia64 equ 1 << 30 .pbe equ 1 << 31 -features_ecx: +cpuid_ecx: .sse3 equ 1 << 0 .pclmulqdq equ 1 << 1 .dtes64 equ 1 << 2 diff --git a/asm/x86-unknown-none/old/cpuid.asm b/asm/x86-unknown-none/old/cpuid.asm deleted file mode 100644 index 17686dc7fdc6ae4f99fa206da9aefed8c462eb1a..0000000000000000000000000000000000000000 --- a/asm/x86-unknown-none/old/cpuid.asm +++ /dev/null @@ -1,27 +0,0 @@ -%include "cpuid.inc" - -required_features: - .edx equ features_edx.fpu | features_edx.sse | features_edx.pae | features_edx.pse | features_edx.pge | features_edx.fxsr - .ecx equ features_ecx.xsave - -check_cpuid: - mov eax, 1 - cpuid - - and edx, required_features.edx - cmp edx, required_features.edx - jne .error - - and ecx, required_features.ecx - cmp ecx, required_features.ecx - jne .error - - ret - -.error: - mov si, .err_features - call print -.halt: - jmp .halt - -.err_features: db "Required CPU features are not present",13,10,0 diff --git a/asm/x86-unknown-none/old/initialize.asm b/asm/x86-unknown-none/old/initialize.asm deleted file mode 100644 index e0ac449690d82ddc441bfbaea81c80d38cd58f98..0000000000000000000000000000000000000000 --- a/asm/x86-unknown-none/old/initialize.asm +++ /dev/null @@ -1,20 +0,0 @@ -SECTION .text -USE16 - -initialize: -.fpu: ;enable fpu - mov eax, cr0 - and al, 11110011b - or al, 00100010b - mov cr0, eax - mov eax, cr4 - or eax, 0x200 - mov cr4, eax - fninit - ret - -.sse: ;enable sse - mov eax, cr4 - or ax, 0000011000000000b - mov cr4, eax - ret diff --git a/asm/x86-unknown-none/old/vesa.asm b/asm/x86-unknown-none/old/vesa.asm deleted file mode 100644 index 367b2c210e7bb2b42b6c2fa3534440c0e08b77f6..0000000000000000000000000000000000000000 --- a/asm/x86-unknown-none/old/vesa.asm +++ /dev/null @@ -1,198 +0,0 @@ -%include "vesa.inc" -SECTION .text -USE16 -vesa: -.getcardinfo: - mov ax, 0x4F00 - mov di, VBECardInfo - int 0x10 - cmp ax, 0x4F - je .findmode - mov eax, 1 - ret - .resetlist: - ;if needed, reset mins/maxes/stuff - xor cx, cx - mov [.minx], cx - mov [.miny], cx - mov [config.xres], cx - mov [config.yres], cx -.findmode: - mov si, [VBECardInfo.videomodeptr] - mov ax, [VBECardInfo.videomodeptr+2] - mov fs, ax - sub si, 2 -.searchmodes: - add si, 2 - mov cx, [fs:si] - cmp cx, 0xFFFF - jne .getmodeinfo - cmp word [.goodmode], 0 - je .resetlist - jmp .findmode -.getmodeinfo: - push esi - mov [.currentmode], cx - mov ax, 0x4F01 - mov di, VBEModeInfo - int 0x10 - pop esi - cmp ax, 0x4F - je .foundmode - mov eax, 1 - ret -.foundmode: - ;check minimum values, really not minimums from an OS perspective but ugly for users - cmp byte [VBEModeInfo.bitsperpixel], 32 - jb .searchmodes -.testx: - mov cx, [VBEModeInfo.xresolution] - cmp word [config.xres], 0 - je .notrequiredx - cmp cx, [config.xres] - je .testy - jmp .searchmodes -.notrequiredx: - cmp cx, [.minx] - jb .searchmodes -.testy: - mov cx, [VBEModeInfo.yresolution] - cmp word [config.yres], 0 - je .notrequiredy - cmp cx, [config.yres] - jne .searchmodes ;as if there weren't enough warnings, USE WITH CAUTION - cmp word [config.xres], 0 - jnz .setmode - jmp .testgood -.notrequiredy: - cmp cx, [.miny] - jb .searchmodes -.testgood: - mov al, 13 - call print_char - mov cx, [.currentmode] - mov [.goodmode], cx - push esi - ; call print_dec - ; mov al, ':' - ; call print_char - mov cx, [VBEModeInfo.xresolution] - call print_dec - mov al, 'x' - call print_char - mov cx, [VBEModeInfo.yresolution] - call print_dec - mov al, '@' - call print_char - xor ch, ch - mov cl, [VBEModeInfo.bitsperpixel] - call print_dec - mov si, .modeok - call print - xor ax, ax - int 0x16 - pop esi - cmp al, 'y' - je .setmode - cmp al, 's' - je .savemode - jmp .searchmodes -.savemode: - mov cx, [VBEModeInfo.xresolution] - mov [config.xres], cx - mov cx, [VBEModeInfo.yresolution] - mov [config.yres], cx - call save_config -.setmode: - mov bx, [.currentmode] - cmp bx, 0 - je .nomode - or bx, 0x4000 - mov ax, 0x4F02 - int 0x10 -.nomode: - cmp ax, 0x4F - je .returngood - mov eax, 1 - ret -.returngood: - xor eax, eax - ret - -.minx dw 640 -.miny dw 480 - -.modeok db ": Is this OK? (s)ave/(y)es/(n)o ",8,8,8,8,0 - -.goodmode dw 0 -.currentmode dw 0 -;useful functions - -; print a number in decimal -; IN -; cx: the number -; CLOBBER -; al, cx, si -print_dec: - mov si, .number -.clear: - mov al, "0" - mov [si], al - inc si - cmp si, .numberend - jb .clear - dec si - call convert_dec - mov si, .number -.lp: - lodsb - cmp si, .numberend - jae .end - cmp al, "0" - jbe .lp -.end: - dec si - call print - ret - -.number times 7 db 0 -.numberend db 0 - -convert_dec: - dec si - mov bx, si ;place to convert into must be in si, number to convert must be in cx -.cnvrt: - mov si, bx - sub si, 4 -.ten4: inc si - cmp cx, 10000 - jb .ten3 - sub cx, 10000 - inc byte [si] - jmp .cnvrt -.ten3: inc si - cmp cx, 1000 - jb .ten2 - sub cx, 1000 - inc byte [si] - jmp .cnvrt -.ten2: inc si - cmp cx, 100 - jb .ten1 - sub cx, 100 - inc byte [si] - jmp .cnvrt -.ten1: inc si - cmp cx, 10 - jb .ten0 - sub cx, 10 - inc byte [si] - jmp .cnvrt -.ten0: inc si - cmp cx, 1 - jb .return - sub cx, 1 - inc byte [si] - jmp .cnvrt -.return: - ret diff --git a/asm/x86-unknown-none/old/vesa.inc b/asm/x86-unknown-none/old/vesa.inc deleted file mode 100644 index 7f854761103ab4ea21d65f27e538d9e0eae17238..0000000000000000000000000000000000000000 --- a/asm/x86-unknown-none/old/vesa.inc +++ /dev/null @@ -1,90 +0,0 @@ -ABSOLUTE 0x5000 -VBECardInfo: - .signature resb 4 - .version resw 1 - .oemstring resd 1 - .capabilities resd 1 - .videomodeptr resd 1 - .totalmemory resw 1 - .oemsoftwarerev resw 1 - .oemvendornameptr resd 1 - .oemproductnameptr resd 1 - .oemproductrevptr resd 1 - .reserved resb 222 - .oemdata resb 256 - -ABSOLUTE 0x5200 -VBEModeInfo: - .attributes resw 1 - .winA resb 1 - .winB resb 1 - .granularity resw 1 - .winsize resw 1 - .segmentA resw 1 - .segmentB resw 1 - .winfuncptr resd 1 - .bytesperscanline resw 1 - .xresolution resw 1 - .yresolution resw 1 - .xcharsize resb 1 - .ycharsize resb 1 - .numberofplanes resb 1 - .bitsperpixel resb 1 - .numberofbanks resb 1 - .memorymodel resb 1 - .banksize resb 1 - .numberofimagepages resb 1 - .unused resb 1 - .redmasksize resb 1 - .redfieldposition resb 1 - .greenmasksize resb 1 - .greenfieldposition resb 1 - .bluemasksize resb 1 - .bluefieldposition resb 1 - .rsvdmasksize resb 1 - .rsvdfieldposition resb 1 - .directcolormodeinfo resb 1 - .physbaseptr resd 1 - .offscreenmemoryoffset resd 1 - .offscreenmemsize resw 1 - .reserved resb 206 - -VBE.ModeAttributes: - .available equ 1 << 0 - .bios equ 1 << 2 - .color equ 1 << 3 - .graphics equ 1 << 4 - .vgacompatible equ 1 << 5 - .notbankable equ 1 << 6 - .linearframebuffer equ 1 << 7 - -ABSOLUTE 0x5400 -VBEEDID: - .header resb 8 - .manufacturer resw 1 - .productid resw 1 - .serial resd 1 - .manufactureweek resb 1 - .manufactureyear resb 1 - .version resb 1 - .revision resb 1 - .input resb 1 - .horizontalsize resb 1 - .verticalsize resb 1 - .gamma resb 1 - .displaytype resb 1 - .chromaticity resb 10 - .timingI resb 1 - .timingII resb 1 - .timingreserved resb 1 - .standardtiming: resw 8 ;format: db (horizontal-248)/8, aspectratio | verticalfrequency - 60 - .aspect.16.10 equ 0 ;mul horizontal by 10, shr 4 to get vertical resolution - .aspect.4.3 equ 1 << 6 ;mul horizontal by 3, shr 2 to get vertical resolution - .aspect.5.4 equ 2 << 6 ;shl horizontal by 2, div by 5 to get vertical resolution - .aspect.16.9 equ 3 << 6 ;mul horizontal by 9, shr by 4 to get vertical resolution - .descriptorblock1 resb 18 - .descriptorblock2 resb 18 - .descriptorblock3 resb 18 - .descriptorblock4 resb 18 - .extensionflag resb 1 - .checksum resb 1 \ No newline at end of file diff --git a/asm/x86-unknown-none/stage2.asm b/asm/x86-unknown-none/stage2.asm index f04b11c6967140e0c3b89c364c06da641de3a84e..baa3f6b0ee0586a25c81f408630b62ba25e508eb 100644 --- a/asm/x86-unknown-none/stage2.asm +++ b/asm/x86-unknown-none/stage2.asm @@ -2,6 +2,9 @@ SECTION .text USE16 stage2.entry: + ; check for required features + call cpuid_check + ; enable A20-Line via IO-Port 92, might not work on all motherboards in al, 0x92 or al, 2 @@ -100,12 +103,13 @@ load_extent: call print_line ret +%include "cpuid.asm" %include "gdt.asm" +%include "long_mode.asm" %include "memory_map.asm" +%include "protected_mode.asm" %include "thunk.asm" %include "unreal.asm" -%include "protected_mode.asm" -%include "long_mode.asm" USE32 stage3.entry: