protected mode or drivers first?
Posted: Tue Mar 02, 2021 9:10 pm
Hi All,
I decided to make a unikernel or library operating system after spending a long time developing applications for real mode that used BIOS interrupts.
(An example of my absolutely flawless top-notch real-mode programs can be found here:
https://gitlab.com/jhumphrey/tty-pre-alpha)
I came to myself, repented of my misdeeds, and decided that I would experience the joys of writing my own drivers instead of having the BIOS do it. Additionally, I wanted to have my programs support multiple alphabets and "successfully" made a driver to handle 8x8 text in mode 11h. I know that it is possible to not use BIOS interrupts, and write your own drivers in real mode, but I figure that eventually, I might want to get into protected mode.
First, because I don't know what kinda programs I am going to try to do.
I am going to port blender to bare metal, with a java VM and windows emulation in 1 meg!!!
Second, I don't know if the CPUs of the future will still have a real mode.
Third, y'all seem to frown on real mode, even though Lou Dite (Ludite) told me something about real mode being the only valid mode, but I do want to use halal osdev practices.
My question is, should I spend my time implementing drivers in REAL mode and then "upgrade" to protected or long mode, or should I concentrate on getting to protected or long mode first, and then implementing drivers? it would seem that it could be hard to port RM code to PM or LM because of different memory schemes.
Recently I have been trying to get into protected mode, but my heart is really more in the drivers than the memory. It might be fun writing the same driver twice, but ultimately it would be a waste of time. I have encountered a difficulty enabling the A20 gate. (The VM crashes) I am sure that it is a simple oversight that I will eventually find (like every other of the countless oversights.) but here is the code for laughs:
And here is the error:
I am still developing my debugging skills, so apologize if this is mundane.
I am not sold on protected mode (though knowing I have more than 1MB could be comforting.) so I feel like "is it really worth the effort to get into protected mode?" but then part of me feels like, "you have to be able to figure it out!"
Thanks,
Johnpaul
P.S: I apologize for not replying to my previous thread, I forgot to check the notify box!
I checked it this time.
I decided to make a unikernel or library operating system after spending a long time developing applications for real mode that used BIOS interrupts.
(An example of my absolutely flawless top-notch real-mode programs can be found here:
https://gitlab.com/jhumphrey/tty-pre-alpha)
I came to myself, repented of my misdeeds, and decided that I would experience the joys of writing my own drivers instead of having the BIOS do it. Additionally, I wanted to have my programs support multiple alphabets and "successfully" made a driver to handle 8x8 text in mode 11h. I know that it is possible to not use BIOS interrupts, and write your own drivers in real mode, but I figure that eventually, I might want to get into protected mode.
First, because I don't know what kinda programs I am going to try to do.
I am going to port blender to bare metal, with a java VM and windows emulation in 1 meg!!!
Second, I don't know if the CPUs of the future will still have a real mode.
Third, y'all seem to frown on real mode, even though Lou Dite (Ludite) told me something about real mode being the only valid mode, but I do want to use halal osdev practices.
My question is, should I spend my time implementing drivers in REAL mode and then "upgrade" to protected or long mode, or should I concentrate on getting to protected or long mode first, and then implementing drivers? it would seem that it could be hard to port RM code to PM or LM because of different memory schemes.
Recently I have been trying to get into protected mode, but my heart is really more in the drivers than the memory. It might be fun writing the same driver twice, but ultimately it would be a waste of time. I have encountered a difficulty enabling the A20 gate. (The VM crashes) I am sure that it is a simple oversight that I will eventually find (like every other of the countless oversights.) but here is the code for laughs:
Code: Select all
; nasm -f bin
BITS 16
ORG 0x7c00
cli
call a20enable
;nothing gets executed beyond here
mov ebx, 0xb8000
mov byte [ebx], 'X'
jmp $
a20enable:
push ax
call a20test
call a20bios
call a20test
call a20kbd
call a20test
call a20fast
call a20test
;it didn't work
mov dword [ebx],":0(0"
hlt
.enabled:
pop ax
ret
a20test:
mov ax, 0x0000
mov es, ax
mov byte [es:0x500], 0x00
mov ax, 0xFFFF
mov gs, ax
mov byte [gs:0x510], 0xFF
mov al, byte [es:0x500]
cmp al, 0
je a20enable.enabled
ret
a20bios:
sti
mov ah, 0x24
mov al, 0x01
int 15h
cli
ret
a20kbd:
call kbdcmdwait
mov al, 0xAD ;PS2 port 1 -> OFF
out 0x64, al
call kbdcmdwait
mov al, 0xD0 ;request output rom controller
out 0x64, al
call kbddatawait ;wait for it....
in al, 0x60 ;here we go!
or al, 2 ;A20 -> ON
push ax
call kbdcmdwait
mov al, 0xD1 ;write out
out 0x64, al
pop ax
out 0x60, al
call kbdcmdwait
mov al, 0xae ;PS2 port 1 -> ON
out 0x64, al
ret
kbdcmdwait:
in al, 0x64
test al, 1
jnz kbdcmdwait
ret
kbddatawait:
in al, 0x64
test al, 2
jnz kbddatawait
ret
a20fast:
in al, 0x92
or al, 2
out 0x92, al
ret
boot:
TIMES 510-($-$$) db 0
dw 0xAA55
Code: Select all
qemu: fatal: Trying to execute code outside RAM or ROM at 0x000a0000
EAX=00007b0c EBX=00000000 ECX=00000000 EDX=00000080
ESI=00000000 EDI=00000000 EBP=00006ef0 ESP=00006ef0
EIP=0009ffbc EFL=00000016 [----AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 00000000 0000ffff 00009300
CS =0000 00000000 0000ffff 00009b00
SS =0000 00000000 0000ffff 00009300
DS =0000 00000000 0000ffff 00009300
FS =0000 00000000 0000ffff 00009300
GS =ffff 000ffff0 0000ffff 00009300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT= 00000000 00000000
IDT= 00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00007b0c CCD=00007b7b CCO=ADDB
EFER=0000000000000000
FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
Aborted (core dumped)
I am not sold on protected mode (though knowing I have more than 1MB could be comforting.) so I feel like "is it really worth the effort to get into protected mode?" but then part of me feels like, "you have to be able to figure it out!"
Thanks,
Johnpaul
P.S: I apologize for not replying to my previous thread, I forgot to check the notify box!
I checked it this time.