Clan x86

Technical (Development, Security, etc.) => General Programming => Operating System Development => Topic started by: Joe on June 16, 2005, 10:19:50 am

Title: JoeOS: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 10:19:50 am
Well, Warrior got somewhere, I guess..

I've been slacking off on learning ASM, and frankly I want to learn it. Also, with learning PHP and Java, I should know enough of the common syntax to slack my way though a bit of C++, so here I go. I found some online tutorials, and I probably have the entire source code to OptimaOS seeing as how Warrior always lobs it at me over AIM (<3), so I'm gonna give it a shot. I've got my old Compaq Presario CDS 520, now named poptart (Thanks Ergot!) as a test box, because MS VPC hates me. I'll let you guys know how it goes.

EDIT -
I now understand why they said we'll be hitting our heads against the wall for the majority of the time. Where the fuck is Warrior?
Title: Re: I'm gonna try some OS Development
Post by: rabbit on June 16, 2005, 05:04:33 pm
Some powercord of his was being retarded and overheated randomly.  He had to send in is faulty "modem" to get a new power cord.  He'll be back soon.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 05:22:22 pm
Seriously? Because I just talked to him last night, and hes on AIM right now (not responding).

EDIT -
Well he was on earlier.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 07:48:12 pm
JoeOS rocks out loud. It doesn't do a single damned thing, but loop infinitly. It rocks!

Code: [Select]
[BITS 16]             ;This tells us we are using 16 Bits
[ORG 0x7C00]          ;We need to tell it the origin now

start:
jmp $

times 510-($-$$) db 0 ;This fills the rest of unused space with 0s
dw 0xAA55             ;Now our signature

Warrior's holding my hand through displaying "JoeOS" to the screen. So far we haven't even mastered the J yet. I mean, its displaying and all.. its just not.

Code: [Select]
[BITS 16]             ;This tells us we are using 16 Bits
[ORG 0x7C00]          ;We need to tell it the origin now

start:

     xor ax, ax ; Make AX = 0
     mov cs, ax ; Setup our registers
     mov ds, ax ; Setup our registers
     mov es, ax ; Setup our registers
     mov fs, ax ; Setup our registers
     
     mov ah, 0Eh
     mov al, 'J'
     mov bh, 0
     mov bl, 0x07
     int 10h
     
jmp $

times 510-($-$$) db 0 ;This fills the rest of unused space with 0s
dw 0xAA55             ;Now our signature
Title: Re: I'm gonna try some OS Development
Post by: Sidoh on June 16, 2005, 07:53:29 pm
Uhm, what the hell? Why do all your comments say "we?" Do you program with a turd in your pocket? :D
Title: Re: I'm gonna try some OS Development
Post by: RoMi on June 16, 2005, 08:01:56 pm
He has been assimilated into the computer, your resistance is futile.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 08:02:24 pm
No, but Warriors holding my hand, in a non gay way. Hes giving me the comments to put in there anyhow. =).

EDIT -
I got my J.
(18:14:39) [x86] Warrior: OK U GOT A JAY
(18:15:45) [x86] Joe: YES I DID
(18:15:51) [x86] Joe: AND I GOT MY BRO TO COME LOOK AT IT!
(18:16:15) [x86] Joe: "Thats really really really gay!"
Title: Re: I'm gonna try some OS Development
Post by: Nate on June 16, 2005, 08:56:47 pm
-----
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 08:57:51 pm
Omg, it printed JoeOS to the screen. I am totally the worlds most awesomest hacker!

Code: [Select]
[BITS 16] ;This tells us we are using 16 Bits
[ORG 0x7C00] ;We need to tell it the origin now

  start:

    ;xor ax, ax ; Make AX = 0
    ;mov cs, ax ; Setup our registers
    ;mov ds, ax ; Setup our registers
    ;mov es, ax ; Setup our registers
    ;mov fs, ax ; Setup our registers

    mov ah, 0Eh
    mov bh, 0
    mov bl, 0x07
    mov al, 'J'
    int 10h
    mov al, 'o'
    int 10h
    mov al, 'e'
    int 10h
    mov al, 'O'
    int 10h
    mov al, 'S'
    int 10h

  jmp $

times 510-($-$$) db 0 ;This fills the rest of unused space with 0s
dw 0xAA55 ;Now our signature

Now, when Warrior gets back from playing CS, I'm going to make it print colored strings!
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 16, 2005, 09:18:23 pm
That's a very crappy way of printing strings :P

You should also note that in the bootloader as I have told you before you are limited to 512 bytes in which you must load a second stage using the int 0x13 and read however many sectors you want to whatever location in the memory you want.

