From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Subject: [PATCH] Separation C and assembly functions to different files
Date: Fri, 12 Jun 2015 23:52:17 -0500 [thread overview]
Message-ID: <CAD6VGubpzYTk1+cnM0_4qjQx17gTUDv2mfjbjY=Uec7io1mjig@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 440 bytes --]
Hi,
-Files arch/i86/kernel/bios16.c and arch/i86/kernel/printreg.c
are now only assembly.
-File arch/i86/lib/memmove.c is now only C.
-Files arch/i86/drivers/char/bell.c and arch/i86/kernel/system.c
now have conditional compilation to select the appropiate inline
assembly style.
-Small fixes in other files.
The kernel was compiled with BCC and tested with QEMU.
Code size reduced in 112 bytes and data size reduced in 4 bytes.
Juan
[-- Attachment #2: elks-3z.patch --]
[-- Type: text/x-patch, Size: 11929 bytes --]
diff -Nur elks.orig/arch/i86/drivers/block/doshd.c elks/arch/i86/drivers/block/doshd.c
--- elks.orig/arch/i86/drivers/block/doshd.c 2015-06-11 13:27:21.000000000 -0500
+++ elks/arch/i86/drivers/block/doshd.c 2015-06-11 13:35:38.000000000 -0500
@@ -70,6 +70,21 @@
static int revalidate_hddisk(int, int);
#endif
+static struct biosparms bdt;
+
+/* Useful defines for accessing the above structure. */
+
+#define CARRY_SET (bdt.fl & 0x1)
+#define BD_IRQ bdt.irq
+#define BD_AX bdt.ax
+#define BD_BX bdt.bx
+#define BD_CX bdt.cx
+#define BD_DX bdt.dx
+#define BD_SI bdt.si
+#define BD_DI bdt.di
+#define BD_ES bdt.es
+#define BD_FL bdt.fl
+
static struct drive_infot {
int cylinders;
int sectors;
@@ -146,7 +161,7 @@
BD_AX = BIOSHD_DRIVE_PARMS;
BD_DX = drive + 0x80;
BD_IRQ = BIOSHD_INT;
- call_bios();
+ call_bios(&bdt);
if (!CARRY_SET) {
drivep->cylinders = ((BD_CX >> 8) | ((BD_CX & 0xC0) << 2)) + 1;
drivep->heads = (BD_DX >> 8) + 1;
@@ -216,7 +231,7 @@
BD_AX = BIOSHD_DRIVE_PARMS;
BD_DX = 0; /* only the number of floppies */
BD_IRQ = BIOSHD_INT;
- call_bios();
+ call_bios(&bdt);
ndrives = (CARRY_SET) ? 0 : BD_DX & 0xff;
#else
@@ -233,7 +248,7 @@
#ifdef CONFIG_HW_USE_INT13_FOR_FLOPPY
- call_bios();
+ call_bios(&bdt);
if ((!CARRY_SET) && ((BD_AX & 0xff00) == 0))
drive_info[drive + 2] = fd_types[BD_BX - 1];
else
@@ -241,7 +256,7 @@
#else
- if ((arch_cpu > 1) && (call_bios(), (!CARRY_SET)) && (BD_AX != 0x100)) {
+ if ((arch_cpu > 1) && (call_bios(&bdt), (!CARRY_SET)) && (BD_AX != 0x100)) {
/* Some XT's return strange results - Al
* The arch_cpu is a safety check
@@ -292,7 +307,7 @@
BD_IRQ = BIOSHD_INT;
BD_AX = BIOSHD_RESET;
BD_DX = hd_drive_map[DEVICE_NR(minor)];
- call_bios();
+ call_bios(&bdt);
/* Dont log this fail - its fine
*/
@@ -326,7 +341,7 @@
BD_FL = 0;
set_irq();
- call_bios();
+ call_bios(&bdt);
if (CARRY_SET) {
if (((BD_AX >> 8) == 0x04) && (count == MAX_ERRS - 1))
break; /* Sector not found */
@@ -438,7 +453,7 @@
BD_IRQ = BIOSHD_INT;
BD_AX = BIOSHD_DRIVE_PARMS;
BD_DX = hd_drive_map[target]; /* Head 0, drive number */
- call_bios();
+ call_bios(&bdt);
if (!CARRY_SET) {
drivep->sectors = (BD_CX & 0x3f);
drivep->cylinders = ((BD_CX >> 8) | ((BD_CX & 0xC0) << 2)) + 1;
@@ -728,7 +743,7 @@
cylinder, head, sector, drive, req->rq_cmd);
debug1("blocks %d\n", this_pass);
set_irq();
- call_bios();
+ call_bios(&bdt);
if (CARRY_SET) {
reset_bioshd(MINOR(req->rq_dev));
dma_avail = 1;
diff -Nur elks.orig/arch/i86/drivers/char/bell.c elks/arch/i86/drivers/char/bell.c
--- elks.orig/arch/i86/drivers/char/bell.c 2015-06-11 13:27:37.000000000 -0500
+++ elks/arch/i86/drivers/char/bell.c 2015-06-11 13:35:38.000000000 -0500
@@ -10,8 +10,8 @@
#define BELL_FREQUENCY 800
#define BELL_PERIOD (1193181/BELL_FREQUENCY)
-#define BELL_PERIOD_L (BELL_PERIOD & 0xFF)
-#define BELL_PERIOD_H (BELL_PERIOD / 256)
+#define BELL_PERIOD_L (unsigned char)(BELL_PERIOD & 0xFF)
+#define BELL_PERIOD_H (unsigned char)(BELL_PERIOD / 256)
#define SPEAKER_PORT (0x61)
#define TIMER2_PORT (0x42)
#define TIMER_CONTROL_PORT (0x43)
@@ -21,6 +21,7 @@
*/
static void sound(void)
{
+#ifdef __BCC__
asm(\
"\tin al,0x61\n" \
"\tor al,#3\n" \
@@ -32,6 +33,13 @@
"\tmov al,#0x05\n" \
"\tout 0x42,al\n" \
);
+#endif
+#ifdef __ia16__
+ outb(inb(SPEAKER_PORT) | 0x03, SPEAKER_PORT);
+ outb(0xB6, TIMER_CONTROL_PORT);
+ outb(BELL_PERIOD_L, TIMER2_PORT);
+ outb(BELL_PERIOD_H, TIMER2_PORT);
+#endif
}
/*
@@ -39,11 +47,16 @@
*/
static void nosound(void)
{
+#ifdef __BCC__
asm(\
"\tin al,0x61\n" \
"\tand al,#0xFC\n" \
"\tout 0x61,al\n" \
);
+#endif
+#ifdef __ia16__
+ outb(inb(SPEAKER_PORT) & ~0x03, SPEAKER_PORT);
+#endif
}
/*
diff -Nur elks.orig/arch/i86/kernel/asm-offsets.c elks/arch/i86/kernel/asm-offsets.c
--- elks.orig/arch/i86/kernel/asm-offsets.c 2015-06-11 13:27:37.000000000 -0500
+++ elks/arch/i86/kernel/asm-offsets.c 2015-06-11 13:41:22.000000000 -0500
@@ -12,7 +12,7 @@
#endif
#endif
-extern int TASK_KRNL_SP, TASK_USER_SP, TASK_USER_SS;
+extern int TASK_KRNL_SP, TASK_USER_SP, TASK_USER_SS, TASK_USER_DS;
extern int TASK_KSTKTOP, TASK_KSTKT_SI;
void asm_offsets(void)
@@ -20,6 +20,7 @@
TASK_KRNL_SP = offsetof(struct task_struct, t_regs.ksp);
TASK_USER_SP = offsetof(struct task_struct, t_regs.sp);
TASK_USER_SS = offsetof(struct task_struct, t_regs.ss);
+ TASK_USER_DS = offsetof(struct task_struct, t_regs.ds);
TASK_KSTKTOP = offsetof(struct task_struct, t_kstack) + KSTACK_BYTES;
TASK_KSTKT_SI = offsetof(struct task_struct, t_kstack) + KSTACK_BYTES - 2;
}
diff -Nur elks.orig/arch/i86/kernel/bios16.c elks/arch/i86/kernel/bios16.c
--- elks.orig/arch/i86/kernel/bios16.c 2015-06-11 13:27:21.000000000 -0500
+++ elks/arch/i86/kernel/bios16.c 2015-06-11 13:35:38.000000000 -0500
@@ -8,16 +8,6 @@
*/
#include <linuxmt/config.h>
-#include <linuxmt/types.h>
-#include <linuxmt/biosparm.h>
-
-static struct biosparms bdt;
-
-/*
- * The external interface is a pointer..
- */
-
-struct biosparms *bios_data_table=&bdt;
/*
* Quick drop into assembler for this one.
@@ -37,24 +27,25 @@
#ifdef CONFIG_ROMCODE
#define stashed_ds [0]
#else
- .extern stashed_ds
+ .extern stashed_ds
#endif
.globl _call_bios
_call_bios:
- pushf
+ push bp
+ mov bp,sp
! Things we want to save - direction flag BP ES
- push bp
- push es
+ pushf
+ push es
push si
push di
! DS already saved in stashed_ds
- mov bx, #_bdt
+ mov bx,4[bp]
! Load the register block from the table
@@ -84,9 +75,9 @@
! Make some breathing room
- pushf
- push bx
+ pushf
push ds
+ push bx
! Stack is now returned FL, BX, DS
@@ -102,10 +93,11 @@
! ***** We can now use the bios data table again *****
- mov bx, #_bdt
+ mov bx,sp
+ seg ss
+ mov bx,18[bx]
- pop 18[bx] ! Save the old DS
- mov 2[bx],ax ! Save the old AX
+ mov 2[bx],ax ! Save the old AX
pop 4[bx] ! Save the old BX
mov 6[bx], cx
mov 8[bx], dx
@@ -113,6 +105,7 @@
mov 12[bx], di
mov 14[bx], bp
mov 16[bx], es
+ pop 18[bx] ! Save the old DS
pop 20[bx] ! Pop the returned flags off
! Restore things we must save
@@ -120,8 +113,8 @@
pop di
pop si
pop es
- pop bp
popf
+ pop bp
ret
#endasm
diff -Nur elks.orig/arch/i86/kernel/mkentry.sh elks/arch/i86/kernel/mkentry.sh
--- elks.orig/arch/i86/kernel/mkentry.sh 2015-06-11 13:27:37.000000000 -0500
+++ elks/arch/i86/kernel/mkentry.sh 2015-06-11 13:35:38.000000000 -0500
@@ -70,7 +70,7 @@
if( depends_on[callno] != "" )
{
- if( callno < maxstd )
+ if( callno < maxno )
{
str = "\t.word _no_syscall";
printf "#else\n%-25s ! %3d - %s\n", str, callno, assigned_to[callno]
diff -Nur elks.orig/arch/i86/kernel/printreg.c elks/arch/i86/kernel/printreg.c
--- elks.orig/arch/i86/kernel/printreg.c 2015-06-11 13:27:37.000000000 -0500
+++ elks/arch/i86/kernel/printreg.c 2015-06-11 13:35:38.000000000 -0500
@@ -1,21 +1,16 @@
#include <linuxmt/config.h>
-#include <linuxmt/kernel.h>
-#include <linuxmt/types.h>
/* This file contains print_regs, which will dump out all of the registers
* and print them out. This is probably one of the sickest routines ever
* written :) - Chad
*/
-void print_regs2(__u16 ax,__u16 bx,__u16 cx,__u16 dx,__u16 di,__u16 si,
- __u16 cs,__u16 ds,__u16 es,__u16 ss,__u16 bp)
-{
- printk("AX=%x BX=%x CX=%x DX=%x DI=%x SI=%x\n", ax, bx, cx, dx, di, si);
- printk("CS=%x DS=%x ES=%x SS=%x BP=%x\n", cs, ds, es, ss, bp);
-}
+/*void print_regs(void);*/
+/*void printsp(void);*/
#ifndef S_SPLINT_S
#asm
+ .extern _printk
.globl _print_regs
_print_regs:
@@ -30,7 +25,9 @@
push cx
push bx
push ax
- call _print_regs2
+ push #fmtprg
+ call _printk
+ pop ax
pop ax
pop bx
pop cx
@@ -59,6 +56,8 @@
.data
msg: .ascii "SP=%x:%x\n"
.byte 0
+fmtprg: .ascii "AX=%x BX=%x CX=%x DX=%x DI=%x SI=%x\nCS=%x DS=%x ES=%x SS=%x BP=%x\n"
+ .byte 0
#endasm
#endif
diff -Nur elks.orig/arch/i86/kernel/system.c elks/arch/i86/kernel/system.c
--- elks.orig/arch/i86/kernel/system.c 2015-06-11 13:27:37.000000000 -0500
+++ elks/arch/i86/kernel/system.c 2015-06-11 13:35:38.000000000 -0500
@@ -57,16 +57,21 @@
/* Stubs for functions needed elsewhere */
-#ifndef S_SPLINT_S
-#asm
- export _hard_reset_now
-
-_hard_reset_now:
-
- mov ax,#0x40 ! No memory check on reboot
- mov ds, ax
- mov [0x72],#0x1234
- jmp #0xffff:0
-
-#endasm
+void hard_reset_now(void)
+{
+#ifdef __BCC__
+ asm(\
+ "\tmov ax,#0x40\n" \
+ "\tmov ds, ax\n" \
+ "\tmov [0x72],#0x1234\n" \
+ "\tjmp #0xffff:0\n" \
+ );
+#endif
+#ifdef __ia16__
+ asm("movw $64,%ax\n\t"
+ "movw %ax,%ds\n\t"
+ "movw $4660,114\n\t"
+ "jmp 65535:0\n\t"
+ );
#endif
+}
diff -Nur elks.orig/arch/i86/lib/fmemset.s elks/arch/i86/lib/fmemset.s
--- elks.orig/arch/i86/lib/fmemset.s 2015-04-26 11:39:15.000000000 -0500
+++ elks/arch/i86/lib/fmemset.s 2015-06-11 13:35:38.000000000 -0500
@@ -27,3 +27,32 @@
pop es
pop bp
ret
+
+!
+! blt_forth( soff, sseg, doff, dseg, bytes )
+! for to > from
+!
+ .globl _blt_forth
+
+_blt_forth:
+ push bp
+ mov bp, sp
+ push es
+ push ds
+ push si
+ push di
+ pushf
+ lds si, [bp+4]
+ les di, [bp+8]
+ mov cx, [bp+12]
+ std
+ rep
+ movsb
+ popf
+ pop di
+ pop si
+ pop ds
+ pop es
+ pop bp
+ ret
+
diff -Nur elks.orig/arch/i86/lib/memmove.c elks/arch/i86/lib/memmove.c
--- elks.orig/arch/i86/lib/memmove.c 2015-04-26 11:39:15.000000000 -0500
+++ elks/arch/i86/lib/memmove.c 2015-06-11 13:35:38.000000000 -0500
@@ -7,7 +7,7 @@
#include <linuxmt/mm.h>
-static void blt_forth(unsigned,unsigned,unsigned,unsigned,unsigned);
+void blt_forth(unsigned,unsigned,unsigned,unsigned,unsigned);
void far_memmove(unsigned sseg, unsigned soff, unsigned dseg, unsigned doff,
unsigned bytes)
@@ -27,34 +27,3 @@
}
}
-#ifndef S_SPLINT_S
-#asm
- .text
- ! blt_forth( soff, sseg, doff, dseg, bytes )
- ! for to > from
- .even
-
-_blt_forth:
- push bp
- mov bp, sp
- push es
- push ds
- push si
- push di
- pushf
- lds si, [bp+4]
- les di, [bp+8]
- mov cx, [bp+12]
- std
- rep
- movsb
- popf
- pop di
- pop si
- pop ds
- pop es
- pop bp
- ret
-
-#endasm
-#endif
diff -Nur elks.orig/include/linuxmt/biosparm.h elks/include/linuxmt/biosparm.h
--- elks.orig/include/linuxmt/biosparm.h 2015-04-26 11:39:15.000000000 -0500
+++ elks/include/linuxmt/biosparm.h 2015-06-11 13:35:38.000000000 -0500
@@ -43,25 +43,7 @@
unsigned short fl; /* 20 */
};
-/* Useful defines for accessing the above structure. */
-
-#define CARRY_SET (bios_data_table->fl & 0x1)
-#define SEGMENT(addr) (((unsigned long)addr) >> 4)
-#define OFFSET(addr) (((unsigned long)addr) & 0xf)
-#define BD_IRQ bios_data_table->irq
-#define BD_AX bios_data_table->ax
-#define BD_BX bios_data_table->bx
-#define BD_CX bios_data_table->cx
-#define BD_DX bios_data_table->dx
-#define BD_SI bios_data_table->si
-#define BD_DI bios_data_table->di
-#define BD_ES bios_data_table->es
-#define BD_FL bios_data_table->fl
-
/* exported functions */
-extern void call_bios(void);
-
-/* Some globals that we need */
-extern struct biosparms *bios_data_table;
+extern void call_bios(struct biosparms *);
#endif
diff -Nur elks.orig/kernel/time.c elks/kernel/time.c
--- elks.orig/kernel/time.c 2015-04-26 11:39:15.000000000 -0500
+++ elks/kernel/time.c 2015-06-11 13:35:38.000000000 -0500
@@ -26,7 +26,7 @@
#include <arch/types.h>
#include <linuxmt/time.h>
-#include <linuxmt/timex.h>
+#include <linuxmt/sched.h>
#include <linuxmt/errno.h>
#include <linuxmt/mm.h>
@@ -34,7 +34,6 @@
#include <arch/system.h>
#include <arch/segment.h>
-#include <linuxmt/sched.h>
/* this is the structure holding the base time (in UTC, of course) */
struct timeval xtime;
next reply other threads:[~2015-06-13 4:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-13 4:52 Juan Perez-Sanchez [this message]
2015-06-13 10:20 ` [PATCH] Separation C and assembly functions to different files u-vpoa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAD6VGubpzYTk1+cnM0_4qjQx17gTUDv2mfjbjY=Uec7io1mjig@mail.gmail.com' \
--to=lithoxs@gmail.com \
--cc=linux-8086@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).