Thanks to all who helped me with my last problem. I have another one which I just can't seem to wrap my mind around. Here is my source in NASM syntax:
;XIX System 19 BootSector - Version pre-Alpha
;this will eventually be able to boot the kernel of XIX
;some time in the future, implement the ability to boot
;multiple systems, and allow debugging messages
;assembler directive for 16-bit code
;assembler directive to set origin to 0x7C00
;main function for booting up and setting up the kernel through the bootsector
boot:
mov , dl ;save the boot drive number to bootdrv, (0x00 = floppy)
lea si, ;loadeffectiveaddress of sysmess into StringIndex
call prnt ;call the prnt function
call stkset ;call the stkset function
call prnt ;call the prnt function
call a20en ;call the a20en function
call prnt ;call the prnt function
call gdtset ;call the gdtset function
call prnt ;call the prnt function
hlt ;REMOVE AFTER TEST
;sub-function for printing the loaded string
prnt:
mov ah, 0x0E ;load teletype character (we want to print something)
mov bh, 0x00 ;tell to print on page 1
mov bl, 0x07 ;black background, white text, non-flashing
.nextchar ;label to jump to for repeating until finished
lodsb ;loads SI into AL for printing
or al, al ;set zero flag if AL = nullchar '0' (set at end of message)
jz .end ;if zero flag set, go to end of sub-function
int 0x10 ;run BIOS video interrupt to prin message
jmp .nextchar ;jump and repeat
.end
ret
;sub-function for setting up the stack
stkset:
mov ax, cs ;setup the ds register indirectly
mov ds, ax
mov es, ax
mov fs, ax
mov ax, 0x1D0 ;setup stack at 0x1D00
mov ss, ax ;align stack
mov sp, 0x200 ;set StackPointer to denote 512 byte stack
mov ax, 0xb800 ;setup video segment
mov gs, ax
lea si, ;loadeffectiveaddress of stkmess into StringIndex
ret
;sub-function for setting up a20
a20en:
in al, 0x92
or al, 2
out 0x92, al
lea si, ;loadeffectiveaddress of a20mess into StringIndex
ret
;sub-function for setting up the Global Descriptor Table
gdtset:
xor ax, ax ;moving GDT to 0x500
mov ds, ax
mov es, ax
mov si, gdt ;move from
mov di, ;move to
mov cx, ;size of GDT
cld ;clear the direction flag
rep movsb ;move the GDT
lea si,
ret
;variables for data and strings
bootdrv db 0 ;will be set to the boot drive number (hopefully 0x00)
sysmess db 'XIX System 19 BootSector - Version pre-Alpha',13,10,10,0 ;string to print
;13 - character return
;10 - new line
;0 - null character
stkmess db 'Memory Stack Successfully Setup',13,10,10,0 ;tell that Memory Stack has been setup
a20mess db 'A20 Successfully Enabled',13,10,10,0 ;tell that A20 has been enabled
gdtmess db 'GDT Successfully Setup',13,10,10,0 ;tell that GDT has been setup
gdtr: ;really basic GDT table
gdtsize dw gdtend-gdt-1 ;size of GDT
gdtbase dd 0x500 ;where the GDT starts, at 0x500 in memory
gdt:
nullsel equ $-gdt ;null descriptor is a must (64-bit per entry)
dd 0x00
dd 0x00
codesel equ $-gdt ;code selector is 4GB with max 0xFFFFF limit
dw 0xFFFF ;limit(2) of selector - 0xFFFFF
dw 0x0 ;base(3) of selector - 0x0
db 0x0 ;base(2) of selector - 0x0
db 0x9A ;type of selector - present,ring0,code,exec/read/accessed (10011000)
db 0xCF ;limit(1) of selector - 0xF 4KB 32bit (11001111)
db 0x0 ;base(1) of selector - 0x0
datasel equ $-gdt ;code selector is 4GB with max 0xFFFFF limit
dw 0xFFFF ;limit(2) of selector - 0xFFFFF
dw 0x0 ;base(3) of selector - 0x0
db 0x0 ;base(2) of selector -0x0
db 0x92 ;type of selector - present,ring0,data/stack,read/write (10010010)
db 0xCF ;limit(1) of selector - 0xF 4KB 32bit (11001111)
db 0x0 ;base (1) of selector - 0x0
gdtend: ;just an empty function for end of GDT
;appendages for bootloader
times 510-($-$$) db 0 ;fill unused space upto 510 bytes with 0
signature dw 0xAA55 ;set bootloader signature
Pretty much, I have isolated it to the line in the stkset function:
mov ax, 0x1D0 ;setup stack at 0x1D00
the thing is, it works when i put it in the main section of the program, but not where it currently is now.
I WOULD take and put it where I know it works, but I need an answer WHY this doesn't work.
Any help would be greatly appreciated.
;XIX System 19 BootSector - Version pre-Alpha
;this will eventually be able to boot the kernel of XIX
;some time in the future, implement the ability to boot
;multiple systems, and allow debugging messages
;assembler directive for 16-bit code
;assembler directive to set origin to 0x7C00
;main function for booting up and setting up the kernel through the bootsector
boot:
mov , dl ;save the boot drive number to bootdrv, (0x00 = floppy)
lea si, ;loadeffectiveaddress of sysmess into StringIndex
call prnt ;call the prnt function
call stkset ;call the stkset function
call prnt ;call the prnt function
call a20en ;call the a20en function
call prnt ;call the prnt function
call gdtset ;call the gdtset function
call prnt ;call the prnt function
hlt ;REMOVE AFTER TEST
;sub-function for printing the loaded string
prnt:
mov ah, 0x0E ;load teletype character (we want to print something)
mov bh, 0x00 ;tell to print on page 1
mov bl, 0x07 ;black background, white text, non-flashing
.nextchar ;label to jump to for repeating until finished
lodsb ;loads SI into AL for printing
or al, al ;set zero flag if AL = nullchar '0' (set at end of message)
jz .end ;if zero flag set, go to end of sub-function
int 0x10 ;run BIOS video interrupt to prin message
jmp .nextchar ;jump and repeat
.end
ret
;sub-function for setting up the stack
stkset:
mov ax, cs ;setup the ds register indirectly
mov ds, ax
mov es, ax
mov fs, ax
mov ax, 0x1D0 ;setup stack at 0x1D00
mov ss, ax ;align stack
mov sp, 0x200 ;set StackPointer to denote 512 byte stack
mov ax, 0xb800 ;setup video segment
mov gs, ax
lea si, ;loadeffectiveaddress of stkmess into StringIndex
ret
;sub-function for setting up a20
a20en:
in al, 0x92
or al, 2
out 0x92, al
lea si, ;loadeffectiveaddress of a20mess into StringIndex
ret
;sub-function for setting up the Global Descriptor Table
gdtset:
xor ax, ax ;moving GDT to 0x500
mov ds, ax
mov es, ax
mov si, gdt ;move from
mov di, ;move to
mov cx, ;size of GDT
cld ;clear the direction flag
rep movsb ;move the GDT
lea si,
ret
;variables for data and strings
bootdrv db 0 ;will be set to the boot drive number (hopefully 0x00)
sysmess db 'XIX System 19 BootSector - Version pre-Alpha',13,10,10,0 ;string to print
;13 - character return
;10 - new line
;0 - null character
stkmess db 'Memory Stack Successfully Setup',13,10,10,0 ;tell that Memory Stack has been setup
a20mess db 'A20 Successfully Enabled',13,10,10,0 ;tell that A20 has been enabled
gdtmess db 'GDT Successfully Setup',13,10,10,0 ;tell that GDT has been setup
gdtr: ;really basic GDT table
gdtsize dw gdtend-gdt-1 ;size of GDT
gdtbase dd 0x500 ;where the GDT starts, at 0x500 in memory
gdt:
nullsel equ $-gdt ;null descriptor is a must (64-bit per entry)
dd 0x00
dd 0x00
codesel equ $-gdt ;code selector is 4GB with max 0xFFFFF limit
dw 0xFFFF ;limit(2) of selector - 0xFFFFF
dw 0x0 ;base(3) of selector - 0x0
db 0x0 ;base(2) of selector - 0x0
db 0x9A ;type of selector - present,ring0,code,exec/read/accessed (10011000)
db 0xCF ;limit(1) of selector - 0xF 4KB 32bit (11001111)
db 0x0 ;base(1) of selector - 0x0
datasel equ $-gdt ;code selector is 4GB with max 0xFFFFF limit
dw 0xFFFF ;limit(2) of selector - 0xFFFFF
dw 0x0 ;base(3) of selector - 0x0
db 0x0 ;base(2) of selector -0x0
db 0x92 ;type of selector - present,ring0,data/stack,read/write (10010010)
db 0xCF ;limit(1) of selector - 0xF 4KB 32bit (11001111)
db 0x0 ;base (1) of selector - 0x0
gdtend: ;just an empty function for end of GDT
;appendages for bootloader
times 510-($-$$) db 0 ;fill unused space upto 510 bytes with 0
signature dw 0xAA55 ;set bootloader signature
Pretty much, I have isolated it to the line in the stkset function:
mov ax, 0x1D0 ;setup stack at 0x1D00
the thing is, it works when i put it in the main section of the program, but not where it currently is now.
I WOULD take and put it where I know it works, but I need an answer WHY this doesn't work.
Any help would be greatly appreciated.
CALL pushes the return address onto the stack. RET pops the return address from the stack.