In the second stage you should prepare to enter protected mode: Enable the a20 line so that you can access the full 4GB in protected mode, setup atleast 3 GDT entries (Null, Code, Data), set the lower bit in cr0, then do a far jump to set CS. Once you're in protected mode you can either load an additional GDT (since the usefulness of your bootloader's GDT can be doubted for some reason) or use the one from before. Then you must handle request for Interrupts and distinguish which ones are exceptions and which are interrupts. This is done by setting up the IDT and handling ISRs. Once you have a *strong* exception handler (you can print registers). I'd work on polling port 0x60 every time you recieve IRQ6 (keybord) for the current character then using a scan code to convert it to ASCII. At this point you can either implement your own variant of "printf" and start implementing your library, or do what I did and setup a sort of driver manager to manage requests for notification of drivers.

Like so:

ServiceA(console) requests Keyboard Notification
ServiceB(someotherservice) requests Keyboard Notificiation

Keyboard IRQ Handler recieves interrupt:
Sends to all of the currently "registered" services for the Driver

Advantages of this: You don't have to have a lot of code in your IRQ handler, just something to dish out whatever needed.

Additionally having an app be able to request scancodes "on the go" using some sort of getkb(int num) to read each character and format it into a string then return when the number is met.

After this I'd implement a scheduler and maybe pre-emptive multitasking whichever then have some kernel level tasks working and swithing first before you move to User Level.

Anything after that is up to you:
Possibly some sort of VFS compatiblity layer? Maybe just run on to implementing something like NTFS or ext2?
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 16, 2005, 09:19:49 pm
Due to preference you may want to switch over to fasm which has basicly the same syntax of NASM but better error reporting and macros.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 09:23:53 pm
Your entire post went right over my head Warrior. Get back on AIM so we can take it nice and slow. Ugh, that sounds discusting. =p

EDIT -
I googled FASM. Am I looking for the flat assembler?
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 16, 2005, 09:27:30 pm
Yep.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 09:28:51 pm
Good. GET ON AIM!
Title: Re: I'm gonna try some OS Development
Post by: Blaze on June 16, 2005, 10:46:18 pm
*Hurrys up and tries to finish his asm book*
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 16, 2005, 11:47:38 pm
Shut up Sidoh. Lets see you write something better. Thanks for the input c0n, I'm trying to get that working. Warrior gave me some code, but its fucked up big time. He went to lay down, and I'm working with Darkness now.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 12:12:36 am
Want your own copy of JoeOS?! Well, you're high. Anyhow, download this (http://www.javaop.com/~joe/joeos.zip), unzip it, and execute make. (You're going to need a floppy disk in fd0, probably a:).
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 17, 2005, 04:37:04 am
Kernel was always easier for me provided I have a good exception handling system for my messups and a semi decent Library
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 12:18:36 pm
c0n, you probably haven't knoticed yet, but Mangix is a moron who has trouble with VisualBasic. Anyone know whats wrong with the following code? It doesn't do jack shit except hang.

Code: [Select]
;-----------------------------------------------------------------------------------------
; These are my string constats. 0x01 is a smily face, 0x0D is a CR, 0x0A is a LF, and 0x00
; is a null terminator. Anything in quotes is the text of the string.
msgwelcome       db "Welcome to JoeOS by Joe[x86]! ",            0x01, 0x0D, 0x0A, 0x00
msghalt          db "Bootloader halted.",                              0x0D, 0x0A, 0x00
msgshutdownsafe  db "It is now safe to shutdown your computer.",       0x0D, 0x0A, 0x00
msgnewline       db                                                    0x0D, 0x0A, 0x00

; ----------------------------------------------------------------------------------------
; Here is the information that shows the processor where the origin of the bootloader is,
; and how many bits we're using.
[BITS 16]     ; This tells us we are using 16 Bits
[ORG 0x0]     ; Origin = 0x00
jmp 0x7c0:start ; Set start to 0x07C0 and start the procecdure "start" there

;-----------------------------------------------------------------------------------------
; This is my start procedure. This initiates the operating system environment, and calls
; my print procedure to display some messages
start:
  xor ax, ax
  mov ax, cs
  mov ds, ax
  mov es, ax
  mov fs, ax
  ; Here I set the value of ax, ds, es, and fs to 0. I cant access these directly, so I xor
  ; ax to make it zero and move it to each of them.

  mov si, msgwelcome
  call print
  ; "Welcome to JoeOS by Joe[x86]! (smile)"
 
  mov si, msghalt
  callcprint
  ; "Bootloader halted."
 
  mov si, msgshutdownsafe
  call print
  ; "It is now safe to shutdown your computer."
 
