Hello,
I'm developing an simple OS, as you can see in my previous posts, but now i have a file that is too big for the boot sector(510 bytes), then i want to split it in two files, one that will be in the boot sector of the floppy and the other that will be in the normal sectors of the floppy, then at the boot time i need that the file that is in the boot sector(a simple boot loader), boots the other that is in the normal sectors of the floppy, but i don't know how to do this, someone can help me!. If needed, here is my code:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

; ------------------------------------------
; Beginning messages
main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV BH, 0
MOV BL, 02h
MOV CX, osmsgend - os_msg           ; Calculate message size. 
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 059 
MOV CX, welcome_end - welcome       ; Calculate message size. 
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP comm_tag
; Beginning messages end
; ------------------------------------------

; Commands Area

; ------------------------------------------
; Show version command end
ver_show:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 059 
MOV CX, ver_end - ver_msg       ; Calculate message size. 
MOV DL, 0
MOV DH, 3
PUSH CS
POP ES
MOV BP, ver_msg
MOV AH, 13h
INT 10h
JMP osmsgend
; Show version command end
; ------------------------------------------

comm_tag:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0 
MOV CX, con_end - con       ; Calculate message size. 
MOV DL, 0
MOV DH, 3
PUSH CS
POP ES
MOV BP, ver_msg
MOV AH, 13h
INT 10h
JMP ver_KeyIn

; ------------------------------------------
; Keyboard input method
xVer  db   'ver', 0
Key:  	times	  128 db 0		      ; reserve 128 byte Keyboard
KScan:	times   128 db 0		      ; reserve 128 byte scan

ver_KeyIn:
  xor bx,bx

ver_KeyIn0:
  mov ah,0
   int 16h				               ; KEYBOARD
   ;ah=scan code   al=ASCII character

   mov [Key+bx],al
   mov [KScan+bx],ah
   inc bx
   cmp al,0dh                       ; Carriage return
   jne  ver_KeyIn0

   ; bx = buffer Length
   mov word [Key + bx - 1],0        ; Overwrite with terminator

   ; String now in buffer
   mov ax,Key
   mov dx,xVer

   call StrICmp

   JMP ver_show

; End of input characters method
; ------------------------------------------
   StrICmp:
   stc
   ret

con DB "> "
con_end:

ver_msg DB "BerlOS Version 0.0.1 beta"
ver_end:

welcome DB "Welcome !"
welcome_end:

os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $

; Boot things
TIMES 510-($-$$) DB 0	            ; Fill the rest of the sector with zeros
DW 0xAA55		                    ; Boot signature

Thanks,
Nathan Paulino Campos

Recommended Answers

All 7 Replies

How many bytes over are you? There are ways to optimize code! 80x86 uses variable length functions and register AL has the fewest bytes!

Compile with a list file output and examine the binary for each line!

I've grabbed one block of your code

;   MOV BX, 0     ; Disable blinking.
;   MOV BH, 00h
;   MOV BL, 07h      ; Color settings
;   MOV AL, 1

;   MOV BH, 0
;   MOV BL, 02h
   mov bx,0002h
   MOV CX, osmsgend - os_msg           ; Calculate message size.

;   MOV DL, 30
;   MOV DH, 0
   mov dx,001eh
   PUSH CS
   POP ES
   MOV BP, os_msg

;   MOV AH, 13h
;   MOV AL, 1
   mov ax,1301h
   INT 10h
   JMP wel

Ok, i'm going to check this, but how i can compile only the boot file(part of my other) that can boot the OS, like in my question?

Thanks!

If you are trying to create two binaries then create two programs. Set one at $100 and the other at $0 origin's. You load the first one normally, and it allocates the space and loads the second one into it.
When you load them one by one set vector locations at the second block's origin. The first program jumps into a jump table or uses a vector table at the origin of the second.
$ORG 100
My loader
JMP $300

Second file which is loaded at $300

$ORG 300                   <---    or $ORG 0
          ; You want no space at the beginning of the file but you want all the jump/call addresses to be correct within the file.

    jmp MyFunc0
    jmp MyFunc1
    jmp MyFunc2
          etc.

MyFunc0:
    ret

MyFunc1:
   ret

So its Jump to front of second file, then immediately jump again to the function. (I think its only 3 bytes for a JMP nEAR)
MyFunc0 = $300
MyFunc1 = $303
MyFunc2 = $306

call MyFunc0
which calls into top of second file
which jumps to its MyFunc0

An alternate is to have a vector table

org $300
     dw   MyFunc0
     dw   MyFunc1
     dw   MyFunc2

MyFunc0:
     ret

Using a vector table

MyFunc0 equ $300
MyFunc1 equ $302
MyFunc2 equ $304
call [MyFunc0]

You can also look for the exe2bin converter to convert your exe to com.

huh, i'm going to test!
But remember that i need to boot the first compiled file, that is in the floppy boot sector, then it boots the second compile file, that is the OS.

Thanks!

Are you trying to spawn a second file, or only bring up the rest of the program in a separate block? If two totally separate programs, then load the second into memory at the adjusted org and then jump at its $100 offset from its load address!

You're in DOS mode? Therefore its a single application!

I'm only trying to bring up the rest of the OS, because it's now so much big, then i can't compile to the boot sector(510 bytes).

wildgoose, it's my OS, that i'm trying to develop!

When I created a multi-stage bootloader I assembled
my first bootloader code so that it would be made into
a 1.44MB floppy disk image.
Then assembled the second stage as a bare binary
image.
Then I used a hex editor to place the second part
at the next consecutive sector.
The first sector loaded by the BIOS bootstrap
used BIOS service routines to read the sectors
of the floppy drive, and loaded the second
part at a convenient address because at this
point you have the RAM to yourself.
You can use BIOS service routines to read sectors of the floppy
drive, the BIOS bootstrap will load the first sector into the
RAM for you and execute it (as you know), and you can use BIOS
service routines to load other sectors into the RAM from
the same drive.
Get a hold of Ralf Brown's interrupt list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.