We load 0 to SS segment register when :
Code: Select all
xor ax, ax
mov ss, ax
Code: Select all
xor sp, sp
Very sorry for my bad English.
Cheers,
CopperMan
Code: Select all
xor ax, ax
mov ss, ax
Code: Select all
xor sp, sp
If you code works fine in bochs and doesn't work on selected PCs then these are possible:phoenix07p wrote: MOV AH,02
MOV AL,18d
MOV CH,0
MOV CL,5d
MOV DH,0
MOV DL,81h
MOV BX,0
MOV ES,BX
MOV BX,0X800
INT 13H
Yes you are. You're just not aware of it.phoenix07p wrote:meanwhile just a question why would I want to initialize segment register if i am not even using them
Code: Select all
**********
kernel.c
**********
#define WHITE_TXT 0x07
extern void k_main();
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
void update_cursor(int row, int col);
void k_main() // like main in a normal C program
{
k_clear_screen();
k_printf("Hi!\nHow's this for a starter OS?", 0);
};
void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vidmem[i]=' ';
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0)
{
if(*message=='\n') // check for a new line
{
line++;
i=(line*80*2);
message++;
} else {
vidmem[i]=*message;
message++;
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
return(1);
};
**********
kernel_start.asm
**********
global loader ; making entry point visible to linker
extern k_main ; kmain is defined elsewhere
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
section .text
align 4
MultiBootHeader:
dd MAGIC
dd FLAGS
dd CHECKSUM
; reserve initial kernel stack space
STACKSIZE equ 0x4000 ; that's 16k.
loader:
mov esp, stack+STACKSIZE ; set up the stack
push eax ; pass Multiboot magic number
push ebx ; pass Multiboot info structure
call kmain ; call kernel proper
cli
hang:
hlt ; halt machine should kernel return
jmp hang
section .bss
align 32
stack:
resb STACKSIZE ; reserve 16k stack on a quadword boundary
***********
linker.ld
**********
ENTRY (loader)
SECTIONS{
. = 0x00100000;
.text :{
*(.text)
}
.rodata ALIGN (0x1000) : {
*(.rodata)
}
.data ALIGN (0x1000) : {
*(.data)
}
.bss : {
sbss = .;
*(COMMON)
*(.bss)
ebss = .;
}
}
neon wrote: Please use code tags when posting code - it makes it easier to read. Also, it might help if you post your bochs crash log (Only the last 10-20 lines please - not the whole log.)
Code: Select all
cli
lgdt [gdtr]
mov eax, cr0
or al,0x1
mov cr0,eax
jmp 0x0000:0x8000 ; this is where es:bx was pointing while reading sectors from floppy
Code: Select all
:
gdt: dw 0x0000, 0x0000, 0x0000, 0x0000
sys_data: dw 0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code: dw 0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:
gdtr: dw gdt_end - gdt - 1
dd gdt