[Solved] Cannot use multiple function calls in my C kernel.
Posted: Wed Jul 01, 2020 6:49 pm
What am I doing wrong? Everything else works print a character at a time, clearing the screen and initializing the terminal.
But every time I execute:
NOTE: Currently I removed the print function from the kernel main, so it doesn't call that function right now.
But if you add it back in then it does the following.
It doesn't work, it's like it skips that function for some reason.
Below should be all code that is related to the issue.
stage2.asm:
entry.asm:
io.c:
kernel.c:
link.ld:
NOTE: I might not have everything needed here, so I'm posting the github project for you to look at.
The code for this project: github.com - boot32-barebones
Thanks in advance for any and all information to correct this issue with my print and print_at functions. Why they (print string functions) don't work was the question? I've been mucking around with this every since Michael Petch and others helped with my last issue. Basically what I'm going for with this project is a starting point for beginners, one that has every tricky 16 bit and 32 bit mode stuff already done. That way all a beginner has to do is clone this project and start making the kernel. If they're going for a 32-bit operating system.
- Phil
But every time I execute:
Code: Select all
print("Some text");
But if you add it back in then it does the following.
It doesn't work, it's like it skips that function for some reason.
Below should be all code that is related to the issue.
stage2.asm:
Code: Select all
; stage 2 boot loader.
; by Philip Simonson.
; =======================
[org 0x7e00]
[bits 16]
start:
mov [iBootDrive], dl
; set text mode (80x25)
mov ax, 0x0003
int 0x10
call a20_bios
call check_a20
mov si, op_loading
call print
call reset_disk
mov ax, 2 ; this is the starting sector LBA addressing
mov cx, 9 ; set this to count of sectors to read
mov bx, load_segment
mov es, bx
mov bx, load_offset
call read_disk
; switch on protected mode
cli
lgdt [gdt.pointer]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword 0x08:INIT_PM
%include "common.inc"
%include "disk.inc"
%include "a20.inc"
%include "gdt.inc"
[bits 32]
INIT_PM:
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ebp, 0x90000
mov esp, ebp
call run_offset
hlt
%include "common32.inc"
op_loading db "Loading kernel, please wait",0
op_done db "done!",10,13,0
op_a20yes db "A20 is enabled.",10,13,0
op_a20no db "A20 is disabled.",10,13,0
op_progress db 0x2e,0
op_failed db 10,13,"File not found!",10,13,0
load_segment equ 0x1000
load_offset equ 0x0000
run_offset equ 0x00010000
%include "bs.inc"
Code: Select all
; entry point for kernel
[bits 32]
section .text
extern kernel_main
global _start
_start:
call kernel_main
hlt
Code: Select all
/*
* Author: Philip R. Simonson
* Date : 07/01/2020
*
****************************************************************
*/
#include "vga.h"
/* Print a string on screen at given (x,y) position.
*/
void print_at(int col, int row, char *s)
{
int offset, i;
if(col >= MAX_COLS || row >= MAX_ROWS) {
offset = print_char(0, 0, 'E');
set_cursor_offset(offset);
}
i = 0;
while(s[i] != 0) {
offset = print_char(col, row, s[i]);
/* Compute row/col for next iteration */
col = get_offset_row(offset);
row = get_offset_col(offset);
}
}
/* Print a string on screen at current location.
*/
void print(char *s)
{
print_at(-1, -1, s);
}
Code: Select all
#include "vga.h"
#include "io.h"
void kernel_main(void)
{
term_init(BLUE, YELLOW);
print_char(-1, -1, 'H');
print_char(-1, -1, 'e');
print_char(-1, -1, 'l');
print_char(-1, -1, 'l');
print_char(-1, -1, 'o');
print_char(-1, -1, ' ');
print_char(-1, -1, 'W');
print_char(-1, -1, 'o');
print_char(-1, -1, 'r');
print_char(-1, -1, 'l');
print_char(-1, -1, 'd');
print_char(-1, -1, '!');
print_char(-1, -1, '\n');
}
Code: Select all
ENTRY(kernel_main);
OUTPUT_FORMAT(elf32-i386);
OUTPUT_ARCH(i386:i386);
BASE_ADDR = 0x00010000;
SECTIONS
{
.text BASE_ADDR : AT(BASE_ADDR)
{
code = .;
*(.text)
. = ALIGN(4K);
}
.rodata : AT(BASE_ADDR + (rodata - code))
{
rodata = .;
*(.rodata)
. = ALIGN(4K);
}
.data : AT(BASE_ADDR + (data - code))
{
data = .;
*(.data)
. = ALIGN(4K);
}
.bss : AT(BASE_ADDR + (bss - code))
{
bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4K);
}
/DISCARD/ :
{
*(.comment);
*(.igot.*);
*(.eh_frame);
}
}
The code for this project: github.com - boot32-barebones
Thanks in advance for any and all information to correct this issue with my print and print_at functions. Why they (print string functions) don't work was the question? I've been mucking around with this every since Michael Petch and others helped with my last issue. Basically what I'm going for with this project is a starting point for beginners, one that has every tricky 16 bit and 32 bit mode stuff already done. That way all a beginner has to do is clone this project and start making the kernel. If they're going for a 32-bit operating system.
- Phil