jmp $ ; Hang
times 510-($-$$) db 0   ; This fills the rest of unused space with 0s
dw 0xAA55               ; Include bootloader signature

;-----------------------------------------------------------------------------------------
; Here is the print procedure I will be using. Written by Warrior[x86]. Broken. =/.
print:
  mov ah, 0x10
  mov bh, 0x00          ; Page = 0
  mov bl, 0x09          ; Color = Blue
  lodsb                 ; Load SI into AL
  cmp al, 0             ; If we hit a null terminator..
  je .Done              ; Go to the label ".Done"
  int 0x10              ; print the character
  jmp print             ; print until the whole string is printed
  .Done:                ; The label ".Done"
ret


EDIT -
OMG WTF I FOUND DEE PROBLEM IT IS 528 KB NOT 512 WTF HELP ME FIX IT WAR!~
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 01:38:11 pm
If you want to tear me down, do it somewhere where I'm not a moderator. Get out of my forum or be positive towards my projects.
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 17, 2005, 03:18:12 pm
I'd think that the far jump would set the CS register *shrug* I lost my source so it's hard to tell what you're doing wrong.

You put your print procedure under the code that fills the rest with zeros so yes, you will step out of the 512 byte limit.

Smooth.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 06:26:16 pm
*cough* Ok. =).
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 17, 2005, 06:43:11 pm
Look up int 13h, you're going to want to have a second stage loaded soon
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 07:37:50 pm
Have these IA-32 processors learned nothing of my stubbornness? Well, looks like they gave up. It works now. I don't have my working bootloader in the zip yet, because it takes forever to upload over SFTP, but download the zip and replace the bootloader.asm file with this (http://www.javaop.com/~joe/joeos/bootloader.asm) if you wanna check it out.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 17, 2005, 10:44:03 pm
I made a JoeOS readme. Poke! (http://www.javaop.com/~joe/joeos/readme.txt) Check it out.
Title: Re: I'm gonna try some OS Development
Post by: zorm on June 17, 2005, 11:06:13 pm
Are you testing on an old system or in something like VMWare or Bochs?
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 17, 2005, 11:14:45 pm
He has a test bed. Bochs is handy for it's useful debug messages and ability to emulate floppys, cdroms, etc.. and even has the ability to plug in additional BIOS's. Oh yea it's open source. 2.2 came out not too long ago :]
Title: Re: I'm gonna try some OS Development
Post by: Blaze on June 17, 2005, 11:37:34 pm
I just tried joes os.  The coolest thing there was the smiley.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 18, 2005, 12:03:47 am
Zorm, I'm testing on a Compaq Presario CDS 520 (an old computer), and occasionally VirtualPC and my bros Dell Dimension 2300.

Warrior, I never got Bochs to work, but I have it installed. VPC likes to kill my modem driver. Wanna help me get Bochs to work? Thanks!

Damn right, Blaze. Go Palio! Oh wait, did I just agree with being torn down? Pfft, you suck Blaze! <3.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 18, 2005, 03:35:20 am
I have successfully loaded my pre-kernel from my floppy disk, so I am out of developming my bootloader, and am no longer restricted by Real Mode and the 512K bootloader limit. I should be able to enter Protected Mode and load a kernel now, however I'll save that for tomorrow. Aparently I've passed c0n at OS development, and thats enough for the first two days, if you ask me. I'm going to bed, cya tomorrow Warrior.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 18, 2005, 05:20:09 pm
Quote
[15:25:22] <Joe[x86]2> wtf
[15:25:24] <Joe[x86]2> well
[15:25:30] <Joe[x86]2> It loads stage 1 just fine
[15:25:37] <Joe[x86]2> attempts to load stage two
[15:25:38] <Joe[x86]2> and does
[15:25:39] <Joe[x86]2> and
[15:25:49] <Joe[x86]2> stage two prints its welcome message.. *counts*
[15:25:57] <Joe[x86]2> 10 fucking times

Oh man, I need to cut myself. I've done a lot of cutting myself lately. By the way, I hope you know I'm not serious about cutting myself. I haven't even hit my head against the wall yet.
Title: Re: I'm gonna try some OS Development
Post by: Tuberload on June 19, 2005, 05:13:17 am
Quote
[15:25:22] <Joe[x86]2> wtf
[15:25:24] <Joe[x86]2> well
[15:25:30] <Joe[x86]2> It loads stage 1 just fine
[15:25:37] <Joe[x86]2> attempts to load stage two
[15:25:38] <Joe[x86]2> and does
[15:25:39] <Joe[x86]2> and
[15:25:49] <Joe[x86]2> stage two prints its welcome message.. *counts*
[15:25:57] <Joe[x86]2> 10 fucking times

Oh man, I need to cut myself. I've done a lot of cutting myself lately. By the way, I hope you know I'm not serious about cutting myself. I haven't even hit my head against the wall yet.

Keep at it and soon the problem will slap you in the face and be as obvious as the fact that you smell funny.
Title: Re: I'm gonna try some OS Development
Post by: Joe on June 19, 2005, 12:47:29 pm
Shut up. You know I don't like people talking about my BO issue. =(

I already fixed it. I was ret'ing instead of jmp'ing.
Title: Re: I'm gonna try some OS Development
Post by: Blaze on June 19, 2005, 12:48:32 pm
You know I don't like people talking about my BO issue. =(
Well, its public now.
Title: Re: I'm gonna try some OS Development
Post by: Tuberload on June 19, 2005, 04:34:28 pm
Shut up. You know I don't like people talking about my BO issue. =(

I already fixed it. I was ret'ing instead of jmp'ing.

;D I took a lucky guess.

Good job on figuring out the problem!
Title: Re: I'm gonna try some OS Development
Post by: Warrior on June 19, 2005, 04:46:29 pm
rofl you're such a retard joe.
Title: Re: I'm gonna try some OS Development
Post by: Tuberload on June 19, 2005, 04:49:57 pm
It's just a joke, he doesn't have a BO problem. We're just trying to make people laugh!
Title: Re: I'm gonna try some OS Development
Post by: Nate on June 19, 2005, 05:39:23 pm
It's just a joke, he doesn't have a BO problem. We're just trying to make people laugh!

Then post a picture of your mom.  Also Joe what advantage does JoeOS have over say Windows XP?  I've been thinking of down-grading to the stone age but I don't know if you are there yet.
Title: Re: I'm gonna try some OS Development
Post by: 01Linux on June 19, 2005, 06:04:04 pm
JoeOS is pre-stone age :p
Title: Re: I'm gonna try some OS Development
Post by: Tuberload on June 19, 2005, 07:59:32 pm
Then post a picture of your mom.

Maybe you would get a laugh, superiority tends to make the jealous laugh in an attempt to keep their insecurities under wraps.

Quote
Also Joe what advantage does JoeOS have over say Windows XP?  I've been thinking of down-grading to the stone age but I don't know if you are there yet.

You're an idiot plain and simple.
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Joe on June 19, 2005, 09:03:26 pm
yeah yeah, saying I was ahead was War's idea. =p

I screwed up my stage two loading, but I can fix it.. later!
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Warrior on June 19, 2005, 09:05:48 pm
As a joke and wasn't meant to go further than a joke
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Nate on July 11, 2006, 06:59:31 pm
I know its been a while but i got bored and am trying some OSDev and ill probably start my own topic but in Warrior's print function that Joe uses 'mov ah, 0x10' makes absolutely no sense.  Shouldn't it be 'mov ah, 0x0E' or maybe 'mov ah, 0x13'?
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Warrior on July 13, 2006, 01:00:58 pm
To be completely honest, I havn't looked at RBIL in a while so it may/may not be right. Of course anything I program is perfect so I'd say "Working as intended" unless of course..Joe managed to screw it up.
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Joe on July 15, 2006, 07:48:19 am
   AH = 0Eh
   AL = character to write
   BH = page number
   BL = foreground color (graphics modes only)


Function to print, untested
(WORD) Length of the string
(WORD) String Pointer

Code: [Select]
printf:
    ; Take in the arguments
    pop ax ; String length
    pop bx ; String pointer

    ; Set the interrupt arguments
    mov ah, 0Eh
    mov bh, 0
    mov bl, 07h

    xor cx, cx ; cx is counter, set to 0

  .startloop
    mv al, [bx+cx] ;[bx+cx] is the character to print
    int 10h
    cmp cx, ax
    je .end
    jmp startloop

  .end
ret
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Warrior on July 15, 2006, 11:55:19 am
Do you even know how printf() works? You'd need to implement stdarg.h and various functions to convert to different things like signed integers, unsigned integers, hex, etc..
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Joe on July 16, 2006, 04:47:32 am
Change the name from printf. It still prints a string.
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: Warrior on July 16, 2006, 04:05:39 pm
I'm still not confortable using the stack before PMode, it's more to cleanup and the same could be acomplished by using the registers which are doing very little..
Title: Re: JoeOS: I'm gonna try some OS Development
Post by: MyndFyre on July 18, 2006, 01:18:23 pm
I'm still not confortable using the stack before PMode, it's more to cleanup and the same could be acomplished by using the registers which are doing very little..
You know, even DOS C libraries had printf.  Psh.

Although, Joe, printf is named printf because it prints a formatted string....