|
|
@ -3,9 +3,13 @@ |
|
|
|
%define GDT (GDT_Paragraph*16) |
|
|
|
%define GDT_CodeSegIndex 1 |
|
|
|
%define GDT_DataSegIndex 2 |
|
|
|
%define GDT_CodeSeg16Index 3 |
|
|
|
%define GDT_DataSeg16Index 4 |
|
|
|
%define GDT_Selector(DescriptorIndex, TableIndicator, RequestorPrivLevel) ((DescriptorIndex << 3) | ((TableIndicator & 1) << 2) | (RequestorPrivLevel & 0x3)) |
|
|
|
%define GDT_CodeSegmentSelector GDT_Selector(GDT_CodeSegIndex, 0, 0) |
|
|
|
%define GDT_DataSegmentSelector GDT_Selector(GDT_DataSegIndex, 0, 0) |
|
|
|
%define GDT_CodeSegSelector GDT_Selector(GDT_CodeSegIndex, 0, 0) |
|
|
|
%define GDT_DataSegSelector GDT_Selector(GDT_DataSegIndex, 0, 0) |
|
|
|
%define GDT_CodeSeg16Selector GDT_Selector(GDT_CodeSeg16Index, 0, 0) |
|
|
|
%define GDT_DataSeg16Selector GDT_Selector(GDT_DataSeg16Index, 0, 0) |
|
|
|
|
|
|
|
%define VIDEO 0xB8000 |
|
|
|
|
|
|
@ -180,22 +184,27 @@ Go32Bit: |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
mov ax, GDT_Paragraph |
|
|
|
mov es, ax |
|
|
|
mov cx, 1024 |
|
|
|
mov cx, 4096 |
|
|
|
lea si, [GO32_COPY_BEGIN] |
|
|
|
xor di, di |
|
|
|
rep movsb |
|
|
|
|
|
|
|
%assign GDT_SIZE 0 |
|
|
|
%assign GDT_COUNT 0 |
|
|
|
|
|
|
|
GDT_NULL_ENTRY 0 |
|
|
|
%assign GDT_SIZE (GDT_SIZE+8) |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_CodeSegIndex*8), 0x00000000, 0xffffffff, CodeRead, 0, 1 |
|
|
|
%assign GDT_SIZE (GDT_SIZE+8) |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_DataSegIndex*8), 0x00000000, 0xffffffff, DataMutable, 0, 1 |
|
|
|
%assign GDT_SIZE (GDT_SIZE+8) |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_CodeSeg16Index*8), 0x00000000, 0xffffffff, CodeRead, 0, 0 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
GDT_ENTRY (GDT_DataSeg16Index*8), 0x00000000, 0xffffffff, DataMutable, 0, 0 |
|
|
|
%assign GDT_COUNT (GDT_COUNT+1) |
|
|
|
|
|
|
|
cli |
|
|
|
lgdt [GDT_Record] |
|
|
@ -215,10 +224,10 @@ ClearPrefetchQueue: |
|
|
|
db 0x66 ; 32bit override |
|
|
|
db 0xea ; Long jump |
|
|
|
dd ProtectedModeBaby ; Absolute address |
|
|
|
dw GDT_CodeSegmentSelector ; Descriptor Selector |
|
|
|
dw GDT_CodeSegSelector ; Descriptor Selector |
|
|
|
|
|
|
|
GDT_Record: |
|
|
|
dw GDT_SIZE - 1 ; Size of GDT in bytes minus 1 |
|
|
|
dw (GDT_COUNT*8) - 1 ; Size of GDT in bytes minus 1 |
|
|
|
dd 0x1000*16 ; Linear address of GDT |
|
|
|
|
|
|
|
|
|
|
@ -229,12 +238,12 @@ BITS 32 |
|
|
|
GO32_COPY_BEGIN: |
|
|
|
|
|
|
|
segment Go32Bit vstart=GDT |
|
|
|
GDT_SPACE: times 3 dw 0, 0, 0, 0;dq 0 |
|
|
|
GDT_SPACE: times (GDT_COUNT*8) db 0 |
|
|
|
|
|
|
|
ProtectedModeBaby: |
|
|
|
|
|
|
|
; Update Other Segments |
|
|
|
mov ax, GDT_DataSegmentSelector |
|
|
|
mov ax, GDT_DataSegSelector |
|
|
|
mov ds, ax |
|
|
|
mov ss, ax |
|
|
|
mov es, ax |
|
|
@ -242,65 +251,197 @@ ProtectedModeBaby: |
|
|
|
mov gs, ax |
|
|
|
|
|
|
|
; Setup stack |
|
|
|
mov esp, 0xffffffff |
|
|
|
mov esp, 0x800000 |
|
|
|
mov ebp, esp |
|
|
|
|
|
|
|
DrawStuff: |
|
|
|
mov ecx, 0 |
|
|
|
mov edx, 0 |
|
|
|
lea edi, [VIDEO] |
|
|
|
mov ax, 0x4000 |
|
|
|
LoopRows: |
|
|
|
LoopCols: |
|
|
|
mov bl, cl |
|
|
|
and bl, dl |
|
|
|
shl bl, 4 |
|
|
|
mov ah, bl |
|
|
|
ror bl, 1 |
|
|
|
xor ah, bl |
|
|
|
and ah, 0x70 |
|
|
|
mov al, dl |
|
|
|
add al, cl |
|
|
|
and al, 4 |
|
|
|
ror al, 1 |
|
|
|
or ah, al |
|
|
|
mov al, 0 |
|
|
|
mov WORD [edi], ax |
|
|
|
inc edi |
|
|
|
inc edi |
|
|
|
inc ecx |
|
|
|
cmp ecx, 80 |
|
|
|
je BreakLoopCols |
|
|
|
jmp LoopCols |
|
|
|
BreakLoopCols: |
|
|
|
mov al, '@' |
|
|
|
DrawBG: |
|
|
|
mov eax, [Px] |
|
|
|
shr eax, 6 |
|
|
|
add eax, ecx |
|
|
|
imul eax, eax |
|
|
|
sar eax, 1 |
|
|
|
; mov ax, bx |
|
|
|
|
|
|
|
mov ebx, [Py] |
|
|
|
shr ebx, 6 |
|
|
|
add ebx, edx |
|
|
|
imul ebx, ebx |
|
|
|
add eax, ebx |
|
|
|
|
|
|
|
; eax = x^2 + y^2 |
|
|
|
mov ebx, [ColorOffset] |
|
|
|
; imul eax, ebx |
|
|
|
sar ebx, 8 |
|
|
|
|
|
|
|
; mov ebp, eax |
|
|
|
; mov bl, (0xda - 0xb3) |
|
|
|
; div byte bl |
|
|
|
; mov bl, ah |
|
|
|
; add bl, 0xb3 |
|
|
|
; mov eax, ebp |
|
|
|
|
|
|
|
; mov al, bl |
|
|
|
; push eax |
|
|
|
; push edx |
|
|
|
; rdtsc |
|
|
|
; mov ebx, eax |
|
|
|
; shr ebx, 26 |
|
|
|
; pop edx |
|
|
|
; pop eax |
|
|
|
|
|
|
|
; mov ah, bl |
|
|
|
|
|
|
|
add ah, bl |
|
|
|
|
|
|
|
stosw |
|
|
|
|
|
|
|
inc ecx |
|
|
|
cmp ecx, 80 |
|
|
|
jne DrawBG |
|
|
|
|
|
|
|
mov ecx, 0 |
|
|
|
inc edx |
|
|
|
cmp edx, 25 |
|
|
|
je BreakLoopRows |
|
|
|
jmp LoopRows |
|
|
|
BreakLoopRows: |
|
|
|
cmp edx, 24 |
|
|
|
jne DrawBG |
|
|
|
|
|
|
|
WriteProtectedModeString: |
|
|
|
cld |
|
|
|
lea esi, [ProtectedWelcomeStr] |
|
|
|
lea edi, [VIDEO+(80*2)*12+19*2] |
|
|
|
|
|
|
|
xor eax, eax |
|
|
|
|
|
|
|
in al, 0x60 ; Get the scan code from the keyboard |
|
|
|
; mov byte [0x98765], al |
|
|
|
; cmp al, 0x01 |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0x2A ; Left Shift Make |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0x36 ; Right Shift Make |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0xAA ; Left Shift Break |
|
|
|
; je .ThereWasNothing |
|
|
|
; cmp al, 0xB6 ; Right Shift Break |
|
|
|
; je .ThereWasNothing |
|
|
|
cmp al, 0x4b; left |
|
|
|
je .KeyLeft |
|
|
|
cmp al, 0x48; up |
|
|
|
je .KeyUp |
|
|
|
cmp al, 0x50; right |
|
|
|
je .KeyDown |
|
|
|
cmp al, 0x4d; down |
|
|
|
je .KeyRight |
|
|
|
; test al, 0x80 |
|
|
|
; je .ThereWasSomething |
|
|
|
.ThereWasNothing: |
|
|
|
mov [Key], byte ' ' |
|
|
|
jmp .PrintKeyLegend |
|
|
|
; lea esi, [ProtectedWelcomeStr] |
|
|
|
|
|
|
|
|
|
|
|
.KeyLeft: |
|
|
|
mov [Key], byte 'L' |
|
|
|
add [Px], dword -1 |
|
|
|
jmp .PrintKeyLegend |
|
|
|
.KeyUp: |
|
|
|
mov [Key], byte 'U' |
|
|
|
add [Py], dword -1 |
|
|
|
jmp .PrintKeyLegend |
|
|
|
.KeyRight: |
|
|
|
mov [Key], byte 'R' |
|
|
|
add [Px], dword 1 |
|
|
|
jmp .PrintKeyLegend |
|
|
|
.KeyDown: |
|
|
|
mov [Key], byte 'D' |
|
|
|
add [Py], dword 1 |
|
|
|
.PrintKeyLegend: |
|
|
|
lea esi, [ThereWasSomethingStr] |
|
|
|
|
|
|
|
lea edi, [VIDEO+(80*24 + (80-11))*2] |
|
|
|
; lea edi, [VIDEO+(80*2)*12+30*2] |
|
|
|
mov ah, 0x0f |
|
|
|
.print_loop: |
|
|
|
mov al, BYTE [esi] |
|
|
|
test al, al |
|
|
|
jz .break_print_loop |
|
|
|
mov BYTE [edi], al |
|
|
|
mov BYTE [edi+1], 0x0f |
|
|
|
stosw |
|
|
|
inc esi |
|
|
|
inc edi |
|
|
|
inc edi |
|
|
|
jmp .print_loop |
|
|
|
.break_print_loop: |
|
|
|
|
|
|
|
lea edi, [VIDEO + (80*24 + 1)*2] |
|
|
|
mov ecx, 40 |
|
|
|
xor eax, eax |
|
|
|
rep stosw |
|
|
|
lea edi, [VIDEO + (80*24 + 1)*2] |
|
|
|
mov eax, dword [Px] |
|
|
|
shr eax, 6 |
|
|
|
call StringifyEax10 |
|
|
|
|
|
|
|
lea edi, [VIDEO + (80*24 + 10)*2] |
|
|
|
mov eax, dword [Py] |
|
|
|
shr eax, 6 |
|
|
|
call StringifyEax10 |
|
|
|
|
|
|
|
add [ColorOffset], dword 1 |
|
|
|
|
|
|
|
jmp DrawStuff |
|
|
|
HALT: |
|
|
|
cli |
|
|
|
hlt |
|
|
|
jmp HALT |
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
StringifyEax10: |
|
|
|
; Puts the stringified version of eax on the stack |
|
|
|
; IN: eax = number to write |
|
|
|
; IN: edi = base of where to write string |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
pushad |
|
|
|
|
|
|
|
mov ebx, 10 ; Divisor |
|
|
|
|
|
|
|
xor ecx, ecx ; Digit count starts at 0 |
|
|
|
|
|
|
|
.loop_divide: ; finds digits and pushes them to stack |
|
|
|
test eax, eax |
|
|
|
jz .break_loop_divide |
|
|
|
xor edx, edx |
|
|
|
div ebx ; edx = (edx:eax)%ebx, eax = (edx:eax)/ebx |
|
|
|
inc ecx ; Increase digit count |
|
|
|
mov byte [.buffer + ecx], dl |
|
|
|
jmp .loop_divide |
|
|
|
.break_loop_divide: |
|
|
|
; dec ecx |
|
|
|
add edi, 16 |
|
|
|
sub edi, ecx |
|
|
|
sub edi, ecx |
|
|
|
|
|
|
|
.loop_print: |
|
|
|
test ecx, ecx |
|
|
|
jz .break_loop_print |
|
|
|
mov al, byte [.buffer + ecx] |
|
|
|
add al, '0' ; Convert to ascii |
|
|
|
mov ah, 0x0f |
|
|
|
stosw |
|
|
|
dec ecx |
|
|
|
jmp .loop_print |
|
|
|
.break_loop_print: |
|
|
|
popad |
|
|
|
ret |
|
|
|
.buffer times 40 db 0 |
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
;; Strings |
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;; |
|
|
|
ProtectedWelcomeStr: db " Placeholder for SingOS - 32 bit edition! ", 0 |
|
|
|
ThereWasSomethingStr: db " KEY = '" |
|
|
|
Key: db " ' ", 0 |
|
|
|
Px: dd 0 |
|
|
|
Py: dd 0 |
|
|
|
ColorOffset: dw 0 |
|
|
|
align 512 |