Hi. I think most of the mods are real-world system engineers/software engineers and they have probably learned their skills either on their own or in class, perhaps both. I myself taught myself. I am a second year CS major and I am just now taking my second Computer Course which relates with my minor and isn't even a programming class, my first one was JAVA. I just started at the bottom (or top) with HTML/JavaScript (web stuff), then I moved to VB (strict Windows user) and then C/C++, then ASM. I just wrote things I wanted to write and that made it both fun and rewarding, so I learned very fast. I wrote many things, and I always made sure they were big. I got my speed up and after... what is it now... 7 years? I thought OK lets go real big and dev an OS. It is very challenging work and even with 7 years I do not feel like I am completely worthy most of the time, some days I do though (when I make something work mainly). You have a long road ahead of you. I hope you stay committed to trying, because you will fail many times and it will seem like your moving backwards. It took me 5 months to make the keyboard respond, the keyboard!! I am fortunate to be as far as I am now (writing a sil3112 driver, thus denoting my near completion) in 6 months. My secret is:
01. I am totally an utterly obsessed with getting it done so much that I put in a lot of my time working on it... more than work or class, which is bad.
02. I stand upon the shoulders of giants and I port a lot of ideas. I try to stay away from Linux code, but I have looked at some things to see how they did it, such as the KB Shift Map.. I didn't use it, but I saw what to do and made my own (still very much different).
The fact that I write pretty well in C has helped a lot too. I suck at ASM, but I hold my own. My kernel is written in C with few ASM components; my HAL is in ASM. So, since C is more readable I would suggest that to you, but it doesn't hurt to know ASM better.
Check out Ralph Brown's INT list and that should help you get to know the functions you will use better. Write some hello world stuff and tweak it many different ways. Try to write the same program in C or C++ and that will help you with inline and also conversions from ASM to C. Get a manual of your compiler, Linker, and Assembler, you may need it.
And, because its your UN-Birthday (maybe your birthday) AND I want you to be successful, here is a starting point:
Code: Select all
;//FREE CODE, I DON'T F-ING CARE WHAT YOU DO WITH IT!! ENJOY AND HAPPY LEARNING!!
[BITS 16] ; We start the setup in Rmode
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
;*******************************
; Step 1: Load our Kernel into memory
;*******************************
reset_drive:
mov ah, 0 ; RESET-command
int 13h ; Call interrupt 13h
or ah, ah ; Check for error code
jnz reset_drive ; Try again if ah != 0
mov ax, 0
mov es, ax
mov bx, 0x1000 ; We load our code at offset: 0:1000h
mov ah, 02h ; READ SECTOR-command
mov al, 11h ; Number of sectors to read
mov ch, 0 ; Cylinder = 0
mov cl, 02h ; Sector = 2
mov dh, 0 ; Head = 0
int 13h ; Call interrupt 13h
or ah, ah ; Check for error code
jnz reset_drive ; Try again if ah != 0
.386 ; start using i386 instructions
;*******************************
; Step 2: Enable the A20 bus line
;*******************************
cli ;disable interrupts
xor cx, cx ;clear the CX register
clear_buf:
in al, 64h ; Get input from keyboard status port
test al, 02h ; Test the buffer full flag
loopnz clear_buf ; Loop until buffer is empty
mov al, 0D1h ; Keyboard: write to output port
out 64h, al ; Output command to keyboard
clear_buf2:
in al, 64h ; Wait 'till buffer is empty again
test al, 02h
loopnz clear_buf2
mov al, 0dfh ; Keyboard: set A20
out 60h, al ; Send it to the keyboard controller
mov cx, 14h
wait_kbc: ; This is approx. a 25uS delay to wait
out 0edh, ax ; for the kb controler to execute our
loop wait_kbc ; Command.
;*******************************
; Step 3: Enable GDT for Pmode
;*******************************
xor ax, ax
mov ds, ax ; Set DS-register to 0 - used by lgdt
lgdt [gdt_desc] ; Load the GDT descriptor
;*******************************
; Step 4: Clear Prefetch Queue
;*******************************
mov eax, cr0 ; Load the control register in
or al, 1 ; Set bit 1: pmode bit
mov cr0, eax ; Copy it back to the control register
;*******************************
; Step 5: Enable Pmode
;*******************************
jmp 08h:PModeMain ; Jump to code segment; Start Pmode
[BITS 32] ; We now need 32-bit instructions
PModeMain:
mov ax, 10h ; Save data segment identifyer
mov ds, ax ; Move a valid data segment into the data segment register
mov ss, ax ; Move a valid data segment into the stack segment register
mov esp, 090000h ; Move the stack pointer to 090000h
;*******************************
; Step 6: Boot our Kernel
;*******************************
jmp 08h:01000h ; Jump to section 08h (code), offset 01000h
;***********************************
;Configurations Section, DO NOT EDIT!!
;***********************************
gdt: ; Address for the GDT
gdt_null: ; Null Segment
dd 0
dd 0
gdt_code: ; Code segment, read/execute, nonconforming
dw 0FFFFh
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data: ; Data segment, read/write, expand down
dw 0FFFFh
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end: ; Used to calculate the size of the GDT
gdt_desc: ; The GDT descriptor
dw gdt_end - gdt - 1 ; Limit (size)
dd gdt ; Address of the GDT
times 510-($-$$) db 0 ; Fill up the file with zeros
dw 0AA55h ; Boot sector identifyer
Don't think I am leaving you hanging without the link info:
Code: Select all
@echo off
::**********************
::Change path to project folder
::**********************
set PATH=c:\djgpp\bin;%PATH%
set DJGPP=c:\djgpp\djgpp.env
chdir C:\djgpp\toy os\src
::***************
::Assemble OS Loader
::***************
nasm -f coff loader.asm -o loader.o
::******************
::Compile/Assemble Kernel
::******************
c:\djgpp\bin\gcc -ffreestanding -c main.c -o main.o
::**************
::Link it all together
::**************
c:\djgpp\bin\ld -Map kernel.sym -T 0x1000 -o kernel loader.o main.o
Something like that. Check your LD Manual for this... it may not be -T (I use a real LINK file in my OS); sorry.
OK. This will need GCC||DJGPP, LD, and NASM.
Side effects are: Once your OS gets bigger than 18 sectors your screwed and will need a second stage or GRUB to continue safely. Now get coding.
P.s. I hope no one gets upset with me helping so much; I believe in examples; sorry.