Author Topic: Never even looked at x86 let alone OSDev before yesterday.  (Read 9081 times)

0 Members and 1 Guest are viewing this topic.

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Never even looked at x86 let alone OSDev before yesterday.
« on: July 11, 2006, 07:27:44 pm »
Code: [Select]
[BITS 16]
[ORG 0x7c00]

main:
xor ax, ax ;Sets ax = 0
mov cs, ax ;All I know is that ds needs
mov ds, ax ;to be offset to 0x00 but Joe did 
mov es, ax ;them all so i followed his lead,
mov fs, ax ;bad idea i know.

mov si, Helloworld ;Moves the location of Helloworld to SI

Call putSTR

jmp $ ;big ass loop, how do i get to the next stage?

PutSTR:
mov ah, 0x0E ;Set TTY mode, no idea what 0x10 is in Joe's
mov bh, 0x00 ;sets page = 0
mov bl, 0x09 ;blue screen, white text iirc
.next ;label to get to next character
lodsb ;Pretty much mov al, si
int 0x10 ;Runs BIOS video interrupt
or al, al ;Determines if al = 0
jz .end ;GoTo label .end if al = 0
jmp .next ;GoTo .next
.end ;Label to bypass loop if end of STR
ret ;Return to main
;Data

Helloworld db 'Hello World', 13, 10, 0

times 510-($-$$) db 0
dw 0xAA55

May be some suggestions or you could completely rip it apart if im not even close that would also be helpful.

Offline zorm

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
    • Zorm's Page
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #1 on: July 12, 2006, 04:15:14 am »
Depending on what you want to do, you could play around with write string (ah = 0x13 for int 10). I wrote this and I'm not sure if its included anywhere else but I'll paste it here just because.

Code: [Select]
putString:
mov bp, sp
inc [putStringRow]
mov dh, [putStringRow] ;row
mov dl, 0 ;column
mov al, 0 ;mode
mov bl, 0x0f ;display attribute
mov ah, 0x13 ;Write String
mov cx, [bp+4] ;String length
mov bp, [bp+2] ;String
int 0x10
retn

loadingString db 'Zorms OS Loading...', 13, 10
putStringRow db 0

and then its called like:

Code: [Select]
push 21 ;String length
push loadingString
call putString

I was just looking over what I have and I don't remember what I was doing in a lot of places. Also this snippet may prove useful:
Code: [Select]
emptySpace = 510 - ($ - $$)
times emptySpace db 0
dw 0xAA55

You could then output emptySpace to know how much space you have left to use.
"Frustra fit per plura quod potest fieri per pauciora"
- William of Ockham

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #2 on: July 12, 2006, 05:45:53 pm »
Well everyone of his comments pretty much says he copied and pasted out of an AIM convo.  SO anyways is it right?  And what do i do next?  Ive just been kind of reading up on more x86 assembly and NASM.

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #3 on: July 13, 2006, 05:44:39 am »
mov cx, [bp+4] ;String length
mov bp, [bp+2] ;String

If the function is called as putString(word length, LPCSTR string), and you're pushing those elements to the stack, couldn't you use this code?

pop cx
pop bp
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #4 on: July 13, 2006, 12:59:03 pm »
I'd refrain from using the stack at all before PMode. Once you're in PMode you just make a descriptor to protect the stack and give it an address, not too hard. Realmode is something you don't want to linger in. Most of it's usefulness can be done in either vm86 mode or with PMode port reading/writing (Talking about detecting 386, 486 and detecting the presence of 'cpuid'). Realmode is there for legacy compatability, don't use it much.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #5 on: July 15, 2006, 07:50:59 am »
Come to think about it, what is a two-byte pointer to a CString called? PCSTR?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #6 on: July 18, 2006, 01:24:30 pm »
Come to think about it, what is a two-byte pointer to a CString called? PCSTR?

 ???  We wouldn't use a two-byte pointer.....  we use four-byte pointers.  Even in real mode, addressing is done by segment:offset.  Anything you're coding in C/C++ won't use a segment:offset addressing mode, though.  Not nowadays.

If you're talking about a length-prefixed string, since C doesn't do them, I don't know why you'd make a data type alias for them. 
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #7 on: July 23, 2006, 01:45:03 am »
I'm talking about 16 bit processors.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #8 on: July 23, 2006, 02:41:20 am »
In a 16-bit processor, all of the pointers will be 16-bit.  Why would you have a special name for it?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #9 on: August 01, 2006, 10:45:22 pm »
Because LPCSTR is a long pointer, right? Or is sizeof(long) processor dependant?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: Never even looked at x86 let alone OSDev before yesterday.
« Reply #10 on: August 01, 2006, 10:53:15 pm »
Because LPCSTR is a long pointer, right? Or is sizeof(long) processor dependant?

LP does mean "long pointer," but on a 64-bit architecture, LPCSTR refers to a 64-bit pointer.  Pointer sizes are processor-dependent and are always the size of the machine word.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.