Fix building C code for 32 bit mode; BIOS string printing

This commit is contained in:
Thomas Oltmann 2026-02-18 00:57:22 +01:00
parent 441d5ef570
commit 68d47cd451
3 changed files with 37 additions and 24 deletions

View file

@ -1,4 +1,8 @@
#include <stdint.h>
//#include <stdint.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#define COM1_BASE_PORT 0x3F8
@ -35,15 +39,14 @@ void serial_write(const char *msg)
}
}
extern void writechar();
extern void bios_write(const char *msg, unsigned length);
void
main()
{
serial_write("init\r\n");
writechar();
serial_write("foo\r\n");
bios_write("init\r\n", 6);
bios_write("karlos\r\n", 8);
for (;;) {
//__asm__ ("hlt" :);
__asm__ ("hlt" :);
}
}

38
Rnbp.S
View file

@ -71,15 +71,6 @@ _start: cli
mov %ss, %ax
mov %ax, real_ss
push $msg_start
call dbgmsg
add $2, %sp
xor %bx, %bx
mov $0x0E, %ah
mov $'B', %al
int $0x10
// initialize our own BSS section
mov $_bss_start, %di
mov $_bss_end, %cx
@ -133,22 +124,38 @@ dbgmsg: push %bp
pop %bp
ret
.global writechar
.global bios_write
.code32
writechar: push %ebp
bios_write: push %ebp
mov %esp, %ebp
push %ebx
mov 8+0(%ebp), %edx
mov 8+4(%ebp), %ecx
PROT16
.code16
REAL
.bwloop: test %ecx, %ecx
jz .bwreturn
xor %bx, %bx
mov $0x0E, %ah
mov $'A', %al
int $0x10
mov (%edx), %al
PROT
push %ecx
push %edx
int $0x10
pop %edx
pop %ecx
add $1, %edx
sub $1, %ecx
jmp .bwloop
.bwreturn: PROT
PROT32
.code32
@ -176,7 +183,8 @@ GDT: // entry 0: null descriptor
// TODO: 32-bit TSS
.set GDT_SIZE, . - GDT
GDT_PTR: .word GDT_SIZE - 1
.quad GDT
.word GDT
.word 0, 0, 0
msg_start: .asciz "Netboot via fernlader v2 ...\r\n"
msg_a20: .asciz " * Enabling A20 Gate\r\n"

View file

@ -1,5 +1,7 @@
CC = cc
#CC = /usr/local/x86_64-karlos-toolchain/bin/x86_64-karlos-gcc
#LD = /usr/local/x86_64-karlos-toolchain/bin/x86_64-karlos-ld
CC = gcc
LD = ld
CFLAGS = -no-pie -fno-pic -fno-stack-protector
LDFLAGS = -Tfernlader.ld
CFLAGS = -no-pie -fno-pic -fno-stack-protector -nostdinc -m32
LDFLAGS = -Tfernlader.ld -m elf_i386