[LinksOS CVS Commit]linksos/main boot.S,NONE,1.1 io.c,NONE,1.1 Makefile,1.4,1.5 kernel.ls,1.2,1.3 ks
Status: Inactive
Brought to you by:
terencevs
|
From: <bg...@us...> - 2003-01-01 06:49:13
|
Update of /cvsroot/linksos/linksos/main
In directory sc8-pr-cvs1:/tmp/cvs-serv13409/main
Modified Files:
Makefile kernel.ls kstdio.c main.c strap.asm
Added Files:
boot.S io.c
Log Message:
Boot using GRUB
Added boot.S to replace strap.asm & changed kprintf() to handle cursor position and newlines. Now kernel works with GRUB ok.
Use Grub as boot loader
a = n/a yet
--- NEW FILE: boot.S ---
/* boot.S - bootstrap the kernel */
/* Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#define ASM 1
#include "include/multiboot.h"
.text
.globl start, _start
start:
_start:
jmp multiboot_entry
/* Align 32 bits boundary. */
.align 4
/* Multiboot header. */
multiboot_header:
/* magic */
.long MULTIBOOT_HEADER_MAGIC
/* flags */
.long MULTIBOOT_HEADER_FLAGS
/* checksum */
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#ifndef __ELF__
/* header_addr */
.long multiboot_header
/* load_addr */
.long _start
/* load_end_addr */
.long _edata
/* bss_end_addr */
.long _end
/* entry_addr */
.long multiboot_entry
#endif /* ! __ELF__ */
multiboot_entry:
/* Initialize the stack pointer. */
movl $(stack + STACK_SIZE), %esp
/* Reset EFLAGS. */
pushl $0
popf
/* Push the pointer to the Multiboot information structure. */
pushl %ebx
/* Push the magic value. */
pushl %eax
/* Now enter the C main function... */
call EXT_C(cmain)
/* Halt. */
pushl $halt_message
call EXT_C(kprintf)
loop: hlt
jmp loop
halt_message:
.asciz "Halted."
/* Our stack area. */
.comm stack, STACK_SIZE
--- NEW FILE: io.c ---
#include "include/io.h"
inline unsigned char inportb(unsigned int port) /* Input a byte from a port */
{
unsigned char ret;
asm volatile ("inb %%dx,%%al":"=a" (ret):"d" (port));
return ret;
}
inline void outportb(unsigned int port,unsigned char value) /* Output a byte to a port */
{
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
}
Index: Makefile
===================================================================
RCS file: /cvsroot/linksos/linksos/main/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Makefile 28 Dec 2002 21:23:25 -0000 1.4
--- Makefile 1 Jan 2003 06:49:06 -0000 1.5
***************
*** 8,12 ****
#The assembler
! ASM = nasm
# The linker
--- 8,12 ----
#The assembler
! AS = as
# The linker
***************
*** 14,25 ****
# The kernel filename
! KERNELFN = kernel.bin
# The object files
! OBJS = kstdio.o main.o strap.o
#Compiler parameters
! CFLAGS = -I$(INCLUDE) -Wall -O -fomit-frame-pointer -c -o
! ASMFLAGS = -f elf
--- 14,24 ----
# The kernel filename
! KERNELFN = kernel.elf
# The object files
! OBJS = kstdio.o main.o boot.o io.o
#Compiler parameters
! CFLAGS = -Wall -O -fomit-frame-pointer -c -o
***************
*** 29,39 ****
$(KERNELFN): $(OBJS)
! $(LD) -Bstatic -o $(KERNELFN) $(OBJS) -Map kernel.map -T kernel.ls
.c.o:
$(CC) $(CFLAGS) $@ $<
! .asm.o:
! $(ASM) $(ASMFLAGS) $<
clean:
--- 28,38 ----
$(KERNELFN): $(OBJS)
! $(LD) -Bstatic -o $(KERNELFN) $(OBJS) -Map kernel.map -Ttext 0x100000
.c.o:
$(CC) $(CFLAGS) $@ $<
! .S.o:
! $(CC) $(CFLAGS) $@ $<
clean:
Index: kernel.ls
===================================================================
RCS file: /cvsroot/linksos/linksos/main/kernel.ls,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** kernel.ls 28 Dec 2002 16:53:16 -0000 1.2
--- kernel.ls 1 Jan 2003 06:49:07 -0000 1.3
***************
*** 1,6 ****
! OUTPUT_FORMAT("binary")
ENTRY(_start)
SECTIONS
! { .text 0x00010000 :
{ *(.text)
. = ALIGN(4096);
--- 1,6 ----
! OUTPUT_FORMAT("elf32")
ENTRY(_start)
SECTIONS
! { .text 0x000100000:
{ *(.text)
. = ALIGN(4096);
Index: kstdio.c
===================================================================
RCS file: /cvsroot/linksos/linksos/main/kstdio.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** kstdio.c 22 Dec 2002 18:42:12 -0000 1.1
--- kstdio.c 1 Jan 2003 06:49:07 -0000 1.2
***************
*** 11,14 ****
--- 11,15 ----
#include "include/kstdio.h"
+ #include "include/io.h"
typedef unsigned char u_char; /* this needs to be moved to a "types"
***************
*** 24,45 ****
{
/* write 'text' to screen. */
! static char* screen = (char*)0xB8000;
! int j;
! static int i = 0;
! static u_char prev;
! for(j=0;text[j]!=0;++i,j++) { /* don't be scared. it's kosher. :) */
! if (((text[j]==0xa) || (text[j]==0xd)) && ((prev==0xa) || (prev==0xd))) {
! continue;
! prev = text[j];
! }
! else if ((text[j]==0xa) || (text[j]==0xd)) {
! i = i + (0xa0);
! prev = text[j];
! continue;
! }
! prev = text[j];
! screen[i*2] = text[j];
! screen[i*2+1] = 7;
! }
}
--- 25,57 ----
{
/* write 'text' to screen. */
! static char* screen = (char*)0xB8000;
! static int curchar,off;
! /*First get the cursor's current position on screen*/
! outportb(0x3d4, 0x0e); /* Get cursor Y position */
! off = inportb(0x3d5);
! off <<= 8;
! outportb(0x3d4, 0x0f); /* And add cursor X position */
! off += inportb(0x3d5);
! off <<= 1;
!
! while((curchar = *text++)){ /*Process text char by char*/
! switch(curchar){
!
! case '\n': /*It is a carriage return*/
! off = 160 + (off/160)*160;
! break;
!
! default: /*Just spit character onto screen*/
! screen[off++] = curchar;
! screen[off++] = 0x07;
! }
! }
!
! /*Move cursor to new screen position*/
! off >>= 1;
! outportb(0x3d4,0x0f);
! outportb(0x3d5,off & 0x0ff);
! outportb(0x3d4,0x0e);
! outportb(0x3d5,off >> 8);
}
Index: main.c
===================================================================
RCS file: /cvsroot/linksos/linksos/main/main.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** main.c 28 Dec 2002 16:53:16 -0000 1.2
--- main.c 1 Jan 2003 06:49:07 -0000 1.3
***************
*** 13,20 ****
#include "include/kstdio.h"
! void main(void)
{
! while(1);
! kprintf("LinksOS v0.0.1a kernel booted.");
}
--- 13,25 ----
#include "include/kstdio.h"
+ #include "include/multiboot.h"
! void cmain(unsigned long magic, multiboot_info_t addr)
{
! if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
! {
! kprintf("Invalid bootloader magic number\n");
! return;
! }
! kprintf("LinksOS v0.0.1a kernel booted.\n");
}
Index: strap.asm
===================================================================
RCS file: /cvsroot/linksos/linksos/main/strap.asm,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** strap.asm 29 Dec 2002 07:54:00 -0000 1.4
--- strap.asm 1 Jan 2003 06:49:07 -0000 1.5
***************
*** 1,26 ****
;-----------------------------------------------------------------------------
! ; filename: strap.asm
! ; creation date: unknown
! ; author: Charles Banas
! ; Edited by Kye Lewis (kye...@us...)
! ; version: 0.02
;-----------------------------------------------------------------------------
! ; revision history:
! ; 12/22/2002 - 1136 MST - Charles Banas
! ; prepared for CVS commit. added comments.
!
! ; 20021229 - 0738GMT - Kye Lewis (kye...@us...)
!
! ; Changed so the file links and compiles on NASM correctly
! ; Changed BITS 16 to BITS 32, and fixed 3 other lines.
!
;-----------------------------------------------------------------------------
! ; description:
! ; this file provides the ability for the kernel to boot with a
! ; minimal bootloader that does not provide A20 or p-mode support.
!
;-----------------------------------------------------------------------------
- ;[BITS 16]
[BITS 32]
[SECTION .text]
--- 1,19 ----
;-----------------------------------------------------------------------------
! ;- filename: strap.asm --
! ;- creation date: unknown --
! ;- author: Charles Banas --
! ;- version: 0.01 --
;-----------------------------------------------------------------------------
! ;- revision history: --
! ;- 12/22/2002 - 1136 MST - Charles Banas --
! ;- prepared for CVS commit. added comments. --
;-----------------------------------------------------------------------------
! ;- description: --
! ;- this file provides the ability for the kernel to boot with a --
! ;- minimal bootloader that does not provide A20 or p-mode support. --
! ;- if the kernel is used in conjunction with GRUB or similar --
! ;- bootloaders, multiboot.s is linked rather than this file. --
;-----------------------------------------------------------------------------
[BITS 32]
[SECTION .text]
***************
*** 30,33 ****
--- 23,27 ----
; the BeFS bootloader loads the kernel image at 1000h:0000h and jumps to
; 1000h:0200h. the DOS-compatible bootloader i use jumps to 1000h:0000h.
+ jmp $
jmp _start
times (0x1fd) nop
***************
*** 53,57 ****
call _disp_str
! call _set_a20
; call _check_a20
jnc a20_good ; alternately, using the _check_a20 code, jz must be used.
--- 47,51 ----
call _disp_str
! call _set_a20
; call _check_a20
jnc a20_good ; alternately, using the _check_a20 code, jz must be used.
***************
*** 288,292 ****
; Protected-mode segment
;---------------
!
do_pm:
mov ax,SYS_DATA_SEL ; now in 32-bit pmode
--- 282,286 ----
; Protected-mode segment
;---------------
! [BITS 32]
do_pm:
mov ax,SYS_DATA_SEL ; now in 32-bit pmode
|